Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Side by Side Diff: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm

Issue 864153003: Added 'Find'/'Paste and Match Style' menu items for hosted apps on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Sets the menu item with |item_tag| in |top_level_item| visible.
79 // Assumes that the menu item only has exactly one alternate, since AppKit
tapted 2015/01/30 00:52:48 I think it needs to say If |has_alternate| is tru
mitchellj 2015/01/30 02:53:38 Done.
80 // requires that alternate menu items are hidden first.
81 void SetItemWithTagVisible(NSMenuItem* top_level_item,
82 NSInteger item_tag,
83 bool visible,
84 bool has_alternate) {
85 NSMenu* submenu = [top_level_item submenu];
86 NSMenuItem* menuItem = [submenu itemWithTag:item_tag];
tapted 2015/01/30 00:52:48 itemWithTag returns `nil` if the tag isn't found.
tapted 2015/01/30 00:52:48 Since it's not an objective-C method, hacker_style
mitchellj 2015/01/30 02:53:38 Done.
mitchellj 2015/01/30 02:53:38 Done.
87 NSInteger nextIndex = [submenu indexOfItem:menuItem] + 1;
88
89 // If no menu item follows the current one, then set visibility and return.
90 if (!has_alternate || nextIndex >= [submenu numberOfItems]) {
tapted 2015/01/30 00:52:48 I think `nextIndex >= [submenu numberOfItems]` is
mitchellj 2015/01/30 02:53:38 Done.
91 [menuItem setHidden:!visible];
92 return;
93 }
94
95 NSMenuItem* nextMenuItem = [submenu itemAtIndex:nextIndex];
96 [nextMenuItem setAlternate:visible];
97 [nextMenuItem setHidden:!visible];
98 [menuItem setHidden:!visible];
99 }
100
78 } // namespace 101 } // namespace
79 102
80 // Used by AppShimMenuController to manage menu items that are a copy of a 103 // 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 104 // 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 105 // 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_| 106 // 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. 107 // 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 108 // 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 109 // 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. 110 // doppelganger just copies the item and sets a new action.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW); 286 AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW);
264 // Set the expected key equivalent explicitly here because 287 // Set the expected key equivalent explicitly here because
265 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to 288 // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to
266 // "W" (Cmd+Shift+w) when a tabbed window has focus; it will change it back 289 // "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. 290 // to Cmd+w when a non-tabbed window has focus.
268 NSMenuItem* closeWindowMenuItem = 291 NSMenuItem* closeWindowMenuItem =
269 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW]; 292 [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW];
270 [closeWindowMenuItem setKeyEquivalent:@"w"]; 293 [closeWindowMenuItem setKeyEquivalent:@"w"];
271 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; 294 [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
272 295
273 // Edit menu. This copies the menu entirely and removes 296 // 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, 297 // 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 298 // explicitly.
276 // copy them explicitly.
277 editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); 299 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 300
282 // View menu. Remove "Always Show Bookmark Bar" and separator. 301 // View menu. Remove "Always Show Bookmark Bar" and separator.
283 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); 302 viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]);
284 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES); 303 RemoveMenuItemWithTag(viewMenuItem_, IDC_SHOW_BOOKMARK_BAR, YES);
285 304
286 // History menu. 305 // History menu.
287 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]); 306 historyMenuItem_.reset([NewTopLevelItemFrom(IDC_HISTORY_MENU) retain]);
288 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK); 307 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_BACK);
289 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD); 308 AddDuplicateItem(historyMenuItem_, IDC_HISTORY_MENU, IDC_FORWARD);
290 309
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 [hideDoppelganger_ enableForApp:app]; 391 [hideDoppelganger_ enableForApp:app];
373 [quitDoppelganger_ enableForApp:app]; 392 [quitDoppelganger_ enableForApp:app];
374 [newDoppelganger_ enableForApp:app]; 393 [newDoppelganger_ enableForApp:app];
375 [openDoppelganger_ enableForApp:app]; 394 [openDoppelganger_ enableForApp:app];
376 395
377 [appMenuItem_ setTitle:appId]; 396 [appMenuItem_ setTitle:appId];
378 [[appMenuItem_ submenu] setTitle:title]; 397 [[appMenuItem_ submenu] setTitle:title];
379 398
380 [mainMenu addItem:appMenuItem_]; 399 [mainMenu addItem:appMenuItem_];
381 [mainMenu addItem:fileMenuItem_]; 400 [mainMenu addItem:fileMenuItem_];
401
402 if (!app->is_hosted_app()) {
403 SetItemWithTagVisible(
404 editMenuItem_, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, false, true);
tapted 2015/01/30 00:52:48 how about SetItemWithTagVisible( editMenu
mitchellj 2015/01/30 02:53:38 Done.
405 SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, false, false);
406 } else {
407 SetItemWithTagVisible(
408 editMenuItem_, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, true, true);
409 SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, true, false);
410 }
382 [mainMenu addItem:editMenuItem_]; 411 [mainMenu addItem:editMenuItem_];
412
383 if (app->is_hosted_app()) { 413 if (app->is_hosted_app()) {
384 [mainMenu addItem:viewMenuItem_]; 414 [mainMenu addItem:viewMenuItem_];
385 [mainMenu addItem:historyMenuItem_]; 415 [mainMenu addItem:historyMenuItem_];
386 } 416 }
387 [mainMenu addItem:windowMenuItem_]; 417 [mainMenu addItem:windowMenuItem_];
388 } 418 }
389 419
390 - (void)removeMenuItems { 420 - (void)removeMenuItems {
391 if (!appId_) 421 if (!appId_)
392 return; 422 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 478
449 - (void)focusCurrentPlatformApp { 479 - (void)focusCurrentPlatformApp {
450 extensions::AppWindow* appWindow = 480 extensions::AppWindow* appWindow =
451 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 481 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
452 [NSApp keyWindow]); 482 [NSApp keyWindow]);
453 if (appWindow) 483 if (appWindow)
454 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); 484 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow);
455 } 485 }
456 486
457 @end 487 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698