Skip to content
Permalink
Browse files
More of <rdar://problem/8613727> and https://bugs.webkit.org/show_bug…
….cgi?id=50042

WK2 Context Menu Items need a user data object and a client callback for selection.

Reviewed by Dan Bernstein.

* Shared/API/c/WKContextMenuItem.cpp:
(WKContextMenuItemGetUserData):
(WKContextMenuItemSetUserData):
* Shared/API/c/WKContextMenuItem.h:

* Shared/WebContextMenuItem.cpp:
(WebKit::WebContextMenuItem::userData):
(WebKit::WebContextMenuItem::setUserData):
* Shared/WebContextMenuItem.h:

* Shared/WebContextMenuItemData.cpp:
(WebKit::WebContextMenuItemData::userData):
(WebKit::WebContextMenuItemData::setUserData):
* Shared/WebContextMenuItemData.h:

* UIProcess/API/C/WKPage.h:

* UIProcess/WebPageContextMenuClient.cpp:
(WebKit::WebPageContextMenuClient::customContextMenuItemSelected): Added for WK2 apps to get a callback.
* UIProcess/WebPageContextMenuClient.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::contextMenuItemSelected):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(-[WebUserDataWrapper initWithUserData:WebKit::]): Add an "APIObject" user data wrapper class to associate with the NSMenuItem.
(-[WebUserDataWrapper WebKit::]):
(-[WebMenuTarget forwardContextMenuAction:]): Include the user data object in the created ContextMenuItemData.
(WebKit::nsMenuItemVector):



Canonical link: https://commits.webkit.org/63167@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@72707 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
beidson committed Nov 25, 2010
1 parent be023fe commit 9f10fda8a571693c56608b2ab68c5cfbae907eec
@@ -1,3 +1,39 @@
2010-11-24 Brady Eidson <beidson@apple.com>

Reviewed by Dan Bernstein.

More of <rdar://problem/8613727> and https://bugs.webkit.org/show_bug.cgi?id=50042
WK2 Context Menu Items need a user data object and a client callback for selection.

* Shared/API/c/WKContextMenuItem.cpp:
(WKContextMenuItemGetUserData):
(WKContextMenuItemSetUserData):
* Shared/API/c/WKContextMenuItem.h:

* Shared/WebContextMenuItem.cpp:
(WebKit::WebContextMenuItem::userData):
(WebKit::WebContextMenuItem::setUserData):
* Shared/WebContextMenuItem.h:

* Shared/WebContextMenuItemData.cpp:
(WebKit::WebContextMenuItemData::userData):
(WebKit::WebContextMenuItemData::setUserData):
* Shared/WebContextMenuItemData.h:

* UIProcess/API/C/WKPage.h:

* UIProcess/WebPageContextMenuClient.cpp:
(WebKit::WebPageContextMenuClient::customContextMenuItemSelected): Added for WK2 apps to get a callback.
* UIProcess/WebPageContextMenuClient.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::contextMenuItemSelected):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(-[WebUserDataWrapper initWithUserData:WebKit::]): Add an "APIObject" user data wrapper class to associate with the NSMenuItem.
(-[WebUserDataWrapper WebKit::]):
(-[WebMenuTarget forwardContextMenuAction:]): Include the user data object in the created ContextMenuItemData.
(WebKit::nsMenuItemVector):

2010-11-24 Andras Becsi <abecsi@inf.u-szeged.hu>

Reviewed by Kenneth Rohde Christiansen.
@@ -88,3 +88,13 @@ WKArrayRef WKContextMenuCopySubmenuItems(WKContextMenuItemRef itemRef)
{
return toAPI(toImpl(itemRef)->submenuItemsAsImmutableArray().leakRef());
}

WKTypeRef WKContextMenuItemGetUserData(WKContextMenuItemRef itemRef)
{
return toAPI(toImpl(itemRef)->userData());
}

void WKContextMenuItemSetUserData(WKContextMenuItemRef itemRef, WKTypeRef userDataRef)
{
toImpl(itemRef)->setUserData(toImpl(userDataRef));
}
@@ -47,6 +47,9 @@ WK_EXPORT bool WKContextMenuItemGetEnabled(WKContextMenuItemRef);
WK_EXPORT bool WKContextMenuItemGetChecked(WKContextMenuItemRef);
WK_EXPORT WKArrayRef WKContextMenuCopySubmenuItems(WKContextMenuItemRef);

WK_EXPORT WKTypeRef WKContextMenuItemGetUserData(WKContextMenuItemRef);
WK_EXPORT void WKContextMenuItemSetUserData(WKContextMenuItemRef, WKTypeRef);

#ifdef __cplusplus
}
#endif
@@ -74,5 +74,15 @@ PassRefPtr<ImmutableArray> WebContextMenuItem::submenuItemsAsImmutableArray() co
return ImmutableArray::adopt(result);
}

APIObject* WebContextMenuItem::userData() const
{
return m_webContextMenuItemData.userData();
}

void WebContextMenuItem::setUserData(APIObject* userData)
{
m_webContextMenuItemData.setUserData(userData);
}

} // namespace WebKit

@@ -46,6 +46,9 @@ class WebContextMenuItem : public APIObject {

PassRefPtr<ImmutableArray> submenuItemsAsImmutableArray() const;

APIObject* userData() const;
void setUserData(APIObject*);

WebContextMenuItemData* data() { return &m_webContextMenuItemData; }

private:
@@ -25,6 +25,7 @@

#include "WebContextMenuItemData.h"

#include "APIObject.h"
#include "ArgumentCoders.h"
#include "Arguments.h"
#include <wtf/text/CString.h>
@@ -87,6 +88,16 @@ ContextMenuItem WebContextMenuItemData::core() const
return ContextMenuItem(m_action, m_title, m_enabled, m_checked, subMenuItems);
}

