| 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/extension_toolbar_model.h" |
| 12 #include "chrome/browser/extensions/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 13 #include "chrome/browser/views/browser_bubble.h" | 13 #include "chrome/browser/views/browser_bubble.h" |
| 14 #include "chrome/browser/views/extensions/extension_action_context_menu.h" | 14 #include "chrome/browser/views/extensions/extension_action_context_menu.h" |
| 15 #include "chrome/common/notification_observer.h" | 15 #include "chrome/common/notification_observer.h" |
| 16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
| 17 #include "views/controls/button/menu_button.h" | 17 #include "views/controls/button/menu_button.h" |
| 18 #include "views/controls/menu/view_menu_delegate.h" | 18 #include "views/controls/menu/view_menu_delegate.h" |
| 19 #include "views/controls/resize_gripper.h" | 19 #include "views/controls/resize_gripper.h" |
| 20 #include "views/view.h" | 20 #include "views/view.h" |
| 21 | 21 |
| 22 class BrowserActionOverflowMenuController; |
| 22 class BrowserActionsContainer; | 23 class BrowserActionsContainer; |
| 23 class BrowserActionOverflowMenuController; | |
| 24 class Extension; | 24 class Extension; |
| 25 class ExtensionAction; | 25 class ExtensionAction; |
| 26 class ExtensionPopup; | 26 class ExtensionPopup; |
| 27 class PrefService; | 27 class PrefService; |
| 28 class Profile; | 28 class Profile; |
| 29 class SlideAnimation; | 29 class SlideAnimation; |
| 30 class ToolbarView; | 30 class ToolbarView; |
| 31 | 31 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
| 33 // BrowserActionButton | 33 // BrowserActionButton |
| 34 | 34 |
| 35 // The BrowserActionButton is a specialization of the MenuButton class. | 35 // The BrowserActionButton is a specialization of the MenuButton class. |
| 36 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 36 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
| 37 // loading the image for the button asynchronously on the file thread. | 37 // loading the image for the button asynchronously on the file thread. |
| 38 class BrowserActionButton : public views::MenuButton, | 38 class BrowserActionButton : public views::MenuButton, |
| 39 public views::ButtonListener, | 39 public views::ButtonListener, |
| 40 public ImageLoadingTracker::Observer, | 40 public ImageLoadingTracker::Observer, |
| 41 public NotificationObserver { | 41 public NotificationObserver { |
| 42 public: | 42 public: |
| 43 BrowserActionButton(Extension* extension, BrowserActionsContainer* panel); | 43 BrowserActionButton(Extension* extension, BrowserActionsContainer* panel); |
| 44 ~BrowserActionButton(); | 44 ~BrowserActionButton(); |
| 45 | 45 |
| 46 ExtensionAction* browser_action() const { return browser_action_; } | 46 ExtensionAction* browser_action() const { return browser_action_; } |
| 47 Extension* extension() { return extension_; } | 47 Extension* extension() { return extension_; } |
| 48 | 48 |
| 49 // Called to update the display to match the browser action's state. | 49 // Called to update the display to match the browser action's state. |
| 50 void UpdateState(); | 50 void UpdateState(); |
| 51 | 51 |
| 52 // Returns the default icon, if any. |
| 53 const SkBitmap& default_icon() const { return default_icon_; } |
| 54 |
| 52 // Overridden from views::View. Return a 0-inset so the icon can draw all the | 55 // Overridden from views::View. Return a 0-inset so the icon can draw all the |
| 53 // way to the edge of the view if it wants. | 56 // way to the edge of the view if it wants. |
| 54 virtual gfx::Insets GetInsets() const; | 57 virtual gfx::Insets GetInsets() const; |
| 55 | 58 |
| 56 // Overridden from views::ButtonListener: | 59 // Overridden from views::ButtonListener: |
| 57 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 60 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 58 | 61 |
| 59 // Overridden from ImageLoadingTracker. | 62 // Overridden from ImageLoadingTracker. |
| 60 virtual void OnImageLoaded(SkBitmap* image, size_t index); | 63 virtual void OnImageLoaded(SkBitmap* image, size_t index); |
| 61 | 64 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 virtual void Layout(); | 133 virtual void Layout(); |
| 131 | 134 |
| 132 // Override PaintChildren so that we can paint the badge on top of children. | 135 // Override PaintChildren so that we can paint the badge on top of children. |
| 133 virtual void PaintChildren(gfx::Canvas* canvas); | 136 virtual void PaintChildren(gfx::Canvas* canvas); |
| 134 | 137 |
| 135 // The container for this view. | 138 // The container for this view. |
| 136 BrowserActionsContainer* panel_; | 139 BrowserActionsContainer* panel_; |
| 137 | 140 |
| 138 // The button this view contains. | 141 // The button this view contains. |
| 139 BrowserActionButton* button_; | 142 BrowserActionButton* button_; |
| 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
| 140 }; | 145 }; |
| 141 | 146 |
| 142 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
| 143 // | 148 // |
| 144 // The BrowserActionsContainer is a container view, responsible for drawing the | 149 // The BrowserActionsContainer is a container view, responsible for drawing the |
| 145 // browser action icons (extensions that add icons to the toolbar). | 150 // browser action icons (extensions that add icons to the toolbar). |
| 146 // | 151 // |
| 147 // The BrowserActionsContainer (when it contains one or more icons) consists of | 152 // The BrowserActionsContainer (when it contains one or more icons) consists of |
| 148 // the following elements, numbered as seen below the line: | 153 // the following elements, numbered as seen below the line: |
| 149 // | 154 // |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // because we won't have enough space to show the new Browser Action until the | 215 // because we won't have enough space to show the new Browser Action until the |
| 211 // animation ends and we don't want the chevron to flash into view while we are | 216 // animation ends and we don't want the chevron to flash into view while we are |
| 212 // growing the container. | 217 // growing the container. |
| 213 // | 218 // |
| 214 //////////////////////////////////////////////////////////////////////////////// | 219 //////////////////////////////////////////////////////////////////////////////// |
| 215 class BrowserActionsContainer | 220 class BrowserActionsContainer |
| 216 : public views::View, | 221 : public views::View, |
| 217 public NotificationObserver, | 222 public NotificationObserver, |
| 218 public BrowserBubble::Delegate, | 223 public BrowserBubble::Delegate, |
| 219 public views::ViewMenuDelegate, | 224 public views::ViewMenuDelegate, |
| 225 public views::DragController, |
| 220 public views::ResizeGripper::ResizeGripperDelegate, | 226 public views::ResizeGripper::ResizeGripperDelegate, |
| 221 public AnimationDelegate, | 227 public AnimationDelegate, |
| 222 public ExtensionToolbarModel::Observer { | 228 public ExtensionToolbarModel::Observer { |
| 223 public: | 229 public: |
| 224 BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); | 230 BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); |
| 225 virtual ~BrowserActionsContainer(); | 231 virtual ~BrowserActionsContainer(); |
| 226 | 232 |
| 227 static void RegisterUserPrefs(PrefService* prefs); | 233 static void RegisterUserPrefs(PrefService* prefs); |
| 228 | 234 |
| 229 // Get the number of browser actions being displayed. | 235 // Get the number of browser actions being displayed. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 242 BrowserActionView* GetBrowserActionViewAt(int index) { | 248 BrowserActionView* GetBrowserActionViewAt(int index) { |
| 243 return browser_action_views_[index]; | 249 return browser_action_views_[index]; |
| 244 } | 250 } |
| 245 | 251 |
| 246 // Retrieve the BrowserActionView for |extension|. | 252 // Retrieve the BrowserActionView for |extension|. |
| 247 BrowserActionView* GetBrowserActionView(Extension* extension); | 253 BrowserActionView* GetBrowserActionView(Extension* extension); |
| 248 | 254 |
| 249 // Update the views to reflect the state of the browser action icons. | 255 // Update the views to reflect the state of the browser action icons. |
| 250 void RefreshBrowserActionViews(); | 256 void RefreshBrowserActionViews(); |
| 251 | 257 |
| 258 // Sets up the browser action view vector. |
| 259 void CreateBrowserActionViews(); |
| 260 |
| 252 // Delete all browser action views. | 261 // Delete all browser action views. |
| 253 void DeleteBrowserActionViews(); | 262 void DeleteBrowserActionViews(); |
| 254 | 263 |
| 255 // Called when a browser action becomes visible/hidden. | 264 // Called when a browser action becomes visible/hidden. |
| 256 void OnBrowserActionVisibilityChanged(); | 265 void OnBrowserActionVisibilityChanged(); |
| 257 | 266 |
| 258 // Called when the user clicks on the browser action icon. | 267 // Called when the user clicks on the browser action icon. |
| 259 void OnBrowserActionExecuted(BrowserActionButton* button); | 268 void OnBrowserActionExecuted(BrowserActionButton* button); |
| 260 | 269 |
| 261 // Overridden from views::View: | 270 // Overridden from views::View: |
| 262 virtual gfx::Size GetPreferredSize(); | 271 virtual gfx::Size GetPreferredSize(); |
| 263 virtual void Layout(); | 272 virtual void Layout(); |
| 264 virtual void Paint(gfx::Canvas* canvas); | 273 virtual void Paint(gfx::Canvas* canvas); |
| 265 virtual void ViewHierarchyChanged(bool is_add, | 274 virtual void ViewHierarchyChanged(bool is_add, |
| 266 views::View* parent, | 275 views::View* parent, |
| 267 views::View* child); | 276 views::View* child); |
| 277 virtual bool GetDropFormats( |
| 278 int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats); |
| 279 virtual bool AreDropTypesRequired(); |
| 280 virtual bool CanDrop(const OSExchangeData& data); |
| 281 virtual void OnDragEntered(const views::DropTargetEvent& event); |
| 282 virtual int OnDragUpdated(const views::DropTargetEvent& event); |
| 283 virtual void OnDragExited(); |
| 284 virtual int OnPerformDrop(const views::DropTargetEvent& event); |
| 268 | 285 |
| 269 // Overridden from NotificationObserver: | 286 // Overridden from NotificationObserver: |
| 270 virtual void Observe(NotificationType type, | 287 virtual void Observe(NotificationType type, |
| 271 const NotificationSource& source, | 288 const NotificationSource& source, |
| 272 const NotificationDetails& details); | 289 const NotificationDetails& details); |
| 273 | 290 |
| 274 // BrowserBubble::Delegate methods. | 291 // BrowserBubble::Delegate methods. |
| 275 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); | 292 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); |
| 276 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); | 293 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); |
| 277 virtual void BubbleGotFocus(BrowserBubble* bubble); | 294 virtual void BubbleGotFocus(BrowserBubble* bubble); |
| 278 virtual void BubbleLostFocus(BrowserBubble* bubble, | 295 virtual void BubbleLostFocus(BrowserBubble* bubble, |
| 279 gfx::NativeView focused_view); | 296 gfx::NativeView focused_view); |
| 280 | 297 |
| 281 // Overridden from views::ViewMenuDelegate: | 298 // Overridden from views::ViewMenuDelegate: |
| 282 virtual void RunMenu(View* source, const gfx::Point& pt); | 299 virtual void RunMenu(View* source, const gfx::Point& pt); |
| 283 | 300 |
| 301 // Overridden from views::DragController: |
| 302 virtual void WriteDragData(View* sender, |
| 303 int press_x, |
| 304 int press_y, |
| 305 OSExchangeData* data); |
| 306 virtual int GetDragOperations(View* sender, int x, int y); |
| 307 virtual bool CanStartDrag(View* sender, |
| 308 int press_x, |
| 309 int press_y, |
| 310 int x, |
| 311 int y); |
| 312 |
| 284 // Overridden from ResizeGripper::ResizeGripperDelegate: | 313 // Overridden from ResizeGripper::ResizeGripperDelegate: |
| 285 virtual void OnResize(int resize_amount, bool done_resizing); | 314 virtual void OnResize(int resize_amount, bool done_resizing); |
| 286 | 315 |
| 287 // Overridden from AnimationDelegate: | 316 // Overridden from AnimationDelegate: |
| 288 virtual void AnimationProgressed(const Animation* animation); | 317 virtual void AnimationProgressed(const Animation* animation); |
| 289 virtual void AnimationEnded(const Animation* animation); | 318 virtual void AnimationEnded(const Animation* animation); |
| 290 | 319 |
| 291 // Hide the current popup. | 320 // Hide the current popup. |
| 292 void HidePopup(); | 321 void HidePopup(); |
| 293 | 322 |
| 294 // Simulate a click on a browser action button. This should only be | 323 // Simulate a click on a browser action button. This should only be |
| 295 // used by unit tests. | 324 // used by unit tests. |
| 296 void TestExecuteBrowserAction(int index); | 325 void TestExecuteBrowserAction(int index); |
| 297 | 326 |
| 298 // Retrieve the current popup. This should only be used by unit tests. | 327 // Retrieve the current popup. This should only be used by unit tests. |
| 299 ExtensionPopup* TestGetPopup() { return popup_; } | 328 ExtensionPopup* TestGetPopup() { return popup_; } |
| 300 | 329 |
| 301 private: | 330 private: |
| 302 // ExtensionToolbarModel::Observer implementation. | 331 // ExtensionToolbarModel::Observer implementation. |
| 303 virtual void BrowserActionAdded(Extension* extension, int index); | 332 virtual void BrowserActionAdded(Extension* extension, int index); |
| 304 virtual void BrowserActionRemoved(Extension* extension); | 333 virtual void BrowserActionRemoved(Extension* extension); |
| 334 virtual void BrowserActionMoved(Extension* extension, int index); |
| 305 | 335 |
| 306 // Closes the overflow menu if open. | 336 // Closes the overflow menu if open. |
| 307 void CloseOverflowMenu(); | 337 void CloseOverflowMenu(); |
| 308 | 338 |
| 309 // Takes a width in pixels, calculates how many icons fit within that space | 339 // Takes a width in pixels, calculates how many icons fit within that space |
| 310 // (up to the maximum number of icons in our vector) and shaves off the | 340 // (up to the maximum number of icons in our vector) and shaves off the |
| 311 // excess pixels. | 341 // excess pixels. |allow_shrink_to_minimum| specifies whether this function |
| 312 int ClampToNearestIconCount(int pixels) const; | 342 // clamps the size down further (down to ContainerMinSize()) if there is not |
| 343 // room for even one icon. When determining how large the container should be |
| 344 // this should be |true|. When determining where to place items, such as the |
| 345 // drop indicator, this should be |false|. |
| 346 int ClampToNearestIconCount(int pixels, bool allow_shrink_to_minimum) const; |
| 313 | 347 |
| 314 // Calculates the width of the container area NOT used to show the icons (the | 348 // Calculates the width of the container area NOT used to show the icons (the |
| 315 // controls to the left and to the right of the icons). | 349 // controls to the left and to the right of the icons). |
| 316 int WidthOfNonIconArea() const; | 350 int WidthOfNonIconArea() const; |
| 317 | 351 |
| 318 // Given a number of |icons| return the amount of pixels needed to draw it, | 352 // Given a number of |icons| return the amount of pixels needed to draw it, |
| 319 // including the controls (chevron if visible and resize gripper). | 353 // including the controls (chevron if visible and resize gripper). |
| 320 int IconCountToWidth(int icons) const; | 354 int IconCountToWidth(int icons) const; |
| 321 | 355 |
| 322 // Returns the absolute minimum size you can shrink the container down to and | 356 // Returns the absolute minimum size you can shrink the container down to and |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 401 |
| 368 // This is used while the user is resizing (and when the animations are in | 402 // This is used while the user is resizing (and when the animations are in |
| 369 // progress) to know how wide the delta is between the current state and what | 403 // progress) to know how wide the delta is between the current state and what |
| 370 // we should draw. | 404 // we should draw. |
| 371 int resize_amount_; | 405 int resize_amount_; |
| 372 | 406 |
| 373 // Keeps track of the absolute pixel width the container should have when we | 407 // Keeps track of the absolute pixel width the container should have when we |
| 374 // are done animating. | 408 // are done animating. |
| 375 int animation_target_size_; | 409 int animation_target_size_; |
| 376 | 410 |
| 411 // The x position for where to draw the drop indicator. -1 if no indicator. |
| 412 int drop_indicator_position_; |
| 413 |
| 377 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 414 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |
| 378 | 415 |
| 379 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 416 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 380 }; | 417 }; |
| 381 | 418 |
| 382 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 419 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |