Holding down on candidates in the TouchBar should show panel on screen
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Dec 2016 21:30:30 +0000 (21:30 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Dec 2016 21:30:30 +0000 (21:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166367
-and corresponding-
<rdar://problem/28479236>

Reviewed by Tim Horton.

Source/WebCore:

Expose the version of setCandidates: that takes a rect.
* platform/spi/cocoa/NSTouchBarSPI.h:

Source/WebKit/mac:

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

Call the version of setCandidates: that takes a rect. We need to keep the helper
function in WK1 (unlike WK2) since we also use it for testing.
* WebView/WebView.mm:
(-[WebView showCandidates:forString:inRect:forSelectedRange:view:completionHandler:]):

Source/WebKit2:

The showCandidates() helper function is not needed. We can call the AppKit method
directly at the one call site.
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:

The panel should appear under the selection, so offset the selection rect.
(WebKit::WebViewImpl::handleRequestedCandidates):

No more showCandidates() since we can call it directly.
(WebKit::WebViewImpl::showCandidates): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/spi/cocoa/NSTouchBarSPI.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm

index f560f0d..611d3f7 100644 (file)
@@ -1,3 +1,15 @@
+2016-12-21  Beth Dakin  <bdakin@apple.com>
+
+        Holding down on candidates in the TouchBar should show panel on screen
+        https://bugs.webkit.org/show_bug.cgi?id=166367
+        -and corresponding-
+        <rdar://problem/28479236>
+
+        Reviewed by Tim Horton.
+
+        Expose the version of setCandidates: that takes a rect.
+        * platform/spi/cocoa/NSTouchBarSPI.h:
+
 2016-12-21  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Extensions3DOpenGL[ES] constructor should not be explicit
index e6defaa..9f948c1 100644 (file)
@@ -27,6 +27,7 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 
+#import <AppKit/NSCandidateListTouchBarItem_Private.h>
 #import <AppKit/NSFunctionBar_Private.h>
 #import <AppKit/NSTextTouchBarItemController_WebKitSPI.h>
 #import <AppKit/NSTouchBar_Private.h>
@@ -54,6 +55,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @end
 
+@interface NSCandidateListTouchBarItem ()
+- (void)setCandidates:(NSArray *)candidates forSelectedRange:(NSRange)selectedRange inString:(nullable NSString *)string rect:(NSRect)rect view:(nullable NSView *)view completionHandler:(nullable void (^)(id acceptedCandidate))completionBlock;
+@end
+
 #endif // !USE(APPLE_INTERNAL_SDK)
 
 APPKIT_EXTERN NSNotificationName const NSTouchBarWillEnterCustomization API_AVAILABLE(macosx(10.12.2));
index 412d55e..126e81a 100644 (file)
@@ -1,3 +1,21 @@
+2016-12-21  Beth Dakin  <bdakin@apple.com>
+
+        Holding down on candidates in the TouchBar should show panel on screen
+        https://bugs.webkit.org/show_bug.cgi?id=166367
+        -and corresponding-
+        <rdar://problem/28479236>
+
+        Reviewed by Tim Horton.
+
+        Stray whitespace.
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::handleRequestedCandidates):
+
+        Call the version of setCandidates: that takes a rect. We need to keep the helper 
+        function in WK1 (unlike WK2) since we also use it for testing.
+        * WebView/WebView.mm:
+        (-[WebView showCandidates:forString:inRect:forSelectedRange:view:completionHandler:]):
+
 2016-12-20  Dean Jackson  <dino@apple.com>
 
         Remove INDIE_UI
index 4252639..2a2c5bb 100644 (file)
@@ -1248,7 +1248,6 @@ void WebEditorClient::handleRequestedCandidates(NSInteger sequenceNumber, NSArra
         rectForSelectionCandidates = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
 
     [m_webView showCandidates:candidates forString:m_paragraphContextForCandidateRequest.get() inRect:rectForSelectionCandidates forSelectedRange:m_rangeForCandidates view:m_webView completionHandler:nil];
-
 }
 
 void WebEditorClient::handleAcceptedCandidateWithSoftSpaces(TextCheckingResult acceptedCandidate)
index e66cdf8..09f6df0 100644 (file)
@@ -5025,7 +5025,7 @@ static Vector<String> toStringVector(NSArray* patterns)
 
 - (void)showCandidates:(NSArray<NSTextCheckingResult *> *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock
 {
-    [self.candidateList setCandidates:candidates forSelectedRange:range inString:string];
+    [self.candidateList setCandidates:candidates forSelectedRange:range inString:string rect:rectOfTypedString view:view completionHandler:completionBlock];
 }
 
 - (BOOL)shouldRequestCandidates
index 6b1ef29..10af92c 100644 (file)
@@ -1,3 +1,23 @@
+2016-12-21  Beth Dakin  <bdakin@apple.com>
+
+        Holding down on candidates in the TouchBar should show panel on screen
+        https://bugs.webkit.org/show_bug.cgi?id=166367
+        -and corresponding-
+        <rdar://problem/28479236>
+
+        Reviewed by Tim Horton.
+
+        The showCandidates() helper function is not needed. We can call the AppKit method 
+        directly at the one call site.
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+
+        The panel should appear under the selection, so offset the selection rect.
+        (WebKit::WebViewImpl::handleRequestedCandidates):
+
+        No more showCandidates() since we can call it directly. 
+        (WebKit::WebViewImpl::showCandidates): Deleted.
+
 2016-12-20  Taras Tsugrii  <ttsugrii@fb.com>
 
         Fix undefined behavior caused by macro expansion producing 'defined'
index 65a99ce..714941e 100644 (file)
@@ -493,7 +493,6 @@ public:
 
     void forceRequestCandidatesForTesting();
     bool shouldRequestCandidates() const;
-    void showCandidates(NSArray *candidates, NSString *, NSRect rectOfTypedString, NSRange selectedRange, NSView *, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate));
 
     bool windowIsFrontWindowUnderMouse(NSEvent *);
 
index 0e17401..c9fc184 100644 (file)
@@ -1183,11 +1183,6 @@ bool WebViewImpl::shouldRequestCandidates() const
     return !m_page->editorState().isInPasswordField && candidateListTouchBarItem().candidateListVisible;
 }
 
