Bug 238680

Summary: AccessibilityNodeObject::elementRect should use children rects for display:contents AX objects
Product: WebKit Reporter: Tyler Wilcock <tyler_w>
Component: AccessibilityAssignee: Tyler Wilcock <tyler_w>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, andresg_22, apinheiro, cfleizach, dmazzoni, ews-watchlist, jcraig, jdiggs, samuel_white, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Tyler Wilcock 2022-04-01 13:02:04 PDT
Because display:contents AccessibilityNodeObjects can have rendered content (unlike `hidden`, `aria-hidden="false"` node objects), we can compute AccessibilityNodeObject::elementRect by adding up the rectangles of the object's children.
Comment 1 Radar WebKit Bug Importer 2022-04-01 13:02:15 PDT
<rdar://problem/91177670>
Comment 2 Tyler Wilcock 2022-04-01 13:05:38 PDT
Created attachment 456393 [details]
Patch
Comment 3 chris fleizach 2022-04-01 13:17:20 PDT
Comment on attachment 456393 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456393&action=review

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:227
> +        if (is<AccessibilityNodeObject>(ancestor))

since AXRenderObject inherits from AXNodeObject isn't this true for render objects?
is this better as

if (!is<AccessibilityRenderObject>) { continue
Comment 4 Tyler Wilcock 2022-04-01 13:31:49 PDT
Created attachment 456397 [details]
Patch
Comment 5 Tyler Wilcock 2022-04-01 13:32:24 PDT
(In reply to chris fleizach from comment #3)
> Comment on attachment 456393 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=456393&action=review
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:227
> > +        if (is<AccessibilityNodeObject>(ancestor))
> 
> since AXRenderObject inherits from AXNodeObject isn't this true for render
> objects?
> is this better as
> 
> if (!is<AccessibilityRenderObject>) { continue
Yes, thanks!
Comment 6 chris fleizach 2022-04-01 13:41:31 PDT
Comment on attachment 456397 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456397&action=review

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:212
> +        auto childrenCopy = m_children;

are we actually doing any copying here? or can we just iteration m_children?
Comment 7 Andres Gonzalez 2022-04-01 13:55:29 PDT
(In reply to chris fleizach from comment #6)
> Comment on attachment 456397 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=456397&action=review
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:212
> > +        auto childrenCopy = m_children;
> 
> are we actually doing any copying here? or can we just iteration m_children?

Yes, I think the copy is not necessary since m_children is a Vector<RefPtr<AXCoreObject>> so the objects are not going away since they are held by the RefPtr.
Comment 8 Andres Gonzalez 2022-04-01 13:59:11 PDT
(In reply to Andres Gonzalez from comment #7)
> (In reply to chris fleizach from comment #6)
> > Comment on attachment 456397 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=456397&action=review
> > 
> > > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:212
> > > +        auto childrenCopy = m_children;
> > 
> > are we actually doing any copying here? or can we just iteration m_children?
> 
> Yes, I think the copy is not necessary since m_children is a
> Vector<RefPtr<AXCoreObject>> so the objects are not going away since they
> are held by the RefPtr.

So I think you can do just:

+        for (const auto& child : children(false))
Comment 9 Tyler Wilcock 2022-04-03 12:23:17 PDT
Created attachment 456508 [details]
Patch
Comment 10 Tyler Wilcock 2022-04-03 12:26:24 PDT
> So I think you can do just:
> 
> +        for (const auto& child : children(false))
We can't use children() (even children(false)) because AXCoreObject::children is not const, while boundingBoxRect is. So we can loop through m_children, which is essentially the same as children(false).
Comment 11 Tyler Wilcock 2022-04-03 18:37:29 PDT
Created attachment 456525 [details]
Patch
Comment 12 Andres Gonzalez 2022-04-04 07:03:15 PDT
(In reply to Tyler Wilcock from comment #10)
> > So I think you can do just:
> > 
> > +        for (const auto& child : children(false))
> We can't use children() (even children(false)) because
> AXCoreObject::children is not const, while boundingBoxRect is. So we can
> loop through m_children, which is essentially the same as children(false).

The problem with that is that a subclass of AXNodeObject now or in the future may override children() and do something that is not equivalent to just m_children. A workaround for the const issue is to use const_cast as ugly as it is.
Comment 13 Tyler Wilcock 2022-04-04 07:11:31 PDT
Created attachment 456566 [details]
Patch
Comment 14 EWS 2022-04-04 13:42:44 PDT
Committed r292314 (249207@main): <https://commits.webkit.org/249207@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 456566 [details].