Commit c4728817 authored by bweinstein@apple.com's avatar bweinstein@apple.com

JavaScriptCore: Turn on USE(CROSS_PLATFORM_CONTEXT_MENUS) for Windows.

Reviewed by Adam Roben.

* wtf/Platform.h:

WebCore: Prep for WebKit2: Context menu support on Windows
https://bugs.webkit.org/show_bug.cgi?id=50514
        
Reviewed by Adam Roben.

Before this patch ContextMenu on Windows were backed by HMENUs, and ContextMenuItems
were backed by MENUITEMINFOs. This meant they couldn't be copied, and they needed to
be to work in WebKit2.
        
This patch adds a new USE flag - CROSS_PLATFORM_CONTEXT_MENUS that are for a cross-platform
representation of context menus. This patch also has Windows adopt them.
        
Cross-platform context menus change the API of context menus and the ContextMenuClient. There
is no more idea of a PlatformMenuDescription or a PlatformMenuItemDescription. Menus are backed
by a Vector of ContextMenuItems, and menu items are backed by the variables they need (enabled, checked
title, action, type, and submenu).
        
This patch also refactors the ContextMenuClient interface to use a variation on the getCustomMenuFromDefaultItems
function to allow for customization of the context menu.
        
For other ports to use CROSS_PLATFORM_CONTEXT_MENUS, all they need to do is write conversion functions from
a ContextMenu <-> native menu type, and ContextMenuItem <-> native menu item type. For Windows, this is done
in ContextMenuWin.cpp and ContextMenuItemWin.cpp.

No new tests, no change in behavior.

* WebCore.vcproj/WebCore.vcproj: Add new files (only needed on Windows for now).
* loader/EmptyClients.h:
(WebCore::EmptyContextMenuClient::customizeMenu): Define this function if CROSS_PLATFORM_CONTEXT_MENUS
    is on.
* page/ContextMenuClient.h: Ditto. 
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::showContextMenu): Call customizeMenu instead of 
    getCustomMenuFromDefaultItems if CROSS_PLATFORM_CONTEXT_MENUS is on.
* platform/ContextMenu.cpp: Added.
(WebCore::ContextMenu::ContextMenu): Empty constructor.
(WebCore::ContextMenu::setItems): Sets the items in the menu.
(WebCore::ContextMenu::items): Returns the items in the menu.
(WebCore::ContextMenu::itemAtIndex):
(WebCore::itemWithActionInMenu): Returns the item with the correct action, recursively descending
    into submenus.
(WebCore::ContextMenu::itemWithAction): Calls through to itemWithActionInMenu.
* platform/ContextMenu.h: Added a new set of functions and member variables that are defined for
    CROSS_PLATFORM_CONTEXT_MENUS.
(WebCore::ContextMenu::appendItem): Appends an item to the menu.
* platform/ContextMenuItem.cpp: Added.
(WebCore::ContextMenuItem::ContextMenuItem):
(WebCore::ContextMenuItem::~ContextMenuItem):
(WebCore::ContextMenuItem::setSubMenu):
* platform/ContextMenuItem.h:
(WebCore::ContextMenuItem::type): Returns the type.
(WebCore::ContextMenuItem::setType): Sets the type.
(WebCore::ContextMenuItem::action): Returns the action.
(WebCore::ContextMenuItem::setAction): Sets the action.
(WebCore::ContextMenuItem::title): Returns the title.
(WebCore::ContextMenuItem::setTitle): Sets the title.
(WebCore::ContextMenuItem::checked): Returns whether or not the menu item is checked.
(WebCore::ContextMenuItem::setChecked): Sets whether ot not the menu item is checked.
(WebCore::ContextMenuItem::enabled): Returns whether or not the menu item is enabled.
(WebCore::ContextMenuItem::setEnabled): Sets whether or not the menu item is enabled.
(WebCore::ContextMenuItem::submenu): Returns the submenu.
* platform/PlatformMenuDescription.h: Remove the idea if a PlatformMenuDescription if 
    CROSS_PLATFORM_CONTEXT_MENUS is on.
* platform/win/ContextMenuItemWin.cpp:
(WebCore::ContextMenuItem::ContextMenuItem): Creates a ContextMenuItem from a MENUITEMINFO.
(WebCore::ContextMenuItem::nativeMenuItem): Creates and returns a MENUITEMINFO.
* platform/win/ContextMenuWin.cpp:
(WebCore::ContextMenu::ContextMenu): Creates a ContextMenu from an HMENU.
(WebCore::ContextMenu::nativeMenu): Creates and returns an HMENU.

