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

Changeset 284606 in webkit


Ignore:
Timestamp:
Oct 21, 2021, 9:27:29 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

AX: Any addition of children should funnel through AccessibilityObject::addChild
https://bugs.webkit.org/show_bug.cgi?id=231914

Patch by Tyler Wilcock <Tyler Wilcock> on 2021-10-21
Reviewed by Chris Fleizach.

All addition of children now goes through
AccessibilityObject::addChild. This is good for two reasons:

  1. It ensures we aren't inserting ignored elements into the tree.

insertChild (downstream of addChild) checks this. Prior to this
patch, there were cases where we could insert ignored children into the
tree because no check was made.

  1. We can reliably set state on the child based on the state of the

parent at insertion time. For example, children can set a flag if
any of their ancestors have an application or document role, which can
be useful for some AX clients.

  • accessibility/AccessibilityARIAGrid.cpp:

(WebCore::AccessibilityARIAGrid::addTableCellChild):
(WebCore::AccessibilityARIAGrid::addChildren):

  • accessibility/AccessibilityListBox.cpp:

(WebCore::AccessibilityListBox::addChildren):

  • accessibility/AccessibilityMenuList.cpp:

(WebCore::AccessibilityMenuList::addChildren):

  • accessibility/AccessibilityMenuListPopup.cpp:

(WebCore::AccessibilityMenuListPopup::addChildren):

  • accessibility/AccessibilityObject.cpp:

(WebCore::isAutofillButton):
(WebCore::isTableComponent):
(WebCore::AccessibilityObject::insertChild):

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::addImageMapChildren):
(WebCore::AccessibilityRenderObject::addTextFieldChildren):
(WebCore::AccessibilityRenderObject::addRemoteSVGChildren):

  • accessibility/AccessibilityScrollView.cpp:

(WebCore::AccessibilityScrollView::addChildScrollbar):

  • accessibility/AccessibilitySlider.cpp:

(WebCore::AccessibilitySlider::addChildren):

  • accessibility/AccessibilitySpinButton.cpp:

(WebCore::AccessibilitySpinButton::addChildren):

  • accessibility/AccessibilityTable.cpp:

(WebCore::AccessibilityTable::addChildren):
(WebCore::AccessibilityTable::addTableCellChild):

  • accessibility/AccessibilityTableColumn.cpp:

(WebCore::AccessibilityTableColumn::addChildren):

  • accessibility/AccessibilityTableHeaderContainer.cpp:

(WebCore::AccessibilityTableHeaderContainer::addChildren):

  • accessibility/AccessibilityTableRow.cpp:

