Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: chrome/browser/ui/views/browser_action_view.h

Issue 10533086: Action box menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Action box menu Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 class BrowserActionView : public views::View {
31 public:
32 // Need DragControler here because BrowserActionView could be dragged/dropped.
33 class Delegate : public views::DragController {
34 public:
35 // Returns the current tab's ID, or -1 if there is no current tab.
36 virtual int GetCurrentTabId() const = 0;
37
38 // Called when the user clicks on the browser action icon.
39 virtual void OnBrowserActionExecuted(BrowserActionButton* button) = 0;
40
41 // Called when a browser action becomes visible/hidden.
42 virtual void OnBrowserActionVisibilityChanged() = 0;
43
44 // Returns relative position of the |button_| inside BrowserActionView.
45 virtual gfx::Size GetViewContentOffset() const = 0;
46
47 protected:
48 Delegate() {}
49 virtual ~Delegate() {}
50 };
51
52 BrowserActionView(const extensions::Extension* extension,
53 Browser* browser,
54 Delegate* delegate);
55 virtual ~BrowserActionView();
56
57 BrowserActionButton* button() { return button_; }
58
59 // Allocates a canvas object on the heap and draws into it the icon for the
60 // view as well as the badge (if any). Caller is responsible for deleting the
61 // returned object.
62 gfx::Canvas* GetIconWithBadge();
63
64 // Overridden from views::View:
65 virtual void Layout() OVERRIDE;
66 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
67 virtual gfx::Size GetPreferredSize() OVERRIDE;
68
69 protected:
70 // Overridden from views::View to paint the badge on top of children.
71 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
72 virtual void ViewHierarchyChanged(bool is_add,
73 View* parent,
74 View* child) OVERRIDE;
75
76 private:
77 // The Browser object this view is associated with.
78 Browser* browser_;
79
80 // The container for this view.
81 Delegate* delegate_;
82
83 // The button this view contains.
84 BrowserActionButton* button_;
85
86 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
87 };
88
89 ////////////////////////////////////////////////////////////////////////////////
25 // BrowserActionButton 90 // BrowserActionButton
26 91
27 // The BrowserActionButton is a specialization of the MenuButton class. 92 // The BrowserActionButton is a specialization of the MenuButton class.
28 // It acts on a ExtensionAction, in this case a BrowserAction and handles 93 // It acts on a ExtensionAction, in this case a BrowserAction and handles
29 // loading the image for the button asynchronously on the file thread. 94 // loading the image for the button asynchronously on the file thread.
30 class BrowserActionButton : public views::MenuButton, 95 class BrowserActionButton : public views::MenuButton,
31 public views::ButtonListener, 96 public views::ButtonListener,
32 public views::ContextMenuController, 97 public views::ContextMenuController,
33 public ImageLoadingTracker::Observer, 98 public ImageLoadingTracker::Observer,
34 public content::NotificationObserver { 99 public content::NotificationObserver {
35 public: 100 public:
36 BrowserActionButton(const extensions::Extension* extension, 101 BrowserActionButton(const extensions::Extension* extension,
37 BrowserActionsContainer* panel); 102 Browser* browser_,
103 BrowserActionView::Delegate* delegate);
38 104
39 // Call this instead of delete. 105 // Call this instead of delete.
40 void Destroy(); 106 void Destroy();
41 107
42 ExtensionAction* browser_action() const { return browser_action_; } 108 ExtensionAction* browser_action() const { return browser_action_; }
43 const extensions::Extension* extension() { return extension_; } 109 const extensions::Extension* extension() { return extension_; }
44 110
45 // Called to update the display to match the browser action's state. 111 // Called to update the display to match the browser action's state.
46 void UpdateState(); 112 void UpdateState();
47 113
(...skipping 28 matching lines...) Expand all
76 // MenuButton behavior overrides. These methods all default to TextButton 142 // MenuButton behavior overrides. These methods all default to TextButton
77 // behavior unless this button is a popup. In that case, it uses MenuButton 143 // behavior unless this button is a popup. In that case, it uses MenuButton
78 // behavior. MenuButton has the notion of a child popup being shown where the 144 // behavior. MenuButton has the notion of a child popup being shown where the
79 // button will stay in the pushed state until the "menu" (a popup in this 145 // button will stay in the pushed state until the "menu" (a popup in this
80 // case) is dismissed. 146 // case) is dismissed.
81 virtual bool Activate() OVERRIDE; 147 virtual bool Activate() OVERRIDE;
82 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; 148 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
83 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; 149 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
84 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; 150 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
85 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; 151 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE;
152 virtual void ShowContextMenu(const gfx::Point& p,
153 bool is_mouse_gesture) OVERRIDE;
86 154
87 // Overridden from ui::AcceleratorTarget. 155 // Overridden from ui::AcceleratorTarget.
88 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 156 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
89 157
90 // Notifications when to set button state to pushed/not pushed (for when the 158 // Notifications when to set button state to pushed/not pushed (for when the
91 // popup/context menu is hidden or shown by the container). 159 // popup/context menu is hidden or shown by the container).
92 void SetButtonPushed(); 160 void SetButtonPushed();
93 void SetButtonNotPushed(); 161 void SetButtonNotPushed();
94 162
163 void SetTooltipDisabled(bool disable_tooltip);
164
95 // Whether the browser action is enabled on this tab. Note that we cannot use 165 // Whether the browser action is enabled on this tab. Note that we cannot use
96 // the built-in views enabled/SetEnabled because disabled views do not 166 // the built-in views enabled/SetEnabled because disabled views do not
97 // receive drag events. 167 // receive drag events.
98 bool IsEnabled(int tab_id) const; 168 bool IsEnabled(int tab_id) const;
99 169
100 protected: 170 protected:
101 // Overridden from views::View: 171 // Overridden from views::View:
102 virtual void ViewHierarchyChanged(bool is_add, 172 virtual void ViewHierarchyChanged(bool is_add,
103 View* parent, 173 View* parent,
104 View* child) OVERRIDE; 174 View* child) OVERRIDE;
105 175
106 private: 176 private:
107 virtual ~BrowserActionButton(); 177 virtual ~BrowserActionButton();
108 178
109 // Register an extension command if the extension has an active one. 179 // Register an extension command if the extension has an active one.
110 void MaybeRegisterExtensionCommand(); 180 void MaybeRegisterExtensionCommand();
111 181
112 // Unregisters an extension command, if the extension has registered one and 182 // Unregisters an extension command, if the extension has registered one and
113 // it is active. 183 // it is active.
114 void MaybeUnregisterExtensionCommand(bool only_if_active); 184 void MaybeUnregisterExtensionCommand(bool only_if_active);
115 185
186 // Returns tooltip for the button.
187 string16 GetTextForTooltip();
188
189 // The Browser object this button is associated with.
190 Browser* browser_;
191
116 // The browser action this view represents. The ExtensionAction is not owned 192 // The browser action this view represents. The ExtensionAction is not owned
117 // by this class. 193 // by this class.
118 ExtensionAction* browser_action_; 194 ExtensionAction* browser_action_;
119 195
120 // The extension associated with the browser action we're displaying. 196 // The extension associated with the browser action we're displaying.
121 const extensions::Extension* extension_; 197 const extensions::Extension* extension_;
122 198
123 // The object that is waiting for the image loading to complete 199 // The object that is waiting for the image loading to complete
124 // asynchronously. 200 // asynchronously.
125 ImageLoadingTracker tracker_; 201 ImageLoadingTracker tracker_;
126 202
127 // The default icon for our browser action. This might be non-empty if the 203 // The default icon for our browser action. This might be non-empty if the
128 // browser action had a value for default_icon in the manifest. 204 // browser action had a value for default_icon in the manifest.
129 SkBitmap default_icon_; 205 SkBitmap default_icon_;
130 206
131 // The browser action shelf. 207 // The browser action shelf.
132 BrowserActionsContainer* panel_; 208 BrowserActionView::Delegate* delegate_;
133 209
134 // The context menu. This member is non-NULL only when the menu is shown. 210 // The context menu. This member is non-NULL only when the menu is shown.
135 views::MenuItemView* context_menu_; 211 views::MenuItemView* context_menu_;
136 212
137 content::NotificationRegistrar registrar_; 213 content::NotificationRegistrar registrar_;
138 214
139 // The extension keybinding accelerator this browser action is listening for 215 // The extension key binding accelerator this browser action is listening for
140 // (to show the popup). 216 // (to show the popup).
141 scoped_ptr<ui::Accelerator> keybinding_; 217 scoped_ptr<ui::Accelerator> keybinding_;
142 218
219 // True if tooltip was disabled.
220 bool disable_tooltip_;
221
143 friend class base::DeleteHelper<BrowserActionButton>; 222 friend class base::DeleteHelper<BrowserActionButton>;
144 223
145 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); 224 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton);
146 }; 225 };
147 226
148
149 ////////////////////////////////////////////////////////////////////////////////
150 // BrowserActionView
151 // A single section in the browser action container. This contains the actual
152 // BrowserActionButton, as well as the logic to paint the badge.
153
154 class BrowserActionView : public views::View {
155 public:
156 BrowserActionView(const extensions::Extension* extension,
157 BrowserActionsContainer* panel);
158 virtual ~BrowserActionView();
159
160 BrowserActionButton* button() { return button_; }
161
162 // Allocates a canvas object on the heap and draws into it the icon for the
163 // view as well as the badge (if any). Caller is responsible for deleting the
164 // returned object.
165 gfx::Canvas* GetIconWithBadge();
166
167 // Overridden from views::View:
168 virtual void Layout() OVERRIDE;
169 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
170
171 protected:
172 // Overridden from views::View to paint the badge on top of children.
173 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
174
175 private:
176 // The container for this view.
177 BrowserActionsContainer* panel_;
178
179 // The button this view contains.
180 BrowserActionButton* button_;
181
182 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
183 };
184
185 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ 227 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698