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

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

Issue 675893002: Revert of Rename BrowserActionView to ToolbarActionView (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_
7
8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "ui/views/controls/button/menu_button.h"
12 #include "ui/views/controls/button/menu_button_listener.h"
13 #include "ui/views/drag_controller.h"
14 #include "ui/views/view.h"
15
16 class Browser;
17 class ExtensionAction;
18
19 namespace extensions {
20 class Extension;
21 }
22
23 namespace gfx {
24 class Image;
25 }
26
27 ////////////////////////////////////////////////////////////////////////////////
28 // ToolbarActionView
29 // A wrapper around a ToolbarActionViewController to display a toolbar action
30 // action in the BrowserActionsContainer.
31 class ToolbarActionView : public views::MenuButton,
32 public ToolbarActionViewDelegate,
33 public views::ButtonListener,
34 public content::NotificationObserver {
35 public:
36 // Need DragController here because ToolbarActionView could be
37 // dragged/dropped.
38 class Delegate : public views::DragController {
39 public:
40 // Returns the current web contents.
41 virtual content::WebContents* GetCurrentWebContents() = 0;
42
43 // Whether the container for this button is shown inside a menu.
44 virtual bool ShownInsideMenu() const = 0;
45
46 // Notifies that a drag completed.
47 virtual void OnToolbarActionViewDragDone() = 0;
48
49 // Returns the view of the toolbar actions overflow menu to use as a
50 // reference point for a popup when this view isn't visible.
51 virtual views::MenuButton* GetOverflowReferenceView() = 0;
52
53 // Sets the delegate's active popup owner to be |popup_owner|.
54 virtual void SetPopupOwner(ToolbarActionView* popup_owner) = 0;
55
56 // Hides the active popup of the delegate, if one exists.
57 virtual void HideActivePopup() = 0;
58
59 // Returns the primary ToolbarActionView associated with the given
60 // |extension|.
61 virtual ToolbarActionView* GetMainViewForAction(
62 ToolbarActionView* view) = 0;
63
64 protected:
65 virtual ~Delegate() {}
66 };
67
68 ToolbarActionView(scoped_ptr<ToolbarActionViewController> view_controller,
69 Browser* browser,
70 Delegate* delegate);
71 virtual ~ToolbarActionView();
72
73 // Called to update the display to match the toolbar action's state.
74 void UpdateState();
75
76 // Overridden from views::View:
77 virtual void GetAccessibleState(ui::AXViewState* state) override;
78
79 // Overridden from views::ButtonListener:
80 virtual void ButtonPressed(views::Button* sender,
81 const ui::Event& event) override;
82
83 // Overridden from content::NotificationObserver:
84 virtual void Observe(int type,
85 const content::NotificationSource& source,
86 const content::NotificationDetails& details) override;
87
88 // MenuButton behavior overrides. These methods all default to LabelButton
89 // behavior unless this button is a popup. In that case, it uses MenuButton
90 // behavior. MenuButton has the notion of a child popup being shown where the
91 // button will stay in the pushed state until the "menu" (a popup in this
92 // case) is dismissed.
93 virtual bool Activate() override;
94 virtual bool OnMousePressed(const ui::MouseEvent& event) override;
95 virtual void OnMouseReleased(const ui::MouseEvent& event) override;
96 virtual void OnMouseExited(const ui::MouseEvent& event) override;
97 virtual bool OnKeyReleased(const ui::KeyEvent& event) override;
98 virtual void OnGestureEvent(ui::GestureEvent* event) override;
99 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const
100 override;
101
102 // ToolbarActionViewDelegate: (public because called by others).
103 virtual content::WebContents* GetCurrentWebContents() const override;
104
105 ToolbarActionViewController* view_controller() {
106 return view_controller_.get();
107 }
108 Browser* browser() { return browser_; }
109
110 // Returns button icon so it can be accessed during tests.
111 gfx::ImageSkia GetIconForTest();
112
113 private:
114 // Overridden from views::View:
115 virtual void ViewHierarchyChanged(
116 const ViewHierarchyChangedDetails& details) override;
117 virtual void OnDragDone() override;
118 virtual gfx::Size GetPreferredSize() const override;
119 virtual void PaintChildren(gfx::Canvas* canvas,
120 const views::CullSet& cull_set) override;
121
122 // ToolbarActionViewDelegate:
123 virtual views::View* GetAsView() override;
124 virtual bool IsShownInMenu() override;
125 virtual views::FocusManager* GetFocusManagerForAccelerator() override;
126 virtual views::Widget* GetParentForContextMenu() override;
127 virtual ToolbarActionViewController* GetPreferredPopupViewController()
128 override;
129 virtual views::View* GetReferenceViewForPopup() override;
130 virtual views::MenuButton* GetContextMenuButton() override;
131 virtual void HideActivePopup() override;
132 virtual void OnIconUpdated() override;
133 virtual void OnPopupShown(bool grant_tab_permissions) override;
134 virtual void CleanupPopup() override;
135
136 // A lock to keep the MenuButton pressed when a menu or popup is visible.
137 // This needs to be destroyed after |view_controller_|, because
138 // |view_controller_|'s destructor can call CleanupPopup(), which uses this
139 // object.
140 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_;
141
142 // The controller for this toolbar action view.
143 scoped_ptr<ToolbarActionViewController> view_controller_;
144
145 // The associated browser.
146 Browser* browser_;
147
148 // Delegate that usually represents a container for ToolbarActionView.
149 Delegate* delegate_;
150
151 // Used to make sure we only register the command once.
152 bool called_register_command_;
153
154 content::NotificationRegistrar registrar_;
155
156 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView);
157 };
158
159 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698