(WebCore::AccessibilityTableRow::addChildren):

Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284604 r284606  
     12021-10-21  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: Any addition of children should funnel through AccessibilityObject::addChild
     4        https://bugs.webkit.org/show_bug.cgi?id=231914
     5
     6        Reviewed by Chris Fleizach.
     7
     8        All addition of children now goes through
     9        AccessibilityObject::addChild. This is good for two reasons:
     10
     11        1. It ensures we aren't inserting ignored elements into the tree.
     12        `insertChild` (downstream of `addChild`) checks this. Prior to this
     13        patch, there were cases where we could insert ignored children into the
     14        tree because no check was made.
     15
     16        2. We can reliably set state on the child based on the state of the
     17        parent at insertion time. For example, children can set a flag if
     18        any of their ancestors have an application or document role, which can
     19        be useful for some AX clients.
     20
     21        * accessibility/AccessibilityARIAGrid.cpp:
     22        (WebCore::AccessibilityARIAGrid::addTableCellChild):
     23        (WebCore::AccessibilityARIAGrid::addChildren):
     24        * accessibility/AccessibilityListBox.cpp:
     25        (WebCore::AccessibilityListBox::addChildren):
     26        * accessibility/AccessibilityMenuList.cpp:
     27        (WebCore::AccessibilityMenuList::addChildren):
     28        * accessibility/AccessibilityMenuListPopup.cpp:
     29        (WebCore::AccessibilityMenuListPopup::addChildren):
     30        * accessibility/AccessibilityObject.cpp:
     31        (WebCore::isAutofillButton):
     32        (WebCore::isTableComponent):
     33        (WebCore::AccessibilityObject::insertChild):
     34        * accessibility/AccessibilityRenderObject.cpp:
     35        (WebCore::AccessibilityRenderObject::addImageMapChildren):
     36        (WebCore::AccessibilityRenderObject::addTextFieldChildren):
     37        (WebCore::AccessibilityRenderObject::addRemoteSVGChildren):
     38        * accessibility/AccessibilityScrollView.cpp:
     39        (WebCore::AccessibilityScrollView::addChildScrollbar):
     40        * accessibility/AccessibilitySlider.cpp:
     41        (WebCore::AccessibilitySlider::addChildren):
     42        * accessibility/AccessibilitySpinButton.cpp:
     43        (WebCore::AccessibilitySpinButton::addChildren):
     44        * accessibility/AccessibilityTable.cpp:
     45        (WebCore::AccessibilityTable::addChildren):
     46        (WebCore::AccessibilityTable::addTableCellChild):
     47        * accessibility/AccessibilityTableColumn.cpp:
     48        (WebCore::AccessibilityTableColumn::addChildren):
     49        * accessibility/AccessibilityTableHeaderContainer.cpp:
     50        (WebCore::AccessibilityTableHeaderContainer::addChildren):
     51        * accessibility/AccessibilityTableRow.cpp:
     52        (WebCore::AccessibilityTableRow::addChildren):
     53
    1542021-10-21  Antti Koivisto  <antti@apple.com>
    255
  • trunk/Source/WebCore/accessibility/AccessibilityARIAGrid.cpp

    r265514 r284606  
    6868    row.setRowIndex((int)m_rows.size());
    6969    m_rows.append(&row);
    70 
    71     // Try adding the row if it's not ignoring accessibility,
    72     // otherwise add its children (the cells) as the grid's children.
    73     if (!row.accessibilityIsIgnored())
    74         m_children.append(&row);
    75     else
    76         m_children.appendVector(row.children());
    77 
     70    addChild(&row);
    7871    appendedRows.add(&row);
    7972    return true;
     
    143136        column.setParent(this);
    144137        m_columns.append(&column);
    145         if (!column.accessibilityIsIgnored())
    146             m_children.append(&column);
     138        addChild(&column);
    147139    }
    148140
    149     auto* headerContainerObject = headerContainer();
    150     if (headerContainerObject && !headerContainerObject->accessibilityIsIgnored())
    151         m_children.append(headerContainerObject);
     141    addChild(headerContainer());
    152142}
    153143   
  • trunk/Source/WebCore/accessibility/AccessibilityListBox.cpp

    r268454 r284606  
    7474    m_haveChildren = true;
    7575
    76     for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems()) {
    77         AccessibilityObject* listOption = listBoxOptionAccessibilityObject(listItem);
    78         if (listOption && !listOption->accessibilityIsIgnored())
    79             m_children.append(listOption);
    80     }
     76    for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems())
     77        addChild(listBoxOptionAccessibilityObject(listItem));
    8178}
    8279
  • trunk/Source/WebCore/accessibility/AccessibilityMenuList.cpp

    r277660 r284606  
    8383
    8484    m_haveChildren = true;
    85     m_children.append(list);
    86 
     85    addChild(list);
    8786    list->addChildren();
    8887}
  • trunk/Source/WebCore/accessibility/AccessibilityMenuListPopup.cpp

    r266805 r284606  
    9797    m_haveChildren = true;
    9898
    99     for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems()) {
    100         // FIXME: Why does AccessibilityListBox::addChildren check accessibilityIsIgnored but this does not?
    101         if (auto option = menuListOptionAccessibilityObject(listItem))
    102             m_children.append(option);
    103     }
     99    for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems())
     100        addChild(menuListOptionAccessibilityObject(listItem));
    104101}
    105102
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r284529 r284606  
    484484        results.append(object);
    485485}
    486    
     486
     487#ifndef NDEBUG
     488static bool isTableComponent(AXCoreObject& axObject)
     489{
     490    return axObject.isTable() || axObject.isTableColumn() || axObject.isTableRow() || axObject.isTableCell();
     491}
     492#endif
     493
    487494void AccessibilityObject::insertChild(AXCoreObject* child, unsigned index)
    488495{
     
    517524            m_children.insert(index + i, children[i]);
    518525    } else {
    519         ASSERT(child->parentObject() == this);
     526        // Table component child-parent relationships often don't line up properly, hence the need for methods
     527        // like parentTable() and parentRow(). Exclude them from this ASSERT.
     528        ASSERT((!isTableComponent(*child) && !isTableComponent(*this)) ? child->parentObject() == this : true);
    520529        m_children.insert(index, child);
    521530    }
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r284524 r284606  
    32843284        areaObject.setParent(this);
    32853285        if (!areaObject.accessibilityIsIgnored())
    3286             m_children.append(&areaObject);
     3286            addChild(&areaObject);
    32873287        else
    32883288            axObjectCache()->remove(areaObject.objectID());
     
    33173317    axSpinButton.setSpinButtonElement(downcast<SpinButtonElement>(spinButtonElement));
    33183318    axSpinButton.setParent(this);
    3319     m_children.append(&axSpinButton);
     3319    addChild(&axSpinButton);
    33203320}
    33213321   
     
    33813381    // the parent must be set, because there's no other way to get back to who created the image.
    33823382    root->setParent(this);
    3383    
    3384     if (root->accessibilityIsIgnored()) {
    3385         for (const auto& child : root->children())
    3386             m_children.append(child);
    3387     } else
    3388         m_children.append(root);
     3383    addChild(root);
    33893384}
    33903385
  • trunk/Source/WebCore/accessibility/AccessibilityScrollView.cpp

    r284009 r284606  
    164164    auto& scrollBarObject = downcast<AccessibilityScrollbar>(*cache->getOrCreate(scrollbar));
    165165    scrollBarObject.setParent(this);
    166     m_children.append(&scrollBarObject);
     166    addChild(&scrollBarObject);
    167167    return &scrollBarObject;
    168168}
  • trunk/Source/WebCore/accessibility/AccessibilitySlider.cpp

    r283269 r284606  
    101101        cache->remove(thumb.objectID());
    102102    else
    103         m_children.append(&thumb);
     103        addChild(&thumb);
    104104}
    105105
  • trunk/Source/WebCore/accessibility/AccessibilitySpinButton.cpp

    r265514 r284606  
    9292    incrementor.setIsIncrementor(true);
    9393    incrementor.setParent(this);
    94     m_children.append(&incrementor);
     94    addChild(&incrementor);
    9595
    9696    auto& decrementor = downcast<AccessibilitySpinButtonPart>(*cache->create(AccessibilityRole::SpinButtonPart));
    9797    decrementor.setIsIncrementor(false);
    9898    decrementor.setParent(this);
    99     m_children.append(&decrementor);
     99    addChild(&decrementor);
    100100}
    101101   
  • trunk/Source/WebCore/accessibility/AccessibilityTable.cpp

    r277269 r284606  
    395395        if (auto caption = tableElement->caption()) {
    396396            AccessibilityObject* axCaption = axObjectCache()->getOrCreate(caption.get());
     397            // While `addChild` won't insert ignored children, we still need this accessibilityIsIgnored
     398            // check so that `addChild` doesn't try to add the caption's children in its stead. Basically,
     399            // explicitly checking accessibilityIsIgnored() ignores the caption and any of its children.
    397400            if (axCaption && !axCaption->accessibilityIsIgnored())
    398                 m_children.append(axCaption);
     401                addChild(axCaption);
    399402        }
    400403    }
     
    421424        column.setParent(this);
    422425        m_columns.append(&column);
    423         if (!column.accessibilityIsIgnored())
    424             m_children.append(&column);
    425     }
    426 
    427     auto* headerContainerObject = headerContainer();
    428     if (headerContainerObject && !headerContainerObject->accessibilityIsIgnored())
    429         m_children.append(headerContainerObject);
     426        addChild(&column);
     427    }
     428    addChild(headerContainer());
    430429
    431430    // Sometimes the cell gets the wrong role initially because it is created before the parent
     
    452451    row.setRowIndex(static_cast<int>(m_rows.size()));
    453452    m_rows.append(&row);
    454     if (!row.accessibilityIsIgnored())
    455         m_children.append(&row);
     453    addChild(&row);
    456454    appendedRows.add(&row);
    457455       
  • trunk/Source/WebCore/accessibility/AccessibilityTableColumn.cpp

    r261729 r284606  
    203203            continue;
    204204           
    205         m_children.append(cell);
     205        addChild(cell);
    206206    }
    207207}
  • trunk/Source/WebCore/accessibility/AccessibilityTableHeaderContainer.cpp

    r257200 r284606  
    7474        return;
    7575
    76     m_children = parentTable.columnHeaders();
     76    for (auto& columnHeader : parentTable.columnHeaders())
     77        addChild(columnHeader.get());
    7778
    7879    for (const auto& child : m_children)
  • trunk/Source/WebCore/accessibility/AccessibilityTableRow.cpp

    r277269 r284606  
    110110    return nullptr;
    111111}
    112    
     112
    113113AXCoreObject* AccessibilityTableRow::headerObject()
    114114{
     
    151151{
    152152    // If the element specifies its cells through aria-owns, return that first.
    153     AccessibilityChildrenVector ariaOwns;
    154     ariaOwnsElements(ariaOwns);
    155     if (ariaOwns.size())
    156         m_children = WTFMove(ariaOwns);
     153    AccessibilityChildrenVector ariaOwnedElements;
     154    ariaOwnsElements(ariaOwnedElements);
     155    if (ariaOwnedElements.size()) {
     156        for (auto& ariaOwnedElement : ariaOwnedElements)
     157            addChild(ariaOwnedElement.get());
     158    }
    157159    else
    158160        AccessibilityRenderObject::addChildren();
Note: See TracChangeset for help on using the changeset viewer.