Provide a way for WebKit1 clients to override default action menu items
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Oct 2014 20:08:13 +0000 (20:08 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Oct 2014 20:08:13 +0000 (20:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138066
-and corresponding-
rdar://problem/18451638

Reviewed by Anders Carlsson.

WebActionMenuController now has an ivar for the WebActionMenuType so that it can
send that along to clients customizing the menu.
* WebView/WebActionMenuController.h:
* WebView/WebActionMenuController.mm:
(-[WebActionMenuController prepareForMenu:withEvent:]):
(-[WebActionMenuController _defaultMenuItemsForHitTestResult:]):

New enum and new SPI to customize menus.
* WebView/WebUIDelegatePrivate.h:

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

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

index 4244b67..3f6722e 100644 (file)
@@ -1,3 +1,22 @@
+2014-10-27  Beth Dakin  <bdakin@apple.com>
+
+        Provide a way for WebKit1 clients to override default action menu items
+        https://bugs.webkit.org/show_bug.cgi?id=138066
+        -and corresponding-
+        rdar://problem/18451638
+
+        Reviewed by Anders Carlsson.
+
+        WebActionMenuController now has an ivar for the WebActionMenuType so that it can 
+        send that along to clients customizing the menu.
+        * WebView/WebActionMenuController.h:
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController prepareForMenu:withEvent:]):
+        (-[WebActionMenuController _defaultMenuItemsForHitTestResult:]):
+
+        New enum and new SPI to customize menus.
+        * WebView/WebUIDelegatePrivate.h:
+
 2014-10-24  Benjamin Poulain  <bpoulain@apple.com>
 
         Fix the iOS build
index d3cd8f6..5aa3542 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#import "WebUIDelegatePrivate.h"
+
 @class WebView;
 
 @interface WebActionMenuController : NSObject {
 @private
     WebView *_webView;
+    WebActionMenuType _type;
 }
 
 - (id)initWithWebView:(WebView *)webView;
index 21f57bf..d383aa5 100644 (file)
@@ -58,7 +58,9 @@ using namespace WebCore;
 {
     if (!(self = [super init]))
         return nil;
+
     _webView = webView;
+    _type = WebActionMenuNone;
 
     return self;
 }
@@ -81,9 +83,12 @@ using namespace WebCore;
 
     NSDictionary *hitTestResult = [_webView elementAtPoint:[_webView convertPoint:event.locationInWindow fromView:nil]];
 
-    // FIXME: We should support API for clients to customize the menu items.
     NSArray *menuItems = [self _defaultMenuItemsForHitTestResult:hitTestResult];
 
+    // Allow clients to customize the menu items.
+    if ([[_webView UIDelegate] respondsToSelector:@selector(_webView:actionMenuItemsForHitTestResult:withType:defaultActionMenuItems:)])
+        menuItems = [[_webView UIDelegate] _webView:_webView actionMenuItemsForHitTestResult:hitTestResult withType:_type defaultActionMenuItems:menuItems];
+
     for (NSMenuItem *item in menuItems)
         [actionMenu addItem:item];
 }
@@ -236,9 +241,13 @@ static NSImage *webKitBundleImageNamed(NSString *name)
 - (NSArray *)_defaultMenuItemsForHitTestResult:(NSDictionary *)hitTestResult
 {
     NSURL *url = [hitTestResult objectForKey:WebElementLinkURLKey];
-    if (url)
+
+    if (url) {
+        _type = WebActionMenuLink;
         return [self _defaultMenuItemsForLink:hitTestResult];
+    }
 
+    _type = WebActionMenuNone;
     return @[ ];
 }
 
index b56b76e..3f910bc 100644 (file)
@@ -112,6 +112,18 @@ enum {
     WebMenuItemTagBaseApplication = 10000
 };
 
+enum {
+    WebActionMenuItemTagNoAction = 0,
+    WebActionMenuItemTagOpenLinkInDefaultBrowser,
+    WebActionMenuItemTagPreviewLink,
+    WebActionMenuItemTagAddLinkToSafariReadingList
+};
+
+typedef enum {
+    WebActionMenuNone = 0,
+    WebActionMenuLink
+} WebActionMenuType;
+
 // Message Sources.
 extern NSString *WebConsoleMessageXMLMessageSource;
 extern NSString *WebConsoleMessageJSMessageSource;
@@ -193,6 +205,7 @@ extern NSString *WebConsoleMessageErrorMessageLevel;
 - (void)webView:(WebView *)sender willPopupMenu:(NSMenu *)menu;
 - (void)webView:(WebView *)sender contextMenuItemSelected:(NSMenuItem *)item forElement:(NSDictionary *)element;
 - (void)webView:(WebView *)sender saveFrameView:(WebFrameView *)frameView showingPanel:(BOOL)showingPanel;
+- (NSArray *)_webView:(WebView *)sender actionMenuItemsForHitTestResult:(NSDictionary *)hitTestResult withType:(WebActionMenuType)type defaultActionMenuItems:(NSArray *)defaultMenuItems;
 #endif
 - (BOOL)webView:(WebView *)sender didPressMissingPluginButton:(DOMElement *)element;
 /*!
@@ -269,11 +282,4 @@ extern NSString *WebConsoleMessageErrorMessageLevel;
 
 - (NSData *)webCryptoMasterKeyForWebView:(WebView *)sender;
 
-enum {
-    WebActionMenuItemTagNoAction = 0,
-    WebActionMenuItemTagOpenLinkInDefaultBrowser,
-    WebActionMenuItemTagPreviewLink,
-    WebActionMenuItemTagAddLinkToSafariReadingList
-};
-
 @end