aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmltextareaelement.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rwxr-xr-xcomponents/script/dom/htmltextareaelement.rs52
1 files changed, 25 insertions, 27 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index a6899b05a06..58e017de93a 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(false);
+ self.reset();
}
}
@@ -244,7 +244,26 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// https://html.spec.whatwg.org/multipage/#dom-textarea-value
fn SetValue(&self, value: DOMString) {
- self.update_text_contents(value, true);
+ 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);
}
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
@@ -306,9 +325,9 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
impl HTMLTextAreaElement {
- pub fn reset(&self, update_text_cursor: bool) {
+ pub fn reset(&self) {
// https://html.spec.whatwg.org/multipage/#the-textarea-element:concept-form-reset-control
- self.update_text_contents(self.DefaultValue(), update_text_cursor);
+ self.SetValue(self.DefaultValue());
self.value_dirty.set(false);
}
@@ -316,27 +335,6 @@ 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();
-
- // 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);
- }
-
- self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
- }
}
@@ -429,7 +427,7 @@ impl VirtualMethods for HTMLTextAreaElement {
s.children_changed(mutation);
}
if !self.value_dirty.get() {
- self.reset(false);
+ self.reset();
}
}
@@ -480,7 +478,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(false);
+ self.reset();
}
}