<rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Nov 2010 18:34:04 +0000 (18:34 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Nov 2010 18:34:04 +0000 (18:34 +0000)
Context menu support for WebKit 2.

Reviewed by Anders Carlsson.

WebCore:

Add a "showContextMenu" call to Chrome/ChromeClient:
* loader/EmptyClients.h:
(WebCore::EmptyChromeClient::showContextMenu):
* page/Chrome.cpp:
(WebCore::Chrome::showContextMenu):
* page/Chrome.h:
* page/ChromeClient.h:

Add a "platform description to ContextMenuItem" creator, will be needed by WebKit2
* platform/ContextMenu.h:
* platform/mac/ContextMenuMac.mm:
(WebCore::contextMenuItemVector):

* platform/mac/ContextMenuItemMac.mm:
(WebCore::ContextMenuItem::checked): WebKit2 ports now need this implemented.

Stub these out to keep their WK2 ports building:
* platform/qt/ContextMenuItemQt.cpp:
(WebCore::ContextMenuItem::checked):
* platform/qt/ContextMenuQt.cpp:
(WebCore::contextMenuItemVector):
* platform/win/ContextMenuItemWin.cpp:
(WebCore::ContextMenuItem::checked):
* platform/win/ContextMenuWin.cpp:
(WebCore::contextMenuItemVector):

WebKit/chromium:

* src/ChromeClientImpl.h:
(WebKit::ChromeClientImpl::showContextMenu):

WebKit/efl:

* WebCoreSupport/ChromeClientEfl.h:
(WebCore::ChromeClientEfl::showContextMenu):

WebKit/gtk:

* WebCoreSupport/ChromeClientGtk.h:
(WebKit::ChromeClient::showContextMenu):

WebKit/haiku:

* WebCoreSupport/ChromeClientHaiku.h:
(WebCore::ChromeClientHaiku::showContextMenu):

WebKit/mac:

* WebCoreSupport/WebChromeClient.h:
(WebChromeClient::showContextMenu):

WebKit/qt:

* WebCoreSupport/ChromeClientQt.h:
(WebCore::ChromeClientQt::showContextMenu):

WebKit/win:

* WebCoreSupport/WebChromeClient.h:
(WebChromeClient::showContextMenu):

WebKit/wx:

* WebKitSupport/ChromeClientWx.h:
(WebCore::ChromeClientWx::showContextMenu):

WebKit2:

* WebKit2.pro:
* WebKit2.xcodeproj/project.pbxproj:
* win/WebKit2.vcproj:

* Shared/WebContextMenuItem.cpp: Added.
(WebKit::WebContextMenuItem::WebContextMenuItem):
(WebKit::WebContextMenuItem::encode):
(WebKit::WebContextMenuItem::decode):
(WebKit::kitItems):
* Shared/WebContextMenuItem.h: Added.

* UIProcess/API/mac/PageClientImpl.h:
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/API/qt/qwkpage.cpp:
(QWKPagePrivate::createContextMenuProxy): Stub to keep the build working.
* UIProcess/API/qt/qwkpage_p.h:
* UIProcess/PageClient.h:

* UIProcess/WebContextMenuProxy.cpp: Added.
(WebKit::WebContextMenuProxy::~WebContextMenuProxy):
(WebKit::WebContextMenuProxy::WebContextMenuProxy):
* UIProcess/WebContextMenuProxy.h: Added.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showContextMenu): Shows the menu after receiving the message from the WebProcess.
(WebKit::WebPageProxy::contextMenuItemSelected): Sends info about the selected menu item to the WebProcess
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* UIProcess/mac/WebContextMenuProxyMac.h: Added.
(WebKit::WebContextMenuProxyMac::create):
* UIProcess/mac/WebContextMenuProxyMac.mm: Added.
(+[WebMenuTarget sharedMenuTarget]):
(-[WebMenuTarget WebKit::]):
(-[WebMenuTarget setMenuProxy:WebKit::]):
(-[WebMenuTarget forwardContextMenuAction:]):
(WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::contextMenuItemSelected):
(WebKit::populateNSMenu):
(WebKit::nsMenuItemVector):
(WebKit::WebContextMenuProxyMac::populate):
(WebKit::WebContextMenuProxyMac::showContextMenu):
(WebKit::WebContextMenuProxyMac::hideContextMenu):

* UIProcess/win/WebView.cpp:
(WebKit::WebView::createContextMenuProxy): Stub for now.
* UIProcess/win/WebView.h:

* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::showContextMenu):
* WebProcess/WebCoreSupport/WebChromeClient.h:

* WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
(WebKit::WebContextMenuClient::getCustomMenuFromDefaultItems): Return the WebCore-provided default
  menu for now. Embedding app customization will come later (see bug 48720)

* WebProcess/WebPage/WebContextMenu.cpp: Added.
(WebKit::WebContextMenu::WebContextMenu):
(WebKit::WebContextMenu::~WebContextMenu):
(WebKit::WebContextMenu::show):
(WebKit::WebContextMenu::itemSelected):
* WebProcess/WebPage/WebContextMenu.h: Added.
(WebKit::WebContextMenu::create):

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::contextMenu):
(WebKit::handleMouseEvent): Pass right mouse presses along to WebCore as both a mouse event and context menu event,
  the same way WebKit1 does.
(WebKit::WebPage::didSelectItemFromActiveContextMenu):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

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

58 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp.in
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/loader/EmptyClients.h
WebCore/page/Chrome.cpp
WebCore/page/Chrome.h
WebCore/page/ChromeClient.h
WebCore/platform/ContextMenu.h
WebCore/platform/mac/ContextMenuItemMac.mm
WebCore/platform/mac/ContextMenuMac.mm
WebCore/platform/qt/ContextMenuItemQt.cpp
WebCore/platform/qt/ContextMenuQt.cpp
WebCore/platform/win/ContextMenuItemWin.cpp
WebCore/platform/win/ContextMenuWin.cpp
WebKit/chromium/ChangeLog
WebKit/chromium/src/ChromeClientImpl.h
WebKit/efl/ChangeLog
WebKit/efl/WebCoreSupport/ChromeClientEfl.h
WebKit/gtk/ChangeLog
WebKit/gtk/WebCoreSupport/ChromeClientGtk.h
WebKit/haiku/ChangeLog
WebKit/haiku/WebCoreSupport/ChromeClientHaiku.h
WebKit/mac/ChangeLog
WebKit/mac/WebCoreSupport/WebChromeClient.h
WebKit/qt/ChangeLog
WebKit/qt/WebCoreSupport/ChromeClientQt.h
WebKit/win/ChangeLog
WebKit/win/WebCoreSupport/WebChromeClient.h
WebKit/wx/ChangeLog
WebKit/wx/WebKitSupport/ChromeClientWx.h
WebKit2/ChangeLog
WebKit2/Shared/WebContextMenuItem.cpp [new file with mode: 0644]
WebKit2/Shared/WebContextMenuItem.h [new file with mode: 0644]
WebKit2/UIProcess/API/mac/PageClientImpl.h
WebKit2/UIProcess/API/mac/PageClientImpl.mm
WebKit2/UIProcess/API/qt/qwkpage.cpp
WebKit2/UIProcess/API/qt/qwkpage_p.h
WebKit2/UIProcess/PageClient.h
WebKit2/UIProcess/WebContextMenuProxy.cpp [new file with mode: 0644]
WebKit2/UIProcess/WebContextMenuProxy.h [new file with mode: 0644]
WebKit2/UIProcess/WebPageProxy.cpp
WebKit2/UIProcess/WebPageProxy.h
WebKit2/UIProcess/WebPageProxy.messages.in
WebKit2/UIProcess/mac/WebContextMenuProxyMac.h [new file with mode: 0644]
WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm [new file with mode: 0644]
WebKit2/UIProcess/win/WebView.cpp
WebKit2/UIProcess/win/WebView.h
WebKit2/WebKit2.pro
WebKit2/WebKit2.xcodeproj/project.pbxproj
WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.cpp
WebKit2/WebProcess/WebPage/WebContextMenu.cpp [new file with mode: 0644]
WebKit2/WebProcess/WebPage/WebContextMenu.h [new file with mode: 0644]
WebKit2/WebProcess/WebPage/WebPage.cpp
WebKit2/WebProcess/WebPage/WebPage.h
WebKit2/WebProcess/WebPage/WebPage.messages.in
WebKit2/win/WebKit2.vcproj

