OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
12 #import "chrome/browser/ui/cocoa/menu_controller.h" | 13 #import "chrome/browser/ui/cocoa/menu_controller.h" |
13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
14 | 15 |
15 // Obj-C bridge class that is the target of all items in the context menu. | 16 // Obj-C bridge class that is the target of all items in the context menu. |
16 // Relies on the tag being set to the command id. | 17 // Relies on the tag being set to the command id. |
17 | 18 |
18 RenderViewContextMenuMac::RenderViewContextMenuMac( | 19 RenderViewContextMenuMac::RenderViewContextMenuMac( |
19 TabContents* web_contents, | 20 TabContents* web_contents, |
20 const ContextMenuParams& params, | 21 const ContextMenuParams& params, |
21 NSView* parent_view) | 22 NSView* parent_view) |
(...skipping 30 matching lines...) Expand all Loading... |
52 // Make sure events can be pumped while the menu is up. | 53 // Make sure events can be pumped while the menu is up. |
53 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 54 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
54 | 55 |
55 // Show the menu. | 56 // Show the menu. |
56 [NSMenu popUpContextMenu:[menuController_ menu] | 57 [NSMenu popUpContextMenu:[menuController_ menu] |
57 withEvent:clickEvent | 58 withEvent:clickEvent |
58 forView:parent_view_]; | 59 forView:parent_view_]; |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
| 63 void RenderViewContextMenuMac::ExecuteCommand(int id) { |
| 64 [[[parent_view_ window] windowController] commitInstant]; |
| 65 RenderViewContextMenu::ExecuteCommand(id); |
| 66 } |
| 67 |
62 bool RenderViewContextMenuMac::GetAcceleratorForCommandId( | 68 bool RenderViewContextMenuMac::GetAcceleratorForCommandId( |
63 int command_id, | 69 int command_id, |
64 ui::Accelerator* accelerator) { | 70 ui::Accelerator* accelerator) { |
65 return false; | 71 return false; |
66 } | 72 } |
67 | 73 |
68 void RenderViewContextMenuMac::InitPlatformMenu() { | 74 void RenderViewContextMenuMac::InitPlatformMenu() { |
69 bool has_selection = !params_.selection_text.empty(); | 75 bool has_selection = !params_.selection_text.empty(); |
70 | 76 |
71 if (has_selection) { | 77 if (has_selection) { |
(...skipping 12 matching lines...) Expand all Loading... |
84 NSString* text = base::SysUTF16ToNSString(params_.selection_text); | 90 NSString* text = base::SysUTF16ToNSString(params_.selection_text); |
85 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName]; | 91 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName]; |
86 // 10.5 and earlier require declareTypes before setData. | 92 // 10.5 and earlier require declareTypes before setData. |
87 // See the documentation on [NSPasteboard declareTypes]. | 93 // See the documentation on [NSPasteboard declareTypes]. |
88 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; | 94 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; |
89 [pboard declareTypes:toDeclare owner:nil]; | 95 [pboard declareTypes:toDeclare owner:nil]; |
90 BOOL ok = [pboard setString:text forType:NSStringPboardType]; | 96 BOOL ok = [pboard setString:text forType:NSStringPboardType]; |
91 if (ok) | 97 if (ok) |
92 NSPerformService(@"Look Up in Dictionary", pboard); | 98 NSPerformService(@"Look Up in Dictionary", pboard); |
93 } | 99 } |
OLD | NEW |