| Index: ui/views/controls/menu/menu_runner_impl_cocoa.mm
|
| diff --git a/ui/views/controls/menu/menu_runner_impl_cocoa.mm b/ui/views/controls/menu/menu_runner_impl_cocoa.mm
|
| index 02d6a95faedd333d822d5c28abb0ab1d9982a5e3..316de4df23b08e63b160b9e8c1a0004a6b445022 100644
|
| --- a/ui/views/controls/menu/menu_runner_impl_cocoa.mm
|
| +++ b/ui/views/controls/menu/menu_runner_impl_cocoa.mm
|
| @@ -5,6 +5,7 @@
|
| #import "ui/views/controls/menu/menu_runner_impl_cocoa.h"
|
|
|
| #include "base/mac/sdk_forward_declarations.h"
|
| +#import "ui/base/cocoa/cocoa_base_utils.h"
|
| #import "ui/base/cocoa/menu_controller.h"
|
| #include "ui/base/models/menu_model.h"
|
| #include "ui/events/base_event_utils.h"
|
| @@ -79,6 +80,36 @@ base::scoped_nsobject<NSView> CreateMenuAnchorView(
|
| return anchor_view;
|
| }
|
|
|
| +// Returns an appropriate event (with a location) suitable for showing a context
|
| +// menu. Uses [NSApp currentEvent] if it's a non-nil mouse click event,
|
| +// otherwise creates an autoreleased dummy event located at |anchor|.
|
| +NSEvent* EventForPositioningContextMenu(const gfx::Rect& anchor,
|
| + NSWindow* window) {
|
| + NSEvent* event = [NSApp currentEvent];
|
| + switch ([event type]) {
|
| + case NSLeftMouseDown:
|
| + case NSLeftMouseUp:
|
| + case NSRightMouseDown:
|
| + case NSRightMouseUp:
|
| + case NSOtherMouseDown:
|
| + case NSOtherMouseUp:
|
| + return event;
|
| + default:
|
| + break;
|
| + }
|
| + NSPoint location_in_window = ui::ConvertPointFromScreenToWindow(
|
| + window, gfx::ScreenPointToNSPoint(anchor.CenterPoint()));
|
| + return [NSEvent mouseEventWithType:NSRightMouseDown
|
| + location:location_in_window
|
| + modifierFlags:0
|
| + timestamp:0
|
| + windowNumber:[window windowNumber]
|
| + context:nil
|
| + eventNumber:0
|
| + clickCount:1
|
| + pressure:0];
|
| +}
|
| +
|
| } // namespace
|
|
|
| // static
|
| @@ -133,14 +164,15 @@ void MenuRunnerImplCocoa::RunMenuAt(Widget* parent,
|
| closing_event_time_ = base::TimeTicks();
|
| running_ = true;
|
|
|
| + NSWindow* window = parent->GetNativeWindow();
|
| if (run_types & MenuRunner::CONTEXT_MENU) {
|
| [NSMenu popUpContextMenu:[menu_controller_ menu]
|
| - withEvent:[NSApp currentEvent]
|
| + withEvent:EventForPositioningContextMenu(bounds, window)
|
| forView:parent->GetNativeView()];
|
| } else if (run_types & MenuRunner::COMBOBOX) {
|
| NSMenuItem* checked_item = FirstCheckedItem(menu_controller_);
|
| base::scoped_nsobject<NSView> anchor_view(
|
| - CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item));
|
| + CreateMenuAnchorView(window, bounds, checked_item));
|
| NSMenu* menu = [menu_controller_ menu];
|
| [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth];
|
| [menu popUpMenuPositioningItem:checked_item
|
|
|