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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_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, 1 month 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_TOOLBAR_ACTION_VIEW_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_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 // ToolbarActionView 28 // ToolbarActionView
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 class ToolbarActionView : public views::MenuButton, 31 class ToolbarActionView : public views::MenuButton,
32 public ToolbarActionViewDelegate, 32 public ToolbarActionViewDelegateViews,
33 public views::ButtonListener, 33 public views::ButtonListener,
34 public content::NotificationObserver { 34 public content::NotificationObserver {
35 public: 35 public:
36 // Need DragController here because ToolbarActionView could be 36 // Need DragController here because ToolbarActionView could be
37 // dragged/dropped. 37 // dragged/dropped.
38 class Delegate : public views::DragController { 38 class Delegate : public views::DragController {
39 public: 39 public:
40 // Returns the current web contents. 40 // Returns the current web contents.
41 virtual content::WebContents* GetCurrentWebContents() = 0; 41 virtual content::WebContents* GetCurrentWebContents() = 0;
42 42
(...skipping 20 matching lines...) Expand all
63 63
64 protected: 64 protected:
65 ~Delegate() override {} 65 ~Delegate() override {}
66 }; 66 };
67 67
68 ToolbarActionView(scoped_ptr<ToolbarActionViewController> view_controller, 68 ToolbarActionView(scoped_ptr<ToolbarActionViewController> view_controller,
69 Browser* browser, 69 Browser* browser,
70 Delegate* delegate); 70 Delegate* delegate);
71 ~ToolbarActionView() override; 71 ~ToolbarActionView() override;
72 72
73 // Called to update the display to match the toolbar action's state.
74 void UpdateState();
75
76 // Overridden from views::View: 73 // Overridden from views::View:
77 void GetAccessibleState(ui::AXViewState* state) override; 74 void GetAccessibleState(ui::AXViewState* state) override;
78 75
79 // Overridden from views::ButtonListener: 76 // Overridden from views::ButtonListener:
80 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 77 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
81 78
82 // Overridden from content::NotificationObserver: 79 // Overridden from content::NotificationObserver:
83 void Observe(int type, 80 void Observe(int type,
84 const content::NotificationSource& source, 81 const content::NotificationSource& source,
85 const content::NotificationDetails& details) override; 82 const content::NotificationDetails& details) override;
86 83
87 // MenuButton behavior overrides. These methods all default to LabelButton 84 // MenuButton behavior overrides. These methods all default to LabelButton
88 // behavior unless this button is a popup. In that case, it uses MenuButton 85 // behavior unless this button is a popup. In that case, it uses MenuButton
89 // behavior. MenuButton has the notion of a child popup being shown where the 86 // behavior. MenuButton has the notion of a child popup being shown where the
90 // button will stay in the pushed state until the "menu" (a popup in this 87 // button will stay in the pushed state until the "menu" (a popup in this
91 // case) is dismissed. 88 // case) is dismissed.
92 bool Activate() override; 89 bool Activate() override;
93 bool OnMousePressed(const ui::MouseEvent& event) override; 90 bool OnMousePressed(const ui::MouseEvent& event) override;
94 void OnMouseReleased(const ui::MouseEvent& event) override; 91 void OnMouseReleased(const ui::MouseEvent& event) override;
95 void OnMouseExited(const ui::MouseEvent& event) override; 92 void OnMouseExited(const ui::MouseEvent& event) override;
96 bool OnKeyReleased(const ui::KeyEvent& event) override; 93 bool OnKeyReleased(const ui::KeyEvent& event) override;
97 void OnGestureEvent(ui::GestureEvent* event) override; 94 void OnGestureEvent(ui::GestureEvent* event) override;
98 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; 95 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override;
99 96
100 // ToolbarActionViewDelegate: (public because called by others). 97 // ToolbarActionViewDelegate: (public because called by others).
98 void UpdateState() override;
101 content::WebContents* GetCurrentWebContents() const override; 99 content::WebContents* GetCurrentWebContents() const override;
102 100
103 ToolbarActionViewController* view_controller() { 101 ToolbarActionViewController* view_controller() {
104 return view_controller_.get(); 102 return view_controller_.get();
105 } 103 }
106 Browser* browser() { return browser_; } 104 Browser* browser() { return browser_; }
107 105
108 // Returns button icon so it can be accessed during tests. 106 // Returns button icon so it can be accessed during tests.
109 gfx::ImageSkia GetIconForTest(); 107 gfx::ImageSkia GetIconForTest();
110 108
111 private: 109 private:
112 // Overridden from views::View: 110 // Overridden from views::View:
113 void ViewHierarchyChanged( 111 void ViewHierarchyChanged(
114 const ViewHierarchyChangedDetails& details) override; 112 const ViewHierarchyChangedDetails& details) override;
115 void OnDragDone() override; 113 void OnDragDone() override;
116 gfx::Size GetPreferredSize() const override; 114 gfx::Size GetPreferredSize() const override;
117 void PaintChildren(gfx::Canvas* canvas, 115 void PaintChildren(gfx::Canvas* canvas,
118 const views::CullSet& cull_set) override; 116 const views::CullSet& cull_set) override;
119 117
120 // ToolbarActionViewDelegate: 118 // ToolbarActionViewDelegateViews:
121 views::View* GetAsView() override; 119 views::View* GetAsView() override;
122 bool IsShownInMenu() override; 120 bool IsShownInMenu() override;
123 views::FocusManager* GetFocusManagerForAccelerator() override; 121 views::FocusManager* GetFocusManagerForAccelerator() override;
124 views::Widget* GetParentForContextMenu() override; 122 views::Widget* GetParentForContextMenu() override;
125 ToolbarActionViewController* GetPreferredPopupViewController() override; 123 ToolbarActionViewController* GetPreferredPopupViewController() override;
126 views::View* GetReferenceViewForPopup() override; 124 views::View* GetReferenceViewForPopup() override;
127 views::MenuButton* GetContextMenuButton() override; 125 views::MenuButton* GetContextMenuButton() override;
128 void HideActivePopup() override; 126 void HideActivePopup() override;
129 void OnIconUpdated() override;
130 void OnPopupShown(bool grant_tab_permissions) override; 127 void OnPopupShown(bool grant_tab_permissions) override;
131 void CleanupPopup() override; 128 void CleanupPopup() override;
132 129
133 // A lock to keep the MenuButton pressed when a menu or popup is visible. 130 // A lock to keep the MenuButton pressed when a menu or popup is visible.
134 // This needs to be destroyed after |view_controller_|, because 131 // This needs to be destroyed after |view_controller_|, because
135 // |view_controller_|'s destructor can call CleanupPopup(), which uses this 132 // |view_controller_|'s destructor can call CleanupPopup(), which uses this
136 // object. 133 // object.
137 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; 134 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_;
138 135
139 // The controller for this toolbar action view. 136 // The controller for this toolbar action view.
140 scoped_ptr<ToolbarActionViewController> view_controller_; 137 scoped_ptr<ToolbarActionViewController> view_controller_;
141 138
142 // The associated browser. 139 // The associated browser.
143 Browser* browser_; 140 Browser* browser_;
144 141
145 // Delegate that usually represents a container for ToolbarActionView. 142 // Delegate that usually represents a container for ToolbarActionView.
146 Delegate* delegate_; 143 Delegate* delegate_;
147 144
148 // Used to make sure we only register the command once. 145 // Used to make sure we only register the command once.
149 bool called_register_command_; 146 bool called_register_command_;
150 147
151 content::NotificationRegistrar registrar_; 148 content::NotificationRegistrar registrar_;
152 149
153 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); 150 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView);
154 }; 151 };
155 152
156 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ 153 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698