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

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

Issue 661493004: Add infrastructure for Chrome Actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_TOOLBAR_BROWSER_ACTION_VIEW_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
7 7
8 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h"
9 #include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h"
10 #include "content/public/browser/notification_observer.h" 9 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h" 10 #include "content/public/browser/notification_registrar.h"
12 #include "ui/views/controls/button/menu_button.h" 11 #include "ui/views/controls/button/menu_button.h"
13 #include "ui/views/controls/button/menu_button_listener.h" 12 #include "ui/views/controls/button/menu_button_listener.h"
14 #include "ui/views/drag_controller.h" 13 #include "ui/views/drag_controller.h"
15 #include "ui/views/view.h" 14 #include "ui/views/view.h"
16 15
17 class Browser; 16 class Browser;
18 class ExtensionAction; 17 class ExtensionAction;
19 18
20 namespace extensions { 19 namespace extensions {
21 class Extension; 20 class Extension;
22 } 21 }
23 22
24 namespace gfx { 23 namespace gfx {
25 class Image; 24 class Image;
26 } 25 }
27 26
28 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
29 // BrowserActionView 28 // BrowserActionView
30 // A wrapper around an ExtensionActionViewController to display an extension 29 // A wrapper around a ToolbarActionViewController to display a toolbar action
31 // action in the BrowserActionsContainer. 30 // action in the BrowserActionsContainer.
32 // Despite its name, this class can handle either Browser Actions or Page 31 // Despite its name, this class can handle any type of toolbar action, including
33 // Actions. 32 // extension actions (browser and page actions) and component actions.
34 // TODO(devlin): Rename this and BrowserActionsContainer when more of the 33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the
35 // toolbar redesign is done. 34 // toolbar redesign is done.
36 class BrowserActionView : public views::MenuButton, 35 class BrowserActionView : public views::MenuButton,
37 public ExtensionActionViewDelegate, 36 public ToolbarActionViewDelegate,
38 public views::ButtonListener, 37 public views::ButtonListener,
39 public content::NotificationObserver { 38 public content::NotificationObserver {
40 public: 39 public:
41 // Need DragController here because BrowserActionView could be 40 // Need DragController here because BrowserActionView could be
42 // dragged/dropped. 41 // dragged/dropped.
43 class Delegate : public views::DragController { 42 class Delegate : public views::DragController {
44 public: 43 public:
45 // Returns the current web contents. 44 // Returns the current web contents.
46 virtual content::WebContents* GetCurrentWebContents() = 0; 45 virtual content::WebContents* GetCurrentWebContents() = 0;
47 46
(...skipping 11 matching lines...) Expand all
59 virtual views::MenuButton* GetOverflowReferenceView() = 0; 58 virtual views::MenuButton* GetOverflowReferenceView() = 0;
60 59
61 // Sets the delegate's active popup owner to be |popup_owner|. 60 // Sets the delegate's active popup owner to be |popup_owner|.
62 virtual void SetPopupOwner(BrowserActionView* popup_owner) = 0; 61 virtual void SetPopupOwner(BrowserActionView* popup_owner) = 0;
63 62
64 // Hides the active popup of the delegate, if one exists. 63 // Hides the active popup of the delegate, if one exists.
65 virtual void HideActivePopup() = 0; 64 virtual void HideActivePopup() = 0;
66 65
67 // Returns the primary BrowserActionView associated with the given 66 // Returns the primary BrowserActionView associated with the given
68 // |extension|. 67 // |extension|.
69 virtual BrowserActionView* GetMainViewForExtension( 68 virtual BrowserActionView* GetMainViewForAction(
70 const extensions::Extension* extension) = 0; 69 BrowserActionView* view) = 0;
71 70
72 protected: 71 protected:
73 virtual ~Delegate() {} 72 virtual ~Delegate() {}
74 }; 73 };
75 74
76 // The IconObserver will receive a notification when the button's icon has 75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller,
77 // been updated.
78 class IconObserver {
79 public:
80 virtual void OnIconUpdated(const gfx::ImageSkia& icon) = 0;
81
82 protected:
83 virtual ~IconObserver() {}
84 };
85
86 BrowserActionView(const extensions::Extension* extension,
87 ExtensionAction* extension_action,
88 Browser* browser, 76 Browser* browser,
89 BrowserActionView::Delegate* delegate); 77 Delegate* delegate);
90 virtual ~BrowserActionView(); 78 virtual ~BrowserActionView();
91 79
92 const extensions::Extension* extension() const {
93 return view_controller_->extension();
94 }
95 ExtensionAction* extension_action() {
96 return view_controller_->extension_action();
97 }
98 ExtensionActionViewController* view_controller() {
99 return view_controller_.get();
100 }
101 void set_icon_observer(IconObserver* icon_observer) {
102 icon_observer_ = icon_observer;
103 }
104
105 // Called to update the display to match the browser action's state. 80 // Called to update the display to match the browser action's state.
106 void UpdateState(); 81 void UpdateState();
107 82
108 // Does this button's action have a popup?
109 bool IsPopup();
110
111 // Overridden from views::View: 83 // Overridden from views::View:
112 virtual void GetAccessibleState(ui::AXViewState* state) override; 84 virtual void GetAccessibleState(ui::AXViewState* state) override;
113 85
114 // Overridden from views::ButtonListener: 86 // Overridden from views::ButtonListener:
115 virtual void ButtonPressed(views::Button* sender, 87 virtual void ButtonPressed(views::Button* sender,
116 const ui::Event& event) override; 88 const ui::Event& event) override;
117 89
118 // Overridden from content::NotificationObserver: 90 // Overridden from content::NotificationObserver:
119 virtual void Observe(int type, 91 virtual void Observe(int type,
120 const content::NotificationSource& source, 92 const content::NotificationSource& source,
121 const content::NotificationDetails& details) override; 93 const content::NotificationDetails& details) override;
122 94
123 // MenuButton behavior overrides. These methods all default to LabelButton 95 // MenuButton behavior overrides. These methods all default to LabelButton
124 // behavior unless this button is a popup. In that case, it uses MenuButton 96 // behavior unless this button is a popup. In that case, it uses MenuButton
125 // behavior. MenuButton has the notion of a child popup being shown where the 97 // behavior. MenuButton has the notion of a child popup being shown where the
126 // button will stay in the pushed state until the "menu" (a popup in this 98 // button will stay in the pushed state until the "menu" (a popup in this
127 // case) is dismissed. 99 // case) is dismissed.
128 virtual bool Activate() override; 100 virtual bool Activate() override;
129 virtual bool OnMousePressed(const ui::MouseEvent& event) override; 101 virtual bool OnMousePressed(const ui::MouseEvent& event) override;
130 virtual void OnMouseReleased(const ui::MouseEvent& event) override; 102 virtual void OnMouseReleased(const ui::MouseEvent& event) override;
131 virtual void OnMouseExited(const ui::MouseEvent& event) override; 103 virtual void OnMouseExited(const ui::MouseEvent& event) override;
132 virtual bool OnKeyReleased(const ui::KeyEvent& event) override; 104 virtual bool OnKeyReleased(const ui::KeyEvent& event) override;
133 virtual void OnGestureEvent(ui::GestureEvent* event) override; 105 virtual void OnGestureEvent(ui::GestureEvent* event) override;
134 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const 106 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const
135 override; 107 override;
136 108
137 // Whether the browser action is enabled on this tab. Note that we cannot use 109 // ToolbarActionViewDelegate: (public because called by others).
138 // the built-in views enabled/SetEnabled because disabled views do not 110 virtual content::WebContents* GetCurrentWebContents() const override;
139 // receive drag events.
140 bool IsEnabled(int tab_id) const;
141 111
142 // Gets the icon of this button and its badge. 112 ToolbarActionViewController* view_controller() {
143 gfx::ImageSkia GetIconWithBadge(); 113 return view_controller_.get();
114 }
115 Browser* browser() { return browser_; }
144 116
145 // Returns button icon so it can be accessed during tests. 117 // Returns button icon so it can be accessed during tests.
146 gfx::ImageSkia GetIconForTest(); 118 gfx::ImageSkia GetIconForTest();
147 119
148 private: 120 private:
149 // Overridden from views::View: 121 // Overridden from views::View:
150 virtual void ViewHierarchyChanged( 122 virtual void ViewHierarchyChanged(
151 const ViewHierarchyChangedDetails& details) override; 123 const ViewHierarchyChangedDetails& details) override;
152 virtual void OnDragDone() override; 124 virtual void OnDragDone() override;
153 virtual gfx::Size GetPreferredSize() const override; 125 virtual gfx::Size GetPreferredSize() const override;
154 virtual void PaintChildren(gfx::Canvas* canvas, 126 virtual void PaintChildren(gfx::Canvas* canvas,
155 const views::CullSet& cull_set) override; 127 const views::CullSet& cull_set) override;
156 128
157 // ExtensionActionViewDelegate: 129 // ToolbarActionViewDelegate:
158 virtual views::View* GetAsView() override; 130 virtual views::View* GetAsView() override;
159 virtual bool IsShownInMenu() override; 131 virtual bool IsShownInMenu() override;
160 virtual views::FocusManager* GetFocusManagerForAccelerator() override; 132 virtual views::FocusManager* GetFocusManagerForAccelerator() override;
161 virtual views::Widget* GetParentForContextMenu() override; 133 virtual views::Widget* GetParentForContextMenu() override;
162 virtual ExtensionActionViewController* GetPreferredPopupViewController() 134 virtual ToolbarActionViewController* GetPreferredPopupViewController()
163 override; 135 override;
164 virtual views::View* GetReferenceViewForPopup() override; 136 virtual views::View* GetReferenceViewForPopup() override;
165 virtual views::MenuButton* GetContextMenuButton() override; 137 virtual views::MenuButton* GetContextMenuButton() override;
166 virtual content::WebContents* GetCurrentWebContents() override;
167 virtual void HideActivePopup() override; 138 virtual void HideActivePopup() override;
168 virtual void OnIconUpdated() override; 139 virtual void OnIconUpdated() override;
169 virtual void OnPopupShown(bool grant_tab_permissions) override; 140 virtual void OnPopupShown(bool grant_tab_permissions) override;
170 virtual void CleanupPopup() override; 141 virtual void CleanupPopup() override;
171 142
172 // A lock to keep the MenuButton pressed when a menu or popup is visible. 143 // A lock to keep the MenuButton pressed when a menu or popup is visible.
173 // This needs to be destroyed after |view_controller_|, because 144 // This needs to be destroyed after |view_controller_|, because
174 // |view_controller_|'s destructor can call CleanupPopup(), which uses this 145 // |view_controller_|'s destructor can call CleanupPopup(), which uses this
175 // object. 146 // object.
176 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; 147 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_;
177 148
178 // The controller for this ExtensionAction view. 149 // The controller for this toolbar action view.
179 scoped_ptr<ExtensionActionViewController> view_controller_; 150 scoped_ptr<ToolbarActionViewController> view_controller_;
151
152 // The associated browser.
153 Browser* browser_;
180 154
181 // Delegate that usually represents a container for BrowserActionView. 155 // Delegate that usually represents a container for BrowserActionView.
182 BrowserActionView::Delegate* delegate_; 156 Delegate* delegate_;
183 157
184 // Used to make sure we only register the command once. 158 // Used to make sure we only register the command once.
185 bool called_registered_extension_command_; 159 bool called_register_command_;
186 160
187 content::NotificationRegistrar registrar_; 161 content::NotificationRegistrar registrar_;
188 162
189 // The observer that we need to notify when the icon of the button has been
190 // updated.
191 IconObserver* icon_observer_;
192
193 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); 163 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
194 }; 164 };
195 165
196 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ 166 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698