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/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/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 const CGFloat kMinimumLocationBarWidth = 100.0; | 74 const CGFloat kMinimumLocationBarWidth = 100.0; |
75 | 75 |
76 // The duration of any animation that occurs within the toolbar in seconds. | 76 // The duration of any animation that occurs within the toolbar in seconds. |
77 const CGFloat kAnimationDuration = 0.2; | 77 const CGFloat kAnimationDuration = 0.2; |
78 | 78 |
79 // The amount of left padding that the wrench menu should have. | 79 // The amount of left padding that the wrench menu should have. |
80 const CGFloat kWrenchMenuLeftPadding = 3.0; | 80 const CGFloat kWrenchMenuLeftPadding = 3.0; |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 @interface ToolbarController(Private) | 84 @interface ToolbarController() |
85 - (void)addAccessibilityDescriptions; | 85 - (void)addAccessibilityDescriptions; |
86 - (void)initCommandStatus:(CommandUpdater*)commands; | 86 - (void)initCommandStatus:(CommandUpdater*)commands; |
87 - (void)prefChanged:(std::string*)prefName; | 87 - (void)prefChanged:(std::string*)prefName; |
88 - (BackgroundGradientView*)backgroundGradientView; | 88 - (BackgroundGradientView*)backgroundGradientView; |
89 - (void)toolbarFrameChanged; | 89 - (void)toolbarFrameChanged; |
90 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 90 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
91 - (void)maintainMinimumLocationBarWidth; | 91 - (void)maintainMinimumLocationBarWidth; |
92 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 92 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
93 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 93 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
94 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; | 94 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; |
95 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 95 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
96 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 96 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
97 - (void)badgeWrenchMenuIfNeeded; | 97 - (void)badgeWrenchMenuIfNeeded; |
98 | |
99 @property(assign, nonatomic) Browser* browser; | |
Robert Sesek
2011/09/19 18:57:36
@property goes above method declarations
sail
2011/09/19 19:19:59
Done.
| |
100 | |
98 @end | 101 @end |
99 | 102 |
100 namespace ToolbarControllerInternal { | 103 namespace ToolbarControllerInternal { |
101 | 104 |
102 // A C++ delegate that handles the accelerators in the wrench menu. | 105 // A C++ delegate that handles the accelerators in the wrench menu. |
103 class WrenchAcceleratorDelegate : public ui::AcceleratorProvider { | 106 class WrenchAcceleratorDelegate : public ui::AcceleratorProvider { |
104 public: | 107 public: |
105 virtual bool GetAcceleratorForCommandId(int command_id, | 108 virtual bool GetAcceleratorForCommandId(int command_id, |
106 ui::Accelerator* accelerator_generic) { | 109 ui::Accelerator* accelerator_generic) { |
107 // Downcast so that when the copy constructor is invoked below, the key | 110 // Downcast so that when the copy constructor is invoked below, the key |
(...skipping 13 matching lines...) Expand all Loading... | |
121 | 124 |
122 // A class registered for C++ notifications. This is used to detect changes in | 125 // A class registered for C++ notifications. This is used to detect changes in |
123 // preferences and upgrade available notifications. Bridges the notification | 126 // preferences and upgrade available notifications. Bridges the notification |
124 // back to the ToolbarController. | 127 // back to the ToolbarController. |
125 class NotificationBridge : public NotificationObserver { | 128 class NotificationBridge : public NotificationObserver { |
126 public: | 129 public: |
127 explicit NotificationBridge(ToolbarController* controller) | 130 explicit NotificationBridge(ToolbarController* controller) |
128 : controller_(controller) { | 131 : controller_(controller) { |
129 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 132 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
130 NotificationService::AllSources()); | 133 NotificationService::AllSources()); |
134 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | |
135 Source<Profile>([controller browser]->profile())); | |
131 } | 136 } |
132 | 137 |
133 // Overridden from NotificationObserver: | 138 // Overridden from NotificationObserver: |
134 virtual void Observe(int type, | 139 virtual void Observe(int type, |
135 const NotificationSource& source, | 140 const NotificationSource& source, |
136 const NotificationDetails& details) { | 141 const NotificationDetails& details) { |
137 switch (type) { | 142 switch (type) { |
138 case chrome::NOTIFICATION_PREF_CHANGED: | 143 case chrome::NOTIFICATION_PREF_CHANGED: |
139 [controller_ prefChanged:Details<std::string>(details).ptr()]; | 144 [controller_ prefChanged:Details<std::string>(details).ptr()]; |
140 break; | 145 break; |
141 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: | 146 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: |
147 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: | |
142 [controller_ badgeWrenchMenuIfNeeded]; | 148 [controller_ badgeWrenchMenuIfNeeded]; |
143 break; | 149 break; |
144 default: | 150 default: |
145 NOTREACHED(); | 151 NOTREACHED(); |
146 } | 152 } |
147 } | 153 } |
148 | 154 |
149 private: | 155 private: |
150 ToolbarController* controller_; // weak, owns us | 156 ToolbarController* controller_; // weak, owns us |
151 | 157 |
152 NotificationRegistrar registrar_; | 158 NotificationRegistrar registrar_; |
153 }; | 159 }; |
154 | 160 |
155 } // namespace ToolbarControllerInternal | 161 } // namespace ToolbarControllerInternal |
156 | 162 |
157 @implementation ToolbarController | 163 @implementation ToolbarController |
158 | 164 |
165 @synthesize browser = browser_; | |
166 | |
159 - (id)initWithModel:(ToolbarModel*)model | 167 - (id)initWithModel:(ToolbarModel*)model |
160 commands:(CommandUpdater*)commands | 168 commands:(CommandUpdater*)commands |
161 profile:(Profile*)profile | 169 profile:(Profile*)profile |
162 browser:(Browser*)browser | 170 browser:(Browser*)browser |
163 resizeDelegate:(id<ViewResizer>)resizeDelegate | 171 resizeDelegate:(id<ViewResizer>)resizeDelegate |
164 nibFileNamed:(NSString*)nibName { | 172 nibFileNamed:(NSString*)nibName { |
165 DCHECK(model && commands && profile && [nibName length]); | 173 DCHECK(model && commands && profile && [nibName length]); |
166 if ((self = [super initWithNibName:nibName | 174 if ((self = [super initWithNibName:nibName |
167 bundle:base::mac::MainAppBundle()])) { | 175 bundle:base::mac::MainAppBundle()])) { |
168 toolbarModel_ = model; | 176 toolbarModel_ = model; |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 813 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
806 // Do nothing. | 814 // Do nothing. |
807 } | 815 } |
808 | 816 |
809 // (URLDropTargetController protocol) | 817 // (URLDropTargetController protocol) |
810 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 818 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
811 return drag_util::IsUnsupportedDropData(profile_, info); | 819 return drag_util::IsUnsupportedDropData(profile_, info); |
812 } | 820 } |
813 | 821 |
814 @end | 822 @end |
OLD | NEW |