| 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> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 // The BrowserActionButton is a specialization of the MenuButton class. | 105 // The BrowserActionButton is a specialization of the MenuButton class. |
| 106 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 106 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
| 107 // loading the image for the button asynchronously on the file thread. | 107 // loading the image for the button asynchronously on the file thread. |
| 108 class BrowserActionButton : public views::MenuButton, | 108 class BrowserActionButton : public views::MenuButton, |
| 109 public views::ButtonListener, | 109 public views::ButtonListener, |
| 110 public views::ContextMenuController, | 110 public views::ContextMenuController, |
| 111 public content::NotificationObserver, | 111 public content::NotificationObserver, |
| 112 public ExtensionActionIconFactory::Observer { | 112 public ExtensionActionIconFactory::Observer { |
| 113 public: | 113 public: |
| 114 // The IconObserver will receive a notification when the button's icon has |
| 115 // been updated. |
| 116 class IconObserver { |
| 117 public: |
| 118 virtual void OnIconUpdated(const gfx::ImageSkia& icon) = 0; |
| 119 |
| 120 protected: |
| 121 virtual ~IconObserver() {} |
| 122 }; |
| 123 |
| 114 BrowserActionButton(const extensions::Extension* extension, | 124 BrowserActionButton(const extensions::Extension* extension, |
| 115 Browser* browser_, | 125 Browser* browser_, |
| 116 BrowserActionView::Delegate* delegate); | 126 BrowserActionView::Delegate* delegate); |
| 117 | 127 |
| 118 // Call this instead of delete. | 128 // Call this instead of delete. |
| 119 void Destroy(); | 129 void Destroy(); |
| 120 | 130 |
| 121 ExtensionAction* browser_action() const { return browser_action_; } | 131 ExtensionAction* browser_action() const { return browser_action_; } |
| 122 const extensions::Extension* extension() { return extension_; } | 132 const extensions::Extension* extension() { return extension_; } |
| 123 | 133 |
| 134 void set_icon_observer(IconObserver* icon_observer) { |
| 135 icon_observer_ = icon_observer; |
| 136 } |
| 137 |
| 124 // Called to update the display to match the browser action's state. | 138 // Called to update the display to match the browser action's state. |
| 125 void UpdateState(); | 139 void UpdateState(); |
| 126 | 140 |
| 127 // Does this button's action have a popup? | 141 // Does this button's action have a popup? |
| 128 virtual bool IsPopup(); | 142 virtual bool IsPopup(); |
| 129 virtual GURL GetPopupUrl(); | 143 virtual GURL GetPopupUrl(); |
| 130 | 144 |
| 131 // Overridden from views::View: | 145 // Overridden from views::View: |
| 132 virtual bool CanHandleAccelerators() const OVERRIDE; | 146 virtual bool CanHandleAccelerators() const OVERRIDE; |
| 133 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 147 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 void SetButtonNotPushed(); | 184 void SetButtonNotPushed(); |
| 171 | 185 |
| 172 // Whether the browser action is enabled on this tab. Note that we cannot use | 186 // Whether the browser action is enabled on this tab. Note that we cannot use |
| 173 // the built-in views enabled/SetEnabled because disabled views do not | 187 // the built-in views enabled/SetEnabled because disabled views do not |
| 174 // receive drag events. | 188 // receive drag events. |
| 175 bool IsEnabled(int tab_id) const; | 189 bool IsEnabled(int tab_id) const; |
| 176 | 190 |
| 177 // Returns icon factory for the button. | 191 // Returns icon factory for the button. |
| 178 ExtensionActionIconFactory& icon_factory() { return icon_factory_; } | 192 ExtensionActionIconFactory& icon_factory() { return icon_factory_; } |
| 179 | 193 |
| 194 // Gets the icon of this button and its badge. |
| 195 gfx::ImageSkia GetIconWithBadge(); |
| 196 |
| 180 // Returns button icon so it can be accessed during tests. | 197 // Returns button icon so it can be accessed during tests. |
| 181 gfx::ImageSkia GetIconForTest(); | 198 gfx::ImageSkia GetIconForTest(); |
| 182 | 199 |
| 183 protected: | 200 protected: |
| 184 // Overridden from views::View: | 201 // Overridden from views::View: |
| 185 virtual void ViewHierarchyChanged( | 202 virtual void ViewHierarchyChanged( |
| 186 const ViewHierarchyChangedDetails& details) OVERRIDE; | 203 const ViewHierarchyChangedDetails& details) OVERRIDE; |
| 187 | 204 |
| 188 private: | 205 private: |
| 189 virtual ~BrowserActionButton(); | 206 virtual ~BrowserActionButton(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 240 |
| 224 content::NotificationRegistrar registrar_; | 241 content::NotificationRegistrar registrar_; |
| 225 | 242 |
| 226 // The extension key binding accelerator this browser action is listening for | 243 // The extension key binding accelerator this browser action is listening for |
| 227 // (to show the popup). | 244 // (to show the popup). |
| 228 scoped_ptr<ui::Accelerator> keybinding_; | 245 scoped_ptr<ui::Accelerator> keybinding_; |
| 229 | 246 |
| 230 // Responsible for running the menu. | 247 // Responsible for running the menu. |
| 231 scoped_ptr<views::MenuRunner> menu_runner_; | 248 scoped_ptr<views::MenuRunner> menu_runner_; |
| 232 | 249 |
| 250 // The observer that we need to notify when the icon of the button has been |
| 251 // updated. |
| 252 IconObserver* icon_observer_; |
| 253 |
| 233 friend class base::DeleteHelper<BrowserActionButton>; | 254 friend class base::DeleteHelper<BrowserActionButton>; |
| 234 | 255 |
| 235 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 256 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
| 236 }; | 257 }; |
| 237 | 258 |
| 238 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 259 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| OLD | NEW |