WebKit/win: Prep for WebKit2: Context menu support on Windows
https://bugs.webkit.org/show_bug.cgi?id=50514
        
Reviewed by Adam Roben.

Update WebKit for the new CROSS_PLATFORM_CONTEXT_MENUS flag, and define customizeMenu
instead of getCustomMenuFromDefaultItems.

* WebCoreSupport/WebContextMenuClient.cpp:
(WebContextMenuClient::customizeMenu): getCustomMenuFromDefaultItems was turned into
    this function, with refactoring using nativeMenu instead of platformDescription.
(WebContextMenuClient::contextMenuItemSelected):  Use nativeMenu instead of platformDescription.
* WebCoreSupport/WebContextMenuClient.h:
* WebView.cpp:
(WebView::handleContextMenuEvent): Call nativeMenu instead of platformDescription.
(WebView::performContextMenuAction): Only call itemAtIndex with one argument, no need
    for the second.

WebKit2: Prep for WebKit2: Context menu support on Windows
https://bugs.webkit.org/show_bug.cgi?id=50514
        
Reviewed by Adam Roben.

Update WebKit2 to call the correct code when CROSS_PLATFORM_CONTEXT_MENUS is set.

* Shared/WebContextMenuItemData.cpp:
(WebKit::WebContextMenuItemData::WebContextMenuItemData): Add a branch based on whether or not 
    CROSS_PLATFORM_CONTEXT_MENUS is set.
* WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
(WebKit::WebContextMenuClient::customizeMenu): Define different functions based on
    whether or not CROSS_PLATFORM_CONTEXT_MENUS. Both of these are stubs, so functionality
    doesn't need to be shared.
* WebProcess/WebCoreSupport/WebContextMenuClient.h: Define different functions based on
    whether or not CROSS_PLATFORM_CONTEXT_MENUS. 
* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::show): Add a branch based on whether or not 
    CROSS_PLATFORM_CONTEXT_MENUS is set.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73802 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 005063e1
