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 #ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ | 5 #ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ |
6 #define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ | 6 #define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #import <Cocoa/Cocoa.h> | 12 #import <Cocoa/Cocoa.h> |
13 | 13 |
14 #include "base/scoped_nsobject.h" | 14 #include "base/scoped_nsobject.h" |
15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
16 #include "base/scoped_vector.h" | 16 #include "base/scoped_vector.h" |
17 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 17 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
18 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 18 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
19 #include "chrome/browser/extensions/image_loading_tracker.h" | 19 #include "chrome/browser/extensions/image_loading_tracker.h" |
20 #include "chrome/browser/first_run.h" | 20 #include "chrome/browser/first_run.h" |
21 #include "chrome/browser/location_bar.h" | 21 #include "chrome/browser/location_bar.h" |
22 #include "chrome/browser/toolbar_model.h" | 22 #include "chrome/browser/toolbar_model.h" |
23 #include "chrome/common/content_settings_types.h" | 23 #include "chrome/common/content_settings_types.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
25 | 25 |
26 @class AutocompleteTextField; | 26 @class AutocompleteTextField; |
27 class CommandUpdater; | 27 class CommandUpdater; |
| 28 class ContentSettingDecoration; |
28 class ContentSettingImageModel; | 29 class ContentSettingImageModel; |
29 class EVBubbleDecoration; | 30 class EVBubbleDecoration; |
30 @class ExtensionPopupController; | 31 @class ExtensionPopupController; |
31 class LocationIconDecoration; | 32 class LocationIconDecoration; |
32 class PageActionDecoration; | 33 class PageActionDecoration; |
33 class Profile; | 34 class Profile; |
34 class SelectedKeywordDecoration; | 35 class SelectedKeywordDecoration; |
35 class StarDecoration; | 36 class StarDecoration; |
36 class ToolbarModel; | 37 class ToolbarModel; |
37 | 38 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 NSImage* GetTabButtonImage(); | 129 NSImage* GetTabButtonImage(); |
129 NSImage* GetKeywordImage(const std::wstring& keyword); | 130 NSImage* GetKeywordImage(const std::wstring& keyword); |
130 AutocompleteTextField* GetAutocompleteTextField() { return field_; } | 131 AutocompleteTextField* GetAutocompleteTextField() { return field_; } |
131 | 132 |
132 | 133 |
133 // Overridden from NotificationObserver. | 134 // Overridden from NotificationObserver. |
134 virtual void Observe(NotificationType type, | 135 virtual void Observe(NotificationType type, |
135 const NotificationSource& source, | 136 const NotificationSource& source, |
136 const NotificationDetails& details); | 137 const NotificationDetails& details); |
137 | 138 |
138 // Used to display a clickable icon in the location bar. | |
139 class LocationBarImageView { | |
140 public: | |
141 explicit LocationBarImageView() : image_(nil), | |
142 label_(nil), | |
143 visible_(false) {} | |
144 virtual ~LocationBarImageView() {} | |
145 | |
146 // Sets the image. | |
147 void SetImage(NSImage* image); | |
148 | |
149 // Get the |resource_id| image resource and set the image. | |
150 void SetIcon(int resource_id); | |
151 | |
152 // Sets the label text, font, and color. |text| may be nil; |color| and | |
153 // |font| are ignored if |text| is nil. | |
154 void SetLabel(NSString* text, NSFont* baseFont, NSColor* color); | |
155 | |
156 // Sets the visibility. SetImage() should be called with a valid image | |
157 // before the visibility is set to |true|. | |
158 void SetVisible(bool visible); | |
159 | |
160 NSImage* GetImage() const { return image_; } | |
161 NSAttributedString* GetLabel() const { return label_; } | |
162 bool IsVisible() const { return visible_; } | |
163 | |
164 // Default size when no image is present. | |
165 virtual NSSize GetDefaultImageSize() const; | |
166 | |
167 // Returns the size of the image, else the default size. | |
168 NSSize GetImageSize() const; | |
169 | |
170 // Returns the tooltip for this image view or |nil| if there is none. | |
171 virtual NSString* GetToolTip() { return nil; } | |
172 | |
173 // Used to determinate if the item can act as a drag source. | |
174 virtual bool IsDraggable() { return false; } | |
175 | |
176 // The drag pasteboard to use if a drag is initiated. | |
177 virtual NSPasteboard* GetDragPasteboard() { return nil; } | |
178 | |
179 // Called on mouse down. | |
180 virtual void OnMousePressed(NSRect bounds) {} | |
181 | |
182 // Called to get the icon's context menu. Return |nil| for no menu. | |
183 virtual NSMenu* GetMenu() { return nil; } | |
184 | |
185 private: | |
186 scoped_nsobject<NSImage> image_; | |
187 | |
188 // The label shown next to the icon, or nil if none. | |
189 scoped_nsobject<NSAttributedString> label_; | |
190 | |
191 bool visible_; | |
192 | |
193 DISALLOW_COPY_AND_ASSIGN(LocationBarImageView); | |
194 }; | |
195 | |
196 // ContentSettingImageView is used to display the content settings images | |
197 // on the current page. | |
198 class ContentSettingImageView : public LocationBarImageView { | |
199 public: | |
200 ContentSettingImageView(ContentSettingsType settings_type, | |
201 LocationBarViewMac* owner, | |
202 Profile* profile); | |
203 virtual ~ContentSettingImageView(); | |
204 | |
205 // Shows a content settings bubble. | |
206 void OnMousePressed(NSRect bounds); | |
207 | |
208 // Updates the image and visibility state based on the supplied TabContents. | |
209 void UpdateFromTabContents(const TabContents* tab_contents); | |
210 | |
211 // Returns the tooltip for this Page Action image or |nil| if there is none. | |
212 virtual NSString* GetToolTip(); | |
213 | |
214 private: | |
215 void SetToolTip(NSString* tooltip); | |
216 | |
217 scoped_ptr<ContentSettingImageModel> content_setting_image_model_; | |
218 | |
219 LocationBarViewMac* owner_; | |
220 Profile* profile_; | |
221 scoped_nsobject<NSString> tooltip_; | |
222 | |
223 DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView); | |
224 }; | |
225 typedef ScopedVector<ContentSettingImageView> ContentSettingViews; | |
226 | |
227 private: | 139 private: |
228 // Posts |notification| to the default notification center. | 140 // Posts |notification| to the default notification center. |
229 void PostNotification(NSString* notification); | 141 void PostNotification(NSString* notification); |
230 | 142 |
231 // Return the decoration for |page_action|. | 143 // Return the decoration for |page_action|. |
232 PageActionDecoration* GetPageActionDecoration(ExtensionAction* page_action); | 144 PageActionDecoration* GetPageActionDecoration(ExtensionAction* page_action); |
233 | 145 |
234 // Clear the page-action decorations. | 146 // Clear the page-action decorations. |
235 void DeletePageActionDecorations(); | 147 void DeletePageActionDecorations(); |
236 | 148 |
237 // Re-generate the page-action decorations from the profile's | 149 // Re-generate the page-action decorations from the profile's |
238 // extension service. | 150 // extension service. |
239 void RefreshPageActionDecorations(); | 151 void RefreshPageActionDecorations(); |
240 | 152 |
241 // Updates visibility of the content settings icons based on the current | 153 // Updates visibility of the content settings icons based on the current |
242 // tab contents state. | 154 // tab contents state. |
243 void RefreshContentSettingsViews(); | 155 void RefreshContentSettingsDecorations(); |
244 | 156 |
245 void ShowFirstRunBubbleInternal(FirstRun::BubbleType bubble_type); | 157 void ShowFirstRunBubbleInternal(FirstRun::BubbleType bubble_type); |
246 | 158 |
247 scoped_ptr<AutocompleteEditViewMac> edit_view_; | 159 scoped_ptr<AutocompleteEditViewMac> edit_view_; |
248 | 160 |
249 CommandUpdater* command_updater_; // Weak, owned by Browser. | 161 CommandUpdater* command_updater_; // Weak, owned by Browser. |
250 | 162 |
251 AutocompleteTextField* field_; // owned by tab controller | 163 AutocompleteTextField* field_; // owned by tab controller |
252 | 164 |
253 // When we get an OnAutocompleteAccept notification from the autocomplete | 165 // When we get an OnAutocompleteAccept notification from the autocomplete |
(...skipping 13 matching lines...) Expand all Loading... |
267 // A decoration that shows a lock icon and ev-cert label in a bubble | 179 // A decoration that shows a lock icon and ev-cert label in a bubble |
268 // on the left. | 180 // on the left. |
269 scoped_ptr<EVBubbleDecoration> ev_bubble_decoration_; | 181 scoped_ptr<EVBubbleDecoration> ev_bubble_decoration_; |
270 | 182 |
271 // Bookmark star right of page actions. | 183 // Bookmark star right of page actions. |
272 scoped_ptr<StarDecoration> star_decoration_; | 184 scoped_ptr<StarDecoration> star_decoration_; |
273 | 185 |
274 // Any installed Page Actions. | 186 // Any installed Page Actions. |
275 ScopedVector<PageActionDecoration> page_action_decorations_; | 187 ScopedVector<PageActionDecoration> page_action_decorations_; |
276 | 188 |
277 // The content blocked views. | 189 // The content blocked decorations. |
278 ContentSettingViews content_setting_views_; | 190 ScopedVector<ContentSettingDecoration> content_setting_decorations_; |
279 | 191 |
280 Profile* profile_; | 192 Profile* profile_; |
281 | 193 |
282 Browser* browser_; | 194 Browser* browser_; |
283 | 195 |
284 ToolbarModel* toolbar_model_; // Weak, owned by Browser. | 196 ToolbarModel* toolbar_model_; // Weak, owned by Browser. |
285 | 197 |
286 // Image used in drawing keyword hint. | 198 // Image used in drawing keyword hint. |
287 scoped_nsobject<NSImage> tab_button_image_; | 199 scoped_nsobject<NSImage> tab_button_image_; |
288 | 200 |
289 // The transition type to use for the navigation. | 201 // The transition type to use for the navigation. |
290 PageTransition::Type transition_; | 202 PageTransition::Type transition_; |
291 | 203 |
292 // Used to register for notifications received by NotificationObserver. | 204 // Used to register for notifications received by NotificationObserver. |
293 NotificationRegistrar registrar_; | 205 NotificationRegistrar registrar_; |
294 | 206 |
295 // Used to schedule a task for the first run info bubble. | 207 // Used to schedule a task for the first run info bubble. |
296 ScopedRunnableMethodFactory<LocationBarViewMac> first_run_bubble_; | 208 ScopedRunnableMethodFactory<LocationBarViewMac> first_run_bubble_; |
297 | 209 |
298 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac); | 210 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac); |
299 }; | 211 }; |
300 | 212 |
301 #endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ | 213 #endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ |
OLD | NEW |