| 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 25 matching lines...) Expand all Loading... |
| 36 using content::HostZoomMap; | 36 using content::HostZoomMap; |
| 37 using content::UserMetricsAction; | 37 using content::UserMetricsAction; |
| 38 | 38 |
| 39 @interface WrenchMenuController (Private) | 39 @interface WrenchMenuController (Private) |
| 40 - (void)createModel; | 40 - (void)createModel; |
| 41 - (void)adjustPositioning; | 41 - (void)adjustPositioning; |
| 42 - (void)performCommandDispatch:(NSNumber*)tag; | 42 - (void)performCommandDispatch:(NSNumber*)tag; |
| 43 - (NSButton*)zoomDisplay; | 43 - (NSButton*)zoomDisplay; |
| 44 - (void)removeAllItems:(NSMenu*)menu; | 44 - (void)removeAllItems:(NSMenu*)menu; |
| 45 - (NSMenu*)recentTabsSubmenu; | 45 - (NSMenu*)recentTabsSubmenu; |
| 46 - (int)maxWidthForMenuModel:(ui::MenuModel*)model |
| 47 modelIndex:(int)modelIndex; |
| 46 @end | 48 @end |
| 47 | 49 |
| 48 namespace WrenchMenuControllerInternal { | 50 namespace WrenchMenuControllerInternal { |
| 49 | 51 |
| 50 // A C++ delegate that handles the accelerators in the wrench menu. | 52 // A C++ delegate that handles the accelerators in the wrench menu. |
| 51 class AcceleratorDelegate : public ui::AcceleratorProvider { | 53 class AcceleratorDelegate : public ui::AcceleratorProvider { |
| 52 public: | 54 public: |
| 53 virtual bool GetAcceleratorForCommandId(int command_id, | 55 virtual bool GetAcceleratorForCommandId(int command_id, |
| 54 ui::Accelerator* out_accelerator) { | 56 ui::Accelerator* out_accelerator) { |
| 55 AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); | 57 AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 while ([menu numberOfItems]) { | 316 while ([menu numberOfItems]) { |
| 315 [menu removeItemAtIndex:0]; | 317 [menu removeItemAtIndex:0]; |
| 316 } | 318 } |
| 317 } | 319 } |
| 318 | 320 |
| 319 - (NSMenu*)recentTabsSubmenu { | 321 - (NSMenu*)recentTabsSubmenu { |
| 320 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU); | 322 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU); |
| 321 return [[[self menu] itemWithTitle:title] submenu]; | 323 return [[[self menu] itemWithTitle:title] submenu]; |
| 322 } | 324 } |
| 323 | 325 |
| 326 // This overrdies the parent class to return a custom width for recent tabs |
| 327 // menu. |
| 328 - (int)maxWidthForMenuModel:(ui::MenuModel*)model |
| 329 modelIndex:(int)modelIndex { |
| 330 int index = 0; |
| 331 ui::MenuModel* recentTabsMenuModel = [self wrenchMenuModel]; |
| 332 if (ui::MenuModel::GetModelAndIndexForCommandId( |
| 333 IDC_RESTORE_TAB, &recentTabsMenuModel, &index)) { |
| 334 if (recentTabsMenuModel == model) { |
| 335 return static_cast<RecentTabsSubMenuModel*>( |
| 336 recentTabsMenuModel)->GetMaxWidthForItemAtIndex(modelIndex); |
| 337 } |
| 338 } |
| 339 return -1; |
| 340 } |
| 341 |
| 324 @end // @implementation WrenchMenuController | 342 @end // @implementation WrenchMenuController |
| 325 | 343 |
| 326 //////////////////////////////////////////////////////////////////////////////// | 344 //////////////////////////////////////////////////////////////////////////////// |
| 327 | 345 |
| 328 @implementation WrenchMenuButtonViewController | 346 @implementation WrenchMenuButtonViewController |
| 329 | 347 |
| 330 @synthesize editItem = editItem_; | 348 @synthesize editItem = editItem_; |
| 331 @synthesize editCut = editCut_; | 349 @synthesize editCut = editCut_; |
| 332 @synthesize editCopy = editCopy_; | 350 @synthesize editCopy = editCopy_; |
| 333 @synthesize editPaste = editPaste_; | 351 @synthesize editPaste = editPaste_; |
| 334 @synthesize zoomItem = zoomItem_; | 352 @synthesize zoomItem = zoomItem_; |
| 335 @synthesize zoomPlus = zoomPlus_; | 353 @synthesize zoomPlus = zoomPlus_; |
| 336 @synthesize zoomDisplay = zoomDisplay_; | 354 @synthesize zoomDisplay = zoomDisplay_; |
| 337 @synthesize zoomMinus = zoomMinus_; | 355 @synthesize zoomMinus = zoomMinus_; |
| 338 @synthesize zoomFullScreen = zoomFullScreen_; | 356 @synthesize zoomFullScreen = zoomFullScreen_; |
| 339 | 357 |
| 340 - (id)initWithController:(WrenchMenuController*)controller { | 358 - (id)initWithController:(WrenchMenuController*)controller { |
| 341 if ((self = [super initWithNibName:@"WrenchMenu" | 359 if ((self = [super initWithNibName:@"WrenchMenu" |
| 342 bundle:base::mac::FrameworkBundle()])) { | 360 bundle:base::mac::FrameworkBundle()])) { |
| 343 controller_ = controller; | 361 controller_ = controller; |
| 344 } | 362 } |
| 345 return self; | 363 return self; |
| 346 } | 364 } |
| 347 | 365 |
| 348 - (IBAction)dispatchWrenchMenuCommand:(id)sender { | 366 - (IBAction)dispatchWrenchMenuCommand:(id)sender { |
| 349 [controller_ dispatchWrenchMenuCommand:sender]; | 367 [controller_ dispatchWrenchMenuCommand:sender]; |
| 350 } | 368 } |
| 351 | 369 |
| 352 @end // @implementation WrenchMenuButtonViewController | 370 @end // @implementation WrenchMenuButtonViewController |
| OLD | NEW |