servo: Merge #13762 - Implement "reset algorithm" for `<select>` (from frewsxcv:select-reset); r=Manishearth
authorCorey Farwell <coreyf@rwell.org>
Thu, 20 Oct 2016 23:31:46 -0500
changeset 339965 f778d6fee54c191e640717baf5780c30d3a61849
parent 339964 9c4be769929f0aaff7bc25b1c1c74e0676dbf31b
child 339966 121c429a753fc41eed792d85c7c2106c1fc0ce01
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #13762 - Implement "reset algorithm" for `<select>` (from frewsxcv:select-reset); r=Manishearth Source-Repo: https://github.com/servo/servo Source-Revision: 28be83bd9a5b2adc136bfdf006ae5d285d0178ad
servo/components/script/dom/htmlformelement.rs
servo/components/script/dom/htmlselectelement.rs
--- a/servo/components/script/dom/htmlformelement.rs
+++ b/servo/components/script/dom/htmlformelement.rs
@@ -629,18 +629,17 @@ impl HTMLFormElement {
                     child.downcast::<HTMLInputElement>().unwrap().reset();
                 }
                 // TODO HTMLKeygenElement unimplemented
                 //NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLKeygenElement)) => {
                 //    // Unimplemented
                 //    {}
                 //}
                 NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
-                    // Unimplemented
-                    {}
+                    child.downcast::<HTMLSelectElement>().unwrap().reset();
                 }
                 NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
                     child.downcast::<HTMLTextAreaElement>().unwrap().reset();
                 }
                 NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOutputElement)) => {
                     // Unimplemented
                     {}
                 }
--- a/servo/components/script/dom/htmlselectelement.rs
+++ b/servo/components/script/dom/htmlselectelement.rs
@@ -79,16 +79,26 @@ impl HTMLSelectElement {
     pub fn new(local_name: Atom,
                prefix: Option<DOMString>,
                document: &Document) -> Root<HTMLSelectElement> {
         Node::reflect_node(box HTMLSelectElement::new_inherited(local_name, prefix, document),
                            document,
                            HTMLSelectElementBinding::Wrap)
     }
 
+    // https://html.spec.whatwg.org/multipage/#the-select-element:concept-form-reset-control
+    pub fn reset(&self) {
+        let node = self.upcast::<Node>();
+        for opt in node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>) {
+            opt.set_selectedness(opt.DefaultSelected());
+            opt.set_dirtiness(false);
+        }
+        self.ask_for_reset();
+    }
+
     // https://html.spec.whatwg.org/multipage/#ask-for-a-reset
     pub fn ask_for_reset(&self) {
         if self.Multiple() {
             return;
         }
 
         let mut first_enabled: Option<Root<HTMLOptionElement>> = None;
         let mut last_selected: Option<Root<HTMLOptionElement>> = None;