Bug 1365092 - Move side effects of SetAttr, UnsetAttr, and ParseAttribute functions to BeforeSetAttr and AfterSetAttr r=bz

This is necessary to facilitate the transition to cloning attributes instead of reparsing them.

MozReview-Commit-ID: Gyd1tD6ldly
This commit is contained in:
Kirk Steuber
2017-06-07 10:28:20 -07:00
parent 8f7a03110f
commit 6684b17554
32 changed files with 604 additions and 670 deletions

View File

@@ -1301,9 +1301,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,
@@ -1324,6 +1337,12 @@ HTMLSelectElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
// Clear the cached @autocomplete attribute and autocompleteInfo state.
mAutocompleteAttrState = nsContentUtils::eAutocompleteAttrState_Unknown;
mAutocompleteInfoState = 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);
}
}
}
@@ -1332,37 +1351,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)
{