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