index ea759e2..eb8c777 100644 (file)
@@ -1,3 +1,36 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        Add a "showContextMenu" call to Chrome/ChromeClient:
+        * loader/EmptyClients.h:
+        (WebCore::EmptyChromeClient::showContextMenu):
+        * page/Chrome.cpp:
+        (WebCore::Chrome::showContextMenu):
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+
+        Add a "platform description to ContextMenuItem" creator, will be needed by WebKit2
+        * platform/ContextMenu.h:
+        * platform/mac/ContextMenuMac.mm:
+        (WebCore::contextMenuItemVector):
+
+        * platform/mac/ContextMenuItemMac.mm:
+        (WebCore::ContextMenuItem::checked): WebKit2 ports now need this implemented.
+
+        Stub these out to keep their WK2 ports building:
+        * platform/qt/ContextMenuItemQt.cpp:
+        (WebCore::ContextMenuItem::checked):
+        * platform/qt/ContextMenuQt.cpp:
+        (WebCore::contextMenuItemVector):
+        * platform/win/ContextMenuItemWin.cpp:
+        (WebCore::ContextMenuItem::checked):
+        * platform/win/ContextMenuWin.cpp:
+        (WebCore::contextMenuItemVector):
+
 2010-11-01  Eric Carlson  <eric.carlson@apple.com>
 
         Reviewed by Adam Roben.
index a4d5dbc..dc207bf 100644 (file)
@@ -1225,9 +1225,22 @@ __ZNK7WebCore18RenderLayerBacking20compositingLayerTypeEv
 #if ENABLE(CONTEXT_MENUS)
 __ZN7WebCore11ContextMenu22setPlatformDescriptionEP14NSMutableArray
 __ZN7WebCore12EventHandler20sendContextMenuEventEP7NSEvent
+__ZN7WebCore12EventHandler20sendContextMenuEventERKNS_18PlatformMouseEventE
 __ZN7WebCore15ContextMenuItem26releasePlatformDescriptionEv
+__ZN7WebCore15ContextMenuItemC1ENS_19ContextMenuItemTypeENS_17ContextMenuActionERKN3WTF6StringEPNS_11ContextMenuE
+__ZN7WebCore15ContextMenuItemD1Ev
 __ZN7WebCore21ContextMenuController16clearContextMenuEv
+__ZN7WebCore21ContextMenuController23contextMenuItemSelectedEPNS_15ContextMenuItemE
+__ZN7WebCore21contextMenuItemVectorEP14NSMutableArray
+__ZN7WebCore6Chrome15showContextMenuEv
 __ZNK7WebCore11ContextMenu19platformDescriptionEv
+__ZNK7WebCore11ContextMenu21checkOrEnableIfNeededERNS_15ContextMenuItemE
+__ZNK7WebCore15ContextMenuItem15platformSubMenuEv
+__ZNK7WebCore15ContextMenuItem4typeEv
+__ZNK7WebCore15ContextMenuItem5titleEv
+__ZNK7WebCore15ContextMenuItem6actionEv
+__ZNK7WebCore15ContextMenuItem7checkedEv
+__ZNK7WebCore15ContextMenuItem7enabledEv
 #endif
 
 #if ENABLE(DASHBOARD_SUPPORT)
index b3a8d86..d2d683b 100644 (file)
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
                        compatibilityVersion = "Xcode 2.4";
+                       developmentRegion = English;
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index 0dba4ee..6d37907 100644 (file)
@@ -139,6 +139,10 @@ public:
     virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const { return adoptRef(new EmptyPopupMenu()); }
     virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const { return adoptRef(new EmptySearchPopupMenu()); }
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
+
     virtual void setStatusbarText(const String&) { }
 
     virtual bool tabsToLinks() const { return false; }
index 762b087..aed2784 100644 (file)
@@ -502,4 +502,11 @@ PassRefPtr<SearchPopupMenu> Chrome::createSearchPopupMenu(PopupMenuClient* clien
     return m_client->createSearchPopupMenu(client);
 }
 
+#if ENABLE(CONTEXT_MENUS)
+void Chrome::showContextMenu()
+{
+    m_client->showContextMenu();
+}
+#endif
+
 } // namespace WebCore
index 9f43b11..97665da 100644 (file)
@@ -155,6 +155,10 @@ namespace WebCore {
         PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;
         PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;
 
+#if ENABLE(CONTEXT_MENUS)
+        void showContextMenu();
+#endif
+
     private:
         Page* m_page;
         ChromeClient* m_client;
index abeabf9..22f1814 100644 (file)
@@ -269,6 +269,10 @@ namespace WebCore {
         virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const = 0;
         virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const = 0;
 
+#if ENABLE(CONTEXT_MENUS)
+        virtual void showContextMenu() = 0;
+#endif
+
         virtual void postAccessibilityNotification(AccessibilityObject*, AXObjectCache::AXNotification) { }
 
     protected:
index ca21f29..2a2a017 100644 (file)
@@ -91,6 +91,8 @@ namespace WebCore {
 #endif
     };
 
+Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription);
+
 }
 
 #endif // ContextMenu_h
index 48da786..ce779ec 100644 (file)
@@ -154,6 +154,11 @@ bool ContextMenuItem::enabled() const
     return [m_platformDescription.get() isEnabled];
 }
 
+bool ContextMenuItem::checked() const
+{
+    return [m_platformDescription.get() state] == NSOnState;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(CONTEXT_MENUS)
index 8ced8cb..c427e3c 100644 (file)
@@ -153,6 +153,19 @@ NSMutableArray* ContextMenu::releasePlatformDescription()
     return m_platformDescription.releaseRef();
 }
 
+Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription menu)
+{
+    Vector<ContextMenuItem> items;
+    unsigned count = [menu count];
+    if (menu)
+        items.reserveCapacity(count);
+    
+    for (unsigned i = 0; i < count; ++i)
+        items.append(ContextMenuItem([menu objectAtIndex:i]));
+    
+    return items;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(CONTEXT_MENUS)
index b91a2a7..a65e50c 100644 (file)
@@ -104,6 +104,12 @@ void ContextMenuItem::setChecked(bool on)
     m_platformDescription.checked = on;
 }
 
+bool ContextMenuItem::checked() const
+{
+    // FIXME - Implement
+    return false;
+}
+
 void ContextMenuItem::setEnabled(bool on)
 {
     m_platformDescription.enabled = on;
index 30c4c2d..2c1a6cb 100644 (file)
@@ -74,6 +74,11 @@ PlatformMenuDescription ContextMenu::releasePlatformDescription()
     return PlatformMenuDescription();
 }
 
+Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription)
+{
+    // FIXME - Implement    
+    return Vector<ContextMenuItem>();
+}
 
 }
 // vim: ts=4 sw=4 et
index ade0db0..d2ce76d 100644 (file)
@@ -184,6 +184,12 @@ void ContextMenuItem::setChecked(bool checked)
     }
 }
 
+bool ContextMenuItem::checked() const
+{
+    // FIXME - Implement
+    return false;
+}
+
 void ContextMenuItem::setEnabled(bool enabled)
 {
     m_platformDescription->fMask |= MIIM_STATE;
index 5260866..82511e4 100644 (file)
@@ -155,4 +155,10 @@ HMENU ContextMenu::releasePlatformDescription()
     return description;
 }
 
+Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription)
+{
+    // FIXME - Implement    
+    return Vector<ContextMenuItem>();
+}
+
 }
index 5450843..ff509a9 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * src/ChromeClientImpl.h:
+        (WebKit::ChromeClientImpl::showContextMenu):
+
 2010-11-01  Pavel Feldman  <pfeldman@chromium.org>
 
         Not reviewed: Chromium build fix.
index 039fc1b..fbebf62 100644 (file)
@@ -174,6 +174,10 @@ public:
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
+
 private:
     void getPopupMenuInfo(WebCore::PopupContainer*, WebPopupMenuInfo*);
 
index d9b5222..f46c247 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebCoreSupport/ChromeClientEfl.h:
+        (WebCore::ChromeClientEfl::showContextMenu):
+
 2010-10-29  Daniel Bates  <dbates@rim.com>
 
         No review, rolling out 70971.
