aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmltextareaelement.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-01-26 13:58:01 -0600
committerGitHub <noreply@github.com>2018-01-26 13:58:01 -0600
commitc2dfece49f1d59f51a3207cd3d88c282ee1adf70 (patch)
tree824bc776762e450e937595676dba99040875822b /components/script/dom/htmltextareaelement.rs
parentce17959f7c5f817bc5739c6693c93cafb1855f4f (diff)
parenta8b64aca2a9c5e6e3756145afc0dedb606947ef8 (diff)
downloadservo-c2dfece49f1d59f51a3207cd3d88c282ee1adf70.tar.gz
servo-c2dfece49f1d59f51a3207cd3d88c282ee1adf70.zip
Auto merge of #19544 - jonleighton:issue-19171-5, r=nox
Text selection API conformance This is my next batch of changes for issue #19171. All the tests in tests/wpt/metadata/html/semantics/forms/textfieldselection/ are now passing (and also some tests outside of there). I've made detailed notes about the changes in each commit message. r? @KiChjang <!-- 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/19544) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rwxr-xr-xcomponents/script/dom/htmltextareaelement.rs51
1 files changed, 39 insertions, 12 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index af69e227d60..bdb0020c616 100755
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -5,6 +5,7 @@
use dom::attr::Attr;
use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
+use dom::bindings::codegen::Bindings::HTMLFormElementBinding::SelectionMode;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
@@ -35,7 +36,7 @@ use std::default::Default;
use std::ops::Range;
use style::attr::AttrValue;
use style::element_state::ElementState;
-use textinput::{Direction, KeyReaction, Lines, Selection, SelectionDirection, TextInput};
+use textinput::{Direction, KeyReaction, Lines, SelectionDirection, TextInput};
#[dom_struct]
pub struct HTMLTextAreaElement {
@@ -44,7 +45,7 @@ pub struct HTMLTextAreaElement {
textinput: DomRefCell<TextInput<ScriptToConstellationChan>>,
placeholder: DomRefCell<DOMString>,
// https://html.spec.whatwg.org/multipage/#concept-textarea-dirty
- value_changed: Cell<bool>,
+ value_dirty: Cell<bool>,
form_owner: MutNullableDom<HTMLFormElement>,
}
@@ -81,7 +82,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom<HTMLTextAreaElement> {
return None;
}
let textinput = (*self.unsafe_get()).textinput.borrow_for_layout();
- Some(textinput.get_absolute_selection_range())
+ Some(textinput.sorted_selection_offsets_range())
}
#[allow(unsafe_code)]
@@ -122,7 +123,7 @@ impl HTMLTextAreaElement {
placeholder: DomRefCell::new(DOMString::new()),
textinput: DomRefCell::new(TextInput::new(
Lines::Multiple, DOMString::new(), chan, None, None, SelectionDirection::None)),
- value_changed: Cell::new(false),
+ value_dirty: Cell::new(false),
form_owner: Default::default(),
}
}
@@ -152,6 +153,14 @@ impl TextControl for HTMLTextAreaElement {
fn selection_api_applies(&self) -> bool {
true
}
+
+ fn has_selectable_text(&self) -> bool {
+ true
+ }
+
+ fn set_dirty_value_flag(&self, value: bool) {
+ self.value_dirty.set(value)
+ }
}
impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
@@ -227,7 +236,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// if the element's dirty value flag is false, then the element's
// raw value must be set to the value of the element's textContent IDL attribute
- if !self.value_changed.get() {
+ if !self.value_dirty.get() {
self.reset();
}
}
@@ -243,19 +252,19 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// Step 1
let old_value = textinput.get_content();
- let old_selection = textinput.selection_begin;
+ let old_selection = textinput.selection_origin;
// Step 2
textinput.set_content(value);
// Step 3
- self.value_changed.set(true);
+ self.value_dirty.set(true);
if old_value != textinput.get_content() {
// Step 4
- textinput.adjust_horizontal_to_limit(Direction::Forward, Selection::NotSelected);
+ textinput.clear_selection_to_limit(Direction::Forward);
} else {
- textinput.selection_begin = old_selection;
+ textinput.selection_origin = old_selection;
}
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
@@ -266,6 +275,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()
@@ -300,6 +314,19 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
fn SetSelectionRange(&self, start: u32, end: u32, direction: Option<DOMString>) -> ErrorResult {
self.set_dom_selection_range(start, end, direction)
}
+
+ // https://html.spec.whatwg.org/multipage/#dom-textarea/input-setrangetext
+ fn SetRangeText(&self, replacement: DOMString) -> ErrorResult {
+ // defined in TextControl trait
+ self.set_dom_range_text(replacement, None, None, Default::default())
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-textarea/input-setrangetext
+ fn SetRangeText_(&self, replacement: DOMString, start: u32, end: u32,
+ selection_mode: SelectionMode) -> ErrorResult {
+ // defined in TextControl trait
+ self.set_dom_range_text(replacement, Some(start), Some(end), selection_mode)
+ }
}
@@ -307,7 +334,7 @@ impl HTMLTextAreaElement {
pub fn reset(&self) {
// https://html.spec.whatwg.org/multipage/#the-textarea-element:concept-form-reset-control
self.SetValue(self.DefaultValue());
- self.value_changed.set(false);
+ self.value_dirty.set(false);
}
}
@@ -400,7 +427,7 @@ impl VirtualMethods for HTMLTextAreaElement {
if let Some(ref s) = self.super_type() {
s.children_changed(mutation);
}
- if !self.value_changed.get() {
+ if !self.value_dirty.get() {
self.reset();
}
}
@@ -423,7 +450,7 @@ impl VirtualMethods for HTMLTextAreaElement {
match action {
KeyReaction::TriggerDefaultAction => (),
KeyReaction::DispatchInput => {
- self.value_changed.set(true);
+ self.value_dirty.set(true);
self.update_placeholder_shown_state();
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.mark_as_handled();