| 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> |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 BrowserActionButton* button_; | 168 BrowserActionButton* button_; |
| 169 | 169 |
| 170 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | 170 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
| 174 // | 174 // |
| 175 // The BrowserActionsContainer is a container view, responsible for drawing the | 175 // The BrowserActionsContainer is a container view, responsible for drawing the |
| 176 // browser action icons (extensions that add icons to the toolbar). | 176 // browser action icons (extensions that add icons to the toolbar). |
| 177 // | 177 // |
| 178 // The BrowserActionsContainer (when it contains one or more icons) consists of | 178 // The container is placed flush against the omnibox and wrench menu, and its |
| 179 // the following elements, numbered as seen below the line: | 179 // layout looks like: |
| 180 // | 180 // rI_I_IcCs |
| 181 // r _ Icon _ Icon _ Icon _ [chevron] _ | _ | 181 // Where the letters are as follows: |
| 182 // ----------------------------------------- | 182 // r: An invisible resize area. This is ToolbarView::kStandardSpacing pixels |
| 183 // 1 2 3 4 5 6 7 8 | 183 // wide and directly adjacent to the omnibox. |
| 184 // | 184 // I: An icon. This is as wide as the IDR_BROWSER_ACTION image. |
| 185 // 1) An invisible resize area. | 185 // _: kItemSpacing pixels of empty space. |
| 186 // 2) Padding (kHorizontalPadding). | 186 // c: kChevronSpacing pixels of empty space. Only present if C is present. |
| 187 // 3) The browser action icon button (BrowserActionView). | 187 // C: An optional chevron, visible for overflow. As wide as the |
| 188 // 4) Padding to visually separate icons from one another | 188 // IDR_BROWSER_ACTIONS_OVERFLOW image. |
| 189 // (kBrowserActionButtonPadding). Not included if only one icon visible. | 189 // s: ToolbarView::kStandardSpacing pixels of empty space (before the wrench |
| 190 // 5) The chevron menu (MenuButton), shown when there is not enough room to show | 190 // menu). |
| 191 // all the icons. | 191 // The reason the container contains the trailing space "s", rather than having |
| 192 // 6) Padding (kDividerHorizontalMargin). | 192 // it be handled by the parent view, is so that when the chevron is invisible |
| 193 // 7) A thin vertical divider drawn during Paint to create visual separation for | 193 // and the user starts dragging an icon around, we have the space to draw the |
| 194 // the container from the Page and Wrench menus. | 194 // ultimate drop indicator. (Otherwise, we'd be trying to draw it into the |
| 195 // 8) Padding (kChevronRightMargin). | 195 // padding beyond our right edge, and it wouldn't appear.) |
| 196 // | 196 // |
| 197 // The BrowserActionsContainer follows a few rules, in terms of user experience: | 197 // The BrowserActionsContainer follows a few rules, in terms of user experience: |
| 198 // | 198 // |
| 199 // 1) The container can never grow beyond the space needed to show all icons | 199 // 1) The container can never grow beyond the space needed to show all icons |
| 200 // (hereby referred to as the max width). | 200 // (hereby referred to as the max width). |
| 201 // 2) The container can never shrink below the space needed to show just the | 201 // 2) The container can never shrink below the space needed to show just the |
| 202 // initial padding and the chevron (ignoring the case where there are no icons | 202 // initial padding and the chevron (ignoring the case where there are no icons |
| 203 // to show, in which case the container won't be visible anyway). | 203 // to show, in which case the container won't be visible anyway). |
| 204 // 3) The container snaps into place (to the pixel count that fits the visible | 204 // 3) The container snaps into place (to the pixel count that fits the visible |
| 205 // icons) to make sure there is no wasted space at the edges of the container. | 205 // icons) to make sure there is no wasted space at the edges of the container. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 public ExtensionToolbarModel::Observer, | 251 public ExtensionToolbarModel::Observer, |
| 252 public BrowserActionOverflowMenuController::Observer, | 252 public BrowserActionOverflowMenuController::Observer, |
| 253 public ExtensionContextMenuModel::PopupDelegate, | 253 public ExtensionContextMenuModel::PopupDelegate, |
| 254 public ExtensionPopup::Observer { | 254 public ExtensionPopup::Observer { |
| 255 public: | 255 public: |
| 256 BrowserActionsContainer(Browser* browser, views::View* owner_view); | 256 BrowserActionsContainer(Browser* browser, views::View* owner_view); |
| 257 virtual ~BrowserActionsContainer(); | 257 virtual ~BrowserActionsContainer(); |
| 258 | 258 |
| 259 static void RegisterUserPrefs(PrefService* prefs); | 259 static void RegisterUserPrefs(PrefService* prefs); |
| 260 | 260 |
| 261 void Init(); |
| 262 |
| 261 // Get the number of browser actions being displayed. | 263 // Get the number of browser actions being displayed. |
| 262 int num_browser_actions() const { return browser_action_views_.size(); } | 264 int num_browser_actions() const { return browser_action_views_.size(); } |
| 263 | 265 |
| 264 // Whether we are performing resize animation on the container. | 266 // Whether we are performing resize animation on the container. |
| 265 bool animating() const { return animation_target_size_ > 0; } | 267 bool animating() const { return animation_target_size_ > 0; } |
| 266 | 268 |
| 267 // Returns the chevron, if any. | 269 // Returns the chevron, if any. |
| 268 const views::View* chevron() const { return chevron_; } | 270 const views::View* chevron() const { return chevron_; } |
| 269 | 271 |
| 270 // Returns the profile this container is associated with. | 272 // Returns the profile this container is associated with. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 views::View* parent, | 313 views::View* parent, |
| 312 views::View* child); | 314 views::View* child); |
| 313 virtual bool GetDropFormats( | 315 virtual bool GetDropFormats( |
| 314 int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats); | 316 int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats); |
| 315 virtual bool AreDropTypesRequired(); | 317 virtual bool AreDropTypesRequired(); |
| 316 virtual bool CanDrop(const OSExchangeData& data); | 318 virtual bool CanDrop(const OSExchangeData& data); |
| 317 virtual void OnDragEntered(const views::DropTargetEvent& event); | 319 virtual void OnDragEntered(const views::DropTargetEvent& event); |
| 318 virtual int OnDragUpdated(const views::DropTargetEvent& event); | 320 virtual int OnDragUpdated(const views::DropTargetEvent& event); |
| 319 virtual void OnDragExited(); | 321 virtual void OnDragExited(); |
| 320 virtual int OnPerformDrop(const views::DropTargetEvent& event); | 322 virtual int OnPerformDrop(const views::DropTargetEvent& event); |
| 323 virtual void OnThemeChanged(); |
| 321 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); | 324 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); |
| 322 | 325 |
| 323 // Overridden from views::ViewMenuDelegate: | 326 // Overridden from views::ViewMenuDelegate: |
| 324 virtual void RunMenu(View* source, const gfx::Point& pt); | 327 virtual void RunMenu(View* source, const gfx::Point& pt); |
| 325 | 328 |
| 326 // Overridden from views::DragController: | 329 // Overridden from views::DragController: |
| 327 virtual void WriteDragData(View* sender, | 330 virtual void WriteDragData(View* sender, |
| 328 const gfx::Point& press_pt, | 331 const gfx::Point& press_pt, |
| 329 OSExchangeData* data); | 332 OSExchangeData* data); |
| 330 virtual int GetDragOperations(View* sender, const gfx::Point& p); | 333 virtual int GetDragOperations(View* sender, const gfx::Point& p); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // Set how many icons the container should show. This should only be used by | 368 // Set how many icons the container should show. This should only be used by |
| 366 // unit tests. | 369 // unit tests. |
| 367 void TestSetIconVisibilityCount(size_t icons); | 370 void TestSetIconVisibilityCount(size_t icons); |
| 368 | 371 |
| 369 // During testing we can disable animations by setting this flag to true, | 372 // During testing we can disable animations by setting this flag to true, |
| 370 // so that the bar resizes instantly, instead of having to poll it while it | 373 // so that the bar resizes instantly, instead of having to poll it while it |
| 371 // animates to open/closed status. | 374 // animates to open/closed status. |
| 372 static bool disable_animations_during_testing_; | 375 static bool disable_animations_during_testing_; |
| 373 | 376 |
| 374 private: | 377 private: |
| 378 friend class BrowserActionView; // So it can access IconHeight(). |
| 375 friend class ShowFolderMenuTask; | 379 friend class ShowFolderMenuTask; |
| 376 | 380 |
| 377 typedef std::vector<BrowserActionView*> BrowserActionViews; | 381 typedef std::vector<BrowserActionView*> BrowserActionViews; |
| 378 | 382 |
| 383 // Returns the width of an icon, optionally with its padding. |
| 384 static int IconWidth(bool include_padding); |
| 385 |
| 386 // Returns the height of an icon. |
| 387 static int IconHeight(); |
| 388 |
| 379 // ExtensionToolbarModel::Observer implementation. | 389 // ExtensionToolbarModel::Observer implementation. |
| 380 virtual void BrowserActionAdded(Extension* extension, int index); | 390 virtual void BrowserActionAdded(Extension* extension, int index); |
| 381 virtual void BrowserActionRemoved(Extension* extension); | 391 virtual void BrowserActionRemoved(Extension* extension); |
| 382 virtual void BrowserActionMoved(Extension* extension, int index); | 392 virtual void BrowserActionMoved(Extension* extension, int index); |
| 383 virtual void ModelLoaded(); | 393 virtual void ModelLoaded(); |
| 384 | 394 |
| 395 void LoadImages(); |
| 396 |
| 385 // Sets the initial container width. | 397 // Sets the initial container width. |
| 386 void SetContainerWidth(); | 398 void SetContainerWidth(); |
| 387 | 399 |
| 388 // Closes the overflow menu if open. | 400 // Closes the overflow menu if open. |
| 389 void CloseOverflowMenu(); | 401 void CloseOverflowMenu(); |
| 390 | 402 |
| 391 // Cancels the timer for showing the drop down menu. | 403 // Cancels the timer for showing the drop down menu. |
| 392 void StopShowFolderDropMenuTimer(); | 404 void StopShowFolderDropMenuTimer(); |
| 393 | 405 |
| 394 // Show the drop down folder after a slight delay. | 406 // Show the drop down folder after a slight delay. |
| 395 void StartShowFolderDropMenuTimer(); | 407 void StartShowFolderDropMenuTimer(); |
| 396 | 408 |
| 397 // Show the overflow menu. | 409 // Show the overflow menu. |
| 398 void ShowDropFolder(); | 410 void ShowDropFolder(); |
| 399 | 411 |
| 400 // Sets the drop indicator position (and schedules paint if the position has | 412 // Sets the drop indicator position (and schedules paint if the position has |
| 401 // changed). | 413 // changed). |
| 402 void SetDropIndicator(int x_pos); | 414 void SetDropIndicator(int x_pos); |
| 403 | 415 |
| 404 // Takes a width in pixels, calculates how many icons fit within that space | 416 // Given a number of |icons| and whether to |display_chevron|, returns the |
| 405 // (up to the maximum number of icons in our vector) and shaves off the | 417 // amount of pixels needed to draw the entire container. For convenience, |
| 406 // excess pixels. |allow_shrink_to_minimum| specifies whether this function | 418 // callers can set |icons| to -1 to mean "all icons". |
| 407 // clamps the size down further (down to ContainerMinSize()) if there is not | 419 int IconCountToWidth(int icons, bool display_chevron) const; |
| 408 // room for even one icon. When determining how large the container should be | |
| 409 // this should be |true|. When determining where to place items, such as the | |
| 410 // drop indicator, this should be |false|. | |
| 411 int ClampToNearestIconCount(int pixels, bool allow_shrink_to_minimum) const; | |
| 412 | 420 |
| 413 // Calculates the width of the container area NOT used to show the icons (the | 421 // Given a pixel width, returns the number of icons that fit, assuming we need |
| 414 // controls to the left and to the right of the icons). | 422 // to show a chevron. |
| 415 int WidthOfNonIconArea() const; | 423 int WidthToIconCount(int pixels) const; |
| 416 | |
| 417 // Given a number of |icons| return the amount of pixels needed to draw it, | |
| 418 // including the controls (chevron if visible and resize area). | |
| 419 int IconCountToWidth(int icons) const; | |
| 420 | 424 |
| 421 // 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 |
| 422 // still show it. We account for the chevron and the resize gripper, but not | 426 // still show it. This assumes a visible chevron because the only way we |
| 423 // all the padding that we normally show if there are icons. | 427 // would not have a chevron when shrinking down this far is if there were no |
| 428 // icons, in which case the container wouldn't be shown at all. |
| 424 int ContainerMinSize() const; | 429 int ContainerMinSize() const; |
| 425 | 430 |
| 426 // Animate to the target value (unless testing, in which case we go straight | 431 // Animate to the target value (unless testing, in which case we go straight |
| 427 // to the target size). | 432 // to the target size). |
| 428 void Animate(Tween::Type type, int target_size); | 433 void Animate(Tween::Type type, int target_size); |
| 429 | 434 |
| 430 // Returns true if this extension should be shown in this toolbar. This can | 435 // Returns true if this extension should be shown in this toolbar. This can |
| 431 // return false if we are in an incognito window and the extension is disabled | 436 // return false if we are in an incognito window and the extension is disabled |
| 432 // for incognito. | 437 // for incognito. |
| 433 bool ShouldDisplayBrowserAction(Extension* extension); | 438 bool ShouldDisplayBrowserAction(Extension* extension); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 493 |
| 489 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 494 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |
| 490 | 495 |
| 491 // Handles delayed showing of the overflow menu when hovering. | 496 // Handles delayed showing of the overflow menu when hovering. |
| 492 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; | 497 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; |
| 493 | 498 |
| 494 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 499 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 495 }; | 500 }; |
| 496 | 501 |
| 497 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 502 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |