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 // If |has_alternate| is true, the item immediately following |item_tag| is | |
tapted
2015/01/30 03:06:22
keep the `// Sets the menu item with |item_tag| in
mitchellj
2015/01/30 03:24:29
Done.
| |
79 // assumed to be its (only) alternate. Since AppKit is unable to hide items | |
80 // with alternates, |has_alternate| will cause -[NSMenuItem alternate] to be | |
81 // removed when hiding and restored when showing. | |
82 void SetItemWithTagVisible(NSMenuItem* top_level_item, | |
83 NSInteger item_tag, | |
84 bool visible, | |
85 bool has_alternate) { | |
86 NSMenu* submenu = [top_level_item submenu]; | |
87 NSMenuItem* menu_item = [submenu itemWithTag:item_tag]; | |
88 DCHECK(menu_item); | |
89 | |
90 if (!has_alternate) { | |
91 [menu_item setHidden:!visible]; | |
92 return; | |
93 } | |
94 | |
95 NSInteger next_index = [submenu indexOfItem:menu_item] + 1; | |
96 DCHECK_LT(next_index, [submenu numberOfItems]); | |
97 | |
98 NSMenuItem* next_menu_item = [submenu itemAtIndex:next_index]; | |
tapted
2015/01/30 03:06:22
nit: next_menu_item -> alternate_item is probably
mitchellj
2015/01/30 03:24:29
Done.
| |
99 [next_menu_item setAlternate:visible]; | |
100 [next_menu_item setHidden:!visible]; | |
101 [menu_item setHidden:!visible]; | |
102 } | |
103 | |
78 } // namespace | 104 } // namespace |
79 | 105 |
80 // Used by AppShimMenuController to manage menu items that are a copy of a | 106 // 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 | 107 // 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 | 108 // 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_| | 109 // 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. | 110 // 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 | 111 // 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 | 112 // 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. | 113 // 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); | 289 AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW); |
264 // Set the expected key equivalent explicitly here because | 290 // Set the expected key equivalent explicitly here because |
265 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to | 291 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to |
266 // "W" (Cmd+Shift+w) when a tabbed window has focus; it will change it back | 292 // "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. | 293 // to Cmd+w when a non-tabbed window has focus. |
268 NSMenuItem* closeWindowMenuItem = | 294 NSMenuItem* closeWindowMenuItem = |
269 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; | 295 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; |
270 [closeWindowMenuItem setKeyEquivalent:@"w"]; | 296 [closeWindowMenuItem setKeyEquivalent:@"w"]; |
271 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; | 297 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; |
272 | 298 |
273 // Edit menu. This copies the menu entirely and removes | 299 // 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, | 300 // 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 | 301 // explicitly. |
276 // copy them explicitly. | |
277 editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); | 302 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 | 303 |
282 // View menu. Remove "Always Show Bookmark Bar" and separator. | 304 // View menu. Remove "Always Show Bookmark Bar" and separator. |
283 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); | 305 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); |
284 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); | 306 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); |
285 | 307 |
286 // History menu. | 308 // History menu. |
287 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); | 309 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); |
288 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); | 310 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); |
289 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); | 311 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); |
290 | 312 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 [hideDoppelganger_ enableForApp:app]; | 394 [hideDoppelganger_ enableForApp:app]; |
373 [quitDoppelganger_ enableForApp:app]; | 395 [quitDoppelganger_ enableForApp:app]; |
374 [newDoppelganger_ enableForApp:app]; | 396 [newDoppelganger_ enableForApp:app]; |
375 [openDoppelganger_ enableForApp:app]; | 397 [openDoppelganger_ enableForApp:app]; |
376 | 398 |
377 [appMenuItem_ setTitle:appId]; | 399 [appMenuItem_ setTitle:appId]; |
378 [[appMenuItem_ submenu] setTitle:title]; | 400 [[appMenuItem_ submenu] setTitle:title]; |
379 | 401 |
380 [mainMenu addItem:appMenuItem_]; | 402 [mainMenu addItem:appMenuItem_]; |
381 [mainMenu addItem:fileMenuItem_]; | 403 [mainMenu addItem:fileMenuItem_]; |
404 | |
405 if (!app->is_hosted_app()) { | |
406 SetItemWithTagVisible(editMenuItem_, | |
407 IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, | |
408 app->is_hosted_app(), true); | |
409 SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, app->is_hosted_app(), | |
410 false); | |
411 } else { | |
tapted
2015/01/30 03:06:22
this `else` is now identical to the non-else -> no
mitchellj
2015/01/30 03:24:29
Oops, you're right.
| |
412 SetItemWithTagVisible(editMenuItem_, | |
413 IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, | |
414 app->is_hosted_app(), true); | |
415 SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, app->is_hosted_app(), | |
416 false); | |
417 } | |
382 [mainMenu addItem:editMenuItem_]; | 418 [mainMenu addItem:editMenuItem_]; |
419 | |
383 if (app->is_hosted_app()) { | 420 if (app->is_hosted_app()) { |
384 [mainMenu addItem:viewMenuItem_]; | 421 [mainMenu addItem:viewMenuItem_]; |
385 [mainMenu addItem:historyMenuItem_]; | 422 [mainMenu addItem:historyMenuItem_]; |
386 } | 423 } |
387 [mainMenu addItem:windowMenuItem_]; | 424 [mainMenu addItem:windowMenuItem_]; |
388 } | 425 } |
389 | 426 |
390 - (void)removeMenuItems { | 427 - (void)removeMenuItems { |
391 if (!appId_) | 428 if (!appId_) |
392 return; | 429 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 | 485 |
449 - (void)focusCurrentPlatformApp { | 486 - (void)focusCurrentPlatformApp { |
450 extensions::AppWindow* appWindow = | 487 extensions::AppWindow* appWindow = |
451 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 488 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
452 [NSApp keyWindow]); | 489 [NSApp keyWindow]); |
453 if (appWindow) | 490 if (appWindow) |
454 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); | 491 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); |
455 } | 492 } |
456 | 493 |
457 @end | 494 @end |
OLD | NEW |