WebPage::selectPositionAtPoint() does not focus an element in a non-focused frame
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Mar 2020 21:10:09 +0000 (21:10 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Mar 2020 21:10:09 +0000 (21:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=209559
<rdar://problem/60887055>

Reviewed by Wenson Hsieh.

Source/WebKit:

Call setFocusedFrameBeforeSelectingTextAtLocation() in WebPage::selectPositionAtPoint() to
update the focused frame before performing the selection. This way the target element will
be focused by the selection, if not already focused.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::selectPositionAtPoint):

Tools:

Add a test.

* TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm:
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259078 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm

index cfb0462..9812d17 100644 (file)
@@ -1,3 +1,18 @@
+2020-03-26  Daniel Bates  <dabates@apple.com>
+
+        WebPage::selectPositionAtPoint() does not focus an element in a non-focused frame
+        https://bugs.webkit.org/show_bug.cgi?id=209559
+        <rdar://problem/60887055>
+
+        Reviewed by Wenson Hsieh.
+
+        Call setFocusedFrameBeforeSelectingTextAtLocation() in WebPage::selectPositionAtPoint() to
+        update the focused frame before performing the selection. This way the target element will
+        be focused by the selection, if not already focused.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::selectPositionAtPoint):
+
 2020-03-26  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         WebKitTestRunner should enable ResourceLoadStatistics also for non-Cocoa ports
index a440b1c..a87dbef 100644 (file)
@@ -2058,6 +2058,8 @@ void WebPage::selectPositionAtPoint(const WebCore::IntPoint& point, bool isInter
 {
     SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true };
 
+    setFocusedFrameBeforeSelectingTextAtLocation(point);
+
     auto& frame = m_page->focusController().focusedOrMainFrame();
     VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
     
index 90ce8c6..de010ec 100644 (file)
@@ -1,3 +1,16 @@
+2020-03-26  Daniel Bates  <dabates@apple.com>
+
+        WebPage::selectPositionAtPoint() does not focus an element in a non-focused frame
+        https://bugs.webkit.org/show_bug.cgi?id=209559
+        <rdar://problem/60887055>
+
+        Reviewed by Wenson Hsieh.
+
+        Add a test.
+
+        * TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm:
+        (TEST):
+
 2020-03-26  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         WebKitTestRunner should enable ResourceLoadStatistics also for non-Cocoa ports
index fa0578a..5404066 100644 (file)
@@ -154,4 +154,25 @@ TEST(UIWKInteractionViewProtocol, SelectPositionAtPointInFocusedElementStartsInp
     TestWebKitAPI::Util::run(&didCallDecidePolicyForFocusedElement);
 }
 
+TEST(UIWKInteractionViewProtocol, SelectPositionAtPointInElementInNonFocusedFrame)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]);
+    auto inputDelegate = adoptNS([TestInputDelegate new]);
+    [webView _setInputDelegate:inputDelegate.get()];
+
+    bool didStartInputSession = false;
+    [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) {
+        didStartInputSession = true;
+        return _WKFocusStartsInputSessionPolicyAllow;
+    }];
+
+    [webView synchronouslyLoadHTMLString:@"<body style='margin: 0; padding: 0'><iframe height='100' width='100%' style='border: none; padding: 0; margin: 0' srcdoc='<body style=\"margin: 0; padding: 0\"><div contenteditable=\"true\" style=\"width: 200px; height: 200px\"></body>'></iframe></body>"];
+    EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.querySelector('iframe').contentDocument.activeElement.tagName"]);
+
+    [webView becomeFirstResponder];
+    [webView selectPositionAtPoint:CGPointMake(0, 0)];
+    TestWebKitAPI::Util::run(&didStartInputSession);
+    EXPECT_WK_STREQ("DIV", [webView stringByEvaluatingJavaScript:@"document.querySelector('iframe').contentDocument.activeElement.tagName"]);
+}
+
 #endif