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"
22 class BrowserActionsContainer
;
28 class WrenchMenuModel
;
29 class WrenchToolbarButton
;
31 namespace extensions
{
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
{
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.
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)
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.
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_
; }
110 WrenchMenuBadgeController
* wrench_menu_badge_controller() {
111 return &badge_controller_
;
114 // AccessiblePaneView:
115 bool SetPaneFocus(View
* initial_focus
) override
;
116 void GetAccessibleState(ui::AXViewState
* state
) override
;
118 // views::MenuButtonListener:
119 void OnMenuButtonClicked(views::View
* source
,
120 const gfx::Point
& point
) override
;
122 // LocationBarView::Delegate:
123 content::WebContents
* GetWebContents() override
;
124 ToolbarModel
* GetToolbarModel() override
;
125 const ToolbarModel
* GetToolbarModel() const override
;
126 views::Widget
* CreateViewsBubble(
127 views::BubbleDelegateView
* bubble_delegate
) override
;
128 PageActionImageView
* CreatePageActionImageView(
129 LocationBarView
* owner
,
130 ExtensionAction
* action
) override
;
131 ContentSettingBubbleModelDelegate
* GetContentSettingBubbleModelDelegate()
133 void ShowWebsiteSettings(
134 content::WebContents
* web_contents
,
136 const SecurityStateModel::SecurityInfo
& security_info
) override
;
139 void EnabledStateChangedForCommand(int id
, bool enabled
) override
;
141 // views::ButtonListener:
142 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
144 // views::WidgetObserver:
145 void OnWidgetActivationChanged(views::Widget
* widget
, bool active
) override
;
147 // content::NotificationObserver:
148 void Observe(int type
,
149 const content::NotificationSource
& source
,
150 const content::NotificationDetails
& details
) override
;
152 // ui::AcceleratorProvider:
153 bool GetAcceleratorForCommandId(int command_id
,
154 ui::Accelerator
* accelerator
) override
;
157 gfx::Size
GetPreferredSize() const override
;
158 gfx::Size
GetMinimumSize() const override
;
159 void Layout() override
;
160 void OnPaint(gfx::Canvas
* canvas
) override
;
161 void OnThemeChanged() override
;
162 const char* GetClassName() const override
;
163 bool AcceleratorPressed(const ui::Accelerator
& acc
) override
;
165 // Whether the wrench/hotdogs menu is currently showing.
166 bool IsWrenchMenuShowing() const;
168 // Whether the toolbar view needs its background painted by the
169 // BrowserNonClientFrameView.
170 bool ShouldPaintBackground() const;
173 // The apparent horizontal space between most items, and the vertical
174 // padding above and below them.
175 kStandardSpacing
= 3,
177 // The top of the toolbar has an edge we have to skip over in addition to
178 // the standard spacing.
182 WrenchMenu
* wrench_menu_for_testing() { return wrench_menu_
.get(); }
185 // AccessiblePaneView:
186 bool SetPaneFocusAndFocusDefault() override
;
187 void RemovePaneFocus() override
;
190 // Types of display mode this toolbar can have.
192 DISPLAYMODE_NORMAL
, // Normal toolbar with buttons, etc.
193 DISPLAYMODE_LOCATION
// Slimline toolbar showing only compact location
194 // bar, used for popups.
197 // views::ViewTargeterDelegate:
198 bool DoesIntersectRect(const views::View
* target
,
199 const gfx::Rect
& rect
) const override
;
201 // WrenchMenuBadgeController::Delegate:
202 void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type
,
203 WrenchIconPainter::Severity severity
,
204 bool animate
) override
;
206 // Returns the number of pixels above the location bar in non-normal display.
207 int PopupTopSpacing() const;
209 // Given toolbar contents of size |size|, returns the total toolbar size.
210 gfx::Size
SizeForContentSize(gfx::Size size
) const;
212 // Loads the images for all the child views.
215 bool is_display_mode_normal() const {
216 return display_mode_
== DISPLAYMODE_NORMAL
;
219 // Shows the critical notification bubble against the wrench menu.
220 void ShowCriticalNotification();
222 // Shows the outdated install notification bubble against the wrench menu.
223 // |auto_update_enabled| is set to true when auto-upate is on.
224 void ShowOutdatedInstallNotification(bool auto_update_enabled
);
226 void OnShowHomeButtonChanged();
228 int content_shadow_height() const;
232 ToolbarButton
* forward_
;
233 ReloadButton
* reload_
;
235 LocationBarView
* location_bar_
;
236 BrowserActionsContainer
* browser_actions_
;
237 WrenchToolbarButton
* app_menu_
;
240 WrenchMenuBadgeController badge_controller_
;
242 // Controls whether or not a home button should be shown on the toolbar.
243 BooleanPrefMember show_home_button_
;
245 // The display mode used when laying out the toolbar.
246 DisplayMode display_mode_
;
248 // Wrench model and menu.
249 // Note that the menu should be destroyed before the model it uses, so the
250 // menu should be listed later.
251 scoped_ptr
<WrenchMenuModel
> wrench_menu_model_
;
252 scoped_ptr
<WrenchMenu
> wrench_menu_
;
254 // A list of listeners to call when the menu opens.
255 base::ObserverList
<views::MenuListener
> menu_listeners_
;
257 content::NotificationRegistrar registrar_
;
259 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView
);
262 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_