WK1: Need new SPI for Webkit clients to override default immediate action
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Dec 2014 01:48:45 +0000 (01:48 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Dec 2014 01:48:45 +0000 (01:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139568
-and corresponding-
rdar://problem/19225448

Reviewed by Dan Bernstein.

Call SPI giving clients a chance to override the default behavior.
* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController _updateImmediateActionItem]):

New SPI.
* WebView/WebUIDelegatePrivate.h:

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

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebImmediateActionController.mm
Source/WebKit/mac/WebView/WebUIDelegatePrivate.h

index ccadfe1..31760f8 100644 (file)
@@ -1,3 +1,19 @@
+2014-12-11  Beth Dakin  <bdakin@apple.com>
+
+        WK1: Need new SPI for Webkit clients to override default immediate action
+        https://bugs.webkit.org/show_bug.cgi?id=139568
+        -and corresponding-
+        rdar://problem/19225448
+
+        Reviewed by Dan Bernstein.
+
+        Call SPI giving clients a chance to override the default behavior.
+        * WebView/WebImmediateActionController.mm:
+        (-[WebImmediateActionController _updateImmediateActionItem]):
+
+        New SPI.
+        * WebView/WebUIDelegatePrivate.h:
+
 2014-12-11  Timothy Horton  <timothy_horton@apple.com>
 
         Move the preview popover to WebImmediateActionController
index 888fb9a..6a4f4a2 100644 (file)
@@ -27,6 +27,7 @@
 
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
 
+#import "WebElementDictionary.h"
 #import "WebFrameInternal.h"
 #import "WebHTMLView.h"
 #import "WebHTMLViewInternal.h"
@@ -126,6 +127,7 @@ using namespace WebCore;
 {
     _type = WebImmediateActionNone;
     _immediateActionRecognizer.animationController = nil;
+    id <NSImmediateActionAnimationController> defaultAnimationController = nil;
 
     NSURL *url = _hitTestResult.absoluteLinkURL();
     NSString *absoluteURLString = [url absoluteString];
@@ -135,9 +137,22 @@ using namespace WebCore;
         RetainPtr<QLPreviewMenuItem> qlPreviewLinkItem = [NSMenuItem standardQuickLookMenuItem];
         [qlPreviewLinkItem setPreviewStyle:QLPreviewStylePopover];
         [qlPreviewLinkItem setDelegate:self];
-        _immediateActionRecognizer.animationController = (id<NSImmediateActionAnimationController>)qlPreviewLinkItem.get();
-        return;
+        defaultAnimationController = (id <NSImmediateActionAnimationController>)qlPreviewLinkItem.get();
+    }
+
+    // Allow clients the opportunity to override the default immediate action.
+    id customClientAnimationController = nil;
+    if ([[_webView UIDelegate] respondsToSelector:@selector(_webView:immediateActionAnimationControllerForHitTestResult:withType:)]) {
+        RetainPtr<WebElementDictionary> webHitTestResult = [[WebElementDictionary alloc] initWithHitTestResult:_hitTestResult];
+        customClientAnimationController = [[_webView UIDelegate] _webView:_webView immediateActionAnimationControllerForHitTestResult:webHitTestResult.get() withType:_type];
     }
+
+    if (customClientAnimationController == [NSNull null])
+        return;
+    if (customClientAnimationController && [customClientAnimationController conformsToProtocol:@protocol(NSImmediateActionAnimationController)])
+        _immediateActionRecognizer.animationController = (id <NSImmediateActionAnimationController>)customClientAnimationController;
+    else
+        _immediateActionRecognizer.animationController = defaultAnimationController;
 }
 
 #pragma mark QLPreviewMenuItemDelegate implementation
index 95e3d28..234cde5 100644 (file)
@@ -234,6 +234,10 @@ extern NSString *WebConsoleMessageErrorMessageLevel;
 - (void)webView:(WebView *)sender saveFrameView:(WebFrameView *)frameView showingPanel:(BOOL)showingPanel;
 - (NSArray *)_webView:(WebView *)sender actionMenuItemsForHitTestResult:(NSDictionary *)hitTestResult withType:(WebActionMenuType)type defaultActionMenuItems:(NSArray *)defaultMenuItems;
 - (DDActionContext *)_webView:(WebView *)sender actionContextForHitTestResult:(NSDictionary *)hitTestResult range:(DOMRange **)range;
+
+// Clients that want to maintain default behavior can return nil. To disable the immediate action entirely, return NSNull. And to
+// do something custom, return an object that conforms to the NSImmediateActionAnimationController protocol.
+- (id)_webView:(WebView *)sender immediateActionAnimationControllerForHitTestResult:(NSDictionary *)hitTestResult withType:(WebImmediateActionType)type;
 #endif
 - (BOOL)webView:(WebView *)sender didPressMissingPluginButton:(DOMElement *)element;
 /*!