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

Unified Diff: chrome/browser/ui/toolbar/toolbar_actions_bar.h

Issue 766263003: [Extension Toolbar] Refactor and finish pop out logic for actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/toolbar/toolbar_actions_bar.h
diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar.h b/chrome/browser/ui/toolbar/toolbar_actions_bar.h
index 9f9d5e91f046ff63e9147f63381fdaefbceab53f..65674d9f2b93f57922a1dc692f3e27899d34ba2e 100644
--- a/chrome/browser/ui/toolbar/toolbar_actions_bar.h
+++ b/chrome/browser/ui/toolbar/toolbar_actions_bar.h
@@ -9,7 +9,6 @@
#include "base/memory/scoped_vector.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
-#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/geometry/size.h"
@@ -31,8 +30,7 @@ class ToolbarActionViewController;
// (fka wrench) menu. The main bar can have only a single row of icons with
// flexible width, whereas the overflow bar has multiple rows of icons with a
// fixed width (the width of the menu).
-class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
- public TabStripModelObserver {
+class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer {
public:
// A struct to contain the platform settings.
struct PlatformSettings {
@@ -63,7 +61,7 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
ToolbarActionsBar(ToolbarActionsBarDelegate* delegate,
Browser* browser,
- bool in_overflow_mode);
+ ToolbarActionsBar* main_bar);
~ToolbarActionsBar() override;
// Returns the width of a browser action icon, optionally including the
@@ -110,11 +108,12 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
// and dragged the view from |dragged_index| to |dropped_index|.
// |drag_type| indicates whether or not the icon was dragged between the
// overflow and main containers.
+ // The main container should handle all drag/drop notifications.
void OnDragDrop(int dragged_index,
int dropped_index,
DragType drag_type);
- const std::vector<ToolbarActionViewController*>& toolbar_actions() {
+ const std::vector<ToolbarActionViewController*>& toolbar_actions() const {
return toolbar_actions_.get();
}
bool enabled() const { return model_ != nullptr; }
@@ -127,7 +126,14 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; }
+ // If this is true, actions that want to run (e.g., an extension's page
+ // action) will pop out of overflow to draw more attention.
+ // See also TabOrderHelper in the .cc file.
+ static bool pop_out_actions_to_run;
+
private:
+ class TabOrderHelper;
+
using ToolbarActions = ScopedVector<ToolbarActionViewController>;
// ExtensionToolbarModel::Observer:
@@ -144,14 +150,6 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
void OnToolbarModelInitialized() override;
Browser* GetBrowser() override;
- // TabStripModelObserver:
- void TabInsertedAt(content::WebContents* web_contents,
- int index,
- bool foreground) override;
- void TabDetachedAt(content::WebContents* web_contents,
- int index) override;
- void TabStripModelDeleted() override;
-
// Resizes the delegate (if necessary) to the preferred size using the given
// |tween_type| and optionally suppressing the chevron.
void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron);
@@ -162,9 +160,16 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
// Returns the current web contents.
content::WebContents* GetCurrentWebContents();
- // Reorders the toolbar actions to reflect any that need to pop out.
+ // Reorders the toolbar actions to reflect the model and, optionally, to
+ // "pop out" any overflowed actions that want to run (depending on the
+ // value of |pop_out_actions_to_run|.
void ReorderActions();
+ // Copies the action order from the main bar (only called for the overflow).
+ void CopyActionOrder();
+
+ bool in_overflow_mode() const { return main_bar_ != nullptr; }
+
// The delegate for this object (in a real build, this is the view).
ToolbarActionsBarDelegate* delegate_;
@@ -174,8 +179,13 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
// The observed toolbar model.
extensions::ExtensionToolbarModel* model_;
- // True if this bar is for the overflow menu.
- bool in_overflow_mode_;
+ // The controller for the main toolbar actions bar. This will be null if this
+ // is the main bar.
+ ToolbarActionsBar* main_bar_;
+
+ // The controller for the overflow toolbar actions bar; this can be null
+ // even if this is the main bar, since the overflow is not always open.
+ ToolbarActionsBar* overflow_bar_;
// Platform-specific settings for dimensions and the overflow chevron.
PlatformSettings platform_settings_;
@@ -183,20 +193,13 @@ class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer,
// The toolbar actions.
ToolbarActions toolbar_actions_;
- // The set of tabs for the given action (the key) is currently "popped out".
- // "Popped out" actions are those that were in the overflow menu normally, but
- // want to run and are moved to the main bar so the user can see them.
- std::map<ToolbarActionViewController*, std::set<int>> popped_out_in_tabs_;
-
- // The set of tab ids that have been checked for whether actions need to be
- // popped out or not.
- std::set<int> tabs_checked_for_pop_out_;
+ // The TabOrderHelper that manages popping out actions that want to act.
+ // This is only non-null if |pop_out_actions_to_run| is true.
+ scoped_ptr<TabOrderHelper> tab_order_helper_;
ScopedObserver<extensions::ExtensionToolbarModel,
extensions::ExtensionToolbarModel::Observer> model_observer_;
- ScopedObserver<TabStripModel, TabStripModelObserver> tab_strip_observer_;
-
// True if we should suppress layout, such as when we are creating or
// adjusting a lot of actions at once.
bool suppress_layout_;

Powered by Google App Engine
This is Rietveld 408576698