Title: [191413] trunk/Source/WebKit/win
Revision
191413
Author
ander...@apple.com
Date
2015-10-21 16:54:32 -0700 (Wed, 21 Oct 2015)

Log Message

Simplify context menu handling on Windows
https://bugs.webkit.org/show_bug.cgi?id=150423

Reviewed by Tim Horton.

Instead of converting a ContextMenu to a HMENU, then back to a ContextMenu, and then back to a HMENU again
just convert it once right before showing it and let the UIDelegate return a new menu at at time where we don't
have to convert it back.

* WebCoreSupport/WebContextMenuClient.cpp:
(WebContextMenuClient::customizeMenu):
* WebView.cpp:
(WebView::createContextMenu):
(WebView::handleContextMenuEvent):
* WebView.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/win/ChangeLog (191412 => 191413)


--- trunk/Source/WebKit/win/ChangeLog	2015-10-21 23:14:31 UTC (rev 191412)
+++ trunk/Source/WebKit/win/ChangeLog	2015-10-21 23:54:32 UTC (rev 191413)
@@ -1,3 +1,21 @@
+2015-10-21  Anders Carlsson  <ander...@apple.com>
+
+        Simplify context menu handling on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=150423
+
+        Reviewed by Tim Horton.
+
+        Instead of converting a ContextMenu to a HMENU, then back to a ContextMenu, and then back to a HMENU again
+        just convert it once right before showing it and let the UIDelegate return a new menu at at time where we don't
+        have to convert it back.
+
+        * WebCoreSupport/WebContextMenuClient.cpp:
+        (WebContextMenuClient::customizeMenu):
+        * WebView.cpp:
+        (WebView::createContextMenu):
+        (WebView::handleContextMenuEvent):
+        * WebView.h:
+
 2015-10-21  Carlos Garcia Campos  <cgar...@igalia.com>
 
         NetworkProcess: DNS prefetch happens in the Web Process

Modified: trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp (191412 => 191413)


--- trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp	2015-10-21 23:14:31 UTC (rev 191412)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp	2015-10-21 23:54:32 UTC (rev 191413)
@@ -52,29 +52,9 @@
     delete this;
 }
 
-std::unique_ptr<ContextMenu> WebContextMenuClient::customizeMenu(std::unique_ptr<ContextMenu> popMenu)
+std::unique_ptr<ContextMenu> WebContextMenuClient::customizeMenu(std::unique_ptr<ContextMenu> menu)
 {
-    std::unique_ptr<ContextMenu> menu = WTF::move(popMenu);
-
-    COMPtr<IWebUIDelegate> uiDelegate;
-    if (FAILED(m_webView->uiDelegate(&uiDelegate)))
-        return menu;
-
-    ASSERT(uiDelegate);
-
-    HMENU nativeMenu = menu->platformContextMenu();
-    COMPtr<WebElementPropertyBag> propertyBag;
-    propertyBag.adoptRef(WebElementPropertyBag::createInstance(m_webView->page()->contextMenuController().hitTestResult()));
-    // FIXME: We need to decide whether to do the default before calling this delegate method
-    if (FAILED(uiDelegate->contextMenuItemsForElement(m_webView, propertyBag.get(), nativeMenu, &nativeMenu))) {
-        ::DestroyMenu(nativeMenu);
-        return menu;
-    }
-    
-    std::unique_ptr<ContextMenu> customizedMenu = std::unique_ptr<ContextMenu>(new ContextMenu(nativeMenu));
-    ::DestroyMenu(nativeMenu);
-
-    return customizedMenu;
+    return WTF::move(menu);
 }
 
 void WebContextMenuClient::contextMenuItemSelected(ContextMenuItem* item, const ContextMenu* parentMenu)

Modified: trunk/Source/WebKit/win/WebView.cpp (191412 => 191413)


--- trunk/Source/WebKit/win/WebView.cpp	2015-10-21 23:14:31 UTC (rev 191412)
+++ trunk/Source/WebKit/win/WebView.cpp	2015-10-21 23:54:32 UTC (rev 191413)
@@ -1393,6 +1393,36 @@
     return m_page;
 }
 
+HMENU WebView::createContextMenu()
+{
+    auto& contextMenuController = m_page->contextMenuController();
+
+    ContextMenu* coreMenu = contextMenuController.contextMenu();
+    if (!coreMenu)
+        return nullptr;
+
+    HMENU contextMenu = coreMenu->platformContextMenu();
+
+    COMPtr<IWebUIDelegate> uiDelegate;
+    if (SUCCEEDED(this->uiDelegate(&uiDelegate))) {
+        ASSERT(uiDelegate);
+
+        COMPtr<WebElementPropertyBag> propertyBag;
+        propertyBag.adoptRef(WebElementPropertyBag::createInstance(contextMenuController.hitTestResult()));
+
+        HMENU newMenu = nullptr;
+        if (SUCCEEDED(uiDelegate->contextMenuItemsForElement(this, propertyBag.get(), contextMenu, &newMenu))) {
+            // Make sure to delete the old menu if the delegate returned a new menu.
+            if (newMenu != contextMenu) {
+                ::DestroyMenu(contextMenu);
+                contextMenu = newMenu;
+            }
+        }
+    }
+
+    return contextMenu;
+}
+
 bool WebView::handleContextMenuEvent(WPARAM wParam, LPARAM lParam)
 {
     // Translate the screen coordinates into window coordinates
@@ -1456,19 +1486,23 @@
     if (!::ClientToScreen(m_viewWindow, &point))
         return false;
 
+    HMENU contextMenu = createContextMenu();
+
     BOOL hasCustomMenus = false;
     if (m_uiDelegate)
         m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
 
     if (hasCustomMenus)
-        m_uiDelegate->trackCustomPopupMenu((IWebView*)this, coreMenu->platformContextMenu(), &point);
+        m_uiDelegate->trackCustomPopupMenu((IWebView*)this, contextMenu, &point);
     else {
         // Surprisingly, TPM_RIGHTBUTTON means that items are selectable with either the right OR left mouse button
         UINT flags = TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERPOSANIMATION | TPM_HORIZONTAL
             | TPM_LEFTALIGN | TPM_HORPOSANIMATION;
-        ::TrackPopupMenuEx(coreMenu->platformContextMenu(), flags, point.x, point.y, m_viewWindow, 0);
+        ::TrackPopupMenuEx(contextMenu, flags, point.x, point.y, m_viewWindow, 0);
     }
 
+    ::DestroyMenu(contextMenu);
+
     return true;
 }
 

Modified: trunk/Source/WebKit/win/WebView.h (191412 => 191413)


--- trunk/Source/WebKit/win/WebView.h	2015-10-21 23:14:31 UTC (rev 191412)
+++ trunk/Source/WebKit/win/WebView.h	2015-10-21 23:54:32 UTC (rev 191413)
@@ -400,6 +400,7 @@
     bool handleMouseEvent(UINT, WPARAM, LPARAM);
     void setMouseActivated(bool flag) { m_mouseActivated = flag; }
     bool handleContextMenuEvent(WPARAM, LPARAM);
+    HMENU createContextMenu();
     bool onMeasureItem(WPARAM, LPARAM);
     bool onDrawItem(WPARAM, LPARAM);
     bool onInitMenuPopup(WPARAM, LPARAM);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to