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 HideMenuItemWithIndex(NSMenuItem* top_level_item, | |
|
tapted
2015/01/29 05:13:37
Comment for this function - e.g. it's a bit subtle
tapted
2015/01/29 05:13:37
Since it both hides and shows, a better name would
mitchellj
2015/01/30 00:06:57
Done.
| |
| 79 NSInteger index, | |
|
tapted
2015/01/29 05:13:37
could you use WithTag instead? combined with has_a
mitchellj
2015/01/30 00:06:57
Done.
| |
| 80 bool hidden, | |
| 81 bool isAlternateMenuItem) { | |
|
tapted
2015/01/29 05:13:37
since this isn't an Objective C method, use hacker
mitchellj
2015/01/30 00:06:57
Done.
| |
| 82 NSMenu* submenu = [top_level_item submenu]; | |
| 83 if (index >= [submenu numberOfItems]) | |
|
tapted
2015/01/29 05:13:37
if this ever hit? DCHECK instead?
mitchellj
2015/01/30 00:06:57
This is now checked, as we are grabbing the next m
| |
| 84 return; | |
| 85 | |
| 86 NSMenuItem* menuItem = [submenu itemAtIndex:index]; | |
| 87 if (isAlternateMenuItem) | |
| 88 [menuItem setAlternate:!hidden]; | |
| 89 [menuItem setHidden:hidden]; | |
| 90 } | |
| 91 | |
| 78 } // namespace | 92 } // namespace |
| 79 | 93 |
| 80 // Used by AppShimMenuController to manage menu items that are a copy of a | 94 // 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 | 95 // 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 | 96 // 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_| | 97 // 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. | 98 // 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 | 99 // 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 | 100 // 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. | 101 // 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); | 277 AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW); |
| 264 // Set the expected key equivalent explicitly here because | 278 // Set the expected key equivalent explicitly here because |
| 265 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to | 279 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to |
| 266 // "W" (Cmd+Shift+w) when a tabbed window has focus; it will change it back | 280 // "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. | 281 // to Cmd+w when a non-tabbed window has focus. |
| 268 NSMenuItem* closeWindowMenuItem = | 282 NSMenuItem* closeWindowMenuItem = |
| 269 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; | 283 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; |
| 270 [closeWindowMenuItem setKeyEquivalent:@"w"]; | 284 [closeWindowMenuItem setKeyEquivalent:@"w"]; |
| 271 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; | 285 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; |
| 272 | 286 |
| 273 // Edit menu. This copies the menu entirely and removes | 287 // 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, | 288 // 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 | 289 // explicitly. |
| 276 // copy them explicitly. | |
| 277 editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); | 290 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 | 291 |
| 282 // View menu. Remove "Always Show Bookmark Bar" and separator. | 292 // View menu. Remove "Always Show Bookmark Bar" and separator. |
| 283 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); | 293 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); |
| 284 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); | 294 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); |
| 285 | 295 |
| 286 // History menu. | 296 // History menu. |
| 287 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); | 297 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); |
| 288 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); | 298 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); |
| 289 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); | 299 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); |
| 290 | 300 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 [hideDoppelganger_ enableForApp:app]; | 382 [hideDoppelganger_ enableForApp:app]; |
| 373 [quitDoppelganger_ enableForApp:app]; | 383 [quitDoppelganger_ enableForApp:app]; |
| 374 [newDoppelganger_ enableForApp:app]; | 384 [newDoppelganger_ enableForApp:app]; |
| 375 [openDoppelganger_ enableForApp:app]; | 385 [openDoppelganger_ enableForApp:app]; |
| 376 | 386 |
| 377 [appMenuItem_ setTitle:appId]; | 387 [appMenuItem_ setTitle:appId]; |
| 378 [[appMenuItem_ submenu] setTitle:title]; | 388 [[appMenuItem_ submenu] setTitle:title]; |
| 379 | 389 |
| 380 [mainMenu addItem:appMenuItem_]; | 390 [mainMenu addItem:appMenuItem_]; |
| 381 [mainMenu addItem:fileMenuItem_]; | 391 [mainMenu addItem:fileMenuItem_]; |
| 392 | |
| 393 // Hide the "Paste and Match Style" and "Find" menu items for non-hosted | |
| 394 // apps from the Edit menu. | |
| 395 NSInteger pasteMatchStyleindex = [[editMenuItem_ submenu] | |
|
tapted
2015/01/29 05:13:37
index -> Index
mitchellj
2015/01/30 00:06:57
Done.
| |
| 396 indexOfItemWithTag:IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE]; | |
| 397 if (!app->is_hosted_app()) { | |
| 398 // We need to hide the alternate menu item to "Patch and Match Style" | |
|
tapted
2015/01/29 05:13:37
I'd say this more like
// AppKit requires that al
mitchellj
2015/01/30 00:06:57
Done. Moved this comment to the new function SetIt
| |
| 399 // first. | |
| 400 HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex + 1, YES, YES); | |
|
tapted
2015/01/29 05:13:37
since they are being passed to bool (not BOOL) use
mitchellj
2015/01/30 00:06:57
Done.
| |
| 401 HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex, YES, NO); | |
| 402 HideMenuItemWithIndex( | |
| 403 editMenuItem_, | |
| 404 [[editMenuItem_ submenu] indexOfItemWithTag:IDC_FIND_MENU], YES, NO); | |
|
tapted
2015/01/29 05:13:37
nit: make a temporary for this, same as pasteMatch
mitchellj
2015/01/30 00:06:57
Done.
| |
| 405 } else { | |
| 406 HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex + 1, NO, YES); | |
| 407 HideMenuItemWithIndex(editMenuItem_, pasteMatchStyleindex, NO, NO); | |
| 408 HideMenuItemWithIndex( | |
| 409 editMenuItem_, | |
| 410 [[editMenuItem_ submenu] indexOfItemWithTag:IDC_FIND_MENU], NO, 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 |