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

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

Issue 670463004: Make a platform-independent ToolbarActionViewController (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/toolbar/toolbar_action_view_delegate.h" 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h"
9 #include "content/public/browser/notification_observer.h" 9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h" 10 #include "content/public/browser/notification_registrar.h"
11 #include "ui/views/controls/button/menu_button.h" 11 #include "ui/views/controls/button/menu_button.h"
12 #include "ui/views/controls/button/menu_button_listener.h" 12 #include "ui/views/controls/button/menu_button_listener.h"
13 #include "ui/views/drag_controller.h" 13 #include "ui/views/drag_controller.h"
14 #include "ui/views/view.h" 14 #include "ui/views/view.h"
15 15
16 class Browser; 16 class Browser;
17 class ExtensionAction; 17 class ExtensionAction;
18 18
19 namespace extensions { 19 namespace extensions {
20 class Extension; 20 class Extension;
21 } 21 }
22 22
23 namespace gfx { 23 namespace gfx {
24 class Image; 24 class Image;
25 } 25 }
26 26
27 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
28 // BrowserActionView 28 // BrowserActionView
29 // A wrapper around a ToolbarActionViewController to display a toolbar action 29 // A wrapper around a ToolbarActionViewController to display a toolbar action
30 // action in the BrowserActionsContainer. 30 // action in the BrowserActionsContainer.
31 // Despite its name, this class can handle any type of toolbar action, including 31 // Despite its name, this class can handle any type of toolbar action, including
32 // extension actions (browser and page actions) and component actions. 32 // extension actions (browser and page actions) and component actions.
33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the 33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the
34 // toolbar redesign is done. 34 // toolbar redesign is done.
35 class BrowserActionView : public views::MenuButton, 35 class BrowserActionView : public views::MenuButton,
36 public ToolbarActionViewDelegate, 36 public ToolbarActionViewDelegateViews,
37 public views::ButtonListener, 37 public views::ButtonListener,
38 public content::NotificationObserver { 38 public content::NotificationObserver {
39 public: 39 public:
40 // Need DragController here because BrowserActionView could be 40 // Need DragController here because BrowserActionView could be
41 // dragged/dropped. 41 // dragged/dropped.
42 class Delegate : public views::DragController { 42 class Delegate : public views::DragController {
43 public: 43 public:
44 // Returns the current web contents. 44 // Returns the current web contents.
45 virtual content::WebContents* GetCurrentWebContents() = 0; 45 virtual content::WebContents* GetCurrentWebContents() = 0;
46 46
(...skipping 21 matching lines...) Expand all
68 virtual BrowserActionView* GetMainViewForAction( 68 virtual BrowserActionView* GetMainViewForAction(
69 BrowserActionView* view) = 0; 69 BrowserActionView* view) = 0;
70 70
71 protected: 71 protected:
72 virtual ~Delegate() {} 72 virtual ~Delegate() {}
73 }; 73 };
74 74
75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller, 75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller,
76 Browser* browser, 76 Browser* browser,
77 Delegate* delegate); 77 Delegate* delegate);
78 virtual ~BrowserActionView(); 78 ~BrowserActionView() override;
79
80 // Called to update the display to match the browser action's state.
81 void UpdateState();
82 79
83 // Overridden from views::View: 80 // Overridden from views::View:
84 virtual void GetAccessibleState(ui::AXViewState* state) override; 81 void GetAccessibleState(ui::AXViewState* state) override;
85 82
86 // Overridden from views::ButtonListener: 83 // Overridden from views::ButtonListener:
87 virtual void ButtonPressed(views::Button* sender, 84 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
88 const ui::Event& event) override;
89 85
90 // Overridden from content::NotificationObserver: 86 // Overridden from content::NotificationObserver:
91 virtual void Observe(int type, 87 void Observe(int type,
92 const content::NotificationSource& source, 88 const content::NotificationSource& source,
93 const content::NotificationDetails& details) override; 89 const content::NotificationDetails& details) override;
94 90
95 // MenuButton behavior overrides. These methods all default to LabelButton 91 // MenuButton behavior overrides. These methods all default to LabelButton
96 // behavior unless this button is a popup. In that case, it uses MenuButton 92 // behavior unless this button is a popup. In that case, it uses MenuButton
97 // behavior. MenuButton has the notion of a child popup being shown where the 93 // behavior. MenuButton has the notion of a child popup being shown where the
98 // button will stay in the pushed state until the "menu" (a popup in this 94 // button will stay in the pushed state until the "menu" (a popup in this
99 // case) is dismissed. 95 // case) is dismissed.
100 virtual bool Activate() override; 96 bool Activate() override;
101 virtual bool OnMousePressed(const ui::MouseEvent& event) override; 97 bool OnMousePressed(const ui::MouseEvent& event) override;
102 virtual void OnMouseReleased(const ui::MouseEvent& event) override; 98 void OnMouseReleased(const ui::MouseEvent& event) override;
103 virtual void OnMouseExited(const ui::MouseEvent& event) override; 99 void OnMouseExited(const ui::MouseEvent& event) override;
104 virtual bool OnKeyReleased(const ui::KeyEvent& event) override; 100 bool OnKeyReleased(const ui::KeyEvent& event) override;
105 virtual void OnGestureEvent(ui::GestureEvent* event) override; 101 void OnGestureEvent(ui::GestureEvent* event) override;
106 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const 102 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override;
107 override;
108 103
109 // ToolbarActionViewDelegate: (public because called by others). 104 // ToolbarActionViewDelegate: (public because called by others).
110 virtual content::WebContents* GetCurrentWebContents() const override; 105 void UpdateState() override;
106 content::WebContents* GetCurrentWebContents() const override;
111 107
112 ToolbarActionViewController* view_controller() { 108 ToolbarActionViewController* view_controller() {
113 return view_controller_.get(); 109 return view_controller_.get();
114 } 110 }
115 Browser* browser() { return browser_; } 111 Browser* browser() { return browser_; }
116 112
117 // Returns button icon so it can be accessed during tests. 113 // Returns button icon so it can be accessed during tests.
118 gfx::ImageSkia GetIconForTest(); 114 gfx::ImageSkia GetIconForTest();
119 115
120 private: 116 private:
121 // Overridden from views::View: 117 // Overridden from views::View:
122 virtual void ViewHierarchyChanged( 118 void ViewHierarchyChanged(const ViewHierarchyChangedDetails& details)
123 const ViewHierarchyChangedDetails& details) override; 119 override;
124 virtual void OnDragDone() override; 120 void OnDragDone() override;
125 virtual gfx::Size GetPreferredSize() const override; 121 gfx::Size GetPreferredSize() const override;
126 virtual void PaintChildren(gfx::Canvas* canvas, 122 void PaintChildren(gfx::Canvas* canvas,
127 const views::CullSet& cull_set) override; 123 const views::CullSet& cull_set) override;
128 124
129 // ToolbarActionViewDelegate: 125 // ToolbarActionViewDelegateViews:
130 virtual views::View* GetAsView() override; 126 views::View* GetAsView() override;
131 virtual bool IsShownInMenu() override; 127 bool IsShownInMenu() override;
132 virtual views::FocusManager* GetFocusManagerForAccelerator() override; 128 views::FocusManager* GetFocusManagerForAccelerator() override;
133 virtual views::Widget* GetParentForContextMenu() override; 129 views::Widget* GetParentForContextMenu() override;
134 virtual ToolbarActionViewController* GetPreferredPopupViewController() 130 ToolbarActionViewController* GetPreferredPopupViewController() override;
135 override; 131 views::View* GetReferenceViewForPopup() override;
136 virtual views::View* GetReferenceViewForPopup() override; 132 views::MenuButton* GetContextMenuButton() override;
137 virtual views::MenuButton* GetContextMenuButton() override; 133 void HideActivePopup() override;
138 virtual void HideActivePopup() override; 134 void OnPopupShown(bool grant_tab_permissions) override;
139 virtual void OnIconUpdated() override; 135 void CleanupPopup() override;
140 virtual void OnPopupShown(bool grant_tab_permissions) override;
141 virtual void CleanupPopup() override;
142 136
143 // A lock to keep the MenuButton pressed when a menu or popup is visible. 137 // A lock to keep the MenuButton pressed when a menu or popup is visible.
144 // This needs to be destroyed after |view_controller_|, because 138 // This needs to be destroyed after |view_controller_|, because
145 // |view_controller_|'s destructor can call CleanupPopup(), which uses this 139 // |view_controller_|'s destructor can call CleanupPopup(), which uses this
146 // object. 140 // object.
147 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; 141 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_;
148 142
149 // The controller for this toolbar action view. 143 // The controller for this toolbar action view.
150 scoped_ptr<ToolbarActionViewController> view_controller_; 144 scoped_ptr<ToolbarActionViewController> view_controller_;
151 145
152 // The associated browser. 146 // The associated browser.
153 Browser* browser_; 147 Browser* browser_;
154 148
155 // Delegate that usually represents a container for BrowserActionView. 149 // Delegate that usually represents a container for BrowserActionView.
156 Delegate* delegate_; 150 Delegate* delegate_;
157 151
158 // Used to make sure we only register the command once. 152 // Used to make sure we only register the command once.
159 bool called_register_command_; 153 bool called_register_command_;
160 154
161 content::NotificationRegistrar registrar_; 155 content::NotificationRegistrar registrar_;
162 156
163 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); 157 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
164 }; 158 };
165 159
166 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ 160 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698