Commit 0af77c4e authored by benwells's avatar benwells Committed by Commit bot

Revert of Make extensions that desire to act pop out if in overflow (patchset...

Revert of Make extensions that desire to act pop out if in overflow (patchset #6 id:200001 of https://codereview.chromium.org/675023002/)

Reason for revert:
Suspect this patch of causing errors on linux valgrind for LocationBarControllerUnitTest.NavigationClearsState.

http://build.chromium.org/p/chromium.memory.fyi/builders/Linux%20Tests%20%28valgrind%29%285%29/builds/31337

Sample valgrind output:
Suppression (error hash=#606630BA25518095#):
For more info on using suppressions see http://dev.chromium.org/developers/tree-sheriffs/sheriff-details-chromium/memory-sheriff#TOC-Suppressing-memory-reports
{
<insert_a_suppression_name_here>
Memcheck:Unaddressable
fun:_ZN16ExtensionService21NotifyExtensionLoadedEPKN10extensions9ExtensionE
fun:_ZN16ExtensionService12AddExtensionEPKN10extensions9ExtensionE
fun:_ZN10extensions12_GLOBAL__N_129LocationBarControllerUnitTest12AddExtensionEbRKSs
fun:_ZN10extensions12_GLOBAL__N_156LocationBarControllerUnitTest_NavigationClearsState_Test8TestBodyEv
}

Original issue's description:
> Make extensions that desire to act pop out if in overflow
>
> If an extension desires to act, it should pop itself out of
> the overflow menu.  There should also be a visual queue for
> extensions that are already visible, but what exactly that
> should be is still being discussed.
>
> BUG=417441
>
> Committed: https://crrev.com/d604171517135387ca3b4c33d7f1774c8d2d38b0
> Cr-Commit-Position: refs/heads/master@{#302511}

TBR=finnur@chromium.org,pkasting@chromium.org,rdevlin.cronin@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=417441

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

Cr-Commit-Position: refs/heads/master@{#302563}
parent f5c403d7
...@@ -121,8 +121,9 @@ void ExtensionToolbarModel::MoveExtensionIcon(const std::string& id, ...@@ -121,8 +121,9 @@ void ExtensionToolbarModel::MoveExtensionIcon(const std::string& id,
UpdatePrefs(); UpdatePrefs();
} }
void ExtensionToolbarModel::SetVisibleIconCount(size_t count) { void ExtensionToolbarModel::SetVisibleIconCount(int count) {
visible_icon_count_ = (count == toolbar_items_.size()) ? -1 : count; visible_icon_count_ =
count == static_cast<int>(toolbar_items_.size()) ? -1 : count;
// Only set the prefs if we're not in highlight mode and the profile is not // Only set the prefs if we're not in highlight mode and the profile is not
// incognito. Highlight mode is designed to be a transitory state, and should // incognito. Highlight mode is designed to be a transitory state, and should
...@@ -151,18 +152,11 @@ void ExtensionToolbarModel::OnExtensionActionUpdated( ...@@ -151,18 +152,11 @@ void ExtensionToolbarModel::OnExtensionActionUpdated(
ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID( ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID(
extension_action->extension_id()); extension_action->extension_id());
// Notify observers if the extension exists and is in the model. // Notify observers if the extension exists and is in the model.
ExtensionList::const_iterator iter = if (extension &&
std::find(toolbar_items_.begin(), toolbar_items_.end(), extension); std::find(toolbar_items_.begin(),
if (iter != toolbar_items_.end()) { toolbar_items_.end(),
FOR_EACH_OBSERVER( extension) != toolbar_items_.end()) {
Observer, observers_, ToolbarExtensionUpdated(extension)); FOR_EACH_OBSERVER(Observer, observers_, ToolbarExtensionUpdated(extension));
// If the action was in the overflow menu, we have to alert observers that
// the toolbar needs to be reordered (to show the action).
if (static_cast<size_t>(iter - toolbar_items_.begin()) >=
visible_icon_count()) {
FOR_EACH_OBSERVER(
Observer, observers_, OnToolbarReorderNecessary(web_contents));
}
} }
} }
...@@ -506,7 +500,9 @@ void ExtensionToolbarModel::IncognitoPopulate() { ...@@ -506,7 +500,9 @@ void ExtensionToolbarModel::IncognitoPopulate() {
ExtensionToolbarModel::Get(profile_->GetOriginalProfile()); ExtensionToolbarModel::Get(profile_->GetOriginalProfile());
// Find the absolute value of the original model's count. // Find the absolute value of the original model's count.
int original_visible = original_model->visible_icon_count(); int original_visible = original_model->GetVisibleIconCount();
if (original_visible == -1)
original_visible = original_model->toolbar_items_.size();
// In incognito mode, we show only those extensions that are // In incognito mode, we show only those extensions that are
// incognito-enabled. Further, any actions that were overflowed in regular // incognito-enabled. Further, any actions that were overflowed in regular
...@@ -603,49 +599,6 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() { ...@@ -603,49 +599,6 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() {
} }
} }
size_t ExtensionToolbarModel::GetVisibleIconCountForTab(
content::WebContents* web_contents) const {
if (all_icons_visible())
return visible_icon_count(); // Already displaying all actions.
ExtensionActionAPI* extension_action_api = ExtensionActionAPI::Get(profile_);
size_t total_icons = visible_icon_count_;
for (size_t i = total_icons; i < toolbar_items_.size(); ++i) {
if (extension_action_api->ExtensionWantsToRun(toolbar_items_[i].get(),
web_contents))
++total_icons;
}
return total_icons;
}
ExtensionList ExtensionToolbarModel::GetItemOrderForTab(
content::WebContents* web_contents) const {
// If we're highlighting, the items are always the same.
if (is_highlighting_)
return highlighted_items_;
// Start by initializing the array to be the same as toolbar items (this isn't
// any more expensive than initializing it to be of the same size with all
// nulls, and saves us time at the end).
ExtensionList result = toolbar_items_;
if (toolbar_items_.empty())
return result;
ExtensionList overflowed_actions_wanting_to_run;
ExtensionActionAPI* extension_action_api = ExtensionActionAPI::Get(profile_);
size_t boundary = visible_icon_count();
// Rotate any actions that want to run to the boundary between visible and
// overflowed actions.
for (ExtensionList::iterator iter = result.begin() + boundary;
iter != result.end(); ++iter) {
if (extension_action_api->ExtensionWantsToRun(iter->get(), web_contents)) {
std::rotate(result.begin() + boundary, iter, iter + 1);
++boundary;
}
}
return result;
}
bool ExtensionToolbarModel::ShowExtensionActionPopup( bool ExtensionToolbarModel::ShowExtensionActionPopup(
const Extension* extension, const Extension* extension,
Browser* browser, Browser* browser,
......
...@@ -41,17 +41,16 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -41,17 +41,16 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// delegate. // delegate.
class Observer { class Observer {
public: public:
// TODO(devlin): Rename these methods to be OnFoo. // An extension has been added to the toolbar and should go at |index|.
// Signals that an |extension| has been added to the toolbar at |index|.
virtual void ToolbarExtensionAdded(const Extension* extension, virtual void ToolbarExtensionAdded(const Extension* extension,
int index) = 0; int index) = 0;
// Signals that the given |extension| has been removed from the toolbar. // The given |extension| should be removed from the toolbar.
virtual void ToolbarExtensionRemoved(const Extension* extension) = 0; virtual void ToolbarExtensionRemoved(const Extension* extension) = 0;
// Signals that the given |extension| has been moved to |index|. |index| is // The given |extension| has been moved to |index|. |index| is the desired
// the desired *final* index of the extension (that is, in the adjusted // *final* index of the extension (that is, in the adjusted order, extension
// order, extension should be at |index|). // should be at |index|).
virtual void ToolbarExtensionMoved(const Extension* extension, virtual void ToolbarExtensionMoved(const Extension* extension,
int index) = 0; int index) = 0;
...@@ -59,18 +58,18 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -59,18 +58,18 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// updated. // updated.
virtual void ToolbarExtensionUpdated(const Extension* extension) = 0; virtual void ToolbarExtensionUpdated(const Extension* extension) = 0;
// Signals the |extension| to show the popup now in the active window. // Signal the |extension| to show the popup now in the active window.
// If |grant_active_tab| is true, then active tab permissions should be // If |grant_active_tab| is true, then active tab permissions should be
// given to the extension (only do this if this is through a user action). // given to the extension (only do this if this is through a user action).
// Returns true if a popup was slated to be shown. // Returns true if a popup was slated to be shown.
virtual bool ShowExtensionActionPopup(const Extension* extension, virtual bool ShowExtensionActionPopup(const Extension* extension,
bool grant_active_tab) = 0; bool grant_active_tab) = 0;
// Signals when the container needs to be redrawn because of a size change, // Signal when the container needs to be redrawn because of a size change,
// and when the model has finished loading. // and when the model has finished loading.
virtual void ToolbarVisibleCountChanged() = 0; virtual void ToolbarVisibleCountChanged() = 0;
// Signals that the model has entered or exited highlighting mode, or that // Signal that the model has entered or exited highlighting mode, or that
// the extensions being highlighted have (probably*) changed. Highlighting // the extensions being highlighted have (probably*) changed. Highlighting
// mode indicates that only a subset of the extensions are actively // mode indicates that only a subset of the extensions are actively
// displayed, and those extensions should be highlighted for extra emphasis. // displayed, and those extensions should be highlighted for extra emphasis.
...@@ -79,12 +78,6 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -79,12 +78,6 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// with the new set (and just assume the new set is different). // with the new set (and just assume the new set is different).
virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0; virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0;
// Signals that the toolbar needs to be reordered for the given
// |web_contents|. This is caused by an overflowed action wanting to run,
// and needing to "pop itself out".
virtual void OnToolbarReorderNecessary(
content::WebContents* web_contents) = 0;
// Returns the browser associated with the Observer. // Returns the browser associated with the Observer.
virtual Browser* GetBrowser() = 0; virtual Browser* GetBrowser() = 0;
...@@ -95,7 +88,7 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -95,7 +88,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// Convenience function to get the ExtensionToolbarModel for a Profile. // Convenience function to get the ExtensionToolbarModel for a Profile.
static ExtensionToolbarModel* Get(Profile* profile); static ExtensionToolbarModel* Get(Profile* profile);
// Adds or removes an observer. // Add or remove an observer.
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
...@@ -105,14 +98,10 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -105,14 +98,10 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// Sets the number of extension icons that should be visible. // Sets the number of extension icons that should be visible.
// If count == size(), this will set the visible icon count to -1, meaning // If count == size(), this will set the visible icon count to -1, meaning
// "show all actions". // "show all actions".
void SetVisibleIconCount(size_t count); void SetVisibleIconCount(int count);
size_t visible_icon_count() const {
return visible_icon_count_ == -1 ?
toolbar_items().size() : static_cast<size_t>(visible_icon_count_);
}
bool all_icons_visible() const { return visible_icon_count_ == -1; } // As above, a return value of -1 represents "show all actions".
int GetVisibleIconCount() const { return visible_icon_count_; }
bool extensions_initialized() const { return extensions_initialized_; } bool extensions_initialized() const { return extensions_initialized_; }
...@@ -124,16 +113,6 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -124,16 +113,6 @@ class ExtensionToolbarModel : public content::NotificationObserver,
void OnExtensionToolbarPrefChange(); void OnExtensionToolbarPrefChange();
// Returns the item order for a given tab. This can be different from the
// base item order if the action wants to run on the given page, and needs to
// be popped out of overflow.
ExtensionList GetItemOrderForTab(content::WebContents* web_contents) const;
// Returns the visible icon count for a given tab. This can be different from
// the base item order if the action wants to run on the given page and needs
// to be popped out of overflow.
size_t GetVisibleIconCountForTab(content::WebContents* web_contents) const;
// Finds the Observer associated with |browser| and tells it to display a // Finds the Observer associated with |browser| and tells it to display a
// popup for the given |extension|. If |grant_active_tab| is true, this // popup for the given |extension|. If |grant_active_tab| is true, this
// grants active tab permissions to the |extension|; only do this because of // grants active tab permissions to the |extension|; only do this because of
...@@ -147,7 +126,7 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -147,7 +126,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// the overflow bucket). // the overflow bucket).
void EnsureVisibility(const ExtensionIdList& extension_ids); void EnsureVisibility(const ExtensionIdList& extension_ids);
// Highlights the extensions specified by |extension_ids|. This will cause // Highlight the extensions specified by |extension_ids|. This will cause
// the ToolbarModel to only display those extensions. // the ToolbarModel to only display those extensions.
// Highlighting mode is only entered if there is at least one extension to // Highlighting mode is only entered if there is at least one extension to
// be shown. // be shown.
...@@ -250,9 +229,7 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -250,9 +229,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
ExtensionIdList last_known_positions_; ExtensionIdList last_known_positions_;
// The number of icons visible (the rest should be hidden in the overflow // The number of icons visible (the rest should be hidden in the overflow
// chevron). A value of -1 indicates that all icons should be visible. // chevron).
// TODO(devlin): Make a new variable to indicate that all icons should be
// visible, instead of overloading this one.
int visible_icon_count_; int visible_icon_count_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
......
...@@ -245,10 +245,6 @@ class ExtensionServiceObserverBridge ...@@ -245,10 +245,6 @@ class ExtensionServiceObserverBridge
void ToolbarVisibleCountChanged() override {} void ToolbarVisibleCountChanged() override {}
void OnToolbarReorderNecessary(content::WebContents* web_contents) override {
// TODO(devlin): Implement on mac.
}
void ToolbarHighlightModeChanged(bool is_highlighting) override {} void ToolbarHighlightModeChanged(bool is_highlighting) override {}
Browser* GetBrowser() override { return browser_; } Browser* GetBrowser() override { return browser_; }
...@@ -359,7 +355,9 @@ class ExtensionServiceObserverBridge ...@@ -359,7 +355,9 @@ class ExtensionServiceObserverBridge
} }
- (void)resizeContainerAndAnimate:(BOOL)animate { - (void)resizeContainerAndAnimate:(BOOL)animate {
int iconCount = toolbarModel_->visible_icon_count(); int iconCount = toolbarModel_->GetVisibleIconCount();
if (iconCount < 0) // If no buttons are hidden.
iconCount = [self buttonCount];
[containerView_ resizeToWidth:[self containerWidthWithButtonCount:iconCount] [containerView_ resizeToWidth:[self containerWidthWithButtonCount:iconCount]
animate:animate]; animate:animate];
...@@ -379,8 +377,9 @@ class ExtensionServiceObserverBridge ...@@ -379,8 +377,9 @@ class ExtensionServiceObserverBridge
if (!toolbarModel_) if (!toolbarModel_)
return 0; return 0;
int savedButtonCount = toolbarModel_->visible_icon_count(); int savedButtonCount = toolbarModel_->GetVisibleIconCount();
if (static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) if (savedButtonCount < 0 || // all icons are visible
static_cast<NSUInteger>(savedButtonCount) > [self buttonCount])
savedButtonCount = [self buttonCount]; savedButtonCount = [self buttonCount];
return [self containerWidthWithButtonCount:savedButtonCount]; return [self containerWidthWithButtonCount:savedButtonCount];
} }
......
...@@ -716,7 +716,7 @@ void WrenchMenuModel::CreateExtensionToolbarOverflowMenu() { ...@@ -716,7 +716,7 @@ void WrenchMenuModel::CreateExtensionToolbarOverflowMenu() {
extensions::ExtensionToolbarModel* toolbar_model = extensions::ExtensionToolbarModel* toolbar_model =
extensions::ExtensionToolbarModel::Get(browser_->profile()); extensions::ExtensionToolbarModel::Get(browser_->profile());
// A count of -1 means all actions are visible. // A count of -1 means all actions are visible.
if (!toolbar_model->all_icons_visible()) if (toolbar_model->GetVisibleIconCount() != -1)
AddSeparator(ui::UPPER_SEPARATOR); AddSeparator(ui::UPPER_SEPARATOR);
#endif // defined(TOOLKIT_VIEWS) #endif // defined(TOOLKIT_VIEWS)
} }
......
...@@ -60,8 +60,7 @@ ScopedVector<ToolbarActionViewController> GetToolbarActions( ...@@ -60,8 +60,7 @@ ScopedVector<ToolbarActionViewController> GetToolbarActions(
// Extension actions come first. // Extension actions come first.
extensions::ExtensionActionManager* action_manager = extensions::ExtensionActionManager* action_manager =
extensions::ExtensionActionManager::Get(browser->profile()); extensions::ExtensionActionManager::Get(browser->profile());
const extensions::ExtensionList& toolbar_items = model->GetItemOrderForTab( const extensions::ExtensionList& toolbar_items = model->toolbar_items();
browser->tab_strip_model()->GetActiveWebContents());
for (const scoped_refptr<const Extension>& extension : toolbar_items) { for (const scoped_refptr<const Extension>& extension : toolbar_items) {
actions.push_back(new ExtensionActionViewController( actions.push_back(new ExtensionActionViewController(
extension.get(), extension.get(),
...@@ -126,8 +125,6 @@ BrowserActionsContainer::BrowserActionsContainer( ...@@ -126,8 +125,6 @@ BrowserActionsContainer::BrowserActionsContainer(
resize_area_(NULL), resize_area_(NULL),
chevron_(NULL), chevron_(NULL),
suppress_chevron_(false), suppress_chevron_(false),
suppress_animation_(false),
suppress_layout_(false),
resize_amount_(0), resize_amount_(0),
animation_target_size_(0) { animation_target_size_(0) {
set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR);
...@@ -197,22 +194,8 @@ ToolbarActionView* BrowserActionsContainer::GetViewForExtension( ...@@ -197,22 +194,8 @@ ToolbarActionView* BrowserActionsContainer::GetViewForExtension(
} }
void BrowserActionsContainer::RefreshToolbarActionViews() { void BrowserActionsContainer::RefreshToolbarActionViews() {
if (toolbar_action_views_.empty())
return; // Nothing to do.
// When we do a bulk-refresh of views (such as when we switch tabs), we don't
// animate the difference. We only animate when it's a change driven by the
// action.
base::AutoReset<bool> animation_resetter(&suppress_animation_, true);
{
// Don't layout until the end.
base::AutoReset<bool> layout_resetter(&suppress_layout_, true);
for (ToolbarActionView* view : toolbar_action_views_) for (ToolbarActionView* view : toolbar_action_views_)
view->UpdateState(); view->UpdateState();
}
ReorderViews(); // Also triggers a layout.
} }
void BrowserActionsContainer::CreateToolbarActionViews() { void BrowserActionsContainer::CreateToolbarActionViews() {
...@@ -220,10 +203,6 @@ void BrowserActionsContainer::CreateToolbarActionViews() { ...@@ -220,10 +203,6 @@ void BrowserActionsContainer::CreateToolbarActionViews() {
if (!model_) if (!model_)
return; return;
{
// We don't Layout while creating views. Instead, Layout() once at the end.
base::AutoReset<bool> layout_resetter(&suppress_layout_, true);
ScopedVector<ToolbarActionViewController> actions = ScopedVector<ToolbarActionViewController> actions =
GetToolbarActions(model_, browser_); GetToolbarActions(model_, browser_);
for (ToolbarActionViewController* controller : actions) { for (ToolbarActionViewController* controller : actions) {
...@@ -233,10 +212,6 @@ void BrowserActionsContainer::CreateToolbarActionViews() { ...@@ -233,10 +212,6 @@ void BrowserActionsContainer::CreateToolbarActionViews() {
AddChildView(view); AddChildView(view);
} }
actions.weak_clear(); actions.weak_clear();
}
Layout();
SchedulePaint();
} }
void BrowserActionsContainer::DeleteToolbarActionViews() { void BrowserActionsContainer::DeleteToolbarActionViews() {
...@@ -273,10 +248,12 @@ void BrowserActionsContainer::ExecuteExtensionCommand( ...@@ -273,10 +248,12 @@ void BrowserActionsContainer::ExecuteExtensionCommand(
void BrowserActionsContainer::NotifyActionMovedToOverflow() { void BrowserActionsContainer::NotifyActionMovedToOverflow() {
// When an action is moved to overflow, we shrink the size of the container // When an action is moved to overflow, we shrink the size of the container
// by 1. // by 1.
size_t icon_count = model_->visible_icon_count(); int icon_count = model_->GetVisibleIconCount();
// Since this happens when an icon moves from the main bar to overflow, we // Since this happens when an icon moves from the main bar to overflow, we
// can't possibly have had no visible icons on the main bar. // can't possibly have had no visible icons on the main bar.
DCHECK_NE(0u, icon_count); DCHECK_NE(0, icon_count);
if (icon_count == -1)
icon_count = toolbar_action_views_.size();
model_->SetVisibleIconCount(icon_count - 1); model_->SetVisibleIconCount(icon_count - 1);
} }
...@@ -380,9 +357,6 @@ gfx::Size BrowserActionsContainer::GetMinimumSize() const { ...@@ -380,9 +357,6 @@ gfx::Size BrowserActionsContainer::GetMinimumSize() const {
} }
void BrowserActionsContainer::Layout() { void BrowserActionsContainer::Layout() {
if (suppress_layout_)
return;
if (toolbar_action_views_.empty()) { if (toolbar_action_views_.empty()) {
SetVisible(false); SetVisible(false);
return; return;
...@@ -576,7 +550,7 @@ int BrowserActionsContainer::OnPerformDrop( ...@@ -576,7 +550,7 @@ int BrowserActionsContainer::OnPerformDrop(
if (in_overflow_mode()) if (in_overflow_mode())
main_container_->NotifyActionMovedToOverflow(); main_container_->NotifyActionMovedToOverflow();
else // This is the main container. else // This is the main container.
model_->SetVisibleIconCount(model_->visible_icon_count() + 1); model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1);
} }
OnDragExited(); // Perform clean up after dragging. OnDragExited(); // Perform clean up after dragging.
...@@ -807,13 +781,14 @@ void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, ...@@ -807,13 +781,14 @@ void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension,
if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()->
IsBeingUpgraded(extension)) { IsBeingUpgraded(extension)) {
// We need to resize if either: // We need to resize if either:
// - The container is set to display all icons, or // - The container is set to display all icons (visible count = -1), or
// - The container will need to expand to include the chevron. This can // - The container will need to expand to include the chevron. This can
// happen when the container is set to display <n> icons, where <n> is // happen when the container is set to display <n> icons, where <n> is
// the number of icons before the new icon. With the new icon, the chevron // the number of icons before the new icon. With the new icon, the chevron
// will need to be displayed. // will need to be displayed.
if (model_->all_icons_visible() || int model_icon_count = model_->GetVisibleIconCount();
(model_->visible_icon_count() < toolbar_action_views_.size() && if (model_icon_count == -1 ||
(static_cast<size_t>(model_icon_count) < toolbar_action_views_.size() &&
(chevron_ && !chevron_->visible()))) { (chevron_ && !chevron_->visible()))) {
suppress_chevron_ = true; suppress_chevron_ = true;
Animate(gfx::Tween::LINEAR, GetIconCount()); Animate(gfx::Tween::LINEAR, GetIconCount());
...@@ -905,15 +880,8 @@ bool BrowserActionsContainer::ShowExtensionActionPopup( ...@@ -905,15 +880,8 @@ bool BrowserActionsContainer::ShowExtensionActionPopup(
} }
void BrowserActionsContainer::ToolbarVisibleCountChanged() { void BrowserActionsContainer::ToolbarVisibleCountChanged() {
if (GetPreferredWidth() != container_width_) { if (GetPreferredWidth() != container_width_)
Animate(gfx::Tween::EASE_OUT, GetIconCount()); Animate(gfx::Tween::EASE_OUT, GetIconCount());
} else if (animation_target_size_ != 0) {
// It's possible that we're right where we're supposed to be in terms of
// icon count, but that we're also currently resizing. If this is the case,
// end the current animation with the current width.
animation_target_size_ = container_width_;
resize_animation_->Reset();
}
} }
void BrowserActionsContainer::ToolbarHighlightModeChanged( void BrowserActionsContainer::ToolbarHighlightModeChanged(
...@@ -927,12 +895,6 @@ void BrowserActionsContainer::ToolbarHighlightModeChanged( ...@@ -927,12 +895,6 @@ void BrowserActionsContainer::ToolbarHighlightModeChanged(
Animate(gfx::Tween::LINEAR, GetIconCount()); Animate(gfx::Tween::LINEAR, GetIconCount());
} }
void BrowserActionsContainer::OnToolbarReorderNecessary(
content::WebContents* web_contents) {
if (GetCurrentWebContents() == web_contents)
ReorderViews();
}
Browser* BrowserActionsContainer::GetBrowser() { Browser* BrowserActionsContainer::GetBrowser() {
return browser_; return browser_;
} }
...@@ -1018,8 +980,7 @@ int BrowserActionsContainer::MinimumNonemptyWidth() const { ...@@ -1018,8 +980,7 @@ int BrowserActionsContainer::MinimumNonemptyWidth() const {
void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type, void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type,
size_t num_visible_icons) { size_t num_visible_icons) {
int target_size = IconCountToWidth(num_visible_icons); int target_size = IconCountToWidth(num_visible_icons);
if (resize_animation_ && !disable_animations_during_testing_ && if (resize_animation_ && !disable_animations_during_testing_) {
!suppress_animation_) {
// Animate! We have to set the animation_target_size_ after calling Reset(), // Animate! We have to set the animation_target_size_ after calling Reset(),
// because that could end up calling AnimationEnded which clears the value. // because that could end up calling AnimationEnded which clears the value.
resize_animation_->Reset(); resize_animation_->Reset();
...@@ -1032,58 +993,20 @@ void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type, ...@@ -1032,58 +993,20 @@ void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type,
} }
} }
void BrowserActionsContainer::ReorderViews() {
extensions::ExtensionList new_order =
model_->GetItemOrderForTab(GetCurrentWebContents());
if (new_order.empty())
return; // Nothing to do.
#if DCHECK_IS_ON
// Make sure the lists are in sync. There should be a view for each action in
// the new order.
// |toolbar_action_views_| may have more views than actions are present in
// |new_order| if there are any component toolbar actions.
// TODO(devlin): Change this to DCHECK_EQ when all toolbar actions are shown
// in the model.
DCHECK_LE(new_order.size(), toolbar_action_views_.size());
for (const scoped_refptr<const Extension>& extension : new_order)
DCHECK(GetViewForExtension(extension.get()));
#endif
// Run through the views and compare them to the desired order. If something
// is out of place, find the correct spot for it.
for (size_t i = 0; i < new_order.size() - 1; ++i) {
if (new_order[i]->id() !=
toolbar_action_views_[i]->view_controller()->GetId()) {
// Find where the correct view is (it's guaranteed to be after our current
// index, since everything up to this point is correct).
size_t j = i + 1;
while (new_order[i]->id() !=
toolbar_action_views_[j]->view_controller()->GetId())
++j;
std::swap(toolbar_action_views_[i], toolbar_action_views_[j]);
}
}
// Our visible browser actions may have changed - re-Layout() and check the
// size.
ToolbarVisibleCountChanged();
OnBrowserActionVisibilityChanged();
}
size_t BrowserActionsContainer::GetIconCount() const { size_t BrowserActionsContainer::GetIconCount() const {
if (!model_) if (!model_)
return 0u; return 0u;
// Find the absolute value for the model's visible count. // Find the absolute value for the model's visible count.
size_t model_visible_size = model_->GetVisibleIconCountForTab( int model_visible_size = model_->GetVisibleIconCount();
browser_->tab_strip_model()->GetActiveWebContents()); size_t absolute_model_visible_size = model_visible_size == -1 ?
model_->toolbar_items().size() : model_visible_size;
#if DCHECK_IS_ON #if !defined(NDEBUG)
// Good time for some sanity checks: We should never try to display more // Good time for some sanity checks: We should never try to display more
// icons than we have, and we should always have a view per item in the model. // icons than we have, and we should always have a view per item in the model.
// (The only exception is if this is in initialization.) // (The only exception is if this is in initialization.)
if (initialized_ && !suppress_layout_) { if (initialized_) {
size_t num_extension_actions = 0u; size_t num_extension_actions = 0u;
for (ToolbarActionView* view : toolbar_action_views_) { for (ToolbarActionView* view : toolbar_action_views_) {
// No component action should ever have a valid extension id, so we can // No component action should ever have a valid extension id, so we can
...@@ -1093,12 +1016,13 @@ size_t BrowserActionsContainer::GetIconCount() const { ...@@ -1093,12 +1016,13 @@ size_t BrowserActionsContainer::GetIconCount() const {
if (crx_file::id_util::IdIsValid(view->view_controller()->GetId())) if (crx_file::id_util::IdIsValid(view->view_controller()->GetId()))
++num_extension_actions; ++num_extension_actions;
} }
DCHECK_LE(model_visible_size, num_extension_actions); DCHECK_LE(absolute_model_visible_size, num_extension_actions);
DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions);
} }
#endif #endif
// The overflow displays any icons not shown by the main bar. // The overflow displays any icons not shown by the main bar.
return in_overflow_mode() ? return in_overflow_mode() ?
model_->toolbar_items().size() - model_visible_size : model_visible_size; model_->toolbar_items().size() - absolute_model_visible_size :
absolute_model_visible_size;
} }
...@@ -285,7 +285,6 @@ class BrowserActionsContainer ...@@ -285,7 +285,6 @@ class BrowserActionsContainer
bool grant_active_tab) override; bool grant_active_tab) override;
void ToolbarVisibleCountChanged() override; void ToolbarVisibleCountChanged() override;
void ToolbarHighlightModeChanged(bool is_highlighting) override; void ToolbarHighlightModeChanged(bool is_highlighting) override;
void OnToolbarReorderNecessary(content::WebContents* web_contents) override;
Browser* GetBrowser() override; Browser* GetBrowser() override;
void LoadImages(); void LoadImages();
...@@ -320,15 +319,12 @@ class BrowserActionsContainer ...@@ -320,15 +319,12 @@ class BrowserActionsContainer
// case the container wouldn't be shown at all. // case the container wouldn't be shown at all.
int MinimumNonemptyWidth() const; int MinimumNonemptyWidth() const;
// Animates to the target size (unless testing, in which case we go straight // Animate to the target size (unless testing, in which case we go straight to
// to the target size). // the target size).
void Animate(gfx::Tween::Type type, size_t num_visible_icons); void Animate(gfx::Tween::Type type, size_t num_visible_icons);
// Reorders the views to match the toolbar model for the active tab.
void ReorderViews();
// Returns the number of icons that this container should draw. This differs // Returns the number of icons that this container should draw. This differs
// from the model's visible_icon_count if this container is for the overflow. // from the model's GetVisibleIconCount if this container is for the overflow.
size_t GetIconCount() const; size_t GetIconCount() const;
// Whether this container is in overflow mode (as opposed to in 'main' // Whether this container is in overflow mode (as opposed to in 'main'
...@@ -377,14 +373,6 @@ class BrowserActionsContainer ...@@ -377,14 +373,6 @@ class BrowserActionsContainer
// Don't show the chevron while animating. // Don't show the chevron while animating.
bool suppress_chevron_; bool suppress_chevron_;
// True if we should suppress animation; we typically do this e.g. when
// switching tabs changes the state of the icons.
bool suppress_animation_;
// True if we should suppress layout, such as when we are creating or
// adjusting a lot of views.
bool suppress_layout_;
// This is used while the user is resizing (and when the animations are in // This is used while the user is resizing (and when the animations are in
// progress) to know how wide the delta is between the current state and what // progress) to know how wide the delta is between the current state and what
// we should draw. // we should draw.
......
...@@ -116,7 +116,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, DragBrowserActions) { ...@@ -116,7 +116,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, DragBrowserActions) {
EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2)); EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2));
EXPECT_EQ(3u, container->VisibleBrowserActions()); EXPECT_EQ(3u, container->VisibleBrowserActions());
EXPECT_FALSE(container->chevron()->visible()); EXPECT_FALSE(container->chevron()->visible());
EXPECT_TRUE(model->all_icons_visible()); EXPECT_EQ(-1, model->GetVisibleIconCount());
// TODO(devlin): Ideally, we'd also have tests for dragging from the legacy // TODO(devlin): Ideally, we'd also have tests for dragging from the legacy
// overflow menu (i.e., chevron) to the main bar, but this requires either // overflow menu (i.e., chevron) to the main bar, but this requires either
...@@ -438,8 +438,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, ...@@ -438,8 +438,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest,
overflow_bar()->Layout(); overflow_bar()->Layout();
// All actions are showing, and are in the installation order. // All actions are showing, and are in the installation order.
EXPECT_TRUE(model()->all_icons_visible()); EXPECT_EQ(-1, model()->GetVisibleIconCount());
EXPECT_EQ(3u, model()->visible_icon_count());
ASSERT_EQ(3u, main_bar()->num_toolbar_actions()); ASSERT_EQ(3u, main_bar()->num_toolbar_actions());
EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u));
......
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