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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/extensions/image_loading_tracker.h" | 11 #include "chrome/browser/extensions/image_loading_tracker.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.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 |
20 namespace views { | 22 namespace views { |
21 class MenuItemView; | 23 class MenuItemView; |
22 } | 24 } |
23 | 25 |
24 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
27 // BrowserActionView | |
28 // A single section in the browser action container. This contains the actual | |
29 // BrowserActionButton, as well as the logic to paint the badge. | |
30 | |
Aaron Boodman
2012/07/02 22:41:34
Delete this line.
yefimt
2012/07/11 22:34:34
Done.
| |
31 class BrowserActionView : public views::View { | |
32 public: | |
33 class Delegate : public views::DragController { | |
34 public: | |
35 virtual Browser* GetBrowser() const = 0; | |
36 virtual int GetCurrentTabId() const = 0; | |
37 virtual void OnBrowserActionExecuted(BrowserActionButton* button) = 0; | |
38 virtual void OnBrowserActionVisibilityChanged() = 0; | |
39 virtual gfx::Size GetViewContentOffset() const = 0; | |
Aaron Boodman
2012/07/02 22:41:34
This name is not very descriptive. Can you pick a
yefimt
2012/07/11 22:34:34
I have a hard time to come up with a better name,
| |
40 | |
41 protected: | |
42 Delegate() {} | |
43 virtual ~Delegate() {} | |
44 }; | |
45 | |
46 BrowserActionView(const extensions::Extension* extension, Delegate* delegate); | |
47 virtual ~BrowserActionView(); | |
48 | |
49 BrowserActionButton* button() { return button_; } | |
50 | |
51 // Allocates a canvas object on the heap and draws into it the icon for the | |
52 // view as well as the badge (if any). Caller is responsible for deleting the | |
53 // returned object. | |
54 gfx::Canvas* GetIconWithBadge(); | |
55 | |
56 // Overridden from views::View: | |
57 virtual void Layout() OVERRIDE; | |
58 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
59 | |
60 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
61 | |
62 protected: | |
63 // Overridden from views::View to paint the badge on top of children. | |
64 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | |
65 | |
66 private: | |
67 // The container for this view. | |
68 Delegate* delegate_; | |
69 | |
70 // The button this view contains. | |
71 BrowserActionButton* button_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | |
74 }; | |
75 | |
76 //////////////////////////////////////////////////////////////////////////////// | |
25 // BrowserActionButton | 77 // BrowserActionButton |
26 | 78 |
27 // The BrowserActionButton is a specialization of the MenuButton class. | 79 // The BrowserActionButton is a specialization of the MenuButton class. |
28 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 80 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
29 // loading the image for the button asynchronously on the file thread. | 81 // loading the image for the button asynchronously on the file thread. |
30 class BrowserActionButton : public views::MenuButton, | 82 class BrowserActionButton : public views::MenuButton, |
31 public views::ButtonListener, | 83 public views::ButtonListener, |
Aaron Boodman
2012/07/02 22:41:34
These should line up as they did before.
yefimt
2012/07/11 22:34:34
Done
I have a devstudio plugin which tries to do s
| |
32 public ImageLoadingTracker::Observer, | 84 public ImageLoadingTracker::Observer, |
33 public content::NotificationObserver { | 85 public content::NotificationObserver { |
34 public: | 86 public: |
35 BrowserActionButton(const extensions::Extension* extension, | 87 BrowserActionButton(const extensions::Extension* extension, |
36 BrowserActionsContainer* panel); | 88 BrowserActionView::Delegate* delegate); |
Aaron Boodman
2012/07/02 22:41:34
Put indent back as before.
yefimt
2012/07/11 22:34:34
Done.
| |
37 | 89 |
38 // Call this instead of delete. | 90 // Call this instead of delete. |
39 void Destroy(); | 91 void Destroy(); |
40 | 92 |
41 ExtensionAction* browser_action() const { return browser_action_; } | 93 ExtensionAction* browser_action() const { return browser_action_; } |
42 const extensions::Extension* extension() { return extension_; } | 94 const extensions::Extension* extension() { return extension_; } |
43 | 95 |
44 // Called to update the display to match the browser action's state. | 96 // Called to update the display to match the browser action's state. |
45 void UpdateState(); | 97 void UpdateState(); |
46 | 98 |
47 // Returns the default icon, if any. | 99 // Returns the default icon, if any. |
48 const SkBitmap& default_icon() const { return default_icon_; } | 100 const SkBitmap& default_icon() const { return default_icon_; } |
49 | 101 |
50 // Does this button's action have a popup? | 102 // Does this button's action have a popup? |
51 virtual bool IsPopup(); | 103 virtual bool IsPopup(); |
52 virtual GURL GetPopupUrl(); | 104 virtual GURL GetPopupUrl(); |
53 | 105 |
54 // Overridden from views::View: | 106 // Overridden from views::View: |
55 virtual bool CanHandleAccelerators() const OVERRIDE; | 107 virtual bool CanHandleAccelerators() const OVERRIDE; |
56 | 108 |
57 // Overridden from views::ButtonListener: | 109 // Overridden from views::ButtonListener: |
58 virtual void ButtonPressed(views::Button* sender, | 110 virtual void ButtonPressed(views::Button* sender, |
59 const views::Event& event) OVERRIDE; | 111 const views::Event& event) OVERRIDE; |
Aaron Boodman
2012/07/02 22:41:34
Why are you changing all these indents?
yefimt
2012/07/11 22:34:34
Done.
| |
60 | 112 |
61 // Overridden from ImageLoadingTracker. | 113 // Overridden from ImageLoadingTracker. |
62 virtual void OnImageLoaded(const gfx::Image& image, | 114 virtual void OnImageLoaded(const gfx::Image& image, |
63 const std::string& extension_id, | 115 const std::string& extension_id, |
64 int index) OVERRIDE; | 116 int index) OVERRIDE; |
65 | 117 |
66 // Overridden from content::NotificationObserver: | 118 // Overridden from content::NotificationObserver: |
67 virtual void Observe(int type, | 119 virtual void Observe(int type, |
68 const content::NotificationSource& source, | 120 const content::NotificationSource& source, |
69 const content::NotificationDetails& details) OVERRIDE; | 121 const content::NotificationDetails& details) OVERRIDE; |
70 | 122 |
71 // MenuButton behavior overrides. These methods all default to TextButton | 123 // MenuButton behavior overrides. These methods all default to TextButton |
72 // behavior unless this button is a popup. In that case, it uses MenuButton | 124 // behavior unless this button is a popup. In that case, it uses MenuButton |
73 // behavior. MenuButton has the notion of a child popup being shown where the | 125 // behavior. MenuButton has the notion of a child popup being shown where the |
74 // button will stay in the pushed state until the "menu" (a popup in this | 126 // button will stay in the pushed state until the "menu" (a popup in this |
75 // case) is dismissed. | 127 // case) is dismissed. |
76 virtual bool Activate() OVERRIDE; | 128 virtual bool Activate() OVERRIDE; |
77 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | 129 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
78 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 130 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |
79 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 131 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
80 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; | 132 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; |
81 virtual void ShowContextMenu(const gfx::Point& p, | 133 virtual void ShowContextMenu(const gfx::Point& p, |
82 bool is_mouse_gesture) OVERRIDE; | 134 bool is_mouse_gesture) OVERRIDE; |
83 | 135 |
84 // Overridden from ui::AcceleratorTarget. | 136 // Overridden from ui::AcceleratorTarget. |
85 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 137 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
86 | 138 |
87 // Notifications when to set button state to pushed/not pushed (for when the | 139 // Notifications when to set button state to pushed/not pushed (for when the |
88 // popup/context menu is hidden or shown by the container). | 140 // popup/context menu is hidden or shown by the container). |
89 void SetButtonPushed(); | 141 void SetButtonPushed(); |
90 void SetButtonNotPushed(); | 142 void SetButtonNotPushed(); |
91 | 143 |
144 void DisableTooltip(bool disable_tooltip); | |
Aaron Boodman
2012/07/02 22:41:34
Hm, we should do something with the tooltip text t
yefimt
2012/07/11 22:34:34
This one disables tooltip for an browser action bu
| |
145 | |
92 protected: | 146 protected: |
93 // Overridden from views::View: | 147 // Overridden from views::View: |
94 virtual void ViewHierarchyChanged(bool is_add, | 148 virtual void ViewHierarchyChanged(bool is_add, |
95 View* parent, | 149 View* parent, |
96 View* child) OVERRIDE; | 150 View* child) OVERRIDE; |
97 | 151 |
98 private: | 152 private: |
99 virtual ~BrowserActionButton(); | 153 virtual ~BrowserActionButton(); |
100 | 154 |
101 // Register an extension command if the extension has an active one. | 155 // Register an extension command if the extension has an active one. |
102 void MaybeRegisterExtensionCommand(); | 156 void MaybeRegisterExtensionCommand(); |
103 | 157 |
104 // Unregisters an extension command, if the extension has registered one and | 158 // Unregisters an extension command, if the extension has registered one and |
105 // it is active. | 159 // it is active. |
106 void MaybeUnregisterExtensionCommand(bool only_if_active); | 160 void MaybeUnregisterExtensionCommand(bool only_if_active); |
107 | 161 |
108 // The browser action this view represents. The ExtensionAction is not owned | 162 // The browser action this view represents. The ExtensionAction is not owned |
109 // by this class. | 163 // by this class. |
110 ExtensionAction* browser_action_; | 164 ExtensionAction* browser_action_; |
111 | 165 |
112 // The extension associated with the browser action we're displaying. | 166 // The extension associated with the browser action we're displaying. |
113 const extensions::Extension* extension_; | 167 const extensions::Extension* extension_; |
114 | 168 |
115 // The object that is waiting for the image loading to complete | 169 // The object that is waiting for the image loading to complete |
116 // asynchronously. | 170 // asynchronously. |
117 ImageLoadingTracker tracker_; | 171 ImageLoadingTracker tracker_; |
118 | 172 |
119 // The default icon for our browser action. This might be non-empty if the | 173 // The default icon for our browser action. This might be non-empty if the |
120 // browser action had a value for default_icon in the manifest. | 174 // browser action had a value for default_icon in the manifest. |
121 SkBitmap default_icon_; | 175 SkBitmap default_icon_; |
122 | 176 |
123 // The browser action shelf. | 177 // The browser action shelf. |
124 BrowserActionsContainer* panel_; | 178 BrowserActionView::Delegate* delegate_; |
125 | 179 |
126 // The context menu. This member is non-NULL only when the menu is shown. | 180 // The context menu. This member is non-NULL only when the menu is shown. |
127 views::MenuItemView* context_menu_; | 181 views::MenuItemView* context_menu_; |
128 | 182 |
129 content::NotificationRegistrar registrar_; | 183 content::NotificationRegistrar registrar_; |
130 | 184 |
131 // The extension keybinding accelerator this browser action is listening for | 185 // The extension key binding accelerator this browser action is listening for |
132 // (to show the popup). | 186 // (to show the popup). |
133 scoped_ptr<ui::Accelerator> keybinding_; | 187 scoped_ptr<ui::Accelerator> keybinding_; |
134 | 188 |
189 bool disable_tooltip_; | |
Aaron Boodman
2012/07/02 22:41:34
Comment.
yefimt
2012/07/11 22:34:34
Done.
| |
190 | |
135 friend class base::DeleteHelper<BrowserActionButton>; | 191 friend class base::DeleteHelper<BrowserActionButton>; |
136 | 192 |
137 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 193 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
138 }; | 194 }; |
139 | 195 |
140 | |
141 //////////////////////////////////////////////////////////////////////////////// | |
142 // BrowserActionView | |
143 // A single section in the browser action container. This contains the actual | |
144 // BrowserActionButton, as well as the logic to paint the badge. | |
145 | |
146 class BrowserActionView : public views::View { | |
147 public: | |
148 BrowserActionView(const extensions::Extension* extension, | |
149 BrowserActionsContainer* panel); | |
150 virtual ~BrowserActionView(); | |
151 | |
152 BrowserActionButton* button() { return button_; } | |
153 | |
154 // Allocates a canvas object on the heap and draws into it the icon for the | |
155 // view as well as the badge (if any). Caller is responsible for deleting the | |
156 // returned object. | |
157 gfx::Canvas* GetIconWithBadge(); | |
158 | |
159 // Overridden from views::View: | |
160 virtual void Layout() OVERRIDE; | |
161 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
162 | |
163 protected: | |
164 // Overridden from views::View to paint the badge on top of children. | |
165 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | |
166 | |
167 private: | |
168 // The container for this view. | |
169 BrowserActionsContainer* panel_; | |
170 | |
171 // The button this view contains. | |
172 BrowserActionButton* button_; | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | |
175 }; | |
176 | |
177 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ | 196 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
OLD | NEW |