- Revision
- 198997
- Author
- [email protected]
- Date
- 2016-04-04 00:53:40 -0700 (Mon, 04 Apr 2016)
Log Message
AX: Consolidate radio button group member code with that in HTMLElement derivatives
https://bugs.webkit.org/show_bug.cgi?id=155696
<rdar://problem/25260379>
Reviewed by Darin Adler.
Behavior covered by existing tests.
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::addRadioButtonGroupMembers):
* dom/CheckedRadioButtons.cpp:
(WebCore::RadioButtonGroup::isValid):
(WebCore::RadioButtonGroup::members):
(WebCore::RadioButtonGroup::setCheckedButton):
(WebCore::CheckedRadioButtons::addButton):
(WebCore::CheckedRadioButtons::groupMembers):
(WebCore::CheckedRadioButtons::updateCheckedState):
* dom/CheckedRadioButtons.h:
* dom/Range.h:
(WebCore::documentOrderComparator):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::isInRequiredRadioButtonGroup):
(WebCore::HTMLInputElement::radioButtonGroup):
(WebCore::HTMLInputElement::checkedRadioButtonForGroup):
* html/HTMLInputElement.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (198996 => 198997)
--- trunk/Source/WebCore/ChangeLog 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/ChangeLog 2016-04-04 07:53:40 UTC (rev 198997)
@@ -1,3 +1,31 @@
+2016-04-04 Chris Fleizach <[email protected]>
+
+ AX: Consolidate radio button group member code with that in HTMLElement derivatives
+ https://bugs.webkit.org/show_bug.cgi?id=155696
+ <rdar://problem/25260379>
+
+ Reviewed by Darin Adler.
+
+ Behavior covered by existing tests.
+
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::addRadioButtonGroupMembers):
+ * dom/CheckedRadioButtons.cpp:
+ (WebCore::RadioButtonGroup::isValid):
+ (WebCore::RadioButtonGroup::members):
+ (WebCore::RadioButtonGroup::setCheckedButton):
+ (WebCore::CheckedRadioButtons::addButton):
+ (WebCore::CheckedRadioButtons::groupMembers):
+ (WebCore::CheckedRadioButtons::updateCheckedState):
+ * dom/CheckedRadioButtons.h:
+ * dom/Range.h:
+ (WebCore::documentOrderComparator):
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::isInRequiredRadioButtonGroup):
+ (WebCore::HTMLInputElement::radioButtonGroup):
+ (WebCore::HTMLInputElement::checkedRadioButtonForGroup):
+ * html/HTMLInputElement.h:
+
2016-04-03 Darin Adler <[email protected]>
Remove unneeded UsePointersEvenForNonNullableObjectArguments in WebKitCSSMatrix.idl
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (198996 => 198997)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2016-04-04 07:53:40 UTC (rev 198997)
@@ -967,19 +967,9 @@
Node* node = this->node();
if (is<HTMLInputElement>(node)) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
- // if there's a form, then this is easy
- if (input.form()) {
- for (auto& associateElement : input.form()->namedElements(input.name())) {
- if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement.get()))
- linkedUIElements.append(object);
- }
- } else {
- for (auto& associateElement : descendantsOfType<HTMLInputElement>(node->document())) {
- if (associateElement.isRadioButton() && associateElement.name() == input.name()) {
- if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement))
- linkedUIElements.append(object);
- }
- }
+ for (auto& radioSibling : input.radioButtonGroup()) {
+ if (AccessibilityObject* object = axObjectCache()->getOrCreate(radioSibling))
+ linkedUIElements.append(object);
}
} else {
// If we didn't find any radio button siblings with the traditional naming, lets search for a radio group role and find its children.
Modified: trunk/Source/WebCore/dom/CheckedRadioButtons.cpp (198996 => 198997)
--- trunk/Source/WebCore/dom/CheckedRadioButtons.cpp 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/dom/CheckedRadioButtons.cpp 2016-04-04 07:53:40 UTC (rev 198997)
@@ -20,6 +20,7 @@
#include "config.h"
#include "CheckedRadioButtons.h"
+#include "Range.h"
#include "HTMLInputElement.h"
#include <wtf/HashSet.h>
@@ -38,7 +39,8 @@
void requiredAttributeChanged(HTMLInputElement*);
void remove(HTMLInputElement*);
bool contains(HTMLInputElement*) const;
-
+ Vector<HTMLInputElement*> members() const;
+
private:
void updateValidityForAllButtons();
bool isValid() const;
@@ -60,6 +62,14 @@
return !isRequired() || m_checkedButton;
}
+Vector<HTMLInputElement*> RadioButtonGroup::members() const
+{
+ Vector<HTMLInputElement*> members;
+ copyToVector(m_members, members);
+ std::sort(members.begin(), members.end(), documentOrderComparator);
+ return members;
+}
+
void RadioButtonGroup::setCheckedButton(HTMLInputElement* button)
{
HTMLInputElement* oldCheckedButton = m_checkedButton;
@@ -189,6 +199,22 @@
group->add(element);
}
+Vector<HTMLInputElement*> CheckedRadioButtons::groupMembers(const HTMLInputElement& element) const
+{
+ ASSERT(element.isRadioButton());
+ if (!element.isRadioButton())
+ return { };
+
+ auto* name = element.name().impl();
+ if (!name)
+ return { };
+
+ auto* group = m_nameToGroupMap->get(name);
+ if (!group)
+ return { };
+ return group->members();
+}
+
void CheckedRadioButtons::updateCheckedState(HTMLInputElement* element)
{
ASSERT(element->isRadioButton());
Modified: trunk/Source/WebCore/dom/CheckedRadioButtons.h (198996 => 198997)
--- trunk/Source/WebCore/dom/CheckedRadioButtons.h 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/dom/CheckedRadioButtons.h 2016-04-04 07:53:40 UTC (rev 198997)
@@ -24,6 +24,7 @@
#include <memory>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
namespace WebCore {
@@ -42,7 +43,8 @@
void removeButton(HTMLInputElement*);
HTMLInputElement* checkedButtonForGroup(const AtomicString& groupName) const;
bool isInRequiredGroup(HTMLInputElement*) const;
-
+ Vector<HTMLInputElement*> groupMembers(const HTMLInputElement&) const;
+
private:
typedef HashMap<AtomicStringImpl*, std::unique_ptr<RadioButtonGroup>> NameToGroupMap;
std::unique_ptr<NameToGroupMap> m_nameToGroupMap;
Modified: trunk/Source/WebCore/dom/Range.h (198996 => 198997)
--- trunk/Source/WebCore/dom/Range.h 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/dom/Range.h 2016-04-04 07:53:40 UTC (rev 198997)
@@ -182,6 +182,11 @@
WEBCORE_EXPORT bool areRangesEqual(const Range*, const Range*);
bool rangesOverlap(const Range*, const Range*);
+inline bool documentOrderComparator(const Node* a, const Node* b)
+{
+ return Range::compareBoundaryPoints(const_cast<Node*>(a), 0, const_cast<Node*>(b), 0, ASSERT_NO_EXCEPTION) < 0;
+}
+
} // namespace
#if ENABLE(TREE_DEBUGGING)
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (198996 => 198997)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2016-04-04 07:53:40 UTC (rev 198997)
@@ -1776,6 +1776,14 @@
return false;
}
+Vector<HTMLInputElement*> HTMLInputElement::radioButtonGroup() const
+{
+ CheckedRadioButtons* buttons = checkedRadioButtons();
+ if (!buttons)
+ return { };
+ return buttons->groupMembers(*this);
+}
+
HTMLInputElement* HTMLInputElement::checkedRadioButtonForGroup() const
{
if (CheckedRadioButtons* buttons = checkedRadioButtons())
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (198996 => 198997)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2016-04-04 07:42:31 UTC (rev 198996)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2016-04-04 07:53:40 UTC (rev 198997)
@@ -271,6 +271,7 @@
void listAttributeTargetChanged();
#endif
+ Vector<HTMLInputElement*> radioButtonGroup() const;
HTMLInputElement* checkedRadioButtonForGroup() const;
bool isInRequiredRadioButtonGroup();