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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.h

Issue 542493002: Cleanup BrowserActionsContainer a bit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +DCHECK Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
7 7
8 #include "base/observer_list.h" 8 #include "base/observer_list.h"
9 #include "chrome/browser/extensions/extension_keybinding_registry.h" 9 #include "chrome/browser/extensions/extension_keybinding_registry.h"
10 #include "chrome/browser/extensions/extension_toolbar_model.h" 10 #include "chrome/browser/extensions/extension_toolbar_model.h"
11 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro ller.h" 11 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro ller.h"
12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" 12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "ui/gfx/animation/animation_delegate.h" 13 #include "ui/gfx/animation/animation_delegate.h"
15 #include "ui/gfx/animation/tween.h" 14 #include "ui/gfx/animation/tween.h"
16 #include "ui/views/controls/button/menu_button_listener.h" 15 #include "ui/views/controls/button/menu_button_listener.h"
17 #include "ui/views/controls/resize_area_delegate.h" 16 #include "ui/views/controls/resize_area_delegate.h"
18 #include "ui/views/drag_controller.h" 17 #include "ui/views/drag_controller.h"
19 #include "ui/views/view.h" 18 #include "ui/views/view.h"
20 19
21 class BrowserActionsContainerObserver; 20 class BrowserActionsContainerObserver;
22 class ExtensionKeybindingRegistryViews; 21 class ExtensionKeybindingRegistryViews;
23 class ExtensionPopup; 22 class ExtensionPopup;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const views::View* chevron() const { return chevron_; } 152 const views::View* chevron() const { return chevron_; }
154 153
155 // Returns the profile this container is associated with. 154 // Returns the profile this container is associated with.
156 Profile* profile() const { return profile_; } 155 Profile* profile() const { return profile_; }
157 156
158 // Get a particular browser action view. 157 // Get a particular browser action view.
159 BrowserActionView* GetBrowserActionViewAt(int index) { 158 BrowserActionView* GetBrowserActionViewAt(int index) {
160 return browser_action_views_[index]; 159 return browser_action_views_[index];
161 } 160 }
162 161
163 // Retrieve the BrowserActionView for a certain extension |action|. 162 // Returns the BrowserActionView* associated with the given |extension|, or
164 BrowserActionView* GetBrowserActionView(ExtensionAction* action); 163 // NULL if none exists.
164 BrowserActionView* GetViewForExtension(
165 const extensions::Extension* extension);
165 166
166 // Update the views to reflect the state of the browser action icons. 167 // Update the views to reflect the state of the browser action icons.
167 void RefreshBrowserActionViews(); 168 void RefreshBrowserActionViews();
168 169
169 // Sets up the browser action view vector. 170 // Sets up the browser action view vector.
170 void CreateBrowserActionViews(); 171 void CreateBrowserActionViews();
171 172
172 // Delete all browser action views. 173 // Delete all browser action views.
173 void DeleteBrowserActionViews(); 174 void DeleteBrowserActionViews();
174 175
(...skipping 16 matching lines...) Expand all
191 void RemoveObserver(BrowserActionsContainerObserver* observer); 192 void RemoveObserver(BrowserActionsContainerObserver* observer);
192 193
193 // Overridden from views::View: 194 // Overridden from views::View:
194 virtual gfx::Size GetPreferredSize() const OVERRIDE; 195 virtual gfx::Size GetPreferredSize() const OVERRIDE;
195 virtual gfx::Size GetMinimumSize() const OVERRIDE; 196 virtual gfx::Size GetMinimumSize() const OVERRIDE;
196 virtual void Layout() OVERRIDE; 197 virtual void Layout() OVERRIDE;
197 virtual bool GetDropFormats(int* formats, 198 virtual bool GetDropFormats(int* formats,
198 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; 199 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
199 virtual bool AreDropTypesRequired() OVERRIDE; 200 virtual bool AreDropTypesRequired() OVERRIDE;
200 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE; 201 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
201 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
202 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; 202 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
203 virtual void OnDragExited() OVERRIDE; 203 virtual void OnDragExited() OVERRIDE;
204 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; 204 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
205 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 205 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
206 206
207 // Overridden from views::MenuButtonListener: 207 // Overridden from views::MenuButtonListener:
208 virtual void OnMenuButtonClicked(views::View* source, 208 virtual void OnMenuButtonClicked(views::View* source,
209 const gfx::Point& point) OVERRIDE; 209 const gfx::Point& point) OVERRIDE;
210 210
211 // Overridden from views::DragController: 211 // Overridden from views::DragController:
(...skipping 22 matching lines...) Expand all
234 virtual bool ShownInsideMenu() const OVERRIDE; 234 virtual bool ShownInsideMenu() const OVERRIDE;
235 virtual void OnBrowserActionViewDragDone() OVERRIDE; 235 virtual void OnBrowserActionViewDragDone() OVERRIDE;
236 virtual views::View* GetOverflowReferenceView() OVERRIDE; 236 virtual views::View* GetOverflowReferenceView() OVERRIDE;
237 virtual void SetPopupOwner(BrowserActionView* popup_owner) OVERRIDE; 237 virtual void SetPopupOwner(BrowserActionView* popup_owner) OVERRIDE;
238 virtual void HideActivePopup() OVERRIDE; 238 virtual void HideActivePopup() OVERRIDE;
239 239
240 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: 240 // Overridden from extension::ExtensionKeybindingRegistry::Delegate:
241 virtual extensions::ActiveTabPermissionGranter* 241 virtual extensions::ActiveTabPermissionGranter*
242 GetActiveTabPermissionGranter() OVERRIDE; 242 GetActiveTabPermissionGranter() OVERRIDE;
243 243
244 // Moves a browser action with |id| to |new_index|.
245 void MoveBrowserAction(const std::string& extension_id, size_t new_index);
246
247 // Retrieve the current popup. This should only be used by unit tests. 244 // Retrieve the current popup. This should only be used by unit tests.
248 ExtensionPopup* TestGetPopup(); 245 ExtensionPopup* TestGetPopup();
249 246
250 // Set how many icons the container should show. This should only be used by 247 // Set how many icons the container should show. This should only be used by
251 // unit tests. 248 // unit tests.
252 void TestSetIconVisibilityCount(size_t icons); 249 void TestSetIconVisibilityCount(size_t icons);
253 250
254 // During testing we can disable animations by setting this flag to true, 251 // During testing we can disable animations by setting this flag to true,
255 // so that the bar resizes instantly, instead of having to poll it while it 252 // so that the bar resizes instantly, instead of having to poll it while it
256 // animates to open/closed status. 253 // animates to open/closed status.
257 static bool disable_animations_during_testing_; 254 static bool disable_animations_during_testing_;
258 255
259 protected: 256 protected:
260 // Overridden from views::View: 257 // Overridden from views::View:
261 virtual void ViewHierarchyChanged( 258 virtual void ViewHierarchyChanged(
262 const ViewHierarchyChangedDetails& details) OVERRIDE; 259 const ViewHierarchyChangedDetails& details) OVERRIDE;
263 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 260 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
264 virtual void OnThemeChanged() OVERRIDE; 261 virtual void OnThemeChanged() OVERRIDE;
265 262
266 private: 263 private:
267 friend class BrowserActionView; // So it can access IconWidth(). 264 friend class BrowserActionView; // So it can access IconWidth().
268 friend class ShowFolderMenuTask;
269 265
270 // A struct representing the position at which an action will be dropped. 266 // A struct representing the position at which an action will be dropped.
271 struct DropPosition; 267 struct DropPosition;
272 268
273 typedef std::vector<BrowserActionView*> BrowserActionViews; 269 typedef std::vector<BrowserActionView*> BrowserActionViews;
274 270
275 // Returns the width of an icon, optionally with its padding. 271 // Returns the width of an icon, optionally with its padding.
276 static int IconWidth(bool include_padding); 272 static int IconWidth(bool include_padding);
277 273
278 // Returns the height of an icon. 274 // Returns the height of an icon.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void Animate(gfx::Tween::Type type, size_t num_visible_icons); 331 void Animate(gfx::Tween::Type type, size_t num_visible_icons);
336 332
337 // Returns true if this extension should be shown in this toolbar. This can 333 // Returns true if this extension should be shown in this toolbar. This can
338 // return false if we are in an incognito window and the extension is disabled 334 // return false if we are in an incognito window and the extension is disabled
339 // for incognito. 335 // for incognito.
340 bool ShouldDisplayBrowserAction(const extensions::Extension* extension) const; 336 bool ShouldDisplayBrowserAction(const extensions::Extension* extension) const;
341 337
342 // Return the index of the first visible icon. 338 // Return the index of the first visible icon.
343 size_t GetFirstVisibleIconIndex() const; 339 size_t GetFirstVisibleIconIndex() const;
344 340
345 // Returns the BrowserActionView* associated with the given |extension|, or
346 // NULL if none exists.
347 BrowserActionView* GetViewForExtension(
348 const extensions::Extension* extension);
349
350 // Returns the number of icons that this container should draw. This differs 341 // Returns the number of icons that this container should draw. This differs
351 // from the model's GetVisibleIconCount if this container is for the overflow. 342 // from the model's GetVisibleIconCount if this container is for the overflow.
352 size_t GetIconCount() const; 343 size_t GetIconCount() const;
353 344
354 // Whether this container is in overflow mode (as opposed to in 'main' 345 // Whether this container is in overflow mode (as opposed to in 'main'
355 // mode). See class comments for details on the difference. 346 // mode). See class comments for details on the difference.
356 bool in_overflow_mode() const { return main_container_ != NULL; } 347 bool in_overflow_mode() const { return main_container_ != NULL; }
357 348
358 // The vector of browser actions (icons/image buttons for each action). Note 349 // The vector of browser actions (icons/image buttons for each action). Note
359 // that not every BrowserAction in the ToolbarModel will necessarily be in 350 // that not every BrowserAction in the ToolbarModel will necessarily be in
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // are done animating. 403 // are done animating.
413 int animation_target_size_; 404 int animation_target_size_;
414 405
415 // The DropPosition for the current drag-and-drop operation, or NULL if there 406 // The DropPosition for the current drag-and-drop operation, or NULL if there
416 // is none. 407 // is none.
417 scoped_ptr<DropPosition> drop_position_; 408 scoped_ptr<DropPosition> drop_position_;
418 409
419 // The class that registers for keyboard shortcuts for extension commands. 410 // The class that registers for keyboard shortcuts for extension commands.
420 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; 411 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_;
421 412
422 base::WeakPtrFactory<BrowserActionsContainer> task_factory_;
423
424 // Handles delayed showing of the overflow menu when hovering. 413 // Handles delayed showing of the overflow menu when hovering.
425 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; 414 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_;
426 415
427 ObserverList<BrowserActionsContainerObserver> observers_; 416 ObserverList<BrowserActionsContainerObserver> observers_;
428 417
429 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); 418 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
430 }; 419 };
431 420
432 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 421 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698