summaryrefslogtreecommitdiffstats
path: root/dom/html/HTMLSelectElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/HTMLSelectElement.cpp')
-rw-r--r--dom/html/HTMLSelectElement.cpp56
1 files changed, 22 insertions, 34 deletions
diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp
index d11f8b90f..36dac0852 100644
--- a/dom/html/HTMLSelectElement.cpp
+++ b/dom/html/HTMLSelectElement.cpp
@@ -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)
{