Bug 203798

Summary: AX: WKWebView does not shift Accessibility Focus for Catalyst
Product: WebKit Reporter: Eric Liang <ericliang>
Component: AccessibilityAssignee: Per Arne Vollan <pvollan>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, apinheiro, bfulgham, cfleizach, commit-queue, dbates, dmazzoni, ews-watchlist, jcraig, jdiggs, pvollan, samuel_white, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Eric Liang 2019-11-03 16:45:17 PST
WKWebViews do not respond to JavaScript that tell them to `focus()`, changing the Accessibility Element selected.

Steps To Reproduce:
1. Enable VoiceOver
2. Open a webpage that auto-shifts Accessibility focus via JavaScript.
3. Verify that no shift occurs.

(See Notes section for a working sample and instructions)

Results:
The WKWebView should adjust its Accessibility focus, but does not.

Regression:
This feature works great on iPad, just not in Catalyst.

Notes:
1. Download simpleCommands.zip containing HTML, CSS, and JS files.
2. Enable VoiceOver
3. Open simpleCommands.html inside Safari. After 5 seconds, the focus should switch and VoiceOver should begin reading out ‘today’s date’.

4. Now open the project found in WebpageCutscene.zip. It uses the same webpage as before.
5. Build and Run this project targeting Mac Catalyst. You will see that the VoiceOver focus does not shift when ran inside an app.
Comment 1 Radar WebKit Bug Importer 2019-11-03 16:45:27 PST
<rdar://problem/56851887>
Comment 2 Eric Liang 2019-11-03 17:21:08 PST
Created attachment 382712 [details]
Patch
Comment 3 chris fleizach 2019-11-03 18:13:03 PST
Comment on attachment 382712 [details]
Patch

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

> Source/WebKit/UIProcess/ios/WKContentView.mm:578
> +    [self _updateRemoteAccessibilityRegistration:NO];

there are a number of places to cleanup. check the other places where we do accessibility cleanup
Comment 4 chris fleizach 2019-11-03 18:13:49 PST
You should also get a WebKit2 contributors point of view, like Daniel Bates or Brent Fulgham
Comment 5 Eric Liang 2019-11-03 23:34:09 PST
(In reply to chris fleizach from comment #3)
> Comment on attachment 382712 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=382712&action=review
> 
> > Source/WebKit/UIProcess/ios/WKContentView.mm:578
> > +    [self _updateRemoteAccessibilityRegistration:NO];
> 
> there are a number of places to cleanup. check the other places where we do
> accessibility cleanup

Even though we do more cleanups in other places, if the process identifier didn't change, do we need to unregister the pid for ax?
Comment 6 Eric Liang 2019-11-03 23:35:34 PST
(In reply to chris fleizach from comment #3)
> Comment on attachment 382712 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=382712&action=review
> 
> > Source/WebKit/UIProcess/ios/WKContentView.mm:578
> > +    [self _updateRemoteAccessibilityRegistration:NO];
> 
> there are a number of places to cleanup. check the other places where we do
> accessibility cleanup

the Mac version cleans up when 1) page closed, 2) process swaps or exits
Comment 7 chris fleizach 2019-11-04 02:45:00 PST
Comment on attachment 382712 [details]
Patch

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

>>>> Source/WebKit/UIProcess/ios/WKContentView.mm:578
>>>> +    [self _updateRemoteAccessibilityRegistration:NO];
>>> 
>>> there are a number of places to cleanup. check the other places where we do accessibility cleanup
>> 
>> Even though we do more cleanups in other places, if the process identifier didn't change, do we need to unregister the pid for ax?
> 
> the Mac version cleans up when 1) page closed, 2) process swaps or exits

ok I think that's right
Comment 8 Tim Horton 2019-11-04 11:15:06 PST
Comment on attachment 382712 [details]
Patch

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

> Source/WebKit/UIProcess/ios/WKContentView.mm:73
> +SOFT_LINK_FRAMEWORK(AppKit)
> +SOFT_LINK_CLASS(AppKit, NSAccessibilityRemoteUIElement)

Why are you softlinking AppKit? WebKit links AppKit directly.