2010-12-10 Brian Weinstein <bweinstein@apple.com>
Reviewed by Adam Roben.
Turn on USE(CROSS_PLATFORM_CONTEXT_MENUS) for Windows.
* wtf/Platform.h:
2010-12-10 Martin Robinson <mrobinson@igalia.com>
Unreviewed, rolling out r73703.
......
......@@ -1106,6 +1106,10 @@
#define WTF_USE_PLATFORM_STRATEGIES 1
#endif
#if PLATFORM(WIN)
#define WTF_USE_CROSS_PLATFORM_CONTEXT_MENUS 1
#endif
/* Geolocation request policy. pre-emptive policy is to acquire user permission before acquiring location.
Client based implementations will have option to choose between pre-emptive and nonpre-emptive permission policy.
pre-emptive permission policy is enabled by default for all client-based implementations. */
......
2010-12-09 Brian Weinstein <bweinstein@apple.com>
Reviewed by Adam Roben.
Prep for WebKit2: Context menu support on Windows
https://bugs.webkit.org/show_bug.cgi?id=50514
Before this patch ContextMenu on Windows were backed by HMENUs, and ContextMenuItems
were backed by MENUITEMINFOs. This meant they couldn't be copied, and they needed to
be to work in WebKit2.
This patch adds a new USE flag - CROSS_PLATFORM_CONTEXT_MENUS that are for a cross-platform
representation of context menus. This patch also has Windows adopt them.
Cross-platform context menus change the API of context menus and the ContextMenuClient. There
is no more idea of a PlatformMenuDescription or a PlatformMenuItemDescription. Menus are backed
by a Vector of ContextMenuItems, and menu items are backed by the variables they need (enabled, checked
title, action, type, and submenu).
This patch also refactors the ContextMenuClient interface to use a variation on the getCustomMenuFromDefaultItems
function to allow for customization of the context menu.
For other ports to use CROSS_PLATFORM_CONTEXT_MENUS, all they need to do is write conversion functions from
a ContextMenu <-> native menu type, and ContextMenuItem <-> native menu item type. For Windows, this is done
in ContextMenuWin.cpp and ContextMenuItemWin.cpp.
No new tests, no change in behavior.
* WebCore.vcproj/WebCore.vcproj: Add new files (only needed on Windows for now).
* loader/EmptyClients.h:
(WebCore::EmptyContextMenuClient::customizeMenu): Define this function if CROSS_PLATFORM_CONTEXT_MENUS
is on.
* page/ContextMenuClient.h: Ditto.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::showContextMenu): Call customizeMenu instead of
getCustomMenuFromDefaultItems if CROSS_PLATFORM_CONTEXT_MENUS is on.
* platform/ContextMenu.cpp: Added.
(WebCore::ContextMenu::ContextMenu): Empty constructor.
(WebCore::ContextMenu::setItems): Sets the items in the menu.
(WebCore::ContextMenu::items): Returns the items in the menu.
(WebCore::ContextMenu::itemAtIndex):
(WebCore::itemWithActionInMenu): Returns the item with the correct action, recursively descending
into submenus.
(WebCore::ContextMenu::itemWithAction): Calls through to itemWithActionInMenu.
* platform/ContextMenu.h: Added a new set of functions and member variables that are defined for
CROSS_PLATFORM_CONTEXT_MENUS.
(WebCore::ContextMenu::appendItem): Appends an item to the menu.
* platform/ContextMenuItem.cpp: Added.
(WebCore::ContextMenuItem::ContextMenuItem):
(WebCore::ContextMenuItem::~ContextMenuItem):
(WebCore::ContextMenuItem::setSubMenu):
* platform/ContextMenuItem.h:
(WebCore::ContextMenuItem::type): Returns the type.
(WebCore::ContextMenuItem::setType): Sets the type.
(WebCore::ContextMenuItem::action): Returns the action.
(WebCore::ContextMenuItem::setAction): Sets the action.
(WebCore::ContextMenuItem::title): Returns the title.
(WebCore::ContextMenuItem::setTitle): Sets the title.
(WebCore::ContextMenuItem::checked): Returns whether or not the menu item is checked.
(WebCore::ContextMenuItem::setChecked): Sets whether ot not the menu item is checked.
(WebCore::ContextMenuItem::enabled): Returns whether or not the menu item is enabled.
(WebCore::ContextMenuItem::setEnabled): Sets whether or not the menu item is enabled.
(WebCore::ContextMenuItem::submenu): Returns the submenu.
* platform/PlatformMenuDescription.h: Remove the idea if a PlatformMenuDescription if
CROSS_PLATFORM_CONTEXT_MENUS is on.
* platform/win/ContextMenuItemWin.cpp:
(WebCore::ContextMenuItem::ContextMenuItem): Creates a ContextMenuItem from a MENUITEMINFO.
(WebCore::ContextMenuItem::nativeMenuItem): Creates and returns a MENUITEMINFO.
* platform/win/ContextMenuWin.cpp:
(WebCore::ContextMenu::ContextMenu): Creates a ContextMenu from an HMENU.
(WebCore::ContextMenu::nativeMenu): Creates and returns an HMENU.
2010-12-10 Emil Eklund <eae@chromium.org>
Reviewed by Adam Barth.
......
......@@ -25305,10 +25305,18 @@
RelativePath="..\platform\ContentType.h"
>
</File>
<File
RelativePath="..\platform\ContextMenu.cpp"
>
</File>
<File
RelativePath="..\platform\ContextMenu.h"
>
</File>
<File
RelativePath="..\platform\ContextMenuItem.cpp"
>
</File>
<File
RelativePath="..\platform\ContextMenuItem.h"
>
......@@ -501,7 +501,11 @@ public:
virtual ~EmptyContextMenuClient() { }
virtual void contextMenuDestroyed() { }
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
virtual PassOwnPtr<ContextMenu> customizeMenu(PassOwnPtr<ContextMenu>) { return 0; }
#else
virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*) { return 0; }
#endif
virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) { }
virtual void downloadURL(const KURL&) { }
......
......@@ -26,11 +26,12 @@
#ifndef ContextMenuClient_h
#define ContextMenuClient_h
#include "ContextMenu.h"
#include "PlatformMenuDescription.h"
#include <wtf/Forward.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
class ContextMenu;
class ContextMenuItem;
class Frame;
class HitTestResult;
......@@ -41,7 +42,12 @@ namespace WebCore {
virtual ~ContextMenuClient() { }
virtual void contextMenuDestroyed() = 0;
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
virtual PassOwnPtr<ContextMenu> customizeMenu(PassOwnPtr<ContextMenu>) = 0;
#else
virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*) = 0;
#endif
virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) = 0;
virtual void downloadURL(const KURL& url) = 0;
......
......@@ -144,8 +144,13 @@ void ContextMenuController::showContextMenu(Event* event)
if (m_page->inspectorController()->enabled())
addInspectElementItem();
#endif
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
m_contextMenu = m_client->customizeMenu(m_contextMenu.release());
#else
PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
m_contextMenu->setPlatformDescription(customMenu);
#endif
event->setDefaultHandled();
}
......
/*
* 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 "config.h"
#include "ContextMenu.h"
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
namespace WebCore {
ContextMenu::ContextMenu()
{
}
static const ContextMenuItem* findItemWithAction(unsigned action, const Vector<ContextMenuItem>& items)
{
for (size_t i = 0; i < items.size(); ++i) {
const ContextMenuItem& item = items[i];
if (item.action() == action)
return &item;
if (item.type() != SubmenuType)
continue;
if (const ContextMenuItem* subMenuItem = findItemWithAction(action, item.subMenuItems()))
return subMenuItem;
}
return 0;
}
ContextMenuItem* ContextMenu::itemWithAction(unsigned action)
{
// FIXME: When more platforms switch over, this fucntion should return a const ContextMenuItem*'s, and the const_cast
// won't be needed anymore.
return const_cast<ContextMenuItem*>(findItemWithAction(action, m_items));
}
} // namespace WebCore
#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
......@@ -48,13 +48,34 @@ namespace WebCore {
{
public:
ContextMenu();
ContextMenuItem* itemWithAction(unsigned);
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
#if PLATFORM(WIN)
typedef HMENU NativeMenu;
#endif
explicit ContextMenu(NativeMenu);
NativeMenu nativeMenu() const;
static NativeMenu createNativeMenuFromItems(const Vector<ContextMenuItem>&);
static void getContextMenuItems(NativeMenu, Vector<ContextMenuItem>&);
// FIXME: When more platforms switch over, this should return const ContextMenuItem*'s.
ContextMenuItem* itemAtIndex(unsigned index) { return &m_items[index]; }
void setItems(const Vector<ContextMenuItem>& items) { m_items = items; }
const Vector<ContextMenuItem>& items() const { return m_items; }
void appendItem(const ContextMenuItem& item) { m_items.append(item); }
#else
ContextMenu(const PlatformMenuDescription);
~ContextMenu();
void insertItem(unsigned position, ContextMenuItem&);
void appendItem(ContextMenuItem&);
ContextMenuItem* itemWithAction(unsigned);
ContextMenuItem* itemAtIndex(unsigned, const PlatformMenuDescription);
unsigned itemCount() const;
......@@ -63,10 +84,17 @@ namespace WebCore {
void setPlatformDescription(PlatformMenuDescription);
PlatformMenuDescription releasePlatformDescription();
#if PLATFORM(WX)
static ContextMenuItem* itemWithId(int);
#endif
#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
private:
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
Vector<ContextMenuItem> m_items;
#else
#if PLATFORM(MAC)
// Keep this in sync with the PlatformMenuDescription typedef
RetainPtr<NSMutableArray> m_platformDescription;
......@@ -83,10 +111,14 @@ namespace WebCore {
unsigned m_itemCount;
#endif
#endif
#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
};
#if !USE(CROSS_PLATFORM_CONTEXT_MENUS)
Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription);
PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>&);
#endif
}
......
/*
* 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 "config.h"
#include "ContextMenuItem.h"
#include "ContextMenu.h"
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
namespace WebCore {
ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu)
: m_type(type)
, m_action(action)
, m_title(title)
, m_enabled(true)
, m_checked(false)
{
setSubMenu(subMenu);
}
ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked)
: m_type(type)
, m_action(action)
, m_title(title)
, m_enabled(enabled)
, m_checked(checked)
{
}
ContextMenuItem::ContextMenuItem(ContextMenuAction action, const String& title, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems)
: m_type(SubmenuType)
, m_action(action)
, m_title(title)
, m_enabled(enabled)
, m_checked(checked)
, m_subMenuItems(subMenuItems)
{
}
ContextMenuItem::~ContextMenuItem()
{
}
void ContextMenuItem::setSubMenu(ContextMenu* subMenu)
{
if (subMenu) {
m_type = SubmenuType;
m_subMenuItems = subMenu->items();
} else {
m_type = ActionType;
m_subMenuItems.clear();
}
}
void ContextMenuItem::setType(ContextMenuItemType type)
{
m_type = type;
}
ContextMenuItemType ContextMenuItem::type() const
{
return m_type;
}
void ContextMenuItem::setAction(ContextMenuAction action)
{
m_action = action;
}
ContextMenuAction ContextMenuItem::action() const
{
return m_action;
}
void ContextMenuItem::setChecked(bool checked)
{
m_checked = checked;
}
bool ContextMenuItem::checked() const
{
return m_checked;
}
void ContextMenuItem::setEnabled(bool enabled)
{
m_enabled = enabled;
}
bool ContextMenuItem::enabled() const
{
return m_enabled;
}
} // namespace WebCore
#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
......@@ -40,7 +40,7 @@
class NSMenuItem;
#endif
#elif PLATFORM(WIN)
typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
typedef struct tagMENUITEMINFOW MENUITEMINFO;
#elif PLATFORM(GTK)
typedef struct _GtkMenuItem GtkMenuItem;
#elif PLATFORM(QT)
......@@ -166,8 +166,6 @@ namespace WebCore {
#if PLATFORM(MAC)
typedef NSMenuItem* PlatformMenuItemDescription;
#elif PLATFORM(WIN)
typedef LPMENUITEMINFO PlatformMenuItemDescription;
#elif PLATFORM(QT)
struct PlatformMenuItemDescription {
PlatformMenuItemDescription()
......@@ -253,50 +251,80 @@ namespace WebCore {
#endif
class ContextMenuItem : public FastAllocBase {
public:
ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, ContextMenu* subMenu = 0);
ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
~ContextMenuItem();
void setType(ContextMenuItemType);
ContextMenuItemType type() const;
void setAction(ContextMenuAction);
ContextMenuAction action() const;
void setChecked(bool = true);
bool checked() const;
void setEnabled(bool = true);
bool enabled() const;
void setSubMenu(ContextMenu*);
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
#if PLATFORM(WIN)
typedef MENUITEMINFO NativeItem;
#endif
ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
explicit ContextMenuItem(const NativeItem&);
// On Windows, the title (dwTypeData of the MENUITEMINFO) is not set in this function. Callers can set the title themselves,
// and handle the lifetime of the title, if they need it.
NativeItem nativeMenuItem() const;
void setTitle(const String& title) { m_title = title; }
const String& title() const { return m_title; }
const Vector<ContextMenuItem>& subMenuItems() const { return m_subMenuItems; }
#else
public:
ContextMenuItem(PlatformMenuItemDescription);
ContextMenuItem(ContextMenu* subMenu = 0);
ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu = 0);
ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
#if PLATFORM(GTK)
ContextMenuItem(GtkMenuItem*);
#endif
~ContextMenuItem();
PlatformMenuItemDescription releasePlatformDescription();
ContextMenuItemType type() const;
void setType(ContextMenuItemType);
ContextMenuAction action() const;
void setAction(ContextMenuAction);
String title() const;
void setTitle(const String&);
PlatformMenuDescription platformSubMenu() const;
void setSubMenu(ContextMenu*);
void setSubMenu(Vector<ContextMenuItem>&);
void setChecked(bool = true);
bool checked() const;
void setEnabled(bool = true);
bool enabled() const;
// FIXME: Do we need a keyboard accelerator here?
#if PLATFORM(GTK)
static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&);
#endif
#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
private:
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
String m_title;
bool m_enabled;
bool m_checked;
ContextMenuAction m_action;
ContextMenuItemType m_type;
Vector<ContextMenuItem> m_subMenuItems;
#else
#if PLATFORM(MAC)
RetainPtr<NSMenuItem> m_platformDescription;
#else
PlatformMenuItemDescription m_platformDescription;
#endif
#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
};
}
......
......@@ -32,8 +32,6 @@
#else
class NSMutableArray;
#endif
#elif PLATFORM(WIN)
typedef struct HMENU__* HMENU;
#elif PLATFORM(QT)
#include <qlist.h>
#elif PLATFORM(GTK)
......@@ -46,10 +44,9 @@ class BMenu;
namespace WebCore {
#if !USE(CROSS_PLATFORM_CONTEXT_MENUS)
#if PLATFORM(MAC)
typedef NSMutableArray* PlatformMenuDescription;
#elif PLATFORM(WIN)
typedef HMENU PlatformMenuDescription;
#elif PLATFORM(QT)
class ContextMenuItem;
typedef const QList<ContextMenuItem>* PlatformMenuDescription;
......@@ -62,6 +59,7 @@ namespace WebCore {
#else
typedef void* PlatformMenuDescription;
#endif
#endif // !USE(CROSS_PLATFORM_CONTEXT_MENUS)
} // namespace
......
......@@ -28,198 +28,66 @@
#include "ContextMenu.h"
#include <wtf/text/CString.h>
#include <windows.h>
#if OS(WINCE)
#ifndef MFS_DISABLED
#define MFS_DISABLED MF_GRAYED
#endif
#ifndef MIIM_FTYPE
#define MIIM_FTYPE MIIM_TYPE
#endif
#ifndef MIIM_STRING
#define MIIM_STRING 0
#endif
#endif
namespace WebCore {
ContextMenuItem::ContextMenuItem(LPMENUITEMINFO item)
: m_platformDescription(item)
{
}
ContextMenuItem::ContextMenuItem(ContextMenu* subMenu)
ContextMenuItem::ContextMenuItem(const MENUITEMINFO& info)
{
m_platformDescription = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO));
if (!m_platformDescription)
return;
if (info.fMask & MIIM_FTYPE)
m_type = info.fType == MFT_SEPARATOR ? SeparatorType : ActionType;
else
m_type = SeparatorType;
memset(m_platformDescription, 0, sizeof(MENUITEMINFO));
m_platformDescription->cbSize = sizeof(MENUITEMINFO);
if (m_type == ActionType && info.fMask & MIIM_STRING)
m_title = String(info.dwTypeData, info.cch);
m_platformDescription->wID = ContextMenuItemTagNoAction;
if (subMenu) {
m_platformDescription->fMask |= MIIM_SUBMENU;
m_platformDescription->hSubMenu = subMenu->platformDescription();
if ((info.fMask & MIIM_SUBMENU) && info.hSubMenu) {
m_type = SubmenuType;
ContextMenu::getContextMenuItems(info.hSubMenu, m_subMenuItems);
}
}
ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu)
{
m_platformDescription = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO));
if (!m_platformDescription)
return;
memset(m_platformDescription, 0, sizeof(MENUITEMINFO));
m_platformDescription->cbSize = sizeof(MENUITEMINFO);
m_platformDescription->fMask = MIIM_FTYPE;
if (info.fMask & MIIM_ID)
m_action = static_cast<ContextMenuAction>(info.wID);
else
m_action = ContextMenuItemTagNoAction;
if (type == SeparatorType) {
m_platformDescription->fType = MFT_SEPARATOR;
return;
if (info.fMask & MIIM_STATE) {
m_checked = info.fState & MFS_CHECKED;
m_enabled = !(info.fState & MFS_DISABLED);
} else {
m_checked = false;
m_enabled = false;
}
if (subMenu) {
m_platformDescription->fMask |= MIIM_STRING | MIIM_SUBMENU;
m_platformDescription->hSubMenu = subMenu->platformDescription();
} else
m_platformDescription->fMask |= MIIM_STRING | MIIM_ID;
m_platformDescription->fType = MFT_STRING;
m_platformDescription->wID = action;
String t = title;
m_platformDescription->cch = t.length();
m_platformDescription->dwTypeData = wcsdup(t.charactersWithNullTermination());
}
ContextMenuItem::ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool, bool)
// ContextMenuItem::nativeMenuItem doesn't set the info.dwTypeData. This is
// done to make the lifetime handling of the returned MENUITEMINFO easier on
// callers. Callers can set dwTypeData themselves (and make their own decisions
// about its lifetime) if they need it.
MENUITEMINFO ContextMenuItem::nativeMenuItem() const
{
// FIXME: Implement
}
MENUITEMINFO info = {0};
info.cbSize = sizeof(MENUITEMINFO);
ContextMenuItem::ContextMenuItem(ContextMenuAction, const String&, bool, bool, Vector<ContextMenuItem>&)
{