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 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 using content::HostZoomMap; | 37 using content::HostZoomMap; |
38 using content::UserMetricsAction; | 38 using content::UserMetricsAction; |
39 | 39 |
40 @interface WrenchMenuController (Private) | 40 @interface WrenchMenuController (Private) |
41 - (void)createModel; | 41 - (void)createModel; |
42 - (void)adjustPositioning; | 42 - (void)adjustPositioning; |
43 - (void)performCommandDispatch:(NSNumber*)tag; | 43 - (void)performCommandDispatch:(NSNumber*)tag; |
44 - (NSButton*)zoomDisplay; | 44 - (NSButton*)zoomDisplay; |
45 - (void)removeAllItems:(NSMenu*)menu; | 45 - (void)removeAllItems:(NSMenu*)menu; |
46 - (NSMenu*)recentTabsSubmenu; | 46 - (NSMenu*)recentTabsSubmenu; |
47 - (int)maxWidthForMenuModel:(ui::MenuModel*)model | |
48 modelIndex:(int)modelIndex; | |
47 @end | 49 @end |
48 | 50 |
49 namespace WrenchMenuControllerInternal { | 51 namespace WrenchMenuControllerInternal { |
50 | 52 |
51 // A C++ delegate that handles the accelerators in the wrench menu. | 53 // A C++ delegate that handles the accelerators in the wrench menu. |
52 class AcceleratorDelegate : public ui::AcceleratorProvider { | 54 class AcceleratorDelegate : public ui::AcceleratorProvider { |
53 public: | 55 public: |
54 virtual bool GetAcceleratorForCommandId(int command_id, | 56 virtual bool GetAcceleratorForCommandId(int command_id, |
55 ui::Accelerator* accelerator_generic) { | 57 ui::Accelerator* accelerator_generic) { |
56 // Downcast so that when the copy constructor is invoked below, the key | 58 // Downcast so that when the copy constructor is invoked below, the key |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 while ([menu numberOfItems]) { | 322 while ([menu numberOfItems]) { |
321 [menu removeItemAtIndex:0]; | 323 [menu removeItemAtIndex:0]; |
322 } | 324 } |
323 } | 325 } |
324 | 326 |
325 - (NSMenu*)recentTabsSubmenu { | 327 - (NSMenu*)recentTabsSubmenu { |
326 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU); | 328 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU); |
327 return [[[self menu] itemWithTitle:title] submenu]; | 329 return [[[self menu] itemWithTitle:title] submenu]; |
328 } | 330 } |
329 | 331 |
332 // This overrdies the parent class to return a custom width for recent tabs | |
333 // menu. | |
334 - (int)maxWidthForMenuModel:(ui::MenuModel*)model | |
335 modelIndex:(int)modelIndex { | |
336 int index = 0; | |
337 ui::MenuModel* recentTabsMenuModel = [self wrenchMenuModel]; | |
338 if (ui::MenuModel::GetModelAndIndexForCommandId( | |
339 IDC_RESTORE_TAB, &recentTabsMenuModel, &index)) { | |
340 if (recentTabsMenuModel == model) | |
Robert Sesek
2012/11/27 17:09:20
nit: braces needed since the body is more than one
sail
2012/11/28 07:38:25
Done.
| |
341 return static_cast<RecentTabsSubMenuModel*>( | |
342 recentTabsMenuModel)->GetMaxWidthForItemAtIndex(modelIndex); | |
343 } | |
344 return -1; | |
345 } | |
346 | |
330 @end // @implementation WrenchMenuController | 347 @end // @implementation WrenchMenuController |
331 | 348 |
332 //////////////////////////////////////////////////////////////////////////////// | 349 //////////////////////////////////////////////////////////////////////////////// |
333 | 350 |
334 @implementation WrenchMenuButtonViewController | 351 @implementation WrenchMenuButtonViewController |
335 | 352 |
336 @synthesize editItem = editItem_; | 353 @synthesize editItem = editItem_; |
337 @synthesize editCut = editCut_; | 354 @synthesize editCut = editCut_; |
338 @synthesize editCopy = editCopy_; | 355 @synthesize editCopy = editCopy_; |
339 @synthesize editPaste = editPaste_; | 356 @synthesize editPaste = editPaste_; |
340 @synthesize zoomItem = zoomItem_; | 357 @synthesize zoomItem = zoomItem_; |
341 @synthesize zoomPlus = zoomPlus_; | 358 @synthesize zoomPlus = zoomPlus_; |
342 @synthesize zoomDisplay = zoomDisplay_; | 359 @synthesize zoomDisplay = zoomDisplay_; |
343 @synthesize zoomMinus = zoomMinus_; | 360 @synthesize zoomMinus = zoomMinus_; |
344 @synthesize zoomFullScreen = zoomFullScreen_; | 361 @synthesize zoomFullScreen = zoomFullScreen_; |
345 | 362 |
346 - (id)initWithController:(WrenchMenuController*)controller { | 363 - (id)initWithController:(WrenchMenuController*)controller { |
347 if ((self = [super initWithNibName:@"WrenchMenu" | 364 if ((self = [super initWithNibName:@"WrenchMenu" |
348 bundle:base::mac::FrameworkBundle()])) { | 365 bundle:base::mac::FrameworkBundle()])) { |
349 controller_ = controller; | 366 controller_ = controller; |
350 } | 367 } |
351 return self; | 368 return self; |
352 } | 369 } |
353 | 370 |
354 - (IBAction)dispatchWrenchMenuCommand:(id)sender { | 371 - (IBAction)dispatchWrenchMenuCommand:(id)sender { |
355 [controller_ dispatchWrenchMenuCommand:sender]; | 372 [controller_ dispatchWrenchMenuCommand:sender]; |
356 } | 373 } |
357 | 374 |
358 @end // @implementation WrenchMenuButtonViewController | 375 @end // @implementation WrenchMenuButtonViewController |
OLD | NEW |