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

Changeset 287810 in webkit


Ignore:
Timestamp:
Jan 8, 2022, 8:40:34 AM (5 years ago)
Author:
Tyler Wilcock
Message:

AX: AccessibilityObject::setFocused(true) should make the webpage focused, and make web content the first responder
https://bugs.webkit.org/show_bug.cgi?id=234885

Reviewed by Darin Adler.

Source/WebCore:

With this patch, focusing an element via an AX client on iOS makes
the page focused immediately. This allows a focus ring to be drawn,
even when apps that embed WKWebViews don't make web content the
first responder themselves ([WKContentViewInteraction becomeFirstResponderForWebView]
makes the page focused after a delay due to async IPC between the UI and web processes).

Tests: accessibility/ios-simulator/accessibility-make-first-responder.html

accessibility/ios-simulator/taking-focus-should-refocus-page.html

  • accessibility/AccessibilityObject.cpp:

(WebCore::AccessibilityObject::setFocused):
Make the webpage focused if it isn't already focused.

  • testing/Internals.cpp:

(WebCore::Internals::setPageIsFocused):
Added to simulate the scenario where the webpage doesn't gain focus
through becoming first responder.

  • testing/Internals.h:

Add setPageIsFocused.

  • testing/Internals.idl:

Add setPageIsFocused.

Source/WebKit:

With this patch, focusing an element via an AX client on iOS makes web content
the first responder. This allows a focus ring to be drawn and for web content
to perform other important actions upon taking first respondership
(see [WKContentViewInteraction becomeFirstResponderForWebView]), even when apps
that embed WKWebViews don't make web content the first responder themselves.

  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::assistiveTechnologyMakeFirstResponder):

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::assistiveTechnologyMakeFirstResponder):

Tools:

Add testing functionality necessary to check that web content is the
first responder in the UI process.

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
  • TestRunnerShared/UIScriptContext/UIScriptController.h:

(WTR::UIScriptController::isWebContentFirstResponder const):
Added.

  • WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:

(WTR::AccessibilityUIElement::takeFocus):
Implement this method.

  • WebKitTestRunner/ios/UIScriptControllerIOS.h:
  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptControllerIOS::isWebContentFirstResponder const):
Added.

LayoutTests:

Add tests verifying that focusing an element via an AX client:

  1. Makes the page focused immediately
  2. Makes web content the first responder

This allows a focus ring to be drawn, even when apps that embed
WKWebViews don't make web content the first responder themselves.

  • accessibility/ios-simulator/accessibility-make-first-responder-expected.txt: Added.
  • accessibility/ios-simulator/accessibility-make-first-responder.html: Added.
  • accessibility/ios-simulator/taking-focus-should-refocus-page-expected.txt: Added.
  • accessibility/ios-simulator/taking-focus-should-refocus-page.html: Added.
