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
{
34 class ExtensionMessageBubbleFactory
;
41 // The Browser Window's toolbar.
42 class ToolbarView
: public views::AccessiblePaneView
,
43 public views::MenuButtonListener
,
44 public ui::AcceleratorProvider
,
45 public LocationBarView::Delegate
,
46 public content::NotificationObserver
,
47 public CommandObserver
,
48 public views::ButtonListener
,
49 public views::WidgetObserver
,
50 public views::ViewTargeterDelegate
,
51 public WrenchMenuBadgeController::Delegate
{
53 // The view class name.
54 static const char kViewClassName
[];
56 explicit ToolbarView(Browser
* browser
);
57 ~ToolbarView() override
;
59 // Create the contents of the Browser Toolbar.
62 // Forces the toolbar (and transitively the location bar) to update its
63 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
64 // and should restore any previous location bar state (such as user editing)
66 void Update(content::WebContents
* tab
);
68 // Clears the current state for |tab|.
69 void ResetTabState(content::WebContents
* tab
);
71 // Set focus to the toolbar with complete keyboard access, with the
72 // focus initially set to the app menu. Focus will be restored
73 // to the last focused view if the user escapes.
74 void SetPaneFocusAndFocusAppMenu();
76 // Returns true if the app menu is focused.
77 bool IsAppMenuFocused();
79 // Add a listener to receive a callback when the menu opens.
80 void AddMenuListener(views::MenuListener
* listener
);
82 // Remove a menu listener.
83 void RemoveMenuListener(views::MenuListener
* listener
);
85 virtual bool GetAcceleratorInfo(int id
, ui::Accelerator
* accel
);
87 // Returns the view to which the bookmark bubble should be anchored.
88 views::View
* GetBookmarkBubbleAnchor();
90 // Returns the view to which the Translate bubble should be anchored.
91 views::View
* GetTranslateBubbleAnchor();
93 // Executes |command| registered by |extension|.
94 void ExecuteExtensionCommand(const extensions::Extension
* extension
,
95 const extensions::Command
& command
);
97 // Shows the app (wrench) menu. |for_drop| indicates whether the menu is
98 // opened for a drag-and-drop operation.
99 void ShowAppMenu(bool for_drop
);
102 Browser
* browser() const { return browser_
; }
103 BrowserActionsContainer
* browser_actions() const { return browser_actions_
; }
104 ReloadButton
* reload_button() const { return reload_
; }
105 LocationBarView
* location_bar() const { return location_bar_
; }
106 WrenchToolbarButton
* app_menu() const { return app_menu_
; }
107 HomeButton
* home_button() const { return home_
; }
109 // AccessiblePaneView:
110 bool SetPaneFocus(View
* initial_focus
) override
;
111 void GetAccessibleState(ui::AXViewState
* state
) override
;
113 // views::MenuButtonListener:
114 void OnMenuButtonClicked(views::View
* source
,
115 const gfx::Point
& point
) override
;
117 // LocationBarView::Delegate:
118 content::WebContents
* GetWebContents() override
;
119 ToolbarModel
* GetToolbarModel() override
;
120 const ToolbarModel
* GetToolbarModel() const override
;
121 InstantController
* GetInstant() override
;
122 views::Widget
* CreateViewsBubble(
123 views::BubbleDelegateView
* bubble_delegate
) override
;
124 PageActionImageView
* CreatePageActionImageView(
125 LocationBarView
* owner
,
126 ExtensionAction
* action
) override
;
127 ContentSettingBubbleModelDelegate
* GetContentSettingBubbleModelDelegate()
129 void ShowWebsiteSettings(content::WebContents
* web_contents
,
131 const content::SSLStatus
& ssl
) override
;
134 void EnabledStateChangedForCommand(int id
, bool enabled
) override
;
136 // views::ButtonListener:
137 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
139 // views::WidgetObserver:
140 void OnWidgetVisibilityChanged(views::Widget
* widget
, bool visible
) override
;
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
;
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;
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.
179 // AccessiblePaneView:
180 bool SetPaneFocusAndFocusDefault() override
;
181 void RemovePaneFocus() override
;
184 // Types of display mode this toolbar can have.
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.
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;
226 ToolbarButton
* forward_
;
227 ReloadButton
* reload_
;
229 LocationBarView
* location_bar_
;
230 BrowserActionsContainer
* browser_actions_
;
231 WrenchToolbarButton
* app_menu_
;
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 // The factory to create bubbles to warn about dangerous/suspicious
250 scoped_ptr
<extensions::ExtensionMessageBubbleFactory
>
251 extension_message_bubble_factory_
;
253 // A list of listeners to call when the menu opens.
254 ObserverList
<views::MenuListener
> menu_listeners_
;
256 content::NotificationRegistrar registrar_
;
258 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView
);
261 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_