index f0aeb8d..53cac59 100644 (file)
@@ -115,6 +115,10 @@ public:
     virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*);
 #endif
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
+
     virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
     virtual void chooseIconForFiles(const Vector<String>&, FileChooser*);
     virtual void formStateDidChange(const Node*);
index c8e3df3..b6d4e9b 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebCoreSupport/ChromeClientGtk.h:
+        (WebKit::ChromeClient::showContextMenu):
+
 2010-11-01  Martin Robinson  <mrobinson@igalia.com>
 
         Reviewed by Xan Lopez.
index b925313..87f1dab 100644 (file)
@@ -117,6 +117,9 @@ namespace WebKit {
         virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
         virtual void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin*);
 #endif
+#if ENABLE(CONTEXT_MENUS)
+        virtual void showContextMenu() { }
+#endif
         virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
         virtual void chooseIconForFiles(const Vector<WTF::String>&, WebCore::FileChooser*);
 
index 7ed4fad..6d43561 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebCoreSupport/ChromeClientHaiku.h:
+        (WebCore::ChromeClientHaiku::showContextMenu):
+
 2010-10-29  Alexey Proskuryakov  <ap@apple.com>
 
         Reviewed by Darin Adler.
index 9409c69..e8f488e 100644 (file)
@@ -137,6 +137,9 @@ namespace WebCore {
         virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
         virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*);
 #endif
+#if ENABLE(CONTEXT_MENUS)
+        virtual void showContextMenu() { }
+#endif
 
         // This is an asynchronous call. The ChromeClient can display UI asking the user for permission
         // to use Geolococation.
index cec4718..f328e4e 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebCoreSupport/WebChromeClient.h:
+        (WebChromeClient::showContextMenu):
+
 2010-10-29  Daniel Bates  <dbates@rim.com>
 
         No review, rolling out 70971.
index 209c2b9..890637e 100644 (file)
@@ -178,6 +178,9 @@ public:
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
 private:
     WebView *m_webView;
 };
index 8bffa0b..320fc88 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebCoreSupport/ChromeClientQt.h:
+        (WebCore::ChromeClientQt::showContextMenu):
+
 2010-10-31  Robert Hogan  <robert@webkit.org>
 
         Reviewed by Antonio Gomes.
index bbd2452..71b9626 100644 (file)
@@ -134,6 +134,9 @@ namespace WebCore {
         virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
         virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*);
 #endif
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
 
 #if ENABLE(NOTIFICATIONS)
         virtual NotificationPresenter* notificationPresenter() const;
index 6af6b3e..cb65428 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebCoreSupport/WebChromeClient.h:
+        (WebChromeClient::showContextMenu):
+
 2010-11-01  Adam Roben  <aroben@apple.com>
 
         Cancel main resource loads after we hand them off to the media engine
index 5167c06..bfa3c80 100644 (file)
@@ -122,6 +122,10 @@ public:
     virtual void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin*);
 #endif
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
+
     virtual void populateVisitedLinks();
 
     virtual bool paintCustomScrollbar(WebCore::GraphicsContext*, const WebCore::FloatRect&, WebCore::ScrollbarControlSize, 
index 123b839..3895a2e 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebKitSupport/ChromeClientWx.h:
+        (WebCore::ChromeClientWx::showContextMenu):
+
 2010-10-29  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam Weinig.
index 755beb7..3ca763e 100644 (file)
@@ -129,6 +129,10 @@ public:
     virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*);
 #endif
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu() { }
+#endif
+
     virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
     virtual void chooseIconForFiles(const Vector<String>&, FileChooser*);
 
index 8b690a6..adc5b4d 100644 (file)
@@ -1,3 +1,84 @@
+2010-11-01  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/7660547> and https://bugs.webkit.org/show_bug.cgi?id=48699
+        Context menu support for WebKit 2.
+
+        * WebKit2.pro:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * win/WebKit2.vcproj:
+
+        * Shared/WebContextMenuItem.cpp: Added.
+        (WebKit::WebContextMenuItem::WebContextMenuItem):
+        (WebKit::WebContextMenuItem::encode):
+        (WebKit::WebContextMenuItem::decode):
+        (WebKit::kitItems):
+        * Shared/WebContextMenuItem.h: Added.
+
+        * UIProcess/API/mac/PageClientImpl.h:
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::createContextMenuProxy):
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPagePrivate::createContextMenuProxy): Stub to keep the build working.
+        * UIProcess/API/qt/qwkpage_p.h:
+        * UIProcess/PageClient.h:
+
+        * UIProcess/WebContextMenuProxy.cpp: Added.
+        (WebKit::WebContextMenuProxy::~WebContextMenuProxy):
+        (WebKit::WebContextMenuProxy::WebContextMenuProxy):
+        * UIProcess/WebContextMenuProxy.h: Added.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::showContextMenu): Shows the menu after receiving the message from the WebProcess.
+        (WebKit::WebPageProxy::contextMenuItemSelected): Sends info about the selected menu item to the WebProcess
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        * UIProcess/mac/WebContextMenuProxyMac.h: Added.
+        (WebKit::WebContextMenuProxyMac::create):
+        * UIProcess/mac/WebContextMenuProxyMac.mm: Added.
+        (+[WebMenuTarget sharedMenuTarget]):
+        (-[WebMenuTarget WebKit::]):
+        (-[WebMenuTarget setMenuProxy:WebKit::]):
+        (-[WebMenuTarget forwardContextMenuAction:]):
+        (WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
+        (WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac):
+        (WebKit::WebContextMenuProxyMac::contextMenuItemSelected):
+        (WebKit::populateNSMenu):
+        (WebKit::nsMenuItemVector):
+        (WebKit::WebContextMenuProxyMac::populate):
+        (WebKit::WebContextMenuProxyMac::showContextMenu):
+        (WebKit::WebContextMenuProxyMac::hideContextMenu):
+
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::createContextMenuProxy): Stub for now.
+        * UIProcess/win/WebView.h:
+
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::showContextMenu):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
+        * WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
+        (WebKit::WebContextMenuClient::getCustomMenuFromDefaultItems): Return the WebCore-provided default
+          menu for now. Embedding app customization will come later (see bug 48720)
+
+        * WebProcess/WebPage/WebContextMenu.cpp: Added.
+        (WebKit::WebContextMenu::WebContextMenu):
+        (WebKit::WebContextMenu::~WebContextMenu):
+        (WebKit::WebContextMenu::show):
+        (WebKit::WebContextMenu::itemSelected):
+        * WebProcess/WebPage/WebContextMenu.h: Added.
+        (WebKit::WebContextMenu::create):
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::contextMenu):
+        (WebKit::handleMouseEvent): Pass right mouse presses along to WebCore as both a mouse event and context menu event, 
+          the same way WebKit1 does.
+        (WebKit::WebPage::didSelectItemFromActiveContextMenu):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2010-11-01  Adam Roben  <aroben@apple.com>
 
         Cancel main resource loads after we hand them off to the media engine
