Bug 257377

Summary: AX: Implement unit testing of the functionality in NSApplicationAccessibilityFocusedUIElement.
Product: WebKit Reporter: Andres Gonzalez <andresg_22>
Component: AccessibilityAssignee: Andres Gonzalez <andresg_22>
Status: RESOLVED FIXED    
Severity: Normal CC: andresg_22, darin, tyler_w, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch none

Description Andres Gonzalez 2023-05-26 05:35:55 PDT
No AX layout test exercise this functionality.
Comment 1 Radar WebKit Bug Importer 2023-05-26 05:36:23 PDT
<rdar://problem/109884868>
Comment 2 Andres Gonzalez 2023-05-26 06:21:26 PDT
Created attachment 466506 [details]
Patch
Comment 3 Darin Adler 2023-05-26 09:44:27 PDT
I suggest the function we add to the header not take any arguments. It can call the internal function that takes and ignores an NSApplication and a SEL.
Comment 4 Darin Adler 2023-05-26 09:45:11 PDT
By the way, the bugs.webkit.org review tool is no longer working for me. I encourage everyone to switch to GitHub pull requests soon.
Comment 5 Tyler Wilcock 2023-05-26 10:24:23 PDT
Comment on attachment 466506 [details]
Patch

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

> Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:278
> +#if ENABLE(ACCESSIBILITY_ISOLATED_TREE) && USE(APPKIT)
> +    UNUSED_PARAM(pageRef);
> +    return WebKit::WebProcess::accessibilityFocusedUIElement(nil, nil);
> +#else

Prior to this change, accessibility would be enabled (via AXObjectCache::enableAccessibility()), assuming we had a non-null `pageRef`, `page`, and `focusedDocument`. Do we want / need to preserve that behavior somehow?

> Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:298
> +#endif

Thoughts on adding // ENABLE(ACCESSIBILITY_ISOLATED_TREE) && USE(APPKIT) after this #endif? This added #endif is sibling to an #else of a different compiler directive, so the extra context on which one is ending here could be nice.
Comment 6 Andres Gonzalez 2023-05-30 13:20:30 PDT
Created attachment 466537 [details]
Patch
Comment 7 Andres Gonzalez 2023-05-30 13:25:33 PDT
(In reply to Darin Adler from comment #3)
> I suggest the function we add to the header not take any arguments. It can
> call the internal function that takes and ignores an NSApplication and a SEL.

Added the method to the header that takes no arguments as you suggested. This static method now implements the functionality. The AppKit override that takes and ignores NSApplication and SEL, now simply calls this method. I think it is much cleaner now. Thanks.
Comment 8 Andres Gonzalez 2023-05-30 13:38:21 PDT
(In reply to Tyler Wilcock from comment #5)
> Comment on attachment 466506 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=466506&action=review
> 
> > Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:278
> > +#if ENABLE(ACCESSIBILITY_ISOLATED_TREE) && USE(APPKIT)
> > +    UNUSED_PARAM(pageRef);
> > +    return WebKit::WebProcess::accessibilityFocusedUIElement(nil, nil);
> > +#else
> 
> Prior to this change, accessibility would be enabled (via
> AXObjectCache::enableAccessibility()), assuming we had a non-null `pageRef`,
> `page`, and `focusedDocument`. Do we want / need to preserve that behavior
> somehow?

AXObjectCache::enableAccessibility is called because this path ultimately results in getting the root element, to get the focused element from it, and getting the root does:

- (id)accessibilityRootObjectWrapper
{
#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
    if (!isMainRunLoop()) {
        if (RefPtr root = m_isolatedTreeRoot.get())
            return root->wrapper();
    }
#endif

    return ax::retrieveAutoreleasedValueFromMainThread<id>([protectedSelf = retainPtr(self)] () -> RetainPtr<id> {
        if (!WebCore::AXObjectCache::accessibilityEnabled())
            WebCore::AXObjectCache::enableAccessibility();


> 
> > Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:298
> > +#endif
> 
> Thoughts on adding // ENABLE(ACCESSIBILITY_ISOLATED_TREE) && USE(APPKIT)
> after this #endif? This added #endif is sibling to an #else of a different
> compiler directive, so the extra context on which one is ending here could
> be nice.

Done.
Comment 9 EWS 2023-05-30 18:16:39 PDT
Committed 264706@main (2def5f3d4ef5): <https://commits.webkit.org/264706@main>

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