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_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
6 #define CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 6 #define CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "chrome/browser/extensions/extension_toolbar_model.h" |
11 #include "chrome/browser/extensions/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/image_loading_tracker.h" |
12 #include "chrome/browser/views/browser_bubble.h" | 13 #include "chrome/browser/views/browser_bubble.h" |
13 #include "chrome/browser/views/extensions/extension_action_context_menu.h" | 14 #include "chrome/browser/views/extensions/extension_action_context_menu.h" |
14 #include "chrome/common/notification_observer.h" | 15 #include "chrome/common/notification_observer.h" |
15 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
16 #include "views/controls/button/menu_button.h" | 17 #include "views/controls/button/menu_button.h" |
17 #include "views/controls/menu/view_menu_delegate.h" | 18 #include "views/controls/menu/view_menu_delegate.h" |
18 #include "views/controls/resize_gripper.h" | 19 #include "views/controls/resize_gripper.h" |
19 #include "views/view.h" | 20 #include "views/view.h" |
20 | 21 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // animation ends and we don't want the chevron to flash into view while we are | 211 // animation ends and we don't want the chevron to flash into view while we are |
211 // growing the container. | 212 // growing the container. |
212 // | 213 // |
213 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
214 class BrowserActionsContainer | 215 class BrowserActionsContainer |
215 : public views::View, | 216 : public views::View, |
216 public NotificationObserver, | 217 public NotificationObserver, |
217 public BrowserBubble::Delegate, | 218 public BrowserBubble::Delegate, |
218 public views::ViewMenuDelegate, | 219 public views::ViewMenuDelegate, |
219 public views::ResizeGripper::ResizeGripperDelegate, | 220 public views::ResizeGripper::ResizeGripperDelegate, |
220 public AnimationDelegate { | 221 public AnimationDelegate, |
| 222 public ExtensionToolbarModel::Observer { |
221 public: | 223 public: |
222 BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); | 224 BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); |
223 virtual ~BrowserActionsContainer(); | 225 virtual ~BrowserActionsContainer(); |
224 | 226 |
225 static void RegisterUserPrefs(PrefService* prefs); | 227 static void RegisterUserPrefs(PrefService* prefs); |
226 | 228 |
227 // Get the number of browser actions being displayed. | 229 // Get the number of browser actions being displayed. |
228 int num_browser_actions() const { return browser_action_views_.size(); } | 230 int num_browser_actions() const { return browser_action_views_.size(); } |
229 | 231 |
230 // Whether we are performing resize animation on the container. | 232 // Whether we are performing resize animation on the container. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 void HidePopup(); | 292 void HidePopup(); |
291 | 293 |
292 // Simulate a click on a browser action button. This should only be | 294 // Simulate a click on a browser action button. This should only be |
293 // used by unit tests. | 295 // used by unit tests. |
294 void TestExecuteBrowserAction(int index); | 296 void TestExecuteBrowserAction(int index); |
295 | 297 |
296 // Retrieve the current popup. This should only be used by unit tests. | 298 // Retrieve the current popup. This should only be used by unit tests. |
297 ExtensionPopup* TestGetPopup() { return popup_; } | 299 ExtensionPopup* TestGetPopup() { return popup_; } |
298 | 300 |
299 private: | 301 private: |
300 // Adds a browser action view for the extension if it needs one. DCHECK if | 302 // ExtensionToolbarModel::Observer implementation. |
301 // it has already been added. | 303 virtual void BrowserActionAdded(Extension* extension, int index); |
302 void AddBrowserAction(Extension* extension); | 304 virtual void BrowserActionRemoved(Extension* extension); |
303 | |
304 // Removes the browser action view for an extension if it has one. DCHECK if | |
305 // no such view. | |
306 void RemoveBrowserAction(Extension* extension); | |
307 | 305 |
308 // Closes the overflow menu if open. | 306 // Closes the overflow menu if open. |
309 void CloseOverflowMenu(); | 307 void CloseOverflowMenu(); |
310 | 308 |
311 // Takes a width in pixels, calculates how many icons fit within that space | 309 // Takes a width in pixels, calculates how many icons fit within that space |
312 // (up to the maximum number of icons in our vector) and shaves off the | 310 // (up to the maximum number of icons in our vector) and shaves off the |
313 // excess pixels. | 311 // excess pixels. |
314 int ClampToNearestIconCount(int pixels) const; | 312 int ClampToNearestIconCount(int pixels) const; |
315 | 313 |
316 // Calculates the width of the container area NOT used to show the icons (the | 314 // Calculates the width of the container area NOT used to show the icons (the |
(...skipping 22 matching lines...) Expand all Loading... |
339 // The toolbar that owns us. | 337 // The toolbar that owns us. |
340 ToolbarView* toolbar_; | 338 ToolbarView* toolbar_; |
341 | 339 |
342 // The current popup and the button it came from. NULL if no popup. | 340 // The current popup and the button it came from. NULL if no popup. |
343 ExtensionPopup* popup_; | 341 ExtensionPopup* popup_; |
344 | 342 |
345 // The button that triggered the current popup (just a reference to a button | 343 // The button that triggered the current popup (just a reference to a button |
346 // from browser_action_views_). | 344 // from browser_action_views_). |
347 BrowserActionButton* popup_button_; | 345 BrowserActionButton* popup_button_; |
348 | 346 |
| 347 // The model that tracks the order of the toolbar icons. |
| 348 ExtensionToolbarModel* model_; |
| 349 |
349 // The current size of the container. | 350 // The current size of the container. |
350 gfx::Size container_size_; | 351 gfx::Size container_size_; |
351 | 352 |
352 // The resize gripper for the container. | 353 // The resize gripper for the container. |
353 views::ResizeGripper* resize_gripper_; | 354 views::ResizeGripper* resize_gripper_; |
354 | 355 |
355 // The chevron for accessing the overflow items. | 356 // The chevron for accessing the overflow items. |
356 views::MenuButton* chevron_; | 357 views::MenuButton* chevron_; |
357 | 358 |
358 // The menu to show for the overflow button (chevron). | 359 // The menu to show for the overflow button (chevron). |
(...skipping 13 matching lines...) Expand all Loading... |
372 // Keeps track of the absolute pixel width the container should have when we | 373 // Keeps track of the absolute pixel width the container should have when we |
373 // are done animating. | 374 // are done animating. |
374 int animation_target_size_; | 375 int animation_target_size_; |
375 | 376 |
376 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 377 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |
377 | 378 |
378 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 379 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
379 }; | 380 }; |
380 | 381 |
381 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 382 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
OLD | NEW |