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

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/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 {
Peter Kasting 2012/07/14 02:08:01 Why is the delegate a DragController? Either the
yefimt 2012/07/17 18:20:37 They could implement it by themself, but then Brow
32 public:
33 // Returns the browser this container is associated with.
34 virtual Browser* GetBrowser() const = 0;
Peter Kasting 2012/07/14 02:08:01 Why add this getter instead of just passing the Br
yefimt 2012/07/17 18:20:37 It is possible, I just didnt want to change existi
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 a content inside the view.
Peter Kasting 2012/07/14 02:08:01 Nit: "a content" is not grammatical, and regardles
yefimt 2012/07/17 18:20:37 Ok, I got a few comments about it, I guess I canno
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
Peter Kasting 2012/07/14 02:08:01 Nit: Remove blank line
yefimt 2012/07/17 18:20:37 Done.
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
73 private:
74 // The container for this view.
75 Delegate* delegate_;
76
77 // The button this view contains.
78 BrowserActionButton* button_;
79
80 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
81 };
82
83 ////////////////////////////////////////////////////////////////////////////////
24 // BrowserActionButton 84 // BrowserActionButton
25 85
26 // The BrowserActionButton is a specialization of the MenuButton class. 86 // The BrowserActionButton is a specialization of the MenuButton class.
27 // It acts on a ExtensionAction, in this case a BrowserAction and handles 87 // It acts on a ExtensionAction, in this case a BrowserAction and handles
28 // loading the image for the button asynchronously on the file thread. 88 // loading the image for the button asynchronously on the file thread.
29 class BrowserActionButton : public views::MenuButton, 89 class BrowserActionButton : public views::MenuButton,
30 public views::ButtonListener, 90 public views::ButtonListener,
31 public ImageLoadingTracker::Observer, 91 public ImageLoadingTracker::Observer,
32 public content::NotificationObserver { 92 public content::NotificationObserver {
33 public: 93 public:
34 BrowserActionButton(const extensions::Extension* extension, 94 BrowserActionButton(const extensions::Extension* extension,
35 BrowserActionsContainer* panel); 95 BrowserActionView::Delegate* delegate);
36 96
37 // Call this instead of delete. 97 // Call this instead of delete.
38 void Destroy(); 98 void Destroy();
39 99
40 ExtensionAction* browser_action() const { return browser_action_; } 100 ExtensionAction* browser_action() const { return browser_action_; }
41 const extensions::Extension* extension() { return extension_; } 101 const extensions::Extension* extension() { return extension_; }
42 102
43 // Called to update the display to match the browser action's state. 103 // Called to update the display to match the browser action's state.
44 void UpdateState(); 104 void UpdateState();
45 105
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 bool is_mouse_gesture) OVERRIDE; 141 bool is_mouse_gesture) OVERRIDE;
82 142
83 // Overridden from ui::AcceleratorTarget. 143 // Overridden from ui::AcceleratorTarget.
84 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 144 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
85 145
86 // Notifications when to set button state to pushed/not pushed (for when the 146 // Notifications when to set button state to pushed/not pushed (for when the
87 // popup/context menu is hidden or shown by the container). 147 // popup/context menu is hidden or shown by the container).
88 void SetButtonPushed(); 148 void SetButtonPushed();
89 void SetButtonNotPushed(); 149 void SetButtonNotPushed();
90 150
151 void SetTooltipDisabled(bool disable_tooltip);
152
91 protected: 153 protected:
92 // Overridden from views::View: 154 // Overridden from views::View:
93 virtual void ViewHierarchyChanged(bool is_add, 155 virtual void ViewHierarchyChanged(bool is_add,
94 View* parent, 156 View* parent,
Peter Kasting 2012/07/14 02:08:01 Nit: Why did you change the previous correct inden
yefimt 2012/07/17 18:20:37 It is not exactly me, Visual Assist I have in devs
95 View* child) OVERRIDE; 157 View* child) OVERRIDE;
96 158
97 private: 159 private:
98 virtual ~BrowserActionButton(); 160 virtual ~BrowserActionButton();
99 161
100 // Register an extension command if the extension has an active one. 162 // Register an extension command if the extension has an active one.
101 void MaybeRegisterExtensionCommand(); 163 void MaybeRegisterExtensionCommand();
102 164
103 // Unregisters an extension command, if the extension has registered one and 165 // Unregisters an extension command, if the extension has registered one and
104 // it is active. 166 // it is active.
105 void MaybeUnregisterExtensionCommand(bool only_if_active); 167 void MaybeUnregisterExtensionCommand(bool only_if_active);
106 168
169 // Returns tooltip for the button.
170 string16 GetTextForTooltip();
171
107 // The browser action this view represents. The ExtensionAction is not owned 172 // The browser action this view represents. The ExtensionAction is not owned
108 // by this class. 173 // by this class.
109 ExtensionAction* browser_action_; 174 ExtensionAction* browser_action_;
110 175
111 // The extension associated with the browser action we're displaying. 176 // The extension associated with the browser action we're displaying.
112 const extensions::Extension* extension_; 177 const extensions::Extension* extension_;
113 178
114 // The object that is waiting for the image loading to complete 179 // The object that is waiting for the image loading to complete
115 // asynchronously. 180 // asynchronously.
116 ImageLoadingTracker tracker_; 181 ImageLoadingTracker tracker_;
117 182
118 // The default icon for our browser action. This might be non-empty if the 183 // 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. 184 // browser action had a value for default_icon in the manifest.
120 SkBitmap default_icon_; 185 SkBitmap default_icon_;
121 186
122 // The browser action shelf. 187 // The browser action shelf.
123 BrowserActionsContainer* panel_; 188 BrowserActionView::Delegate* delegate_;
124 189
125 // The context menu. This member is non-NULL only when the menu is shown. 190 // The context menu. This member is non-NULL only when the menu is shown.
126 views::MenuItemView* context_menu_; 191 views::MenuItemView* context_menu_;
127 192
128 content::NotificationRegistrar registrar_; 193 content::NotificationRegistrar registrar_;
129 194
130 // The extension keybinding accelerator this browser action is listening for 195 // The extension key binding accelerator this browser action is listening for
131 // (to show the popup). 196 // (to show the popup).
132 scoped_ptr<ui::Accelerator> keybinding_; 197 scoped_ptr<ui::Accelerator> keybinding_;
133 198
199 // True if tooltip was disabled.
200 bool disable_tooltip_;
201
134 friend class base::DeleteHelper<BrowserActionButton>; 202 friend class base::DeleteHelper<BrowserActionButton>;
135 203
136 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); 204 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton);
137 }; 205 };
138 206
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_ 207 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698