diff --git a/WebKit2/Shared/WebContextMenuItem.cpp b/WebKit2/Shared/WebContextMenuItem.cpp
new file mode 100644 (file)
index 0000000..ea83426
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "WebContextMenuItem.h"
+
+#include "ArgumentCoders.h"
+#include "Arguments.h"
+#include <wtf/text/CString.h>
+#include <WebCore/ContextMenu.h>
+
+namespace WebKit {
+
+WebContextMenuItem::WebContextMenuItem()
+    : m_type(WebCore::ActionType)
+    , m_action(WebCore::ContextMenuItemTagNoAction)
+    , m_enabled(true)
+    , m_checked(false)
+{
+}
+
+WebContextMenuItem::WebContextMenuItem(WebCore::ContextMenuItemType type, WebCore::ContextMenuAction action, const String& title, bool enabled, bool checked)
+    : m_type(type)
+    , m_action(action)
+    , m_title(title)
+    , m_enabled(enabled)
+    , m_checked(checked)
+{
+    ASSERT(type == WebCore::ActionType || type == WebCore::CheckableActionType || type == WebCore::SeparatorType);
+}
+
+WebContextMenuItem::WebContextMenuItem(WebCore::ContextMenuAction action, const String& title, bool enabled, const Vector<WebContextMenuItem>& submenu)
+    : m_type(WebCore::SubmenuType)
+    , m_action(action)
+    , m_title(title)
+    , m_enabled(enabled)
+    , m_checked(false)
+    , m_submenu(submenu)
+{
+}
+
+WebContextMenuItem::WebContextMenuItem(WebCore::ContextMenuItem& item, WebCore::ContextMenu* menu)
+    : m_type(item.type())
+    , m_action(item.action())
+    , m_title(item.title())
+{
+    if (m_type == WebCore::SubmenuType) {
+        Vector<WebCore::ContextMenuItem> coreSubmenu = WebCore::contextMenuItemVector(item.platformSubMenu());
+        m_submenu = kitItems(coreSubmenu, menu);
+    }
+    
+    menu->checkOrEnableIfNeeded(item);
+    
+    m_enabled = item.enabled();
+    m_checked = item.checked();
+}
+
+void WebContextMenuItem::encode(CoreIPC::ArgumentEncoder* encoder) const
+{
+    encoder->encode(CoreIPC::In(static_cast<uint32_t>(m_type), static_cast<uint32_t>(m_action), m_title, m_checked, m_enabled, m_submenu));
+}
+
+bool WebContextMenuItem::decode(CoreIPC::ArgumentDecoder* decoder, WebContextMenuItem& item)
+{
+    uint32_t type;
+    uint32_t action;
+    String title;
+    bool checked;
+    bool enabled;
+    Vector<WebContextMenuItem> submenu;
+
+    if (!decoder->decode(CoreIPC::Out(type, action, title, checked, enabled, submenu)))
+        return false;
+
+    switch (type) {
+    case WebCore::ActionType:
+    case WebCore::SeparatorType:
+    case WebCore::CheckableActionType:
+        item = WebContextMenuItem(static_cast<WebCore::ContextMenuItemType>(type), static_cast<WebCore::ContextMenuAction>(action), title, enabled, checked);
+        break;
+    case WebCore::SubmenuType:
+        item = WebContextMenuItem(static_cast<WebCore::ContextMenuAction>(action), title, enabled, submenu);
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        return false;
+    }
+
+    return true;
+}
+
+Vector<WebContextMenuItem> kitItems(Vector<WebCore::ContextMenuItem>& coreItems, WebCore::ContextMenu* menu)
+{
+    Vector<WebContextMenuItem> result;
+    result.reserveCapacity(coreItems.size());
+    for (unsigned i = 0; i < coreItems.size(); ++i)
+        result.append(WebContextMenuItem(coreItems[i], menu));
+    
+    return result;
+}
+
+} // namespace WebKit
diff --git a/WebKit2/Shared/WebContextMenuItem.h b/WebKit2/Shared/WebContextMenuItem.h
new file mode 100644 (file)
index 0000000..de98b9d
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebContextMenuItem_h
+#define WebContextMenuItem_h
+
+#include <WebCore/ContextMenuItem.h>
+#include <wtf/text/WTFString.h>
+
+namespace CoreIPC {
+    class ArgumentDecoder;
+    class ArgumentEncoder;
+}
+
+namespace WebCore {
+    class ContextMenu;
+}
+
+namespace WebKit {
+
+class WebContextMenuItem {
+public:
+    WebContextMenuItem();
+    WebContextMenuItem(WebCore::ContextMenuItem&, WebCore::ContextMenu* menu);
+    WebContextMenuItem(WebCore::ContextMenuItemType, WebCore::ContextMenuAction, const String& title, bool enabled, bool checked);
+    WebContextMenuItem(WebCore::ContextMenuAction, const String& title, bool enabled, const Vector<WebContextMenuItem>& submenu);
+
+    WebCore::ContextMenuItemType type() const { return m_type; }
+    WebCore::ContextMenuAction action() const { return m_action; }
+    const String& title() const { return m_title; }
+    bool enabled() const { return m_enabled; }
+    bool checked() const { return m_checked; }
+    const Vector<WebContextMenuItem>& submenu() const { return m_submenu; }
+    
+    void encode(CoreIPC::ArgumentEncoder*) const;
+    static bool decode(CoreIPC::ArgumentDecoder*, WebContextMenuItem&);
+
+private:
+    WebCore::ContextMenuItemType m_type;
+    WebCore::ContextMenuAction m_action;
+    String m_title;
+    bool m_enabled;
+    bool m_checked;
+    Vector<WebContextMenuItem> m_submenu;
+};
+
+Vector<WebContextMenuItem> kitItems(Vector<WebCore::ContextMenuItem>&, WebCore::ContextMenu*);
+
+} // namespace WebKit
+
+#endif // WebContextMenuItem_h
index 8fc7376..236a274 100644 (file)
@@ -66,6 +66,7 @@ private:
     virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
 
     virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy();
+    virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
 
     void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut);
 
index 0f25121..3532cd2 100644 (file)
@@ -30,6 +30,7 @@
 #import "WKAPICast.h"
 #import "WKStringCF.h"
 #import "WKViewInternal.h"
+#import "WebContextMenuProxyMac.h"
 #import "WebEditCommandProxy.h"
 #import "WebPopupMenuProxyMac.h"
 #import <WebCore/Cursor.h>
@@ -245,6 +246,11 @@ PassRefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy()
     return WebPopupMenuProxyMac::create(m_wkView);
 }
 
+PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page)
+{
+    return WebContextMenuProxyMac::create(m_wkView, page);
+}
+
 void PageClientImpl::setFindIndicator(PassRefPtr<FindIndicator> findIndicator, bool fadeOut)
 {
     [m_wkView _setFindIndicator:findIndicator fadeOut:fadeOut];
index 67603b0..6cefcc2 100644 (file)
@@ -30,6 +30,7 @@
 #include "LocalizedStrings.h"
 #include "NativeWebKeyboardEvent.h"
 #include "WebContext.h"
+#include "WebContextMenuProxy.h"
 #include "WebEventFactoryQt.h"
 #include "WebPlatformStrategies.h"
 #include "WebPopupMenuProxyQt.h"
@@ -134,6 +135,12 @@ PassRefPtr<WebPopupMenuProxy> QWKPagePrivate::createPopupMenuProxy()
     return WebPopupMenuProxyQt::create();
 }
 
+PassRefPtr<WebContextMenuProxy> QWKPagePrivate::createContextMenuProxy(WebPageProxy*)
+{
+    // FIXME: Implement;
+    return 0;
+}
+
 void QWKPagePrivate::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut)
 {
 }
index 73fbe33..531b085 100644 (file)
@@ -61,6 +61,7 @@ public:
     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
     virtual void didNotHandleKeyEvent(const WebKit::NativeWebKeyboardEvent&);
     virtual PassRefPtr<WebKit::WebPopupMenuProxy> createPopupMenuProxy();
+    virtual PassRefPtr<WebKit::WebContextMenuProxy> createContextMenuProxy(WebKit::WebPageProxy*);
 
     virtual void setFindIndicator(PassRefPtr<WebKit::FindIndicator>, bool fadeOut);
 
index b94f0ad..0bee10c 100644 (file)
@@ -39,8 +39,9 @@ namespace WebKit {
 
 class FindIndicator;
 class NativeWebKeyboardEvent;
-class WebEditCommandProxy;
 class NativeWebKeyboardEvent;
+class WebContextMenuProxy;
+class WebEditCommandProxy;
 class WebPopupMenuProxy;
 
 class PageClient {
@@ -72,6 +73,7 @@ public:
     virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&) = 0;
 
     virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy() = 0;
+    virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*) = 0;
 
     virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut) = 0;
 
diff --git a/WebKit2/UIProcess/WebContextMenuProxy.cpp b/WebKit2/UIProcess/WebContextMenuProxy.cpp
new file mode 100644 (file)
index 0000000..887a260
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "WebContextMenuProxy.h"
+
+namespace WebKit {
+
+WebContextMenuProxy::WebContextMenuProxy()
+{
+}
+
+WebContextMenuProxy::~WebContextMenuProxy()
+{
+}
+
+} // namespace WebKit
diff --git a/WebKit2/UIProcess/WebContextMenuProxy.h b/WebKit2/UIProcess/WebContextMenuProxy.h
new file mode 100644 (file)
index 0000000..6af9b40
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebContextMenuProxy_h
+#define WebContextMenuProxy_h
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+    class IntPoint;
+}
+
+namespace WebKit {
+
+struct WebContextMenuItem;
+
+class WebContextMenuProxy : public RefCounted<WebContextMenuProxy> {
+public:
+    virtual ~WebContextMenuProxy();
+
+    virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItem>& items) = 0;
+    virtual void hideContextMenu() = 0;
+
+protected:
+    WebContextMenuProxy();
+};
+
+} // namespace WebKit
+
+#endif // WebPopupMenuProxy_h
index 828367f..c91bc00 100644 (file)
@@ -36,6 +36,7 @@
 #include "WebBackForwardListItem.h"
 #include "WebCertificateInfo.h"
 #include "WebContext.h"
