Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 8 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 11 #include "chrome/browser/extensions/extension_context_menu_model.h" | 9 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 10 #include "chrome/browser/ui/views/extensions/extension_popup.h" | |
| 12 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 14 #include "ui/views/context_menu_controller.h" | 13 #include "ui/views/context_menu_controller.h" |
| 15 #include "ui/views/controls/button/menu_button.h" | 14 #include "ui/views/controls/button/menu_button.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/drag_controller.h" | 16 #include "ui/views/drag_controller.h" |
| 18 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 18 #include "ui/views/widget/widget_observer.h" | |
| 19 | 19 |
| 20 class Browser; | 20 class Browser; |
| 21 class BrowserActionButton; | 21 class BrowserActionButton; |
| 22 class ExtensionAction; | 22 class ExtensionAction; |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 class Extension; | 25 class Extension; |
| 26 class ExtensionToolbarModel; | |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace gfx { | 29 namespace gfx { |
| 29 class Image; | 30 class Image; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace views { | 33 namespace views { |
| 33 class MenuItemView; | 34 class MenuItemView; |
| 34 class MenuRunner; | 35 class MenuRunner; |
| 35 } | 36 } |
| 36 | 37 |
| 37 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
| 38 // BrowserActionView | 39 // BrowserActionView |
| 39 // A single entry in the browser action container. This contains the actual | 40 // A single entry in the browser action container. This contains the actual |
| 40 // BrowserActionButton, as well as the logic to paint the badge. | 41 // BrowserActionButton, as well as the logic to paint the badge. |
| 41 class BrowserActionView : public views::View { | 42 class BrowserActionView : public views::View { |
| 42 public: | 43 public: |
| 43 // Need DragController here because BrowserActionView could be | 44 // Need DragController here because BrowserActionView could be |
| 44 // dragged/dropped. | 45 // dragged/dropped. |
| 45 class Delegate : public views::DragController, | 46 class Delegate : public views::DragController { |
| 46 public ExtensionContextMenuModel::PopupDelegate { | |
| 47 public: | 47 public: |
| 48 // Returns the current tab's ID, or -1 if there is no current tab. | 48 // Returns the current tab's ID, or -1 if there is no current tab. |
| 49 virtual int GetCurrentTabId() const = 0; | 49 virtual int GetCurrentTabId() const = 0; |
| 50 | 50 |
| 51 // Called when the user clicks on the browser action icon. | |
| 52 virtual void OnBrowserActionExecuted(BrowserActionButton* button) = 0; | |
| 53 | |
| 54 // Called when a browser action becomes visible/hidden. | 51 // Called when a browser action becomes visible/hidden. |
| 55 virtual void OnBrowserActionVisibilityChanged() = 0; | 52 virtual void OnBrowserActionVisibilityChanged() = 0; |
| 56 | 53 |
| 57 // Whether the container for this button is shown inside a menu. | 54 // Whether the container for this button is shown inside a menu. |
| 58 virtual bool ShownInsideMenu() const = 0; | 55 virtual bool ShownInsideMenu() const = 0; |
| 59 | 56 |
| 60 // Notifies that a drag completed. Note this will only happen if the view | 57 // Notifies that a drag completed. Note this will only happen if the view |
| 61 // wasn't removed during the drag-and-drop process (i.e., not when there | 58 // wasn't removed during the drag-and-drop process (i.e., not when there |
| 62 // was a move in the browser actions, since we re-create the views each | 59 // was a move in the browser actions, since we re-create the views each |
| 63 // time we re-order the browser actions). | 60 // time we re-order the browser actions). |
| 64 virtual void OnBrowserActionViewDragDone() = 0; | 61 virtual void OnBrowserActionViewDragDone() = 0; |
| 65 | 62 |
| 63 // Returns the view of the browser actions overflow menu to use as a | |
| 64 // reference point for a popup when this view isn't visible. | |
| 65 virtual views::View* GetOverflowReferenceView() = 0; | |
| 66 | |
| 67 // Sets the delegate's active popup owner to be |popup_owner|. | |
| 68 virtual void SetPopupOwner(BrowserActionButton* popup_owner) = 0; | |
| 69 | |
| 70 // Hides the active popup of the delegate, if one exists. | |
| 71 virtual void HideActivePopup() = 0; | |
| 72 | |
| 73 // Returns the Model backing the browser actions. | |
| 74 virtual extensions::ExtensionToolbarModel* GetModel() = 0; | |
| 75 | |
| 66 protected: | 76 protected: |
| 67 virtual ~Delegate() {} | 77 virtual ~Delegate() {} |
| 68 }; | 78 }; |
| 69 | 79 |
| 70 BrowserActionView(const extensions::Extension* extension, | 80 BrowserActionView(const extensions::Extension* extension, |
| 71 Browser* browser, | 81 Browser* browser, |
| 72 Delegate* delegate); | 82 Delegate* delegate); |
| 73 virtual ~BrowserActionView(); | 83 virtual ~BrowserActionView(); |
| 74 | 84 |
| 75 BrowserActionButton* button() { return button_; } | 85 BrowserActionButton* button() { return button_; } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 106 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
| 107 // BrowserActionButton | 117 // BrowserActionButton |
| 108 | 118 |
| 109 // The BrowserActionButton is a specialization of the MenuButton class. | 119 // The BrowserActionButton is a specialization of the MenuButton class. |
| 110 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 120 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
| 111 // loading the image for the button asynchronously on the file thread. | 121 // loading the image for the button asynchronously on the file thread. |
| 112 class BrowserActionButton : public views::MenuButton, | 122 class BrowserActionButton : public views::MenuButton, |
| 113 public views::ButtonListener, | 123 public views::ButtonListener, |
| 114 public views::ContextMenuController, | 124 public views::ContextMenuController, |
| 115 public content::NotificationObserver, | 125 public content::NotificationObserver, |
| 116 public ExtensionActionIconFactory::Observer { | 126 public ExtensionActionIconFactory::Observer, |
| 127 public views::WidgetObserver, | |
| 128 public ExtensionContextMenuModel::PopupDelegate { | |
| 117 public: | 129 public: |
| 118 // The IconObserver will receive a notification when the button's icon has | 130 // The IconObserver will receive a notification when the button's icon has |
| 119 // been updated. | 131 // been updated. |
| 120 class IconObserver { | 132 class IconObserver { |
| 121 public: | 133 public: |
| 122 virtual void OnIconUpdated(const gfx::ImageSkia& icon) = 0; | 134 virtual void OnIconUpdated(const gfx::ImageSkia& icon) = 0; |
| 123 | 135 |
| 124 protected: | 136 protected: |
| 125 virtual ~IconObserver() {} | 137 virtual ~IconObserver() {} |
| 126 }; | 138 }; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 139 icon_observer_ = icon_observer; | 151 icon_observer_ = icon_observer; |
| 140 } | 152 } |
| 141 | 153 |
| 142 // Called to update the display to match the browser action's state. | 154 // Called to update the display to match the browser action's state. |
| 143 void UpdateState(); | 155 void UpdateState(); |
| 144 | 156 |
| 145 // Does this button's action have a popup? | 157 // Does this button's action have a popup? |
| 146 virtual bool IsPopup(); | 158 virtual bool IsPopup(); |
| 147 virtual GURL GetPopupUrl(); | 159 virtual GURL GetPopupUrl(); |
| 148 | 160 |
| 161 // Show this extension's popup. If |grant_tab_permissions| is true, this will | |
| 162 // grant the extension active tab permissions. Only do this if this was done | |
| 163 // through a user action (and not, e.g., an API). | |
|
Peter Kasting
2014/07/26 02:33:20
Tiny nit: Remove commas (slightly more readable)
Devlin
2014/07/29 19:07:14
Done.
| |
| 164 bool ShowPopup(ExtensionPopup::ShowAction show_action, | |
| 165 bool grant_tab_permissions); | |
| 166 | |
| 167 // Hides the popup, if one is open. | |
| 168 void HidePopup(); | |
| 169 | |
| 170 // Executes the browser action (also showing the popup, if one exists). | |
|
Peter Kasting
2014/07/26 02:33:20
Nit: also showing -> and also shows?
Devlin
2014/07/29 19:07:14
Done.
| |
| 171 void ExecuteBrowserAction(); | |
| 172 | |
| 149 // Overridden from views::View: | 173 // Overridden from views::View: |
| 150 virtual bool CanHandleAccelerators() const OVERRIDE; | 174 virtual bool CanHandleAccelerators() const OVERRIDE; |
| 151 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | 175 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; |
| 152 | 176 |
| 153 // Overridden from views::ButtonListener: | 177 // Overridden from views::ButtonListener: |
| 154 virtual void ButtonPressed(views::Button* sender, | 178 virtual void ButtonPressed(views::Button* sender, |
| 155 const ui::Event& event) OVERRIDE; | 179 const ui::Event& event) OVERRIDE; |
| 156 | 180 |
| 157 // Overridden from views::ContextMenuController. | 181 // Overridden from views::ContextMenuController. |
| 158 virtual void ShowContextMenuForView(View* source, | 182 virtual void ShowContextMenuForView(View* source, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 187 // Notifications when to set button state to pushed/not pushed (for when the | 211 // Notifications when to set button state to pushed/not pushed (for when the |
| 188 // popup/context menu is hidden or shown by the container). | 212 // popup/context menu is hidden or shown by the container). |
| 189 void SetButtonPushed(); | 213 void SetButtonPushed(); |
| 190 void SetButtonNotPushed(); | 214 void SetButtonNotPushed(); |
| 191 | 215 |
| 192 // Whether the browser action is enabled on this tab. Note that we cannot use | 216 // Whether the browser action is enabled on this tab. Note that we cannot use |
| 193 // the built-in views enabled/SetEnabled because disabled views do not | 217 // the built-in views enabled/SetEnabled because disabled views do not |
| 194 // receive drag events. | 218 // receive drag events. |
| 195 bool IsEnabled(int tab_id) const; | 219 bool IsEnabled(int tab_id) const; |
| 196 | 220 |
| 197 // Returns icon factory for the button. | 221 // Accessors. |
| 198 ExtensionActionIconFactory& icon_factory() { return icon_factory_; } | 222 ExtensionActionIconFactory& icon_factory() { return icon_factory_; } |
| 223 ExtensionPopup* popup() { return popup_; } | |
| 199 | 224 |
| 200 // Gets the icon of this button and its badge. | 225 // Gets the icon of this button and its badge. |
| 201 gfx::ImageSkia GetIconWithBadge(); | 226 gfx::ImageSkia GetIconWithBadge(); |
| 202 | 227 |
| 203 // Returns button icon so it can be accessed during tests. | 228 // Returns button icon so it can be accessed during tests. |
| 204 gfx::ImageSkia GetIconForTest(); | 229 gfx::ImageSkia GetIconForTest(); |
| 205 | 230 |
| 206 protected: | 231 protected: |
| 207 // Overridden from views::View: | 232 // Overridden from views::View: |
| 208 virtual void ViewHierarchyChanged( | 233 virtual void ViewHierarchyChanged( |
| 209 const ViewHierarchyChangedDetails& details) OVERRIDE; | 234 const ViewHierarchyChangedDetails& details) OVERRIDE; |
| 210 virtual void OnDragDone() OVERRIDE; | 235 virtual void OnDragDone() OVERRIDE; |
| 211 | 236 |
| 212 private: | 237 private: |
| 213 virtual ~BrowserActionButton(); | 238 virtual ~BrowserActionButton(); |
| 214 | 239 |
| 240 // ExtensionContextMenuModel::PopupDelegate: | |
| 241 virtual void InspectPopup(ExtensionAction* action) OVERRIDE; | |
|
Peter Kasting
2014/07/26 02:33:20
It seems like we should make this public, so that
Devlin
2014/07/29 19:07:14
Yeah - I was torn. I like hiding these when possi
| |
| 242 | |
| 243 // views::WidgetObserver: | |
| 244 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | |
| 245 | |
| 215 // Register an extension command if the extension has an active one. | 246 // Register an extension command if the extension has an active one. |
| 216 void MaybeRegisterExtensionCommand(); | 247 void MaybeRegisterExtensionCommand(); |
| 217 | 248 |
| 218 // Unregisters an extension command, if the extension has registered one and | 249 // Unregisters an extension command, if the extension has registered one and |
| 219 // it is active. | 250 // it is active. |
| 220 void MaybeUnregisterExtensionCommand(bool only_if_active); | 251 void MaybeUnregisterExtensionCommand(bool only_if_active); |
| 221 | 252 |
| 222 // The Browser object this button is associated with. | 253 // The Browser object this button is associated with. |
| 223 Browser* browser_; | 254 Browser* browser_; |
| 224 | 255 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 244 | 275 |
| 245 content::NotificationRegistrar registrar_; | 276 content::NotificationRegistrar registrar_; |
| 246 | 277 |
| 247 // The extension key binding accelerator this browser action is listening for | 278 // The extension key binding accelerator this browser action is listening for |
| 248 // (to show the popup). | 279 // (to show the popup). |
| 249 scoped_ptr<ui::Accelerator> keybinding_; | 280 scoped_ptr<ui::Accelerator> keybinding_; |
| 250 | 281 |
| 251 // Responsible for running the menu. | 282 // Responsible for running the menu. |
| 252 scoped_ptr<views::MenuRunner> menu_runner_; | 283 scoped_ptr<views::MenuRunner> menu_runner_; |
| 253 | 284 |
| 285 // The browser action's popup, if it is visible, NULL otherwise. | |
|
Peter Kasting
2014/07/26 02:33:20
Tiny nit: Change second comma to a semicolon or pe
Devlin
2014/07/29 19:07:14
Done.
| |
| 286 ExtensionPopup* popup_; | |
| 287 | |
| 254 // The observer that we need to notify when the icon of the button has been | 288 // The observer that we need to notify when the icon of the button has been |
| 255 // updated. | 289 // updated. |
| 256 IconObserver* icon_observer_; | 290 IconObserver* icon_observer_; |
| 257 | 291 |
| 258 friend class base::DeleteHelper<BrowserActionButton>; | 292 friend class base::DeleteHelper<BrowserActionButton>; |
| 259 | 293 |
| 260 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 294 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
| 261 }; | 295 }; |
| 262 | 296 |
| 263 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 297 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| OLD | NEW |