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 "chrome/browser/ui/views/extensions/extension_action_view_controller.h" | 8 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" |
9 #include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h" | 9 #include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
12 #include "ui/views/controls/button/menu_button.h" | 12 #include "ui/views/controls/button/menu_button.h" |
13 #include "ui/views/controls/button/menu_button_listener.h" | 13 #include "ui/views/controls/button/menu_button_listener.h" |
14 #include "ui/views/drag_controller.h" | 14 #include "ui/views/drag_controller.h" |
15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
16 | 16 |
17 class Browser; | 17 class Browser; |
18 class BrowserActionButton; | |
19 class ExtensionAction; | 18 class ExtensionAction; |
20 | 19 |
21 namespace extensions { | 20 namespace extensions { |
22 class Extension; | 21 class Extension; |
23 } | 22 } |
24 | 23 |
25 namespace gfx { | 24 namespace gfx { |
26 class Image; | 25 class Image; |
27 } | 26 } |
28 | 27 |
29 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
30 // BrowserActionView | 29 // BrowserActionView |
31 // A single entry in the browser action container. This contains the actual | 30 // A wrapper around an ExtensionActionViewController to display an extension |
32 // BrowserActionButton, as well as the logic to paint the badge. | 31 // action in the BrowserActionsContainer. |
33 class BrowserActionView : public views::View { | 32 // Despite its name, this class can handle either Browser Actions or Page |
| 33 // Actions. |
| 34 // TODO(devlin): Rename this and BrowserActionsContainer when more of the |
| 35 // toolbar redesign is done. |
| 36 class BrowserActionView : public views::MenuButton, |
| 37 public ExtensionActionViewDelegate, |
| 38 public views::ButtonListener, |
| 39 public content::NotificationObserver { |
34 public: | 40 public: |
35 // Need DragController here because BrowserActionView could be | 41 // Need DragController here because BrowserActionView could be |
36 // dragged/dropped. | 42 // dragged/dropped. |
37 class Delegate : public views::DragController { | 43 class Delegate : public views::DragController { |
38 public: | 44 public: |
39 // Returns the current web contents. | 45 // Returns the current web contents. |
40 virtual content::WebContents* GetCurrentWebContents() = 0; | 46 virtual content::WebContents* GetCurrentWebContents() = 0; |
41 | 47 |
42 // Called when a browser action becomes visible/hidden. | 48 // Called when a browser action becomes visible/hidden. |
43 virtual void OnBrowserActionVisibilityChanged() = 0; | 49 virtual void OnBrowserActionVisibilityChanged() = 0; |
44 | 50 |
45 // Whether the container for this button is shown inside a menu. | 51 // Whether the container for this button is shown inside a menu. |
46 virtual bool ShownInsideMenu() const = 0; | 52 virtual bool ShownInsideMenu() const = 0; |
47 | 53 |
48 // Notifies that a drag completed. Note this will only happen if the view | 54 // Notifies that a drag completed. Note this will only happen if the view |
49 // wasn't removed during the drag-and-drop process (i.e., not when there | 55 // wasn't removed during the drag-and-drop process (i.e., not when there |
50 // was a move in the browser actions, since we re-create the views each | 56 // was a move in the browser actions, since we re-create the views each |
51 // time we re-order the browser actions). | 57 // time we re-order the browser actions). |
52 virtual void OnBrowserActionViewDragDone() = 0; | 58 virtual void OnBrowserActionViewDragDone() = 0; |
53 | 59 |
54 // Returns the view of the browser actions overflow menu to use as a | 60 // Returns the view of the browser actions overflow menu to use as a |
55 // reference point for a popup when this view isn't visible. | 61 // reference point for a popup when this view isn't visible. |
56 virtual views::View* GetOverflowReferenceView() = 0; | 62 virtual views::View* GetOverflowReferenceView() = 0; |
57 | 63 |
58 // Sets the delegate's active popup owner to be |popup_owner|. | 64 // Sets the delegate's active popup owner to be |popup_owner|. |
59 virtual void SetPopupOwner(BrowserActionButton* popup_owner) = 0; | 65 virtual void SetPopupOwner(BrowserActionView* popup_owner) = 0; |
60 | 66 |
61 // Hides the active popup of the delegate, if one exists. | 67 // Hides the active popup of the delegate, if one exists. |
62 virtual void HideActivePopup() = 0; | 68 virtual void HideActivePopup() = 0; |
63 | 69 |
64 protected: | 70 protected: |
65 virtual ~Delegate() {} | 71 virtual ~Delegate() {} |
66 }; | 72 }; |
67 | 73 |
68 BrowserActionView(const extensions::Extension* extension, | |
69 Browser* browser, | |
70 Delegate* delegate); | |
71 virtual ~BrowserActionView(); | |
72 | |
73 BrowserActionButton* button() { return button_.get(); } | |
74 | |
75 // Gets browser action button icon with the badge. | |
76 gfx::ImageSkia GetIconWithBadge(); | |
77 | |
78 // Overridden from views::View: | |
79 virtual void Layout() OVERRIDE; | |
80 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | |
81 virtual gfx::Size GetPreferredSize() const OVERRIDE; | |
82 | |
83 protected: | |
84 // Overridden from views::View to paint the badge on top of children. | |
85 virtual void PaintChildren(gfx::Canvas* canvas, | |
86 const views::CullSet& cull_set) OVERRIDE; | |
87 | |
88 private: | |
89 // Usually a container for this view. | |
90 Delegate* delegate_; | |
91 | |
92 // The button this view contains. | |
93 scoped_ptr<BrowserActionButton> button_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | |
96 }; | |
97 | |
98 //////////////////////////////////////////////////////////////////////////////// | |
99 // BrowserActionButton | |
100 | |
101 // The BrowserActionButton is a specialization of the MenuButton class. | |
102 // This wraps an ExtensionActionView, and has knowledge of how to render itself | |
103 // and when to trigger the extension action. | |
104 class BrowserActionButton : public views::MenuButton, | |
105 public ExtensionActionViewDelegate, | |
106 public views::ButtonListener, | |
107 public content::NotificationObserver { | |
108 public: | |
109 // The IconObserver will receive a notification when the button's icon has | 74 // The IconObserver will receive a notification when the button's icon has |
110 // been updated. | 75 // been updated. |
111 class IconObserver { | 76 class IconObserver { |
112 public: | 77 public: |
113 virtual void OnIconUpdated(const gfx::ImageSkia& icon) = 0; | 78 virtual void OnIconUpdated(const gfx::ImageSkia& icon) = 0; |
114 | 79 |
115 protected: | 80 protected: |
116 virtual ~IconObserver() {} | 81 virtual ~IconObserver() {} |
117 }; | 82 }; |
118 | 83 |
119 BrowserActionButton(const extensions::Extension* extension, | 84 BrowserActionView(const extensions::Extension* extension, |
120 Browser* browser, | 85 Browser* browser, |
121 BrowserActionView::Delegate* delegate); | 86 BrowserActionView::Delegate* delegate); |
122 virtual ~BrowserActionButton(); | 87 virtual ~BrowserActionView(); |
123 | 88 |
124 const extensions::Extension* extension() const { | 89 const extensions::Extension* extension() const { |
125 return view_controller_->extension(); | 90 return view_controller_->extension(); |
126 } | 91 } |
127 ExtensionAction* extension_action() { | 92 ExtensionAction* extension_action() { |
128 return view_controller_->extension_action(); | 93 return view_controller_->extension_action(); |
129 } | 94 } |
130 ExtensionActionViewController* view_controller() { | 95 ExtensionActionViewController* view_controller() { |
131 return view_controller_.get(); | 96 return view_controller_.get(); |
132 } | 97 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // the built-in views enabled/SetEnabled because disabled views do not | 140 // the built-in views enabled/SetEnabled because disabled views do not |
176 // receive drag events. | 141 // receive drag events. |
177 bool IsEnabled(int tab_id) const; | 142 bool IsEnabled(int tab_id) const; |
178 | 143 |
179 // Gets the icon of this button and its badge. | 144 // Gets the icon of this button and its badge. |
180 gfx::ImageSkia GetIconWithBadge(); | 145 gfx::ImageSkia GetIconWithBadge(); |
181 | 146 |
182 // Returns button icon so it can be accessed during tests. | 147 // Returns button icon so it can be accessed during tests. |
183 gfx::ImageSkia GetIconForTest(); | 148 gfx::ImageSkia GetIconForTest(); |
184 | 149 |
185 protected: | 150 private: |
186 // Overridden from views::View: | 151 // Overridden from views::View: |
187 virtual void ViewHierarchyChanged( | 152 virtual void ViewHierarchyChanged( |
188 const ViewHierarchyChangedDetails& details) OVERRIDE; | 153 const ViewHierarchyChangedDetails& details) OVERRIDE; |
189 virtual void OnDragDone() OVERRIDE; | 154 virtual void OnDragDone() OVERRIDE; |
| 155 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
| 156 virtual void PaintChildren(gfx::Canvas* canvas, |
| 157 const views::CullSet& cull_set) OVERRIDE; |
190 | 158 |
191 private: | |
192 // ExtensionActionViewDelegate: | 159 // ExtensionActionViewDelegate: |
193 virtual views::View* GetAsView() OVERRIDE; | 160 virtual views::View* GetAsView() OVERRIDE; |
194 virtual bool IsShownInMenu() OVERRIDE; | 161 virtual bool IsShownInMenu() OVERRIDE; |
195 virtual views::FocusManager* GetFocusManagerForAccelerator() OVERRIDE; | 162 virtual views::FocusManager* GetFocusManagerForAccelerator() OVERRIDE; |
196 virtual views::Widget* GetParentForContextMenu() OVERRIDE; | 163 virtual views::Widget* GetParentForContextMenu() OVERRIDE; |
197 virtual views::View* GetReferenceViewForPopup() OVERRIDE; | 164 virtual views::View* GetReferenceViewForPopup() OVERRIDE; |
198 virtual content::WebContents* GetCurrentWebContents() OVERRIDE; | 165 virtual content::WebContents* GetCurrentWebContents() OVERRIDE; |
199 virtual void HideActivePopup() OVERRIDE; | 166 virtual void HideActivePopup() OVERRIDE; |
200 virtual void OnIconUpdated() OVERRIDE; | 167 virtual void OnIconUpdated() OVERRIDE; |
201 virtual void OnPopupShown(bool grant_tab_permissions) OVERRIDE; | 168 virtual void OnPopupShown(bool grant_tab_permissions) OVERRIDE; |
202 virtual void CleanupPopup() OVERRIDE; | 169 virtual void CleanupPopup() OVERRIDE; |
203 virtual void OnWillShowContextMenus() OVERRIDE; | 170 virtual void OnWillShowContextMenus() OVERRIDE; |
204 virtual void OnContextMenuDone() OVERRIDE; | 171 virtual void OnContextMenuDone() OVERRIDE; |
205 | 172 |
206 // The controller for this ExtensionAction view. | 173 // The controller for this ExtensionAction view. |
207 scoped_ptr<ExtensionActionViewController> view_controller_; | 174 scoped_ptr<ExtensionActionViewController> view_controller_; |
208 | 175 |
209 // Delegate that usually represents a container for BrowserActionView. | 176 // Delegate that usually represents a container for BrowserActionView. |
210 BrowserActionView::Delegate* delegate_; | 177 BrowserActionView::Delegate* delegate_; |
211 | 178 |
212 // Used to make sure we only register the command once. | 179 // Used to make sure we only register the command once. |
213 bool called_registered_extension_command_; | 180 bool called_registered_extension_command_; |
214 | 181 |
215 content::NotificationRegistrar registrar_; | 182 content::NotificationRegistrar registrar_; |
216 | 183 |
217 // The observer that we need to notify when the icon of the button has been | 184 // The observer that we need to notify when the icon of the button has been |
218 // updated. | 185 // updated. |
219 IconObserver* icon_observer_; | 186 IconObserver* icon_observer_; |
220 | 187 |
221 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 188 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
222 }; | 189 }; |
223 | 190 |
224 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 191 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
OLD | NEW |