From 0148e9705b9e6dad41dd1895313c57f2acca3c56 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 7 Dec 2017 13:58:24 +0100 Subject: [PATCH] Support the select() method on input/textarea Issue #19171 --- components/script/dom/htmlinputelement.rs | 30 +++++++ components/script/dom/htmltextareaelement.rs | 9 ++ components/script/dom/textcontrol.rs | 12 +++ .../dom/webidls/HTMLInputElement.webidl | 2 +- .../dom/webidls/HTMLTextAreaElement.webidl | 2 +- .../wpt/metadata/html/dom/interfaces.html.ini | 78 ---------------- .../textfieldselection/select-event.html.ini | 18 ---- .../textfieldselection/selection.html.ini | 44 --------- .../the-input-element/selection.html.ini | 90 ------------------- 9 files changed, 53 insertions(+), 232 deletions(-) delete mode 100644 tests/wpt/metadata/html/semantics/forms/textfieldselection/selection.html.ini diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index ed153529889..c6d72d5489d 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -417,6 +417,31 @@ impl TextControl for HTMLInputElement { _ => false } } + + // https://html.spec.whatwg.org/multipage/#concept-input-apply + // + // Defines input types to which the select() IDL method applies. These are a superset of the + // types for which selection_api_applies() returns true. + // + // Types omitted which could theoretically be included if they were + // rendered as a text control: file + fn has_selectable_text(&self) -> bool { + match self.input_type() { + InputType::Text | InputType::Search | InputType::Url + | InputType::Tel | InputType::Password | InputType::Email + | InputType::Date | InputType::Month | InputType::Week + | InputType::Time | InputType::DatetimeLocal | InputType::Number + | InputType::Color => { + true + } + + InputType::Button | InputType::Checkbox | InputType::File + | InputType::Hidden | InputType::Image | InputType::Radio + | InputType::Range | InputType::Reset | InputType::Submit => { + false + } + } + } } impl HTMLInputElementMethods for HTMLInputElement { @@ -687,6 +712,11 @@ impl HTMLInputElementMethods for HTMLInputElement { } } + // https://html.spec.whatwg.org/multipage/#dom-textarea/input-select + fn Select(&self) { + self.dom_select(); // defined in TextControl trait + } + // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart fn GetSelectionStart(&self) -> Option { self.get_dom_selection_start() diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index af69e227d60..e0388011b0f 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -152,6 +152,10 @@ impl TextControl for HTMLTextAreaElement { fn selection_api_applies(&self) -> bool { true } + + fn has_selectable_text(&self) -> bool { + true + } } impl HTMLTextAreaElementMethods for HTMLTextAreaElement { @@ -266,6 +270,11 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { self.upcast::().labels() } + // https://html.spec.whatwg.org/multipage/#dom-textarea/input-select + fn Select(&self) { + self.dom_select(); // defined in TextControl trait + } + // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart fn GetSelectionStart(&self) -> Option { self.get_dom_selection_start() diff --git a/components/script/dom/textcontrol.rs b/components/script/dom/textcontrol.rs index 9143c2bda23..c2eb42dae17 100644 --- a/components/script/dom/textcontrol.rs +++ b/components/script/dom/textcontrol.rs @@ -15,6 +15,18 @@ use textinput::{SelectionDirection, TextInput}; pub trait TextControl: DerivedFrom + DerivedFrom { fn textinput(&self) -> &DomRefCell>; fn selection_api_applies(&self) -> bool; + fn has_selectable_text(&self) -> bool; + + // https://html.spec.whatwg.org/multipage/#dom-textarea/input-select + fn dom_select(&self) { + // Step 1 + if !self.has_selectable_text() { + return; + } + + // Step 2 + self.set_selection_range(Some(0), Some(u32::max_value()), None); + } // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart fn get_dom_selection_start(&self) -> Option { diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl index 93a5a7f108b..ae8906b4e4c 100644 --- a/components/script/dom/webidls/HTMLInputElement.webidl +++ b/components/script/dom/webidls/HTMLInputElement.webidl @@ -89,7 +89,7 @@ interface HTMLInputElement : HTMLElement { readonly attribute NodeList labels; - //void select(); + void select(); [SetterThrows] attribute unsigned long? selectionStart; [SetterThrows] diff --git a/components/script/dom/webidls/HTMLTextAreaElement.webidl b/components/script/dom/webidls/HTMLTextAreaElement.webidl index f0e8a0be118..c02cc5730a4 100644 --- a/components/script/dom/webidls/HTMLTextAreaElement.webidl +++ b/components/script/dom/webidls/HTMLTextAreaElement.webidl @@ -50,7 +50,7 @@ interface HTMLTextAreaElement : HTMLElement { readonly attribute NodeList labels; - // void select(); + void select(); [SetterThrows] attribute unsigned long? selectionStart; [SetterThrows] diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index d58a1b90b02..90f98d5ce88 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -3090,9 +3090,6 @@ [HTMLInputElement interface: operation setCustomValidity(DOMString)] expected: FAIL - [HTMLInputElement interface: operation select()] - expected: FAIL - [HTMLInputElement interface: operation setRangeText(DOMString)] expected: FAIL @@ -3342,9 +3339,6 @@ [HTMLTextAreaElement interface: operation setCustomValidity(DOMString)] expected: FAIL - [HTMLTextAreaElement interface: operation select()] - expected: FAIL - [HTMLTextAreaElement interface: operation setRangeText(DOMString)] expected: FAIL @@ -11787,9 +11781,6 @@ [HTMLInputElement interface: document.createElement("input") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -11853,9 +11844,6 @@ [HTMLInputElement interface: createInput("text") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("text") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("text") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -11919,9 +11907,6 @@ [HTMLInputElement interface: createInput("hidden") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("hidden") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("hidden") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -11985,9 +11970,6 @@ [HTMLInputElement interface: createInput("search") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("search") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("search") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12051,9 +12033,6 @@ [HTMLInputElement interface: createInput("tel") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("tel") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("tel") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12117,9 +12096,6 @@ [HTMLInputElement interface: createInput("url") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("url") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("url") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12183,9 +12159,6 @@ [HTMLInputElement interface: createInput("email") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("email") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("email") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12249,9 +12222,6 @@ [HTMLInputElement interface: createInput("password") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("password") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("password") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12315,9 +12285,6 @@ [HTMLInputElement interface: createInput("date") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("date") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("date") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12381,9 +12348,6 @@ [HTMLInputElement interface: createInput("month") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("month") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("month") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12447,9 +12411,6 @@ [HTMLInputElement interface: createInput("week") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("week") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("week") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12513,9 +12474,6 @@ [HTMLInputElement interface: createInput("time") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("time") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("time") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12579,9 +12537,6 @@ [HTMLInputElement interface: createInput("datetime-local") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("datetime-local") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("datetime-local") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12645,9 +12600,6 @@ [HTMLInputElement interface: createInput("number") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("number") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("number") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12711,9 +12663,6 @@ [HTMLInputElement interface: createInput("range") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("range") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("range") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12777,9 +12726,6 @@ [HTMLInputElement interface: createInput("color") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("color") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("color") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12843,9 +12789,6 @@ [HTMLInputElement interface: createInput("checkbox") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("checkbox") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("checkbox") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12909,9 +12852,6 @@ [HTMLInputElement interface: createInput("radio") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("radio") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("radio") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -12978,9 +12918,6 @@ [HTMLInputElement interface: createInput("file") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("file") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("file") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -13044,9 +12981,6 @@ [HTMLInputElement interface: createInput("submit") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("submit") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("submit") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -13110,9 +13044,6 @@ [HTMLInputElement interface: createInput("image") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("image") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("image") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -13176,9 +13107,6 @@ [HTMLInputElement interface: createInput("reset") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("reset") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("reset") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -13242,9 +13170,6 @@ [HTMLInputElement interface: createInput("button") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLInputElement interface: createInput("button") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLInputElement interface: createInput("button") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL @@ -13377,9 +13302,6 @@ [HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "setCustomValidity(DOMString)" with the proper type] expected: FAIL - [HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "select()" with the proper type] - expected: FAIL - [HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "setRangeText(DOMString)" with the proper type] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/textfieldselection/select-event.html.ini b/tests/wpt/metadata/html/semantics/forms/textfieldselection/select-event.html.ini index 1f1def1f0da..803dce040ad 100644 --- a/tests/wpt/metadata/html/semantics/forms/textfieldselection/select-event.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/textfieldselection/select-event.html.ini @@ -1,8 +1,5 @@ [select-event.html] type: testharness - [textarea: select()] - expected: FAIL - [textarea: select() a second time (must not fire select)] expected: FAIL @@ -24,9 +21,6 @@ [textarea: setRangeText() a second time (must not fire select)] expected: FAIL - [input type text: select()] - expected: FAIL - [input type text: select() a second time (must not fire select)] expected: FAIL @@ -48,9 +42,6 @@ [input type text: setRangeText() a second time (must not fire select)] expected: FAIL - [input type search: select()] - expected: FAIL - [input type search: select() a second time (must not fire select)] expected: FAIL @@ -72,9 +63,6 @@ [input type search: setRangeText() a second time (must not fire select)] expected: FAIL - [input type tel: select()] - expected: FAIL - [input type tel: select() a second time (must not fire select)] expected: FAIL @@ -96,9 +84,6 @@ [input type tel: setRangeText() a second time (must not fire select)] expected: FAIL - [input type url: select()] - expected: FAIL - [input type url: select() a second time (must not fire select)] expected: FAIL @@ -120,9 +105,6 @@ [input type url: setRangeText() a second time (must not fire select)] expected: FAIL - [input type password: select()] - expected: FAIL - [input type password: select() a second time (must not fire select)] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection.html.ini b/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection.html.ini deleted file mode 100644 index f9483ec5a35..00000000000 --- a/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection.html.ini +++ /dev/null @@ -1,44 +0,0 @@ -[selection.html] - type: testharness - [test if selection text is correct for input] - expected: FAIL - - [test if selection text is correct for textarea] - expected: FAIL - - [test if non-ascii selection text is correct for input] - expected: FAIL - - [test if non-ascii selection text is correct for textarea] - expected: FAIL - - [test SelectionStart offset for input] - expected: FAIL - - [test SelectionStart offset for textarea] - expected: FAIL - - [test SelectionEnd offset for input] - expected: FAIL - - [test SelectionEnd offset for textarea] - expected: FAIL - - [test SelectionDirection for input] - expected: FAIL - - [test SelectionDirection for textarea] - expected: FAIL - - [test SelectionStart offset for input that is appended] - expected: FAIL - - [test SelectionStart offset for textarea that is appended] - expected: FAIL - - [test SelectionEnd offset for input that is appended] - expected: FAIL - - [test SelectionEnd offset for textarea that is appended] - expected: FAIL - diff --git a/tests/wpt/metadata/html/semantics/forms/the-input-element/selection.html.ini b/tests/wpt/metadata/html/semantics/forms/the-input-element/selection.html.ini index 11e799be3f6..3eab14f776c 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-input-element/selection.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-input-element/selection.html.ini @@ -1,71 +1,5 @@ [selection.html] type: testharness - [input type text should support the select() method] - expected: FAIL - - [input type search should support the select() method] - expected: FAIL - - [input type url should support the select() method] - expected: FAIL - - [input type tel should support the select() method] - expected: FAIL - - [input type email should support the select() method] - expected: FAIL - - [input type password should support the select() method] - expected: FAIL - - [input type date should support the select() method] - expected: FAIL - - [input type month should support the select() method] - expected: FAIL - - [input type week should support the select() method] - expected: FAIL - - [input type time should support the select() method] - expected: FAIL - - [input type datetime-local should support the select() method] - expected: FAIL - - [input type number should support the select() method] - expected: FAIL - - [input type color should support the select() method] - expected: FAIL - - [input type file should support the select() method] - expected: FAIL - - [input type hidden should not support the select() method] - expected: FAIL - - [input type range should not support the select() method] - expected: FAIL - - [input type checkbox should not support the select() method] - expected: FAIL - - [input type radio should not support the select() method] - expected: FAIL - - [input type submit should not support the select() method] - expected: FAIL - - [input type image should not support the select() method] - expected: FAIL - - [input type reset should not support the select() method] - expected: FAIL - - [input type button should not support the select() method] - expected: FAIL - [input type text should support all selection attributes and methods] expected: FAIL @@ -132,27 +66,3 @@ [input type button should not support variable-length selections] expected: FAIL - [input type hidden should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type range should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type checkbox should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type radio should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type submit should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type image should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type reset should do nothing when the select() method is called (but, not throw)] - expected: FAIL - - [input type button should do nothing when the select() method is called (but, not throw)] - expected: FAIL -