summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/browser_actions_container.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 20:19:45 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 20:19:45 +0000
commitc6980ea5692e31581fe2f65c6ee2a5a9547145f2 (patch)
treea0aa2b959bb561340df5236818844f782e38ed2b /chrome/browser/views/browser_actions_container.cc
parent7b09195a9d70b397da7b6dea3a9fabe30fb1c79b (diff)
downloadchromium_src-c6980ea5692e31581fe2f65c6ee2a5a9547145f2.zip
chromium_src-c6980ea5692e31581fe2f65c6ee2a5a9547145f2.tar.gz
chromium_src-c6980ea5692e31581fe2f65c6ee2a5a9547145f2.tar.bz2
Use the new number-of-browser-actions pref instead of width-in-pixels to
save and restore the browser action toolbar's size. Linux already does this. Also fixes a regression where Windows would ignore the pref and always show all browser actions on startup. Review URL: http://codereview.chromium.org/1081009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42250 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/browser_actions_container.cc')
-rw-r--r--chrome/browser/views/browser_actions_container.cc50
1 files changed, 29 insertions, 21 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc
index 32f0f02..d56e421 100644
--- a/chrome/browser/views/browser_actions_container.cc
+++ b/chrome/browser/views/browser_actions_container.cc
@@ -338,11 +338,7 @@ BrowserActionsContainer::BrowserActionsContainer(
ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) {
SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR);
- ExtensionsService* extension_service = profile_->GetExtensionsService();
- if (!extension_service) // The |extension_service| can be NULL in Incognito.
- return;
-
- model_ = extension_service->toolbar_model();
+ model_ = profile_->GetExtensionsService()->toolbar_model();
model_->AddObserver(this);
resize_animation_.reset(new SlideAnimation(this));
@@ -360,15 +356,24 @@ BrowserActionsContainer::BrowserActionsContainer(
chevron_->EnableCanvasFlippingForRTLUI(true);
AddChildView(chevron_);
- int predefined_width =
- profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth);
- if (predefined_width == 0) {
- // The width will never be 0 (due to container min size restriction)
- // except when no width has been saved. So, in that case ask the model
- // how many icons we'll show and set initial size to that.
- predefined_width = IconCountToWidth(model_->size());
+ if (!profile_->GetPrefs()->HasPrefPath(prefs::kExtensionToolbarSize)) {
+ // Migration code to the new VisibleIconCount pref.
+ // TODO(mpcomplete): remove this after users are upgraded to 5.0.
+ int predefined_width =
+ profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth);
+ if (predefined_width != 0) {
+ int icon_width = (kButtonSize + kBrowserActionButtonPadding);
+ model_->SetVisibleIconCount(
+ (predefined_width - WidthOfNonIconArea()) / icon_width);
+ }
}
- container_size_ = gfx::Size(predefined_width, kButtonSize);
+
+ int visible_actions = model_->GetVisibleIconCount();
+ if (visible_actions < 0) // all icons should be visible
+ visible_actions = model_->size();
+ else
+ chevron_->SetVisible(true);
+ container_size_ = gfx::Size(IconCountToWidth(visible_actions), kButtonSize);
}
BrowserActionsContainer::~BrowserActionsContainer() {
@@ -567,8 +572,6 @@ gfx::Size BrowserActionsContainer::GetPreferredSize() {
}
void BrowserActionsContainer::Layout() {
- if (!resize_gripper_ || !chevron_)
- return; // These classes are not created in Incognito mode.
if (browser_action_views_.size() == 0) {
resize_gripper_->SetVisible(false);
chevron_->SetVisible(false);
@@ -895,14 +898,16 @@ void BrowserActionsContainer::BrowserActionAdded(Extension* extension,
browser_action_views_.insert(browser_action_views_.begin() + index, view);
AddChildView(index, view);
+ // If we are still initializing the container, don't bother animating.
+ if (model_->size() != browser_action_views_.size())
+ return;
+
// For details on why we do the following see the class comments in the
// header.
// Determine if we need to increase (we only do that if the container was
- // showing all icons before the addition of this icon). We use -1 because
- // we don't want to count the view that we just added.
- if (visible_actions < browser_action_views_.size() - 1 ||
- extension->being_upgraded()) {
+ // showing all icons before the addition of this icon).
+ if (model_->GetVisibleIconCount() >= 0 || extension->being_upgraded()) {
// Some icons were hidden, don't increase the size of the container.
OnBrowserActionVisibilityChanged();
} else {
@@ -1064,8 +1069,11 @@ void BrowserActionsContainer::AnimationEnded(const Animation* animation) {
OnBrowserActionVisibilityChanged();
suppress_chevron_ = false;
- profile_->GetPrefs()->SetInteger(prefs::kBrowserActionContainerWidth,
- container_size_.width());
+ // Don't save the icon count in incognito because there may be fewer icons
+ // in that mode. The result is that the container in a normal window is always
+ // at least as wide as in an incognito window.
+ if (!profile_->IsOffTheRecord())
+ model_->SetVisibleIconCount(VisibleBrowserActions());
}
void BrowserActionsContainer::NotifyMenuDeleted(