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 enabling/disabling menu items and handling when | 98 // A C++ delegate that handles the accelerators in the wrench menu. |
99 // a menu command is chosen. | 99 class WrenchAcceleratorDelegate : public menus::AcceleratorProvider { |
100 class MenuDelegate : public menus::SimpleMenuModel::Delegate { | |
101 public: | 100 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 } | |
116 virtual bool GetAcceleratorForCommandId(int command_id, | 101 virtual bool GetAcceleratorForCommandId(int command_id, |
117 menus::Accelerator* accelerator_generic) { | 102 menus::Accelerator* accelerator_generic) { |
118 // Downcast so that when the copy constructor is invoked below, the key | 103 // Downcast so that when the copy constructor is invoked below, the key |
119 // string gets copied, too. | 104 // string gets copied, too. |
120 menus::AcceleratorCocoa* out_accelerator = | 105 menus::AcceleratorCocoa* out_accelerator = |
121 static_cast<menus::AcceleratorCocoa*>(accelerator_generic); | 106 static_cast<menus::AcceleratorCocoa*>(accelerator_generic); |
122 AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); | 107 AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); |
123 const menus::AcceleratorCocoa* accelerator = | 108 const menus::AcceleratorCocoa* accelerator = |
124 keymap->GetAcceleratorForCommand(command_id); | 109 keymap->GetAcceleratorForCommand(command_id); |
125 if (accelerator) { | 110 if (accelerator) { |
126 *out_accelerator = *accelerator; | 111 *out_accelerator = *accelerator; |
127 return true; | 112 return true; |
128 } | 113 } |
129 return false; | 114 return false; |
130 } | 115 } |
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_; | |
151 }; | 116 }; |
152 | 117 |
153 // A class registered for C++ notifications. This is used to detect changes in | 118 // A class registered for C++ notifications. This is used to detect changes in |
154 // preferences and upgrade available notifications. Bridges the notification | 119 // preferences and upgrade available notifications. Bridges the notification |
155 // back to the ToolbarController. | 120 // back to the ToolbarController. |
156 class NotificationBridge : public NotificationObserver { | 121 class NotificationBridge : public NotificationObserver { |
157 public: | 122 public: |
158 explicit NotificationBridge(ToolbarController* controller) | 123 explicit NotificationBridge(ToolbarController* controller) |
159 : controller_(controller) { | 124 : controller_(controller) { |
160 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, | 125 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 505 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
541 byAmount:moveX]]; | 506 byAmount:moveX]]; |
542 [homeButton_ setHidden:hide]; | 507 [homeButton_ setHidden:hide]; |
543 } | 508 } |
544 | 509 |
545 // Install the menu wrench buttons. Calling this repeatedly is inexpensive so it | 510 // Install the menu wrench buttons. Calling this repeatedly is inexpensive so it |
546 // can be done every time the buttons are shown. | 511 // can be done every time the buttons are shown. |
547 - (void)installWrenchMenu { | 512 - (void)installWrenchMenu { |
548 if (wrenchMenuModel_.get()) | 513 if (wrenchMenuModel_.get()) |
549 return; | 514 return; |
550 menuDelegate_.reset(new ToolbarControllerInternal::MenuDelegate(browser_)); | 515 acceleratorDelegate_.reset( |
516 new ToolbarControllerInternal::WrenchAcceleratorDelegate()); | |
551 | 517 |
552 wrenchMenuModel_.reset(new WrenchMenuModel(menuDelegate_.get(), browser_)); | 518 wrenchMenuModel_.reset(new WrenchMenuModel( |
553 [wrenchMenuController_ setModel:wrenchMenuModel_.get()]; | 519 acceleratorDelegate_.get(), browser_)); |
520 [wrenchMenuController_ setWrenchMenuModel:wrenchMenuModel_.get()]; | |
554 [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; | 521 [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; |
555 [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; | 522 [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; |
556 } | 523 } |
557 | 524 |
558 - (WrenchMenuController*)wrenchMenuController { | 525 - (WrenchMenuController*)wrenchMenuController { |
559 return wrenchMenuController_; | 526 return wrenchMenuController_; |
560 } | 527 } |
561 | 528 |
562 - (void)badgeWrenchMenu { | 529 - (void)badgeWrenchMenu { |
563 // In the Windows version, the ball doesn't actually pulsate, and is always | 530 // In the Windows version, the ball doesn't actually pulsate, and is always |
564 // drawn with the inactive image. Why? (We follow suit, though not on the | 531 // drawn with the inactive image. Why? (We follow suit, though not on the |
565 // weird positioning they do that overlaps the button border.) | 532 // weird positioning they do that overlaps the button border.) |
566 NSImage* badge = nsimage_cache::ImageNamed(@"upgrade_dot.pdf"); | 533 NSImage* badge = nsimage_cache::ImageNamed(@"upgrade_dot.pdf"); |
567 NSImage* wrenchImage = nsimage_cache::ImageNamed(kWrenchButtonImageName); | 534 NSImage* wrenchImage = nsimage_cache::ImageNamed(kWrenchButtonImageName); |
568 NSSize wrenchImageSize = [wrenchImage size]; | 535 NSSize wrenchImageSize = [wrenchImage size]; |
569 | 536 |
570 scoped_nsobject<NSImage> overlayImage( | 537 scoped_nsobject<NSImage> overlayImage( |
571 [[NSImage alloc] initWithSize:wrenchImageSize]); | 538 [[NSImage alloc] initWithSize:wrenchImageSize]); |
572 | 539 |
573 [overlayImage lockFocus]; | 540 [overlayImage lockFocus]; |
574 [badge drawAtPoint:NSZeroPoint | 541 [badge drawAtPoint:NSZeroPoint |
575 fromRect:NSZeroRect | 542 fromRect:NSZeroRect |
576 operation:NSCompositeSourceOver | 543 operation:NSCompositeSourceOver |
577 fraction:1.0]; | 544 fraction:1.0]; |
578 [overlayImage unlockFocus]; | 545 [overlayImage unlockFocus]; |
579 | 546 |
580 [[wrenchButton_ cell] setOverlayImage:overlayImage]; | 547 [[wrenchButton_ cell] setOverlayImage:overlayImage]; |
581 | |
582 [wrenchMenuController_ insertUpdateAvailableItem]; | |
Robert Sesek
2010/08/24 00:31:13
Removing this concerns me. Does this break the up
| |
583 } | 548 } |
584 | 549 |
585 - (void)prefChanged:(std::string*)prefName { | 550 - (void)prefChanged:(std::string*)prefName { |
586 if (!prefName) return; | 551 if (!prefName) return; |
587 if (*prefName == prefs::kShowHomeButton) { | 552 if (*prefName == prefs::kShowHomeButton) { |
588 [self showOptionalHomeButton]; | 553 [self showOptionalHomeButton]; |
589 } | 554 } |
590 } | 555 } |
591 | 556 |
592 - (void)createBrowserActionButtons { | 557 - (void)createBrowserActionButtons { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { | 758 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { |
794 // Do nothing. | 759 // Do nothing. |
795 } | 760 } |
796 | 761 |
797 // (URLDropTargetController protocol) | 762 // (URLDropTargetController protocol) |
798 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 763 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
799 // Do nothing. | 764 // Do nothing. |
800 } | 765 } |
801 | 766 |
802 @end | 767 @end |
OLD | NEW |