Title: [176037] trunk/Source
Revision
176037
Author
[email protected]
Date
2014-11-12 13:50:16 -0800 (Wed, 12 Nov 2014)

Log Message

Need to show the text indicator when Data Detectors shows a popover
https://bugs.webkit.org/show_bug.cgi?id=138664
<rdar://problem/18869900>

Reviewed by Beth Dakin.

* UIProcess/mac/WKActionMenuController.h:
* UIProcess/mac/WKActionMenuController.mm:
(hasDataDetectorsCompletionAPI):
Determine if we have the new API.

(-[WKActionMenuController willDestroyView:]):
(-[WKActionMenuController willOpenMenu:withEvent:]):
Make use of the new API.
If we wanted to show a Data Detectors menu but have no items (or they're all
disabled), cancel the menu.
If we don't have it, manually manipulate the highlight.

(-[WKActionMenuController didCloseMenu:withEvent:]):
Make use of the new API.
If we don't have it, manually manipulate the highlight.

(-[WKActionMenuController _defaultMenuItemsForDataDetectedText]):
Set up completion handlers if we have the new API; when DataDetectors
presents UI, show the text indicator, when it dismisses, hide it.
If we don't have the API, manually manipulate the highlight.

* platform/spi/mac/DataDetectorsSPI.h:
Add new DataDetectors SPI.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176036 => 176037)


--- trunk/Source/WebCore/ChangeLog	2014-11-12 21:48:51 UTC (rev 176036)
+++ trunk/Source/WebCore/ChangeLog	2014-11-12 21:50:16 UTC (rev 176037)
@@ -1,3 +1,14 @@
+2014-11-12  Tim Horton  <[email protected]>
+
+        Need to show the text indicator when Data Detectors shows a popover
+        https://bugs.webkit.org/show_bug.cgi?id=138664
+        <rdar://problem/18869900>
+
+        Reviewed by Beth Dakin.
+
+        * platform/spi/mac/DataDetectorsSPI.h:
+        Add new DataDetectors SPI.
+
 2014-11-12  Chris Dumez  <[email protected]>
 
         Minor improvements to RenderListItem

Modified: trunk/Source/WebCore/platform/spi/mac/DataDetectorsSPI.h (176036 => 176037)


--- trunk/Source/WebCore/platform/spi/mac/DataDetectorsSPI.h	2014-11-12 21:48:51 UTC (rev 176036)
+++ trunk/Source/WebCore/platform/spi/mac/DataDetectorsSPI.h	2014-11-12 21:50:16 UTC (rev 176037)
@@ -69,6 +69,8 @@
 @property (copy) void (^completionHandler)(void);
 @property (assign) BOOL forActionMenuContent;
 
+- (DDActionContext *)contextForView:(NSView *)view altMode:(BOOL)altMode interactionStartedHandler:(void (^)(void))interactionStartedHandler interactionChangedHandler:(void (^)(void))interactionChangedHandler interactionStoppedHandler:(void (^)(void))interactionStoppedHandler;
+
 @end
 
 @interface DDActionsManager : NSObject
@@ -78,4 +80,8 @@
 - (NSArray *)menuItemsForTargetURL:(NSString *)targetURL actionContext:(DDActionContext *)context;
 - (void)requestBubbleClosureUnanchorOnFailure:(BOOL)unanchorOnFailure;
 
++ (BOOL)shouldUseActionsWithContext:(DDActionContext *)context;
++ (void)didUseActions;
+
+
 @end

Modified: trunk/Source/WebKit2/ChangeLog (176036 => 176037)


--- trunk/Source/WebKit2/ChangeLog	2014-11-12 21:48:51 UTC (rev 176036)
+++ trunk/Source/WebKit2/ChangeLog	2014-11-12 21:50:16 UTC (rev 176037)
@@ -14,6 +14,35 @@
 
 2014-11-12  Tim Horton  <[email protected]>
 
+        Need to show the text indicator when Data Detectors shows a popover
+        https://bugs.webkit.org/show_bug.cgi?id=138664
+        <rdar://problem/18869900>
+
+        Reviewed by Beth Dakin.
+
+        * UIProcess/mac/WKActionMenuController.h:
+        * UIProcess/mac/WKActionMenuController.mm:
+        (hasDataDetectorsCompletionAPI):
+        Determine if we have the new API.
+
+        (-[WKActionMenuController willDestroyView:]):
+        (-[WKActionMenuController willOpenMenu:withEvent:]):
+        Make use of the new API.
+        If we wanted to show a Data Detectors menu but have no items (or they're all
+        disabled), cancel the menu.
+        If we don't have it, manually manipulate the highlight.
+
+        (-[WKActionMenuController didCloseMenu:withEvent:]):
+        Make use of the new API.
+        If we don't have it, manually manipulate the highlight.
+
+        (-[WKActionMenuController _defaultMenuItemsForDataDetectedText]):
+        Set up completion handlers if we have the new API; when DataDetectors
+        presents UI, show the text indicator, when it dismisses, hide it.
+        If we don't have the API, manually manipulate the highlight.
+
+2014-11-12  Tim Horton  <[email protected]>
+
         Make action menus much more reliable
         https://bugs.webkit.org/show_bug.cgi?id=138654
         <rdar://problem/18909111>

Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h (176036 => 176037)


