+2006-12-04 Beth Dakin <bdakin@apple.com>
+
+ Reviewed by Geoff.
+
+ With the new changes to ContextMenuItems, WebCore context menus
+ stopped appearing at all. And then when I got them to appear, they
+ crashed. This fixes both of these problems.
+
+ * platform/mac/ContextMenuItemMac.mm:
+ (WebCore::ContextMenuItem::ContextMenuItem): keyEquivalent cannot
+ be nil. This was causing Obj-C to throw an exception preventing the
+ menus from popping up at all.
+ * platform/mac/ContextMenuMac.mm:
+ (+[WebCoreMenuTarget sharedMenuTarget]): Re-name our static
+ MenuTarget so that it is more clear that it is a static and shared
+ WebCoreMenuTarget.
+ (WebCore::ContextMenu::ContextMenu): Initialize the
+ WebCoreMenuTarget's controller in the ContextMenu constructor
+ instead of in getNSMenuItem since the controller will only possibly
+ change when a new ContextMenu has been created.
+ (WebCore::ContextMenu::~ContextMenu): Set the target's controller
+ to 0.
+ (WebCore::getNSMenuItem): A lot of this work is being done other
+ places now. Call new class method on WebCoreMenuTarget to get the
+ shared target.
+ (WebCore::ContextMenu::appendItem): We should not be releasing the
+ menuItem here! This caused the crashes I saw.
+ (WebCore::ContextMenu::insertItem): Same.
+
2006-12-04 Anders Carlsson <acarlsson@apple.com>
Fix the build.
#include "ContextMenu.h"
#include "ContextMenuController.h"
-
-@interface MenuTarget : NSObject {
+
+@interface WebCoreMenuTarget : NSObject {
WebCore::ContextMenuController* _menuController;
}
++ (WebCoreMenuTarget*)sharedMenuTarget;
- (WebCore::ContextMenuController*)menuController;
- (void)setMenuController:(WebCore::ContextMenuController*)menuController;
- (void)forwardContextMenuAction:(id)sender;
@end
-@implementation MenuTarget
+static WebCoreMenuTarget* target;
+
+@implementation WebCoreMenuTarget
-- (id)initWithContextMenuController:(WebCore::ContextMenuController*)menuController
++ (WebCoreMenuTarget*)sharedMenuTarget
{
- self = [super init];
- if (!self)
- return nil;
-
- _menuController = menuController;
- return self;
+ if (!target)
+ target = [[WebCoreMenuTarget alloc] init];
+ return target;
}
- (WebCore::ContextMenuController*)menuController
namespace WebCore {
-static MenuTarget* target;
-
ContextMenu::ContextMenu(const HitTestResult& result)
: m_hitTestResult(result)
{
NSMutableArray* array = [[NSMutableArray alloc] init];
m_platformDescription = array;
- [array release];
+ [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()
{
+ [[WebCoreMenuTarget sharedMenuTarget] setMenuController:0];
}
static NSMenuItem* getNSMenuItem(ContextMenu* menu, const ContextMenuItem& item)
if (!menu->platformDescription())
return 0;
- ContextMenuController* currentController = menu->controller();
- if (!target)
- target = [[MenuTarget alloc] initWithContextMenuController:currentController];
- else if (currentController != [target menuController])
- [target setMenuController:currentController];
-
NSMenuItem* menuItem = item.platformDescription();
if (item.type() == ActionType) {
- [menuItem setTarget:target];
+ [menuItem setTarget:[WebCoreMenuTarget sharedMenuTarget]];
[menuItem setAction:@selector(forwardContextMenuAction:)];
}
NSMenuItem* menuItem = getNSMenuItem(this, item);
if (!menuItem)
return;
-
[m_platformDescription.get() addObject:menuItem];
- [menuItem release];
}
void ContextMenu::insertItem(unsigned position, const ContextMenuItem& item)
NSMenuItem* menuItem = getNSMenuItem(this, item);
if (!menuItem)
return;
-
[m_platformDescription.get() insertObject:menuItem atIndex:position];
- [menuItem release];
}
unsigned ContextMenu::itemCount() const