Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_UI_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/extension_toolbar_model.h" | 8 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 9 #include "chrome/browser/ui/views/browser_action_view.h" | |
| 9 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro ller.h" | 10 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro ller.h" |
| 10 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 11 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
| 11 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
| 12 #include "ui/base/animation/animation_delegate.h" | 13 #include "ui/base/animation/animation_delegate.h" |
| 13 #include "ui/base/animation/tween.h" | 14 #include "ui/base/animation/tween.h" |
| 14 #include "ui/views/controls/button/menu_button.h" | 15 #include "ui/views/controls/button/menu_button.h" |
| 15 #include "ui/views/controls/button/menu_button_listener.h" | 16 #include "ui/views/controls/button/menu_button_listener.h" |
| 16 #include "ui/views/controls/resize_area_delegate.h" | 17 #include "ui/views/controls/resize_area_delegate.h" |
| 17 #include "ui/views/drag_controller.h" | 18 #include "ui/views/drag_controller.h" |
| 18 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // NOTE: When adding Browser Actions to a maximum width container (no overflow) | 98 // NOTE: When adding Browser Actions to a maximum width container (no overflow) |
| 98 // we make sure to suppress the chevron menu if it wasn't visible. This is | 99 // we make sure to suppress the chevron menu if it wasn't visible. This is |
| 99 // because we won't have enough space to show the new Browser Action until the | 100 // because we won't have enough space to show the new Browser Action until the |
| 100 // animation ends and we don't want the chevron to flash into view while we are | 101 // animation ends and we don't want the chevron to flash into view while we are |
| 101 // growing the container. | 102 // growing the container. |
| 102 // | 103 // |
| 103 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
| 104 class BrowserActionsContainer | 105 class BrowserActionsContainer |
| 105 : public views::View, | 106 : public views::View, |
| 106 public views::MenuButtonListener, | 107 public views::MenuButtonListener, |
| 107 public views::DragController, | |
| 108 public views::ResizeAreaDelegate, | 108 public views::ResizeAreaDelegate, |
| 109 public ui::AnimationDelegate, | 109 public ui::AnimationDelegate, |
| 110 public ExtensionToolbarModel::Observer, | 110 public ExtensionToolbarModel::Observer, |
| 111 public BrowserActionOverflowMenuController::Observer, | 111 public BrowserActionOverflowMenuController::Observer, |
| 112 public views::Widget::Observer { | 112 public views::Widget::Observer, |
| 113 public BrowserActionView::Delegate { | |
| 113 public: | 114 public: |
| 114 BrowserActionsContainer(Browser* browser, views::View* owner_view); | 115 BrowserActionsContainer(Browser* browser, views::View* owner_view); |
| 115 virtual ~BrowserActionsContainer(); | 116 virtual ~BrowserActionsContainer(); |
| 116 | 117 |
| 117 void Init(); | 118 void Init(); |
| 118 | 119 |
| 119 // Get the number of browser actions being displayed. | 120 // Get the number of browser actions being displayed. |
| 120 int num_browser_actions() const { return browser_action_views_.size(); } | 121 int num_browser_actions() const { return browser_action_views_.size(); } |
| 121 | 122 |
| 122 // Whether we are performing resize animation on the container. | 123 // Whether we are performing resize animation on the container. |
| 123 bool animating() const { return animation_target_size_ > 0; } | 124 bool animating() const { return animation_target_size_ > 0; } |
| 124 | 125 |
| 125 // Returns the chevron, if any. | 126 // Returns the chevron, if any. |
| 126 views::View* chevron() { return chevron_; } | 127 views::View* chevron() { return chevron_; } |
| 127 const views::View* chevron() const { return chevron_; } | 128 const views::View* chevron() const { return chevron_; } |
| 128 | 129 |
| 129 // Returns the profile this container is associated with. | 130 // Returns the profile this container is associated with. |
| 130 Profile* profile() const { return profile_; } | 131 Profile* profile() const { return profile_; } |
| 131 | 132 |
| 132 // Returns the browser this container is associated with. | |
| 133 Browser* browser() const { return browser_; } | |
| 134 | |
| 135 // Returns the current tab's ID, or -1 if there is no current tab. | |
| 136 int GetCurrentTabId() const; | |
| 137 | |
| 138 // Get a particular browser action view. | 133 // Get a particular browser action view. |
| 139 BrowserActionView* GetBrowserActionViewAt(int index) { | 134 BrowserActionView* GetBrowserActionViewAt(int index) { |
| 140 return browser_action_views_[index]; | 135 return browser_action_views_[index]; |
| 141 } | 136 } |
| 142 | 137 |
| 143 // Retrieve the BrowserActionView for |extension|. | 138 // Retrieve the BrowserActionView for |extension|. |
| 144 BrowserActionView* GetBrowserActionView(ExtensionAction* action); | 139 BrowserActionView* GetBrowserActionView(ExtensionAction* action); |
| 145 | 140 |
| 146 // Update the views to reflect the state of the browser action icons. | 141 // Update the views to reflect the state of the browser action icons. |
| 147 void RefreshBrowserActionViews(); | 142 void RefreshBrowserActionViews(); |
| 148 | 143 |
| 149 // Sets up the browser action view vector. | 144 // Sets up the browser action view vector. |
| 150 void CreateBrowserActionViews(); | 145 void CreateBrowserActionViews(); |
| 151 | 146 |
| 152 // Delete all browser action views. | 147 // Delete all browser action views. |
| 153 void DeleteBrowserActionViews(); | 148 void DeleteBrowserActionViews(); |
| 154 | 149 |
| 155 // Called when a browser action becomes visible/hidden. | |
| 156 void OnBrowserActionVisibilityChanged(); | |
| 157 | |
| 158 // Returns how many browser actions are visible. | 150 // Returns how many browser actions are visible. |
| 159 size_t VisibleBrowserActions() const; | 151 size_t VisibleBrowserActions() const; |
| 160 | 152 |
| 161 // Called when the user clicks on the browser action icon. | |
| 162 void OnBrowserActionExecuted(BrowserActionButton* button); | |
| 163 | |
| 164 // Overridden from views::View: | 153 // Overridden from views::View: |
| 165 virtual gfx::Size GetPreferredSize() OVERRIDE; | 154 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 166 virtual void Layout() OVERRIDE; | 155 virtual void Layout() OVERRIDE; |
| 167 virtual bool GetDropFormats(int* formats, | 156 virtual bool GetDropFormats(int* formats, |
| 168 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; | 157 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; |
| 169 virtual bool AreDropTypesRequired() OVERRIDE; | 158 virtual bool AreDropTypesRequired() OVERRIDE; |
| 170 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE; | 159 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE; |
| 171 virtual void OnDragEntered(const views::DropTargetEvent& event) OVERRIDE; | 160 virtual void OnDragEntered(const views::DropTargetEvent& event) OVERRIDE; |
| 172 virtual int OnDragUpdated(const views::DropTargetEvent& event) OVERRIDE; | 161 virtual int OnDragUpdated(const views::DropTargetEvent& event) OVERRIDE; |
| 173 virtual void OnDragExited() OVERRIDE; | 162 virtual void OnDragExited() OVERRIDE; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 195 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 184 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 196 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 185 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 197 | 186 |
| 198 // Overridden from BrowserActionOverflowMenuController::Observer: | 187 // Overridden from BrowserActionOverflowMenuController::Observer: |
| 199 virtual void NotifyMenuDeleted( | 188 virtual void NotifyMenuDeleted( |
| 200 BrowserActionOverflowMenuController* controller) OVERRIDE; | 189 BrowserActionOverflowMenuController* controller) OVERRIDE; |
| 201 | 190 |
| 202 // Overridden from views::Widget::Observer | 191 // Overridden from views::Widget::Observer |
| 203 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; | 192 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
| 204 | 193 |
| 194 // Overridden from BrowserActionView::Delegate: | |
| 195 virtual Browser* GetBrowser() const; | |
|
Peter Kasting
2012/07/21 01:55:13
This should be removed, as it's no longer overridi
yefimt
2012/07/23 23:47:52
Done.
| |
| 196 virtual int GetCurrentTabId() const OVERRIDE; | |
| 197 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE; | |
| 198 virtual void OnBrowserActionVisibilityChanged() OVERRIDE; | |
| 199 virtual gfx::Size GetViewContentOffset() const OVERRIDE; | |
| 200 | |
| 205 // Moves a browser action with |id| to |new_index|. | 201 // Moves a browser action with |id| to |new_index|. |
| 206 void MoveBrowserAction(const std::string& extension_id, size_t new_index); | 202 void MoveBrowserAction(const std::string& extension_id, size_t new_index); |
| 207 | 203 |
| 208 // Hide the current popup. | 204 // Hide the current popup. |
| 209 void HidePopup(); | 205 void HidePopup(); |
| 210 | 206 |
| 211 // Simulate a click on a browser action button. This should only be | 207 // Simulate a click on a browser action button. This should only be |
| 212 // used by unit tests. | 208 // used by unit tests. |
| 213 void TestExecuteBrowserAction(int index); | 209 void TestExecuteBrowserAction(int index); |
| 214 | 210 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 | 359 |
| 364 base::WeakPtrFactory<BrowserActionsContainer> task_factory_; | 360 base::WeakPtrFactory<BrowserActionsContainer> task_factory_; |
| 365 | 361 |
| 366 // Handles delayed showing of the overflow menu when hovering. | 362 // Handles delayed showing of the overflow menu when hovering. |
| 367 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; | 363 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; |
| 368 | 364 |
| 369 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 365 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 370 }; | 366 }; |
| 371 | 367 |
| 372 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 368 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |