| 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/app_menu/app_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/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #import "chrome/browser/app_controller_mac.h" | 13 #import "chrome/browser/app_controller_mac.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 43 const int kRightPadding = 10; | 43 const int kRightPadding = 10; |
| 44 | 44 |
| 45 // In *very* extreme cases, it's possible that there are so many overflowed | 45 // In *very* extreme cases, it's possible that there are so many overflowed |
| 46 // actions, we won't be able to show them all. Cap the height so that the | 46 // actions, we won't be able to show them all. Cap the height so that the |
| 47 // overflow won't make the menu larger than the height of the screen. | 47 // overflow won't make the menu larger than the height of the screen. |
| 48 // Note: With this height, we can show 104 actions. Less than 0.0002% of our | 48 // Note: With this height, we can show 104 actions. Less than 0.0002% of our |
| 49 // users will be affected. | 49 // users will be affected. |
| 50 const int kMaxOverflowContainerHeight = 416; | 50 const int kMaxOverflowContainerHeight = 416; |
| 51 } | 51 } |
| 52 | 52 |
| 53 namespace wrench_menu_controller { | 53 namespace app_menu_controller { |
| 54 const CGFloat kWrenchBubblePointOffsetY = 6; | 54 const CGFloat kAppMenuBubblePointOffsetY = 6; |
| 55 } | 55 } |
| 56 | 56 |
| 57 using base::UserMetricsAction; | 57 using base::UserMetricsAction; |
| 58 | 58 |
| 59 @interface WrenchMenuController (Private) | 59 @interface AppMenuController (Private) |
| 60 - (void)createModel; | 60 - (void)createModel; |
| 61 - (void)adjustPositioning; | 61 - (void)adjustPositioning; |
| 62 - (void)performCommandDispatch:(NSNumber*)tag; | 62 - (void)performCommandDispatch:(NSNumber*)tag; |
| 63 - (NSButton*)zoomDisplay; | 63 - (NSButton*)zoomDisplay; |
| 64 - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; | 64 - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; |
| 65 - (void)removeAllItems:(NSMenu*)menu; | 65 - (void)removeAllItems:(NSMenu*)menu; |
| 66 - (NSMenu*)recentTabsSubmenu; | 66 - (NSMenu*)recentTabsSubmenu; |
| 67 - (RecentTabsSubMenuModel*)recentTabsMenuModel; | 67 - (RecentTabsSubMenuModel*)recentTabsMenuModel; |
| 68 - (int)maxWidthForMenuModel:(ui::MenuModel*)model | 68 - (int)maxWidthForMenuModel:(ui::MenuModel*)model |
| 69 modelIndex:(int)modelIndex; | 69 modelIndex:(int)modelIndex; |
| 70 @end | 70 @end |
| 71 | 71 |
| 72 namespace WrenchMenuControllerInternal { | 72 namespace AppMenuControllerInternal { |
| 73 | 73 |
| 74 // A C++ delegate that handles the accelerators in the wrench menu. | 74 // A C++ delegate that handles the accelerators in the app menu. |
| 75 class AcceleratorDelegate : public ui::AcceleratorProvider { | 75 class AcceleratorDelegate : public ui::AcceleratorProvider { |
| 76 public: | 76 public: |
| 77 bool GetAcceleratorForCommandId(int command_id, | 77 bool GetAcceleratorForCommandId(int command_id, |
| 78 ui::Accelerator* out_accelerator) override { | 78 ui::Accelerator* out_accelerator) override { |
| 79 AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); | 79 AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); |
| 80 const ui::Accelerator* accelerator = | 80 const ui::Accelerator* accelerator = |
| 81 keymap->GetAcceleratorForCommand(command_id); | 81 keymap->GetAcceleratorForCommand(command_id); |
| 82 if (!accelerator) | 82 if (!accelerator) |
| 83 return false; | 83 return false; |
| 84 *out_accelerator = *accelerator; | 84 *out_accelerator = *accelerator; |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 class ZoomLevelObserver { | 89 class ZoomLevelObserver { |
| 90 public: | 90 public: |
| 91 ZoomLevelObserver(WrenchMenuController* controller, | 91 ZoomLevelObserver(AppMenuController* controller, |
| 92 ui_zoom::ZoomEventManager* manager) | 92 ui_zoom::ZoomEventManager* manager) |
| 93 : controller_(controller) { | 93 : controller_(controller) { |
| 94 subscription_ = manager->AddZoomLevelChangedCallback( | 94 subscription_ = manager->AddZoomLevelChangedCallback( |
| 95 base::Bind(&ZoomLevelObserver::OnZoomLevelChanged, | 95 base::Bind(&ZoomLevelObserver::OnZoomLevelChanged, |
| 96 base::Unretained(this))); | 96 base::Unretained(this))); |
| 97 } | 97 } |
| 98 | 98 |
| 99 ~ZoomLevelObserver() {} | 99 ~ZoomLevelObserver() {} |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { | 102 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { |
| 103 AppMenuModel* appMenuModel = [controller_ appMenuModel]; | 103 AppMenuModel* appMenuModel = [controller_ appMenuModel]; |
| 104 appMenuModel->UpdateZoomControls(); | 104 appMenuModel->UpdateZoomControls(); |
| 105 const base::string16 level = | 105 const base::string16 level = |
| 106 appMenuModel->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY); | 106 appMenuModel->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY); |
| 107 [[controller_ zoomDisplay] setTitle:SysUTF16ToNSString(level)]; | 107 [[controller_ zoomDisplay] setTitle:SysUTF16ToNSString(level)]; |
| 108 } | 108 } |
| 109 | 109 |
| 110 scoped_ptr<content::HostZoomMap::Subscription> subscription_; | 110 scoped_ptr<content::HostZoomMap::Subscription> subscription_; |
| 111 | 111 |
| 112 WrenchMenuController* controller_; // Weak; owns this. | 112 AppMenuController* controller_; // Weak; owns this. |
| 113 | 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(ZoomLevelObserver); | 114 DISALLOW_COPY_AND_ASSIGN(ZoomLevelObserver); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class ToolbarActionsBarObserverHelper : public ToolbarActionsBarObserver { | 117 class ToolbarActionsBarObserverHelper : public ToolbarActionsBarObserver { |
| 118 public: | 118 public: |
| 119 ToolbarActionsBarObserverHelper(WrenchMenuController* controller, | 119 ToolbarActionsBarObserverHelper(AppMenuController* controller, |
| 120 ToolbarActionsBar* toolbar_actions_bar) | 120 ToolbarActionsBar* toolbar_actions_bar) |
| 121 : controller_(controller), | 121 : controller_(controller), |
| 122 scoped_observer_(this) { | 122 scoped_observer_(this) { |
| 123 scoped_observer_.Add(toolbar_actions_bar); | 123 scoped_observer_.Add(toolbar_actions_bar); |
| 124 } | 124 } |
| 125 ~ToolbarActionsBarObserverHelper() override {} | 125 ~ToolbarActionsBarObserverHelper() override {} |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 // ToolbarActionsBarObserver: | 128 // ToolbarActionsBarObserver: |
| 129 void OnToolbarActionsBarDestroyed() override { | 129 void OnToolbarActionsBarDestroyed() override { |
| 130 scoped_observer_.RemoveAll(); | 130 scoped_observer_.RemoveAll(); |
| 131 } | 131 } |
| 132 void OnToolbarActionsBarDidStartResize() override { | 132 void OnToolbarActionsBarDidStartResize() override { |
| 133 [controller_ updateBrowserActionsSubmenu]; | 133 [controller_ updateBrowserActionsSubmenu]; |
| 134 } | 134 } |
| 135 | 135 |
| 136 WrenchMenuController* controller_; | 136 AppMenuController* controller_; |
| 137 ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver> scoped_observer_; | 137 ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver> scoped_observer_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarObserverHelper); | 139 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarObserverHelper); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace WrenchMenuControllerInternal | 142 } // namespace AppMenuControllerInternal |
| 143 | 143 |
| 144 @implementation WrenchMenuController | 144 @implementation AppMenuController |
| 145 | 145 |
| 146 - (id)initWithBrowser:(Browser*)browser { | 146 - (id)initWithBrowser:(Browser*)browser { |
| 147 if ((self = [super init])) { | 147 if ((self = [super init])) { |
| 148 browser_ = browser; | 148 browser_ = browser; |
| 149 acceleratorDelegate_.reset( | 149 acceleratorDelegate_.reset( |
| 150 new WrenchMenuControllerInternal::AcceleratorDelegate()); | 150 new AppMenuControllerInternal::AcceleratorDelegate()); |
| 151 [self createModel]; | 151 [self createModel]; |
| 152 } | 152 } |
| 153 return self; | 153 return self; |
| 154 } | 154 } |
| 155 | 155 |
| 156 - (void)dealloc { | 156 - (void)dealloc { |
| 157 [self browserWillBeDestroyed]; | 157 [self browserWillBeDestroyed]; |
| 158 [super dealloc]; | 158 [super dealloc]; |
| 159 } | 159 } |
| 160 | 160 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 MenuTrackedRootView* view = nil; | 197 MenuTrackedRootView* view = nil; |
| 198 switch (command_id) { | 198 switch (command_id) { |
| 199 case IDC_EXTENSIONS_OVERFLOW_MENU: { | 199 case IDC_EXTENSIONS_OVERFLOW_MENU: { |
| 200 browserActionsMenuItem_ = customItem.get(); | 200 browserActionsMenuItem_ = customItem.get(); |
| 201 view = [buttonViewController_ toolbarActionsOverflowItem]; | 201 view = [buttonViewController_ toolbarActionsOverflowItem]; |
| 202 BrowserActionsContainerView* containerView = | 202 BrowserActionsContainerView* containerView = |
| 203 [buttonViewController_ overflowActionsContainerView]; | 203 [buttonViewController_ overflowActionsContainerView]; |
| 204 | 204 |
| 205 // The overflow browser actions container can't function properly without | 205 // The overflow browser actions container can't function properly without |
| 206 // a main counterpart, so if the browser window hasn't initialized, abort. | 206 // a main counterpart, so if the browser window hasn't initialized, abort. |
| 207 // (This is fine because we re-populate the wrench menu each time before | 207 // (This is fine because we re-populate the app menu each time before we |
| 208 // we show it.) | 208 // show it.) |
| 209 if (!browser_->window()) | 209 if (!browser_->window()) |
| 210 break; | 210 break; |
| 211 | 211 |
| 212 BrowserActionsController* mainController = | 212 BrowserActionsController* mainController = |
| 213 [[[BrowserWindowController browserWindowControllerForWindow:browser_-> | 213 [[[BrowserWindowController browserWindowControllerForWindow:browser_-> |
| 214 window()->GetNativeWindow()] toolbarController] | 214 window()->GetNativeWindow()] toolbarController] |
| 215 browserActionsController]; | 215 browserActionsController]; |
| 216 toolbar_actions_bar_observer_.reset( | 216 toolbar_actions_bar_observer_.reset( |
| 217 new WrenchMenuControllerInternal::ToolbarActionsBarObserverHelper( | 217 new AppMenuControllerInternal::ToolbarActionsBarObserverHelper( |
| 218 self, [mainController toolbarActionsBar])); | 218 self, [mainController toolbarActionsBar])); |
| 219 browserActionsController_.reset( | 219 browserActionsController_.reset( |
| 220 [[BrowserActionsController alloc] | 220 [[BrowserActionsController alloc] |
| 221 initWithBrowser:browser_ | 221 initWithBrowser:browser_ |
| 222 containerView:containerView | 222 containerView:containerView |
| 223 mainController:mainController]); | 223 mainController:mainController]); |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 case IDC_EDIT_MENU: | 226 case IDC_EDIT_MENU: |
| 227 view = [buttonViewController_ editItem]; | 227 view = [buttonViewController_ editItem]; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 [view setFrameOrigin:NSZeroPoint]; | 327 [view setFrameOrigin:NSZeroPoint]; |
| 328 [[containerView superview] setFrameOrigin:NSZeroPoint]; | 328 [[containerView superview] setFrameOrigin:NSZeroPoint]; |
| 329 [containerView setFrameOrigin:NSMakePoint(kLeftPadding, 0)]; | 329 [containerView setFrameOrigin:NSMakePoint(kLeftPadding, 0)]; |
| 330 } | 330 } |
| 331 | 331 |
| 332 - (void)menuWillOpen:(NSMenu*)menu { | 332 - (void)menuWillOpen:(NSMenu*)menu { |
| 333 [super menuWillOpen:menu]; | 333 [super menuWillOpen:menu]; |
| 334 | 334 |
| 335 zoom_level_observer_.reset( | 335 zoom_level_observer_.reset( |
| 336 new WrenchMenuControllerInternal::ZoomLevelObserver( | 336 new AppMenuControllerInternal::ZoomLevelObserver( |
| 337 self, | 337 self, |
| 338 ui_zoom::ZoomEventManager::GetForBrowserContext( | 338 ui_zoom::ZoomEventManager::GetForBrowserContext( |
| 339 browser_->profile()))); | 339 browser_->profile()))); |
| 340 NSString* title = base::SysUTF16ToNSString( | 340 NSString* title = base::SysUTF16ToNSString( |
| 341 [self appMenuModel]->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY)); | 341 [self appMenuModel]->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY)); |
| 342 [[[buttonViewController_ zoomItem] viewWithTag:IDC_ZOOM_PERCENT_DISPLAY] | 342 [[[buttonViewController_ zoomItem] viewWithTag:IDC_ZOOM_PERCENT_DISPLAY] |
| 343 setTitle:title]; | 343 setTitle:title]; |
| 344 content::RecordAction(UserMetricsAction("ShowAppMenu")); | 344 content::RecordAction(UserMetricsAction("ShowAppMenu")); |
| 345 | 345 |
| 346 NSImage* icon = [self appMenuModel]->browser()->window()->IsFullscreen() | 346 NSImage* icon = [self appMenuModel]->browser()->window()->IsFullscreen() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 372 [self removeAllItems:newMenu]; | 372 [self removeAllItems:newMenu]; |
| 373 for (NSMenuItem* item in itemArray) { | 373 for (NSMenuItem* item in itemArray) { |
| 374 [menu addItem:item]; | 374 [menu addItem:item]; |
| 375 } | 375 } |
| 376 | 376 |
| 377 [self updateRecentTabsSubmenu]; | 377 [self updateRecentTabsSubmenu]; |
| 378 [self updateBookmarkSubMenu]; | 378 [self updateBookmarkSubMenu]; |
| 379 [self updateBrowserActionsSubmenu]; | 379 [self updateBrowserActionsSubmenu]; |
| 380 } | 380 } |
| 381 | 381 |
| 382 // Used to dispatch commands from the Wrench menu. The custom items within the | 382 // Used to dispatch commands from the App menu. The custom items within the |
| 383 // menu cannot be hooked up directly to First Responder because the window in | 383 // menu cannot be hooked up directly to First Responder because the window in |
| 384 // which the controls reside is not the BrowserWindowController, but a | 384 // which the controls reside is not the BrowserWindowController, but a |
| 385 // NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system. | 385 // NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system. |
| 386 - (IBAction)dispatchWrenchMenuCommand:(id)sender { | 386 - (IBAction)dispatchAppMenuCommand:(id)sender { |
| 387 NSInteger tag = [sender tag]; | 387 NSInteger tag = [sender tag]; |
| 388 if (sender == [buttonViewController_ zoomPlus] || | 388 if (sender == [buttonViewController_ zoomPlus] || |
| 389 sender == [buttonViewController_ zoomMinus]) { | 389 sender == [buttonViewController_ zoomMinus]) { |
| 390 // Do a direct dispatch rather than scheduling on the outermost run loop, | 390 // Do a direct dispatch rather than scheduling on the outermost run loop, |
| 391 // which would not get hit until after the menu had closed. | 391 // which would not get hit until after the menu had closed. |
| 392 [self performCommandDispatch:[NSNumber numberWithInt:tag]]; | 392 [self performCommandDispatch:[NSNumber numberWithInt:tag]]; |
| 393 | 393 |
| 394 // The zoom buttons should not close the menu if opened sticky. | 394 // The zoom buttons should not close the menu if opened sticky. |
| 395 if ([sender respondsToSelector:@selector(isTracking)] && | 395 if ([sender respondsToSelector:@selector(isTracking)] && |
| 396 [sender performSelector:@selector(isTracking)]) { | 396 [sender performSelector:@selector(isTracking)]) { |
| 397 [menu_ cancelTracking]; | 397 [menu_ cancelTracking]; |
| 398 } | 398 } |
| 399 } else { | 399 } else { |
| 400 // The custom views within the Wrench menu are abnormal and keep the menu | 400 // The custom views within the App menu are abnormal and keep the menu open |
| 401 // open after a target-action. Close the menu manually. | 401 // after a target-action. Close the menu manually. |
| 402 [menu_ cancelTracking]; | 402 [menu_ cancelTracking]; |
| 403 | 403 |
| 404 // Executing certain commands from the nested run loop of the menu can lead | 404 // Executing certain commands from the nested run loop of the menu can lead |
| 405 // to wonky behavior (e.g. http://crbug.com/49716). To avoid this, schedule | 405 // to wonky behavior (e.g. http://crbug.com/49716). To avoid this, schedule |
| 406 // the dispatch on the outermost run loop. | 406 // the dispatch on the outermost run loop. |
| 407 [self performSelector:@selector(performCommandDispatch:) | 407 [self performSelector:@selector(performCommandDispatch:) |
| 408 withObject:[NSNumber numberWithInt:tag] | 408 withObject:[NSNumber numberWithInt:tag] |
| 409 afterDelay:0.0]; | 409 afterDelay:0.0]; |
| 410 } | 410 } |
| 411 } | 411 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 432 return browserActionsController_.get(); | 432 return browserActionsController_.get(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 - (void)createModel { | 435 - (void)createModel { |
| 436 DCHECK(browser_); | 436 DCHECK(browser_); |
| 437 recentTabsMenuModelDelegate_.reset(); | 437 recentTabsMenuModelDelegate_.reset(); |
| 438 appMenuModel_.reset(new AppMenuModel(acceleratorDelegate_.get(), browser_)); | 438 appMenuModel_.reset(new AppMenuModel(acceleratorDelegate_.get(), browser_)); |
| 439 [self setModel:appMenuModel_.get()]; | 439 [self setModel:appMenuModel_.get()]; |
| 440 | 440 |
| 441 buttonViewController_.reset( | 441 buttonViewController_.reset( |
| 442 [[WrenchMenuButtonViewController alloc] initWithController:self]); | 442 [[AppMenuButtonViewController alloc] initWithController:self]); |
| 443 [buttonViewController_ view]; | 443 [buttonViewController_ view]; |
| 444 | 444 |
| 445 // See comment in containerSuperviewFrameChanged:. | 445 // See comment in containerSuperviewFrameChanged:. |
| 446 NSView* containerSuperview = | 446 NSView* containerSuperview = |
| 447 [[buttonViewController_ overflowActionsContainerView] superview]; | 447 [[buttonViewController_ overflowActionsContainerView] superview]; |
| 448 [containerSuperview setPostsFrameChangedNotifications:YES]; | 448 [containerSuperview setPostsFrameChangedNotifications:YES]; |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Fit the localized strings into the Cut/Copy/Paste control, then resize the | 451 // Fit the localized strings into the Cut/Copy/Paste control, then resize the |
| 452 // whole menu item accordingly. | 452 // whole menu item accordingly. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 514 |
| 515 - (NSMenu*)recentTabsSubmenu { | 515 - (NSMenu*)recentTabsSubmenu { |
| 516 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU); | 516 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU); |
| 517 return [[[self menu] itemWithTitle:title] submenu]; | 517 return [[[self menu] itemWithTitle:title] submenu]; |
| 518 } | 518 } |
| 519 | 519 |
| 520 // The recent tabs menu model is recognized by the existence of either the | 520 // The recent tabs menu model is recognized by the existence of either the |
| 521 // kRecentlyClosedHeaderCommandId or the kDisabledRecentlyClosedHeaderCommandId. | 521 // kRecentlyClosedHeaderCommandId or the kDisabledRecentlyClosedHeaderCommandId. |
| 522 - (RecentTabsSubMenuModel*)recentTabsMenuModel { | 522 - (RecentTabsSubMenuModel*)recentTabsMenuModel { |
| 523 int index = 0; | 523 int index = 0; |
| 524 // Start searching at the wrench menu model level, |model| will be updated | 524 // Start searching at the app menu model level, |model| will be updated only |
| 525 // only if the command we're looking for is found in one of the [sub]menus. | 525 // if the command we're looking for is found in one of the [sub]menus. |
| 526 ui::MenuModel* model = [self appMenuModel]; | 526 ui::MenuModel* model = [self appMenuModel]; |
| 527 if (ui::MenuModel::GetModelAndIndexForCommandId( | 527 if (ui::MenuModel::GetModelAndIndexForCommandId( |
| 528 RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId, &model, | 528 RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId, &model, |
| 529 &index)) { | 529 &index)) { |
| 530 return static_cast<RecentTabsSubMenuModel*>(model); | 530 return static_cast<RecentTabsSubMenuModel*>(model); |
| 531 } | 531 } |
| 532 if (ui::MenuModel::GetModelAndIndexForCommandId( | 532 if (ui::MenuModel::GetModelAndIndexForCommandId( |
| 533 RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId, | 533 RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId, |
| 534 &model, &index)) { | 534 &model, &index)) { |
| 535 return static_cast<RecentTabsSubMenuModel*>(model); | 535 return static_cast<RecentTabsSubMenuModel*>(model); |
| 536 } | 536 } |
| 537 return NULL; | 537 return NULL; |
| 538 } | 538 } |
| 539 | 539 |
| 540 // This overrdies the parent class to return a custom width for recent tabs | 540 // This overrdies the parent class to return a custom width for recent tabs |
| 541 // menu. | 541 // menu. |
| 542 - (int)maxWidthForMenuModel:(ui::MenuModel*)model | 542 - (int)maxWidthForMenuModel:(ui::MenuModel*)model |
| 543 modelIndex:(int)modelIndex { | 543 modelIndex:(int)modelIndex { |
| 544 RecentTabsSubMenuModel* recentTabsMenuModel = [self recentTabsMenuModel]; | 544 RecentTabsSubMenuModel* recentTabsMenuModel = [self recentTabsMenuModel]; |
| 545 if (recentTabsMenuModel && recentTabsMenuModel == model) { | 545 if (recentTabsMenuModel && recentTabsMenuModel == model) { |
| 546 return recentTabsMenuModel->GetMaxWidthForItemAtIndex(modelIndex); | 546 return recentTabsMenuModel->GetMaxWidthForItemAtIndex(modelIndex); |
| 547 } | 547 } |
| 548 return -1; | 548 return -1; |
| 549 } | 549 } |
| 550 | 550 |
| 551 @end // @implementation WrenchMenuController | 551 @end // @implementation AppMenuController |
| 552 | 552 |
| 553 //////////////////////////////////////////////////////////////////////////////// | 553 //////////////////////////////////////////////////////////////////////////////// |
| 554 | 554 |
| 555 @interface WrenchMenuButtonViewController () | 555 @interface AppMenuButtonViewController () |
| 556 - (void)containerSuperviewFrameChanged:(NSNotification*)notification; | 556 - (void)containerSuperviewFrameChanged:(NSNotification*)notification; |
| 557 @end | 557 @end |
| 558 | 558 |
| 559 @implementation WrenchMenuButtonViewController | 559 @implementation AppMenuButtonViewController |
| 560 | 560 |
| 561 @synthesize editItem = editItem_; | 561 @synthesize editItem = editItem_; |
| 562 @synthesize editCut = editCut_; | 562 @synthesize editCut = editCut_; |
| 563 @synthesize editCopy = editCopy_; | 563 @synthesize editCopy = editCopy_; |
| 564 @synthesize editPaste = editPaste_; | 564 @synthesize editPaste = editPaste_; |
| 565 @synthesize zoomItem = zoomItem_; | 565 @synthesize zoomItem = zoomItem_; |
| 566 @synthesize zoomPlus = zoomPlus_; | 566 @synthesize zoomPlus = zoomPlus_; |
| 567 @synthesize zoomDisplay = zoomDisplay_; | 567 @synthesize zoomDisplay = zoomDisplay_; |
| 568 @synthesize zoomMinus = zoomMinus_; | 568 @synthesize zoomMinus = zoomMinus_; |
| 569 @synthesize zoomFullScreen = zoomFullScreen_; | 569 @synthesize zoomFullScreen = zoomFullScreen_; |
| 570 @synthesize toolbarActionsOverflowItem = toolbarActionsOverflowItem_; | 570 @synthesize toolbarActionsOverflowItem = toolbarActionsOverflowItem_; |
| 571 @synthesize overflowActionsContainerView = overflowActionsContainerView_; | 571 @synthesize overflowActionsContainerView = overflowActionsContainerView_; |
| 572 | 572 |
| 573 - (id)initWithController:(WrenchMenuController*)controller { | 573 - (id)initWithController:(AppMenuController*)controller { |
| 574 if ((self = [super initWithNibName:@"WrenchMenu" | 574 if ((self = [super initWithNibName:@"WrenchMenu" |
| 575 bundle:base::mac::FrameworkBundle()])) { | 575 bundle:base::mac::FrameworkBundle()])) { |
| 576 propertyReleaser_.Init(self, [WrenchMenuButtonViewController class]); | 576 propertyReleaser_.Init(self, [AppMenuButtonViewController class]); |
| 577 controller_ = controller; | 577 controller_ = controller; |
| 578 [[NSNotificationCenter defaultCenter] | 578 [[NSNotificationCenter defaultCenter] |
| 579 addObserver:self | 579 addObserver:self |
| 580 selector:@selector(containerSuperviewFrameChanged:) | 580 selector:@selector(containerSuperviewFrameChanged:) |
| 581 name:NSViewFrameDidChangeNotification | 581 name:NSViewFrameDidChangeNotification |
| 582 object:[overflowActionsContainerView_ superview]]; | 582 object:[overflowActionsContainerView_ superview]]; |
| 583 } | 583 } |
| 584 return self; | 584 return self; |
| 585 } | 585 } |
| 586 | 586 |
| 587 - (void)dealloc { | 587 - (void)dealloc { |
| 588 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 588 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 589 [super dealloc]; | 589 [super dealloc]; |
| 590 } | 590 } |
| 591 | 591 |
| 592 - (IBAction)dispatchWrenchMenuCommand:(id)sender { | 592 - (IBAction)dispatchAppMenuCommand:(id)sender { |
| 593 [controller_ dispatchWrenchMenuCommand:sender]; | 593 [controller_ dispatchAppMenuCommand:sender]; |
| 594 } | 594 } |
| 595 | 595 |
| 596 - (void)containerSuperviewFrameChanged:(NSNotification*)notification { | 596 - (void)containerSuperviewFrameChanged:(NSNotification*)notification { |
| 597 // AppKit menus were probably never designed with a view like the browser | 597 // AppKit menus were probably never designed with a view like the browser |
| 598 // actions container in mind, and, as a result, we come across a few oddities. | 598 // actions container in mind, and, as a result, we come across a few oddities. |
| 599 // One of these is that the container's superview will, on some versions of | 599 // One of these is that the container's superview will, on some versions of |
| 600 // OSX, change frame position sometime after the the menu begins tracking | 600 // OSX, change frame position sometime after the the menu begins tracking |
| 601 // (and thus, after all our ability to adjust it normally). Throw in the | 601 // (and thus, after all our ability to adjust it normally). Throw in the |
| 602 // towel, and simply don't let the frame move from where it's supposed to be. | 602 // towel, and simply don't let the frame move from where it's supposed to be. |
| 603 // TODO(devlin): Yet another Cocoa hack. It'd be good to find a workaround, | 603 // TODO(devlin): Yet another Cocoa hack. It'd be good to find a workaround, |
| 604 // but unlikely unless we replace the Cocoa menu implementation. | 604 // but unlikely unless we replace the Cocoa menu implementation. |
| 605 NSView* containerSuperview = [overflowActionsContainerView_ superview]; | 605 NSView* containerSuperview = [overflowActionsContainerView_ superview]; |
| 606 if (NSMinX([containerSuperview frame]) != 0) | 606 if (NSMinX([containerSuperview frame]) != 0) |
| 607 [containerSuperview setFrameOrigin:NSZeroPoint]; | 607 [containerSuperview setFrameOrigin:NSZeroPoint]; |
| 608 } | 608 } |
| 609 | 609 |
| 610 @end // @implementation WrenchMenuButtonViewController | 610 @end // @implementation AppMenuButtonViewController |
| OLD | NEW |