OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/toolbar/toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
35 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 35 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
36 #import "chrome/browser/ui/cocoa/menu_button.h" | 36 #import "chrome/browser/ui/cocoa/menu_button.h" |
37 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" | 37 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" |
38 #import "chrome/browser/ui/cocoa/toolbar/reload_button.h" | 38 #import "chrome/browser/ui/cocoa/toolbar/reload_button.h" |
39 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button.h" | 39 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button.h" |
40 #import "chrome/browser/ui/cocoa/toolbar/toolbar_view.h" | 40 #import "chrome/browser/ui/cocoa/toolbar/toolbar_view.h" |
41 #import "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h" | 41 #import "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h" |
42 #import "chrome/browser/ui/cocoa/view_id_util.h" | 42 #import "chrome/browser/ui/cocoa/view_id_util.h" |
43 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" | 43 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" |
44 #include "chrome/browser/ui/global_error/global_error_service.h" | |
45 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | |
46 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 44 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
47 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
48 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 46 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
49 #include "chrome/browser/upgrade_detector.h" | 47 #include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h" |
50 #include "chrome/common/pref_names.h" | 48 #include "chrome/common/pref_names.h" |
51 #include "components/metrics/proto/omnibox_event.pb.h" | 49 #include "components/metrics/proto/omnibox_event.pb.h" |
52 #include "components/search_engines/template_url_service.h" | 50 #include "components/search_engines/template_url_service.h" |
53 #include "components/url_fixer/url_fixer.h" | 51 #include "components/url_fixer/url_fixer.h" |
54 #include "content/public/browser/notification_details.h" | |
55 #include "content/public/browser/notification_observer.h" | |
56 #include "content/public/browser/notification_service.h" | |
57 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
58 #include "grit/chromium_strings.h" | 53 #include "grit/chromium_strings.h" |
59 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
60 #include "grit/theme_resources.h" | 55 #include "grit/theme_resources.h" |
61 #import "ui/base/cocoa/menu_controller.h" | 56 #import "ui/base/cocoa/menu_controller.h" |
62 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
63 #include "ui/base/l10n/l10n_util_mac.h" | 58 #include "ui/base/l10n/l10n_util_mac.h" |
64 #include "ui/base/resource/resource_bundle.h" | 59 #include "ui/base/resource/resource_bundle.h" |
65 #include "ui/gfx/image/image.h" | 60 #include "ui/gfx/image/image.h" |
66 #include "ui/gfx/rect.h" | 61 #include "ui/gfx/rect.h" |
(...skipping 25 matching lines...) Expand all Loading... |
92 - (void)prefChanged:(const std::string&)prefName; | 87 - (void)prefChanged:(const std::string&)prefName; |
93 - (BackgroundGradientView*)backgroundGradientView; | 88 - (BackgroundGradientView*)backgroundGradientView; |
94 - (void)toolbarFrameChanged; | 89 - (void)toolbarFrameChanged; |
95 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 90 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
96 - (void)maintainMinimumLocationBarWidth; | 91 - (void)maintainMinimumLocationBarWidth; |
97 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 92 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
98 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 93 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
99 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; | 94 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; |
100 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 95 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
101 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 96 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
102 - (void)updateWrenchButtonSeverity; | 97 - (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity |
| 98 animate:(BOOL)animate; |
103 @end | 99 @end |
104 | 100 |
105 namespace ToolbarControllerInternal { | 101 namespace ToolbarControllerInternal { |
106 | 102 |
107 // A class registered for C++ notifications. This is used to detect changes in | 103 // A class registered for C++ notifications. This is used to detect changes in |
108 // preferences and upgrade available notifications. Bridges the notification | 104 // preferences and upgrade available notifications. Bridges the notification |
109 // back to the ToolbarController. | 105 // back to the ToolbarController. |
110 class NotificationBridge | 106 class NotificationBridge : public WrenchMenuBadgeController::Delegate { |
111 : public content::NotificationObserver { | |
112 public: | 107 public: |
113 explicit NotificationBridge(ToolbarController* controller) | 108 explicit NotificationBridge(ToolbarController* controller) |
114 : controller_(controller) { | 109 : controller_(controller), |
115 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 110 badge_controller_([controller browser]->profile(), this) { |
116 content::NotificationService::AllSources()); | 111 } |
117 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 112 virtual ~NotificationBridge() { |
118 content::Source<Profile>([controller browser]->profile())); | |
119 } | 113 } |
120 | 114 |
121 // Overridden from content::NotificationObserver: | 115 void UpdateBadgeSeverity() { |
122 virtual void Observe(int type, | 116 badge_controller_.UpdateDelegate(); |
123 const content::NotificationSource& source, | 117 } |
124 const content::NotificationDetails& details) OVERRIDE { | 118 |
125 switch (type) { | 119 virtual void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type, |
126 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: | 120 WrenchIconPainter::Severity severity, |
127 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: | 121 bool animate) OVERRIDE { |
128 [controller_ updateWrenchButtonSeverity]; | 122 [controller_ updateWrenchButtonSeverity:severity animate:animate]; |
129 break; | |
130 default: | |
131 NOTREACHED(); | |
132 } | |
133 } | 123 } |
134 | 124 |
135 void OnPreferenceChanged(const std::string& pref_name) { | 125 void OnPreferenceChanged(const std::string& pref_name) { |
136 [controller_ prefChanged:pref_name]; | 126 [controller_ prefChanged:pref_name]; |
137 } | 127 } |
138 | 128 |
139 private: | 129 private: |
140 ToolbarController* controller_; // weak, owns us | 130 ToolbarController* controller_; // weak, owns us |
141 | 131 |
142 content::NotificationRegistrar registrar_; | 132 WrenchMenuBadgeController badge_controller_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(NotificationBridge); |
143 }; | 135 }; |
144 | 136 |
145 } // namespace ToolbarControllerInternal | 137 } // namespace ToolbarControllerInternal |
146 | 138 |
147 @implementation ToolbarController | 139 @implementation ToolbarController |
148 | 140 |
149 @synthesize browser = browser_; | 141 @synthesize browser = browser_; |
150 | 142 |
151 - (id)initWithCommands:(CommandUpdater*)commands | 143 - (id)initWithCommands:(CommandUpdater*)commands |
152 profile:(Profile*)profile | 144 profile:(Profile*)profile |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 [[homeButton_ cell] setImageID:IDR_HOME_P | 237 [[homeButton_ cell] setImageID:IDR_HOME_P |
246 forButtonState:image_button_cell::kPressedState]; | 238 forButtonState:image_button_cell::kPressedState]; |
247 | 239 |
248 [[wrenchButton_ cell] setImageID:IDR_TOOLS | 240 [[wrenchButton_ cell] setImageID:IDR_TOOLS |
249 forButtonState:image_button_cell::kDefaultState]; | 241 forButtonState:image_button_cell::kDefaultState]; |
250 [[wrenchButton_ cell] setImageID:IDR_TOOLS_H | 242 [[wrenchButton_ cell] setImageID:IDR_TOOLS_H |
251 forButtonState:image_button_cell::kHoverState]; | 243 forButtonState:image_button_cell::kHoverState]; |
252 [[wrenchButton_ cell] setImageID:IDR_TOOLS_P | 244 [[wrenchButton_ cell] setImageID:IDR_TOOLS_P |
253 forButtonState:image_button_cell::kPressedState]; | 245 forButtonState:image_button_cell::kPressedState]; |
254 | 246 |
255 [self updateWrenchButtonSeverity]; | 247 notificationBridge_.reset( |
| 248 new ToolbarControllerInternal::NotificationBridge(self)); |
| 249 notificationBridge_->UpdateBadgeSeverity(); |
256 | 250 |
257 [wrenchButton_ setOpenMenuOnClick:YES]; | 251 [wrenchButton_ setOpenMenuOnClick:YES]; |
258 | 252 |
259 [backButton_ setOpenMenuOnRightClick:YES]; | 253 [backButton_ setOpenMenuOnRightClick:YES]; |
260 [forwardButton_ setOpenMenuOnRightClick:YES]; | 254 [forwardButton_ setOpenMenuOnRightClick:YES]; |
261 | 255 |
262 [backButton_ setHandleMiddleClick:YES]; | 256 [backButton_ setHandleMiddleClick:YES]; |
263 [forwardButton_ setHandleMiddleClick:YES]; | 257 [forwardButton_ setHandleMiddleClick:YES]; |
264 [reloadButton_ setHandleMiddleClick:YES]; | 258 [reloadButton_ setHandleMiddleClick:YES]; |
265 [homeButton_ setHandleMiddleClick:YES]; | 259 [homeButton_ setHandleMiddleClick:YES]; |
266 | 260 |
267 [self initCommandStatus:commands_]; | 261 [self initCommandStatus:commands_]; |
268 | 262 |
269 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, | 263 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, |
270 profile_, browser_)); | 264 profile_, browser_)); |
271 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 265 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 266 |
272 // Register pref observers for the optional home and page/options buttons | 267 // Register pref observers for the optional home and page/options buttons |
273 // and then add them to the toolbar based on those prefs. | 268 // and then add them to the toolbar based on those prefs. |
274 notificationBridge_.reset( | |
275 new ToolbarControllerInternal::NotificationBridge(self)); | |
276 PrefService* prefs = profile_->GetPrefs(); | 269 PrefService* prefs = profile_->GetPrefs(); |
277 showHomeButton_.Init( | 270 showHomeButton_.Init( |
278 prefs::kShowHomeButton, prefs, | 271 prefs::kShowHomeButton, prefs, |
279 base::Bind( | 272 base::Bind( |
280 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, | 273 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, |
281 base::Unretained(notificationBridge_.get()))); | 274 base::Unretained(notificationBridge_.get()))); |
282 [self showOptionalHomeButton]; | 275 [self showOptionalHomeButton]; |
283 [self installWrenchMenu]; | 276 [self installWrenchMenu]; |
284 | 277 |
285 // Create the controllers for the back/forward menus. | 278 // Create the controllers for the back/forward menus. |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 wrenchMenuController_.reset( | 561 wrenchMenuController_.reset( |
569 [[WrenchMenuController alloc] initWithBrowser:browser_]); | 562 [[WrenchMenuController alloc] initWithBrowser:browser_]); |
570 [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; | 563 [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; |
571 [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; | 564 [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; |
572 } | 565 } |
573 | 566 |
574 - (WrenchMenuController*)wrenchMenuController { | 567 - (WrenchMenuController*)wrenchMenuController { |
575 return wrenchMenuController_; | 568 return wrenchMenuController_; |
576 } | 569 } |
577 | 570 |
578 - (void)updateWrenchButtonSeverity { | 571 - (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity |
| 572 animate:(BOOL)animate { |
579 WrenchToolbarButtonCell* cell = | 573 WrenchToolbarButtonCell* cell = |
580 base::mac::ObjCCastStrict<WrenchToolbarButtonCell>([wrenchButton_ cell]); | 574 base::mac::ObjCCastStrict<WrenchToolbarButtonCell>([wrenchButton_ cell]); |
581 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | 575 [cell setSeverity:severity shouldAnimate:animate]; |
582 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = | |
583 UpgradeDetector::GetInstance()->upgrade_notification_stage(); | |
584 [cell setSeverity:WrenchIconPainter::SeverityFromUpgradeLevel(level) | |
585 shouldAnimate:WrenchIconPainter::ShouldAnimateUpgradeLevel(level)]; | |
586 return; | |
587 } | |
588 | |
589 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( | |
590 browser_->profile())->GetHighestSeverityGlobalErrorWithWrenchMenuItem(); | |
591 if (error) { | |
592 [cell setSeverity:WrenchIconPainter::GlobalErrorSeverity() | |
593 shouldAnimate:YES]; | |
594 return; | |
595 } | |
596 | |
597 [cell setSeverity:WrenchIconPainter::SEVERITY_NONE shouldAnimate:YES]; | |
598 } | 576 } |
599 | 577 |
600 - (void)prefChanged:(const std::string&)prefName { | 578 - (void)prefChanged:(const std::string&)prefName { |
601 if (prefName == prefs::kShowHomeButton) { | 579 if (prefName == prefs::kShowHomeButton) { |
602 [self showOptionalHomeButton]; | 580 [self showOptionalHomeButton]; |
603 } | 581 } |
604 } | 582 } |
605 | 583 |
606 - (void)createBrowserActionButtons { | 584 - (void)createBrowserActionButtons { |
607 if (!browserActionsController_.get()) { | 585 if (!browserActionsController_.get()) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 832 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
855 // Do nothing. | 833 // Do nothing. |
856 } | 834 } |
857 | 835 |
858 // (URLDropTargetController protocol) | 836 // (URLDropTargetController protocol) |
859 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 837 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
860 return drag_util::IsUnsupportedDropData(profile_, info); | 838 return drag_util::IsUnsupportedDropData(profile_, info); |
861 } | 839 } |
862 | 840 |
863 @end | 841 @end |
OLD | NEW |