[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da

bweinstein at apple.com bweinstein at apple.com
Wed Dec 22 18:26:47 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 01fc7a4db89bc59af7cfc673e7df78d9ab27b363
Author: bweinstein at apple.com <bweinstein at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Dec 10 23:43:44 2010 +0000

    WebKit2: Context menu support on Windows
    <https://bugs.webkit.org/show_bug.cgi?id=50514>
    
    Reviewed by Darin Adler.
    
    Implment showing of the context menu on Windows for WebKit2, and calling through to
    WebPageProxy::contextMenuItemSelected.
    
    * UIProcess/win/WebContextMenuProxyWin.cpp:
    (WebKit::WebContextMenuProxyWin::WebContextMenuProxyWin): Initialize the member variables.
    (WebKit::WebContextMenuProxyWin::populateMenu): Iterate over the vector of WebContextMenuItemData
        that was passed in, adding the menu items and recursively calling back into this function to populate
        any submenus that are needed. This function also sets up the map from action identifierss to WebContextMenuItemData,
        to use to find the WebContextMenuItemData from a selected menu item.
    (WebKit::WebContextMenuProxyWin::showContextMenu): Destroy any menu we have already created, populate the menu
        to show, and show the context menu. Once TrackPopupMenuEx returns, it returns identifier of the selected menu item.
        Look up that identifier in the map we created, and tell the WebPageProxy that a context menu item was selected.
    (WebKit::WebContextMenuProxyWin::hideContextMenu): Destroy the HMENU if it is non-null, and clear the identifier map.
    * UIProcess/win/WebContextMenuProxyWin.h:
    (WebKit::WebContextMenuProxyWin::create): Call through to the constructor, and change the arguments that it takes.
    * UIProcess/win/WebView.cpp:
    (WebKit::WebView::createContextMenuProxy): Call with the correct arguments.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73815 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 99fd924..2453001 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,28 @@
+2010-12-10  Brian Weinstein  <bweinstein at apple.com>
+
+        Reviewed by Darin Adler.
+
+        WebKit2: Context menu support on Windows
+        <https://bugs.webkit.org/show_bug.cgi?id=50514>
+        
+        Implment showing of the context menu on Windows for WebKit2, and calling through to
+        WebPageProxy::contextMenuItemSelected.
+
+        * UIProcess/win/WebContextMenuProxyWin.cpp:
+        (WebKit::WebContextMenuProxyWin::WebContextMenuProxyWin): Initialize the member variables.
+        (WebKit::WebContextMenuProxyWin::populateMenu): Iterate over the vector of WebContextMenuItemData
+            that was passed in, adding the menu items and recursively calling back into this function to populate
+            any submenus that are needed. This function also sets up the map from action identifierss to WebContextMenuItemData,
+            to use to find the WebContextMenuItemData from a selected menu item.
+        (WebKit::WebContextMenuProxyWin::showContextMenu): Destroy any menu we have already created, populate the menu
+            to show, and show the context menu. Once TrackPopupMenuEx returns, it returns identifier of the selected menu item.
+            Look up that identifier in the map we created, and tell the WebPageProxy that a context menu item was selected.
+        (WebKit::WebContextMenuProxyWin::hideContextMenu): Destroy the HMENU if it is non-null, and clear the identifier map. 
+        * UIProcess/win/WebContextMenuProxyWin.h:
+        (WebKit::WebContextMenuProxyWin::create): Call through to the constructor, and change the arguments that it takes.
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::createContextMenuProxy): Call with the correct arguments.
+
 2010-12-10  Jessie Berlin  <jberlin at apple.com>
 
         Qt Build Fix. Unreviewed.
