Title: [110340] trunk
Revision
110340
Author
[email protected]
Date
2012-03-09 15:11:47 -0800 (Fri, 09 Mar 2012)

Log Message

Implement selectedOptions attribute of <select>.
https://bugs.webkit.org/show_bug.cgi?id=80631

Reviewed by Benjamin Poulain.

Source/WebCore:

Add a new collection as a member of HTMLSelectElement which is
used to store the selected elements. Extend HTMLCollection to
support the new collection type needed by this feature.

Reference : http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#dom-select-selectedoptions

Test: fast/dom/select-selectedOptions.html

* html/CollectionType.h:
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::shouldIncludeChildren):
(WebCore::HTMLCollection::isAcceptableElement):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::selectedOptions):
(WebCore):
* html/HTMLSelectElement.h:
(HTMLSelectElement):
* html/HTMLSelectElement.idl:

LayoutTests:

New tests to cover the feature.

* fast/dom/select-selectedOptions-expected.txt: Added.
* fast/dom/select-selectedOptions.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (110339 => 110340)


--- trunk/LayoutTests/ChangeLog	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/LayoutTests/ChangeLog	2012-03-09 23:11:47 UTC (rev 110340)
@@ -1,3 +1,15 @@
+2012-03-09  Alexis Menard  <[email protected]>
+
+        Implement selectedOptions attribute of <select>.
+        https://bugs.webkit.org/show_bug.cgi?id=80631
+
+        Reviewed by Benjamin Poulain.
+
+        New tests to cover the feature.
+
+        * fast/dom/select-selectedOptions-expected.txt: Added.
+        * fast/dom/select-selectedOptions.html: Added.
+
 2012-03-09  Ken Buchanan  <[email protected]>
 
         Crash due to inserting letter into div with first-letter

Added: trunk/LayoutTests/fast/dom/select-selectedOptions-expected.txt (0 => 110340)


--- trunk/LayoutTests/fast/dom/select-selectedOptions-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/select-selectedOptions-expected.txt	2012-03-09 23:11:47 UTC (rev 110340)
@@ -0,0 +1,46 @@
+
+1) Initial there is no selected options.
+PASS mySelect.options.length is 2
+PASS mySelect.selectedOptions.length is 0
+2) Select an option should update the selected options collection.
+PASS mySelect.options.length is 2
+PASS mySelect.selectedOptions.length is 1
+PASS mySelect.selectedOptions[0].text is 'one'
+3) Adding a non selected option should not change the selected options collection.
+PASS mySelect.options.length is 3
+PASS mySelect.selectedOptions.length is 1
+PASS mySelect.selectedOptions[0].text is 'one'
+4) Adding a selected option should change the selected options collection.
+PASS mySelect.options.length is 4
+PASS mySelect.selectedOptions.length is 2
+PASS mySelect.selectedOptions[0].text is 'one'
+PASS mySelect.selectedOptions[1].text is 'five'
+5) Unselect an option should update the selected options collection.
+PASS mySelect.options.length is 4
+PASS mySelect.selectedOptions.length is 1
+PASS mySelect.selectedOptions[0].text is 'five'
+6) Remove an option unselected should not update the selected options collection.
+PASS mySelect.options.length is 3
+PASS mySelect.selectedOptions.length is 1
+PASS mySelect.selectedOptions[0].text is 'five'
+7) Remove an option selected should update the selected options collection.
+PASS mySelect.options.length is 2
+PASS mySelect.selectedOptions.length is 0
+8) Change multiple attribute to false should update selectedOptions.
+PASS mySelect.options.length is 2
+PASS mySelect.selectedOptions.length is 1
+PASS mySelect.selectedOptions[0].text is 'two'
+9) Even with an option disabled selectedOptions should be updated.
+PASS mySelect.options.length is 2
+PASS mySelect.selectedOptions.length is 1
+PASS mySelect.selectedOptions[0].text is 'one'
+10) Even with select element disabled, the selectedOptions should be updated.
+PASS mySelect.options.length is 2
+PASS mySelect.selectedOptions.length is 2
+PASS mySelect.selectedOptions[0].text is 'one'
+PASS mySelect.selectedOptions[1].text is 'two'
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/select-selectedOptions.html (0 => 110340)


