Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3142)

Unified Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 476873002: Make hiding an extension action cause it to go to the overflow menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/toolbar/browser_actions_container.cc
diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.cc b/chrome/browser/ui/views/toolbar/browser_actions_container.cc
index 92fbd3e716e193445e8d0cf209c64e5fb8bb7197..de9c60508ce18c6ea05c14e4a22d106997860565 100644
--- a/chrome/browser/ui/views/toolbar/browser_actions_container.cc
+++ b/chrome/browser/ui/views/toolbar/browser_actions_container.cc
@@ -318,8 +318,7 @@ void BrowserActionsContainer::RemoveObserver(
}
gfx::Size BrowserActionsContainer::GetPreferredSize() const {
- size_t icon_count = browser_action_views_.size() -
- (in_overflow_mode() ? main_container_->VisibleBrowserActions() : 0);
+ size_t icon_count = GetIconCount();
// If there are no actions to show, or we are in overflow mode and the main
// container is already showing them all, then no further work is required.
@@ -624,8 +623,18 @@ void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) {
int max_width = IconCountToWidth(-1, false);
container_width_ =
std::min(std::max(0, container_width_ - resize_amount), max_width);
- SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT,
- WidthToIconCount(container_width_));
+
+ // Save off the desired number of visible icons. We do this now instead of at
+ // the end of the animation so that even if the browser is shut down while
+ // animating, the right value will be restored on next run.
+ // NOTE: 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.
+ int visible_icons = WidthToIconCount(container_width_);
+ if (!profile_->IsOffTheRecord())
+ model_->SetVisibleIconCount(visible_icons);
+
+ Animate(gfx::Tween::EASE_OUT, visible_icons);
}
void BrowserActionsContainer::AnimationProgressed(
@@ -796,8 +805,6 @@ void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension,
if (!ShouldDisplayBrowserAction(extension))
return;
- size_t visible_actions = VisibleBrowserActionsAfterAnimation();
-
// Add the new browser action to the vector and the view hierarchy.
if (profile_->IsOffTheRecord())
index = model_->OriginalIndexToIncognito(index);
@@ -819,7 +826,7 @@ void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension,
!extensions::ExtensionSystem::Get(profile_)->runtime_data()->
IsBeingUpgraded(extension)) {
suppress_chevron_ = true;
- SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1);
+ Animate(gfx::Tween::LINEAR, browser_action_views_.size());
} else {
// Just redraw the (possibly modified) visible icon set.
OnBrowserActionVisibilityChanged();
@@ -854,8 +861,7 @@ void BrowserActionsContainer::ToolbarExtensionRemoved(
// overflow container by 1. Either way the size changed, so animate.
if (chevron_)
chevron_->SetVisible(false);
- SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT,
- browser_action_views_.size());
+ Animate(gfx::Tween::EASE_OUT, browser_action_views_.size());
Finnur 2014/08/21 10:47:51 I can't say for sure if this is correct. I suspect
Devlin 2014/08/21 13:56:30 Sorry; I didn't explain very well. I'm fairly cer
Finnur 2014/08/21 14:08:30 No, I would agree that there's no need to save the
Devlin 2014/08/21 15:24:59 Ah yes, sorry, width. :) (that should teach me to
}
return; // We have found the action to remove, bail out.
}
@@ -906,7 +912,10 @@ bool BrowserActionsContainer::ShowExtensionActionPopup(
}
void BrowserActionsContainer::ToolbarVisibleCountChanged() {
+ int old_container_width = container_width_;
SetContainerWidth();
+ if (old_container_width != container_width_)
+ Animate(gfx::Tween::EASE_OUT, GetIconCount());
Finnur 2014/08/21 10:47:51 I am unclear on this one too...
Devlin 2014/08/21 13:56:30 Here, we just say "Animate to the number of icons
}
void BrowserActionsContainer::ToolbarHighlightModeChanged(
@@ -917,7 +926,7 @@ void BrowserActionsContainer::ToolbarHighlightModeChanged(
// the extra complexity to create and insert only the new extensions.
DeleteBrowserActionViews();
CreateBrowserActionViews();
- SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size());
+ Animate(gfx::Tween::LINEAR, browser_action_views_.size());
Finnur 2014/08/21 10:47:50 This is probably a good change, since if the brows
}
void BrowserActionsContainer::LoadImages() {
@@ -941,13 +950,7 @@ void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
}
void BrowserActionsContainer::SetContainerWidth() {
- // The slave only draws the overflow (what isn't visible in the other
- // container).
- int visible_actions = in_overflow_mode() ?
- model_->toolbar_items().size() - model_->GetVisibleIconCount() :
- model_->GetVisibleIconCount();
- if (visible_actions < 0) // All icons should be visible.
- visible_actions = model_->toolbar_items().size();
+ int visible_actions = GetIconCount();
if (chevron_) {
chevron_->SetVisible(
static_cast<size_t>(visible_actions) < model_->toolbar_items().size());
@@ -1024,17 +1027,8 @@ int BrowserActionsContainer::MinimumNonemptyWidth() const {
chevron_->GetPreferredSize().width();
}
-void BrowserActionsContainer::SaveDesiredSizeAndAnimate(
- gfx::Tween::Type tween_type,
- size_t num_visible_icons) {
- // Save off the desired number of visible icons. We do this now instead of at
- // the end of the animation so that even if the browser is shut down while
- // animating, the right value will be restored on next run.
- // NOTE: 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(num_visible_icons);
Devlin 2014/08/21 00:06:29 Had to move this to OnResize because otherwise the
+void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type,
+ size_t num_visible_icons) {
int target_size = IconCountToWidth(num_visible_icons,
num_visible_icons < browser_action_views_.size());
if (resize_animation_ && !disable_animations_during_testing_) {
@@ -1087,3 +1081,11 @@ BrowserActionView* BrowserActionsContainer::GetViewForExtension(
return NULL;
}
+
+size_t BrowserActionsContainer::GetIconCount() const {
+ int visible_icons = model_->GetVisibleIconCount();
+ if (visible_icons == -1)
+ visible_icons = model_->toolbar_items().size();
+ return in_overflow_mode() ?
+ model_->toolbar_items().size() - visible_icons : visible_icons;
+}

Powered by Google App Engine
This is Rietveld 408576698