WebCore:
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Dec 2007 00:23:34 +0000 (00:23 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Dec 2007 00:23:34 +0000 (00:23 +0000)
        Reviewed by John Sullivan.

        - fix a bug in debug builds only where selecting an earlier item in
          a popup selects the first item

        Test: fast/forms/menulist-selection-reset.html

        * html/HTMLSelectElement.cpp:
        (WebCore::HTMLSelectElement::recalcListItems): Added an argument that
        tells that function whether it should update the selected state of
        option elements.
        (WebCore::HTMLSelectElement::checkListItems): Changed to pass false
        as the above argument.
        * html/HTMLSelectElement.h:

LayoutTests:

        Reviewed by John Sullivan.

        - test for a bug in debug builds only where selecting an earlier item in
          a popup selects the first item

        * fast/forms/menulist-selection-reset-expected.txt: Added.
        * fast/forms/menulist-selection-reset.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28666 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/menulist-selection-reset-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/menulist-selection-reset.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLSelectElement.cpp
WebCore/html/HTMLSelectElement.h

index d622dbb5cda52937db0ab12a73809984581e07ac..60e910870fb42a6955ec8b173563f944c0b4c43c 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-12  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by John Sullivan.
+
+        - test for a bug in debug builds only where selecting an earlier item in
+          a popup selects the first item
+
+        * fast/forms/menulist-selection-reset-expected.txt: Added.
+        * fast/forms/menulist-selection-reset.html: Added.
+
 2007-12-12  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Niko.
diff --git a/LayoutTests/fast/forms/menulist-selection-reset-expected.txt b/LayoutTests/fast/forms/menulist-selection-reset-expected.txt
new file mode 100644 (file)
index 0000000..aa44e7c
--- /dev/null
@@ -0,0 +1,2 @@
+
+PASS
diff --git a/LayoutTests/fast/forms/menulist-selection-reset.html b/LayoutTests/fast/forms/menulist-selection-reset.html
new file mode 100644 (file)
index 0000000..20ac958
--- /dev/null
@@ -0,0 +1,14 @@
+<select id="select">
+    <option>FAIL</option>
+    <option>PASS</option>
+    <option selected="true">Did not run</option>
+</select>
+<p id="result">
+</p>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    select.selectedIndex = 1;
+    result.innerText = select.selectedIndex == 1 ? "PASS" : "FAIL";
+</script>
index d6b5e74b56ad32a2712202e7113c035b221ca18e..17576385df89a8612384dc704fe2ba458d89fbbd 100644 (file)
@@ -1,3 +1,20 @@
+2007-12-12  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by John Sullivan.
+
+        - fix a bug in debug builds only where selecting an earlier item in
+          a popup selects the first item
+
+        Test: fast/forms/menulist-selection-reset.html
+
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::recalcListItems): Added an argument that
+        tells that function whether it should update the selected state of
+        option elements.
+        (WebCore::HTMLSelectElement::checkListItems): Changed to pass false
+        as the above argument.
+        * html/HTMLSelectElement.h:
+
 2007-12-12  Adele Peterson  <adele@apple.com>
 
         Reviewed by Geoff.
index 50c4e74905bc3fc53ffc5ae67c190827b638eb44..12b078157da3f998c646993355d484e3e64ebfa0 100644 (file)
@@ -494,7 +494,7 @@ PassRefPtr<HTMLOptionsCollection> HTMLSelectElement::options()
     return new HTMLOptionsCollection(this);
 }
 
-void HTMLSelectElement::recalcListItems() const
+void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const
 {
     m_listItems.clear();
     HTMLOptionElement* foundSelected = 0;
@@ -513,12 +513,14 @@ void HTMLSelectElement::recalcListItems() const
 
         if (current->hasTagName(optionTag)) {
             m_listItems.append(static_cast<HTMLElement*>(current));
-            if (!foundSelected && (usesMenuList() || (!m_multiple && static_cast<HTMLOptionElement*>(current)->selected()))) {
-                foundSelected = static_cast<HTMLOptionElement*>(current);
-                foundSelected->setSelectedState(true);
-            } else if (foundSelected && !m_multiple && static_cast<HTMLOptionElement*>(current)->selected()) {
-                foundSelected->setSelectedState(false);
-                foundSelected = static_cast<HTMLOptionElement*>(current);
+            if (updateSelectedStates) {
+                if (!foundSelected && (usesMenuList() || (!m_multiple && static_cast<HTMLOptionElement*>(current)->selected()))) {
+                    foundSelected = static_cast<HTMLOptionElement*>(current);
+                    foundSelected->setSelectedState(true);
+                } else if (foundSelected && !m_multiple && static_cast<HTMLOptionElement*>(current)->selected()) {
+                    foundSelected->setSelectedState(false);
+                    foundSelected = static_cast<HTMLOptionElement*>(current);
+                }
             }
         }
         if (current->hasTagName(hrTag))
@@ -1091,7 +1093,7 @@ void HTMLSelectElement::scrollToSelection()
 void HTMLSelectElement::checkListItems() const
 {
     Vector<HTMLElement*> items = m_listItems;
-    recalcListItems();
+    recalcListItems(false);
     ASSERT(items == m_listItems);
 }
 
index 7097145cb28c33e4a46f7918152a050731c28059..5573fab6edade4a888c4b62a391d1ed8f8bc0057 100644 (file)
@@ -138,7 +138,7 @@ public:
     void scrollToSelection();
 
 private:
-    void recalcListItems() const;
+    void recalcListItems(bool updateSelectedStates = true) const;
     void checkListItems() const;
 
     void deselectItems(HTMLOptionElement* excludeElement = 0);