diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 1e1d1387c9b..b7e6cc95fb0 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -8376,13 +8376,11 @@ nsDocument::GetRequiredRadioCount(const nsAString& aName) const } void -nsDocument::RadioRequiredChanged(const nsAString& aName, nsIFormControl* aRadio) +nsDocument::RadioRequiredWillChange(const nsAString& aName, bool aRequiredAdded) { nsRadioGroupStruct* radioGroup = GetOrCreateRadioGroup(aName); - nsCOMPtr element = do_QueryInterface(aRadio); - NS_ASSERTION(element, "radio controls have to be content elements"); - if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) { + if (aRequiredAdded) { radioGroup->mRequiredRadioCount++; } else { NS_ASSERTION(radioGroup->mRequiredRadioCount != 0, diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 93ce1d255f5..14b7ccae201 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -930,8 +930,8 @@ public: virtual void RemoveFromRadioGroup(const nsAString& aName, nsIFormControl* aRadio) MOZ_OVERRIDE; virtual uint32_t GetRequiredRadioCount(const nsAString& aName) const MOZ_OVERRIDE; - virtual void RadioRequiredChanged(const nsAString& aName, - nsIFormControl* aRadio) MOZ_OVERRIDE; + virtual void RadioRequiredWillChange(const nsAString& aName, + bool aRequiredAdded) MOZ_OVERRIDE; virtual bool GetValueMissingState(const nsAString& aName) const MOZ_OVERRIDE; virtual void SetValueMissingState(const nsAString& aName, bool aValue) MOZ_OVERRIDE; diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index 3fc4f83c8e6..8c9fbd33631 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -2196,13 +2196,10 @@ HTMLFormElement::GetRequiredRadioCount(const nsAString& aName) const } void -HTMLFormElement::RadioRequiredChanged(const nsAString& aName, - nsIFormControl* aRadio) +HTMLFormElement::RadioRequiredWillChange(const nsAString& aName, + bool aRequiredAdded) { - nsCOMPtr element = do_QueryInterface(aRadio); - NS_ASSERTION(element, "radio controls have to be content elements!"); - - if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) { + if (aRequiredAdded) { mRequiredRadioButtonCounts.Put(aName, mRequiredRadioButtonCounts.Get(aName)+1); } else { diff --git a/dom/html/HTMLFormElement.h b/dom/html/HTMLFormElement.h index 51921259746..d069fcf3ebe 100644 --- a/dom/html/HTMLFormElement.h +++ b/dom/html/HTMLFormElement.h @@ -76,8 +76,8 @@ public: void AddToRadioGroup(const nsAString& aName, nsIFormControl* aRadio) MOZ_OVERRIDE; void RemoveFromRadioGroup(const nsAString& aName, nsIFormControl* aRadio) MOZ_OVERRIDE; virtual uint32_t GetRequiredRadioCount(const nsAString& aName) const MOZ_OVERRIDE; - virtual void RadioRequiredChanged(const nsAString& aName, - nsIFormControl* aRadio) MOZ_OVERRIDE; + virtual void RadioRequiredWillChange(const nsAString& aName, + bool aRequiredAdded) MOZ_OVERRIDE; virtual bool GetValueMissingState(const nsAString& aName) const MOZ_OVERRIDE; virtual void SetValueMissingState(const nsAString& aName, bool aValue) MOZ_OVERRIDE; diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 4161f1f31c2..9c86a5bc79e 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -1332,6 +1332,16 @@ HTMLInputElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName, AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir, nsGkAtoms::_auto, eIgnoreCase)) { SetDirectionIfAuto(false, aNotify); + } else if (mType == NS_FORM_INPUT_RADIO && aName == nsGkAtoms::required) { + nsCOMPtr container = GetRadioGroupContainer(); + + if (container && + ((aValue && !HasAttr(aNameSpaceID, aName)) || + (!aValue && HasAttr(aNameSpaceID, aName)))) { + nsAutoString name; + GetAttr(kNameSpaceID_None, nsGkAtoms::name, name); + container->RadioRequiredWillChange(name, !!aValue); + } } } @@ -1405,16 +1415,6 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } } - if (mType == NS_FORM_INPUT_RADIO && aName == nsGkAtoms::required) { - nsCOMPtr container = GetRadioGroupContainer(); - - if (container) { - nsAutoString name; - GetAttr(kNameSpaceID_None, nsGkAtoms::name, name); - container->RadioRequiredChanged(name, this); - } - } - if (aName == nsGkAtoms::required || aName == nsGkAtoms::disabled || aName == nsGkAtoms::readonly) { UpdateValueMissingValidityState(); diff --git a/dom/html/nsIRadioGroupContainer.h b/dom/html/nsIRadioGroupContainer.h index 3a076357974..41538948994 100644 --- a/dom/html/nsIRadioGroupContainer.h +++ b/dom/html/nsIRadioGroupContainer.h @@ -18,8 +18,8 @@ class HTMLInputElement; } #define NS_IRADIOGROUPCONTAINER_IID \ -{ 0x22924a01, 0x4360, 0x401b, \ - { 0xb1, 0xd1, 0x56, 0x8d, 0xf5, 0xa3, 0xda, 0x71 } } +{ 0x800320a0, 0x733f, 0x11e4, \ + { 0x82, 0xf8, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } } /** * A container that has multiple radio groups in it, defined by name. @@ -91,8 +91,8 @@ public: virtual void RemoveFromRadioGroup(const nsAString& aName, nsIFormControl* aRadio) = 0; virtual uint32_t GetRequiredRadioCount(const nsAString& aName) const = 0; - virtual void RadioRequiredChanged(const nsAString& aName, - nsIFormControl* aRadio) = 0; + virtual void RadioRequiredWillChange(const nsAString& aName, + bool aRequiredAdded) = 0; virtual bool GetValueMissingState(const nsAString& aName) const = 0; virtual void SetValueMissingState(const nsAString& aName, bool aValue) = 0; }; diff --git a/dom/html/test/forms/mochitest.ini b/dom/html/test/forms/mochitest.ini index be5fc933f12..ad1fe7de67c 100644 --- a/dom/html/test/forms/mochitest.ini +++ b/dom/html/test/forms/mochitest.ini @@ -6,6 +6,7 @@ support-files = [test_bug1039548.html] [test_button_attributes_reflection.html] [test_input_radio_radiogroup.html] +[test_input_radio_required.html] [test_change_event.html] skip-if = buildapp == 'mulet' || (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage [test_datalist_element.html] diff --git a/dom/html/test/forms/test_input_radio_required.html b/dom/html/test/forms/test_input_radio_required.html new file mode 100644 index 00000000000..e1ba4291444 --- /dev/null +++ b/dom/html/test/forms/test_input_radio_required.html @@ -0,0 +1,31 @@ + + + + + Test for Bug 1100535 + + + + + +Mozilla Bug 1100535 +

+ +
+
+
+ +