mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Correct default selectionStart and selectionEnd
This commit is contained in:
parent
b517410a34
commit
87e7b1ee7a
7 changed files with 58 additions and 26 deletions
|
@ -550,18 +550,24 @@ impl HTMLInputElementMethods for HTMLInputElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-input-value
|
||||
fn SetValue(&self, value: DOMString) -> ErrorResult {
|
||||
fn SetValue(&self, mut value: DOMString) -> ErrorResult {
|
||||
match self.value_mode() {
|
||||
ValueMode::Value => {
|
||||
// Steps 1-2.
|
||||
let old_value = mem::replace(self.textinput.borrow_mut().single_line_content_mut(), value);
|
||||
// Step 3.
|
||||
self.value_dirty.set(true);
|
||||
|
||||
// Step 4.
|
||||
self.sanitize_value();
|
||||
self.sanitize_value(&mut value);
|
||||
|
||||
let mut textinput = self.textinput.borrow_mut();
|
||||
|
||||
// Step 5.
|
||||
if *self.textinput.borrow().single_line_content() != old_value {
|
||||
self.textinput.borrow_mut().clear_selection_to_limit(Direction::Forward);
|
||||
if *textinput.single_line_content() != value {
|
||||
// Steps 1-2
|
||||
textinput.set_content(value);
|
||||
|
||||
// Step 5.
|
||||
textinput.clear_selection_to_limit(Direction::Forward);
|
||||
}
|
||||
}
|
||||
ValueMode::Default |
|
||||
|
@ -935,8 +941,7 @@ impl HTMLInputElement {
|
|||
InputType::Image => (),
|
||||
_ => ()
|
||||
}
|
||||
self.SetValue(self.DefaultValue())
|
||||
.expect("Failed to reset input value to default.");
|
||||
self.textinput.borrow_mut().set_content(self.DefaultValue());
|
||||
self.value_dirty.set(false);
|
||||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||
}
|
||||
|
@ -1093,7 +1098,6 @@ impl VirtualMethods for HTMLInputElement {
|
|||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||
|
||||
match attr.local_name() {
|
||||
&local_name!("disabled") => {
|
||||
let disabled_state = match mutation {
|
||||
|
@ -1194,11 +1198,11 @@ impl VirtualMethods for HTMLInputElement {
|
|||
let mut textinput = self.textinput.borrow_mut();
|
||||
let mut value = textinput.single_line_content().clone();
|
||||
self.sanitize_value(&mut value);
|
||||
textinput.set_content(value, true);
|
||||
textinput.set_content(value);
|
||||
|
||||
// Steps 7-9
|
||||
if !previously_selectable && self.selection_api_applies() {
|
||||
self.textinput.borrow_mut().clear_selection_to_limit(Direction::Backward);
|
||||
textinput.clear_selection_to_limit(Direction::Backward);
|
||||
}
|
||||
},
|
||||
AttributeMutation::Removed => {
|
||||
|
@ -1222,9 +1226,7 @@ impl VirtualMethods for HTMLInputElement {
|
|||
let mut value = value.map_or(DOMString::new(), DOMString::from);
|
||||
|
||||
self.sanitize_value(&mut value);
|
||||
|
||||
self.textinput.borrow_mut().set_content(
|
||||
value.map_or(DOMString::new(), DOMString::from));
|
||||
self.textinput.borrow_mut().set_content(value);
|
||||
self.update_placeholder_shown_state();
|
||||
},
|
||||
&local_name!("name") if self.input_type() == InputType::Radio => {
|
||||
|
|
|
@ -248,7 +248,6 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
|||
|
||||
// Step 1
|
||||
let old_value = textinput.get_content();
|
||||
let old_selection = textinput.selection_origin;
|
||||
|
||||
// Step 2
|
||||
textinput.set_content(value);
|
||||
|
@ -259,8 +258,6 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
|||
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);
|
||||
|
@ -327,7 +324,8 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
|||
impl HTMLTextAreaElement {
|
||||
pub fn reset(&self) {
|
||||
// https://html.spec.whatwg.org/multipage/#the-textarea-element:concept-form-reset-control
|
||||
self.SetValue(self.DefaultValue());
|
||||
let mut textinput = self.textinput.borrow_mut();
|
||||
textinput.set_content(self.DefaultValue());
|
||||
self.value_dirty.set(false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue