Reviewed by Beth.
WebCore:
* platform/ContextMenu.h: Added method to retrieve context menu item by index
* platform/win/ContextMenuWin.cpp:
(WebCore::ContextMenu::ContextMenu): call setPlatformDescription() since that will handle
adding the MNS_NOTIFYBYPOS style to the context menu.
(WebCore::contextMenuItemByIdOrPosition): helper method so we don't have to duplicate code
between itemWithAction() and itemAtIndex().
(WebCore::ContextMenu::itemWithAction):
(WebCore::ContextMenu::itemAtIndex):
(WebCore::ContextMenu::setPlatformDescription): add MNS_NOTIFYBYPOS style to the context menu
so we will get notified by menu position through WM_MENUCOMMAND when the item is selected.
WebKit/win:
* WebView.cpp:
(WebView::performContextMenuAction): performContextMenuAction() can now handle context menu
item selection via WM_MENUCOMMAND (by specifying byPosition to be true). In that case, we
get the ContextMenuItem by position rather than by action id.
(WebViewWndProc): handle WM_MENUCOMMAND
* WebView.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25426
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-09-07 Ada Chan <adachan@apple.com>
+
+ <rdar://problem/5395928> Need to be able to handle context menu item selection by index
+
+ Reviewed by Beth.
+
+ * platform/ContextMenu.h: Added method to retrieve context menu item by index
+ * platform/win/ContextMenuWin.cpp:
+ (WebCore::ContextMenu::ContextMenu): call setPlatformDescription() since that will handle
+ adding the MNS_NOTIFYBYPOS style to the context menu.
+ (WebCore::contextMenuItemByIdOrPosition): helper method so we don't have to duplicate code
+ between itemWithAction() and itemAtIndex().
+ (WebCore::ContextMenu::itemWithAction):
+ (WebCore::ContextMenu::itemAtIndex):
+ (WebCore::ContextMenu::setPlatformDescription): add MNS_NOTIFYBYPOS style to the context menu
+ so we will get notified by menu position through WM_MENUCOMMAND when the item is selected.
+
2007-09-07 Justin Garcia <justin.garcia@apple.com>
Reviewed by Darin.
void appendItem(ContextMenuItem&);
ContextMenuItem* itemWithAction(unsigned);
+ ContextMenuItem* itemAtIndex(unsigned, const PlatformMenuDescription);
unsigned itemCount() const;
ContextMenu::ContextMenu(const HitTestResult& result)
: m_hitTestResult(result)
- , m_platformDescription(::CreatePopupMenu())
+ , m_platformDescription(0)
{
+ setPlatformDescription(::CreatePopupMenu());
}
ContextMenu::ContextMenu(const HitTestResult& result, const PlatformMenuDescription menu)
: m_hitTestResult(result)
- , m_platformDescription(menu)
+ , m_platformDescription(0)
{
+ setPlatformDescription(menu);
}
ContextMenu::~ContextMenu()
insertItem(itemCount(), item);
}
-ContextMenuItem* ContextMenu::itemWithAction(unsigned action)
+static ContextMenuItem* contextMenuItemByIdOrPosition(HMENU menu, unsigned id, BOOL byPosition)
{
+ if (!menu)
+ return 0;
LPMENUITEMINFO info = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO));
if (!info)
return 0;
info->fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
- if (!::GetMenuItemInfo(m_platformDescription, action, FALSE, info)) {
+ if (!::GetMenuItemInfo(menu, id, byPosition, info)) {
free(info);
return 0;
}
return 0;
}
info->dwTypeData = buffer;
- ::GetMenuItemInfo(m_platformDescription, action, FALSE, info);
+ ::GetMenuItemInfo(menu, id, byPosition, info);
}
return new ContextMenuItem(info);
}
+ContextMenuItem* ContextMenu::itemWithAction(unsigned action)
+{
+ return contextMenuItemByIdOrPosition(m_platformDescription, action, FALSE);
+}
+
+ContextMenuItem* ContextMenu::itemAtIndex(unsigned index, const PlatformMenuDescription platformDescription)
+{
+ return contextMenuItemByIdOrPosition(platformDescription, index, TRUE);
+}
+
void ContextMenu::setPlatformDescription(HMENU menu)
{
if (menu == m_platformDescription)
::DestroyMenu(m_platformDescription);
m_platformDescription = menu;
+ if (!m_platformDescription)
+ return;
+
+ MENUINFO menuInfo = {0};
+ menuInfo.cbSize = sizeof(MENUINFO);
+ menuInfo.fMask = MIM_STYLE;
+ ::GetMenuInfo(m_platformDescription, &menuInfo);
+ menuInfo.fMask = MIM_STYLE;
+ menuInfo.dwStyle |= MNS_NOTIFYBYPOS;
+ ::SetMenuInfo(m_platformDescription, &menuInfo);
}
HMENU ContextMenu::platformDescription() const
+2007-09-07 Ada Chan <adachan@apple.com>
+
+ <rdar://problem/5395928> Need to be able to handle context menu item selection by index
+
+ Reviewed by Beth.
+
+ * WebView.cpp:
+ (WebView::performContextMenuAction): performContextMenuAction() can now handle context menu
+ item selection via WM_MENUCOMMAND (by specifying byPosition to be true). In that case, we
+ get the ContextMenuItem by position rather than by action id.
+ (WebViewWndProc): handle WM_MENUCOMMAND
+ * WebView.h:
+
2007-09-07 Ada Chan <adachan@apple.com>
<rdar://problem/5453494> Better lifetime management of WebDataSource and WebDocumentLoader
return true;
}
-void WebView::performContextMenuAction(WPARAM wParam, LPARAM /*lParam*/)
+void WebView::performContextMenuAction(WPARAM wParam, LPARAM lParam, bool byPosition)
{
ContextMenu* menu = m_page->contextMenuController()->contextMenu();
ASSERT(menu);
- ContextMenuItem* item = menu->itemWithAction((ContextMenuAction)wParam);
+ ContextMenuItem* item = byPosition ? menu->itemAtIndex((unsigned)wParam, (HMENU)lParam) : menu->itemWithAction((ContextMenuAction)wParam);
+ if (!item)
+ return;
m_page->contextMenuController()->contextMenuItemSelected(item);
delete item;
}
if (HIWORD(wParam))
handled = webView->execCommand(wParam, lParam);
else // If the high word of wParam is 0, the message is from a menu
- webView->performContextMenuAction(wParam, lParam);
+ webView->performContextMenuAction(wParam, lParam, false);
+ break;
+ case WM_MENUCOMMAND:
+ webView->performContextMenuAction(wParam, lParam, true);
break;
case WM_CONTEXTMENU:
handled = webView->handleContextMenuEvent(wParam, lParam);
bool onDrawItem(WPARAM, LPARAM);
bool onInitMenuPopup(WPARAM, LPARAM);
bool onUninitMenuPopup(WPARAM, LPARAM);
- void performContextMenuAction(WPARAM, LPARAM);
+ void performContextMenuAction(WPARAM, LPARAM, bool byPosition);
bool mouseWheel(WPARAM, LPARAM, bool isHorizontal);
bool execCommand(WPARAM wParam, LPARAM lParam);
bool keyDown(WPARAM, LPARAM, bool systemKeyDown = false);