Bug 1385478 - Part 1: Use IsRequired/Required() to get the current required state. r=bz

IsRequired() helper function returns the current 'required' state of the
element, that is, whether its required attribute is set or not. This will be
used only for input elements that @required applies.
This commit is contained in:
Jessica Jong
2017-08-03 01:23:00 -04:00
parent f1faaf0e7d
commit 2cc9e3beb6
13 changed files with 46 additions and 21 deletions

View File

@@ -2314,7 +2314,10 @@ HTMLFormElement::AddToRadioGroup(const nsAString& aName,
nsCOMPtr<nsIContent> element = do_QueryInterface(aRadio);
NS_ASSERTION(element, "radio controls have to be content elements!");
if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
HTMLInputElement* input = HTMLInputElement::FromContent(element);
NS_ASSERTION(input, "radio controls have to be input elements!");
if (input->IsRequired()) {
auto entry = mRequiredRadioButtonCounts.LookupForAdd(aName);
if (!entry) {
entry.OrInsert([]() { return 1; });
@@ -2329,9 +2332,12 @@ HTMLFormElement::RemoveFromRadioGroup(const nsAString& aName,
nsIFormControl* aRadio)
{
nsCOMPtr<nsIContent> element = do_QueryInterface(aRadio);
NS_ASSERTION(element, "radio controls have to be content elements!");
NS_ASSERTION(element, "radio controls have to be content elements");
if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
HTMLInputElement* input = HTMLInputElement::FromContent(element);
NS_ASSERTION(input, "radio controls have to be input elements!");
if (input->IsRequired()) {
auto entry = mRequiredRadioButtonCounts.Lookup(aName);
if (!entry) {
MOZ_ASSERT_UNREACHABLE("At least one radio button has to be required!");