From 93b047a91be55577be475ed9d55ba7a368353de5 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 13 Nov 2017 16:17:20 +0100 Subject: [PATCH] Fire 'select' event in SetSelection{Start,End} Issue #19171 --- components/script/dom/htmlinputelement.rs | 45 ++++++++++++------- .../selection-start-end.html.ini | 26 +---------- 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 48a6110f5032..78afb4630db4 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -574,9 +574,7 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart fn SetSelectionStart(&self, start: u32) { - let selection_end = self.SelectionEnd(); - self.textinput.borrow_mut().set_selection_range(start, selection_end); - self.upcast::().dirty(NodeDamage::OtherNodeDamage); + self.set_selection_range(start, self.SelectionEnd(), self.selection_direction()); } // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend @@ -586,9 +584,7 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend fn SetSelectionEnd(&self, end: u32) { - let selection_start = self.SelectionStart(); - self.textinput.borrow_mut().set_selection_range(selection_start, end); - self.upcast::().dirty(NodeDamage::OtherNodeDamage); + self.set_selection_range(self.SelectionStart(), end, self.selection_direction()); } // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectiondirection @@ -603,17 +599,10 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-textarea/input-setselectionrange fn SetSelectionRange(&self, start: u32, end: u32, direction: Option) { + // Step 4 let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d)); - self.textinput.borrow_mut().selection_direction = direction; - self.textinput.borrow_mut().set_selection_range(start, end); - let window = window_from_node(self); - let _ = window.user_interaction_task_source().queue_event( - &self.upcast(), - atom!("select"), - EventBubbles::Bubbles, - EventCancelable::NotCancelable, - &window); - self.upcast::().dirty(NodeDamage::OtherNodeDamage); + + self.set_selection_range(start, end, direction); } // Select the files based on filepaths passed in, @@ -886,6 +875,30 @@ impl HTMLInputElement { _ => () } } + + fn selection_direction(&self) -> SelectionDirection { + self.textinput.borrow().selection_direction + } + + // https://html.spec.whatwg.org/multipage/#set-the-selection-range + fn set_selection_range(&self, start: u32, end: u32, direction: SelectionDirection) { + // Step 5 + self.textinput.borrow_mut().selection_direction = direction; + + // Step 3 + self.textinput.borrow_mut().set_selection_range(start, end); + + // Step 6 + let window = window_from_node(self); + let _ = window.user_interaction_task_source().queue_event( + &self.upcast(), + atom!("select"), + EventBubbles::Bubbles, + EventCancelable::NotCancelable, + &window); + + self.upcast::().dirty(NodeDamage::OtherNodeDamage); + } } impl VirtualMethods for HTMLInputElement { diff --git a/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection-start-end.html.ini b/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection-start-end.html.ini index b7a69269e742..056dd3bb8a18 100644 --- a/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection-start-end.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/textfieldselection/selection-start-end.html.ini @@ -1,6 +1,6 @@ [selection-start-end.html] type: testharness - expected: TIMEOUT + [onselect should fire when selectionStart is changed] expected: FAIL @@ -16,27 +16,3 @@ [selectionStart edge-case values] expected: FAIL - [onselect should fire when selectionStart is changed on input-appended] - expected: NOTRUN - - [onselect should fire when selectionStart is changed on input-not-appended] - expected: NOTRUN - - [onselect should fire when selectionStart is changed on input-appended-prefocused] - expected: NOTRUN - - [onselect should fire when selectionStart is changed on input-not-appended-prefocused] - expected: NOTRUN - - [onselect should fire when selectionEnd is changed on input-appended] - expected: NOTRUN - - [onselect should fire when selectionEnd is changed on input-not-appended] - expected: NOTRUN - - [onselect should fire when selectionEnd is changed on input-appended-prefocused] - expected: NOTRUN - - [onselect should fire when selectionEnd is changed on input-not-appended-prefocused] - expected: NOTRUN -