aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmltextareaelement.rs
diff options
context:
space:
mode:
authorpaavininanda <paavininanda@gmail.com>2018-02-06 22:33:12 +0530
committerpaavininanda <paavininanda@gmail.com>2018-02-10 17:46:29 +0530
commitb2c1f89b932a72f9e0110c17adde33647e84c902 (patch)
treee07e3491fd5f53d68814ea409a679b656fde00c3 /components/script/dom/htmltextareaelement.rs
parente19bab84cf43c43930d7493840444a8ee2af1e8b (diff)
downloadservo-b2c1f89b932a72f9e0110c17adde33647e84c902.tar.gz
servo-b2c1f89b932a72f9e0110c17adde33647e84c902.zip
Correct default Selectionstart and SelectionEnd
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rwxr-xr-xcomponents/script/dom/htmltextareaelement.rs55
1 files changed, 30 insertions, 25 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 58e017de93a..a5038918517 100755
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -233,7 +233,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_dirty.get() {
- self.reset();
+ self.reset(false);
}
}
@@ -244,26 +244,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// https://html.spec.whatwg.org/multipage/#dom-textarea-value
fn SetValue(&self, value: DOMString) {
- let mut textinput = self.textinput.borrow_mut();
-
- // Step 1
- let old_value = textinput.get_content();
- let old_selection = textinput.selection_origin;
-
- // Step 2
- textinput.set_content(value);
-
- // Step 3
- self.value_dirty.set(true);
-
- if old_value != textinput.get_content() {
- // Step 4
- textinput.clear_selection_to_limit(Direction::Forward);
- } else {
- textinput.selection_origin = old_selection;
- }
-
- self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
+ self.update_text_contents(value, true);
}
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
@@ -325,9 +306,9 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
impl HTMLTextAreaElement {
- pub fn reset(&self) {
+ pub fn reset(&self, update_text_cursor: bool) {
// https://html.spec.whatwg.org/multipage/#the-textarea-element:concept-form-reset-control
- self.SetValue(self.DefaultValue());
+ self.update_text_contents(self.DefaultValue(), update_text_cursor);
self.value_dirty.set(false);
}
@@ -335,6 +316,30 @@ impl HTMLTextAreaElement {
fn selection(&self) -> TextControlSelection<Self> {
TextControlSelection::new(&self, &self.textinput)
}
+
+ // Helper function to check if text_cursor is to be updated or not
+ fn update_text_contents(&self, value: DOMString, update_text_cursor: bool) {
+ let mut textinput = self.textinput.borrow_mut();
+
+ // Step 1
+ let old_value = textinput.get_content();
+ let old_selection = textinput.selection_origin;
+
+ // Step 2
+ textinput.set_content(value, update_text_cursor);
+
+ // Step 3
+ self.value_dirty.set(true);
+
+ if old_value != textinput.get_content() {
+ // Step 4
+ textinput.clear_selection_to_limit(Direction::Forward, update_text_cursor);
+ } else {
+ textinput.selection_origin = old_selection;
+ }
+
+ self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
+ }
}
@@ -427,7 +432,7 @@ impl VirtualMethods for HTMLTextAreaElement {
s.children_changed(mutation);
}
if !self.value_dirty.get() {
- self.reset();
+ self.reset(false);
}
}
@@ -478,7 +483,7 @@ impl VirtualMethods for HTMLTextAreaElement {
self.super_type().unwrap().pop();
// https://html.spec.whatwg.org/multipage/#the-textarea-element:stack-of-open-elements
- self.reset();
+ self.reset(false);
}
}