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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.h

Issue 700453003: Revert of Make extensions that desire to act pop out if in overflow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_toolbar_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/observer_list.h" 9 #include "base/observer_list.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 23 matching lines...) Expand all
34 public: 34 public:
35 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); 35 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs);
36 ~ExtensionToolbarModel() override; 36 ~ExtensionToolbarModel() override;
37 37
38 // A class which is informed of changes to the model; represents the view of 38 // A class which is informed of changes to the model; represents the view of
39 // MVC. Also used for signaling view changes such as showing extension popups. 39 // MVC. Also used for signaling view changes such as showing extension popups.
40 // TODO(devlin): Should this really be an observer? It acts more like a 40 // TODO(devlin): Should this really be an observer? It acts more like a
41 // delegate. 41 // delegate.
42 class Observer { 42 class Observer {
43 public: 43 public:
44 // TODO(devlin): Rename these methods to be OnFoo. 44 // An extension has been added to the toolbar and should go at |index|.
45 // Signals that an |extension| has been added to the toolbar at |index|.
46 virtual void ToolbarExtensionAdded(const Extension* extension, 45 virtual void ToolbarExtensionAdded(const Extension* extension,
47 int index) = 0; 46 int index) = 0;
48 47
49 // Signals that the given |extension| has been removed from the toolbar. 48 // The given |extension| should be removed from the toolbar.
50 virtual void ToolbarExtensionRemoved(const Extension* extension) = 0; 49 virtual void ToolbarExtensionRemoved(const Extension* extension) = 0;
51 50
52 // Signals that the given |extension| has been moved to |index|. |index| is 51 // The given |extension| has been moved to |index|. |index| is the desired
53 // the desired *final* index of the extension (that is, in the adjusted 52 // *final* index of the extension (that is, in the adjusted order, extension
54 // order, extension should be at |index|). 53 // should be at |index|).
55 virtual void ToolbarExtensionMoved(const Extension* extension, 54 virtual void ToolbarExtensionMoved(const Extension* extension,
56 int index) = 0; 55 int index) = 0;
57 56
58 // Signals that the browser action for the given |extension| has been 57 // Signals that the browser action for the given |extension| has been
59 // updated. 58 // updated.
60 virtual void ToolbarExtensionUpdated(const Extension* extension) = 0; 59 virtual void ToolbarExtensionUpdated(const Extension* extension) = 0;
61 60
62 // Signals the |extension| to show the popup now in the active window. 61 // Signal the |extension| to show the popup now in the active window.
63 // If |grant_active_tab| is true, then active tab permissions should be 62 // If |grant_active_tab| is true, then active tab permissions should be
64 // given to the extension (only do this if this is through a user action). 63 // given to the extension (only do this if this is through a user action).
65 // Returns true if a popup was slated to be shown. 64 // Returns true if a popup was slated to be shown.
66 virtual bool ShowExtensionActionPopup(const Extension* extension, 65 virtual bool ShowExtensionActionPopup(const Extension* extension,
67 bool grant_active_tab) = 0; 66 bool grant_active_tab) = 0;
68 67
69 // Signals when the container needs to be redrawn because of a size change, 68 // Signal when the container needs to be redrawn because of a size change,
70 // and when the model has finished loading. 69 // and when the model has finished loading.
71 virtual void ToolbarVisibleCountChanged() = 0; 70 virtual void ToolbarVisibleCountChanged() = 0;
72 71
73 // Signals that the model has entered or exited highlighting mode, or that 72 // Signal that the model has entered or exited highlighting mode, or that
74 // the extensions being highlighted have (probably*) changed. Highlighting 73 // the extensions being highlighted have (probably*) changed. Highlighting
75 // mode indicates that only a subset of the extensions are actively 74 // mode indicates that only a subset of the extensions are actively
76 // displayed, and those extensions should be highlighted for extra emphasis. 75 // displayed, and those extensions should be highlighted for extra emphasis.
77 // * probably, because if we are in highlight mode and receive a call to 76 // * probably, because if we are in highlight mode and receive a call to
78 // highlight a new set of extensions, we do not compare the current set 77 // highlight a new set of extensions, we do not compare the current set
79 // with the new set (and just assume the new set is different). 78 // with the new set (and just assume the new set is different).
80 virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0; 79 virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0;
81 80
82 // Signals that the toolbar needs to be reordered for the given
83 // |web_contents|. This is caused by an overflowed action wanting to run,
84 // and needing to "pop itself out".
85 virtual void OnToolbarReorderNecessary(
86 content::WebContents* web_contents) = 0;
87
88 // Returns the browser associated with the Observer. 81 // Returns the browser associated with the Observer.
89 virtual Browser* GetBrowser() = 0; 82 virtual Browser* GetBrowser() = 0;
90 83
91 protected: 84 protected:
92 virtual ~Observer() {} 85 virtual ~Observer() {}
93 }; 86 };
94 87
95 // Convenience function to get the ExtensionToolbarModel for a Profile. 88 // Convenience function to get the ExtensionToolbarModel for a Profile.
96 static ExtensionToolbarModel* Get(Profile* profile); 89 static ExtensionToolbarModel* Get(Profile* profile);
97 90
98 // Adds or removes an observer. 91 // Add or remove an observer.
99 void AddObserver(Observer* observer); 92 void AddObserver(Observer* observer);
100 void RemoveObserver(Observer* observer); 93 void RemoveObserver(Observer* observer);
101 94
102 // Moves the given |extension|'s icon to the given |index|. 95 // Moves the given |extension|'s icon to the given |index|.
103 void MoveExtensionIcon(const std::string& id, size_t index); 96 void MoveExtensionIcon(const std::string& id, size_t index);
104 97
105 // Sets the number of extension icons that should be visible. 98 // Sets the number of extension icons that should be visible.
106 // If count == size(), this will set the visible icon count to -1, meaning 99 // If count == size(), this will set the visible icon count to -1, meaning
107 // "show all actions". 100 // "show all actions".
108 void SetVisibleIconCount(size_t count); 101 void SetVisibleIconCount(int count);
109 102
110 size_t visible_icon_count() const { 103 // As above, a return value of -1 represents "show all actions".
111 return visible_icon_count_ == -1 ? 104 int GetVisibleIconCount() const { return visible_icon_count_; }
112 toolbar_items().size() : static_cast<size_t>(visible_icon_count_);
113 }
114
115 bool all_icons_visible() const { return visible_icon_count_ == -1; }
116 105
117 bool extensions_initialized() const { return extensions_initialized_; } 106 bool extensions_initialized() const { return extensions_initialized_; }
118 107
119 const ExtensionList& toolbar_items() const { 108 const ExtensionList& toolbar_items() const {
120 return is_highlighting_ ? highlighted_items_ : toolbar_items_; 109 return is_highlighting_ ? highlighted_items_ : toolbar_items_;
121 } 110 }
122 111
123 bool is_highlighting() const { return is_highlighting_; } 112 bool is_highlighting() const { return is_highlighting_; }
124 113
125 void OnExtensionToolbarPrefChange(); 114 void OnExtensionToolbarPrefChange();
126 115
127 // Returns the item order for a given tab. This can be different from the
128 // base item order if the action wants to run on the given page, and needs to
129 // be popped out of overflow.
130 ExtensionList GetItemOrderForTab(content::WebContents* web_contents) const;
131
132 // Returns the visible icon count for a given tab. This can be different from
133 // the base item order if the action wants to run on the given page and needs
134 // to be popped out of overflow.
135 size_t GetVisibleIconCountForTab(content::WebContents* web_contents) const;
136
137 // Finds the Observer associated with |browser| and tells it to display a 116 // Finds the Observer associated with |browser| and tells it to display a
138 // popup for the given |extension|. If |grant_active_tab| is true, this 117 // popup for the given |extension|. If |grant_active_tab| is true, this
139 // grants active tab permissions to the |extension|; only do this because of 118 // grants active tab permissions to the |extension|; only do this because of
140 // a direct user action. 119 // a direct user action.
141 bool ShowExtensionActionPopup(const Extension* extension, 120 bool ShowExtensionActionPopup(const Extension* extension,
142 Browser* browser, 121 Browser* browser,
143 bool grant_active_tab); 122 bool grant_active_tab);
144 123
145 // Ensures that the extensions in the |extension_ids| list are visible on the 124 // Ensures that the extensions in the |extension_ids| list are visible on the
146 // toolbar. This might mean they need to be moved to the front (if they are in 125 // toolbar. This might mean they need to be moved to the front (if they are in
147 // the overflow bucket). 126 // the overflow bucket).
148 void EnsureVisibility(const ExtensionIdList& extension_ids); 127 void EnsureVisibility(const ExtensionIdList& extension_ids);
149 128
150 // Highlights the extensions specified by |extension_ids|. This will cause 129 // Highlight the extensions specified by |extension_ids|. This will cause
151 // the ToolbarModel to only display those extensions. 130 // the ToolbarModel to only display those extensions.
152 // Highlighting mode is only entered if there is at least one extension to 131 // Highlighting mode is only entered if there is at least one extension to
153 // be shown. 132 // be shown.
154 // Returns true if highlighting mode is entered, false otherwise. 133 // Returns true if highlighting mode is entered, false otherwise.
155 bool HighlightExtensions(const ExtensionIdList& extension_ids); 134 bool HighlightExtensions(const ExtensionIdList& extension_ids);
156 135
157 // Stop highlighting extensions. All extensions can be shown again, and the 136 // Stop highlighting extensions. All extensions can be shown again, and the
158 // number of visible icons will be reset to what it was before highlighting. 137 // number of visible icons will be reset to what it was before highlighting.
159 void StopHighlighting(); 138 void StopHighlighting();
160 139
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // if we are exiting highlight mode due to no longer having highlighted items. 222 // if we are exiting highlight mode due to no longer having highlighted items.
244 bool is_highlighting_; 223 bool is_highlighting_;
245 224
246 // The number of icons which were visible before highlighting a subset, in 225 // The number of icons which were visible before highlighting a subset, in
247 // order to restore the count when finished. 226 // order to restore the count when finished.
248 int old_visible_icon_count_; 227 int old_visible_icon_count_;
249 228
250 ExtensionIdList last_known_positions_; 229 ExtensionIdList last_known_positions_;
251 230
252 // The number of icons visible (the rest should be hidden in the overflow 231 // The number of icons visible (the rest should be hidden in the overflow
253 // chevron). A value of -1 indicates that all icons should be visible. 232 // chevron).
254 // TODO(devlin): Make a new variable to indicate that all icons should be
255 // visible, instead of overloading this one.
256 int visible_icon_count_; 233 int visible_icon_count_;
257 234
258 content::NotificationRegistrar registrar_; 235 content::NotificationRegistrar registrar_;
259 236
260 ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer> 237 ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer>
261 extension_action_observer_; 238 extension_action_observer_;
262 239
263 // Listen to extension load, unloaded notifications. 240 // Listen to extension load, unloaded notifications.
264 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 241 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
265 extension_registry_observer_; 242 extension_registry_observer_;
266 243
267 // For observing change of toolbar order preference by external entity (sync). 244 // For observing change of toolbar order preference by external entity (sync).
268 PrefChangeRegistrar pref_change_registrar_; 245 PrefChangeRegistrar pref_change_registrar_;
269 base::Closure pref_change_callback_; 246 base::Closure pref_change_callback_;
270 247
271 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; 248 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_;
272 249
273 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); 250 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel);
274 }; 251 };
275 252
276 } // namespace extensions 253 } // namespace extensions
277 254
278 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ 255 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_toolbar_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698