Changeset 238635 in webkit


Ignore:
Timestamp:
Nov 28, 2018 1:55:13 PM (5 years ago)
Author:
dbates@webkit.org
Message:

[iOS] Page not defocused when Find-in-page becomes first responder
https://bugs.webkit.org/show_bug.cgi?id=192084
<rdar://problem/46146777>

Reviewed by Tim Horton.

Source/WebKit:

When -becomeFirstResponder and -resignFirstResponder is called the page should become focused
and defocused, respectively. WebKit adjusts it behavior depending on whether it knows it has
focus. This includes decisions about whether to allow an element to be focused. We need to
ensure that WebKit knows whether the web view is focused for it to make good decisions.

  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::isViewFocused): Check if the content view is the first responder and
hence is accepting keyboard input. Note that picture-in-picture views do not accept keyboard
input.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView becomeFirstResponderForWebView]): Update activity state when the view
becomes focused.
(-[WKContentView resignFirstResponderForWebView]): Update activity state when the view
becomes defocused.

Tools:

Add tests for both Mac and iOS to ensure that when finding a string on the page
that we do not start an input session if a match is found in an <input> and the
WKWebView is not the first responder.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/WKWebViewFindString.mm: Added.

(-[WKWebViewFindStringInputDelegate _webView:didStartInputSession:]):
(-[WKWebViewFindStringFindDelegate findString]):
(-[WKWebViewFindStringFindDelegate _webView:didCountMatches:forString:]):
(-[WKWebViewFindStringFindDelegate _webView:didFindMatches:forString:withMatchIndex:]):
(-[WKWebViewFindStringFindDelegate _webView:didFailToFindString:]):
(returnNo):
(returnYes):
(viewIsFirstResponder):
(TestWebKitAPI::TEST):

  • WebKitTestRunner/ios/PlatformWebViewIOS.mm:

