| 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 #import "base/mac/scoped_sending_event.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 9 #include "base/memory/scoped_nsobject.h" |
| 9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 10 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/menu_controller.h" | 14 #import "chrome/browser/ui/cocoa/menu_controller.h" |
| 14 #import "content/common/mac/scoped_sending_event.h" | |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Retrieves an NSMenuItem which has the specified command_id. This function | 19 // Retrieves an NSMenuItem which has the specified command_id. This function |
| 20 // traverses the given |model| in the depth-first order. When this function | 20 // traverses the given |model| in the depth-first order. When this function |
| 21 // finds an item whose command_id is the same as the given |command_id|, it | 21 // finds an item whose command_id is the same as the given |command_id|, it |
| 22 // returns the NSMenuItem associated with the item. This function emulates | 22 // returns the NSMenuItem associated with the item. This function emulates |
| 23 // views::MenuItemViews::GetMenuItemByID() for Mac. | 23 // views::MenuItemViews::GetMenuItemByID() for Mac. |
| 24 NSMenuItem* GetMenuItemByID(ui::MenuModel* model, | 24 NSMenuItem* GetMenuItemByID(ui::MenuModel* model, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 { | 82 { |
| 83 // Make sure events can be pumped while the menu is up. | 83 // Make sure events can be pumped while the menu is up. |
| 84 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 84 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 85 | 85 |
| 86 // One of the events that could be pumped is |window.close()|. | 86 // One of the events that could be pumped is |window.close()|. |
| 87 // User-initiated event-tracking loops protect against this by | 87 // User-initiated event-tracking loops protect against this by |
| 88 // setting flags in -[CrApplication sendEvent:], but since | 88 // setting flags in -[CrApplication sendEvent:], but since |
| 89 // web-content menus are initiated by IPC message the setup has to | 89 // web-content menus are initiated by IPC message the setup has to |
| 90 // be done manually. | 90 // be done manually. |
| 91 content::mac::ScopedSendingEvent sendingEventScoper; | 91 base::mac::ScopedSendingEvent sendingEventScoper; |
| 92 | 92 |
| 93 // Show the menu. | 93 // Show the menu. |
| 94 [NSMenu popUpContextMenu:[menuController_ menu] | 94 [NSMenu popUpContextMenu:[menuController_ menu] |
| 95 withEvent:clickEvent | 95 withEvent:clickEvent |
| 96 forView:parent_view_]; | 96 forView:parent_view_]; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void RenderViewContextMenuMac::ExecuteCommand(int id) { | 100 void RenderViewContextMenuMac::ExecuteCommand(int id) { |
| 101 // Auxiliary windows that do not have address bars (Panels for example) | 101 // Auxiliary windows that do not have address bars (Panels for example) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 command_id); | 149 command_id); |
| 150 if (!item) | 150 if (!item) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 // Update the returned NSMenuItem directly so we can update it immediately. | 153 // Update the returned NSMenuItem directly so we can update it immediately. |
| 154 [item setEnabled:enabled]; | 154 [item setEnabled:enabled]; |
| 155 [item setTitle:SysUTF16ToNSString(title)]; | 155 [item setTitle:SysUTF16ToNSString(title)]; |
| 156 [item setHidden:hidden]; | 156 [item setHidden:hidden]; |
| 157 [[item menu] itemChanged:item]; | 157 [[item menu] itemChanged:item]; |
| 158 } | 158 } |
| OLD | NEW |