+#include "WebContextMenuProxy.h"
 #include "WebContextUserMessageCoders.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebData.h"
@@ -1124,6 +1125,21 @@ void WebPageProxy::hidePopupMenu()
     m_activePopupMenu = 0;
 }
 
+void WebPageProxy::showContextMenu(const WebCore::IntPoint& menuLocation, const Vector<WebContextMenuItem>& items)
+{
+    if (m_activeContextMenu)
+        m_activeContextMenu->hideContextMenu();
+    else
+        m_activeContextMenu = m_pageClient->createContextMenuProxy(this);
+      
+    m_activeContextMenu->showContextMenu(menuLocation, items);
+}
+
+void WebPageProxy::contextMenuItemSelected(const WebContextMenuItem& item)
+{
+    process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
+}
+
 void WebPageProxy::registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy, UndoOrRedo undoOrRedo)
 {
     m_pageClient->registerEditCommand(commandProxy, undoOrRedo);
index 77b0dca..03a1bbb 100644 (file)
@@ -32,6 +32,7 @@
 #include "GenericCallback.h"
 #include "SharedMemory.h"
 #include "WKBase.h"
+#include "WebContextMenuItem.h"
 #include "WebEvent.h"
 #include "WebFindClient.h"
 #include "WebFormClient.h"
@@ -77,6 +78,7 @@ class PlatformCertificateInfo;
 class StringPairVector;
 class WebBackForwardList;
 class WebBackForwardListItem;
+class WebContextMenuProxy;
 class WebData;
 class WebEditCommandProxy;
 class WebKeyboardEvent;
@@ -231,6 +233,8 @@ public:
 
     void getStatistics(WKContextStatistics*);
 
+    void contextMenuItemSelected(const WebContextMenuItem&);
+
 private:
     WebPageProxy(WebPageNamespace*, uint64_t pageID);
 
@@ -321,6 +325,9 @@ private:
     void showPopupMenu(const WebCore::IntRect& rect, const Vector<WebPopupItem>& items, int32_t selectedIndex);
     void hidePopupMenu();
 
+    // Context Menu.
+    void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItem>& items);
+
     void takeFocus(bool direction);
     void setToolTip(const String&);
     void setCursor(const WebCore::Cursor&);
@@ -361,6 +368,7 @@ private:
     HashSet<WebEditCommandProxy*> m_editCommandSet;
 
     RefPtr<WebPopupMenuProxy> m_activePopupMenu;
+    RefPtr<WebContextMenuProxy> m_activeContextMenu;
 
     double m_estimatedProgress;
 
index 4059b9d..b484b96 100644 (file)
@@ -118,6 +118,9 @@ messages -> WebPageProxy {
     # PopupMenu.
     ShowPopupMenu(WebCore::IntRect rect, Vector<WebKit::WebPopupItem> items, int32_t selectedIndex)
     HidePopupMenu()
+    
+    # ContextMenu
+    ShowContextMenu(WebCore::IntPoint point, Vector<WebKit::WebContextMenuItem> items)
 
 #if USE(ACCELERATED_COMPOSITING)
     # Accelerated compsiting messages.
diff --git a/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h b/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h
new file mode 100644 (file)
index 0000000..4fcff09
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebContextMenuProxyMac_h
+#define WebContextMenuProxyMac_h
+
+#include "WebContextMenuProxy.h"
+#include <wtf/RetainPtr.h>
+
+#ifdef __OBJC__
+@class NSPopUpButtonCell;
+@class WKView;
+#else
+class NSPopUpButtonCell;
+class WKView;
+#endif
+
+namespace WebKit {
+
+class WebPageProxy;
+
+class WebContextMenuProxyMac : public WebContextMenuProxy {
+public:
+    static PassRefPtr<WebContextMenuProxyMac> create(WKView* webView, WebPageProxy* page)
+    {
+        return adoptRef(new WebContextMenuProxyMac(webView, page));
+    }
+    ~WebContextMenuProxyMac();
+
+    virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItem>&);
+    virtual void hideContextMenu();
+    
+    void contextMenuItemSelected(const WebContextMenuItem&);
+
+private:
+    WebContextMenuProxyMac(WKView*, WebPageProxy*);
+
+    void populate(const Vector<WebContextMenuItem>&);
+
+    RetainPtr<NSPopUpButtonCell> m_popup;
+    WKView* m_webView;
+    WebPageProxy* m_page;
+};
+
+} // namespace WebKit
+
+#endif // WebContextMenuProxyMac_h
diff --git a/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm b/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm
new file mode 100644 (file)
index 0000000..c0eac65
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "WebContextMenuProxyMac.h"
+
+#include "PageClientImpl.h"
+#include "WebContextMenuItem.h"
+#include "WKView.h"
+
+#include <WebCore/IntRect.h>
+#include <WebKitSystemInterface.h>
+
+using namespace WebCore;
+
+@interface WebMenuTarget : NSObject {
+    WebKit::WebContextMenuProxyMac* _menuProxy;
+}
++ (WebMenuTarget*)sharedMenuTarget;
+- (WebKit::WebContextMenuProxyMac*)menuProxy;
+- (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy;
+- (void)forwardContextMenuAction:(id)sender;
+@end
+
+@implementation WebMenuTarget
+
++ (WebMenuTarget*)sharedMenuTarget
+{
+    static WebMenuTarget* target = [[WebMenuTarget alloc] init];
+    return target;
+}
+
+- (WebKit::WebContextMenuProxyMac*)menuProxy
+{
+    return _menuProxy;
+}
+
+- (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy
+{
+    _menuProxy = menuProxy;
+}
+
+- (void)forwardContextMenuAction:(id)sender
+{
+    WebKit::WebContextMenuItem item(ActionType, static_cast<ContextMenuAction>([sender tag]), [sender title], [sender isEnabled], [sender state] == NSOnState);
+    _menuProxy->contextMenuItemSelected(item);
+}
+
+@end
+
+namespace WebKit {
+
+WebContextMenuProxyMac::WebContextMenuProxyMac(WKView* webView, WebPageProxy* page)
+    : m_webView(webView)
+    , m_page(page)
+{
+}
+
+WebContextMenuProxyMac::~WebContextMenuProxyMac()
+{
+    if (m_popup)
+        [m_popup.get() setControlView:nil];
+}
+
+void WebContextMenuProxyMac::contextMenuItemSelected(const WebContextMenuItem& item)
+{
+    m_page->contextMenuItemSelected(item);
+}
+
+static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem> >& menuItemVector)
+{
+    for (unsigned i = 0; i < menuItemVector.size(); ++i) {
+        NSInteger oldState = [menuItemVector[i].get() state];
+        [menu addItem:menuItemVector[i].get()];
+        [menuItemVector[i].get() setState:oldState];
+    }
+}
+
+static Vector<RetainPtr<NSMenuItem> > nsMenuItemVector(const Vector<WebContextMenuItem>& items)
+{
+    Vector<RetainPtr<NSMenuItem> > result;
+
+    unsigned size = items.size();
+    result.reserveCapacity(size);
+    for (unsigned i = 0; i < size; i++) {
+        switch (items[i].type()) {
+        case ActionType:
+        case CheckableActionType: {
+            NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:nsStringFromWebCoreString(items[i].title()) action:@selector(forwardContextMenuAction:) keyEquivalent:@""];
+            [menuItem setTag:items[i].action()];
+            [menuItem setEnabled:items[i].enabled()];
+            [menuItem setState:items[i].checked() ? NSOnState : NSOffState];
+                        
+            result.append(RetainPtr<NSMenuItem>(AdoptNS, menuItem));
+            break;
+        }
+        case SeparatorType:
+            result.append([NSMenuItem separatorItem]);
+            break;
+        case SubmenuType: {
+            NSMenu* menu = [[NSMenu alloc] initWithTitle:nsStringFromWebCoreString(items[i].title())];
+            [menu setAutoenablesItems:NO];
+            populateNSMenu(menu, nsMenuItemVector(items[i].submenu()));
+                
+            NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:nsStringFromWebCoreString(items[i].title()) action:@selector(forwardContextMenuAction:) keyEquivalent:@""];
+            [menuItem setEnabled:items[i].enabled()];
+            [menuItem setSubmenu:menu];
+            [menu release];
+
+            result.append(RetainPtr<NSMenuItem>(AdoptNS, menuItem));
+            
+            break;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+        }
+    }
+
+    WebMenuTarget* target = [WebMenuTarget sharedMenuTarget];
+    for (unsigned i = 0; i < size; ++i)
+        [result[i].get() setTarget:target];
+    
+    return result;
+}
+
+void WebContextMenuProxyMac::populate(const Vector<WebContextMenuItem>& items)
+{
+    if (m_popup)
+        [m_popup.get() removeAllItems];
+    else {
+        m_popup.adoptNS([[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]);
+        [m_popup.get() setUsesItemFromMenu:NO];
+        [m_popup.get() setAutoenablesItems:NO];
+    }
+
+    NSMenu* menu = [m_popup.get() menu];
+    populateNSMenu(menu, nsMenuItemVector(items));
+}
+
+void WebContextMenuProxyMac::showContextMenu(const IntPoint& menuLocation, const Vector<WebContextMenuItem>& items)
+{
+    populate(items);
+    [[WebMenuTarget sharedMenuTarget] setMenuProxy:this];
+    
+    NSRect menuRect = NSMakeRect(menuLocation.x(), menuLocation.y(), 0, 0);
+    
+    [m_popup.get() attachPopUpWithFrame:menuRect inView:m_webView];
+
+    NSMenu* menu = [m_popup.get() menu];
+
+    // These values were borrowed from AppKit to match their placement of the menu.
+    NSRect titleFrame = [m_popup.get()  titleRectForBounds:menuRect];
+    if (titleFrame.size.width <= 0 || titleFrame.size.height <= 0)
+        titleFrame = menuRect;
+    float vertOffset = roundf((NSMaxY(menuRect) - NSMaxY(titleFrame)) + NSHeight(titleFrame));
+    NSPoint location = NSMakePoint(NSMinX(menuRect), NSMaxY(menuRect) - vertOffset);
+
+    RetainPtr<NSView> dummyView(AdoptNS, [[NSView alloc] initWithFrame:menuRect]);
+    [m_webView addSubview:dummyView.get()];
+    location = [dummyView.get() convertPoint:location fromView:m_webView];
+
+    WKPopupMenu(menu, location, roundf(NSWidth(menuRect)), dummyView.get(), -1, nil);
+
+    [m_popup.get() dismissPopUp];
+    [dummyView.get() removeFromSuperview];
+}
+
+void WebContextMenuProxyMac::hideContextMenu()
+{
+    [m_popup.get() dismissPopUp];
+}
+
+} // namespace WebKit
index dfee2aa..f13cccc 100644 (file)
@@ -625,6 +625,12 @@ PassRefPtr<WebPopupMenuProxy> WebView::createPopupMenuProxy()
     return WebPopupMenuProxyWin::create();
 }
 
