Bug 1365092 - Move side effects of SetAttr and ParseAttribute to BeforeSetAttr and AfterSetAttr

* Moves side effects of nsGenericHTMLElement and Element's SetAttr, UnsetAttr, and ParseAttribute functions to the corresponding BeforeSetAttr and AfterSetAttr functions
* Moves side effects of HTMLAnchorElement's SetAttr, UnsetAttr, and ParseAttribute functions to the corresponding BeforeSetAttr and AfterSetAttr functions
* Moves side effects of HTMLImageElement's SetAttr function to the corresponding BeforeSetAttr and AfterSetAttr functions
* Moves side effects of SetAttr, UnsetAttr, and ParseAttribute functions to BeforeSetAttr and AfterSetAttr

Tag #1375
This commit is contained in:
Matt A. Tobin 2020-04-17 05:33:06 -04:00 committed by Roy Tam
commit 6aa436b588
41 changed files with 983 additions and 956 deletions

View file

@ -1272,9 +1272,22 @@ HTMLSelectElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify)
{
if (aNotify && aName == nsGkAtoms::disabled &&
aNameSpaceID == kNameSpaceID_None) {
mDisabledChanged = true;
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::disabled) {
if (aNotify) {
mDisabledChanged = true;
}
} else if (aName == nsGkAtoms::multiple) {
if (!aValue && aNotify && mSelectedIndex >= 0) {
// We're changing from being a multi-select to a single-select.
// Make sure we only have one option selected before we do that.
// Note that this needs to come before we really unset the attr,
// since SetOptionsSelectedByIndex does some bail-out type
// optimization for cases when the select is not multiple that
// would lead to only a single option getting deselected.
SetSelectedIndexInternal(mSelectedIndex, aNotify);
}
}
}
return nsGenericHTMLFormElementWithState::BeforeSetAttr(aNameSpaceID, aName,
@ -1294,6 +1307,12 @@ HTMLSelectElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
} else if (aName == nsGkAtoms::autocomplete) {
// Clear the cached @autocomplete attribute state
mAutocompleteAttrState = nsContentUtils::eAutocompleteAttrState_Unknown;
} else if (aName == nsGkAtoms::multiple) {
if (!aValue && aNotify) {
// We might have become a combobox; make sure _something_ gets
// selected in that case
CheckSelectSomething(aNotify);
}
}
}
@ -1302,37 +1321,6 @@ HTMLSelectElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
aNotify);
}
nsresult
HTMLSelectElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
bool aNotify)
{
if (aNotify && aNameSpaceID == kNameSpaceID_None &&
aAttribute == nsGkAtoms::multiple) {
// We're changing from being a multi-select to a single-select.
// Make sure we only have one option selected before we do that.
// Note that this needs to come before we really unset the attr,
// since SetOptionsSelectedByIndex does some bail-out type
// optimization for cases when the select is not multiple that
// would lead to only a single option getting deselected.
if (mSelectedIndex >= 0) {
SetSelectedIndexInternal(mSelectedIndex, aNotify);
}
}
nsresult rv = nsGenericHTMLFormElementWithState::UnsetAttr(aNameSpaceID, aAttribute,
aNotify);
NS_ENSURE_SUCCESS(rv, rv);
if (aNotify && aNameSpaceID == kNameSpaceID_None &&
aAttribute == nsGkAtoms::multiple) {
// We might have become a combobox; make sure _something_ gets
// selected in that case
CheckSelectSomething(aNotify);
}
return rv;
}
void
HTMLSelectElement::DoneAddingChildren(bool aHaveNotified)
{