--- trunk/LayoutTests/fast/dom/select-selectedOptions.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/select-selectedOptions.html	2012-03-09 23:11:47 UTC (rev 110340)
@@ -0,0 +1,83 @@
+<select id="test" size="3">
+</select>
+<div id="console"></div>
+<script src=""
+<script>
+function reset(mySelect) {
+  mySelect.length = 0;
+  mySelect.multiple = true;
+  mySelect.options[mySelect.length] = new Option("one", "value", false);
+  mySelect.options[mySelect.length] = new Option("two", "value", false);
+}
+
+var mySelect = document.getElementById("test");
+reset(mySelect);
+var i = 0;
+
+debug((++i) + ") Initial there is no selected options.");
+shouldBe("mySelect.options.length", "2");
+shouldBe("mySelect.selectedOptions.length", "0");
+
+debug((++i) + ") Select an option should update the selected options collection.");
+mySelect.options[0].selected = true;
+shouldBe("mySelect.options.length", "2");
+shouldBe("mySelect.selectedOptions.length", "1");
+shouldBe("mySelect.selectedOptions[0].text", "'one'");
+
+debug((++i) + ") Adding a non selected option should not change the selected options collection.");
+mySelect.options[mySelect.length] = new Option("three", "value", false);
+shouldBe("mySelect.options.length", "3");
+shouldBe("mySelect.selectedOptions.length", "1");
+shouldBe("mySelect.selectedOptions[0].text", "'one'");
+
+debug((++i) + ") Adding a selected option should change the selected options collection.");
+mySelect.options[mySelect.length] = new Option("five", "value", true, true);
+shouldBe("mySelect.options.length", "4");
+shouldBe("mySelect.selectedOptions.length", "2");
+shouldBe("mySelect.selectedOptions[0].text", "'one'");
+shouldBe("mySelect.selectedOptions[1].text", "'five'");
+
+debug((++i) + ") Unselect an option should update the selected options collection.");
+mySelect.options[0].selected = false;
+shouldBe("mySelect.options.length", "4");
+shouldBe("mySelect.selectedOptions.length", "1");
+shouldBe("mySelect.selectedOptions[0].text", "'five'");
+
+debug((++i) + ") Remove an option unselected should not update the selected options collection.");
+mySelect.remove(0);
+shouldBe("mySelect.options.length", "3");
+shouldBe("mySelect.selectedOptions.length", "1");
+shouldBe("mySelect.selectedOptions[0].text", "'five'");
+
+debug((++i) + ") Remove an option selected should update the selected options collection.");
+mySelect.remove(2);
+shouldBe("mySelect.options.length", "2");
+shouldBe("mySelect.selectedOptions.length", "0");
+
+mySelect.options[0].selected = true;
+mySelect.options[1].selected = true;
+debug((++i) + ") Change multiple attribute to false should update selectedOptions.");
+mySelect.multiple = false;
+shouldBe("mySelect.options.length", "2");
+shouldBe("mySelect.selectedOptions.length", "1");
+shouldBe("mySelect.selectedOptions[0].text", "'two'");
+
+reset(mySelect);
+debug((++i) + ") Even with an option disabled selectedOptions should be updated.");
+mySelect.options[0].disabled = true;
+mySelect.options[0].selected = true;
+shouldBe("mySelect.options.length", "2");
+shouldBe("mySelect.selectedOptions.length", "1");
+shouldBe("mySelect.selectedOptions[0].text", "'one'");
+
+debug((++i) + ") Even with select element disabled, the selectedOptions should be updated.");
+mySelect.disabled = true;
+mySelect.options[1].selected = true;
+shouldBe("mySelect.options.length", "2");
+shouldBe("mySelect.selectedOptions.length", "2");
+shouldBe("mySelect.selectedOptions[0].text", "'one'");
+shouldBe("mySelect.selectedOptions[1].text", "'two'");
+
+debug("");
+</script>
+<script src=""

Modified: trunk/Source/WebCore/ChangeLog (110339 => 110340)