Location:
trunk
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r287805 r287810  
     12022-01-08  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: AccessibilityObject::setFocused(true) should make the webpage focused, and make web content the first responder
     4        https://bugs.webkit.org/show_bug.cgi?id=234885
     5
     6        Reviewed by Darin Adler.
     7
     8        Add tests verifying that focusing an element via an AX client:
     9
     10          1. Makes the page focused immediately
     11          2. Makes web content the first responder
     12
     13        This allows a focus ring to be drawn, even when apps that embed
     14        WKWebViews don't make web content the first responder themselves.
     15
     16        * accessibility/ios-simulator/accessibility-make-first-responder-expected.txt: Added.
     17        * accessibility/ios-simulator/accessibility-make-first-responder.html: Added.
     18        * accessibility/ios-simulator/taking-focus-should-refocus-page-expected.txt: Added.
     19        * accessibility/ios-simulator/taking-focus-should-refocus-page.html: Added.
     20
    1212022-01-07  Myles C. Maxfield  <mmaxfield@apple.com>
    222
  • trunk/Source/WebCore/ChangeLog

    r287809 r287810  
     12022-01-08  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: AccessibilityObject::setFocused(true) should make the webpage focused, and make web content the first responder
     4        https://bugs.webkit.org/show_bug.cgi?id=234885
     5
     6        Reviewed by Darin Adler.
     7
     8        With this patch, focusing an element via an AX client on iOS makes
     9        the page focused immediately. This allows a focus ring to be drawn,
     10        even when apps that embed WKWebViews don't make web content the
     11        first responder themselves (`[WKContentViewInteraction becomeFirstResponderForWebView]`
     12        makes the page focused after a delay due to async IPC between the UI and web processes).
     13
     14        Tests: accessibility/ios-simulator/accessibility-make-first-responder.html
     15               accessibility/ios-simulator/taking-focus-should-refocus-page.html
     16
     17        * accessibility/AccessibilityObject.cpp:
     18        (WebCore::AccessibilityObject::setFocused):
     19        Make the webpage focused if it isn't already focused.
     20
     21        * testing/Internals.cpp:
     22        (WebCore::Internals::setPageIsFocused):
     23        Added to simulate the scenario where the webpage doesn't gain focus
     24        through becoming first responder.
     25        * testing/Internals.h:
     26        Add setPageIsFocused.
     27        * testing/Internals.idl:
     28        Add setPageIsFocused.
     29
    1302022-01-08  Alan Bujtas  <zalan@apple.com>
    231
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r287232 r287810  
    27722772    if (focus) {
    27732773        // Ensure that the view is focused and active, otherwise, any attempt to set focus to an object inside it will fail.
    2774         auto* document = this->document();
    2775         if (!document)
    2776             return;
    2777 
    2778         auto* frame = document->frame();
     2774        auto* frame = document() ? document()->frame() : nullptr;
    27792775        if (frame && frame->selection().isFocusedAndActive())
    27802776            return; // Nothing to do, already focused and active.
    27812777
    2782         auto* page = document->page();
     2778        auto* page = document() ? document()->page() : nullptr;
    27832779        if (!page)
    27842780            return;
    27852781
    2786         ChromeClient& chromeClient = page->chrome().client();
    2787         chromeClient.focus();
     2782        page->chrome().client().focus();
     2783        // Reset the page pointer in case ChromeClient::focus() caused a side effect that invalidated our old one.
     2784        page = document() ? document()->page() : nullptr;
     2785        if (!page)
     2786            return;
     2787
     2788#if PLATFORM(IOS_FAMILY)
     2789        // Mark the page as focused so the focus ring can be drawn immediately. The page is also marked
     2790        // as focused as part assistiveTechnologyMakeFirstResponder, but that requires some back-and-forth
     2791        // IPC between the web and UI processes, during which we can miss the drawing of the focus ring for the
     2792        // first focused element. Making the page focused is a requirement for making the page selection focused.
     2793        // This is iOS only until there's a demonstrated need for this preemptive focus on other platforms.
     2794        if (!page->focusController().isFocused())
     2795            page->focusController().setFocused(true);
     2796
     2797        // Reset the page pointer in case FocusController::setFocused(true) caused a side effect that invalidated our old one.
     2798        page = document() ? document()->page() : nullptr;
     2799        if (!page)
     2800            return;
     2801#endif
    27882802
    27892803#if PLATFORM(COCOA)
     
    27942808        // Legacy WebKit1 case.
    27952809        if (frameView->platformWidget())
    2796             chromeClient.makeFirstResponder((NSResponder *)frameView->platformWidget());
     2810            page->chrome().client().makeFirstResponder((NSResponder *)frameView->platformWidget());
    27972811        else
    2798             chromeClient.assistiveTechnologyMakeFirstResponder();
     2812            page->chrome().client().assistiveTechnologyMakeFirstResponder();
    27992813#endif
    28002814    }
  • trunk/Source/WebCore/testing/Internals.cpp

    r287731 r287810  
    53615361}
    53625362
     5363void Internals::setPageIsFocused(bool isFocused)
     5364{
     5365    updatePageActivityState(ActivityState::IsFocused, isFocused);
     5366}
     5367
    53635368void Internals::setPageIsFocusedAndActive(bool isFocusedAndActive)
    53645369{
  • trunk/Source/WebCore/testing/Internals.h

    r287663 r287810  
    846846
    847847    void setPageVisibility(bool isVisible);
     848    void setPageIsFocused(bool);
    848849    void setPageIsFocusedAndActive(bool);
    849850    void setPageIsInWindow(bool);
  • trunk/Source/WebCore/testing/Internals.idl

    r287663 r287810  
    886886
    887887    undefined setPageVisibility(boolean isVisible);
     888    undefined setPageIsFocused(boolean isFocused);
    888889    undefined setPageIsFocusedAndActive(boolean isFocused);
    889890    undefined setPageIsInWindow(boolean isInWindow);
  • trunk/Source/WebKit/ChangeLog

    r287808 r287810  
     12022-01-08  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: AccessibilityObject::setFocused(true) should make the webpage focused, and make web content the first responder
     4        https://bugs.webkit.org/show_bug.cgi?id=234885
     5
     6        Reviewed by Darin Adler.
     7
     8        With this patch, focusing an element via an AX client on iOS makes web content
     9        the first responder. This allows a focus ring to be drawn and for web content
     10        to perform other important actions upon taking first respondership
     11        (see `[WKContentViewInteraction becomeFirstResponderForWebView]`), even when apps
     12        that embed WKWebViews don't make web content the first responder themselves.
     13
     14        * UIProcess/ios/PageClientImplIOS.mm:
     15        (WebKit::PageClientImpl::assistiveTechnologyMakeFirstResponder):
     16        * UIProcess/ios/WebPageProxyIOS.mm:
     17        (WebKit::WebPageProxy::assistiveTechnologyMakeFirstResponder):
     18
    1192022-01-07  Jean-Yves Avenard  <jya@apple.com>
    220
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r287021 r287810  
    392392void PageClientImpl::assistiveTechnologyMakeFirstResponder()
    393393{
    394     notImplemented();
     394    [m_contentView becomeFirstResponder];
    395395}
    396396
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r287808 r287810  
    742742void WebPageProxy::assistiveTechnologyMakeFirstResponder()
    743743{
    744     notImplemented();
     744    pageClient().assistiveTechnologyMakeFirstResponder();
    745745}
    746746   
  • trunk/Tools/ChangeLog

    r287790 r287810  
     12022-01-08  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: AccessibilityObject::setFocused(true) should make the webpage focused, and make web content the first responder
     4        https://bugs.webkit.org/show_bug.cgi?id=234885
     5
     6        Reviewed by Darin Adler.
     7
     8        Add testing functionality necessary to check that web content is the
     9        first responder in the UI process.
     10
     11        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     12        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     13        (WTR::UIScriptController::isWebContentFirstResponder const):
     14        Added.
     15
     16        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
     17        (WTR::AccessibilityUIElement::takeFocus):
     18        Implement this method.
     19
     20        * WebKitTestRunner/ios/UIScriptControllerIOS.h:
     21        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     22        (WTR::UIScriptControllerIOS::isWebContentFirstResponder const):
     23        Added.
     24
    1252022-01-07  Tim Horton  <timothy_horton@apple.com>
    226
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r280980 r287810  
    360360    undefined makeWindowContentViewFirstResponder();
    361361    readonly attribute boolean isWindowContentViewFirstResponder;
     362    readonly attribute boolean isWebContentFirstResponder;
    362363
    363364    undefined setHardwareKeyboardAttached(boolean attached);
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r280980 r287810  
    119119    virtual void makeWindowContentViewFirstResponder() { notImplemented(); }
    120120    virtual bool isWindowContentViewFirstResponder() const { notImplemented(); return false; }
     121    virtual bool isWebContentFirstResponder() const { notImplemented(); return false; }
    121122
    122123    virtual void removeViewFromWindow(JSValueRef) { notImplemented(); }
  • trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm

    r286116 r287810  
    7171- (CGFloat)_accessibilityMaxValue;
    7272- (void)_accessibilitySetValue:(NSString *)value;
     73- (void)_accessibilitySetFocus:(BOOL)focus;
    7374- (void)_accessibilityActivate;
    7475- (UIAccessibilityTraits)_axSelectedTrait;
     
    11821183void AccessibilityUIElement::takeFocus()
    11831184{
     1185    [m_element _accessibilitySetFocus:YES];
    11841186}
    11851187
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h

    r280980 r287810  
    169169    WebCore::FloatRect rectForMenuAction(CFStringRef) const;
    170170    void singleTapAtPointWithModifiers(WebCore::FloatPoint location, Vector<String>&& modifierFlags, BlockPtr<void()>&&);
     171
     172    bool isWebContentFirstResponder() const override;
    171173};
    172174
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r282844 r287810  
    13271327}
    13281328
     1329bool UIScriptControllerIOS::isWebContentFirstResponder() const
     1330{
     1331    return [webView() _contentViewIsFirstResponder];
     1332}
     1333
    13291334}
    13301335
Note: See TracChangeset for help on using the changeset viewer.