diff options
author | sidchat@chromium.org <sidchat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 23:41:59 +0000 |
---|---|---|
committer | sidchat@chromium.org <sidchat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 23:41:59 +0000 |
commit | 4ed536fb5831c7ff6c5d2cacaf5182bf9f00af70 (patch) | |
tree | 41799d050159d20283345dc396247e4ee0aae27f | |
parent | 3ed662c37a3d881feb5b6578eb2e0e44586b3f1a (diff) | |
download | chromium_src-4ed536fb5831c7ff6c5d2cacaf5182bf9f00af70.zip chromium_src-4ed536fb5831c7ff6c5d2cacaf5182bf9f00af70.tar.gz chromium_src-4ed536fb5831c7ff6c5d2cacaf5182bf9f00af70.tar.bz2 |
Browser actions: limit minimum size of omnibox. When decreasing the width of the omnibox, the Browser actions start falling off one by one till there are two left. After that, the omnibox itself starts shrinking, as it normally does. Note that if there is only one browser action, then it remains sticky to the toolbar.
BUG=23962
TEST=none
Review URL: http://codereview.chromium.org/262008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28628 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/browser_actions_container.cc | 28 | ||||
-rw-r--r-- | chrome/browser/views/browser_actions_container.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 18 |
3 files changed, 51 insertions, 1 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index e76bce3..a6f2e85 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -35,6 +35,10 @@ static const int kHorizontalPadding = 4; // can draw the badge outside the visual bounds of the contianer. static const int kControlVertOffset = 6; +// The maximum of the minimum number of browser actions present when there is +// not enough space to fit all the browser actions in the toolbar. +static const int kMinimumNumberOfVisibleBrowserActions = 2; + //////////////////////////////////////////////////////////////////////////////// // BrowserActionButton @@ -492,7 +496,12 @@ void BrowserActionsContainer::Layout() { for (size_t i = 0; i < browser_action_views_.size(); ++i) { BrowserActionView* view = browser_action_views_[i]; int x = kHorizontalPadding + i * kIconSize; - view->SetBounds(x, 0, kIconSize, height()); + if (x + kIconSize <= width()) { + view->SetBounds(x, 0, kIconSize, height()); + view->SetVisible(true); + } else { + view->SetVisible(false); + } } } @@ -530,3 +539,20 @@ void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble) { MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod(&BrowserActionsContainer::HidePopup)); } + +int BrowserActionsContainer::GetClippedPreferredWidth(int available_width) { + if (browser_action_views_.size() == 0) + return 0; + + // We have at least one browser action. Make some of them sticky. + int min_width = kHorizontalPadding * 2 + + std::min(static_cast<int>(browser_action_views_.size()), + kMinimumNumberOfVisibleBrowserActions) * kIconSize; + + // Even if available_width is <= 0, we still return at least the |min_width|. + if (available_width <= 0) + return min_width; + + return std::max(min_width, available_width - available_width % kIconSize + + kHorizontalPadding * 2); +} diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h index 76e8101..f3b3863 100644 --- a/chrome/browser/views/browser_actions_container.h +++ b/chrome/browser/views/browser_actions_container.h @@ -63,6 +63,12 @@ class BrowserActionsContainer : public views::View, virtual void BubbleGotFocus(BrowserBubble* bubble); virtual void BubbleLostFocus(BrowserBubble* bubble); + // Get clipped width required to precisely fit the browser action icons + // given a tentative available width. The minimum size it returns is not + // zero, but depends on the minimum number of icons that have to be there + // by default irrespective of the available space to draw them. + int GetClippedPreferredWidth(int available_width); + private: // Hide the current popup. diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index ef460c4..d21db27 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -61,6 +61,9 @@ static const int kStatusBubbleWidth = 480; // Separation between the location bar and the menus. static const int kMenuButtonOffset = 3; +// The minimum width of the location bar when browser actions are visible. +static const int kMinLocationBarWidthWithBrowserActions = 400; + // Padding to the right of the location bar static const int kPaddingRight = 2; @@ -525,6 +528,21 @@ void ToolbarView::Layout() { int available_width = width() - kPaddingRight - bookmark_menu_width - app_menu_width - page_menu_width - browser_actions_width - kMenuButtonOffset - go_button_width - location_x; + + // We wait until the width of location bar is a minimum allowed. After this + // state, the width available for the browser actions is compromised until + // it can hold a minimum number of browser actions (currently 2). After this + // state, the location bar width starts shrinking again, with the minimum + // number of browser actions sticking on the the right of the location bar. + // TODO(sidchat): Use percentage width instead of fixed width to determine + // minimum width of the location bar. BUG=24316. + if (available_width < kMinLocationBarWidthWithBrowserActions && + browser_actions_width > 0) { + available_width += browser_actions_width; + browser_actions_width = browser_actions_->GetClippedPreferredWidth( + available_width - kMinLocationBarWidthWithBrowserActions); + available_width -= browser_actions_width; + } location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), child_height); |