Changeset 293298 in webkit
- Timestamp:
- Apr 23, 2022, 7:27:34 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
-
ChangeLog (modified) (1 diff)
-
accessibility/AccessibilityNodeObject.cpp (modified) (5 diffs)
-
accessibility/AccessibilityNodeObject.h (modified) (1 diff)
-
accessibility/AccessibilityObject.cpp (modified) (3 diffs)
-
accessibility/AccessibilityObject.h (modified) (3 diffs)
-
accessibility/AccessibilityObjectInterface.h (modified) (1 diff)
-
accessibility/AccessibilityRenderObject.cpp (modified) (2 diffs)
-
accessibility/isolatedtree/AXIsolatedObject.cpp (modified) (1 diff)
-
accessibility/isolatedtree/AXIsolatedObject.h (modified) (1 diff)
-
inspector/InspectorAuditAccessibilityObject.cpp (modified) (5 diffs)
-
inspector/agents/InspectorDOMAgent.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r293297 r293298 1 2022-04-23 Andres Gonzalez <andresg_22@apple.com> 2 3 Code cleanup in preparation for optimizing use of AccessibilityObject::elementsFromAttribute. 4 https://bugs.webkit.org/show_bug.cgi?id=239664 5 <rdar://problem/92180286> 6 7 Reviewed by Chris Fleizach. 8 9 No new functionality. 10 11 AccessibilityObject::elementsFromAttribute now returns a vector as 12 opposed to taking an out parameter. This makes the code more concise 13 and possibly more efficient. 14 Removed this method from the AXCoreObject interface, since this method 15 should not be exposed to an AT client. The Inspector is an exception 16 that accesses AccessibilityObjects directly and not through the 17 AXCoreObject interface. 18 All these changes are entirely code cleanup and modernization, no change 19 in functionality. 20 21 * accessibility/AccessibilityNodeObject.cpp: 22 (WebCore::AccessibilityNodeObject::ariaLabeledByText const): 23 (WebCore::AccessibilityNodeObject::textUnderElement const): 24 (WebCore::AccessibilityNodeObject::descriptionForElements const): 25 (WebCore::AccessibilityNodeObject::ariaDescribedByAttribute const): 26 (WebCore::AccessibilityNodeObject::ariaLabeledByAttribute const): 27 (WebCore::AccessibilityNodeObject::accessibilityDescriptionForElements const): Renamed. 28 (WebCore::AccessibilityNodeObject::ariaLabeledByElements const): Deleted. 29 * accessibility/AccessibilityNodeObject.h: 30 * accessibility/AccessibilityObject.cpp: 31 (WebCore::AccessibilityObject::ariaElementsFromAttribute const): 32 (WebCore::AccessibilityObject::elementsFromAttribute const): 33 * accessibility/AccessibilityObject.h: 34 * accessibility/AccessibilityObjectInterface.h: 35 * accessibility/AccessibilityRenderObject.cpp: 36 (WebCore::AccessibilityRenderObject::isTabItemSelected const): 37 * accessibility/isolatedtree/AXIsolatedObject.cpp: 38 (WebCore::AXIsolatedObject::elementsFromAttribute const): Deleted. 39 * accessibility/isolatedtree/AXIsolatedObject.h: 40 * inspector/InspectorAuditAccessibilityObject.cpp: 41 (WebCore::accessiblityObjectForNode): 42 (WebCore::InspectorAuditAccessibilityObject::getControlledNodes): 43 (WebCore::InspectorAuditAccessibilityObject::getFlowedNodes): 44 (WebCore::InspectorAuditAccessibilityObject::getMouseEventNode): 45 (WebCore::InspectorAuditAccessibilityObject::getOwnedNodes): 46 * inspector/agents/InspectorDOMAgent.cpp: 47 (WebCore::InspectorDOMAgent::buildObjectForAccessibilityProperties): 48 1 49 2022-04-23 Alan Bujtas <zalan@apple.com> 2 50 -
trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp
r293006 r293298 1776 1776 return; 1777 1777 1778 Vector<Element*> elements; 1779 ariaLabeledByElements(elements); 1778 auto elements = ariaLabeledByElements(); 1780 1779 1781 1780 Vector<AXCoreObject*> axElements; … … 2079 2078 // This could happen when this node labels multiple child nodes and we didn't 2080 2079 // skip in the above ignoredChildNode check. 2081 Vector<Element*> labeledByElements; 2082 downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements(labeledByElements); 2080 auto labeledByElements = downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements(); 2083 2081 if (labeledByElements.contains(node)) 2084 2082 continue; … … 2334 2332 } 2335 2333 2336 String AccessibilityNodeObject:: accessibilityDescriptionForElements(Vector<Element*> &elements) const2334 String AccessibilityNodeObject::descriptionForElements(Vector<Element*>&& elements) const 2337 2335 { 2338 2336 StringBuilder builder; 2339 unsigned size = elements.size(); 2340 for (unsigned i = 0; i < size; ++i) 2341 appendNameToStringBuilder(builder, accessibleNameForNode(elements[i], node())); 2337 for (auto* element : elements) 2338 appendNameToStringBuilder(builder, accessibleNameForNode(element, node())); 2342 2339 return builder.toString(); 2343 2340 } … … 2345 2342 String AccessibilityNodeObject::ariaDescribedByAttribute() const 2346 2343 { 2347 Vector<Element*> elements; 2348 elementsFromAttribute(elements, aria_describedbyAttr); 2349 2350 return accessibilityDescriptionForElements(elements); 2351 } 2352 2353 void AccessibilityNodeObject::ariaLabeledByElements(Vector<Element*>& elements) const 2354 { 2355 elementsFromAttribute(elements, aria_labelledbyAttr); 2356 if (!elements.size()) 2357 elementsFromAttribute(elements, aria_labeledbyAttr); 2344 return descriptionForElements(elementsFromAttribute(aria_describedbyAttr)); 2345 } 2346 2347 Vector<Element*> AccessibilityNodeObject::ariaLabeledByElements() const 2348 { 2349 // FIXME: should walk the DOM elements only once. 2350 auto elements = elementsFromAttribute(aria_labelledbyAttr); 2351 if (elements.size()) 2352 return elements; 2353 return elementsFromAttribute(aria_labeledbyAttr); 2358 2354 } 2359 2355 … … 2361 2357 String AccessibilityNodeObject::ariaLabeledByAttribute() const 2362 2358 { 2363 Vector<Element*> elements; 2364 ariaLabeledByElements(elements); 2365 2366 return accessibilityDescriptionForElements(elements); 2359 return descriptionForElements(ariaLabeledByElements()); 2367 2360 } 2368 2361 -
trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h
r293006 r293298 182 182 183 183 String ariaAccessibilityDescription() const; 184 void ariaLabeledByElements(Vector<Element*>& elements) const;185 String accessibilityDescriptionForElements(Vector<Element*> &elements) const;184 Vector<Element*> ariaLabeledByElements() const; 185 String descriptionForElements(Vector<Element*>&&) const; 186 186 LayoutRect boundingBoxRect() const override; 187 187 String ariaDescribedByAttribute() const override; -
trunk/Source/WebCore/accessibility/AccessibilityObject.cpp
r293292 r293298 3744 3744 } 3745 3745 3746 void AccessibilityObject::elementsFromAttribute(Vector<Element*>& elements,const QualifiedName& attribute) const3746 Vector<Element*> AccessibilityObject::elementsFromAttribute(const QualifiedName& attribute) const 3747 3747 { 3748 3748 Node* node = this->node(); 3749 3749 if (!node || !node->isElementNode()) 3750 return ;3750 return { }; 3751 3751 3752 3752 auto& idsString = getAttribute(attribute); 3753 3753 if (idsString.isEmpty()) 3754 return; 3755 3754 return { }; 3755 3756 Vector<Element*> elements; 3756 3757 auto& treeScope = node->treeScope(); 3757 3758 SpaceSplitString spaceSplitString(idsString, SpaceSplitString::ShouldFoldCase::No); … … 3761 3762 elements.append(element); 3762 3763 } 3764 return elements; 3763 3765 } 3764 3766 … … 3906 3908 void AccessibilityObject::ariaElementsFromAttribute(AccessibilityChildrenVector& children, const QualifiedName& attributeName) const 3907 3909 { 3908 Vector<Element*> elements; 3909 elementsFromAttribute(elements, attributeName); 3910 auto elements = elementsFromAttribute(attributeName); 3910 3911 AXObjectCache* cache = axObjectCache(); 3911 3912 for (const auto& element : elements) { 3912 if ( AccessibilityObject* axObject = cache->getOrCreate(element))3913 if (auto* axObject = cache->getOrCreate(element)) 3913 3914 children.append(axObject); 3914 3915 } -
trunk/Source/WebCore/accessibility/AccessibilityObject.h
r293292 r293298 298 298 WEBCORE_EXPORT static bool isARIAControl(AccessibilityRole); 299 299 bool supportsCheckedState() const override; 300 300 301 301 bool supportsARIAOwns() const override { return false; } 302 302 bool isActiveDescendantOfFocusedContainer() const override; … … 428 428 bool supportsExpandedTextValue() const override { return false; } 429 429 430 void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const override;430 Vector<Element*> elementsFromAttribute(const QualifiedName&) const; 431 431 432 432 // Only if isColorWell() … … 810 810 811 811 static bool isARIAInput(AccessibilityRole); 812 812 813 void ariaElementsFromAttribute(AccessibilityChildrenVector&, const QualifiedName&) const; 813 814 void ariaElementsReferencedByAttribute(AccessibilityChildrenVector&, const QualifiedName&) const; -
trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h
r293292 r293298 1172 1172 virtual bool supportsExpandedTextValue() const = 0; 1173 1173 1174 virtual void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const = 0;1175 1176 1174 // Only if isColorWell() 1177 1175 virtual SRGBA<uint8_t> colorValue() const = 0; -
trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
r293291 r293298 1803 1803 if (!isTabItem() || !m_renderer) 1804 1804 return false; 1805 1805 1806 1806 Node* node = m_renderer->node(); 1807 1807 if (!node || !node->isElementNode()) 1808 1808 return false; 1809 1809 1810 1810 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel 1811 1811 // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB 1812 1812 // focus inside of it. 1813 AccessibilityObject* focusedElement = static_cast<AccessibilityObject*>(focusedUIElement());1813 auto* focusedElement = static_cast<AccessibilityObject*>(focusedUIElement()); 1814 1814 if (!focusedElement) 1815 1815 return false; 1816 1817 Vector<Element*> elements; 1818 elementsFromAttribute(elements, aria_controlsAttr); 1819 1820 AXObjectCache* cache = axObjectCache(); 1816 1817 auto* cache = axObjectCache(); 1821 1818 if (!cache) 1822 1819 return false; 1823 1820 1821 auto elements = elementsFromAttribute(aria_controlsAttr); 1824 1822 for (const auto& element : elements) { 1825 AccessibilityObject* tabPanel = cache->getOrCreate(element);1823 auto* tabPanel = cache->getOrCreate(element); 1826 1824 1827 1825 // A tab item should only control tab panels. 1828 1826 if (!tabPanel || tabPanel->roleValue() != AccessibilityRole::TabPanel) 1829 1827 continue; 1830 1831 AccessibilityObject* checkFocusElement = focusedElement;1828 1829 auto* checkFocusElement = focusedElement; 1832 1830 // Check if the focused element is a descendant of the element controlled by the tab item. 1833 1831 while (checkFocusElement) { … … 1837 1835 } 1838 1836 } 1839 1837 1840 1838 return false; 1841 1839 } -
trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp
r293292 r293298 2068 2068 } 2069 2069 2070 void AXIsolatedObject::elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const2071 {2072 ASSERT_NOT_REACHED();2073 }2074 2075 2070 AXObjectCache* AXIsolatedObject::axObjectCache() const 2076 2071 { -
trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h
r293292 r293298 583 583 String ariaDescribedByAttribute() const override; 584 584 bool accessibleNameDerivesFromContent() const override; 585 void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const override;586 585 AXObjectCache* axObjectCache() const override; 587 586 Element* anchorElement() const override; -
trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp
r292963 r293298 52 52 } 53 53 54 static A XCoreObject* accessiblityObjectForNode(Node& node)54 static AccessibilityObject* accessiblityObjectForNode(Node& node) 55 55 { 56 56 if (!AXObjectCache::accessibilityEnabled()) … … 246 246 std::optional<Vector<RefPtr<Node>>> result; 247 247 248 if ( AXCoreObject* axObject = accessiblityObjectForNode(node)) {248 if (auto* axObject = accessiblityObjectForNode(node)) { 249 249 Vector<RefPtr<Node>> controlledNodes; 250 250 251 Vector<Element*> controlledElements; 252 axObject->elementsFromAttribute(controlledElements, HTMLNames::aria_controlsAttr); 251 auto controlledElements = axObject->elementsFromAttribute(HTMLNames::aria_controlsAttr); 253 252 for (Element* controlledElement : controlledElements) { 254 253 if (controlledElement) … … 268 267 std::optional<Vector<RefPtr<Node>>> result; 269 268 270 if ( AXCoreObject* axObject = accessiblityObjectForNode(node)) {269 if (auto* axObject = accessiblityObjectForNode(node)) { 271 270 Vector<RefPtr<Node>> flowedNodes; 272 271 273 Vector<Element*> flowedElements; 274 axObject->elementsFromAttribute(flowedElements, HTMLNames::aria_flowtoAttr); 272 auto flowedElements = axObject->elementsFromAttribute(HTMLNames::aria_flowtoAttr); 275 273 for (Element* flowedElement : flowedElements) { 276 274 if (flowedElement) … … 288 286 ERROR_IF_NO_ACTIVE_AUDIT(); 289 287 290 if ( AXCoreObject* axObject = accessiblityObjectForNode(node)) {288 if (auto* axObject = accessiblityObjectForNode(node)) { 291 289 if (is<AccessibilityNodeObject>(axObject)) 292 290 return downcast<AccessibilityNodeObject>(axObject)->mouseButtonListener(MouseButtonListenerResultFilter::IncludeBodyElement); … … 302 300 std::optional<Vector<RefPtr<Node>>> result; 303 301 304 if ( AXCoreObject* axObject = accessiblityObjectForNode(node)) {302 if (auto* axObject = accessiblityObjectForNode(node)) { 305 303 if (axObject->supportsARIAOwns()) { 306 304 Vector<RefPtr<Node>> ownedNodes; 307 305 308 Vector<Element*> ownedElements; 309 axObject->elementsFromAttribute(ownedElements, HTMLNames::aria_ownsAttr); 306 auto ownedElements = axObject->elementsFromAttribute(HTMLNames::aria_ownsAttr); 310 307 for (Element* ownedElement : ownedElements) { 311 308 if (ownedElement) -
trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
r292963 r293298 2076 2076 unsigned level = 0; 2077 2077 2078 if ( AXObjectCache* axObjectCache = node.document().axObjectCache()) {2079 if ( AXCoreObject* axObject = axObjectCache->getOrCreate(&node)) {2078 if (auto* axObjectCache = node.document().axObjectCache()) { 2079 if (auto* axObject = axObjectCache->getOrCreate(&node)) { 2080 2080 2081 2081 if (AXCoreObject* activeDescendant = axObject->activeDescendant()) … … 2104 2104 processAccessibilityChildren(*axObject, *childNodeIds); 2105 2105 } 2106 2107 Vector<Element*> controlledElements; 2108 axObject->elementsFromAttribute(controlledElements, aria_controlsAttr); 2106 2107 auto controlledElements = axObject->elementsFromAttribute(aria_controlsAttr); 2109 2108 if (controlledElements.size()) { 2110 2109 controlledNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create(); … … 2146 2145 expanded = axObject->isExpanded(); 2147 2146 2148 Vector<Element*> flowedElements; 2149 axObject->elementsFromAttribute(flowedElements, aria_flowtoAttr); 2147 auto flowedElements = axObject->elementsFromAttribute(aria_flowtoAttr); 2150 2148 if (flowedElements.size()) { 2151 2149 flowedNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create(); … … 2155 2153 } 2156 2154 } 2157 2155 2158 2156 if (is<Element>(node)) { 2159 2157 supportsFocused = axObject->canSetFocusAttribute(); … … 2219 2217 2220 2218 if (axObject->supportsARIAOwns()) { 2221 Vector<Element*> ownedElements; 2222 axObject->elementsFromAttribute(ownedElements, aria_ownsAttr); 2219 auto ownedElements = axObject->elementsFromAttribute(aria_ownsAttr); 2223 2220 if (ownedElements.size()) { 2224 2221 ownedNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
Note:
See TracChangeset
for help on using the changeset viewer.