+PassRefPtr<WebContextMenuProxy> WebView::createContextMenuProxy(WebPageProxy*)
+{
+    // FIXME: Implement.
+    return 0;
+}
+
 void WebView::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut)
 {
     // FIXME: Implement.
index 054c650..b0860df 100644 (file)
@@ -105,6 +105,7 @@ private:
     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
     virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
     virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy();
+    virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
     virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut);
 
 #if USE(ACCELERATED_COMPOSITING)
index 9001eb3..0725811 100644 (file)
@@ -214,6 +214,7 @@ HEADERS += \
     Shared/UserMessageCoders.h \
     Shared/VisitedLinkTable.h \
     Shared/WebCertificateInfo.h \
+    Shared/WebContextMenuItem.h \
     Shared/WebEvent.h \
     Shared/WebError.h \
     Shared/WebEventConversion.h \
@@ -264,6 +265,7 @@ HEADERS += \
     UIProcess/VisitedLinkProvider.h \
     UIProcess/WebContext.h \
     UIProcess/WebContextInjectedBundleClient.h \
+    UIProcess/WebContextMenuProxy.h \
     UIProcess/WebContextUserMessageCoders.h \
     UIProcess/WebEditCommandProxy.h \
     UIProcess/WebFindClient.h \
@@ -329,6 +331,7 @@ HEADERS += \
     WebProcess/WebPage/FindController.h \
     WebProcess/WebPage/FindPageOverlay.h \
     WebProcess/WebPage/PageOverlay.h \
+    WebProcess/WebPage/WebContextMenu.h \
     WebProcess/WebPage/WebEditCommand.h \
     WebProcess/WebPage/WebFrame.h \
     WebProcess/WebPage/WebInspector.h \
@@ -376,6 +379,7 @@ SOURCES += \
     Shared/qt/WebURLRequestQt.cpp \
     Shared/qt/WebURLResponseQt.cpp \
     Shared/VisitedLinkTable.cpp \
+    Shared/WebContextMenuItem.cpp \
     Shared/WebError.cpp \
     Shared/WebEvent.cpp \
     Shared/WebEventConversion.cpp \
@@ -421,6 +425,7 @@ SOURCES += \
     UIProcess/WebBackForwardList.cpp \
     UIProcess/WebBackForwardListItem.cpp \
     UIProcess/WebContext.cpp \
+    UIProcess/WebContextMenuProxy.cpp \
     UIProcess/WebContextInjectedBundleClient.cpp \
     UIProcess/WebEditCommandProxy.cpp \
     UIProcess/WebFindClient.cpp \
@@ -492,6 +497,7 @@ SOURCES += \
     WebProcess/WebPage/FindController.cpp \
     WebProcess/WebPage/FindPageOverlay.cpp \
     WebProcess/WebPage/PageOverlay.cpp \
+    WebProcess/WebPage/WebContextMenu.cpp \
     WebProcess/WebPage/WebEditCommand.cpp \
     WebProcess/WebPage/WebFrame.cpp \
     WebProcess/WebPage/WebInspector.cpp \
index 630afe6..7c5a495 100644 (file)
                1C8E293A12761E5B00BC7BD0 /* WKInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C8E293812761E5B00BC7BD0 /* WKInspector.cpp */; };
                51578B831209ECEF00A37C4A /* WebData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51578B821209ECEF00A37C4A /* WebData.h */; };
                516A4A5D120A2CCD00C05B7F /* WebError.h in Headers */ = {isa = PBXBuildFile; fileRef = 516A4A5B120A2CCD00C05B7F /* WebError.h */; };
+               51871B5B127CB89D00F76232 /* WebContextMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51871B59127CB89D00F76232 /* WebContextMenu.cpp */; };
+               51871B5C127CB89D00F76232 /* WebContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 51871B5A127CB89D00F76232 /* WebContextMenu.h */; };
                51A7F2F3125BF820008AEB1D /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A7F2F2125BF820008AEB1D /* Logging.h */; };
                51A7F2F5125BF8D4008AEB1D /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A7F2F4125BF8D4008AEB1D /* Logging.cpp */; };