--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h	2014-11-12 21:48:51 UTC (rev 176036)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h	2014-11-12 21:50:16 UTC (rev 176037)
@@ -44,6 +44,7 @@
 };
 }
 
+@class DDActionContext;
 @class WKView;
 
 #if WK_API_ENABLED
@@ -68,6 +69,8 @@
 #if WK_API_ENABLED
     RetainPtr<WKPagePreviewViewController> _previewViewController;
 #endif
+
+    RetainPtr<DDActionContext> _currentActionContext;
 }
 
 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(WKView *)wkView;

Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (176036 => 176037)


--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-11-12 21:48:51 UTC (rev 176036)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-11-12 21:50:16 UTC (rev 176037)
@@ -54,6 +54,15 @@
 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, ImageKit)
 SOFT_LINK_CLASS(ImageKit, IKSlideshow)
 
+static bool hasDataDetectorsCompletionAPI() {
+    static bool hasCompletionAPI;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        hasCompletionAPI = [getDDActionsManagerClass() respondsToSelector:@selector(shouldUseActionsWithContext:)] && [getDDActionsManagerClass() respondsToSelector:@selector(didUseActions)];
+    });
+    return hasCompletionAPI;
+}
+
 using namespace WebCore;
 using namespace WebKit;
 
@@ -156,9 +165,9 @@
 - (void)willDestroyView:(WKView *)view
 {
     _page = nullptr;
-    _wkView = nullptr;
+    _wkView = nil;
     _hitTestResult = ActionMenuHitTestResult();
-
+    _currentActionContext = nil;
 }
 
 - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
@@ -192,9 +201,16 @@
         return;
 
     if (_type == kWKActionMenuDataDetectedItem) {
+        if (_currentActionContext && hasDataDetectorsCompletionAPI()) {
+            if (![getDDActionsManagerClass() shouldUseActionsWithContext:_currentActionContext.get()]) {
+                [menu cancelTracking];
+                return;
+            }
+        }
         if (menu.numberOfItems == 1) {
             _page->clearSelection();
-            [self _showTextIndicator];
+            if (!hasDataDetectorsCompletionAPI())
+                [self _showTextIndicator];
         } else
             _page->selectLastActionMenuRange();
         return;
@@ -217,8 +233,15 @@
     if (menu != _wkView.actionMenu)
         return;
 
-    if (_type == kWKActionMenuDataDetectedItem && menu.numberOfItems > 1)
-        [self _hideTextIndicator];
+    if (_type == kWKActionMenuDataDetectedItem) {
+        if (hasDataDetectorsCompletionAPI()) {
+            if (_currentActionContext)
+                [getDDActionsManagerClass() didUseActions];
+        } else {
+            if (menu.numberOfItems > 1)
+                [self _hideTextIndicator];
+        }
+    }
 
     if (!_shouldKeepPreviewPopoverOpen)
         [self _clearPreviewPopover];
@@ -227,6 +250,7 @@
     _hitTestResult = ActionMenuHitTestResult();
     _type = kWKActionMenuNone;
     _sharingServicePicker = nil;
+    _currentActionContext = nil;
 }
 
 - (void)didPerformActionMenuHitTest:(const ActionMenuHitTestResult&)hitTestResult userData:(API::Object*)userData
@@ -560,13 +584,26 @@
     if (!actionContext)
         return @[ ];
 
-    actionContext.completionHandler = ^() {
-        [self _hideTextIndicator];
-    };
+    if (hasDataDetectorsCompletionAPI()) {
+        _currentActionContext = [actionContext contextForView:_wkView altMode:YES interactionStartedHandler:^() {
+        } interactionChangedHandler:^() {
+            [self _showTextIndicator];
+        } interactionStoppedHandler:^() {
+            [self _hideTextIndicator];
+        }];
+    } else {
+        _currentActionContext = actionContext;
 
-    actionContext.forActionMenuContent = YES;
-    actionContext.highlightFrame = [_wkView.window convertRectToScreen:[_wkView convertRect:_hitTestResult.detectedDataBoundingBox toView:nil]];
-    return [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_hitTestResult.actionContext mainResult] actionContext:actionContext];
+        [_currentActionContext setCompletionHandler:^() {
+            [self _hideTextIndicator];
+        }];
+
+        [_currentActionContext setForActionMenuContent:YES];
+    }
+
+    [_currentActionContext setHighlightFrame:[_wkView.window convertRectToScreen:[_wkView convertRect:_hitTestResult.detectedDataBoundingBox toView:nil]]];
+
+    return [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_currentActionContext mainResult] actionContext:_currentActionContext.get()];
 }
 
 - (NSArray *)_defaultMenuItemsForText
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to