Diff
Modified: trunk/Source/WebCore/ChangeLog (293297 => 293298)
--- trunk/Source/WebCore/ChangeLog 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/ChangeLog 2022-04-24 02:27:34 UTC (rev 293298)
@@ -1,3 +1,51 @@
+2022-04-23 Andres Gonzalez <[email protected]>
+
+ Code cleanup in preparation for optimizing use of AccessibilityObject::elementsFromAttribute.
+ https://bugs.webkit.org/show_bug.cgi?id=239664
+ <rdar://problem/92180286>
+
+ Reviewed by Chris Fleizach.
+
+ No new functionality.
+
+ AccessibilityObject::elementsFromAttribute now returns a vector as
+ opposed to taking an out parameter. This makes the code more concise
+ and possibly more efficient.
+ Removed this method from the AXCoreObject interface, since this method
+ should not be exposed to an AT client. The Inspector is an exception
+ that accesses AccessibilityObjects directly and not through the
+ AXCoreObject interface.
+ All these changes are entirely code cleanup and modernization, no change
+ in functionality.
+
+ * accessibility/AccessibilityNodeObject.cpp:
+ (WebCore::AccessibilityNodeObject::ariaLabeledByText const):
+ (WebCore::AccessibilityNodeObject::textUnderElement const):
+ (WebCore::AccessibilityNodeObject::descriptionForElements const):
+ (WebCore::AccessibilityNodeObject::ariaDescribedByAttribute const):
+ (WebCore::AccessibilityNodeObject::ariaLabeledByAttribute const):
+ (WebCore::AccessibilityNodeObject::accessibilityDescriptionForElements const): Renamed.
+ (WebCore::AccessibilityNodeObject::ariaLabeledByElements const): Deleted.
+ * accessibility/AccessibilityNodeObject.h:
+ * accessibility/AccessibilityObject.cpp:
+ (WebCore::AccessibilityObject::ariaElementsFromAttribute const):
+ (WebCore::AccessibilityObject::elementsFromAttribute const):
+ * accessibility/AccessibilityObject.h:
+ * accessibility/AccessibilityObjectInterface.h:
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::isTabItemSelected const):
+ * accessibility/isolatedtree/AXIsolatedObject.cpp:
+ (WebCore::AXIsolatedObject::elementsFromAttribute const): Deleted.
+ * accessibility/isolatedtree/AXIsolatedObject.h:
+ * inspector/InspectorAuditAccessibilityObject.cpp:
+ (WebCore::accessiblityObjectForNode):
+ (WebCore::InspectorAuditAccessibilityObject::getControlledNodes):
+ (WebCore::InspectorAuditAccessibilityObject::getFlowedNodes):
+ (WebCore::InspectorAuditAccessibilityObject::getMouseEventNode):
+ (WebCore::InspectorAuditAccessibilityObject::getOwnedNodes):
+ * inspector/agents/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::buildObjectForAccessibilityProperties):
+
2022-04-23 Alan Bujtas <[email protected]>
[FFC][Integration] Add integration API to FlexFormattingContext
Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (293297 => 293298)
--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2022-04-24 02:27:34 UTC (rev 293298)
@@ -1775,8 +1775,7 @@
if (!objectCache)
return;
- Vector<Element*> elements;
- ariaLabeledByElements(elements);
+ auto elements = ariaLabeledByElements();
Vector<AXCoreObject*> axElements;
for (const auto& element : elements)
@@ -2078,8 +2077,7 @@
// We should ignore the child if it's labeled by this node.
// This could happen when this node labels multiple child nodes and we didn't
// skip in the above ignoredChildNode check.
- Vector<Element*> labeledByElements;
- downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements(labeledByElements);
+ auto labeledByElements = downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements();
if (labeledByElements.contains(node))
continue;
@@ -2333,37 +2331,32 @@
return builder.toString();
}
-String AccessibilityNodeObject::accessibilityDescriptionForElements(Vector<Element*> &elements) const
+String AccessibilityNodeObject::descriptionForElements(Vector<Element*>&& elements) const
{
StringBuilder builder;
- unsigned size = elements.size();
- for (unsigned i = 0; i < size; ++i)
- appendNameToStringBuilder(builder, accessibleNameForNode(elements[i], node()));
+ for (auto* element : elements)
+ appendNameToStringBuilder(builder, accessibleNameForNode(element, node()));
return builder.toString();
}
String AccessibilityNodeObject::ariaDescribedByAttribute() const
{
- Vector<Element*> elements;
- elementsFromAttribute(elements, aria_describedbyAttr);
-
- return accessibilityDescriptionForElements(elements);
+ return descriptionForElements(elementsFromAttribute(aria_describedbyAttr));
}
-void AccessibilityNodeObject::ariaLabeledByElements(Vector<Element*>& elements) const
+Vector<Element*> AccessibilityNodeObject::ariaLabeledByElements() const
{
- elementsFromAttribute(elements, aria_labelledbyAttr);
- if (!elements.size())
- elementsFromAttribute(elements, aria_labeledbyAttr);
+ // FIXME: should walk the DOM elements only once.
+ auto elements = elementsFromAttribute(aria_labelledbyAttr);
+ if (elements.size())
+ return elements;
+ return elementsFromAttribute(aria_labeledbyAttr);
}
String AccessibilityNodeObject::ariaLabeledByAttribute() const
{
- Vector<Element*> elements;
- ariaLabeledByElements(elements);
-
- return accessibilityDescriptionForElements(elements);
+ return descriptionForElements(ariaLabeledByElements());
}
bool AccessibilityNodeObject::hasAttributesRequiredForInclusion() const
Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h (293297 => 293298)
--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h 2022-04-24 02:27:34 UTC (rev 293298)
@@ -181,8 +181,8 @@
HTMLLabelElement* labelElementContainer() const;
String ariaAccessibilityDescription() const;
- void ariaLabeledByElements(Vector<Element*>& elements) const;
- String accessibilityDescriptionForElements(Vector<Element*> &elements) const;
+ Vector<Element*> ariaLabeledByElements() const;
+ String descriptionForElements(Vector<Element*>&&) const;
LayoutRect boundingBoxRect() const override;
String ariaDescribedByAttribute() const override;
Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (293297 => 293298)
--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp 2022-04-24 02:27:34 UTC (rev 293298)
@@ -3743,16 +3743,17 @@
return ignored;
}
-void AccessibilityObject::elementsFromAttribute(Vector<Element*>& elements, const QualifiedName& attribute) const
+Vector<Element*> AccessibilityObject::elementsFromAttribute(const QualifiedName& attribute) const
{
Node* node = this->node();
if (!node || !node->isElementNode())
- return;
+ return { };
auto& idsString = getAttribute(attribute);
if (idsString.isEmpty())
- return;
+ return { };
+ Vector<Element*> elements;
auto& treeScope = node->treeScope();
SpaceSplitString spaceSplitString(idsString, SpaceSplitString::ShouldFoldCase::No);
size_t length = spaceSplitString.size();
@@ -3760,6 +3761,7 @@
if (auto* element = treeScope.getElementById(spaceSplitString[i]))
elements.append(element);
}
+ return elements;
}
#if PLATFORM(COCOA)
@@ -3905,11 +3907,10 @@
void AccessibilityObject::ariaElementsFromAttribute(AccessibilityChildrenVector& children, const QualifiedName& attributeName) const
{
- Vector<Element*> elements;
- elementsFromAttribute(elements, attributeName);
+ auto elements = elementsFromAttribute(attributeName);
AXObjectCache* cache = axObjectCache();
for (const auto& element : elements) {
- if (AccessibilityObject* axObject = cache->getOrCreate(element))
+ if (auto* axObject = cache->getOrCreate(element))
children.append(axObject);
}
}
Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.h (293297 => 293298)
--- trunk/Source/WebCore/accessibility/AccessibilityObject.h 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.h 2022-04-24 02:27:34 UTC (rev 293298)
@@ -297,7 +297,7 @@
double loadingProgress() const override { return 0; }
WEBCORE_EXPORT static bool isARIAControl(AccessibilityRole);
bool supportsCheckedState() const override;
-
+
bool supportsARIAOwns() const override { return false; }
bool isActiveDescendantOfFocusedContainer() const override;
void ariaActiveDescendantReferencingElements(AccessibilityChildrenVector&) const override;
@@ -427,7 +427,7 @@
String expandedTextValue() const override { return String(); }
bool supportsExpandedTextValue() const override { return false; }
- void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const override;
+ Vector<Element*> elementsFromAttribute(const QualifiedName&) const;
// Only if isColorWell()
SRGBA<uint8_t> colorValue() const override { return Color::transparentBlack; }
@@ -809,6 +809,7 @@
bool dispatchTouchEvent();
static bool isARIAInput(AccessibilityRole);
+
void ariaElementsFromAttribute(AccessibilityChildrenVector&, const QualifiedName&) const;
void ariaElementsReferencedByAttribute(AccessibilityChildrenVector&, const QualifiedName&) const;
virtual bool exposesTitleUIElement() const { return true; }
Modified: trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h (293297 => 293298)
--- trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h 2022-04-24 02:27:34 UTC (rev 293298)
@@ -1171,8 +1171,6 @@
virtual String expandedTextValue() const = 0;
virtual bool supportsExpandedTextValue() const = 0;
- virtual void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const = 0;
-
// Only if isColorWell()
virtual SRGBA<uint8_t> colorValue() const = 0;
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (293297 => 293298)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2022-04-24 02:27:34 UTC (rev 293298)
@@ -1802,33 +1802,31 @@
{
if (!isTabItem() || !m_renderer)
return false;
-
+
Node* node = m_renderer->node();
if (!node || !node->isElementNode())
return false;
-
+
// The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
// that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
// focus inside of it.
- AccessibilityObject* focusedElement = static_cast<AccessibilityObject*>(focusedUIElement());
+ auto* focusedElement = static_cast<AccessibilityObject*>(focusedUIElement());
if (!focusedElement)
return false;
-
- Vector<Element*> elements;
- elementsFromAttribute(elements, aria_controlsAttr);
-
- AXObjectCache* cache = axObjectCache();
+
+ auto* cache = axObjectCache();
if (!cache)
return false;
-
+
+ auto elements = elementsFromAttribute(aria_controlsAttr);
for (const auto& element : elements) {
- AccessibilityObject* tabPanel = cache->getOrCreate(element);
+ auto* tabPanel = cache->getOrCreate(element);
// A tab item should only control tab panels.
if (!tabPanel || tabPanel->roleValue() != AccessibilityRole::TabPanel)
continue;
-
- AccessibilityObject* checkFocusElement = focusedElement;
+
+ auto* checkFocusElement = focusedElement;
// Check if the focused element is a descendant of the element controlled by the tab item.
while (checkFocusElement) {
if (tabPanel == checkFocusElement)
@@ -1836,7 +1834,7 @@
checkFocusElement = checkFocusElement->parentObject();
}
}
-
+
return false;
}
Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp (293297 => 293298)
--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp 2022-04-24 02:27:34 UTC (rev 293298)
@@ -2067,11 +2067,6 @@
return false;
}
-void AXIsolatedObject::elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const
-{
- ASSERT_NOT_REACHED();
-}
-
AXObjectCache* AXIsolatedObject::axObjectCache() const
{
ASSERT(isMainThread());
Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h (293297 => 293298)
--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h 2022-04-24 02:27:34 UTC (rev 293298)
@@ -582,7 +582,6 @@
String ariaLabeledByAttribute() const override;
String ariaDescribedByAttribute() const override;
bool accessibleNameDerivesFromContent() const override;
- void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const override;
AXObjectCache* axObjectCache() const override;
Element* anchorElement() const override;
Element* actionElement() const override;
Modified: trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp (293297 => 293298)
--- trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp 2022-04-24 02:27:34 UTC (rev 293298)
@@ -51,7 +51,7 @@
{
}
-static AXCoreObject* accessiblityObjectForNode(Node& node)
+static AccessibilityObject* accessiblityObjectForNode(Node& node)
{
if (!AXObjectCache::accessibilityEnabled())
AXObjectCache::enableAccessibility();
@@ -245,11 +245,10 @@
std::optional<Vector<RefPtr<Node>>> result;
- if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
+ if (auto* axObject = accessiblityObjectForNode(node)) {
Vector<RefPtr<Node>> controlledNodes;
- Vector<Element*> controlledElements;
- axObject->elementsFromAttribute(controlledElements, HTMLNames::aria_controlsAttr);
+ auto controlledElements = axObject->elementsFromAttribute(HTMLNames::aria_controlsAttr);
for (Element* controlledElement : controlledElements) {
if (controlledElement)
controlledNodes.append(controlledElement);
@@ -267,11 +266,10 @@
std::optional<Vector<RefPtr<Node>>> result;
- if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
+ if (auto* axObject = accessiblityObjectForNode(node)) {
Vector<RefPtr<Node>> flowedNodes;
- Vector<Element*> flowedElements;
- axObject->elementsFromAttribute(flowedElements, HTMLNames::aria_flowtoAttr);
+ auto flowedElements = axObject->elementsFromAttribute(HTMLNames::aria_flowtoAttr);
for (Element* flowedElement : flowedElements) {
if (flowedElement)
flowedNodes.append(flowedElement);
@@ -287,7 +285,7 @@
{
ERROR_IF_NO_ACTIVE_AUDIT();
- if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
+ if (auto* axObject = accessiblityObjectForNode(node)) {
if (is<AccessibilityNodeObject>(axObject))
return downcast<AccessibilityNodeObject>(axObject)->mouseButtonListener(MouseButtonListenerResultFilter::IncludeBodyElement);
}
@@ -301,12 +299,11 @@
std::optional<Vector<RefPtr<Node>>> result;
- if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
+ if (auto* axObject = accessiblityObjectForNode(node)) {
if (axObject->supportsARIAOwns()) {
Vector<RefPtr<Node>> ownedNodes;
- Vector<Element*> ownedElements;
- axObject->elementsFromAttribute(ownedElements, HTMLNames::aria_ownsAttr);
+ auto ownedElements = axObject->elementsFromAttribute(HTMLNames::aria_ownsAttr);
for (Element* ownedElement : ownedElements) {
if (ownedElement)
ownedNodes.append(ownedElement);
Modified: trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp (293297 => 293298)
--- trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp 2022-04-23 23:03:32 UTC (rev 293297)
+++ trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp 2022-04-24 02:27:34 UTC (rev 293298)
@@ -2075,8 +2075,8 @@
unsigned hierarchicalLevel = 0;
unsigned level = 0;
- if (AXObjectCache* axObjectCache = node.document().axObjectCache()) {
- if (AXCoreObject* axObject = axObjectCache->getOrCreate(&node)) {
+ if (auto* axObjectCache = node.document().axObjectCache()) {
+ if (auto* axObject = axObjectCache->getOrCreate(&node)) {
if (AXCoreObject* activeDescendant = axObject->activeDescendant())
activeDescendantNode = activeDescendant->node();
@@ -2103,9 +2103,8 @@
childNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
processAccessibilityChildren(*axObject, *childNodeIds);
}
-
- Vector<Element*> controlledElements;
- axObject->elementsFromAttribute(controlledElements, aria_controlsAttr);
+
+ auto controlledElements = axObject->elementsFromAttribute(aria_controlsAttr);
if (controlledElements.size()) {
controlledNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
for (Element* controlledElement : controlledElements) {
@@ -2145,8 +2144,7 @@
if (supportsExpanded)
expanded = axObject->isExpanded();
- Vector<Element*> flowedElements;
- axObject->elementsFromAttribute(flowedElements, aria_flowtoAttr);
+ auto flowedElements = axObject->elementsFromAttribute(aria_flowtoAttr);
if (flowedElements.size()) {
flowedNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
for (Element* flowedElement : flowedElements) {
@@ -2154,7 +2152,7 @@
flowedNodeIds->addItem(flowedElementId);
}
}
-
+
if (is<Element>(node)) {
supportsFocused = axObject->canSetFocusAttribute();
if (supportsFocused)
@@ -2218,8 +2216,7 @@
mouseEventNode = downcast<AccessibilityNodeObject>(*axObject).mouseButtonListener(MouseButtonListenerResultFilter::IncludeBodyElement);
if (axObject->supportsARIAOwns()) {
- Vector<Element*> ownedElements;
- axObject->elementsFromAttribute(ownedElements, aria_ownsAttr);
+ auto ownedElements = axObject->elementsFromAttribute(aria_ownsAttr);
if (ownedElements.size()) {
ownedNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
for (Element* ownedElement : ownedElements) {