+               51A84CE3127F386B00CA6EA4 /* WebContextMenuProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A84CE2127F386B00CA6EA4 /* WebContextMenuProxy.cpp */; };
+               51ACBA151279E8C300D203B9 /* WebContextMenuItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ACBA131279E8C300D203B9 /* WebContextMenuItem.cpp */; };
+               51ACBA161279E8C300D203B9 /* WebContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACBA141279E8C300D203B9 /* WebContextMenuItem.h */; };
+               51ACBB82127A8BAD00D203B9 /* WebContextMenuProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACBB81127A8BAD00D203B9 /* WebContextMenuProxy.h */; };
+               51ACBBA0127A8F2C00D203B9 /* WebContextMenuProxyMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACBB9E127A8F2C00D203B9 /* WebContextMenuProxyMac.h */; };
+               51ACBBA1127A8F2C00D203B9 /* WebContextMenuProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */; };
                51B3005012529D0E000B5CA0 /* WebBackForwardListCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B3004E12529D0E000B5CA0 /* WebBackForwardListCF.cpp */; };
                51B3005112529D0E000B5CA0 /* WebPageProxyCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B3004F12529D0E000B5CA0 /* WebPageProxyCF.cpp */; };
                6D8A91A611F0EFD100DD01FE /* com.apple.WebProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = 6D8A91A511F0EFD100DD01FE /* com.apple.WebProcess.sb */; };
                32DBCF5E0370ADEE00C91783 /* WebKit2Prefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKit2Prefix.h; sourceTree = "<group>"; };
                51578B821209ECEF00A37C4A /* WebData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebData.h; sourceTree = "<group>"; };
                516A4A5B120A2CCD00C05B7F /* WebError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebError.h; sourceTree = "<group>"; };
+               51871B59127CB89D00F76232 /* WebContextMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenu.cpp; sourceTree = "<group>"; };
+               51871B5A127CB89D00F76232 /* WebContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenu.h; sourceTree = "<group>"; };
                51A7F2F2125BF820008AEB1D /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logging.h; sourceTree = "<group>"; };
                51A7F2F4125BF8D4008AEB1D /* Logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Logging.cpp; sourceTree = "<group>"; };
+               51A84CE2127F386B00CA6EA4 /* WebContextMenuProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenuProxy.cpp; sourceTree = "<group>"; };
+               51ACBA131279E8C300D203B9 /* WebContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenuItem.cpp; sourceTree = "<group>"; };
+               51ACBA141279E8C300D203B9 /* WebContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuItem.h; sourceTree = "<group>"; };
+               51ACBB81127A8BAD00D203B9 /* WebContextMenuProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuProxy.h; sourceTree = "<group>"; };
+               51ACBB9E127A8F2C00D203B9 /* WebContextMenuProxyMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuProxyMac.h; sourceTree = "<group>"; };
+               51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContextMenuProxyMac.mm; sourceTree = "<group>"; };
                51B3004E12529D0E000B5CA0 /* WebBackForwardListCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebBackForwardListCF.cpp; path = cf/WebBackForwardListCF.cpp; sourceTree = "<group>"; };
                51B3004F12529D0E000B5CA0 /* WebPageProxyCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebPageProxyCF.cpp; path = cf/WebPageProxyCF.cpp; sourceTree = "<group>"; };
                5DAD7294116FF70B00EE5396 /* WebProcess.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebProcess.xcconfig; sourceTree = "<group>"; };
                                BCB0AEE7122F53E300B1341E /* MutableDictionary.h */,
                                C02BFF1512514FD8009CCBEA /* NativeWebKeyboardEvent.h */,
                                BCC57161115ADB42001CCAF9 /* NotImplemented.h */,
+                               BCBD3C3A125BFA7A00D2C29F /* StringPairVector.h */,
                                BCB0B0DF12305AB100B1341E /* UserMessageCoders.h */,
                                1A0F29C9120B37160053D1B9 /* VisitedLinkTable.cpp */,
                                1A0F29CA120B37160053D1B9 /* VisitedLinkTable.h */,
                                BC1DD7B1114DC396005ADAF3 /* WebCoreArgumentCoders.h */,
                                BCF50726124329AA005955AE /* WebCertificateInfo.h */,
