Implement :valid :invalid pseudo classes#26729
Merged
mrobinson merged 1 commit intoservo:masterfrom Jul 21, 2023
Merged
Conversation
|
Heads up! This PR modifies the following files:
|
Member
|
r? @Manishearth |
Manishearth
approved these changes
Jun 9, 2020
Member
Manishearth
left a comment
There was a problem hiding this comment.
Looks great, minor issue and then r=me
| self.update_validity_state(ValidationFlags::CUSTOM_ERROR); | ||
| } | ||
|
|
||
| pub fn update_validity_state(&self, update_flags: ValidationFlags) { |
Member
There was a problem hiding this comment.
Please document this function
Contributor
|
☔ The latest upstream changes (presumably #26902) made this pull request unmergeable. Please resolve the merge conflicts. |
4 tasks
bors-servo
added a commit
that referenced
this pull request
Jul 2, 2020
Implement HTMLFormElement.requestSubmit() <!-- Please describe your changes on the following line: --> This PR contains an implementation of [HTMLFormElement.requestSubmit()](https://html.spec.whatwg.org/multipage/forms.html#dom-form-requestsubmit) This is literally my first hundred lines of Rust code, so if I crossed a few sacred lines here and there, please go easy on me :) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23417 <!-- Either: --> - [x] [WPT tests](https://github.com/servo/servo/blob/master/tests/wpt/web-platform-tests/html/semantics/forms/the-form-element/form-requestsubmit.html) for these changes There are two tests that still fail because we don't support `:invalid` CSS selector (see #10781). I verified that they pass if you change them to not use `:invalid`. Should be unlocked by #26729. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo
added a commit
that referenced
this pull request
Jul 2, 2020
Implement HTMLFormElement.requestSubmit() <!-- Please describe your changes on the following line: --> This PR contains an implementation of [HTMLFormElement.requestSubmit()](https://html.spec.whatwg.org/multipage/forms.html#dom-form-requestsubmit) This is literally my first hundred lines of Rust code, so if I crossed a few sacred lines here and there, please go easy on me :) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23417 <!-- Either: --> - [x] [WPT tests](https://github.com/servo/servo/blob/master/tests/wpt/web-platform-tests/html/semantics/forms/the-form-element/form-requestsubmit.html) for these changes There are two tests that still fail because we don't support `:invalid` CSS selector (see #10781). I verified that they pass if you change them to not use `:invalid`. Should be unlocked by #26729. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
4 tasks
Member
|
This was basically ready to go, so I've rebased it and done a bit of cleanup, including adding the documentation that was requested above. Here's the diff with the rebased version: Diff from simple rebase:diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index b341b15361..14f5d6abca 100755
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -243,7 +243,7 @@ impl VirtualMethods for HTMLButtonElement {
}
el.update_sequentially_focusable_status();
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
},
&local_name!("type") => match mutation {
AttributeMutation::Set(_) => {
@@ -254,7 +254,7 @@ impl VirtualMethods for HTMLButtonElement {
};
self.button_type.set(value);
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
},
AttributeMutation::Removed => {
self.button_type.set(ButtonType::Submit);
@@ -263,7 +263,7 @@ impl VirtualMethods for HTMLButtonElement {
&local_name!("form") => {
self.form_attribute_mutated(mutation);
self.validity_state()
- .update_validity_state(ValidationFlags::empty());
+ .perform_validation_and_update(ValidationFlags::empty());
},
_ => {},
}
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 78448f8f49..7594026046 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -1059,7 +1059,7 @@ impl HTMLFormElement {
};
validatable
.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
if !validatable.is_instance_validatable() {
None
} else if validatable.validity_state().invalid_flags().is_empty() {
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 1173f050ec..f0e16612c9 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -1297,7 +1297,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
Ok(())
}
@@ -2473,7 +2473,7 @@ impl VirtualMethods for HTMLInputElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
@@ -2502,7 +2502,7 @@ impl VirtualMethods for HTMLInputElement {
.check_ancestors_disabled_state_for_form_control();
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
fn unbind_from_tree(&self, context: &UnbindContext) {
@@ -2520,7 +2520,7 @@ impl VirtualMethods for HTMLInputElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
// This represents behavior for which the UIEvents spec and the
@@ -2622,7 +2622,7 @@ impl VirtualMethods for HTMLInputElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
// https://html.spec.whatwg.org/multipage/#the-input-element%3Aconcept-node-clone-ext
@@ -2644,7 +2644,7 @@ impl VirtualMethods for HTMLInputElement {
.borrow_mut()
.set_content(self.textinput.borrow().get_content());
elem.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
}
diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs
index 13e34beb22..0f737bcd52 100644
--- a/components/script/dom/htmloptgroupelement.rs
+++ b/components/script/dom/htmloptgroupelement.rs
@@ -66,7 +66,7 @@ impl HTMLOptGroupElement {
{
select
.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
}
}
@@ -140,7 +140,7 @@ impl VirtualMethods for HTMLOptGroupElement {
{
select
.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
}
}
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index 94ee83b646..d11b221f0d 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -180,7 +180,7 @@ impl HTMLOptionElement {
{
select
.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
}
}
@@ -356,7 +356,7 @@ impl VirtualMethods for HTMLOptionElement {
{
select
.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
select.ask_for_reset();
}
diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs
index 267c8feeb1..0cfda5bfaa 100755
--- a/components/script/dom/htmlselectelement.rs
+++ b/components/script/dom/htmlselectelement.rs
@@ -349,7 +349,7 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::VALUE_MISSING);
+ .perform_validation_and_update(ValidationFlags::VALUE_MISSING);
}
// https://html.spec.whatwg.org/multipage/#dom-select-selectedindex
@@ -419,7 +419,7 @@ impl VirtualMethods for HTMLSelectElement {
match attr.local_name() {
&local_name!("required") => {
self.validity_state()
- .update_validity_state(ValidationFlags::VALUE_MISSING);
+ .perform_validation_and_update(ValidationFlags::VALUE_MISSING);
},
&local_name!("disabled") => {
let el = self.upcast::<Element>();
@@ -436,7 +436,7 @@ impl VirtualMethods for HTMLSelectElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::VALUE_MISSING);
+ .perform_validation_and_update(ValidationFlags::VALUE_MISSING);
},
&local_name!("form") => {
self.form_attribute_mutated(mutation);
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index e316edd97b..db21db49b1 100755
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -342,7 +342,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}
@@ -539,7 +539,7 @@ impl VirtualMethods for HTMLTextAreaElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
fn bind_to_tree(&self, context: &BindContext) {
@@ -551,7 +551,7 @@ impl VirtualMethods for HTMLTextAreaElement {
.check_ancestors_disabled_state_for_form_control();
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
@@ -586,7 +586,7 @@ impl VirtualMethods for HTMLTextAreaElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
// The cloning steps for textarea elements must propagate the raw value
@@ -607,7 +607,7 @@ impl VirtualMethods for HTMLTextAreaElement {
textinput.set_content(self.textinput.borrow().get_content());
}
el.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
fn children_changed(&self, mutation: &ChildrenMutation) {
@@ -680,7 +680,7 @@ impl VirtualMethods for HTMLTextAreaElement {
}
self.validity_state()
- .update_validity_state(ValidationFlags::all());
+ .perform_validation_and_update(ValidationFlags::all());
}
fn pop(&self) {
diff --git a/components/script/dom/validitystate.rs b/components/script/dom/validitystate.rs
index 732a98c39c..2af3843c20 100755
--- a/components/script/dom/validitystate.rs
+++ b/components/script/dom/validitystate.rs
@@ -96,15 +96,15 @@ impl ValidityState {
// https://html.spec.whatwg.org/multipage/#custom-validity-error-message
pub fn set_custom_error_message(&self, error: DOMString) {
*self.custom_error_message.borrow_mut() = error;
- self.perform_validation(ValidationFlags::CUSTOM_ERROR);
+ self.perform_validation_and_update(ValidationFlags::CUSTOM_ERROR);
}
/// Given a set of [ValidationFlags], recalculate their value by performing
- /// validation on this [ValidityStates]'s associated element. If a [custom
- /// error](https://html.spec.whatwg.org/multipage/#suffering-from-a-custom-error)
- /// is encountered during validation that will be added to this state's set
- /// of flags.
- pub fn perform_validation(&self, update_flags: ValidationFlags) {
+ /// validation on this [ValidityState]'s associated element. Additionally,
+ /// if [ValidationFlags::CUSTOM_ERROR] is in `update_flags` and a custom
+ /// error has been set on this [ValidityState], the state will be updated
+ /// to reflect the existance of a custom error.
+ pub fn perform_validation_and_update(&self, update_flags: ValidationFlags) {
let mut invalid_flags = self.invalid_flags.get();
invalid_flags.remove(update_flags);
@@ -114,10 +114,10 @@ impl ValidityState {
}
// https://html.spec.whatwg.org/multipage/#suffering-from-a-custom-error
- if update_flags.contains(ValidationFlags::CUSTOM_ERROR) {
- if !self.custom_error_message().is_empty() {
- invalid_flags.insert(ValidationFlags::CUSTOM_ERROR);
- }
+ if update_flags.contains(ValidationFlags::CUSTOM_ERROR) &&
+ !self.custom_error_message().is_empty()
+ {
+ invalid_flags.insert(ValidationFlags::CUSTOM_ERROR);
}
self.invalid_flags.set(invalid_flags);
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/constraints/input-pattern-dynamic-value.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/constraints/input-pattern-dynamic-value.html.ini
deleted file mode 100644
index 6d133b8ec6..0000000000
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/constraints/input-pattern-dynamic-value.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[input-pattern-dynamic-value.html]
- [input validation is updated after pattern attribute change]
- expected: FAIL
-
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/constraints/radio-valueMissing.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/constraints/radio-valueMissing.html.ini
new file mode 100644
index 0000000000..056a42422d
--- /dev/null
+++ b/tests/wpt/meta-legacy-layout/html/semantics/forms/constraints/radio-valueMissing.html.ini
@@ -0,0 +1,3 @@
+[radio-valueMissing.html]
+ [One of the radios is required and another one is checked]
+ expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/form-submit-iframe-then-location-navigate.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/form-submit-iframe-then-location-navigate.html.ini
deleted file mode 100644
index 74e9d711ff..0000000000
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/form-submit-iframe-then-location-navigate.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[form-submit-iframe-then-location-navigate.html]
- expected: TIMEOUT
- [Verifies that location navigations take precedence when following form submissions.]
- expected: TIMEOUT
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/text-plain.window.js.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/text-plain.window.js.ini
index 2ed4e05524..b095623783 100644
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/text-plain.window.js.ini
+++ b/tests/wpt/meta-legacy-layout/html/semantics/forms/form-submission-0/text-plain.window.js.ini
@@ -5,9 +5,6 @@
[text/plain: Basic File test (normal form)]
expected: FAIL
- [text/plain: 0x00 in name (normal form)]
- expected: FAIL
-
[text/plain: 0x00 in value (normal form)]
expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html.ini
index a0e9a63e84..9c19e44bb7 100644
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html.ini
+++ b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html.ini
@@ -1,3 +1,6 @@
[fieldset-intrinsic-size.html]
- [min-content content-box]
+ [max-content content-box]
+ expected: FAIL
+
+ [max-content border-box]
expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-form-element/form-requestsubmit.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-form-element/form-requestsubmit.html.ini
deleted file mode 100644
index 4f05392b2e..0000000000
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-form-element/form-requestsubmit.html.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[form-requestsubmit.html]
- [The value of the submitter should be appended, and form* attributes of the submitter should be handled.]
- expected: FAIL
-
- [requestSubmit() should trigger interactive form validation]
- expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/pattern_attribute.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/pattern_attribute.html.ini
index 23bcf08fd4..55a105a7c6 100644
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/pattern_attribute.html.ini
+++ b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/pattern_attribute.html.ini
@@ -2,18 +2,6 @@
[pattern attribute support on input element]
expected: FAIL
- [basic <input pattern> support]
- expected: FAIL
-
- [<input pattern> is Unicode code point-aware]
- expected: FAIL
-
- [<input pattern> supports Unicode property escape syntax]
- expected: FAIL
-
- [<input pattern> supports Unicode property escape syntax for properties of strings]
- expected: FAIL
-
[<input pattern> supports set difference syntax]
expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/radio.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/radio.html.ini
new file mode 100644
index 0000000000..e6320078ac
--- /dev/null
+++ b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-input-element/radio.html.ini
@@ -0,0 +1,3 @@
+[radio.html]
+ [Radio buttons in an orphan tree should make a group]
+ expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-output-element/output-validity.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-output-element/output-validity.html.ini
deleted file mode 100644
index 28d4f01369..0000000000
--- a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-output-element/output-validity.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[output-validity.html]
- [:valid and :invalid pseudo-class on output element]
- expected: FAIL
diff --git a/tests/wpt/meta-legacy-layout/html/semantics/forms/the-select-element/select-validity.html.ini b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-select-element/select-validity.html.ini
new file mode 100644
index 0000000000..348da577e8
--- /dev/null
+++ b/tests/wpt/meta-legacy-layout/html/semantics/forms/the-select-element/select-validity.html.ini
@@ -0,0 +1,3 @@
+[select-validity.html]
+ [Remove and add back the placeholder label option]
+ expected: FAIL |
Member
|
@bors-servo try=wpt |
Contributor
bors-servo
added a commit
that referenced
this pull request
Jul 21, 2023
Implement :valid :invalid pseudo classes <!-- Please describe your changes on the following line: --> This pull request implements :valid :invalid pseudo classes. Radio button support is currently missing due to concerns about performance. I am willing to discuss how to implement it efficiently. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #10781 - [X] There are tests for these changes
|
Test results for linux-wpt-layout-2013 from try job (#5620735309): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (21)
Stable unexpected results (3)
|
Signed-off-by: Martin Robinson <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request implements :valid :invalid pseudo classes. Radio button support is currently missing due to concerns about performance. I am willing to discuss how to implement it efficiently.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errors