Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" | 5 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 [submenu removeItemAtIndex:index]; | 68 [submenu removeItemAtIndex:index]; |
| 69 | 69 |
| 70 if (!remove_following_separator || index == [submenu numberOfItems]) | 70 if (!remove_following_separator || index == [submenu numberOfItems]) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 NSMenuItem* nextItem = [submenu itemAtIndex:index]; | 73 NSMenuItem* nextItem = [submenu itemAtIndex:index]; |
| 74 if ([nextItem isSeparatorItem]) | 74 if ([nextItem isSeparatorItem]) |
| 75 [submenu removeItem:nextItem]; | 75 [submenu removeItem:nextItem]; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void HideMenuItemWithTag(NSMenuItem* top_level_item, | |
| 79 NSInteger item_tag, | |
| 80 bool hidden) { | |
| 81 NSMenu* submenu = [top_level_item submenu]; | |
| 82 NSMenuItem* menuItem = [submenu itemWithTag:item_tag]; | |
| 83 NSInteger nextIndex = [submenu indexOfItem:menuItem] + 1; | |
| 84 | |
| 85 // If no menu item proceeds the current one, then hide it and return. | |
| 86 if (nextIndex >= [submenu numberOfItems]) { | |
| 87 [menuItem setHidden:hidden]; | |
| 88 return; | |
| 89 } | |
| 90 | |
| 91 NSMenuItem* nextMenuItem = [submenu itemAtIndex:nextIndex]; | |
| 92 if ([nextMenuItem isAlternate]) { | |
|
tapted
2015/01/27 01:40:57
Maybe http://stackoverflow.com/questions/11494509/
| |
| 93 [nextMenuItem setAlternate:!hidden]; | |
| 94 [nextMenuItem setHidden:hidden]; | |
| 95 } | |
| 96 | |
| 97 [menuItem setHidden:hidden]; | |
| 98 } | |
| 99 | |
| 78 } // namespace | 100 } // namespace |
| 79 | 101 |
| 80 // Used by AppShimMenuController to manage menu items that are a copy of a | 102 // Used by AppShimMenuController to manage menu items that are a copy of a |
| 81 // Chrome menu item but with a different action. This manages unsetting and | 103 // Chrome menu item but with a different action. This manages unsetting and |
| 82 // restoring the original item's key equivalent, so that we can use the same | 104 // restoring the original item's key equivalent, so that we can use the same |
| 83 // key equivalent in the copied item with a different action. If |resourceId_| | 105 // key equivalent in the copied item with a different action. If |resourceId_| |
| 84 // is non-zero, this will also update the title to include the app name. | 106 // is non-zero, this will also update the title to include the app name. |
| 85 // If the copy (menuItem) has no key equivalent, and the title does not have the | 107 // If the copy (menuItem) has no key equivalent, and the title does not have the |
| 86 // app name, then enableForApp and disable do not need to be called. I.e. the | 108 // app name, then enableForApp and disable do not need to be called. I.e. the |
| 87 // doppelganger just copies the item and sets a new action. | 109 // doppelganger just copies the item and sets a new action. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW); | 285 AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW); |
| 264 // Set the expected key equivalent explicitly here because | 286 // Set the expected key equivalent explicitly here because |
| 265 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to | 287 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to |
| 266 // "W" (Cmd+Shift+w) when a tabbed window has focus; it will change it back | 288 // "W" (Cmd+Shift+w) when a tabbed window has focus; it will change it back |
| 267 // to Cmd+w when a non-tabbed window has focus. | 289 // to Cmd+w when a non-tabbed window has focus. |
| 268 NSMenuItem* closeWindowMenuItem = | 290 NSMenuItem* closeWindowMenuItem = |
| 269 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; | 291 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; |
| 270 [closeWindowMenuItem setKeyEquivalent:@"w"]; | 292 [closeWindowMenuItem setKeyEquivalent:@"w"]; |
| 271 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; | 293 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; |
| 272 | 294 |
| 273 // Edit menu. This copies the menu entirely and removes | 295 // Edit menu. We copy the menu because the last two items, "Start Dictation" |
| 274 // "Paste and Match Style" and "Find". This is because the last two items, | 296 // and "Special Characters" are added by OSX, so we can't copy them |
| 275 // "Start Dictation" and "Special Characters" are added by OSX, so we can't | 297 // explicitly. |
| 276 // copy them explicitly. | |
| 277 editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); | 298 editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); |
| 278 RemoveMenuItemWithTag(editMenuItem_, | |
| 279 IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, NO); | |
| 280 RemoveMenuItemWithTag(editMenuItem_, IDC_FIND_MENU, NO); | |
| 281 | 299 |
| 282 // View menu. Remove "Always Show Bookmark Bar" and separator. | 300 // View menu. Remove "Always Show Bookmark Bar" and separator. |
| 283 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); | 301 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); |
| 284 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); | 302 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); |
| 285 | 303 |
| 286 // History menu. | 304 // History menu. |
| 287 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); | 305 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); |
| 288 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); | 306 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); |
| 289 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); | 307 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); |
| 290 | 308 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 [hideDoppelganger_ enableForApp:app]; | 390 [hideDoppelganger_ enableForApp:app]; |
| 373 [quitDoppelganger_ enableForApp:app]; | 391 [quitDoppelganger_ enableForApp:app]; |
| 374 [newDoppelganger_ enableForApp:app]; | 392 [newDoppelganger_ enableForApp:app]; |
| 375 [openDoppelganger_ enableForApp:app]; | 393 [openDoppelganger_ enableForApp:app]; |
| 376 | 394 |
| 377 [appMenuItem_ setTitle:appId]; | 395 [appMenuItem_ setTitle:appId]; |
| 378 [[appMenuItem_ submenu] setTitle:title]; | 396 [[appMenuItem_ submenu] setTitle:title]; |
| 379 | 397 |
| 380 [mainMenu addItem:appMenuItem_]; | 398 [mainMenu addItem:appMenuItem_]; |
| 381 [mainMenu addItem:fileMenuItem_]; | 399 [mainMenu addItem:fileMenuItem_]; |
| 400 | |
| 401 // Hide the "Paste and Match Style" and "Find" menu items for non-hosted | |
| 402 // apps from the Edit menu. | |
| 403 if (!app->is_hosted_app()) { | |
| 404 HideMenuItemWithTag(editMenuItem_, | |
| 405 IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, YES); | |
| 406 HideMenuItemWithTag(editMenuItem_, IDC_FIND_MENU, YES); | |
| 407 } else { | |
| 408 HideMenuItemWithTag(editMenuItem_, | |
| 409 IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, NO); | |
| 410 HideMenuItemWithTag(editMenuItem_, IDC_FIND_MENU, NO); | |
| 411 } | |
| 382 [mainMenu addItem:editMenuItem_]; | 412 [mainMenu addItem:editMenuItem_]; |
| 413 | |
| 383 if (app->is_hosted_app()) { | 414 if (app->is_hosted_app()) { |
| 384 [mainMenu addItem:viewMenuItem_]; | 415 [mainMenu addItem:viewMenuItem_]; |
| 385 [mainMenu addItem:historyMenuItem_]; | 416 [mainMenu addItem:historyMenuItem_]; |
| 386 } | 417 } |
| 387 [mainMenu addItem:windowMenuItem_]; | 418 [mainMenu addItem:windowMenuItem_]; |
| 388 } | 419 } |
| 389 | 420 |
| 390 - (void)removeMenuItems { | 421 - (void)removeMenuItems { |
| 391 if (!appId_) | 422 if (!appId_) |
| 392 return; | 423 return; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 | 479 |
| 449 - (void)focusCurrentPlatformApp { | 480 - (void)focusCurrentPlatformApp { |
| 450 extensions::AppWindow* appWindow = | 481 extensions::AppWindow* appWindow = |
| 451 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 482 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 452 [NSApp keyWindow]); | 483 [NSApp keyWindow]); |
| 453 if (appWindow) | 484 if (appWindow) |
| 454 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); | 485 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); |
| 455 } | 486 } |
| 456 | 487 |
| 457 @end | 488 @end |
| OLD | NEW |