diff --git a/WebKit2/UIProcess/win/WebContextMenuProxyWin.cpp b/WebKit2/UIProcess/win/WebContextMenuProxyWin.cpp
index 4a5d22a..090598f 100644
--- a/WebKit2/UIProcess/win/WebContextMenuProxyWin.cpp
+++ b/WebKit2/UIProcess/win/WebContextMenuProxyWin.cpp
@@ -31,23 +31,73 @@ using namespace WebCore;
 
 namespace WebKit {
 
-inline WebContextMenuProxyWin::WebContextMenuProxyWin()
+WebContextMenuProxyWin::WebContextMenuProxyWin(HWND parentWindow, WebPageProxy* page)
+    : m_window(parentWindow)
+    , m_page(page)
+    , m_menu(0)
 {
 }
 
-PassRefPtr<WebContextMenuProxyWin> WebContextMenuProxyWin::create()
+void WebContextMenuProxyWin::populateMenu(HMENU menu, const Vector<WebContextMenuItemData>& items)
 {
-    return adoptRef(new WebContextMenuProxyWin);
+    for (size_t i = 0; i < items.size(); ++i) {
+        const WebContextMenuItemData& itemData = items[i];
+        switch (itemData.type()) {
+        case ActionType:
+        case CheckableActionType: {
+            UINT flags = itemData.enabled() ? MF_ENABLED : MF_DISABLED;
+            if (itemData.checked())
+                flags |= MF_CHECKED;
+            String title = itemData.title();
+            ::AppendMenu(menu, flags, itemData.action(), title.charactersWithNullTermination());
+
+            m_actionMap.add(itemData.action(), itemData);
+            break;
+        }
+        case SeparatorType:
+            ::AppendMenu(menu, MF_SEPARATOR, 0, 0);
+            break;
+        case SubmenuType: {
+            HMENU subMenu = ::CreatePopupMenu();
+            populateMenu(subMenu, itemData.submenu());
+            String title = itemData.title();
+            ::AppendMenu(menu, MF_POPUP, reinterpret_cast<UINT>(subMenu), title.charactersWithNullTermination());
+            break;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+        }
+    }
 }
 
-void WebContextMenuProxyWin::showContextMenu(const IntPoint&, const Vector<WebContextMenuItemData>&)
+void WebContextMenuProxyWin::showContextMenu(const IntPoint& origin, const Vector<WebContextMenuItemData>& items)
 {
-    notImplemented();
+    // Hide any context menu we have showing (this also destroys the menu).
+    hideContextMenu();
+
+    m_menu = ::CreatePopupMenu();
+    populateMenu(m_menu, items);
+
+    POINT point = POINT(origin);
+    if (!::ClientToScreen(m_window, &point))
+        return;
+
+    UINT flags = TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERPOSANIMATION | TPM_HORIZONTAL | TPM_LEFTALIGN | TPM_HORPOSANIMATION | TPM_RETURNCMD | TPM_NONOTIFY;
+    int selectedCommand = ::TrackPopupMenuEx(m_menu, flags, point.x, point.y, m_window, 0);
+    if (!selectedCommand)
+        return;
+
+    m_page->contextMenuItemSelected(m_actionMap.get(selectedCommand));
 }
 
 void WebContextMenuProxyWin::hideContextMenu()
 {
-    notImplemented();
+    if (m_menu) {
+        ::DestroyMenu(m_menu);
+        m_menu = 0;
+    }
+
+    m_actionMap.clear();
 }
 
 } // namespace WebKit
diff --git a/WebKit2/UIProcess/win/WebContextMenuProxyWin.h b/WebKit2/UIProcess/win/WebContextMenuProxyWin.h
index 906fef3..a843b26 100644
--- a/WebKit2/UIProcess/win/WebContextMenuProxyWin.h
+++ b/WebKit2/UIProcess/win/WebContextMenuProxyWin.h
@@ -26,19 +26,34 @@
 #ifndef WebContextMenuProxyWin_h
 #define WebContextMenuProxyWin_h
 
+#include "WebContextMenuItemData.h"
 #include "WebContextMenuProxy.h"
+#include "WebPageProxy.h"
+#include <wtf/HashMap.h>
 
 namespace WebKit {
 
 class WebContextMenuProxyWin : public WebContextMenuProxy {
 public:
-    static PassRefPtr<WebContextMenuProxyWin> create();
+    static PassRefPtr<WebContextMenuProxyWin> create(HWND parentWindow, WebPageProxy* page)
+    {
+        return adoptRef(new WebContextMenuProxyWin(parentWindow, page));
+    }
 
 private:
-    WebContextMenuProxyWin();
+    WebContextMenuProxyWin(HWND parentWindow, WebPageProxy* page);
 
     virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&);
     virtual void hideContextMenu();
+
+    void populateMenu(HMENU, const Vector<WebContextMenuItemData>&);
+
+    HMENU m_menu;
+    HWND m_window;
+    WebPageProxy* m_page;
+
+    // Creates a map from the context menu item's action to the context menu item itself.
+    HashMap<int, WebContextMenuItemData> m_actionMap;
 };
 
 } // namespace WebKit
diff --git a/WebKit2/UIProcess/win/WebView.cpp b/WebKit2/UIProcess/win/WebView.cpp
index a82709e..d434a3e 100644
--- a/WebKit2/UIProcess/win/WebView.cpp
+++ b/WebKit2/UIProcess/win/WebView.cpp
@@ -632,9 +632,9 @@ PassRefPtr<WebPopupMenuProxy> WebView::createPopupMenuProxy()
     return WebPopupMenuProxyWin::create(this);
 }
 
-PassRefPtr<WebContextMenuProxy> WebView::createContextMenuProxy(WebPageProxy*)
+PassRefPtr<WebContextMenuProxy> WebView::createContextMenuProxy(WebPageProxy* page)
 {
-    return WebContextMenuProxyWin::create();
+    return WebContextMenuProxyWin::create(m_window, page);
 }
 
 void WebView::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list