Commit 60350d69 authored by bweinstein@apple.com's avatar bweinstein@apple.com

Part of Layering Violation in ContextMenu

https://bugs.webkit.org/show_bug.cgi?id=50586
        
Reviewed by John Sullivan.

WebCore: 

ContextMenuMac.mm had a WebCoreMenuTarget class, which was responsible for wrapping
a ContextMenuItem, and calling through to the ContextMenuController to validate it
and call a function when it was selected.
        
It was a layering violation to have this class here, because ContextMenu can't know
about ContextMenuController.
        
This patch moves the class that wraps the ContextMenuItems to WebKit/mac/WebHTMLView.mm,
and sets up the menu targets there.

No change in behavior, no new tests.

* WebCore.exp.in: Added function that needs to be exported.
* platform/mac/ContextMenuMac.mm:
(WebCore::ContextMenu::ContextMenu): Don't set the sharedMenuTarget anymore.
(WebCore::ContextMenu::appendItem): Don't call setMenuItemTarget (this is done in WebKit now).
(WebCore::ContextMenu::insertItem): Ditto.

WebKit/mac: 

Move WebMenuTarget from ContextMenuMac to here, because having it in ContextMenuMac
was a layering violation. Also, make sure we set the menu item targets for all menu
items before showing them, because the ContextMenu constructor doesn't do that anymore.

* WebView/WebHTMLView.mm:
(+[WebMenuTarget sharedMenuTarget]): Moved from ContextMenuMac.mm.
(-[WebMenuTarget WebCore::]): Ditto.
(-[WebMenuTarget setMenuController:WebCore::]): Ditto.
(-[WebMenuTarget forwardContextMenuAction:]): Ditto.
(-[WebMenuTarget validateMenuItem:]): Ditto.

(setMenuItemTarget): Sets the target of the NSMenuItem to the shared WebMenuTarget.
(setMenuTargets): Recursively iterates over all NSMenuItems in an NSMenu (including
    submenus), and calls setMenuItemTarget on them.
(-[WebHTMLView menuForEvent:]): Call setMenuTarget on all the menu items before adding
    them to the menu.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73469 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 61d6ee6c
