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