Chromium Code Reviews| 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> | |
| 9 #include <string> | |
| 8 #include <vector> | 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/task.h" | 12 #include "base/task.h" |
| 11 #include "chrome/browser/extensions/extension_toolbar_model.h" | 13 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 12 #include "chrome/browser/extensions/image_loading_tracker.h" | 14 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 13 #include "chrome/browser/views/browser_bubble.h" | 15 #include "chrome/browser/views/browser_bubble.h" |
| 16 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle r.h" | |
| 14 #include "chrome/browser/views/extensions/extension_action_context_menu.h" | 17 #include "chrome/browser/views/extensions/extension_action_context_menu.h" |
| 15 #include "chrome/common/notification_observer.h" | 18 #include "chrome/common/notification_observer.h" |
| 16 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" |
| 17 #include "views/controls/button/menu_button.h" | 20 #include "views/controls/button/menu_button.h" |
| 18 #include "views/controls/menu/view_menu_delegate.h" | 21 #include "views/controls/menu/view_menu_delegate.h" |
| 19 #include "views/controls/resize_gripper.h" | 22 #include "views/controls/resize_gripper.h" |
| 20 #include "views/view.h" | 23 #include "views/view.h" |
| 21 | 24 |
| 22 class BrowserActionOverflowMenuController; | 25 class BrowserActionOverflowMenuController; |
| 23 class BrowserActionsContainer; | 26 class BrowserActionsContainer; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 // | 221 // |
| 219 //////////////////////////////////////////////////////////////////////////////// | 222 //////////////////////////////////////////////////////////////////////////////// |
| 220 class BrowserActionsContainer | 223 class BrowserActionsContainer |
| 221 : public views::View, | 224 : public views::View, |
| 222 public NotificationObserver, | 225 public NotificationObserver, |
| 223 public BrowserBubble::Delegate, | 226 public BrowserBubble::Delegate, |
| 224 public views::ViewMenuDelegate, | 227 public views::ViewMenuDelegate, |
| 225 public views::DragController, | 228 public views::DragController, |
| 226 public views::ResizeGripper::ResizeGripperDelegate, | 229 public views::ResizeGripper::ResizeGripperDelegate, |
| 227 public AnimationDelegate, | 230 public AnimationDelegate, |
| 228 public ExtensionToolbarModel::Observer { | 231 public ExtensionToolbarModel::Observer, |
| 232 public BrowserActionOverflowMenuController::Observer { | |
| 233 friend class ShowFolderMenuTask; | |
| 229 public: | 234 public: |
| 230 BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); | 235 BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); |
| 231 virtual ~BrowserActionsContainer(); | 236 virtual ~BrowserActionsContainer(); |
| 232 | 237 |
| 233 static void RegisterUserPrefs(PrefService* prefs); | 238 static void RegisterUserPrefs(PrefService* prefs); |
| 234 | 239 |
| 235 // Get the number of browser actions being displayed. | 240 // Get the number of browser actions being displayed. |
| 236 int num_browser_actions() const { return browser_action_views_.size(); } | 241 int num_browser_actions() const { return browser_action_views_.size(); } |
| 237 | 242 |
| 238 // Whether we are performing resize animation on the container. | 243 // Whether we are performing resize animation on the container. |
| 239 bool animating() const { return animation_target_size_ > 0; } | 244 bool animating() const { return animation_target_size_ > 0; } |
| 240 | 245 |
| 241 // Returns the chevron, if any. | 246 // Returns the chevron, if any. |
| 242 const views::View* chevron() const { return chevron_; } | 247 const views::View* chevron() const { return chevron_; } |
| 243 | 248 |
| 249 // Returns the profile this container is associated with. | |
| 250 Profile* profile() const { return profile_; } | |
| 251 | |
| 244 // Returns the current tab's ID, or -1 if there is no current tab. | 252 // Returns the current tab's ID, or -1 if there is no current tab. |
| 245 int GetCurrentTabId() const; | 253 int GetCurrentTabId() const; |
| 246 | 254 |
| 247 // Get a particular browser action view. | 255 // Get a particular browser action view. |
| 248 BrowserActionView* GetBrowserActionViewAt(int index) { | 256 BrowserActionView* GetBrowserActionViewAt(int index) { |
| 249 return browser_action_views_[index]; | 257 return browser_action_views_[index]; |
| 250 } | 258 } |
| 251 | 259 |
| 252 // Retrieve the BrowserActionView for |extension|. | 260 // Retrieve the BrowserActionView for |extension|. |
| 253 BrowserActionView* GetBrowserActionView(Extension* extension); | 261 BrowserActionView* GetBrowserActionView(Extension* extension); |
| 254 | 262 |
| 255 // Update the views to reflect the state of the browser action icons. | 263 // Update the views to reflect the state of the browser action icons. |
| 256 void RefreshBrowserActionViews(); | 264 void RefreshBrowserActionViews(); |
| 257 | 265 |
| 258 // Sets up the browser action view vector. | 266 // Sets up the browser action view vector. |
| 259 void CreateBrowserActionViews(); | 267 void CreateBrowserActionViews(); |
| 260 | 268 |
| 261 // Delete all browser action views. | 269 // Delete all browser action views. |
| 262 void DeleteBrowserActionViews(); | 270 void DeleteBrowserActionViews(); |
| 263 | 271 |
| 264 // Called when a browser action becomes visible/hidden. | 272 // Called when a browser action becomes visible/hidden. |
| 265 void OnBrowserActionVisibilityChanged(); | 273 void OnBrowserActionVisibilityChanged(); |
| 266 | 274 |
| 275 // Returns how many browser actions are visible. | |
| 276 size_t VisibleBrowserActions() const; | |
| 277 | |
| 267 // Called when the user clicks on the browser action icon. | 278 // Called when the user clicks on the browser action icon. |
| 268 void OnBrowserActionExecuted(BrowserActionButton* button); | 279 void OnBrowserActionExecuted(BrowserActionButton* button); |
| 269 | 280 |
| 270 // Overridden from views::View: | 281 // Overridden from views::View: |
| 271 virtual gfx::Size GetPreferredSize(); | 282 virtual gfx::Size GetPreferredSize(); |
| 272 virtual void Layout(); | 283 virtual void Layout(); |
| 273 virtual void Paint(gfx::Canvas* canvas); | 284 virtual void Paint(gfx::Canvas* canvas); |
| 274 virtual void ViewHierarchyChanged(bool is_add, | 285 virtual void ViewHierarchyChanged(bool is_add, |
| 275 views::View* parent, | 286 views::View* parent, |
| 276 views::View* child); | 287 views::View* child); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 int x, | 321 int x, |
| 311 int y); | 322 int y); |
| 312 | 323 |
| 313 // Overridden from ResizeGripper::ResizeGripperDelegate: | 324 // Overridden from ResizeGripper::ResizeGripperDelegate: |
| 314 virtual void OnResize(int resize_amount, bool done_resizing); | 325 virtual void OnResize(int resize_amount, bool done_resizing); |
| 315 | 326 |
| 316 // Overridden from AnimationDelegate: | 327 // Overridden from AnimationDelegate: |
| 317 virtual void AnimationProgressed(const Animation* animation); | 328 virtual void AnimationProgressed(const Animation* animation); |
| 318 virtual void AnimationEnded(const Animation* animation); | 329 virtual void AnimationEnded(const Animation* animation); |
| 319 | 330 |
| 331 // Overridden from BrowserActionOverflowMenuController::Observer: | |
| 332 virtual void NotifyMenuDeleted( | |
| 333 BrowserActionOverflowMenuController* controller); | |
| 334 | |
| 335 // Moves a browser action with |id| to |new_index|. | |
| 336 void MoveBrowserAction(const std::string& extension_id, size_t new_index); | |
| 337 | |
| 320 // Hide the current popup. | 338 // Hide the current popup. |
| 321 void HidePopup(); | 339 void HidePopup(); |
| 322 | 340 |
| 323 // Simulate a click on a browser action button. This should only be | 341 // Simulate a click on a browser action button. This should only be |
| 324 // used by unit tests. | 342 // used by unit tests. |
| 325 void TestExecuteBrowserAction(int index); | 343 void TestExecuteBrowserAction(int index); |
| 326 | 344 |
| 327 // Retrieve the current popup. This should only be used by unit tests. | 345 // Retrieve the current popup. This should only be used by unit tests. |
| 328 ExtensionPopup* TestGetPopup() { return popup_; } | 346 ExtensionPopup* TestGetPopup() { return popup_; } |
| 329 | 347 |
| 330 private: | 348 private: |
| 331 // ExtensionToolbarModel::Observer implementation. | 349 // ExtensionToolbarModel::Observer implementation. |
| 332 virtual void BrowserActionAdded(Extension* extension, int index); | 350 virtual void BrowserActionAdded(Extension* extension, int index); |
| 333 virtual void BrowserActionRemoved(Extension* extension); | 351 virtual void BrowserActionRemoved(Extension* extension); |
| 334 virtual void BrowserActionMoved(Extension* extension, int index); | 352 virtual void BrowserActionMoved(Extension* extension, int index); |
| 335 | 353 |
| 336 // Closes the overflow menu if open. | 354 // Closes the overflow menu if open. |
| 337 void CloseOverflowMenu(); | 355 void CloseOverflowMenu(); |
| 338 | 356 |
| 357 // Cancels the timer for showing the drop down menu. | |
| 358 void StopShowFolderDropMenuTimer(); | |
| 359 | |
| 360 // Show the drop down folder after a slight delay. | |
| 361 void StartShowFolderDropMenuTimer(); | |
| 362 | |
| 363 // Show the overflow menu. | |
| 364 void ShowDropFolder(); | |
| 365 | |
| 366 // Sets the drop indicator position (and schedules paint if the position has | |
| 367 // changed). | |
| 368 void SetDropIndicator(int x_pos); | |
|
sky
2010/02/04 20:58:49
x_pos is mildly confusing here as it isn't the x-c
| |
| 369 | |
| 339 // Takes a width in pixels, calculates how many icons fit within that space | 370 // Takes a width in pixels, calculates how many icons fit within that space |
| 340 // (up to the maximum number of icons in our vector) and shaves off the | 371 // (up to the maximum number of icons in our vector) and shaves off the |
| 341 // excess pixels. |allow_shrink_to_minimum| specifies whether this function | 372 // excess pixels. |allow_shrink_to_minimum| specifies whether this function |
| 342 // clamps the size down further (down to ContainerMinSize()) if there is not | 373 // 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 | 374 // 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 | 375 // this should be |true|. When determining where to place items, such as the |
| 345 // drop indicator, this should be |false|. | 376 // drop indicator, this should be |false|. |
| 346 int ClampToNearestIconCount(int pixels, bool allow_shrink_to_minimum) const; | 377 int ClampToNearestIconCount(int pixels, bool allow_shrink_to_minimum) const; |
| 347 | 378 |
| 348 // Calculates the width of the container area NOT used to show the icons (the | 379 // Calculates the width of the container area NOT used to show the icons (the |
| 349 // controls to the left and to the right of the icons). | 380 // controls to the left and to the right of the icons). |
| 350 int WidthOfNonIconArea() const; | 381 int WidthOfNonIconArea() const; |
| 351 | 382 |
| 352 // Given a number of |icons| return the amount of pixels needed to draw it, | 383 // Given a number of |icons| return the amount of pixels needed to draw it, |
| 353 // including the controls (chevron if visible and resize gripper). | 384 // including the controls (chevron if visible and resize gripper). |
| 354 int IconCountToWidth(int icons) const; | 385 int IconCountToWidth(int icons) const; |
| 355 | 386 |
| 356 // Returns the absolute minimum size you can shrink the container down to and | 387 // Returns the absolute minimum size you can shrink the container down to and |
| 357 // still show it. We account for the chevron and the resize gripper, but not | 388 // still show it. We account for the chevron and the resize gripper, but not |
| 358 // all the padding that we normally show if there are icons. | 389 // all the padding that we normally show if there are icons. |
| 359 int ContainerMinSize() const; | 390 int ContainerMinSize() const; |
| 360 | 391 |
| 361 // Returns how many browser actions are visible. | |
| 362 size_t VisibleBrowserActions() const; | |
| 363 | |
| 364 // The vector of browser actions (icons/image buttons for each action). | 392 // The vector of browser actions (icons/image buttons for each action). |
| 365 std::vector<BrowserActionView*> browser_action_views_; | 393 std::vector<BrowserActionView*> browser_action_views_; |
| 366 | 394 |
| 367 NotificationRegistrar registrar_; | 395 NotificationRegistrar registrar_; |
| 368 | 396 |
| 369 Profile* profile_; | 397 Profile* profile_; |
| 370 | 398 |
| 371 // The toolbar that owns us. | 399 // The toolbar that owns us. |
| 372 ToolbarView* toolbar_; | 400 ToolbarView* toolbar_; |
| 373 | 401 |
| 374 // The current popup and the button it came from. NULL if no popup. | 402 // The current popup and the button it came from. NULL if no popup. |
| 375 ExtensionPopup* popup_; | 403 ExtensionPopup* popup_; |
| 376 | 404 |
| 377 // The button that triggered the current popup (just a reference to a button | 405 // The button that triggered the current popup (just a reference to a button |
| 378 // from browser_action_views_). | 406 // from browser_action_views_). |
| 379 BrowserActionButton* popup_button_; | 407 BrowserActionButton* popup_button_; |
| 380 | 408 |
| 381 // The model that tracks the order of the toolbar icons. | 409 // The model that tracks the order of the toolbar icons. |
| 382 ExtensionToolbarModel* model_; | 410 ExtensionToolbarModel* model_; |
| 383 | 411 |
| 384 // The current size of the container. | 412 // The current size of the container. |
| 385 gfx::Size container_size_; | 413 gfx::Size container_size_; |
| 386 | 414 |
| 387 // The resize gripper for the container. | 415 // The resize gripper for the container. |
| 388 views::ResizeGripper* resize_gripper_; | 416 views::ResizeGripper* resize_gripper_; |
| 389 | 417 |
| 390 // The chevron for accessing the overflow items. | 418 // The chevron for accessing the overflow items. |
| 391 views::MenuButton* chevron_; | 419 views::MenuButton* chevron_; |
| 392 | 420 |
| 393 // The menu to show for the overflow button (chevron). | 421 // The menu to show for the overflow button (chevron). This class manages its |
| 394 scoped_ptr<BrowserActionOverflowMenuController> overflow_menu_; | 422 // own lifetime so that it can stay alive during drag and drop operations. |
| 423 BrowserActionOverflowMenuController* overflow_menu_; | |
| 395 | 424 |
| 396 // The animation that happens when the container snaps to place. | 425 // The animation that happens when the container snaps to place. |
| 397 scoped_ptr<SlideAnimation> resize_animation_; | 426 scoped_ptr<SlideAnimation> resize_animation_; |
| 398 | 427 |
| 399 // Don't show the chevron while animating. | 428 // Don't show the chevron while animating. |
| 400 bool suppress_chevron_; | 429 bool suppress_chevron_; |
| 401 | 430 |
| 402 // This is used while the user is resizing (and when the animations are in | 431 // This is used while the user is resizing (and when the animations are in |
| 403 // progress) to know how wide the delta is between the current state and what | 432 // progress) to know how wide the delta is between the current state and what |
| 404 // we should draw. | 433 // we should draw. |
| 405 int resize_amount_; | 434 int resize_amount_; |
| 406 | 435 |
| 407 // Keeps track of the absolute pixel width the container should have when we | 436 // Keeps track of the absolute pixel width the container should have when we |
| 408 // are done animating. | 437 // are done animating. |
| 409 int animation_target_size_; | 438 int animation_target_size_; |
| 410 | 439 |
| 411 // The x position for where to draw the drop indicator. -1 if no indicator. | 440 // The x position for where to draw the drop indicator. -1 if no indicator. |
| 412 int drop_indicator_position_; | 441 int drop_indicator_position_; |
| 413 | 442 |
| 414 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 443 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |
| 415 | 444 |
| 445 // Handles delayed showing of the overflow menu when hovering. | |
| 446 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; | |
| 447 | |
| 416 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 448 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 417 }; | 449 }; |
| 418 | 450 |
| 419 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 451 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |