Bug 1358448 - Add radio back to a radio group after moving out of a form. r=smaug

The container of a radio group is the form, if it belongs to a form, or the
document object otherwise.
When moving a radio out of a form, we should add it back to a radio group.
Similary, before moving the radio to a form, we should remove it from the
original radio group.

MozReview-Commit-ID: 22WsEhz2SXH
This commit is contained in:
Jessica Jong
2017-05-01 23:10:00 +02:00
parent a458c3b4e5
commit 0a69701a7e
8 changed files with 57 additions and 13 deletions

View File

@@ -1760,12 +1760,21 @@ nsGenericHTMLFormElement::SetForm(nsIDOMHTMLFormElement* aForm)
NS_ASSERTION(!mForm,
"We don't support switching from one non-null form to another.");
SetForm(static_cast<HTMLFormElement*>(aForm), false);
}
void nsGenericHTMLFormElement::SetForm(HTMLFormElement* aForm, bool aBindToTree)
{
if (aForm) {
BeforeSetForm(aBindToTree);
}
// keep a *weak* ref to the form here
mForm = static_cast<HTMLFormElement*>(aForm);
mForm = aForm;
}
void
nsGenericHTMLFormElement::ClearForm(bool aRemoveFromForm)
nsGenericHTMLFormElement::ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete)
{
NS_ASSERTION((mForm != nullptr) == HasFlag(ADDED_TO_FORM),
"Form control should have had flag set correctly");
@@ -1792,6 +1801,8 @@ nsGenericHTMLFormElement::ClearForm(bool aRemoveFromForm)
UnsetFlags(ADDED_TO_FORM);
mForm = nullptr;
AfterClearForm(aUnbindOrDelete);
}
Element*
@@ -1876,12 +1887,12 @@ nsGenericHTMLFormElement::UnbindFromTree(bool aDeep, bool aNullParent)
// Might need to unset mForm
if (aNullParent) {
// No more parent means no more form
ClearForm(true);
ClearForm(true, true);
} else {
// Recheck whether we should still have an mForm.
if (HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
!FindAncestorForm(mForm)) {
ClearForm(true);
ClearForm(true, true);
} else {
UnsetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
}
@@ -2269,7 +2280,7 @@ nsGenericHTMLFormElement::UpdateFormOwner(bool aBindToTree,
bool needStateUpdate = false;
if (!aBindToTree) {
needStateUpdate = mForm && mForm->IsDefaultSubmitElement(this);
ClearForm(true);
ClearForm(true, false);
}
HTMLFormElement *oldForm = mForm;
@@ -2295,7 +2306,7 @@ nsGenericHTMLFormElement::UpdateFormOwner(bool aBindToTree,
"associated with the id in @form!");
if (element && element->IsHTMLElement(nsGkAtoms::form)) {
mForm = static_cast<HTMLFormElement*>(element);
SetForm(static_cast<HTMLFormElement*>(element), aBindToTree);
}
}
} else {
@@ -2305,7 +2316,7 @@ nsGenericHTMLFormElement::UpdateFormOwner(bool aBindToTree,
// it to the right value. Also note that even if being bound here didn't
// change our parent, we still need to search, since our parent chain
// probably changed _somewhere_.
mForm = FindAncestorForm();
SetForm(FindAncestorForm(), aBindToTree);
}
}