2010-12-07 Brian Weinstein <bweinstein@apple.com>
Reviewed by John Sullivan.
Part of Layering Violation in ContextMenu
https://bugs.webkit.org/show_bug.cgi?id=50586
ContextMenuMac.mm had a WebCoreMenuTarget class, which was responsible for wrapping
a ContextMenuItem, and calling through to the ContextMenuController to validate it
and call a function when it was selected.
It was a layering violation to have this class here, because ContextMenu can't know
about ContextMenuController.
This patch moves the class that wraps the ContextMenuItems to WebKit/mac/WebHTMLView.mm,
and sets up the menu targets there.
No change in behavior, no new tests.
* WebCore.exp.in: Added function that needs to be exported.
* platform/mac/ContextMenuMac.mm:
(WebCore::ContextMenu::ContextMenu): Don't set the sharedMenuTarget anymore.
(WebCore::ContextMenu::appendItem): Don't call setMenuItemTarget (this is done in WebKit now).
(WebCore::ContextMenu::insertItem): Ditto.
2010-12-07 Simon Fraser <simon.fraser@apple.com>
Reviewed by Dan Bernstein.
......
......@@ -1249,6 +1249,7 @@ __ZN7WebCore15ContextMenuItem26releasePlatformDescriptionEv
__ZN7WebCore15ContextMenuItemC1ENS_17ContextMenuActionERKN3WTF6StringEbbRNS2_6VectorIS0_Lm0EEE
__ZN7WebCore15ContextMenuItemC1ENS_19ContextMenuItemTypeENS_17ContextMenuActionERKN3WTF6StringEPNS_11ContextMenuE
__ZN7WebCore15ContextMenuItemC1ENS_19ContextMenuItemTypeENS_17ContextMenuActionERKN3WTF6StringEbb
__ZN7WebCore15ContextMenuItemC1EP10NSMenuItem
__ZN7WebCore15ContextMenuItemD1Ev
__ZN7WebCore21ContextMenuController16clearContextMenuEv
__ZN7WebCore21ContextMenuController23contextMenuItemSelectedEPNS_15ContextMenuItemE
......
......@@ -28,55 +28,6 @@
#if ENABLE(CONTEXT_MENUS)
#include "ContextMenuController.h"
@interface WebCoreMenuTarget : NSObject {
WebCore::ContextMenuController* _menuController;
}
+ (WebCoreMenuTarget*)sharedMenuTarget;
- (WebCore::ContextMenuController*)menuController;
- (void)setMenuController:(WebCore::ContextMenuController*)menuController;
- (void)forwardContextMenuAction:(id)sender;
- (BOOL)validateMenuItem:(NSMenuItem *)item;
@end
static WebCoreMenuTarget* target;
@implementation WebCoreMenuTarget
+ (WebCoreMenuTarget*)sharedMenuTarget
{
if (!target)
target = [[WebCoreMenuTarget alloc] init];
return target;
}
- (WebCore::ContextMenuController*)menuController
{
return _menuController;
}
- (void)setMenuController:(WebCore::ContextMenuController*)menuController
{
_menuController = menuController;
}
- (void)forwardContextMenuAction:(id)sender
{
WebCore::ContextMenuItem item(WebCore::ActionType, static_cast<WebCore::ContextMenuAction>([sender tag]), [sender title]);
_menuController->contextMenuItemSelected(&item);
}
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
WebCore::ContextMenuItem coreItem(item);
ASSERT(_menuController->contextMenu());
_menuController->contextMenu()->checkOrEnableIfNeeded(coreItem);
return coreItem.enabled();
}
@end
namespace WebCore {
ContextMenu::ContextMenu(const HitTestResult& result)
......@@ -85,35 +36,23 @@ ContextMenu::ContextMenu(const HitTestResult& result)
NSMutableArray* array = [[NSMutableArray alloc] init];
m_platformDescription = array;
[array release];
[[WebCoreMenuTarget sharedMenuTarget] setMenuController:controller()];
}
ContextMenu::ContextMenu(const HitTestResult& result, const PlatformMenuDescription menu)
: m_hitTestResult(result)
, m_platformDescription(menu)
{
[[WebCoreMenuTarget sharedMenuTarget] setMenuController:controller()];
}
ContextMenu::~ContextMenu()
{
}
static void setMenuItemTarget(NSMenuItem* menuItem)
{
[menuItem setTarget:[WebCoreMenuTarget sharedMenuTarget]];
[menuItem setAction:@selector(forwardContextMenuAction:)];
}
void ContextMenu::appendItem(ContextMenuItem& item)
{
checkOrEnableIfNeeded(item);
ContextMenuItemType type = item.type();
NSMenuItem* platformItem = item.releasePlatformDescription();
if (type == ActionType)
setMenuItemTarget(platformItem);
[m_platformDescription.get() addObject:platformItem];
[platformItem release];
......@@ -123,10 +62,7 @@ void ContextMenu::insertItem(unsigned position, ContextMenuItem& item)
{
checkOrEnableIfNeeded(item);
ContextMenuItemType type = item.type();
NSMenuItem* platformItem = item.releasePlatformDescription();
if (type == ActionType)
setMenuItemTarget(platformItem);
[m_platformDescription.get() insertObject:platformItem atIndex:position];
[platformItem release];
......
2010-12-07 Brian Weinstein <bweinstein@apple.com>
Reviewed by John Sullivan.
Part of Layering Violation in ContextMenu
https://bugs.webkit.org/show_bug.cgi?id=50586
Move WebMenuTarget from ContextMenuMac to here, because having it in ContextMenuMac
was a layering violation. Also, make sure we set the menu item targets for all menu
items before showing them, because the ContextMenu constructor doesn't do that anymore.
* WebView/WebHTMLView.mm:
(+[WebMenuTarget sharedMenuTarget]): Moved from ContextMenuMac.mm.
(-[WebMenuTarget WebCore::]): Ditto.
(-[WebMenuTarget setMenuController:WebCore::]): Ditto.
(-[WebMenuTarget forwardContextMenuAction:]): Ditto.
(-[WebMenuTarget validateMenuItem:]): Ditto.
(setMenuItemTarget): Sets the target of the NSMenuItem to the shared WebMenuTarget.
(setMenuTargets): Recursively iterates over all NSMenuItems in an NSMenu (including
submenus), and calls setMenuItemTarget on them.
(-[WebHTMLView menuForEvent:]): Call setMenuTarget on all the menu items before adding
them to the menu.
2010-12-06 Darin Adler <darin@apple.com>
Reviewed by Sam Weinig.
......
......@@ -129,6 +129,53 @@ using namespace HTMLNames;
using namespace WTF;
using namespace std;
@interface WebMenuTarget : NSObject {
WebCore::ContextMenuController* _menuController;
}
+ (WebMenuTarget*)sharedMenuTarget;
- (WebCore::ContextMenuController*)menuController;
- (void)setMenuController:(WebCore::ContextMenuController*)menuController;
- (void)forwardContextMenuAction:(id)sender;
- (BOOL)validateMenuItem:(NSMenuItem *)item;
@end
static WebMenuTarget* target;
@implementation WebMenuTarget
+ (WebMenuTarget*)sharedMenuTarget
{
if (!target)
target = [[WebMenuTarget alloc] init];
return target;
}
- (WebCore::ContextMenuController*)menuController
{
return _menuController;
}
- (void)setMenuController:(WebCore::ContextMenuController*)menuController
{
_menuController = menuController;
}
- (void)forwardContextMenuAction:(id)sender
{
WebCore::ContextMenuItem item(WebCore::ActionType, static_cast<WebCore::ContextMenuAction>([sender tag]), [sender title]);
_menuController->contextMenuItemSelected(&item);
}
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
WebCore::ContextMenuItem coreItem(item);
ASSERT(_menuController->contextMenu());
_menuController->contextMenu()->checkOrEnableIfNeeded(coreItem);
return coreItem.enabled();
}
@end
@interface NSWindow (BorderViewAccess)
- (NSView*)_web_borderView;
@end
......@@ -3223,6 +3270,23 @@ WEBCORE_COMMAND(yankAndSelect)
coreframe->eventHandler()->mouseUp(event);
}
static void setMenuItemTarget(NSMenuItem* menuItem)
{
[menuItem setTarget:[WebMenuTarget sharedMenuTarget]];
[menuItem setAction:@selector(forwardContextMenuAction:)];
}
static void setMenuTargets(NSMenu* menu)
{
NSInteger itemCount = [menu numberOfItems];
for (NSInteger i = 0; i < itemCount; ++i) {
NSMenuItem *item = [menu itemAtIndex:i];
setMenuItemTarget(item);
if ([item hasSubmenu])
setMenuTargets([item submenu]);
}
}
- (NSMenu *)menuForEvent:(NSEvent *)event
{
// There's a chance that if we run a nested event loop the event will be released.
......@@ -3270,6 +3334,10 @@ WEBCORE_COMMAND(yankAndSelect)
NSMenu* menu = [[[NSMenu alloc] init] autorelease];
for (NSUInteger i = 0; i < count; i++)
[menu addItem:[menuItems objectAtIndex:i]];
setMenuTargets(menu);
[[WebMenuTarget sharedMenuTarget] setMenuController:page->contextMenuController()];
return menu;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment