Auto merge of #19202 - jonleighton:issue-19171, r=KiChjang

Fire 'select' event in SetSelection{Start,End}

See #19171.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19202)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-15 04:08:24 -06:00 committed by GitHub
commit 2efbf2230a
2 changed files with 30 additions and 41 deletions

View file

@ -574,9 +574,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart
fn SetSelectionStart(&self, start: u32) { fn SetSelectionStart(&self, start: u32) {
let selection_end = self.SelectionEnd(); self.set_selection_range(start, self.SelectionEnd(), self.selection_direction());
self.textinput.borrow_mut().set_selection_range(start, selection_end);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
} }
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend // 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 // https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend
fn SetSelectionEnd(&self, end: u32) { fn SetSelectionEnd(&self, end: u32) {
let selection_start = self.SelectionStart(); self.set_selection_range(self.SelectionStart(), end, self.selection_direction());
self.textinput.borrow_mut().set_selection_range(selection_start, end);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
} }
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectiondirection // 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 // https://html.spec.whatwg.org/multipage/#dom-textarea/input-setselectionrange
fn SetSelectionRange(&self, start: u32, end: u32, direction: Option<DOMString>) { fn SetSelectionRange(&self, start: u32, end: u32, direction: Option<DOMString>) {
// Step 4
let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d)); 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); self.set_selection_range(start, end, direction);
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::<Node>().dirty(NodeDamage::OtherNodeDamage);
} }
// Select the files based on filepaths passed in, // 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::<Node>().dirty(NodeDamage::OtherNodeDamage);
}
} }
impl VirtualMethods for HTMLInputElement { impl VirtualMethods for HTMLInputElement {

View file

@ -1,6 +1,6 @@
[selection-start-end.html] [selection-start-end.html]
type: testharness type: testharness
expected: TIMEOUT
[onselect should fire when selectionStart is changed] [onselect should fire when selectionStart is changed]
expected: FAIL expected: FAIL
@ -16,27 +16,3 @@
[selectionStart edge-case values] [selectionStart edge-case values]
expected: FAIL 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