| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/toolbar_controller.h" | 5 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 88 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
| 89 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 89 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
| 90 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; | 90 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; |
| 91 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 91 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
| 92 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 92 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
| 93 - (void)badgeWrenchMenu; | 93 - (void)badgeWrenchMenu; |
| 94 @end | 94 @end |
| 95 | 95 |
| 96 namespace ToolbarControllerInternal { | 96 namespace ToolbarControllerInternal { |
| 97 | 97 |
| 98 // A C++ delegate that handles the accelerators in the wrench menu. | 98 // A C++ delegate that handles enabling/disabling menu items and handling when |
| 99 class WrenchAcceleratorDelegate : public menus::AcceleratorProvider { | 99 // a menu command is chosen. |
| 100 class MenuDelegate : public menus::SimpleMenuModel::Delegate { |
| 100 public: | 101 public: |
| 102 explicit MenuDelegate(Browser* browser) |
| 103 : browser_(browser) { } |
| 104 |
| 105 // Overridden from menus::SimpleMenuModel::Delegate |
| 106 virtual bool IsCommandIdChecked(int command_id) const { |
| 107 if (command_id == IDC_SHOW_BOOKMARK_BAR) { |
| 108 return browser_->profile()->GetPrefs()->GetBoolean( |
| 109 prefs::kShowBookmarkBar); |
| 110 } |
| 111 return false; |
| 112 } |
| 113 virtual bool IsCommandIdEnabled(int command_id) const { |
| 114 return browser_->command_updater()->IsCommandEnabled(command_id); |
| 115 } |
| 101 virtual bool GetAcceleratorForCommandId(int command_id, | 116 virtual bool GetAcceleratorForCommandId(int command_id, |
| 102 menus::Accelerator* accelerator_generic) { | 117 menus::Accelerator* accelerator_generic) { |
| 103 // Downcast so that when the copy constructor is invoked below, the key | 118 // Downcast so that when the copy constructor is invoked below, the key |
| 104 // string gets copied, too. | 119 // string gets copied, too. |
| 105 menus::AcceleratorCocoa* out_accelerator = | 120 menus::AcceleratorCocoa* out_accelerator = |
| 106 static_cast<menus::AcceleratorCocoa*>(accelerator_generic); | 121 static_cast<menus::AcceleratorCocoa*>(accelerator_generic); |
| 107 AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); | 122 AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); |
| 108 const menus::AcceleratorCocoa* accelerator = | 123 const menus::AcceleratorCocoa* accelerator = |
| 109 keymap->GetAcceleratorForCommand(command_id); | 124 keymap->GetAcceleratorForCommand(command_id); |
| 110 if (accelerator) { | 125 if (accelerator) { |
| 111 *out_accelerator = *accelerator; | 126 *out_accelerator = *accelerator; |
| 112 return true; | 127 return true; |
| 113 } | 128 } |
| 114 return false; | 129 return false; |
| 115 } | 130 } |
| 131 virtual void ExecuteCommand(int command_id) { |
| 132 browser_->ExecuteCommand(command_id); |
| 133 } |
| 134 virtual bool IsLabelForCommandIdDynamic(int command_id) const { |
| 135 // On Mac, switch between "Enter Full Screen" and "Exit Full Screen". |
| 136 return (command_id == IDC_FULLSCREEN); |
| 137 } |
| 138 virtual string16 GetLabelForCommandId(int command_id) const { |
| 139 if (command_id == IDC_FULLSCREEN) { |
| 140 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. |
| 141 // Note: On startup, |window()| may be NULL. |
| 142 if (browser_->window() && browser_->window()->IsFullscreen()) |
| 143 string_id = IDS_EXIT_FULLSCREEN_MAC; |
| 144 return l10n_util::GetStringUTF16(string_id); |
| 145 } |
| 146 return menus::SimpleMenuModel::Delegate::GetLabelForCommandId(command_id); |
| 147 } |
| 148 |
| 149 private: |
| 150 Browser* browser_; |
| 116 }; | 151 }; |
| 117 | 152 |
| 118 // A class registered for C++ notifications. This is used to detect changes in | 153 // A class registered for C++ notifications. This is used to detect changes in |
| 119 // preferences and upgrade available notifications. Bridges the notification | 154 // preferences and upgrade available notifications. Bridges the notification |
| 120 // back to the ToolbarController. | 155 // back to the ToolbarController. |
| 121 class NotificationBridge : public NotificationObserver { | 156 class NotificationBridge : public NotificationObserver { |
| 122 public: | 157 public: |
| 123 explicit NotificationBridge(ToolbarController* controller) | 158 explicit NotificationBridge(ToolbarController* controller) |
| 124 : controller_(controller) { | 159 : controller_(controller) { |
| 125 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, | 160 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 540 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
| 506 byAmount:moveX]]; | 541 byAmount:moveX]]; |
| 507 [homeButton_ setHidden:hide]; | 542 [homeButton_ setHidden:hide]; |
| 508 } | 543 } |
| 509 | 544 |
| 510 // Install the menu wrench buttons. Calling this repeatedly is inexpensive so it | 545 // Install the menu wrench buttons. Calling this repeatedly is inexpensive so it |
| 511 // can be done every time the buttons are shown. | 546 // can be done every time the buttons are shown. |
| 512 - (void)installWrenchMenu { | 547 - (void)installWrenchMenu { |
| 513 if (wrenchMenuModel_.get()) | 548 if (wrenchMenuModel_.get()) |
| 514 return; | 549 return; |
| 515 acceleratorDelegate_.reset( | 550 menuDelegate_.reset(new ToolbarControllerInternal::MenuDelegate(browser_)); |
| 516 new ToolbarControllerInternal::WrenchAcceleratorDelegate()); | |
| 517 | 551 |
| 518 wrenchMenuModel_.reset(new WrenchMenuModel( | 552 wrenchMenuModel_.reset(new WrenchMenuModel(menuDelegate_.get(), browser_)); |
| 519 acceleratorDelegate_.get(), browser_)); | 553 [wrenchMenuController_ setModel:wrenchMenuModel_.get()]; |
| 520 [wrenchMenuController_ setWrenchMenuModel:wrenchMenuModel_.get()]; | |
| 521 [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; | 554 [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; |
| 522 [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; | 555 [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; |
| 523 } | 556 } |
| 524 | 557 |
| 525 - (WrenchMenuController*)wrenchMenuController { | 558 - (WrenchMenuController*)wrenchMenuController { |
| 526 return wrenchMenuController_; | 559 return wrenchMenuController_; |
| 527 } | 560 } |
| 528 | 561 |
| 529 - (void)badgeWrenchMenu { | 562 - (void)badgeWrenchMenu { |
| 530 // In the Windows version, the ball doesn't actually pulsate, and is always | 563 // In the Windows version, the ball doesn't actually pulsate, and is always |
| 531 // drawn with the inactive image. Why? (We follow suit, though not on the | 564 // drawn with the inactive image. Why? (We follow suit, though not on the |
| 532 // weird positioning they do that overlaps the button border.) | 565 // weird positioning they do that overlaps the button border.) |
| 533 NSImage* badge = nsimage_cache::ImageNamed(@"upgrade_dot.pdf"); | 566 NSImage* badge = nsimage_cache::ImageNamed(@"upgrade_dot.pdf"); |
| 534 NSImage* wrenchImage = nsimage_cache::ImageNamed(kWrenchButtonImageName); | 567 NSImage* wrenchImage = nsimage_cache::ImageNamed(kWrenchButtonImageName); |
| 535 NSSize wrenchImageSize = [wrenchImage size]; | 568 NSSize wrenchImageSize = [wrenchImage size]; |
| 536 | 569 |
| 537 scoped_nsobject<NSImage> overlayImage( | 570 scoped_nsobject<NSImage> overlayImage( |
| 538 [[NSImage alloc] initWithSize:wrenchImageSize]); | 571 [[NSImage alloc] initWithSize:wrenchImageSize]); |
| 539 | 572 |
| 540 [overlayImage lockFocus]; | 573 [overlayImage lockFocus]; |
| 541 [badge drawAtPoint:NSZeroPoint | 574 [badge drawAtPoint:NSZeroPoint |
| 542 fromRect:NSZeroRect | 575 fromRect:NSZeroRect |
| 543 operation:NSCompositeSourceOver | 576 operation:NSCompositeSourceOver |
| 544 fraction:1.0]; | 577 fraction:1.0]; |
| 545 [overlayImage unlockFocus]; | 578 [overlayImage unlockFocus]; |
| 546 | 579 |
| 547 [[wrenchButton_ cell] setOverlayImage:overlayImage]; | 580 [[wrenchButton_ cell] setOverlayImage:overlayImage]; |
| 581 |
| 582 [wrenchMenuController_ insertUpdateAvailableItem]; |
| 548 } | 583 } |
| 549 | 584 |
| 550 - (void)prefChanged:(std::string*)prefName { | 585 - (void)prefChanged:(std::string*)prefName { |
| 551 if (!prefName) return; | 586 if (!prefName) return; |
| 552 if (*prefName == prefs::kShowHomeButton) { | 587 if (*prefName == prefs::kShowHomeButton) { |
| 553 [self showOptionalHomeButton]; | 588 [self showOptionalHomeButton]; |
| 554 } | 589 } |
| 555 } | 590 } |
| 556 | 591 |
| 557 - (void)createBrowserActionButtons { | 592 - (void)createBrowserActionButtons { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { | 793 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { |
| 759 // Do nothing. | 794 // Do nothing. |
| 760 } | 795 } |
| 761 | 796 |
| 762 // (URLDropTargetController protocol) | 797 // (URLDropTargetController protocol) |
| 763 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 798 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 764 // Do nothing. | 799 // Do nothing. |
| 765 } | 800 } |
| 766 | 801 |
| 767 @end | 802 @end |
| OLD | NEW |