| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/slide_animation.h" | 12 #include "app/slide_animation.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "chrome/browser/extensions/extension_context_menu_model.h" | 14 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 15 #include "chrome/browser/extensions/extension_toolbar_model.h" | 15 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 16 #include "chrome/browser/extensions/image_loading_tracker.h" | 16 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 17 #include "chrome/browser/views/browser_bubble.h" | 17 #include "chrome/browser/views/browser_bubble.h" |
| 18 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle
r.h" | 18 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle
r.h" |
| 19 #include "chrome/browser/views/extensions/extension_popup.h" | 19 #include "chrome/browser/views/extensions/extension_popup.h" |
| 20 #include "chrome/common/notification_observer.h" | 20 #include "chrome/common/notification_observer.h" |
| 21 #include "chrome/common/notification_registrar.h" | 21 #include "chrome/common/notification_registrar.h" |
| 22 #include "views/controls/button/menu_button.h" | 22 #include "views/controls/button/menu_button.h" |
| 23 #include "views/controls/menu/view_menu_delegate.h" | 23 #include "views/controls/menu/view_menu_delegate.h" |
| 24 #include "views/controls/resize_gripper.h" | 24 #include "views/controls/resize_area.h" |
| 25 #include "views/view.h" | 25 #include "views/view.h" |
| 26 | 26 |
| 27 class Browser; | 27 class Browser; |
| 28 class BrowserActionsContainer; | 28 class BrowserActionsContainer; |
| 29 class BrowserActionOverflowMenuController; | 29 class BrowserActionOverflowMenuController; |
| 30 class BrowserActionsContainer; | 30 class BrowserActionsContainer; |
| 31 class Extension; | 31 class Extension; |
| 32 class ExtensionAction; | 32 class ExtensionAction; |
| 33 class ExtensionPopup; | 33 class ExtensionPopup; |
| 34 class PrefService; | 34 class PrefService; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
| 178 // | 178 // |
| 179 // The BrowserActionsContainer is a container view, responsible for drawing the | 179 // The BrowserActionsContainer is a container view, responsible for drawing the |
| 180 // browser action icons (extensions that add icons to the toolbar). | 180 // browser action icons (extensions that add icons to the toolbar). |
| 181 // | 181 // |
| 182 // The BrowserActionsContainer (when it contains one or more icons) consists of | 182 // The BrowserActionsContainer (when it contains one or more icons) consists of |
| 183 // the following elements, numbered as seen below the line: | 183 // the following elements, numbered as seen below the line: |
| 184 // | 184 // |
| 185 // || _ Icon _ Icon _ Icon _ [chevron] _ | _ | 185 // r _ Icon _ Icon _ Icon _ [chevron] _ | _ |
| 186 // ----------------------------------------- | 186 // ----------------------------------------- |
| 187 // 1 2 3 4 5 6 7 8 | 187 // 1 2 3 4 5 6 7 8 |
| 188 // | 188 // |
| 189 // 1) The ResizeGripper view. | 189 // 1) An invisible resize area. |
| 190 // 2) Padding (kHorizontalPadding). | 190 // 2) Padding (kHorizontalPadding). |
| 191 // 3) The browser action icon button (BrowserActionView). | 191 // 3) The browser action icon button (BrowserActionView). |
| 192 // 4) Padding to visually separate icons from one another | 192 // 4) Padding to visually separate icons from one another |
| 193 // (kBrowserActionButtonPadding). Not included if only one icon visible. | 193 // (kBrowserActionButtonPadding). Not included if only one icon visible. |
| 194 // 5) The chevron menu (MenuButton), shown when there is not enough room to show | 194 // 5) The chevron menu (MenuButton), shown when there is not enough room to show |
| 195 // all the icons. | 195 // all the icons. |
| 196 // 6) Padding (kDividerHorizontalMargin). | 196 // 6) Padding (kDividerHorizontalMargin). |
| 197 // 7) A thin vertical divider drawn during Paint to create visual separation for | 197 // 7) A thin vertical divider drawn during Paint to create visual separation for |
| 198 // the container from the Page and Wrench menus. | 198 // the container from the Page and Wrench menus. |
| 199 // 8) Padding (kChevronRightMargin). | 199 // 8) Padding (kChevronRightMargin). |
| 200 // | 200 // |
| 201 // The BrowserActionsContainer follows a few rules, in terms of user experience: | 201 // The BrowserActionsContainer follows a few rules, in terms of user experience: |
| 202 // | 202 // |
| 203 // 1) The container can never grow beyond the space needed to show all icons | 203 // 1) The container can never grow beyond the space needed to show all icons |
| 204 // (hereby referred to as the max width). | 204 // (hereby referred to as the max width). |
| 205 // 2) The container can never shrink below the space needed to show just the | 205 // 2) The container can never shrink below the space needed to show just the |
| 206 // resize gripper and the chevron (ignoring the case where there are no icons to | 206 // initial padding and the chevron (ignoring the case where there are no icons |
| 207 // show, in which case the container won't be visible anyway). | 207 // to show, in which case the container won't be visible anyway). |
| 208 // 3) The container snaps into place (to the pixel count that fits the visible | 208 // 3) The container snaps into place (to the pixel count that fits the visible |
| 209 // icons) to make sure there is no wasted space at the edges of the container. | 209 // icons) to make sure there is no wasted space at the edges of the container. |
| 210 // 4) If the user adds or removes icons (read: installs/uninstalls browser | 210 // 4) If the user adds or removes icons (read: installs/uninstalls browser |
| 211 // actions) we grow and shrink the container as needed - but ONLY if the | 211 // actions) we grow and shrink the container as needed - but ONLY if the |
| 212 // container was at max width to begin with. | 212 // container was at max width to begin with. |
| 213 // 5) If the container is NOT at max width (has an overflow menu), we respect | 213 // 5) If the container is NOT at max width (has an overflow menu), we respect |
| 214 // that size when adding and removing icons and DON'T grow/shrink the container. | 214 // that size when adding and removing icons and DON'T grow/shrink the container. |
| 215 // This means that new icons (which always appear at the far right) will show up | 215 // This means that new icons (which always appear at the far right) will show up |
| 216 // in the overflow menu. The install bubble for extensions points to the chevron | 216 // in the overflow menu. The install bubble for extensions points to the chevron |
| 217 // menu in this case. | 217 // menu in this case. |
| 218 // | 218 // |
| 219 // Resizing the BrowserActionsContainer: | 219 // Resizing the BrowserActionsContainer: |
| 220 // | 220 // |
| 221 // The ResizeGripper view sends OnResize messages to the BrowserActionsContainer | 221 // The ResizeArea view sends OnResize messages to the BrowserActionsContainer |
| 222 // class as the user drags the gripper. This modifies the value for | 222 // class as the user drags it. This modifies the value for |resize_amount_|. |
| 223 // |resize_amount_|. That indicates to the container that a resize is in | 223 // That indicates to the container that a resize is in progress and is used to |
| 224 // progress and is used to calculate the size in GetPreferredSize(), though | 224 // calculate the size in GetPreferredSize(), though that function never exceeds |
| 225 // that function never exceeds the defined minimum and maximum size of the | 225 // the defined minimum and maximum size of the container. |
| 226 // container. | |
| 227 // | 226 // |
| 228 // When the user releases the mouse (ends the resize), we calculate a target | 227 // When the user releases the mouse (ends the resize), we calculate a target |
| 229 // size for the container (animation_target_size_), clamp that value to the | 228 // size for the container (animation_target_size_), clamp that value to the |
| 230 // containers min and max and then animate from the *current* position (that the | 229 // containers min and max and then animate from the *current* position (that the |
| 231 // user has dragged the view to) to the target size. | 230 // user has dragged the view to) to the target size. |
| 232 // | 231 // |
| 233 // Animating the BrowserActionsContainer: | 232 // Animating the BrowserActionsContainer: |
| 234 // | 233 // |
| 235 // Animations are used when snapping the container to a value that fits all | 234 // Animations are used when snapping the container to a value that fits all |
| 236 // visible icons. This can be triggered when the user finishes resizing the | 235 // visible icons. This can be triggered when the user finishes resizing the |
| 237 // container or when Browser Actions are added/removed. | 236 // container or when Browser Actions are added/removed. |
| 238 // | 237 // |
| 239 // We always animate from the current width (container_size_.width()) to the | 238 // We always animate from the current width (container_size_.width()) to the |
| 240 // target size (animation_target_size_), using |resize_amount| to keep track of | 239 // target size (animation_target_size_), using |resize_amount| to keep track of |
| 241 // the animation progress. | 240 // the animation progress. |
| 242 // | 241 // |
| 243 // NOTE: When adding Browser Actions to a maximum width container (no overflow) | 242 // NOTE: When adding Browser Actions to a maximum width container (no overflow) |
| 244 // we make sure to suppress the chevron menu if it wasn't visible. This is | 243 // we make sure to suppress the chevron menu if it wasn't visible. This is |
| 245 // because we won't have enough space to show the new Browser Action until the | 244 // because we won't have enough space to show the new Browser Action until the |
| 246 // animation ends and we don't want the chevron to flash into view while we are | 245 // animation ends and we don't want the chevron to flash into view while we are |
| 247 // growing the container. | 246 // growing the container. |
| 248 // | 247 // |
| 249 //////////////////////////////////////////////////////////////////////////////// | 248 //////////////////////////////////////////////////////////////////////////////// |
| 250 class BrowserActionsContainer | 249 class BrowserActionsContainer |
| 251 : public views::View, | 250 : public views::View, |
| 252 public views::ViewMenuDelegate, | 251 public views::ViewMenuDelegate, |
| 253 public views::DragController, | 252 public views::DragController, |
| 254 public views::ResizeGripper::ResizeGripperDelegate, | 253 public views::ResizeArea::ResizeAreaDelegate, |
| 255 public AnimationDelegate, | 254 public AnimationDelegate, |
| 256 public ExtensionToolbarModel::Observer, | 255 public ExtensionToolbarModel::Observer, |
| 257 public BrowserActionOverflowMenuController::Observer, | 256 public BrowserActionOverflowMenuController::Observer, |
| 258 public ExtensionContextMenuModel::PopupDelegate, | 257 public ExtensionContextMenuModel::PopupDelegate, |
| 259 public ExtensionPopup::Observer { | 258 public ExtensionPopup::Observer { |
| 260 public: | 259 public: |
| 261 BrowserActionsContainer(Browser* browser, views::View* owner_view); | 260 BrowserActionsContainer(Browser* browser, views::View* owner_view); |
| 262 virtual ~BrowserActionsContainer(); | 261 virtual ~BrowserActionsContainer(); |
| 263 | 262 |
| 264 static void RegisterUserPrefs(PrefService* prefs); | 263 static void RegisterUserPrefs(PrefService* prefs); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 329 |
| 331 // Overridden from views::DragController: | 330 // Overridden from views::DragController: |
| 332 virtual void WriteDragData(View* sender, | 331 virtual void WriteDragData(View* sender, |
| 333 const gfx::Point& press_pt, | 332 const gfx::Point& press_pt, |
| 334 OSExchangeData* data); | 333 OSExchangeData* data); |
| 335 virtual int GetDragOperations(View* sender, const gfx::Point& p); | 334 virtual int GetDragOperations(View* sender, const gfx::Point& p); |
| 336 virtual bool CanStartDrag(View* sender, | 335 virtual bool CanStartDrag(View* sender, |
| 337 const gfx::Point& press_pt, | 336 const gfx::Point& press_pt, |
| 338 const gfx::Point& p); | 337 const gfx::Point& p); |
| 339 | 338 |
| 340 // Overridden from ResizeGripper::ResizeGripperDelegate: | 339 // Overridden from ResizeArea::ResizeAreaDelegate: |
| 341 virtual void OnResize(int resize_amount, bool done_resizing); | 340 virtual void OnResize(int resize_amount, bool done_resizing); |
| 342 | 341 |
| 343 // Overridden from AnimationDelegate: | 342 // Overridden from AnimationDelegate: |
| 344 virtual void AnimationProgressed(const Animation* animation); | 343 virtual void AnimationProgressed(const Animation* animation); |
| 345 virtual void AnimationEnded(const Animation* animation); | 344 virtual void AnimationEnded(const Animation* animation); |
| 346 | 345 |
| 347 // Overridden from BrowserActionOverflowMenuController::Observer: | 346 // Overridden from BrowserActionOverflowMenuController::Observer: |
| 348 virtual void NotifyMenuDeleted( | 347 virtual void NotifyMenuDeleted( |
| 349 BrowserActionOverflowMenuController* controller); | 348 BrowserActionOverflowMenuController* controller); |
| 350 | 349 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // room for even one icon. When determining how large the container should be | 412 // room for even one icon. When determining how large the container should be |
| 414 // this should be |true|. When determining where to place items, such as the | 413 // this should be |true|. When determining where to place items, such as the |
| 415 // drop indicator, this should be |false|. | 414 // drop indicator, this should be |false|. |
| 416 int ClampToNearestIconCount(int pixels, bool allow_shrink_to_minimum) const; | 415 int ClampToNearestIconCount(int pixels, bool allow_shrink_to_minimum) const; |
| 417 | 416 |
| 418 // Calculates the width of the container area NOT used to show the icons (the | 417 // Calculates the width of the container area NOT used to show the icons (the |
| 419 // controls to the left and to the right of the icons). | 418 // controls to the left and to the right of the icons). |
| 420 int WidthOfNonIconArea() const; | 419 int WidthOfNonIconArea() const; |
| 421 | 420 |
| 422 // Given a number of |icons| return the amount of pixels needed to draw it, | 421 // Given a number of |icons| return the amount of pixels needed to draw it, |
| 423 // including the controls (chevron if visible and resize gripper). | 422 // including the controls (chevron if visible and resize area). |
| 424 int IconCountToWidth(int icons) const; | 423 int IconCountToWidth(int icons) const; |
| 425 | 424 |
| 426 // Returns the absolute minimum size you can shrink the container down to and | 425 // Returns the absolute minimum size you can shrink the container down to and |
| 427 // still show it. We account for the chevron and the resize gripper, but not | 426 // still show it. We account for the chevron and the resize gripper, but not |
| 428 // all the padding that we normally show if there are icons. | 427 // all the padding that we normally show if there are icons. |
| 429 int ContainerMinSize() const; | 428 int ContainerMinSize() const; |
| 430 | 429 |
| 431 // Animate to the target value (unless testing, in which case we go straight | 430 // Animate to the target value (unless testing, in which case we go straight |
| 432 // to the target size). | 431 // to the target size). |
| 433 void Animate(Tween::Type type, int target_size); | 432 void Animate(Tween::Type type, int target_size); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 456 // The button that triggered the current popup (just a reference to a button | 455 // The button that triggered the current popup (just a reference to a button |
| 457 // from browser_action_views_). | 456 // from browser_action_views_). |
| 458 BrowserActionButton* popup_button_; | 457 BrowserActionButton* popup_button_; |
| 459 | 458 |
| 460 // The model that tracks the order of the toolbar icons. | 459 // The model that tracks the order of the toolbar icons. |
| 461 ExtensionToolbarModel* model_; | 460 ExtensionToolbarModel* model_; |
| 462 | 461 |
| 463 // The current size of the container. | 462 // The current size of the container. |
| 464 gfx::Size container_size_; | 463 gfx::Size container_size_; |
| 465 | 464 |
| 466 // The resize gripper for the container. | 465 // The resize area for the container. |
| 467 views::ResizeGripper* resize_gripper_; | 466 views::ResizeArea* resize_area_; |
| 468 | 467 |
| 469 // The chevron for accessing the overflow items. | 468 // The chevron for accessing the overflow items. |
| 470 views::MenuButton* chevron_; | 469 views::MenuButton* chevron_; |
| 471 | 470 |
| 472 // The menu to show for the overflow button (chevron). This class manages its | 471 // The menu to show for the overflow button (chevron). This class manages its |
| 473 // own lifetime so that it can stay alive during drag and drop operations. | 472 // own lifetime so that it can stay alive during drag and drop operations. |
| 474 BrowserActionOverflowMenuController* overflow_menu_; | 473 BrowserActionOverflowMenuController* overflow_menu_; |
| 475 | 474 |
| 476 // The animation that happens when the container snaps to place. | 475 // The animation that happens when the container snaps to place. |
| 477 scoped_ptr<SlideAnimation> resize_animation_; | 476 scoped_ptr<SlideAnimation> resize_animation_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 493 | 492 |
| 494 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 493 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |
| 495 | 494 |
| 496 // Handles delayed showing of the overflow menu when hovering. | 495 // Handles delayed showing of the overflow menu when hovering. |
| 497 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; | 496 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; |
| 498 | 497 |
| 499 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 498 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 500 }; | 499 }; |
| 501 | 500 |
| 502 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 501 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |