Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an element is disabled. It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons: - For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on form elements that can be disabled; form elements that can't be disabled overrides IsDisabled() to return false directly. And, before this patch, NS_EVENT_STATE_DISABLED flag is set by nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all cases when CanBeDisabled() is true, and when CanBeDisabled() is false then IsDisabled() is always false and the flag is not set. - For non form elements, optgroup and option have the flag matching IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's (if it exists) disabled state, which was not done before this patch. For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier, that is, in AfterSetAttr(), before any consumer of IsDisabled(). We also need to update the flag whenever the element's parent (e.g. fieldset or optgroup) disabled state changes and when moving into/out of a parent container. Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the EXTERNALLY_MANAGED_STATES. MozReview-Commit-ID: KSceikeqvvU
This commit is contained in:
@@ -1446,6 +1446,13 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
|
||||
if (aName == nsGkAtoms::required || aName == nsGkAtoms::disabled ||
|
||||
aName == nsGkAtoms::readonly) {
|
||||
if (aName == nsGkAtoms::disabled) {
|
||||
// This *has* to be called *before* validity state check because
|
||||
// UpdateBarredFromConstraintValidation and
|
||||
// UpdateValueMissingValidityState depend on our disabled state.
|
||||
UpdateDisabledState(aNotify);
|
||||
}
|
||||
|
||||
UpdateValueMissingValidityState();
|
||||
|
||||
// This *has* to be called *after* validity has changed.
|
||||
@@ -7463,10 +7470,14 @@ HTMLInputElement::HasCachedSelection()
|
||||
void
|
||||
HTMLInputElement::FieldSetDisabledChanged(bool aNotify)
|
||||
{
|
||||
// This *has* to be called *before* UpdateBarredFromConstraintValidation and
|
||||
// UpdateValueMissingValidityState because these two functions depend on our
|
||||
// disabled state.
|
||||
nsGenericHTMLFormElementWithState::FieldSetDisabledChanged(aNotify);
|
||||
|
||||
UpdateValueMissingValidityState();
|
||||
UpdateBarredFromConstraintValidation();
|
||||
|
||||
nsGenericHTMLFormElementWithState::FieldSetDisabledChanged(aNotify);
|
||||
UpdateState(aNotify);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user