APIObject* WebContextMenuItemData::userData() const
{
return m_userData.get();
}

void WebContextMenuItemData::setUserData(APIObject* userData)
{
m_userData = userData;
}

void WebContextMenuItemData::encode(CoreIPC::ArgumentEncoder* encoder) const
{
encoder->encode(CoreIPC::In(static_cast<uint32_t>(m_type), static_cast<uint32_t>(m_action), m_title, m_checked, m_enabled, m_submenu));
@@ -40,6 +40,8 @@ namespace WebCore {

namespace WebKit {

class APIObject;

class WebContextMenuItemData {
public:
WebContextMenuItemData();
@@ -56,6 +58,9 @@ class WebContextMenuItemData {

WebCore::ContextMenuItem core() const;

APIObject* userData() const;
void setUserData(APIObject*);

void encode(CoreIPC::ArgumentEncoder*) const;
static bool decode(CoreIPC::ArgumentDecoder*, WebContextMenuItemData&);

@@ -66,6 +71,7 @@ class WebContextMenuItemData {
bool m_enabled;
bool m_checked;
Vector<WebContextMenuItemData> m_submenu;
RefPtr<APIObject> m_userData;
};

Vector<WebContextMenuItemData> kitItems(Vector<WebCore::ContextMenuItem>&, WebCore::ContextMenu*);
@@ -205,11 +205,13 @@ enum {

// ContextMenu client
typedef void (*WKPageGetContextMenuFromProposedContextMenuCallback)(WKPageRef page, WKArrayRef proposedMenu, WKArrayRef* newMenu, WKTypeRef userData, const void* clientInfo);
typedef void (*WKPageCustomContextMenuItemSelectedCallback)(WKPageRef page, WKContextMenuItemRef contextMenuItem, const void* clientInfo);

struct WKPageContextMenuClient {
int version;
const void * clientInfo;
WKPageGetContextMenuFromProposedContextMenuCallback getContextMenuFromProposedMenu;
WKPageCustomContextMenuItemSelectedCallback customContextMenuItemSelected;
};
typedef struct WKPageContextMenuClient WKPageContextMenuClient;

@@ -64,4 +64,13 @@ bool WebPageContextMenuClient::getContextMenuFromProposedMenu(WebPageProxy* page
return true;
}

void WebPageContextMenuClient::customContextMenuItemSelected(WebPageProxy* page, const WebContextMenuItemData& itemData)
{
if (!m_client.customContextMenuItemSelected)
return;

RefPtr<WebContextMenuItem> item = WebContextMenuItem::create(itemData);
m_client.customContextMenuItemSelected(toAPI(page), toAPI(item.get()), m_client.clientInfo);
}

} // namespace WebKit
@@ -39,6 +39,7 @@ class WebPageProxy;
class WebPageContextMenuClient : public APIClient<WKPageContextMenuClient> {
public:
bool getContextMenuFromProposedMenu(WebPageProxy*, const Vector<WebContextMenuItemData>& proposedMenu, Vector<WebContextMenuItemData>& customMenu, APIObject* userData);
void customContextMenuItemSelected(WebPageProxy*, const WebContextMenuItemData&);
};

} // namespace WebKit
@@ -1291,6 +1291,12 @@ void WebPageProxy::showContextMenu(const WebCore::IntPoint& menuLocation, const

void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
{
// Application custom items don't need to round-trip through to WebCore in the WebProcess.
if (item.action() >= ContextMenuItemBaseApplicationTag) {
m_contextMenuClient.customContextMenuItemSelected(this, item);
return;
}

process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
}

@@ -34,6 +34,28 @@

using namespace WebCore;

@interface WebUserDataWrapper : NSObject {
RefPtr<WebKit::APIObject> _webUserData;
}
- (id)initWithUserData:(WebKit::APIObject*)userData;
- (WebKit::APIObject*)userData;
@end

@implementation WebUserDataWrapper

- (id)initWithUserData:(WebKit::APIObject*)userData
{
_webUserData = userData;
return self;
}

- (WebKit::APIObject*)userData
{
return _webUserData.get();
}

@end

@interface WebMenuTarget : NSObject {
WebKit::WebContextMenuProxyMac* _menuProxy;
}
@@ -64,6 +86,12 @@ - (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy
- (void)forwardContextMenuAction:(id)sender
{
WebKit::WebContextMenuItemData item(ActionType, static_cast<ContextMenuAction>([sender tag]), [sender title], [sender isEnabled], [sender state] == NSOnState);

if (id representedObject = [sender representedObject]) {
ASSERT([representedObject isKindOfClass:[WebUserDataWrapper class]]);
item.setUserData([static_cast<WebUserDataWrapper *>(representedObject) userData]);
}

_menuProxy->contextMenuItemSelected(item);
}

@@ -112,6 +140,12 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem> >& m
[menuItem setEnabled:items[i].enabled()];
[menuItem setState:items[i].checked() ? NSOnState : NSOffState];

if (items[i].userData()) {
WebUserDataWrapper *wrapper = [[WebUserDataWrapper alloc] initWithUserData:items[i].userData()];
[menuItem setRepresentedObject:wrapper];
[wrapper release];
}

result.append(RetainPtr<NSMenuItem>(AdoptNS, menuItem));
break;
}

0 comments on commit 9f10fda

Please sign in to comment.