Commit b1a2fc8c authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

Fix two bugs in the extension actions toolbar

1. Previously, we didn't animate the browser actions
   container when the visible count changed, because we set
   the width prior to calling animate. Fix it by animating to
   the desired width.
2. There was a bug where we would improperly hide an extension
   upon loading another, because we wouldn't account for the
   chevron width. Fix this, and add a test.

BUG=410348
BUG=410361

Review URL: https://codereview.chromium.org/539543002

Cr-Commit-Position: refs/heads/master@{#293947}
parent 30a1ccd6
...@@ -192,8 +192,10 @@ void BrowserActionsContainer::Init() { ...@@ -192,8 +192,10 @@ void BrowserActionsContainer::Init() {
// We wait to set the container width until now so that the chevron images // We wait to set the container width until now so that the chevron images
// will be loaded. The width calculation needs to know the chevron size. // will be loaded. The width calculation needs to know the chevron size.
if (model_ && model_->extensions_initialized()) if (model_ && model_->extensions_initialized()) {
SetContainerWidth(); container_width_ = GetPreferredWidth();
SetChevronVisibility();
}
} }
BrowserActionView* BrowserActionsContainer::GetViewForExtension( BrowserActionView* BrowserActionsContainer::GetViewForExtension(
...@@ -640,6 +642,7 @@ void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { ...@@ -640,6 +642,7 @@ void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) {
animation_target_size_ = 0; animation_target_size_ = 0;
resize_amount_ = 0; resize_amount_ = 0;
suppress_chevron_ = false; suppress_chevron_ = false;
SetChevronVisibility();
OnBrowserActionVisibilityChanged(); OnBrowserActionVisibilityChanged();
FOR_EACH_OBSERVER(BrowserActionsContainerObserver, FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
...@@ -803,17 +806,28 @@ void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, ...@@ -803,17 +806,28 @@ void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension,
if (!model_->extensions_initialized()) if (!model_->extensions_initialized())
return; return;
// Enlarge the container if it was already at maximum size and we're not in // If this is just an upgrade, then don't worry about resizing.
// the middle of upgrading. if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()->
if ((model_->GetVisibleIconCount() < 0) &&
!extensions::ExtensionSystem::Get(profile_)->runtime_data()->
IsBeingUpgraded(extension)) { IsBeingUpgraded(extension)) {
suppress_chevron_ = true; // We need to resize if either:
Animate(gfx::Tween::LINEAR, browser_action_views_.size()); // - The container is set to display all icons (visible count = -1), or
} else { // - The container will need to expand to include the chevron. This can
// Just redraw the (possibly modified) visible icon set. // happen when the container is set to display <n> icons, where <n> is
OnBrowserActionVisibilityChanged(); // the number of icons before the new icon. With the new icon, the chevron
// will need to be displayed.
int model_icon_count = model_->GetVisibleIconCount();
if (model_icon_count == -1 ||
(static_cast<size_t>(model_icon_count) < browser_action_views_.size() &&
(chevron_ && !chevron_->visible()))) {
suppress_chevron_ = true;
Animate(gfx::Tween::LINEAR, GetIconCount());
return;
}
} }
// Otherwise, we don't have to resize, so just redraw the (possibly modified)
// visible icon set.
OnBrowserActionVisibilityChanged();
} }
void BrowserActionsContainer::ToolbarExtensionRemoved( void BrowserActionsContainer::ToolbarExtensionRemoved(
...@@ -902,9 +916,7 @@ bool BrowserActionsContainer::ShowExtensionActionPopup( ...@@ -902,9 +916,7 @@ bool BrowserActionsContainer::ShowExtensionActionPopup(
} }
void BrowserActionsContainer::ToolbarVisibleCountChanged() { void BrowserActionsContainer::ToolbarVisibleCountChanged() {
int old_container_width = container_width_; if (GetPreferredWidth() != container_width_)
SetContainerWidth();
if (old_container_width != container_width_)
Animate(gfx::Tween::EASE_OUT, GetIconCount()); Animate(gfx::Tween::EASE_OUT, GetIconCount());
} }
...@@ -916,7 +928,7 @@ void BrowserActionsContainer::ToolbarHighlightModeChanged( ...@@ -916,7 +928,7 @@ void BrowserActionsContainer::ToolbarHighlightModeChanged(
// the extra complexity to create and insert only the new extensions. // the extra complexity to create and insert only the new extensions.
DeleteBrowserActionViews(); DeleteBrowserActionViews();
CreateBrowserActionViews(); CreateBrowserActionViews();
Animate(gfx::Tween::LINEAR, browser_action_views_.size()); Animate(gfx::Tween::LINEAR, GetIconCount());
} }
Browser* BrowserActionsContainer::GetBrowser() { Browser* BrowserActionsContainer::GetBrowser() {
...@@ -943,14 +955,16 @@ void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { ...@@ -943,14 +955,16 @@ void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
} }
} }
void BrowserActionsContainer::SetContainerWidth() { int BrowserActionsContainer::GetPreferredWidth() {
int visible_actions = GetIconCount(); size_t visible_actions = GetIconCount();
if (chevron_) { return IconCountToWidth(
chevron_->SetVisible( visible_actions,
static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); chevron_ && visible_actions < browser_action_views_.size());
} }
container_width_ =
IconCountToWidth(visible_actions, chevron_ && chevron_->visible()); void BrowserActionsContainer::SetChevronVisibility() {
if (chevron_)
chevron_->SetVisible(GetIconCount() < browser_action_views_.size());
} }
void BrowserActionsContainer::CloseOverflowMenu() { void BrowserActionsContainer::CloseOverflowMenu() {
......
...@@ -295,8 +295,13 @@ class BrowserActionsContainer ...@@ -295,8 +295,13 @@ class BrowserActionsContainer
// Called when a browser action's visibility may have changed. // Called when a browser action's visibility may have changed.
void OnBrowserActionVisibilityChanged(); void OnBrowserActionVisibilityChanged();
// Sets the initial container width. // Returns the preferred width of the container in order to show all icons
void SetContainerWidth(); // that should be visible and, optionally, the chevron.
int GetPreferredWidth();
// Sets the chevron to be visible or not based on whether all browser actions
// are displayed.
void SetChevronVisibility();
// Closes the overflow menu if open. // Closes the overflow menu if open.
void CloseOverflowMenu(); void CloseOverflowMenu();
......
...@@ -229,6 +229,30 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) { ...@@ -229,6 +229,30 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) {
ASSERT_TRUE(container->chevron()); ASSERT_TRUE(container->chevron());
EXPECT_TRUE(container->chevron()->visible()); EXPECT_TRUE(container->chevron()->visible());
EXPECT_FALSE(container->GetPreferredSize().IsEmpty()); EXPECT_FALSE(container->GetPreferredSize().IsEmpty());
// Reset visibility count to 2. State should be A, B, [C], and the chevron
// should be visible.
browser_actions_bar()->SetIconVisibilityCount(2);
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(1));
EXPECT_TRUE(container->chevron()->visible());
// Disable C (the overflowed extension). State should now be A, B, and the
// chevron should be hidden.
DisableExtension(idC);
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(1));
EXPECT_FALSE(container->chevron()->visible());
// Re-enable C. We should still only have 2 visible icons, and the chevron
// should be visible.
EnableExtension(idC);
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(1));
EXPECT_TRUE(container->chevron()->visible());
} }
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ForceHide) { IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ForceHide) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment