⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 293298 in webkit


Ignore:
Timestamp:
Apr 23, 2022, 7:27:34 PM (4 years ago)
Author:
Andres Gonzalez
Message:

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):

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r293297 r293298  
     12022-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
    1492022-04-23  Alan Bujtas  <zalan@apple.com>
    250
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r293006 r293298  
    17761776            return;
    17771777
    1778         Vector<Element*> elements;
    1779         ariaLabeledByElements(elements);
     1778        auto elements = ariaLabeledByElements();
    17801779
    17811780        Vector<AXCoreObject*> axElements;
     
    20792078            // This could happen when this node labels multiple child nodes and we didn't
    20802079            // skip in the above ignoredChildNode check.
    2081             Vector<Element*> labeledByElements;
    2082             downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements(labeledByElements);
     2080            auto labeledByElements = downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements();
    20832081            if (labeledByElements.contains(node))
    20842082                continue;
     
    23342332}
    23352333
    2336 String AccessibilityNodeObject::accessibilityDescriptionForElements(Vector<Element*> &elements) const
     2334String AccessibilityNodeObject::descriptionForElements(Vector<Element*>&& elements) const
    23372335{
    23382336    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()));
    23422339    return builder.toString();
    23432340}
     
    23452342String AccessibilityNodeObject::ariaDescribedByAttribute() const
    23462343{
    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
     2347Vector<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);
    23582354}
    23592355
     
    23612357String AccessibilityNodeObject::ariaLabeledByAttribute() const
    23622358{
    2363     Vector<Element*> elements;
    2364     ariaLabeledByElements(elements);
    2365 
    2366     return accessibilityDescriptionForElements(elements);
     2359    return descriptionForElements(ariaLabeledByElements());
    23672360}
    23682361
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h

    r293006 r293298  
    182182
    183183    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;
    186186    LayoutRect boundingBoxRect() const override;
    187187    String ariaDescribedByAttribute() const override;
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r293292 r293298  
    37443744}
    37453745
    3746 void AccessibilityObject::elementsFromAttribute(Vector<Element*>& elements, const QualifiedName& attribute) const
     3746Vector<Element*> AccessibilityObject::elementsFromAttribute(const QualifiedName& attribute) const
    37473747{
    37483748    Node* node = this->node();
    37493749    if (!node || !node->isElementNode())
    3750         return;
     3750        return { };
    37513751
    37523752    auto& idsString = getAttribute(attribute);
    37533753    if (idsString.isEmpty())
    3754         return;
    3755 
     3754        return { };
     3755
     3756    Vector<Element*> elements;
    37563757    auto& treeScope = node->treeScope();
    37573758    SpaceSplitString spaceSplitString(idsString, SpaceSplitString::ShouldFoldCase::No);
     
    37613762            elements.append(element);
    37623763    }
     3764    return elements;
    37633765}
    37643766
     
    39063908void AccessibilityObject::ariaElementsFromAttribute(AccessibilityChildrenVector& children, const QualifiedName& attributeName) const
    39073909{
    3908     Vector<Element*> elements;
    3909     elementsFromAttribute(elements, attributeName);
     3910    auto elements = elementsFromAttribute(attributeName);
    39103911    AXObjectCache* cache = axObjectCache();
    39113912    for (const auto& element : elements) {
    3912         if (AccessibilityObject* axObject = cache->getOrCreate(element))
     3913        if (auto* axObject = cache->getOrCreate(element))
    39133914            children.append(axObject);
    39143915    }
  • trunk/Source/WebCore/accessibility/AccessibilityObject.h

    r293292 r293298  
    298298    WEBCORE_EXPORT static bool isARIAControl(AccessibilityRole);
    299299    bool supportsCheckedState() const override;
    300    
     300
    301301    bool supportsARIAOwns() const override { return false; }
    302302    bool isActiveDescendantOfFocusedContainer() const override;
     
    428428    bool supportsExpandedTextValue() const override { return false; }
    429429
    430     void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const override;
     430    Vector<Element*> elementsFromAttribute(const QualifiedName&) const;
    431431
    432432    // Only if isColorWell()
     
    810810
    811811    static bool isARIAInput(AccessibilityRole);
     812
    812813    void ariaElementsFromAttribute(AccessibilityChildrenVector&, const QualifiedName&) const;
    813814    void ariaElementsReferencedByAttribute(AccessibilityChildrenVector&, const QualifiedName&) const;
  • trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h

    r293292 r293298  
    11721172    virtual bool supportsExpandedTextValue() const = 0;
    11731173
    1174     virtual void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const = 0;
    1175 
    11761174    // Only if isColorWell()
    11771175    virtual SRGBA<uint8_t> colorValue() const = 0;
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r293291 r293298  
    18031803    if (!isTabItem() || !m_renderer)
    18041804        return false;
    1805    
     1805
    18061806    Node* node = m_renderer->node();
    18071807    if (!node || !node->isElementNode())
    18081808        return false;
    1809    
     1809
    18101810    // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
    18111811    // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
    18121812    // focus inside of it.
    1813     AccessibilityObject* focusedElement = static_cast<AccessibilityObject*>(focusedUIElement());
     1813    auto* focusedElement = static_cast<AccessibilityObject*>(focusedUIElement());
    18141814    if (!focusedElement)
    18151815        return false;
    1816    
    1817     Vector<Element*> elements;
    1818     elementsFromAttribute(elements, aria_controlsAttr);
    1819    
    1820     AXObjectCache* cache = axObjectCache();
     1816
     1817    auto* cache = axObjectCache();
    18211818    if (!cache)
    18221819        return false;
    1823    
     1820
     1821    auto elements = elementsFromAttribute(aria_controlsAttr);
    18241822    for (const auto& element : elements) {
    1825         AccessibilityObject* tabPanel = cache->getOrCreate(element);
     1823        auto* tabPanel = cache->getOrCreate(element);
    18261824
    18271825        // A tab item should only control tab panels.
    18281826        if (!tabPanel || tabPanel->roleValue() != AccessibilityRole::TabPanel)
    18291827            continue;
    1830        
    1831         AccessibilityObject* checkFocusElement = focusedElement;
     1828
     1829        auto* checkFocusElement = focusedElement;
    18321830        // Check if the focused element is a descendant of the element controlled by the tab item.
    18331831        while (checkFocusElement) {
     
    18371835        }
    18381836    }
    1839    
     1837
    18401838    return false;
    18411839}
  • trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp

    r293292 r293298  
    20682068}
    20692069
    2070 void AXIsolatedObject::elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const
    2071 {
    2072     ASSERT_NOT_REACHED();
    2073 }
    2074 
    20752070AXObjectCache* AXIsolatedObject::axObjectCache() const
    20762071{
  • trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h

    r293292 r293298  
    583583    String ariaDescribedByAttribute() const override;
    584584    bool accessibleNameDerivesFromContent() const override;
    585     void elementsFromAttribute(Vector<Element*>&, const QualifiedName&) const override;
    586585    AXObjectCache* axObjectCache() const override;
    587586    Element* anchorElement() const override;
  • trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp

    r292963 r293298  
    5252}
    5353
    54 static AXCoreObject* accessiblityObjectForNode(Node& node)
     54static AccessibilityObject* accessiblityObjectForNode(Node& node)
    5555{
    5656    if (!AXObjectCache::accessibilityEnabled())
     
    246246    std::optional<Vector<RefPtr<Node>>> result;
    247247
    248     if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
     248    if (auto* axObject = accessiblityObjectForNode(node)) {
    249249        Vector<RefPtr<Node>> controlledNodes;
    250250
    251         Vector<Element*> controlledElements;
    252         axObject->elementsFromAttribute(controlledElements, HTMLNames::aria_controlsAttr);
     251        auto controlledElements = axObject->elementsFromAttribute(HTMLNames::aria_controlsAttr);
    253252        for (Element* controlledElement : controlledElements) {
    254253            if (controlledElement)
     
    268267    std::optional<Vector<RefPtr<Node>>> result;
    269268
    270     if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
     269    if (auto* axObject = accessiblityObjectForNode(node)) {
    271270        Vector<RefPtr<Node>> flowedNodes;
    272271
    273         Vector<Element*> flowedElements;
    274         axObject->elementsFromAttribute(flowedElements, HTMLNames::aria_flowtoAttr);
     272        auto flowedElements = axObject->elementsFromAttribute(HTMLNames::aria_flowtoAttr);
    275273        for (Element* flowedElement : flowedElements) {
    276274            if (flowedElement)
     
    288286    ERROR_IF_NO_ACTIVE_AUDIT();
    289287
    290     if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
     288    if (auto* axObject = accessiblityObjectForNode(node)) {
    291289        if (is<AccessibilityNodeObject>(axObject))
    292290            return downcast<AccessibilityNodeObject>(axObject)->mouseButtonListener(MouseButtonListenerResultFilter::IncludeBodyElement);
     
    302300    std::optional<Vector<RefPtr<Node>>> result;
    303301
    304     if (AXCoreObject* axObject = accessiblityObjectForNode(node)) {
     302    if (auto* axObject = accessiblityObjectForNode(node)) {
    305303        if (axObject->supportsARIAOwns()) {
    306304            Vector<RefPtr<Node>> ownedNodes;
    307305
    308             Vector<Element*> ownedElements;
    309             axObject->elementsFromAttribute(ownedElements, HTMLNames::aria_ownsAttr);
     306            auto ownedElements = axObject->elementsFromAttribute(HTMLNames::aria_ownsAttr);
    310307            for (Element* ownedElement : ownedElements) {
    311308                if (ownedElement)
  • trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp

    r292963 r293298  
    20762076    unsigned level = 0;
    20772077
    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)) {
    20802080
    20812081            if (AXCoreObject* activeDescendant = axObject->activeDescendant())
     
    21042104                processAccessibilityChildren(*axObject, *childNodeIds);
    21052105            }
    2106            
    2107             Vector<Element*> controlledElements;
    2108             axObject->elementsFromAttribute(controlledElements, aria_controlsAttr);
     2106
     2107            auto controlledElements = axObject->elementsFromAttribute(aria_controlsAttr);
    21092108            if (controlledElements.size()) {
    21102109                controlledNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
     
    21462145                expanded = axObject->isExpanded();
    21472146
    2148             Vector<Element*> flowedElements;
    2149             axObject->elementsFromAttribute(flowedElements, aria_flowtoAttr);
     2147            auto flowedElements = axObject->elementsFromAttribute(aria_flowtoAttr);
    21502148            if (flowedElements.size()) {
    21512149                flowedNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
     
    21552153                }
    21562154            }
    2157            
     2155
    21582156            if (is<Element>(node)) {
    21592157                supportsFocused = axObject->canSetFocusAttribute();
     
    22192217
    22202218            if (axObject->supportsARIAOwns()) {
    2221                 Vector<Element*> ownedElements;
    2222                 axObject->elementsFromAttribute(ownedElements, aria_ownsAttr);
     2219                auto ownedElements = axObject->elementsFromAttribute(aria_ownsAttr);
    22232220                if (ownedElements.size()) {
    22242221                    ownedNodeIds = JSON::ArrayOf<Protocol::DOM::NodeId>::create();
Note: See TracChangeset for help on using the changeset viewer.