aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/textinput.rs
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-04-02 08:07:30 -0400
committerGitHub <noreply@github.com>2020-04-02 08:07:30 -0400
commita651bad838e0fc87ea199ff0ec81d53a97bd61dd (patch)
treef3dac563783cfeaa5ca69851c426d7e7b4dff9c3 /components/script/textinput.rs
parente47e884cc738a5cb472416a4fbdd9d2a32a2385c (diff)
parent779552ee7ddbbde1055c7202e16b9a13c3961988 (diff)
downloadservo-a651bad838e0fc87ea199ff0ec81d53a97bd61dd.tar.gz
servo-a651bad838e0fc87ea199ff0ec81d53a97bd61dd.zip
Auto merge of #25447 - teapotd:form-validation, r=jdm
Form constraint validation It's almost done, there are few things remaining: - ~Range underflow, range overflow and step mismatch implementation require #25405~ - ~There are some test failures due to missing DOM parts (#25003)~ - ~`pattern` attribute uses JS regexp syntax. Currently I used regex crate, but it's probably incompatible. Should we use SpiderMonkey's regexp via jsapi?~ - Currently validation errors are reported using `println!`. Are there any better options? - ~["While the user interface is representing input that the user agent cannot convert to punycode, the control is suffering from bad input."](https://html.spec.whatwg.org/multipage/#e-mail-state-(type%3Demail)%3Asuffering-from-bad-input)~ r? @jdm --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #11444 - [x] There are tests for these changes
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r--components/script/textinput.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index bc4c1c4a6cb..623085ccd19 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -184,6 +184,9 @@ pub struct TextInput<T: ClipboardProvider> {
/// <https://html.spec.whatwg.org/multipage/#attr-fe-maxlength>
max_length: Option<UTF16CodeUnits>,
min_length: Option<UTF16CodeUnits>,
+
+ /// Was last change made by set_content?
+ was_last_change_by_set_content: bool,
}
/// Resulting action to be taken by the owner of a text input that is handling an event.
@@ -269,6 +272,7 @@ impl<T: ClipboardProvider> TextInput<T> {
max_length: max_length,
min_length: min_length,
selection_direction: selection_direction,
+ was_last_change_by_set_content: true,
};
i.set_content(initial);
i
@@ -300,6 +304,11 @@ impl<T: ClipboardProvider> TextInput<T> {
self.min_length = length;
}
+ /// Was last edit made by set_content?
+ pub fn was_last_change_by_set_content(&self) -> bool {
+ self.was_last_change_by_set_content
+ }
+
/// Remove a character at the current editing point
pub fn delete_char(&mut self, dir: Direction) {
if self.selection_origin.is_none() || self.selection_origin == Some(self.edit_point) {
@@ -496,6 +505,7 @@ impl<T: ClipboardProvider> TextInput<T> {
};
self.lines = new_lines;
+ self.was_last_change_by_set_content = false;
self.clear_selection();
self.assert_ok_selection();
}
@@ -1035,6 +1045,7 @@ impl<T: ClipboardProvider> TextInput<T> {
vec![content]
};
+ self.was_last_change_by_set_content = true;
self.edit_point = self.edit_point.constrain_to(&self.lines);
if let Some(origin) = self.selection_origin {