-void WebViewImpl::showCandidates(NSArray *candidates, NSString *string, NSRect rectOfTypedString, NSRange selectedRange, NSView *view, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate))
-{
-    [candidateListTouchBarItem() setCandidates:candidates forSelectedRange:selectedRange inString:string];
-}
-
 void WebViewImpl::setEditableElementIsFocused(bool editableElementIsFocused)
 {
     m_editableElementIsFocused = editableElementIsFocused;
@@ -1212,10 +1207,6 @@ bool WebViewImpl::shouldRequestCandidates() const
     return false;
 }
 
-void WebViewImpl::showCandidates(NSArray *candidates, NSString *string, NSRect rectOfTypedString, NSRange selectedRange, NSView *view, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate))
-{
-}
-
 void WebViewImpl::setEditableElementIsFocused(bool editableElementIsFocused)
 {
     m_editableElementIsFocused = editableElementIsFocused;
@@ -2994,13 +2985,10 @@ void WebViewImpl::handleRequestedCandidates(NSInteger sequenceNumber, NSArray<NS
 
     NSRange selectedRange = NSMakeRange(postLayoutData.candidateRequestStartPosition, postLayoutData.selectedTextLength);
     auto weakThis = createWeakPtr();
-    showCandidates(candidates, postLayoutData.paragraphContextForCandidateRequest, postLayoutData.selectionClipRect, selectedRange, m_view, [weakThis](NSTextCheckingResult *acceptedCandidate) {
-        dispatch_async(dispatch_get_main_queue(), ^{
-            if (!weakThis)
-                return;
-            weakThis->handleAcceptedCandidate(acceptedCandidate);
-        });
-    });
+    WebCore::IntRect offsetSelectionRect = postLayoutData.selectionClipRect;
+    offsetSelectionRect.move(0, offsetSelectionRect.height());
+
+    [candidateListTouchBarItem() setCandidates:candidates forSelectedRange:selectedRange inString:postLayoutData.paragraphContextForCandidateRequest rect:offsetSelectionRect view:m_view completionHandler:nil];
 }
 
 static WebCore::TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult)