Bug 1385478 - Part 2: Change Required/IsRequired() to look at NS_EVENT_STATE_REQUIRED instead. r=bz
In order to speed up Required/IsRequired(), instead of querying for the @required attribute, we're now using the NS_EVENT_STATE_REQUIRED flag to know whether an element's value is required. For this to work correctly, we need to set NS_EVENT_STATE_REQUIRED earlier, that is, in AfterSetAttr(), before any consumer of IsRequired(). We also need to update or clear our required states when input type changes, since we may have changed from a required input type to a non-required input type or vice versa. Note that NS_EVENT_STATE_REQUIRED/OPTIONAL is now part of the EXTERNALLY_MANAGED_STATES. MozReview-Commit-ID: Bjiby9GqJSB
This commit is contained in:
@@ -1453,6 +1453,13 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
UpdateDisabledState(aNotify);
|
||||
}
|
||||
|
||||
if (aName == nsGkAtoms::required && DoesRequiredApply()) {
|
||||
// This *has* to be called *before* UpdateValueMissingValidityState
|
||||
// because UpdateValueMissingValidityState depends on our required
|
||||
// state.
|
||||
UpdateRequiredState(!!aValue, aNotify);
|
||||
}
|
||||
|
||||
UpdateValueMissingValidityState();
|
||||
|
||||
// This *has* to be called *after* validity has changed.
|
||||
@@ -5005,6 +5012,17 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify)
|
||||
mFocusedValue.Truncate();
|
||||
}
|
||||
|
||||
// Update or clear our required states since we may have changed from a
|
||||
// required input type to a non-required input type or viceversa.
|
||||
if (DoesRequiredApply()) {
|
||||
bool isRequired = HasAttr(kNameSpaceID_None, nsGkAtoms::required);
|
||||
UpdateRequiredState(isRequired, aNotify);
|
||||
} else if (aNotify) {
|
||||
RemoveStates(REQUIRED_STATES);
|
||||
} else {
|
||||
RemoveStatesSilently(REQUIRED_STATES);
|
||||
}
|
||||
|
||||
UpdateHasRange();
|
||||
|
||||
// Do not notify, it will be done after if needed.
|
||||
@@ -6554,12 +6572,6 @@ HTMLInputElement::IntrinsicState() const
|
||||
state |= nsImageLoadingContent::ImageState();
|
||||
}
|
||||
|
||||
if (DoesRequiredApply() && IsRequired()) {
|
||||
state |= NS_EVENT_STATE_REQUIRED;
|
||||
} else {
|
||||
state |= NS_EVENT_STATE_OPTIONAL;
|
||||
}
|
||||
|
||||
if (IsCandidateForConstraintValidation()) {
|
||||
if (IsValid()) {
|
||||
state |= NS_EVENT_STATE_VALID;
|
||||
|
||||
Reference in New Issue
Block a user