--- trunk/Source/WebCore/ChangeLog	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/Source/WebCore/ChangeLog	2012-03-09 23:11:47 UTC (rev 110340)
@@ -1,3 +1,29 @@
+2012-03-09  Alexis Menard  <[email protected]>
+
+        Implement selectedOptions attribute of <select>.
+        https://bugs.webkit.org/show_bug.cgi?id=80631
+
+        Reviewed by Benjamin Poulain.
+
+        Add a new collection as a member of HTMLSelectElement which is
+        used to store the selected elements. Extend HTMLCollection to
+        support the new collection type needed by this feature.
+
+        Reference : http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#dom-select-selectedoptions
+
+        Test: fast/dom/select-selectedOptions.html
+
+        * html/CollectionType.h:
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::shouldIncludeChildren):
+        (WebCore::HTMLCollection::isAcceptableElement):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::selectedOptions):
+        (WebCore):
+        * html/HTMLSelectElement.h:
+        (HTMLSelectElement):
+        * html/HTMLSelectElement.idl:
+
 2012-03-09  Tien-Ren Chen  <[email protected]>
 
         [chromium] ScrollbarLayerChromium/CCScrollbarLayerImpl for CC-side scrollbar painting

Modified: trunk/Source/WebCore/html/CollectionType.h (110339 => 110340)


--- trunk/Source/WebCore/html/CollectionType.h	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/Source/WebCore/html/CollectionType.h	2012-03-09 23:11:47 UTC (rev 110340)
@@ -51,6 +51,7 @@
     TSectionRows, // all row elements in this table section
     TRCells,      // all cells in this row
     SelectOptions,
+    SelectedOptions,
     DataListOptions,
     MapAreas,
 

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (110339 => 110340)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2012-03-09 23:11:47 UTC (rev 110340)
@@ -61,6 +61,7 @@
     case MapAreas:
     case OtherCollection:
     case SelectOptions:
+    case SelectedOptions:
     case DataListOptions:
     case WindowNamedItems:
 #if ENABLE(MICRODATA)
@@ -114,6 +115,13 @@
         return element->hasLocalName(trTag);
     case SelectOptions:
         return element->hasLocalName(optionTag);
+    case SelectedOptions:
+        if (element->hasLocalName(optionTag)) {
+            HTMLOptionElement* option = static_cast<HTMLOptionElement*>(element);
+            if (option->selected())
+                return true;
+        }
+        return false;
     case DataListOptions:
         if (element->hasLocalName(optionTag)) {
             HTMLOptionElement* option = static_cast<HTMLOptionElement*>(element);

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (110339 => 110340)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2012-03-09 23:11:47 UTC (rev 110340)
@@ -331,6 +331,13 @@
     return childContext.isOnEncapsulationBoundary() && HTMLFormControlElementWithState::childShouldCreateRenderer(childContext);
 }
 
+HTMLCollection* HTMLSelectElement::selectedOptions()
+{
+    if (!m_selectedOptionsCollection)
+        m_selectedOptionsCollection = HTMLCollection::create(this, SelectedOptions);
+    return m_selectedOptionsCollection.get();
+}
+
 HTMLOptionsCollection* HTMLSelectElement::options()
 {
     if (!m_optionsCollection)

Modified: trunk/Source/WebCore/html/HTMLSelectElement.h (110339 => 110340)


--- trunk/Source/WebCore/html/HTMLSelectElement.h	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/Source/WebCore/html/HTMLSelectElement.h	2012-03-09 23:11:47 UTC (rev 110340)
@@ -63,6 +63,7 @@
     void setValue(const String&);
 
     HTMLOptionsCollection* options();
+    HTMLCollection* selectedOptions();
 
     void optionElementChildrenChanged();
 
@@ -178,6 +179,7 @@
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
     OwnPtr<HTMLOptionsCollection> m_optionsCollection;
+    OwnPtr<HTMLCollection> m_selectedOptionsCollection;
 
     // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects.
     mutable Vector<HTMLElement*> m_listItems;

Modified: trunk/Source/WebCore/html/HTMLSelectElement.idl (110339 => 110340)


--- trunk/Source/WebCore/html/HTMLSelectElement.idl	2012-03-09 23:06:05 UTC (rev 110339)
+++ trunk/Source/WebCore/html/HTMLSelectElement.idl	2012-03-09 23:11:47 UTC (rev 110340)
@@ -53,6 +53,7 @@
 #else
         void remove(in long index);
 #endif
+        readonly attribute HTMLCollection selectedOptions;
         attribute long selectedIndex;
         attribute [TreatNullAs=NullString] DOMString value;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to