Bug 1693969 - Remove <form novalidate> handling from :-moz-ui-{valid,invalid} pseudo-classes. r=smaug

There's no way to know whether the submission will actually be
validated, because formnovalidate on submit buttons is a thing (and even
if all the submit controls had formnovalidate, you could still submit
the form and validate it via form.submit()), so it seems better to make
these pseudo-classes not depend on this.

Differential Revision: https://phabricator.services.mozilla.com/D105968
This commit is contained in:
Emilio Cobos Álvarez 2021-02-23 11:26:17 +00:00
parent 31039e0258
commit b0bc0f75a5
26 changed files with 22 additions and 180 deletions

View File

@ -413,15 +413,9 @@ EventStates HTMLButtonElement::IntrinsicState() const {
if (IsCandidateForConstraintValidation()) {
if (IsValid()) {
state |= NS_EVENT_STATE_VALID;
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
state |= NS_EVENT_STATE_MOZ_UI_VALID;
}
state |= NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID;
} else {
state |= NS_EVENT_STATE_INVALID;
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
}
state |= NS_EVENT_STATE_INVALID | NS_EVENT_STATE_MOZ_UI_INVALID;
}
}

View File

@ -185,29 +185,6 @@ nsresult HTMLFormElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
aNotify);
}
nsresult HTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) {
if (aName == nsGkAtoms::novalidate && aNameSpaceID == kNameSpaceID_None) {
// Update all form elements states because they might be [no longer]
// affected by :-moz-ui-valid or :-moz-ui-invalid.
for (uint32_t i = 0, length = mControls->mElements.Length(); i < length;
++i) {
mControls->mElements[i]->UpdateState(true);
}
for (uint32_t i = 0, length = mControls->mNotInElements.Length();
i < length; ++i) {
mControls->mNotInElements[i]->UpdateState(true);
}
}
return nsGenericHTMLElement::AfterSetAttr(
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
}
void HTMLFormElement::GetAutocomplete(nsAString& aValue) {
GetEnumAttr(nsGkAtoms::autocomplete, kFormDefaultAutocomplete->tag, aValue);
}

View File

@ -96,11 +96,6 @@ class HTMLFormElement final : public nsGenericHTMLElement,
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify) override;
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
/**
* Forget all information about the current submission (and the fact that we

View File

@ -5923,10 +5923,8 @@ EventStates HTMLInputElement::IntrinsicState() const {
} else {
state |= NS_EVENT_STATE_INVALID;
if ((!mForm ||
!mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
(GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
(mCanShowInvalidUI && ShouldShowValidityUI()))) {
if (GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
(mCanShowInvalidUI && ShouldShowValidityUI())) {
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
}
}
@ -5936,14 +5934,11 @@ EventStates HTMLInputElement::IntrinsicState() const {
// :-moz-ui-invalid applying before it was focused ;
// 2. The element is either valid or isn't allowed to have
// :-moz-ui-invalid applying ;
// 3. The element has no form owner or its form owner doesn't have the
// novalidate attribute set ;
// 4. The element has already been modified or the user tried to submit the
// 3. The element has already been modified or the user tried to submit the
// form owner while invalid.
if ((!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
(mCanShowValidUI && ShouldShowValidityUI() &&
(IsValid() || (!state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) &&
!mCanShowInvalidUI)))) {
if (mCanShowValidUI && ShouldShowValidityUI() &&
(IsValid() || (!state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) &&
!mCanShowInvalidUI))) {
state |= NS_EVENT_STATE_MOZ_UI_VALID;
}

View File

@ -85,15 +85,9 @@ EventStates HTMLOutputElement::IntrinsicState() const {
// We don't have to call IsCandidateForConstraintValidation()
// because <output> can't be barred from constraint validation.
if (IsValid()) {
states |= NS_EVENT_STATE_VALID;
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
states |= NS_EVENT_STATE_MOZ_UI_VALID;
}
states |= NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID;
} else {
states |= NS_EVENT_STATE_INVALID;
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
states |= NS_EVENT_STATE_MOZ_UI_INVALID;
}
states |= NS_EVENT_STATE_INVALID | NS_EVENT_STATE_MOZ_UI_INVALID;
}
return states;

View File

@ -1229,10 +1229,8 @@ EventStates HTMLSelectElement::IntrinsicState() const {
} else {
state |= NS_EVENT_STATE_INVALID;
if ((!mForm ||
!mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
(GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
(mCanShowInvalidUI && ShouldShowValidityUI()))) {
if (GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
(mCanShowInvalidUI && ShouldShowValidityUI())) {
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
}
}
@ -1242,14 +1240,11 @@ EventStates HTMLSelectElement::IntrinsicState() const {
// :-moz-ui-invalid applying before it was focused ;
// 2. The element is either valid or isn't allowed to have
// :-moz-ui-invalid applying ;
// 3. The element has no form owner or its form owner doesn't have the
// novalidate attribute set ;
// 4. The element has already been modified or the user tried to submit the
// 3. The element has already been modified or the user tried to submit the
// form owner while invalid.
if ((!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
(mCanShowValidUI && ShouldShowValidityUI() &&
if (mCanShowValidUI && ShouldShowValidityUI() &&
(IsValid() || (state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) &&
!mCanShowInvalidUI)))) {
!mCanShowInvalidUI))) {
state |= NS_EVENT_STATE_MOZ_UI_VALID;
}
}

View File

@ -774,11 +774,9 @@ EventStates HTMLTextAreaElement::IntrinsicState() const {
} else {
state |= NS_EVENT_STATE_INVALID;
// :-moz-ui-invalid always apply if the element suffers from a custom
// error and never applies if novalidate is set on the form owner.
if ((!mForm ||
!mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
(GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
(mCanShowInvalidUI && ShouldShowValidityUI()))) {
// error.
if (GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
(mCanShowInvalidUI && ShouldShowValidityUI())) {
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
}
}
@ -788,14 +786,11 @@ EventStates HTMLTextAreaElement::IntrinsicState() const {
// :-moz-ui-invalid applying before it was focused ;
// 2. The element is either valid or isn't allowed to have
// :-moz-ui-invalid applying ;
// 3. The element has no form owner or its form owner doesn't have the
// novalidate attribute set ;
// 4. The element has already been modified or the user tried to submit the
// 3. The element has already been modified or the user tried to submit the
// form owner while invalid.
if ((!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
(mCanShowValidUI && ShouldShowValidityUI() &&
(IsValid() || (state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) &&
!mCanShowInvalidUI)))) {
if (mCanShowValidUI && ShouldShowValidityUI() &&
(IsValid() || (state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) &&
!mCanShowInvalidUI))) {
state |= NS_EVENT_STATE_MOZ_UI_VALID;
}
}

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html class='reftest-wait'>
<link rel='stylesheet' type='text/css' href='style.css'>
<body onload="document.getElementById('b').setCustomValidity('foo');
document.documentElement.className = '';">
<form novalidate>
<button id='b' class='notinvalid'></button>
</form>
</body>
</html>

View File

@ -10,4 +10,3 @@ fuzzy-if(skiaContent,0-1,0-3) == button-type-barred.html button-ref.html
fuzzy-if(skiaContent,0-1,0-3) == button-disabled-fieldset-1.html button-fieldset-ref.html
fuzzy-if(skiaContent,0-1,0-3) == button-disabled-fieldset-2.html button-fieldset-ref.html
fuzzy-if(skiaContent,0-1,0-4) == button-fieldset-legend.html button-fieldset-legend-ref.html
fuzzy-if(skiaContent,0-1,0-3) == button-novalidate.html button-ref.html

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html class="reftest-wait">
<!-- When the form has @novalidate, :-moz-ui-invalid doesn't apply. -->
<link rel='stylesheet' type='text/css' href='style.css'>
<body onload="document.getElementById('i').value = '';
document.documentElement.className = '';">
<form novalidate>
<input id='i' class='notinvalid' required>
</form>
</body>
</html>

View File

@ -38,5 +38,4 @@ fuzzy-if(skiaContent,0-1,0-3) == input-fieldset-legend.html input-fieldset-legen
== input-radio-dyn-valid-2.html success-ref.html
== input-radio-nogroup-required-valid.html success-ref.html
== input-radio-nogroup-required-invalid.html success-ref.html
fuzzy-if(skiaContent,0-1,0-3) == input-novalidate.html input-ref.html
# input type='hidden' shouldn't show

View File

@ -1,3 +1,2 @@
== output-valid.html output-ref.html
== output-invalid.html output-ref.html
== output-novalidate.html output-ref.html

View File

@ -15,4 +15,3 @@ needs-focus == select-required-multiple-valid.html select-required-multiple-ref.
fuzzy-if(skiaContent&&!Android,0-2,0-10) fuzzy-if(Android,0-9,0-1) needs-focus == select-disabled-fieldset-1.html select-fieldset-ref.html
fuzzy-if(skiaContent&&!Android,0-2,0-10) fuzzy-if(Android,0-9,0-1) needs-focus == select-disabled-fieldset-2.html select-fieldset-ref.html
fuzzy-if(skiaContent,0-2,0-10) needs-focus == select-fieldset-legend.html select-fieldset-legend-ref.html
fuzzy-if(skiaContent,0-1,0-5) needs-focus == select-novalidate.html select-required-ref.html

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<form novalidate>
<select required id='s' class='notinvalid'>
<option selected value="">foo</option>
</select>
</form>
</body>
</html>

View File

@ -12,4 +12,3 @@
== textarea-required-invalid-changed.html textarea-ref.html
== textarea-disabled-fieldset-1.html textarea-fieldset-ref.html
== textarea-disabled-fieldset-2.html textarea-fieldset-ref.html
== textarea-novalidate.html textarea-ref.html

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html class='reftest-wait'>
<link rel='stylesheet' type='text/css' href='style.css'>
<body onload="document.getElementById('t').value = '';
document.documentElement.className = '';">
<form novalidate>
<textarea id='t' required class='notinvalid'></textarea>
</form>
</body>
</html>

View File

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<form novalidate>
<button class='notvalid'></button>
</form>
</body>
</html>

View File

@ -10,4 +10,3 @@ fuzzy-if(skiaContent,0-2,0-3) == button-type-barred.html button-ref.html
== button-disabled-fieldset-1.html button-fieldset-ref.html
fuzzy-if(skiaContent,0-1,0-3) == button-disabled-fieldset-2.html button-fieldset-ref.html
fuzzy-if(skiaContent,0-1,0-3) == button-fieldset-legend.html button-fieldset-legend-ref.html
fuzzy-if(skiaContent,0-2,0-2) == button-novalidate.html button-ref.html

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html class="reftest-wait">
<!-- When the form has @novalidate, :-moz-ui-invalid doesn't apply. -->
<link rel='stylesheet' type='text/css' href='style.css'>
<body onload="document.getElementById('i').value = 'foo';
document.documentElement.className = '';">
<form novalidate>
<input id='i' class='notvalid' required>
</form>
</body>
</html>

View File

@ -37,5 +37,4 @@ fuzzy-if(skiaContent,0-1,0-3) == input-fieldset-legend.html input-fieldset-legen
== input-radio-dyn-valid-2.html success-ref.html
== input-radio-nogroup-required-valid.html success-ref.html
== input-radio-nogroup-required-invalid.html success-ref.html
fuzzy-if(skiaContent,0-1,0-3) == input-novalidate.html input-withtext-ref.html
# input type='hidden' shouldn't show

View File

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<form novalidate>
<output class='notvalid'>foo</output>
</form>
</body>
</html>

View File

@ -1,3 +1,2 @@
== output-valid.html output-ref.html
== output-invalid.html output-ref.html
== output-novalidate.html output-ref.html

View File

@ -15,4 +15,3 @@ fuzzy(0-64,0-4) fuzzy-if(asyncPan&&layersGPUAccelerated,0-84,0-77) fuzzy-if(skia
fuzzy-if(Android,0-9,0-1) needs-focus == select-disabled-fieldset-1.html select-fieldset-ref.html
fuzzy-if(skiaContent&&!Android,0-2,0-10) needs-focus == select-disabled-fieldset-2.html select-fieldset-ref.html
fuzzy-if(skiaContent,0-2,0-10) needs-focus == select-fieldset-legend.html select-fieldset-legend-ref.html
fuzzy-if(skiaContent,0-2,0-5) needs-focus == select-novalidate.html select-required-ref.html

View File

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html class="reftest-wait">
<link rel='stylesheet' type='text/css' href='style.css'>
<body onload="document.getElementById('s').selectedIndex = 0;
document.documentElement.className = '';">
<form novalidate>
<select id='s' class='notvalid'>
<option>foo</option>
</select>
</form>
</body>
</html>

View File

@ -14,4 +14,3 @@
== textarea-disabled-fieldset-1.html textarea-fieldset-ref.html
== textarea-disabled-fieldset-2.html textarea-fieldset-ref.html
== textarea-fieldset-legend.html textarea-fieldset-legend-ref.html
== textarea-novalidate.html textarea-withtext-ref.html

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html class='reftest-wait'>
<link rel='stylesheet' type='text/css' href='style.css'>
<body onload="document.getElementById('t').value = 'foo';
document.documentElement.className = '';">
<form novalidate>
<textarea id='t' required class='notvalid'></textarea>
</form>
</body>
</html>