Pipe custom context menu handling through to the UIDelegate object
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Oct 2015 21:41:36 +0000 (21:41 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Oct 2015 21:41:36 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150572

Reviewed by Tim Horton.

* UIProcess/API/APIContextMenuClient.h:
(API::ContextMenuClient::menuFromProposedMenu):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView setUIDelegate:]):
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::createContextMenuClient):
(WebKit::UIDelegate::ContextMenuClient::ContextMenuClient):
(WebKit::UIDelegate::ContextMenuClient::~ContextMenuClient):
(WebKit::UIDelegate::ContextMenuClient::menuFromProposedMenu):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::showContextMenu):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIContextMenuClient.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/Cocoa/UIDelegate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm

index f982338..1489c5d 100644 (file)
@@ -1,3 +1,23 @@
+2015-10-26  Anders Carlsson  <andersca@apple.com>
+
+        Pipe custom context menu handling through to the UIDelegate object
+        https://bugs.webkit.org/show_bug.cgi?id=150572
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/APIContextMenuClient.h:
+        (API::ContextMenuClient::menuFromProposedMenu):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView setUIDelegate:]):
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::createContextMenuClient):
+        (WebKit::UIDelegate::ContextMenuClient::ContextMenuClient):
+        (WebKit::UIDelegate::ContextMenuClient::~ContextMenuClient):
+        (WebKit::UIDelegate::ContextMenuClient::menuFromProposedMenu):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::showContextMenu):
+
 2015-10-26  Alex Christensen  <achristensen@webkit.org>
 
         Build fix when using NETWORK_SESSION after r191457.
index dd50f2e..f253c36 100644 (file)
@@ -32,6 +32,8 @@
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 
+OBJC_CLASS NSMenu;
+
 namespace WebCore {
 class IntPoint;
 }
@@ -52,6 +54,10 @@ public:
     virtual void customContextMenuItemSelected(WebKit::WebPageProxy&, const WebKit::WebContextMenuItemData&) { }
     virtual bool showContextMenu(WebKit::WebPageProxy&, const WebCore::IntPoint&, const Vector<RefPtr<WebKit::WebContextMenuItem>>&) { return false; }
     virtual bool hideContextMenu(WebKit::WebPageProxy&) { return false; }
+
+#if PLATFORM(MAC)
+    virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&) { return menu; }
+#endif
 };
 
 } // namespace API
index cd7eb8c..5931ef3 100644 (file)
@@ -449,6 +449,9 @@ static bool shouldAllowPictureInPictureMediaPlayback()
 
 - (void)setUIDelegate:(id<WKUIDelegate>)UIDelegate
 {
+#if ENABLE(CONTEXT_MENUS)
+    _page->setContextMenuClient(_uiDelegate->createContextMenuClient());
+#endif
     _page->setUIClient(_uiDelegate->createUIClient());
     _uiDelegate->setDelegate(UIDelegate);
 }
index eb43a65..816ea43 100644 (file)
@@ -30,6 +30,7 @@
 
 #if WK_API_ENABLED
 
+#import "APIContextMenuClient.h"
 #import "APIUIClient.h"
 #import "WeakObjCPtr.h"
 #import <wtf/RetainPtr.h>
@@ -45,12 +46,29 @@ public:
     explicit UIDelegate(WKWebView *);
     ~UIDelegate();
 
+#if ENABLE(CONTEXT_MENUS)
+    std::unique_ptr<API::ContextMenuClient> createContextMenuClient();
+#endif
     std::unique_ptr<API::UIClient> createUIClient();
 
     RetainPtr<id <WKUIDelegate> > delegate();
     void setDelegate(id <WKUIDelegate>);
 
 private:
+#if ENABLE(CONTEXT_MENUS)
+    class ContextMenuClient : public API::ContextMenuClient {
+    public:
+        explicit ContextMenuClient(UIDelegate&);
+        ~ContextMenuClient();
+
+    private:
+        // API::ContextMenuClient
+        virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *, const WebKit::WebHitTestResultData&) override;
+
+        UIDelegate& m_uiDelegate;
+    };
+#endif
+
     class UIClient : public API::UIClient {
     public:
         explicit UIClient(UIDelegate&);
index 0976d6b..1856d0c 100644 (file)
@@ -52,6 +52,13 @@ UIDelegate::~UIDelegate()
 {
 }
 
+#if ENABLE(CONTEXT_MENUS)
+std::unique_ptr<API::ContextMenuClient> UIDelegate::createContextMenuClient()
+{
+    return std::make_unique<ContextMenuClient>(*this);
+}
+#endif
+
 std::unique_ptr<API::UIClient> UIDelegate::createUIClient()
 {
     return std::make_unique<UIClient>(*this);
@@ -88,6 +95,25 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewImageOrMediaDocumentSizeChanged = [delegate respondsToSelector:@selector(_webView:imageOrMediaDocumentSizeChanged:)];
 }
 
+#if ENABLE(CONTEXT_MENUS)
+UIDelegate::ContextMenuClient::ContextMenuClient(UIDelegate& uiDelegate)
+    : m_uiDelegate(uiDelegate)
+{
+}
+
+UIDelegate::ContextMenuClient::~ContextMenuClient()
+{
+}
+
+RetainPtr<NSMenu> UIDelegate::ContextMenuClient::menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&)
+{
+    // FIXME: Call the UI delegate.
+    (void)m_uiDelegate;
+
+    return menu;
+}
+#endif
+
 UIDelegate::UIClient::UIClient(UIDelegate& uiDelegate)
     : m_uiDelegate(uiDelegate)
 {
index 6c48d47..448c0bd 100644 (file)
@@ -367,6 +367,7 @@ void WebContextMenuProxyMac::showContextMenu()
     Vector<RefPtr<WebContextMenuItem>> clientItems;
     bool useProposedItems = true;
 
+    // FIXME: Get rid of this once we don't need the C SPI.
     if (m_page.contextMenuClient().getContextMenuFromProposedMenu(m_page, proposedAPIItems, clientItems, m_context.webHitTestResultData(), m_page.process().transformHandlesToObjects(m_userData.object()).get()))
         useProposedItems = false;
 
@@ -377,7 +378,8 @@ void WebContextMenuProxyMac::showContextMenu()
     if (items.isEmpty())
         return;
 
-    m_menu = createContextMenuFromItems(items);
+    auto menu = createContextMenuFromItems(items);
+    m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData());
 
     [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
     [m_menu popUpMenuPositioningItem:nil atLocation:m_context.menuLocation() inView:m_webView];