-                               BCBD3C3A125BFA7A00D2C29F /* StringPairVector.h */,
+                               51ACBA131279E8C300D203B9 /* WebContextMenuItem.cpp */,
+                               51ACBA141279E8C300D203B9 /* WebContextMenuItem.h */,
                                51578B821209ECEF00A37C4A /* WebData.h */,
                                BC575612126E0138006F0F12 /* WebError.cpp */,
                                516A4A5B120A2CCD00C05B7F /* WebError.h */,
                BC032D5E10F4372B0058C15A /* WebPage */ = {
                        isa = PBXGroup;
                        children = (
+                               51871B59127CB89D00F76232 /* WebContextMenu.cpp */,
+                               51871B5A127CB89D00F76232 /* WebContextMenu.h */,
                                BC963D6C113DD19500574BE2 /* mac */,
                                BC5F7BB21182376C0052C02C /* ChunkedUpdateDrawingArea.cpp */,
                                BC5F7BB31182376C0052C02C /* ChunkedUpdateDrawingArea.h */,
                                BC646BF611DD377B006455B0 /* WebBackForwardListItem.h */,
                                BCB9E2421120DACA00A137E0 /* WebContext.cpp */,
                                BCB9E2411120DACA00A137E0 /* WebContext.h */,
+                               51A84CE2127F386B00CA6EA4 /* WebContextMenuProxy.cpp */,
+                               51ACBB81127A8BAD00D203B9 /* WebContextMenuProxy.h */,
                                BCDE059A11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp */,
                                BCDE059911CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h */,
                                BCB0B0DB12305A2500B1341E /* WebContextUserMessageCoders.h */,
                                BC2651F511825EF800243E12 /* ChunkedUpdateDrawingAreaProxyMac.mm */,
                                0F5265BB11DD37860006D33C /* LayerBackedDrawingAreaProxyMac.mm */,
                                1A1C648611F415B700553C19 /* WebContextMac.mm */,
+                               51ACBB9E127A8F2C00D203B9 /* WebContextMenuProxyMac.h */,
+                               51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */,
                                BC5750951268F3C6006F0F12 /* WebPopupMenuProxyMac.h */,
                                BC5750961268F3C6006F0F12 /* WebPopupMenuProxyMac.mm */,
                        );
                                935EEBA4127761D6003322B8 /* InjectedBundleBackForwardListItem.h in Headers */,
                                1A616150127798B5003ACD86 /* DownloadManager.h in Headers */,
                                1A6161D41278981C003ACD86 /* Download.h in Headers */,
+                               51ACBA161279E8C300D203B9 /* WebContextMenuItem.h in Headers */,
+                               51ACBB82127A8BAD00D203B9 /* WebContextMenuProxy.h in Headers */,
+                               51ACBBA0127A8F2C00D203B9 /* WebContextMenuProxyMac.h in Headers */,
                                1A119A95127B796200A9ECB1 /* MessageSender.h in Headers */,
+                               51871B5C127CB89D00F76232 /* WebContextMenu.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                1A61614F127798B5003ACD86 /* DownloadManager.cpp in Sources */,
                                1A6161D51278981C003ACD86 /* Download.cpp in Sources */,
                                1A61639612789B2F003ACD86 /* DownloadMac.mm in Sources */,
+                               51ACBA151279E8C300D203B9 /* WebContextMenuItem.cpp in Sources */,
+                               51ACBBA1127A8F2C00D203B9 /* WebContextMenuProxyMac.mm in Sources */,
                                C0337DAE127A24FE008FF4F4 /* WebEvent.cpp in Sources */,
                                C0337DB0127A28D0008FF4F4 /* WebMouseEvent.cpp in Sources */,
                                C0337DD1127A2980008FF4F4 /* WebWheelEvent.cpp in Sources */,
                                C0337DD3127A2A0E008FF4F4 /* WebKeyboardEvent.cpp in Sources */,
                                C0337DD8127A51B6008FF4F4 /* WebTouchEvent.cpp in Sources */,
                                C0337DDD127A521C008FF4F4 /* WebPlatformTouchPoint.cpp in Sources */,
+                               51871B5B127CB89D00F76232 /* WebContextMenu.cpp in Sources */,
+                               51A84CE3127F386B00CA6EA4 /* WebContextMenuProxy.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 59a95e7..034bb90 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "DrawingArea.h"
 #include "InjectedBundleUserMessageCoders.h"
+#include "WebContextMenu.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebFrame.h"
 #include "WebFrameLoaderClient.h"
@@ -525,6 +526,13 @@ PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebC
     return WebSearchPopupMenu::create(m_page, client);
 }
 
+#if ENABLE(CONTEXT_MENUS)
+void WebChromeClient::showContextMenu()
+{
+    m_page->contextMenu()->show();
+}
+#endif
+
 PassOwnPtr<HTMLParserQuirks> WebChromeClient::createHTMLParserQuirks()
 {
     notImplemented();
index be8a7ab..e82581e 100644 (file)
@@ -170,6 +170,10 @@ private:
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
+#if ENABLE(CONTEXT_MENUS)
+    virtual void showContextMenu();
+#endif
+
 #if USE(ACCELERATED_COMPOSITING)
     virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*);
     virtual void setNeedsOneShotDrawingSynchronization();
index e93fa96..4e9f430 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "WebContextMenuClient.h"
 
+#include <WebCore/ContextMenu.h>
+
 #define DISABLE_NOT_IMPLEMENTED_WARNINGS 1
 #include "NotImplemented.h"
 
@@ -37,10 +39,13 @@ void WebContextMenuClient::contextMenuDestroyed()
     delete this;
 }
 
-PlatformMenuDescription WebContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu*)
+PlatformMenuDescription WebContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu* menu)
 {
-    notImplemented();
-    return 0;
+    // FIXME:  The embedded app needs a chance to customize the context menu, and that will probably happen
+    // via an injected bundle. <rdar://problem/8613727> and https://bugs.webkit.org/show_bug.cgi?id=48720 cover this task.
+
+    ASSERT(menu);
+    return menu->platformDescription();
 }
 
 void WebContextMenuClient::contextMenuItemSelected(ContextMenuItem*, const ContextMenu*)
diff --git a/WebKit2/WebProcess/WebPage/WebContextMenu.cpp b/WebKit2/WebProcess/WebPage/WebContextMenu.cpp
new file mode 100644 (file)
index 0000000..60d0341
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "WebContextMenu.h"
+
+#include "WebCoreArgumentCoders.h"
+#include "WebPage.h"
+#include "WebPageProxyMessages.h"
+#include "WebProcess.h"
+#include <WebCore/ContextMenu.h>
+#include <WebCore/ContextMenuController.h>
+#include <WebCore/Page.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebContextMenu::WebContextMenu(WebPage* page)
+    : m_page(page)
+{
+}
+
+WebContextMenu::~WebContextMenu()
+{
+}
+
+void WebContextMenu::show()
+{
+    WebCore::ContextMenu* menu = m_page->corePage()->contextMenuController()->contextMenu();
+    if (!menu)
+        return;
+    
+    Vector<WebCore::ContextMenuItem> coreItems = WebCore::contextMenuItemVector(menu->platformDescription());
+        
+    WebProcess::shared().connection()->send(Messages::WebPageProxy::ShowContextMenu(menu->hitTestResult().point(), kitItems(coreItems, menu)), m_page->pageID());
+}
+
+void WebContextMenu::itemSelected(const WebContextMenuItem& item)
+{
+    WebCore::ContextMenuItem coreItem(WebCore::ActionType, static_cast<WebCore::ContextMenuAction>(item.action()), item.title());
+    m_page->corePage()->contextMenuController()->contextMenuItemSelected(&coreItem);
+}
+
+} // namespace WebKit
diff --git a/WebKit2/WebProcess/WebPage/WebContextMenu.h b/WebKit2/WebProcess/WebPage/WebContextMenu.h
new file mode 100644 (file)
index 0000000..380b5e2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef WebContextMenu_h
+#define WebContextMenu_h
+
+#include "WebContextMenuItem.h"
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebKit {
+
+class WebPage;
+
+class WebContextMenu : public RefCounted<WebContextMenu> {
+public:
+    static PassRefPtr<WebContextMenu> create(WebPage* page) 
+    {
+        return adoptRef(new WebContextMenu(page));
+    }
+    
+    ~WebContextMenu();
+
+    void show();
+    void itemSelected(const WebContextMenuItem&);
+
+private:
+    WebContextMenu(WebPage*);
+    
+    WebPage* m_page;
+};
+
+} // namespace WebKit
+
+#endif // WebPopupMenu_h
index b11149d..d77dac2 100644 (file)
@@ -38,6 +38,7 @@
 #include "PluginView.h"
 #include "WebBackForwardListProxy.h"
 #include "WebChromeClient.h"
+#include "WebContextMenu.h"
 #include "WebContextMenuClient.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebDragClient.h"
@@ -53,6 +54,8 @@
 #include "WebPreferencesStore.h"
 #include "WebProcess.h"
 #include "WebProcessProxyMessageKinds.h"
+#include <WebCore/Chrome.h>
+#include <WebCore/ContextMenuController.h>
 #include <WebCore/EventHandler.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
@@ -480,6 +483,13 @@ void WebPage::pageDidScroll()
     send(Messages::WebPageProxy::PageDidScroll());
 }
 
+WebContextMenu* WebPage::contextMenu()
+{
+    if (!m_contextMenu)
+        m_contextMenu = WebContextMenu::create(this);
+    return m_contextMenu.get();
+}
+
 // Events 
 
 static const WebEvent* g_currentEvent = 0;
@@ -519,7 +529,20 @@ static bool handleMouseEvent(const WebMouseEvent& mouseEvent, Page* page)
 
     switch (platformMouseEvent.eventType()) {
         case WebCore::MouseEventPressed:
-            return frame->eventHandler()->handleMousePressEvent(platformMouseEvent);
+        {
+            if (platformMouseEvent.button() == WebCore::RightButton)
+                page->contextMenuController()->clearContextMenu();
+            
+            bool handled = frame->eventHandler()->handleMousePressEvent(platformMouseEvent);
+            
+            if (platformMouseEvent.button() == WebCore::RightButton) {
+                handled = frame->eventHandler()->sendContextMenuEvent(platformMouseEvent);
+                if (handled)
+                    page->chrome()->showContextMenu();
+            }
+
+            return handled;
+        }
         case WebCore::MouseEventReleased:
             return frame->eventHandler()->handleMouseReleaseEvent(platformMouseEvent);
         case WebCore::MouseEventMoved:
@@ -883,6 +906,13 @@ void WebPage::didChangeSelectedIndexForActivePopupMenu(int32_t newIndex)
     m_activePopupMenu = 0;
 }
 
+void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItem& item)
+{
+    ASSERT(m_contextMenu);
+    m_contextMenu->itemSelected(item);
+    m_contextMenu = 0;
+}
+
 #if PLATFORM(MAC)
 void WebPage::addPluginView(PluginView* pluginView)
 {
index 8c0c58e..0c881c3 100644 (file)
@@ -68,6 +68,8 @@ class DrawingArea;
 class InjectedBundleBackForwardList;
 class PageOverlay;
 class PluginView;
+class WebContextMenu;
+class WebContextMenuItem;
 class WebEvent;
 class WebFrame;
 class WebInspector;
@@ -186,6 +188,8 @@ public:
     FindController& findController() { return m_findController; }
 
     void pageDidScroll();
+    
+    WebContextMenu* contextMenu();
 
 private:
     WebPage(uint64_t pageID, const WebPageCreationParameters&);
@@ -252,6 +256,10 @@ private:
 
     void didChangeSelectedIndexForActivePopupMenu(int32_t newIndex);
 
+#if ENABLE(CONTEXT_MENUS)
+    void didSelectItemFromActiveContextMenu(const WebContextMenuItem&);
+#endif
+
     OwnPtr<WebCore::Page> m_page;
     RefPtr<WebFrame> m_mainFrame;
     RefPtr<InjectedBundleBackForwardList> m_backForwardList;
@@ -294,6 +302,8 @@ private:
 
     RefPtr<WebPopupMenu> m_activePopupMenu;
 
+    RefPtr<WebContextMenu> m_contextMenu;
+
     uint64_t m_pageID;
 };
 
index f076371..5a62913 100644 (file)
@@ -78,6 +78,9 @@ messages -> WebPage {
 
     # Popup menu.
     DidChangeSelectedIndexForActivePopupMenu(int32_t newIndex);
+    
+    # Context menu.
+    DidSelectItemFromActiveContextMenu(WebKit::WebContextMenuItem menuItem);
 
     SetWindowResizerSize(WebCore::IntSize intersectsView)
 
index cce7e06..ccd3e95 100755 (executable)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\Shared\WebContextMenuItem.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\Shared\WebContextMenuItem.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="..\Shared\WebCoreArgumentCoders.h"\r
                                >\r
                        </File>\r
                                        >\r
                                </File>\r
                                <File\r
+                                       RelativePath="..\WebProcess\WebPage\WebContextMenu.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath="..\WebProcess\WebPage\WebContextMenu.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
                                        RelativePath="..\WebProcess\WebPage\WebEditCommand.cpp"\r
                                        >\r
                                </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\UIProcess\WebContextMenuProxy.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\UIProcess\WebContextMenuProxy.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="..\UIProcess\WebContextUserMessageCoders.h"\r
                                >\r
                        </File>\r