Bug 1556364 - Part 4: Support updating valid/invalid state on form-associated custom elements; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D130128
This commit is contained in:
Edgar Chen 2021-11-26 11:47:40 +00:00
parent 24c777bdf0
commit 87d6eccbbd
4 changed files with 16 additions and 4 deletions

View File

@ -167,6 +167,7 @@ void ElementInternals::SetValidity(
SetValidityState(VALIDITY_STATE_STEP_MISMATCH, aFlags.mStepMismatch);
SetValidityState(VALIDITY_STATE_BAD_INPUT, aFlags.mBadInput);
SetValidityState(VALIDITY_STATE_CUSTOM_ERROR, aFlags.mCustomError);
mTarget->UpdateState(true);
/**
* 5. Set element's validation message to the empty string if message is not

View File

@ -198,6 +198,20 @@ nsresult HTMLElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
}
EventStates HTMLElement::IntrinsicState() const {
EventStates state = nsGenericHTMLFormElement::IntrinsicState();
if (ElementInternals* internals = GetElementInternals()) {
if (internals->IsCandidateForConstraintValidation()) {
if (internals->IsValid()) {
state |= NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID;
} else {
state |= NS_EVENT_STATE_INVALID | NS_EVENT_STATE_MOZ_UI_INVALID;
}
}
}
return state;
}
void HTMLElement::SetFormInternal(HTMLFormElement* aForm, bool aBindToTree) {
ElementInternals* internals = GetElementInternals();
MOZ_ASSERT(internals);

View File

@ -55,6 +55,7 @@ class HTMLElement final : public nsGenericHTMLFormElement {
const nsAttrValue* aValue, const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
EventStates IntrinsicState() const override;
// nsGenericHTMLFormElement
void SetFormInternal(HTMLFormElement* aForm, bool aBindToTree) override;

View File

@ -10,7 +10,3 @@
["anchor" argument of setValidity()]
expected: FAIL
[Custom control affects :valid :invalid for FORM and FIELDSET]
expected: FAIL