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