(WTR::PlatformWebView::PlatformWebView): Make the view the first responder before the
window key. This matches the ordering used in PlatformWebView::focus(). No behavior change.

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r238633 r238635  
     12018-11-28  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Page not defocused when Find-in-page becomes first responder
     4        https://bugs.webkit.org/show_bug.cgi?id=192084
     5        <rdar://problem/46146777>
     6
     7        Reviewed by Tim Horton.
     8
     9        When -becomeFirstResponder and -resignFirstResponder is called the page should become focused
     10        and defocused, respectively. WebKit adjusts it behavior depending on whether it knows it has
     11        focus. This includes decisions about whether to allow an element to be focused. We need to
     12        ensure that WebKit knows whether the web view is focused for it to make good decisions.
     13
     14        * UIProcess/ios/PageClientImplIOS.mm:
     15        (WebKit::PageClientImpl::isViewFocused): Check if the content view is the first responder and
     16        hence is accepting keyboard input. Note that picture-in-picture views do not accept keyboard
     17        input.
     18        * UIProcess/ios/WKContentViewInteraction.mm:
     19        (-[WKContentView becomeFirstResponderForWebView]): Update activity state when the view
     20        becomes focused.
     21        (-[WKContentView resignFirstResponderForWebView]): Update activity state when the view
     22        becomes defocused.
     23
    1242018-11-28  Alex Christensen  <achristensen@webkit.org>
    225
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r238468 r238635  
    167167bool PageClientImpl::isViewFocused()
    168168{
    169     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
    170     return isViewWindowActive() || [m_webView _isRetainingActiveFocusedState];
     169    if (isViewInWindow() && ![m_webView _isBackground])
     170        return [m_webView _contentViewIsFirstResponder];
     171    return [m_webView _isRetainingActiveFocusedState];
    171172}
    172173
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r238526 r238635  
    10351035    }
    10361036
     1037    if (didBecomeFirstResponder)
     1038        _page->activityStateDidChange(WebCore::ActivityState::IsFocused);
     1039
    10371040    if (didBecomeFirstResponder && [self canShowNonEmptySelectionView])
    10381041        [_textSelectionAssistant activateSelection];
     
    10641067
    10651068    bool superDidResign = [super resignFirstResponder];
     1069
     1070    if (superDidResign)
     1071        _page->activityStateDidChange(WebCore::ActivityState::IsFocused);
    10661072
    10671073    _resigningFirstResponder = NO;
  • trunk/Tools/ChangeLog

    r238634 r238635  
     12018-11-28  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Page not defocused when Find-in-page becomes first responder
     4        https://bugs.webkit.org/show_bug.cgi?id=192084
     5        <rdar://problem/46146777>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add tests for both Mac and iOS to ensure that when finding a string on the page
     10        that we do not start an input session if a match is found in an <input> and the
     11        WKWebView is not the first responder.
     12
     13        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     14        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewFindString.mm: Added.
     15        (-[WKWebViewFindStringInputDelegate _webView:didStartInputSession:]):
     16        (-[WKWebViewFindStringFindDelegate findString]):
     17        (-[WKWebViewFindStringFindDelegate _webView:didCountMatches:forString:]):
     18        (-[WKWebViewFindStringFindDelegate _webView:didFindMatches:forString:withMatchIndex:]):
     19        (-[WKWebViewFindStringFindDelegate _webView:didFailToFindString:]):
     20        (returnNo):
     21        (returnYes):
     22        (viewIsFirstResponder):
     23        (TestWebKitAPI::TEST):
     24        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
     25        (WTR::PlatformWebView::PlatformWebView): Make the view the first responder before the
     26        window key. This matches the ordering used in PlatformWebView::focus(). No behavior change.
     27
    1282018-11-28  Aakash Jain  <aakash_jain@apple.com>
    229
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r238544 r238635  
    780780                CE3524F91B1441C40028A7C5 /* TextFieldDidBeginAndEndEditing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */; };
    781781                CE3524FA1B1443890028A7C5 /* input-focus-blur.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */; };
     782                CE449E1121AE0F7200E7ADA1 /* WKWebViewFindString.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE449E1021AE0F7200E7ADA1 /* WKWebViewFindString.mm */; };
    782783                CE4D5DE71F6743BA0072CFC6 /* StringWithDirection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE4D5DE51F6743BA0072CFC6 /* StringWithDirection.cpp */; };
    783784                CE6E81A020A6935F00E2C80F /* SetTimeoutFunction.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE6E819F20A6935F00E2C80F /* SetTimeoutFunction.mm */; };
     
    20542055                CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextFieldDidBeginAndEndEditing_Bundle.cpp; sourceTree = "<group>"; };
    20552056                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "input-focus-blur.html"; sourceTree = "<group>"; };
     2057                CE449E1021AE0F7200E7ADA1 /* WKWebViewFindString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewFindString.mm; sourceTree = "<group>"; };
    20562058                CE4D5DE51F6743BA0072CFC6 /* StringWithDirection.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StringWithDirection.cpp; sourceTree = "<group>"; };
    20572059                CE50D8C81C8665CE0072EA5A /* OptionSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OptionSet.cpp; sourceTree = "<group>"; };
     
    25452547                                F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */,
    25462548                                0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
     2549                                CE449E1021AE0F7200E7ADA1 /* WKWebViewFindString.mm */,
    25472550                                D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
    25482551                                37A9DBE7213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm */,
     
    42134216                                F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */,
    42144217                                0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */,
     4218                                CE449E1121AE0F7200E7ADA1 /* WKWebViewFindString.mm in Sources */,
    42154219                                F4106C6921ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm in Sources */,
    42164220                                D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */,
  • trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm

    r238134 r238635  
    182182
    183183    [m_window.rootViewController.view addSubview:m_view];
     184    [m_view becomeFirstResponder];
    184185    [m_window makeKeyAndVisible];
    185     [m_view becomeFirstResponder];
    186186}
    187187
Note: See TracChangeset for help on using the changeset viewer.