<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[192315] trunk/Source/WebKit/win</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/192315">192315</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2015-11-11 10:20:43 -0800 (Wed, 11 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use Win32 functions to get context menu item info
https://bugs.webkit.org/show_bug.cgi?id=151123
Reviewed by Tim Horton.
* WebView.cpp:
(WebView::handleContextMenuEvent):
Destroy the menu if it already exists. Before creating the menu, make sure to set its style
to MNS_NOTIFYBYPOS, so we'll be able to know which item was selected (instead of just the action ID).
(WebView::onMenuCommand):
Get the selected menu item's ID and title. Create a fake ContextMenuItem and pass it back to WebCore. In the future,
we'll be able to pass just the action and title.
(WebView::WebViewWndProc):
There's no need to listen for WM_COMMAND. Just always listen for WM_MENUCOMMAND. Rename performContextMenuAction to onMenuCommand.
* WebView.h:
Add new member.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitwinChangeLog">trunk/Source/WebKit/win/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitwinWebViewcpp">trunk/Source/WebKit/win/WebView.cpp</a></li>
<li><a href="#trunkSourceWebKitwinWebViewh">trunk/Source/WebKit/win/WebView.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitwinChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/ChangeLog (192314 => 192315)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/ChangeLog        2015-11-11 18:15:56 UTC (rev 192314)
+++ trunk/Source/WebKit/win/ChangeLog        2015-11-11 18:20:43 UTC (rev 192315)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2015-11-11 Anders Carlsson <andersca@apple.com>
+
+ Use Win32 functions to get context menu item info
+ https://bugs.webkit.org/show_bug.cgi?id=151123
+
+ Reviewed by Tim Horton.
+
+ * WebView.cpp:
+ (WebView::handleContextMenuEvent):
+ Destroy the menu if it already exists. Before creating the menu, make sure to set its style
+ to MNS_NOTIFYBYPOS, so we'll be able to know which item was selected (instead of just the action ID).
+
+ (WebView::onMenuCommand):
+ Get the selected menu item's ID and title. Create a fake ContextMenuItem and pass it back to WebCore. In the future,
+ we'll be able to pass just the action and title.
+
+ (WebView::WebViewWndProc):
+ There's no need to listen for WM_COMMAND. Just always listen for WM_MENUCOMMAND. Rename performContextMenuAction to onMenuCommand.
+
+ * WebView.h:
+ Add new member.
+
</ins><span class="cx"> 2015-11-08 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Another Windows build fix.
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebView.cpp (192314 => 192315)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebView.cpp        2015-11-11 18:15:56 UTC (rev 192314)
+++ trunk/Source/WebKit/win/WebView.cpp        2015-11-11 18:20:43 UTC (rev 192315)
</span><span class="lines">@@ -1513,23 +1513,28 @@
</span><span class="cx"> if (!::ClientToScreen(m_viewWindow, &point))
</span><span class="cx"> return false;
</span><span class="cx">
</span><del>- HMENU contextMenu = createContextMenu();
</del><ins>+ if (m_currentContextMenu)
+ ::DestroyMenu(m_currentContextMenu);
+ m_currentContextMenu = createContextMenu();
</ins><span class="cx">
</span><ins>+ MENUINFO menuInfo;
+ menuInfo.cbSize = sizeof(menuInfo);
+ menuInfo.fMask = MIM_STYLE;
+ menuInfo.dwStyle = MNS_NOTIFYBYPOS;
+ ::SetMenuInfo(m_currentContextMenu, &menuInfo);
+
</ins><span class="cx"> BOOL hasCustomMenus = false;
</span><span class="cx"> if (m_uiDelegate)
</span><span class="cx"> m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
</span><span class="cx">
</span><span class="cx"> if (hasCustomMenus)
</span><del>- m_uiDelegate->trackCustomPopupMenu((IWebView*)this, contextMenu, &point);
</del><ins>+ m_uiDelegate->trackCustomPopupMenu((IWebView*)this, m_currentContextMenu, &point);
</ins><span class="cx"> else {
</span><span class="cx"> // Surprisingly, TPM_RIGHTBUTTON means that items are selectable with either the right OR left mouse button
</span><del>- UINT flags = TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERPOSANIMATION | TPM_HORIZONTAL
- | TPM_LEFTALIGN | TPM_HORPOSANIMATION;
- ::TrackPopupMenuEx(contextMenu, flags, point.x, point.y, m_viewWindow, 0);
</del><ins>+ UINT flags = TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERPOSANIMATION | TPM_HORIZONTAL | TPM_LEFTALIGN | TPM_HORPOSANIMATION;
+ ::TrackPopupMenuEx(m_currentContextMenu, flags, point.x, point.y, m_viewWindow, 0);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- ::DestroyMenu(contextMenu);
-
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1597,15 +1602,31 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebView::performContextMenuAction(WPARAM wParam, LPARAM lParam, bool byPosition)
</del><ins>+void WebView::onMenuCommand(WPARAM wParam, LPARAM lParam)
</ins><span class="cx"> {
</span><del>- ContextMenu* menu = m_page->contextMenuController().contextMenu();
- ASSERT(menu);
</del><ins>+ HMENU hMenu = reinterpret_cast<HMENU>(lParam);
+ unsigned index = static_cast<unsigned>(wParam);
</ins><span class="cx">
</span><del>- ContextMenuItem* item = byPosition ? menu->itemAtIndex((unsigned)wParam) : menu->itemWithAction((ContextMenuAction)wParam);
- if (!item)
- return;
- m_page->contextMenuController().contextMenuItemSelected(item);
</del><ins>+ MENUITEMINFO menuItemInfo = { 0 };
+ menuItemInfo.cbSize = sizeof(menuItemInfo);
+ menuItemInfo.fMask = MIIM_STRING;
+ ::GetMenuItemInfo(hMenu, index, true, &menuItemInfo);
+
+ auto buffer = std::make_unique<WCHAR[]>(menuItemInfo.cch + 1);
+ menuItemInfo.dwTypeData = buffer.get();
+ menuItemInfo.cch++;
+ menuItemInfo.fMask |= MIIM_ID;
+
+ ::GetMenuItemInfo(hMenu, index, true, &menuItemInfo);
+
+ ::DestroyMenu(m_currentContextMenu);
+ m_currentContextMenu = nullptr;
+
+ String title(buffer.get(), menuItemInfo.cch);
+ ContextMenuAction action = static_cast<ContextMenuAction>(menuItemInfo.wID);
+
+ ContextMenuItem item(ActionType, action, title, true, false);
+ m_page->contextMenuController().contextMenuItemSelected(&item);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool WebView::handleMouseEvent(UINT message, WPARAM wParam, LPARAM lParam)
</span><span class="lines">@@ -2491,11 +2512,9 @@
</span><span class="cx"> case WM_COMMAND:
</span><span class="cx"> if (HIWORD(wParam))
</span><span class="cx"> handled = webView->execCommand(wParam, lParam);
</span><del>- else // If the high word of wParam is 0, the message is from a menu
- webView->performContextMenuAction(wParam, lParam, false);
</del><span class="cx"> break;
</span><span class="cx"> case WM_MENUCOMMAND:
</span><del>- webView->performContextMenuAction(wParam, lParam, true);
</del><ins>+ webView->onMenuCommand(wParam, lParam);
</ins><span class="cx"> break;
</span><span class="cx"> case WM_CONTEXTMENU:
</span><span class="cx"> handled = webView->handleContextMenuEvent(wParam, lParam);
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebView.h (192314 => 192315)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebView.h        2015-11-11 18:15:56 UTC (rev 192314)
+++ trunk/Source/WebKit/win/WebView.h        2015-11-11 18:20:43 UTC (rev 192315)
</span><span class="lines">@@ -405,7 +405,7 @@
</span><span class="cx"> bool onDrawItem(WPARAM, LPARAM);
</span><span class="cx"> bool onInitMenuPopup(WPARAM, LPARAM);
</span><span class="cx"> bool onUninitMenuPopup(WPARAM, LPARAM);
</span><del>- void performContextMenuAction(WPARAM, LPARAM, bool byPosition);
</del><ins>+ void onMenuCommand(WPARAM, LPARAM);
</ins><span class="cx"> bool mouseWheel(WPARAM, LPARAM, bool isMouseHWheel);
</span><span class="cx"> bool verticalScroll(WPARAM, LPARAM);
</span><span class="cx"> bool horizontalScroll(WPARAM, LPARAM);
</span><span class="lines">@@ -615,6 +615,7 @@
</span><span class="cx"> WebCore::Page* m_page { nullptr };
</span><span class="cx"> WebInspectorClient* m_inspectorClient { nullptr };
</span><span class="cx">
</span><ins>+ HMENU m_currentContextMenu { nullptr };
</ins><span class="cx"> RefPtr<WebCore::SharedGDIObject<HBITMAP>> m_backingStoreBitmap;
</span><span class="cx"> SIZE m_backingStoreSize;
</span><span class="cx"> RefPtr<WebCore::SharedGDIObject<HRGN>> m_backingStoreDirtyRegion;
</span></span></pre>
</div>
</div>
</body>
</html>