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_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/browser/extensions/image_loading_tracker.h" | 10 #include "chrome/browser/extensions/image_loading_tracker.h" |
11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
12 #include "ui/views/context_menu_controller.h" | 12 #include "ui/views/context_menu_controller.h" |
13 #include "ui/views/controls/button/menu_button.h" | 13 #include "ui/views/controls/button/menu_button.h" |
14 #include "ui/views/controls/button/menu_button_listener.h" | 14 #include "ui/views/controls/button/menu_button_listener.h" |
| 15 #include "ui/views/drag_controller.h" |
15 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
16 | 17 |
17 class BrowserActionsContainer; | 18 class Browser; |
| 19 class BrowserActionButton; |
18 class ExtensionAction; | 20 class ExtensionAction; |
19 | 21 |
| 22 namespace extensions { |
| 23 class Extension; |
| 24 } |
| 25 |
20 namespace views { | 26 namespace views { |
21 class MenuItemView; | 27 class MenuItemView; |
| 28 class MenuRunner; |
22 } | 29 } |
23 | 30 |
24 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 32 // BrowserActionView |
| 33 // A single entry in the browser action container. This contains the actual |
| 34 // BrowserActionButton, as well as the logic to paint the badge. |
| 35 class BrowserActionView : public views::View { |
| 36 public: |
| 37 // Need DragController here because BrowserActionView could be |
| 38 // dragged/dropped. |
| 39 class Delegate : public views::DragController { |
| 40 public: |
| 41 // Returns the current tab's ID, or -1 if there is no current tab. |
| 42 virtual int GetCurrentTabId() const = 0; |
| 43 |
| 44 // Called when the user clicks on the browser action icon. |
| 45 virtual void OnBrowserActionExecuted(BrowserActionButton* button) = 0; |
| 46 |
| 47 // Called when a browser action becomes visible/hidden. |
| 48 virtual void OnBrowserActionVisibilityChanged() = 0; |
| 49 |
| 50 // Returns relative position of a button inside BrowserActionView. |
| 51 virtual gfx::Point GetViewContentOffset() const = 0; |
| 52 |
| 53 virtual bool NeedToShowMultipleIconStates() const; |
| 54 virtual bool NeedToShowTooltip() const; |
| 55 |
| 56 protected: |
| 57 virtual ~Delegate() {} |
| 58 }; |
| 59 |
| 60 BrowserActionView(const extensions::Extension* extension, |
| 61 Browser* browser, |
| 62 Delegate* delegate); |
| 63 virtual ~BrowserActionView(); |
| 64 |
| 65 BrowserActionButton* button() { return button_; } |
| 66 |
| 67 // Allocates a canvas object on the heap and draws into it the icon for the |
| 68 // view as well as the badge (if any). Caller is responsible for deleting the |
| 69 // returned object. |
| 70 gfx::Canvas* GetIconWithBadge(); |
| 71 |
| 72 // Overridden from views::View: |
| 73 virtual void Layout() OVERRIDE; |
| 74 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 75 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 76 |
| 77 protected: |
| 78 // Overridden from views::View to paint the badge on top of children. |
| 79 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
| 80 virtual void ViewHierarchyChanged(bool is_add, |
| 81 View* parent, |
| 82 View* child) OVERRIDE; |
| 83 |
| 84 private: |
| 85 // The Browser object this view is associated with. |
| 86 Browser* browser_; |
| 87 |
| 88 // Usually a container for this view. |
| 89 Delegate* delegate_; |
| 90 |
| 91 // The button this view contains. |
| 92 BrowserActionButton* button_; |
| 93 |
| 94 // Extension this view associated with. |
| 95 const extensions::Extension* extension_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
| 98 }; |
| 99 |
| 100 //////////////////////////////////////////////////////////////////////////////// |
25 // BrowserActionButton | 101 // BrowserActionButton |
26 | 102 |
27 // The BrowserActionButton is a specialization of the MenuButton class. | 103 // The BrowserActionButton is a specialization of the MenuButton class. |
28 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 104 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
29 // loading the image for the button asynchronously on the file thread. | 105 // loading the image for the button asynchronously on the file thread. |
30 class BrowserActionButton : public views::MenuButton, | 106 class BrowserActionButton : public views::MenuButton, |
31 public views::ButtonListener, | 107 public views::ButtonListener, |
32 public views::ContextMenuController, | 108 public views::ContextMenuController, |
33 public ImageLoadingTracker::Observer, | 109 public ImageLoadingTracker::Observer, |
34 public content::NotificationObserver { | 110 public content::NotificationObserver { |
35 public: | 111 public: |
36 BrowserActionButton(const extensions::Extension* extension, | 112 BrowserActionButton(const extensions::Extension* extension, |
37 BrowserActionsContainer* panel); | 113 Browser* browser_, |
| 114 BrowserActionView::Delegate* delegate); |
38 | 115 |
39 // Call this instead of delete. | 116 // Call this instead of delete. |
40 void Destroy(); | 117 void Destroy(); |
41 | 118 |
42 ExtensionAction* browser_action() const { return browser_action_; } | 119 ExtensionAction* browser_action() const { return browser_action_; } |
43 const extensions::Extension* extension() { return extension_; } | 120 const extensions::Extension* extension() { return extension_; } |
44 | 121 |
45 // Called to update the display to match the browser action's state. | 122 // Called to update the display to match the browser action's state. |
46 void UpdateState(); | 123 void UpdateState(); |
47 | 124 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 private: | 181 private: |
105 virtual ~BrowserActionButton(); | 182 virtual ~BrowserActionButton(); |
106 | 183 |
107 // Register an extension command if the extension has an active one. | 184 // Register an extension command if the extension has an active one. |
108 void MaybeRegisterExtensionCommand(); | 185 void MaybeRegisterExtensionCommand(); |
109 | 186 |
110 // Unregisters an extension command, if the extension has registered one and | 187 // Unregisters an extension command, if the extension has registered one and |
111 // it is active. | 188 // it is active. |
112 void MaybeUnregisterExtensionCommand(bool only_if_active); | 189 void MaybeUnregisterExtensionCommand(bool only_if_active); |
113 | 190 |
| 191 // The Browser object this button is associated with. |
| 192 Browser* browser_; |
| 193 |
114 // The browser action this view represents. The ExtensionAction is not owned | 194 // The browser action this view represents. The ExtensionAction is not owned |
115 // by this class. | 195 // by this class. |
116 ExtensionAction* browser_action_; | 196 ExtensionAction* browser_action_; |
117 | 197 |
118 // The extension associated with the browser action we're displaying. | 198 // The extension associated with the browser action we're displaying. |
119 const extensions::Extension* extension_; | 199 const extensions::Extension* extension_; |
120 | 200 |
121 // The object that is waiting for the image loading to complete | 201 // The object that is waiting for the image loading to complete |
122 // asynchronously. | 202 // asynchronously. |
123 ImageLoadingTracker tracker_; | 203 ImageLoadingTracker tracker_; |
124 | 204 |
125 // The browser action shelf. | 205 // The default icon for our browser action. This might be non-empty if the |
126 BrowserActionsContainer* panel_; | 206 // browser action had a value for default_icon in the manifest. |
| 207 SkBitmap default_icon_; |
| 208 |
| 209 // Delegate that usually represents a container for BrowserActionView. |
| 210 BrowserActionView::Delegate* delegate_; |
127 | 211 |
128 // The context menu. This member is non-NULL only when the menu is shown. | 212 // The context menu. This member is non-NULL only when the menu is shown. |
129 views::MenuItemView* context_menu_; | 213 views::MenuItemView* context_menu_; |
130 | 214 |
131 content::NotificationRegistrar registrar_; | 215 content::NotificationRegistrar registrar_; |
132 | 216 |
133 // The extension keybinding accelerator this browser action is listening for | 217 // The extension key binding accelerator this browser action is listening for |
134 // (to show the popup). | 218 // (to show the popup). |
135 scoped_ptr<ui::Accelerator> keybinding_; | 219 scoped_ptr<ui::Accelerator> keybinding_; |
136 | 220 |
| 221 // Responsible for running the menu. |
| 222 scoped_ptr<views::MenuRunner> menu_runner_; |
| 223 |
137 friend class base::DeleteHelper<BrowserActionButton>; | 224 friend class base::DeleteHelper<BrowserActionButton>; |
138 | 225 |
139 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 226 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
140 }; | 227 }; |
141 | 228 |
142 | |
143 //////////////////////////////////////////////////////////////////////////////// | |
144 // BrowserActionView | |
145 // A single section in the browser action container. This contains the actual | |
146 // BrowserActionButton, as well as the logic to paint the badge. | |
147 | |
148 class BrowserActionView : public views::View { | |
149 public: | |
150 BrowserActionView(const extensions::Extension* extension, | |
151 BrowserActionsContainer* panel); | |
152 virtual ~BrowserActionView(); | |
153 | |
154 BrowserActionButton* button() { return button_; } | |
155 | |
156 // Allocates a canvas object on the heap and draws into it the icon for the | |
157 // view as well as the badge (if any). Caller is responsible for deleting the | |
158 // returned object. | |
159 gfx::Canvas* GetIconWithBadge(); | |
160 | |
161 // Overridden from views::View: | |
162 virtual void Layout() OVERRIDE; | |
163 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
164 | |
165 protected: | |
166 // Overridden from views::View to paint the badge on top of children. | |
167 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | |
168 | |
169 private: | |
170 // The container for this view. | |
171 BrowserActionsContainer* panel_; | |
172 | |
173 // The button this view contains. | |
174 BrowserActionButton* button_; | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | |
177 }; | |
178 | |
179 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ | 229 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
OLD | NEW |