> Source/WebKit/UIProcess/ios/WKContentView.mm:79
> +@interface NSObject(NSAccessibilityRemoteUIElement_Private)
> +- (void)registerRemoteUIProcessIdentifier:(pid_t)pid;
> +- (void)unregisterRemoteUIProcessIdentifier:(pid_t)pid;
> +@end
> +#endif

This should be in a SPI header, not here.
Comment 9 Eric Liang 2019-11-04 11:19:32 PST
Comment on attachment 382712 [details]
Patch

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

>> Source/WebKit/UIProcess/ios/WKContentView.mm:73
>> +SOFT_LINK_CLASS(AppKit, NSAccessibilityRemoteUIElement)
> 
> Why are you softlinking AppKit? WebKit links AppKit directly.

Correct me if I'm wrong, but this is the iOS code so I don't think we can link or import anything from AppKit because of unavailability build errors.
Comment 10 Tim Horton 2019-11-04 11:21:01 PST
(In reply to Eric Liang from comment #9)
> Comment on attachment 382712 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=382712&action=review
> 
> >> Source/WebKit/UIProcess/ios/WKContentView.mm:73
> >> +SOFT_LINK_CLASS(AppKit, NSAccessibilityRemoteUIElement)
> > 
> > Why are you softlinking AppKit? WebKit links AppKit directly.
> 
> Correct me if I'm wrong, but this is the iOS code so I don't think we can
> link or import anything from AppKit because of unavailability build errors.

Oh, macCatalyst might not link AppKit directly, that's a fair point.

In that case, you should have -Softlinking headers like other frameworks.
Comment 11 Eric Liang 2019-11-04 12:17:15 PST
Created attachment 382757 [details]
Patch
Comment 12 chris fleizach 2019-11-04 14:13:59 PST
Comment on attachment 382757 [details]
Patch

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

> Source/WebKit/UIProcess/ios/AppKitSoftLink.h:2
> + * Copyright (C) 2018 Apple Inc. All rights reserved.

2019

> Source/WebKit/UIProcess/ios/AppKitSoftLink.mm:2
> + * Copyright (C) 2018 Apple Inc. All rights reserved.

2019
Comment 13 Eric Liang 2019-11-04 14:17:48 PST
Created attachment 382774 [details]
Patch
Comment 14 Tim Horton 2019-11-04 14:46:37 PST
Comment on attachment 382774 [details]
Patch

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

> Source/WebKit/UIProcess/ios/AppKitSoftLink.h:38
> +@interface NSObject(NSAccessibilityRemoteUIElement_Private)
> +- (void)registerRemoteUIProcessIdentifier:(pid_t)pid;
> +- (void)unregisterRemoteUIProcessIdentifier:(pid_t)pid;
> +@end

These go in AppKitSPI, not AppKitSoftLink. Probably in a macCatalyst-only section.

Also, the category name should have a space before the opening paren.
Comment 15 Eric Liang 2019-11-04 16:31:07 PST
Created attachment 382786 [details]
Patch
Comment 16 Tim Horton 2019-11-06 14:46:06 PST
Comment on attachment 382786 [details]
Patch

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

> Source/WebCore/PAL/pal/spi/cocoa/NSAccessibilitySPI.h:66
> +SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, AppKit)
> +SOFT_LINK_CLASS_FOR_HEADER(PAL, NSAccessibilityRemoteUIElement)

You moved too much :) These (soft linking bits) should be in -SoftLinking.h/.mm files like they were. Just the forward declarations needed to move here.

Other than that this looks good.
Comment 17 Eric Liang 2019-11-06 17:56:31 PST
Created attachment 382995 [details]
Patch
Comment 18 WebKit Commit Bot 2019-11-06 23:03:24 PST
Comment on attachment 382995 [details]
Patch

Clearing flags on attachment: 382995

Committed r252175: <https://trac.webkit.org/changeset/252175>
Comment 19 WebKit Commit Bot 2019-11-06 23:03:26 PST
All reviewed patches have been landed.  Closing bug.
Comment 20 Per Arne Vollan 2019-11-08 10:54:07 PST Comment hidden (obsolete)
Comment 21 Per Arne Vollan 2019-11-08 10:54:08 PST Comment hidden (obsolete)
Comment 22 chris fleizach 2019-11-08 10:56:03 PST Comment hidden (obsolete)
Comment 23 Tim Horton 2019-11-08 11:03:10 PST Comment hidden (obsolete)