Skip to content

Commit

Permalink
servo: Merge #19202 - Fire 'select' event in SetSelection{Start,End} …
Browse files Browse the repository at this point in the history
…(from jonleighton:issue-19171); r=KiChjang

See #19171.

Source-Repo: https://github.com/servo/servo
Source-Revision: 2efbf2230a61a2fda1ecc4cd12618177d4ca50cd
  • Loading branch information
jonleighton committed Nov 15, 2017
1 parent 1203644 commit 60940a2
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions servo/components/script/dom/htmlinputelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Node>().dirty(NodeDamage::OtherNodeDamage);
self.set_selection_range(start, self.SelectionEnd(), self.selection_direction());
}

// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend
Expand All @@ -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::<Node>().dirty(NodeDamage::OtherNodeDamage);
self.set_selection_range(self.SelectionStart(), end, self.selection_direction());
}

// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectiondirection
Expand All @@ -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<DOMString>) {
// 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::<Node>().dirty(NodeDamage::OtherNodeDamage);

self.set_selection_range(start, end, direction);
}

// Select the files based on filepaths passed in,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 60940a2

Please sign in to comment.