MacViews: Use Mac's "Constrained Window Button" style for Button::STYLE_BUTTON LabelB...
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / toolbar_view.h
blob76c8942a45b160637b31b2b1839d31218a6fbebf
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/observer_list.h"
10 #include "base/prefs/pref_member.h"
11 #include "chrome/browser/command_observer.h"
12 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
13 #include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "ui/base/accelerators/accelerator.h"
16 #include "ui/views/accessible_pane_view.h"
17 #include "ui/views/controls/button/menu_button.h"
18 #include "ui/views/controls/button/menu_button_listener.h"
19 #include "ui/views/view.h"
21 class BackButton;
22 class BrowserActionsContainer;
23 class Browser;
24 class HomeButton;
25 class ReloadButton;
26 class ToolbarButton;
27 class WrenchMenu;
28 class WrenchMenuModel;
29 class WrenchToolbarButton;
31 namespace extensions {
32 class Command;
33 class Extension;
36 namespace views {
37 class MenuListener;
40 // The Browser Window's toolbar.
41 class ToolbarView : public views::AccessiblePaneView,
42 public views::MenuButtonListener,
43 public ui::AcceleratorProvider,
44 public LocationBarView::Delegate,
45 public content::NotificationObserver,
46 public CommandObserver,
47 public views::ButtonListener,
48 public views::WidgetObserver,
49 public views::ViewTargeterDelegate,
50 public WrenchMenuBadgeController::Delegate {
51 public:
52 // The view class name.
53 static const char kViewClassName[];
55 explicit ToolbarView(Browser* browser);
56 ~ToolbarView() override;
58 // Create the contents of the Browser Toolbar.
59 void Init();
61 // Forces the toolbar (and transitively the location bar) to update its
62 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
63 // and should restore any previous location bar state (such as user editing)
64 // as well.
65 void Update(content::WebContents* tab);
67 // Clears the current state for |tab|.
68 void ResetTabState(content::WebContents* tab);
70 // Set focus to the toolbar with complete keyboard access, with the
71 // focus initially set to the app menu. Focus will be restored
72 // to the last focused view if the user escapes.
73 void SetPaneFocusAndFocusAppMenu();
75 // Returns true if the app menu is focused.
76 bool IsAppMenuFocused();
78 // Add a listener to receive a callback when the menu opens.
79 void AddMenuListener(views::MenuListener* listener);
81 // Remove a menu listener.
82 void RemoveMenuListener(views::MenuListener* listener);
84 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
86 // Returns the view to which the bookmark bubble should be anchored.
87 views::View* GetBookmarkBubbleAnchor();
89 // Returns the view to which the Translate bubble should be anchored.
90 views::View* GetTranslateBubbleAnchor();
92 // Executes |command| registered by |extension|.
93 void ExecuteExtensionCommand(const extensions::Extension* extension,
94 const extensions::Command& command);
96 // Shows the app (wrench) menu. |for_drop| indicates whether the menu is
97 // opened for a drag-and-drop operation.
98 void ShowAppMenu(bool for_drop);
100 // Closes the App Menu, if it's open.
101 void CloseAppMenu();
103 // Accessors.
104 Browser* browser() const { return browser_; }
105 BrowserActionsContainer* browser_actions() const { return browser_actions_; }
106 ReloadButton* reload_button() const { return reload_; }
107 LocationBarView* location_bar() const { return location_bar_; }
108 WrenchToolbarButton* app_menu() const { return app_menu_; }
109 HomeButton* home_button() const { return home_; }
111 // AccessiblePaneView:
112 bool SetPaneFocus(View* initial_focus) override;
113 void GetAccessibleState(ui::AXViewState* state) override;
115 // views::MenuButtonListener:
116 void OnMenuButtonClicked(views::View* source,
117 const gfx::Point& point) override;
119 // LocationBarView::Delegate:
120 content::WebContents* GetWebContents() override;
121 ToolbarModel* GetToolbarModel() override;
122 const ToolbarModel* GetToolbarModel() const override;
123 views::Widget* CreateViewsBubble(
124 views::BubbleDelegateView* bubble_delegate) override;
125 PageActionImageView* CreatePageActionImageView(
126 LocationBarView* owner,
127 ExtensionAction* action) override;
128 ContentSettingBubbleModelDelegate* GetContentSettingBubbleModelDelegate()
129 override;
130 void ShowWebsiteSettings(content::WebContents* web_contents,
131 const GURL& url,
132 const content::SSLStatus& ssl) override;
134 // CommandObserver:
135 void EnabledStateChangedForCommand(int id, bool enabled) override;
137 // views::ButtonListener:
138 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
140 // views::WidgetObserver:
141 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
143 // content::NotificationObserver:
144 void Observe(int type,
145 const content::NotificationSource& source,
146 const content::NotificationDetails& details) override;
148 // ui::AcceleratorProvider:
149 bool GetAcceleratorForCommandId(int command_id,
150 ui::Accelerator* accelerator) override;
152 // views::View:
153 gfx::Size GetPreferredSize() const override;
154 gfx::Size GetMinimumSize() const override;
155 void Layout() override;
156 void OnPaint(gfx::Canvas* canvas) override;
157 void OnThemeChanged() override;
158 const char* GetClassName() const override;
159 bool AcceleratorPressed(const ui::Accelerator& acc) override;
161 // Whether the wrench/hotdogs menu is currently showing.
162 bool IsWrenchMenuShowing() const;
164 // Whether the toolbar view needs its background painted by the
165 // BrowserNonClientFrameView.
166 bool ShouldPaintBackground() const;
168 enum {
169 // The apparent horizontal space between most items, and the vertical
170 // padding above and below them.
171 kStandardSpacing = 3,
173 // The top of the toolbar has an edge we have to skip over in addition to
174 // the standard spacing.
175 kVertSpacing = 5,
178 protected:
179 // AccessiblePaneView:
180 bool SetPaneFocusAndFocusDefault() override;
181 void RemovePaneFocus() override;
183 private:
184 // Types of display mode this toolbar can have.
185 enum DisplayMode {
186 DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc.
187 DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location
188 // bar, used for popups.
191 // views::ViewTargeterDelegate:
192 bool DoesIntersectRect(const views::View* target,
193 const gfx::Rect& rect) const override;
195 // WrenchMenuBadgeController::Delegate:
196 void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
197 WrenchIconPainter::Severity severity,
198 bool animate) override;
200 // Returns the number of pixels above the location bar in non-normal display.
201 int PopupTopSpacing() const;
203 // Given toolbar contents of size |size|, returns the total toolbar size.
204 gfx::Size SizeForContentSize(gfx::Size size) const;
206 // Loads the images for all the child views.
207 void LoadImages();
209 bool is_display_mode_normal() const {
210 return display_mode_ == DISPLAYMODE_NORMAL;
213 // Shows the critical notification bubble against the wrench menu.
214 void ShowCriticalNotification();
216 // Shows the outdated install notification bubble against the wrench menu.
217 // |auto_update_enabled| is set to true when auto-upate is on.
218 void ShowOutdatedInstallNotification(bool auto_update_enabled);
220 void OnShowHomeButtonChanged();
222 int content_shadow_height() const;
224 // Controls
225 BackButton* back_;
226 ToolbarButton* forward_;
227 ReloadButton* reload_;
228 HomeButton* home_;
229 LocationBarView* location_bar_;
230 BrowserActionsContainer* browser_actions_;
231 WrenchToolbarButton* app_menu_;
232 Browser* browser_;
234 WrenchMenuBadgeController badge_controller_;
236 // Controls whether or not a home button should be shown on the toolbar.
237 BooleanPrefMember show_home_button_;
239 // The display mode used when laying out the toolbar.
240 DisplayMode display_mode_;
242 // Wrench model and menu.
243 // Note that the menu should be destroyed before the model it uses, so the
244 // menu should be listed later.
245 scoped_ptr<WrenchMenuModel> wrench_menu_model_;
246 scoped_ptr<WrenchMenu> wrench_menu_;
248 // A list of listeners to call when the menu opens.
249 base::ObserverList<views::MenuListener> menu_listeners_;
251 content::NotificationRegistrar registrar_;
253 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
256 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_