- Revision
- 137565
- Author
- [email protected]
- Date
- 2012-12-12 21:44:01 -0800 (Wed, 12 Dec 2012)
Log Message
Validity of a radio button is not updated correctly when it is detached from an invalid radio group
https://bugs.webkit.org/show_bug.cgi?id=104873
Reviewed by Kentaro Hara.
Source/WebCore:
When a radio button is detached from an invalid radio group,
A) we should update button's validity, and
B) it should be valid.
A is handled by the following code in RadioButtonGroup::remove.
if (!wasValid) {
// A radio button not in a group is always valid. We need to make it
// valid only if the group was invalid.
button->setNeedsValidityCheck();
B was incomplete.
bool RadioInputType::valueMissing(const String&) const
{
return element()->isInRequiredRadioButtonGroup() && !element()->checkedRadioButtonForGroup();
isInRequiredRadioButtonGroup checked required state of a group with the
name attribute value even if the radio button was already detached from
the group. isInRequiredRadioButtonGroup should check membership of the
radio button precisely.
Tests: Update fast/forms/radio/radio-live-validation-style.html
* dom/CheckedRadioButtons.cpp:
(RadioButtonGroup): Declare contains.
(WebCore::RadioButtonGroup::contains): Added.
(WebCore::CheckedRadioButtons::isInRequiredGroup): Renamed from
isRequiredGroup. This function takes HTMLInputElement* argument.
* dom/CheckedRadioButtons.h:
(CheckedRadioButtons): Rename isRequiredGroup to isInRequiredGroup.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::isInRequiredRadioButtonGroup):
Make this non-const becaues RadioButtonGroup::m_members needs non-const
pointers. Use CheckedRadioButtons::isInRequiredGroup.
* html/HTMLInputElement.h:
(HTMLInputElement): Make isInRequiredRadioButtonGroup non-const.
LayoutTests:
* fast/forms/radio/radio-live-validation-style-expected.txt:
* fast/forms/radio/radio-live-validation-style.html: Add a test case.
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (137564 => 137565)
--- trunk/LayoutTests/ChangeLog 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/LayoutTests/ChangeLog 2012-12-13 05:44:01 UTC (rev 137565)
@@ -1,3 +1,13 @@
+2012-12-12 Kent Tamura <[email protected]>
+
+ Validity of a radio button is not updated correctly when it is detached from an invalid radio group
+ https://bugs.webkit.org/show_bug.cgi?id=104873
+
+ Reviewed by Kentaro Hara.
+
+ * fast/forms/radio/radio-live-validation-style-expected.txt:
+ * fast/forms/radio/radio-live-validation-style.html: Add a test case.
+
2012-12-12 Kunihiko Sakamoto <[email protected]>
Milliseconds field of date/time input UI should respect step attribute
Modified: trunk/LayoutTests/fast/forms/radio/radio-live-validation-style-expected.txt (137564 => 137565)
--- trunk/LayoutTests/fast/forms/radio/radio-live-validation-style-expected.txt 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/LayoutTests/fast/forms/radio/radio-live-validation-style-expected.txt 2012-12-13 05:44:01 UTC (rev 137565)
@@ -6,6 +6,8 @@
Removing a checked radio button from a required radio button group by a DOM tree mutation:
PASS backgroundOf($("radio1")) is validColor
PASS parent.removeChild($("radio2")); backgroundOf($("radio1")) is invalidColor
+PASS $("radio1").remove(); radio2.webkitMatchesSelector(":valid") is false
+PASS radio2.remove(); radio2.webkitMatchesSelector(":valid") is true
Removing a checked radio button from a required radio button group by name attribute change:
PASS $("radio2").name = "group2"; backgroundOf($("radio1")) is invalidColor
Modified: trunk/LayoutTests/fast/forms/radio/radio-live-validation-style.html (137564 => 137565)
--- trunk/LayoutTests/fast/forms/radio/radio-live-validation-style.html 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/LayoutTests/fast/forms/radio/radio-live-validation-style.html 2012-12-13 05:44:01 UTC (rev 137565)
@@ -30,6 +30,12 @@
'<input type=radio name=group1 checked id=radio2>';
shouldBe('backgroundOf($("radio1"))', 'validColor');
shouldBe('parent.removeChild($("radio2")); backgroundOf($("radio1"))', 'invalidColor');
+parent.innerHTML = '<input type=radio name=group1 required checked id=radio1>' +
+ '<input type=radio name=group1 required id=radio2>' +
+ '<input type=radio name=group1 required id=radio3>';
+var radio2 = $('radio2');
+shouldBeFalse('$("radio1").remove(); radio2.webkitMatchesSelector(":valid")');
+shouldBeTrue('radio2.remove(); radio2.webkitMatchesSelector(":valid")');
debug('');
debug('Removing a checked radio button from a required radio button group by name attribute change:');
Modified: trunk/Source/WebCore/ChangeLog (137564 => 137565)
--- trunk/Source/WebCore/ChangeLog 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/Source/WebCore/ChangeLog 2012-12-13 05:44:01 UTC (rev 137565)
@@ -1,3 +1,45 @@
+2012-12-12 Kent Tamura <[email protected]>
+
+ Validity of a radio button is not updated correctly when it is detached from an invalid radio group
+ https://bugs.webkit.org/show_bug.cgi?id=104873
+
+ Reviewed by Kentaro Hara.
+
+ When a radio button is detached from an invalid radio group,
+ A) we should update button's validity, and
+ B) it should be valid.
+
+ A is handled by the following code in RadioButtonGroup::remove.
+ if (!wasValid) {
+ // A radio button not in a group is always valid. We need to make it
+ // valid only if the group was invalid.
+ button->setNeedsValidityCheck();
+
+ B was incomplete.
+ bool RadioInputType::valueMissing(const String&) const
+ {
+ return element()->isInRequiredRadioButtonGroup() && !element()->checkedRadioButtonForGroup();
+ isInRequiredRadioButtonGroup checked required state of a group with the
+ name attribute value even if the radio button was already detached from
+ the group. isInRequiredRadioButtonGroup should check membership of the
+ radio button precisely.
+
+ Tests: Update fast/forms/radio/radio-live-validation-style.html
+
+ * dom/CheckedRadioButtons.cpp:
+ (RadioButtonGroup): Declare contains.
+ (WebCore::RadioButtonGroup::contains): Added.
+ (WebCore::CheckedRadioButtons::isInRequiredGroup): Renamed from
+ isRequiredGroup. This function takes HTMLInputElement* argument.
+ * dom/CheckedRadioButtons.h:
+ (CheckedRadioButtons): Rename isRequiredGroup to isInRequiredGroup.
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::isInRequiredRadioButtonGroup):
+ Make this non-const becaues RadioButtonGroup::m_members needs non-const
+ pointers. Use CheckedRadioButtons::isInRequiredGroup.
+ * html/HTMLInputElement.h:
+ (HTMLInputElement): Make isInRequiredRadioButtonGroup non-const.
+
2012-12-12 Shinya Kawanaka <[email protected]>
ContainerNodeAlgorithm::notifyInsertedIntoDocument is not used
Modified: trunk/Source/WebCore/dom/CheckedRadioButtons.cpp (137564 => 137565)
--- trunk/Source/WebCore/dom/CheckedRadioButtons.cpp 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/Source/WebCore/dom/CheckedRadioButtons.cpp 2012-12-13 05:44:01 UTC (rev 137565)
@@ -37,6 +37,7 @@
void updateCheckedState(HTMLInputElement*);
void requiredAttributeChanged(HTMLInputElement*);
void remove(HTMLInputElement*);
+ bool contains(HTMLInputElement*) const;
private:
RadioButtonGroup();
@@ -164,6 +165,11 @@
}
}
+bool RadioButtonGroup::contains(HTMLInputElement* button) const
+{
+ return m_members.contains(button);
+}
+
// ----------------------------------------------------------------
// Explicity define empty constructor and destructor in order to prevent the
@@ -227,12 +233,15 @@
return group ? group->checkedButton() : 0;
}
-bool CheckedRadioButtons::isRequiredGroup(const AtomicString& name) const
+bool CheckedRadioButtons::isInRequiredGroup(HTMLInputElement* element) const
{
+ ASSERT(element->isRadioButton());
+ if (element->name().isEmpty())
+ return false;
if (!m_nameToGroupMap)
return false;
- RadioButtonGroup* group = m_nameToGroupMap->get(name.impl());
- return group && group->isRequired();
+ RadioButtonGroup* group = m_nameToGroupMap->get(element->name().impl());
+ return group && group->isRequired() && group->contains(element);
}
void CheckedRadioButtons::removeButton(HTMLInputElement* element)
Modified: trunk/Source/WebCore/dom/CheckedRadioButtons.h (137564 => 137565)
--- trunk/Source/WebCore/dom/CheckedRadioButtons.h 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/Source/WebCore/dom/CheckedRadioButtons.h 2012-12-13 05:44:01 UTC (rev 137565)
@@ -41,7 +41,7 @@
void requiredAttributeChanged(HTMLInputElement*);
void removeButton(HTMLInputElement*);
HTMLInputElement* checkedButtonForGroup(const AtomicString& groupName) const;
- bool isRequiredGroup(const AtomicString& groupName) const;
+ bool isInRequiredGroup(HTMLInputElement*) const;
private:
typedef HashMap<AtomicStringImpl*, OwnPtr<RadioButtonGroup> > NameToGroupMap;
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (137564 => 137565)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2012-12-13 05:44:01 UTC (rev 137565)
@@ -1773,11 +1773,11 @@
#endif
-bool HTMLInputElement::isInRequiredRadioButtonGroup() const
+bool HTMLInputElement::isInRequiredRadioButtonGroup()
{
ASSERT(isRadioButton());
if (CheckedRadioButtons* buttons = checkedRadioButtons())
- return buttons->isRequiredGroup(name());
+ return buttons->isInRequiredGroup(this);
return false;
}
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (137564 => 137565)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2012-12-13 05:31:24 UTC (rev 137564)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2012-12-13 05:44:01 UTC (rev 137565)
@@ -245,7 +245,7 @@
#endif
HTMLInputElement* checkedRadioButtonForGroup() const;
- bool isInRequiredRadioButtonGroup() const;
+ bool isInRequiredRadioButtonGroup();
// Functions for InputType classes.
void setValueInternal(const String&, TextFieldEventBehavior);