Skip to content

Commit

Permalink
Support the select() method on input/textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Jan 26, 2018
1 parent c9ba16f commit 0148e97
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 232 deletions.
30 changes: 30 additions & 0 deletions components/script/dom/htmlinputelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<u32> {
self.get_dom_selection_start()
Expand Down
9 changes: 9 additions & 0 deletions components/script/dom/htmltextareaelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -266,6 +270,11 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
self.upcast::<HTMLElement>().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<u32> {
self.get_dom_selection_start()
Expand Down
12 changes: 12 additions & 0 deletions components/script/dom/textcontrol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ use textinput::{SelectionDirection, TextInput};
pub trait TextControl: DerivedFrom<EventTarget> + DerivedFrom<Node> {
fn textinput(&self) -> &DomRefCell<TextInput<ScriptToConstellationChan>>;
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<u32> {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLInputElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface HTMLInputElement : HTMLElement {

readonly attribute NodeList labels;

//void select();
void select();
[SetterThrows]
attribute unsigned long? selectionStart;
[SetterThrows]
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLTextAreaElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface HTMLTextAreaElement : HTMLElement {

readonly attribute NodeList labels;

// void select();
void select();
[SetterThrows]
attribute unsigned long? selectionStart;
[SetterThrows]
Expand Down
78 changes: 0 additions & 78 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3090,9 +3090,6 @@
[HTMLInputElement interface: operation setCustomValidity(DOMString)]
expected: FAIL

[HTMLInputElement interface: operation select()]
expected: FAIL

[HTMLInputElement interface: operation setRangeText(DOMString)]
expected: FAIL

Expand Down Expand Up @@ -3342,9 +3339,6 @@
[HTMLTextAreaElement interface: operation setCustomValidity(DOMString)]
expected: FAIL

[HTMLTextAreaElement interface: operation select()]
expected: FAIL

[HTMLTextAreaElement interface: operation setRangeText(DOMString)]
expected: FAIL

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 0148e97

Please sign in to comment.