blob: 42fe061a4c2851320e7ec56644b7be5bfc11c2ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/menu_controller.h"
// Obj-C bridge class that is the target of all items in the context menu.
// Relies on the tag being set to the command id.
RenderViewContextMenuMac::RenderViewContextMenuMac(
TabContents* web_contents,
const ContextMenuParams& params,
NSView* parent_view)
: RenderViewContextMenu(web_contents, params),
parent_view_(parent_view) {
}
RenderViewContextMenuMac::~RenderViewContextMenuMac() {
}
void RenderViewContextMenuMac::PlatformInit() {
menuController_.reset(
[[MenuController alloc] initWithModel:&menu_model_
useWithPopUpButtonCell:NO]);
// Synthesize an event for the click, as there is no certainty that
// [NSApp currentEvent] will return a valid event.
NSEvent* currentEvent = [NSApp currentEvent];
NSWindow* window = [parent_view_ window];
NSPoint position = [window mouseLocationOutsideOfEventStream];
NSTimeInterval eventTime = [currentEvent timestamp];
NSEvent* clickEvent = [NSEvent mouseEventWithType:NSRightMouseDown
location:position
modifierFlags:NSRightMouseDownMask
timestamp:eventTime
windowNumber:[window windowNumber]
context:nil
eventNumber:0
clickCount:1
pressure:1.0];
{
// Make sure events can be pumped while the menu is up.
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
// Show the menu.
[NSMenu popUpContextMenu:[menuController_ menu]
withEvent:clickEvent
forView:parent_view_];
}
}
|