On-screen panel for candidate bar is in the wrong place when the caret is at the
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 May 2017 17:36:46 +0000 (17:36 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 May 2017 17:36:46 +0000 (17:36 +0000)
start of a paragraph
https://bugs.webkit.org/show_bug.cgi?id=171453
-and corresponding-
rdar://problem/29779764

Reviewed by Tim Horton.

Source/WebKit/mac:

This bug only happens when the caret is at the beginning of the paragraph, and it
is because Range::absoluteTextQuads() returns no quads in this case. I think it
might be correct that absoluteTextQuads() returns no quads in this case, so this
patch fixes the bug at the call site by using absoluteCaretBounds() in this case.

* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::handleRequestedCandidates):

Source/WebKit2:

This bug only happens when the caret is at the beginning of the paragraph, and it
is because Range::absoluteTextQuads() returns no quads in this case. I think it
might be correct that absoluteTextQuads() returns no quads in this case, so this
patch fixes the bug at the call site by using absoluteCaretBounds() in this case.

SPI for testing.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _candidateRect]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Bug fix.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformEditorState):

Tools:

This test hard-codes the y-coordinate for the expected candidateRect.
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm:
(TEST):

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

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm

index f670f00..55452b1 100644 (file)
@@ -1,3 +1,21 @@
+2017-05-01  Beth Dakin  <bdakin@apple.com>
+
+        On-screen panel for candidate bar is in the wrong place when the caret is at the 
+        start of a paragraph
+        https://bugs.webkit.org/show_bug.cgi?id=171453
+        -and corresponding-
+        rdar://problem/29779764
+
+        Reviewed by Tim Horton.
+
+        This bug only happens when the caret is at the beginning of the paragraph, and it 
+        is because Range::absoluteTextQuads() returns no quads in this case. I think it 
+        might be correct that absoluteTextQuads() returns no quads in this case, so this 
+        patch fixes the bug at the call site by using absoluteCaretBounds() in this case.
+
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::handleRequestedCandidates):
+
 2017-04-30  Dan Bernstein  <mitz@apple.com>
 
         [Cocoa] Replaces uses of [get…() alloc] with alloc…Instance()
index 35d555e..266db49 100644 (file)
@@ -1251,6 +1251,11 @@ void WebEditorClient::handleRequestedCandidates(NSInteger sequenceNumber, NSArra
     selectedRange->absoluteTextQuads(quads);
     if (!quads.isEmpty())
         rectForSelectionCandidates = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
+    else {
+        // Range::absoluteTextQuads() will be empty at the start of a paragraph.
+        if (selection.isCaret())
+            rectForSelectionCandidates = frame->view()->contentsToWindow(frame->selection().absoluteCaretBounds());
+    }
 
     [m_webView showCandidates:candidates forString:m_paragraphContextForCandidateRequest.get() inRect:rectForSelectionCandidates forSelectedRange:m_rangeForCandidates view:m_webView completionHandler:nil];
 }
index a226ff2..8881b4e 100644 (file)
@@ -1,3 +1,27 @@
+2017-05-01  Beth Dakin  <bdakin@apple.com>
+
+        On-screen panel for candidate bar is in the wrong place when the caret is at the 
+        start of a paragraph
+        https://bugs.webkit.org/show_bug.cgi?id=171453
+        -and corresponding-
+        rdar://problem/29779764
+
+        Reviewed by Tim Horton.
+
+        This bug only happens when the caret is at the beginning of the paragraph, and it 
+        is because Range::absoluteTextQuads() returns no quads in this case. I think it 
+        might be correct that absoluteTextQuads() returns no quads in this case, so this 
+        patch fixes the bug at the call site by using absoluteCaretBounds() in this case.
+
+        SPI for testing.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _candidateRect]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+        Bug fix.
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::platformEditorState):
+
 2017-05-01  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Add automation session API
index 14cf3aa..bd8caee 100644 (file)
@@ -5341,6 +5341,11 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     [self insertText:string replacementRange:replacementRange];
 }
 
+- (NSRect)_candidateRect
+{
+    return _page->editorState().postLayoutData().selectionClipRect;
+}
+
 - (void)_setHeaderBannerHeight:(int)height
 {
     _page->setHeaderBannerHeightForTesting(height);
index 764580d..a637c84 100644 (file)
@@ -357,6 +357,7 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 - (void)_didUpdateCandidateListVisibility:(BOOL)visible WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 @property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_insertText:(id)string replacementRange:(NSRange)replacementRange WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (NSRect)_candidateRect WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 
 - (void)_setHeaderBannerHeight:(int)height WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_setFooterBannerHeight:(int)height WK_API_AVAILABLE(macosx(WK_MAC_TBA));
index f8fb041..563a57b 100644 (file)
@@ -149,6 +149,11 @@ void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePost
     selectedRange->absoluteTextQuads(quads);
     if (!quads.isEmpty())
         postLayoutData.selectionClipRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
+    else {
+        // Range::absoluteTextQuads() will be empty at the start of a paragraph.
+        if (selection.isCaret())
+            postLayoutData.selectionClipRect = frame.view()->contentsToWindow(frame.selection().absoluteCaretBounds());
+    }
 }
 
 void WebPage::handleAcceptedCandidate(WebCore::TextCheckingResult acceptedCandidate)
index 2c6411b..45c179e 100644 (file)
@@ -1,3 +1,17 @@
+2017-05-01  Beth Dakin  <bdakin@apple.com>
+
+        On-screen panel for candidate bar is in the wrong place when the caret is at the 
+        start of a paragraph
+        https://bugs.webkit.org/show_bug.cgi?id=171453
+        -and corresponding-
+        rdar://problem/29779764
+
+        Reviewed by Tim Horton.
+
+        This test hard-codes the y-coordinate for the expected candidateRect. 
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm:
+        (TEST):
+
 2017-05-01  David Kilzer  <ddkilzer@apple.com>
 
         check-webkit-style: Enable sprintf(), strcat(), strcpy() and printf() format checks
index 9dd39bb..57b5145 100644 (file)
@@ -243,4 +243,11 @@ TEST(WKWebViewCandidateTests, ShouldRequestCandidatesInTextField)
 
 #endif
 
+TEST(WKWebViewCandidateTests, CandidateRectForEmptyParagraph)
+{
+    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
+    NSRect candidateRect = [wkWebView _candidateRect];
+    EXPECT_NE(0, candidateRect.origin.y);
+}
+
 #endif /* WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101201 */