Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #19272 - jonleighton:issue-19171-2, r=jdm
Further changes in relation to #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/19272) <!-- Reviewable:end -->
- Loading branch information
Showing
7 changed files
with
150 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use dom::bindings::cell::DomRefCell; | ||
use dom::bindings::conversions::DerivedFrom; | ||
use dom::bindings::str::DOMString; | ||
use dom::event::{EventBubbles, EventCancelable}; | ||
use dom::eventtarget::EventTarget; | ||
use dom::node::{Node, NodeDamage, window_from_node}; | ||
use script_traits::ScriptToConstellationChan; | ||
use textinput::{SelectionDirection, TextInput}; | ||
|
||
pub trait TextControl: DerivedFrom<EventTarget> + DerivedFrom<Node> { | ||
fn textinput(&self) -> &DomRefCell<TextInput<ScriptToConstellationChan>>; | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart | ||
fn dom_selection_start(&self) -> u32 { | ||
self.textinput().borrow().get_selection_start() | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart | ||
fn set_dom_selection_start(&self, start: u32) { | ||
self.set_selection_range(start, self.dom_selection_end(), self.selection_direction()); | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend | ||
fn dom_selection_end(&self) -> u32 { | ||
self.textinput().borrow().get_absolute_insertion_point() as u32 | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionend | ||
fn set_dom_selection_end(&self, end: u32) { | ||
self.set_selection_range(self.dom_selection_start(), end, self.selection_direction()); | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectiondirection | ||
fn dom_selection_direction(&self) -> DOMString { | ||
DOMString::from(self.selection_direction()) | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectiondirection | ||
fn set_dom_selection_direction(&self, direction: DOMString) { | ||
self.textinput().borrow_mut().selection_direction = SelectionDirection::from(direction); | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-setselectionrange | ||
fn set_dom_selection_range(&self, start: u32, end: u32, direction: Option<DOMString>) { | ||
// Step 4 | ||
let direction = direction.map_or(SelectionDirection::None, |d| SelectionDirection::from(d)); | ||
|
||
self.set_selection_range(start, end, direction); | ||
} | ||
|
||
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::<EventTarget>(), | ||
atom!("select"), | ||
EventBubbles::Bubbles, | ||
EventCancelable::NotCancelable, | ||
&window); | ||
|
||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 23 additions & 5 deletions
28
tests/wpt/metadata/html/semantics/forms/textfieldselection/selection-start-end.html.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
[selection-start-end.html] | ||
type: testharness | ||
[onselect should fire when selectionStart is changed] | ||
[Setting selectionStart to a value larger than selectionEnd should increase selectionEnd] | ||
expected: FAIL | ||
|
||
[onselect should fire when selectionEnd is changed] | ||
[Setting selectionEnd to a value smaller than selectionStart should decrease selectionStart] | ||
expected: FAIL | ||
|
||
[Setting selectionStart to a value larger than selectionEnd should increase selectionEnd] | ||
[selectionStart edge-case values] | ||
expected: FAIL | ||
|
||
[Setting selectionEnd to a value smaller than selectionStart should decrease selectionStart] | ||
[Initial .value set on textarea-appended should set selectionStart to end of value] | ||
expected: FAIL | ||
|
||
[selectionStart edge-case values] | ||
[Initial .value set on textarea-not-appended should set selectionStart to end of value] | ||
expected: FAIL | ||
|
||
[Initial .value set on textarea-appended-prefocused should set selectionStart to end of value] | ||
expected: FAIL | ||
|
||
[Initial .value set on textarea-not-appended-prefocused should set selectionStart to end of value] | ||
expected: FAIL | ||
|
||
[Initial .value set on textarea-appended should set selectionEnd to end of value] | ||
expected: FAIL | ||
|
||
[Initial .value set on textarea-not-appended should set selectionEnd to end of value] | ||
expected: FAIL | ||
|
||
[Initial .value set on textarea-appended-prefocused should set selectionEnd to end of value] | ||
expected: FAIL | ||
|
||
[Initial .value set on textarea-not-appended-prefocused should set selectionEnd to end of value] | ||
expected: FAIL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters