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_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/prefs/pref_member.h"
14 #include "chrome/browser/command_observer.h"
15 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
17 #include "ui/base/accelerators/accelerator.h"
18 #include "ui/views/accessible_pane_view.h"
19 #include "ui/views/controls/button/menu_button.h"
20 #include "ui/views/controls/button/menu_button_listener.h"
21 #include "ui/views/view.h"
24 class BrowserActionsContainer
;
29 class ToolbarOriginChipView
;
31 class WrenchMenuModel
;
32 class WrenchToolbarButton
;
38 // The Browser Window's toolbar.
39 class ToolbarView
: public views::AccessiblePaneView
,
40 public views::MenuButtonListener
,
41 public ui::AcceleratorProvider
,
42 public LocationBarView::Delegate
,
43 public content::NotificationObserver
,
44 public CommandObserver
,
45 public views::ButtonListener
,
46 public views::WidgetObserver
{
48 // The view class name.
49 static const char kViewClassName
[];
51 explicit ToolbarView(Browser
* browser
);
52 virtual ~ToolbarView();
54 // Create the contents of the Browser Toolbar.
57 // Forces the toolbar (and transitively the location bar) to update its
58 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
59 // and should restore any previous location bar state (such as user editing)
61 void Update(content::WebContents
* tab
);
63 // Set focus to the toolbar with complete keyboard access, with the
64 // focus initially set to the app menu. Focus will be restored
65 // to the last focused view if the user escapes.
66 void SetPaneFocusAndFocusAppMenu();
68 // Returns true if the app menu is focused.
69 bool IsAppMenuFocused();
71 // Add a listener to receive a callback when the menu opens.
72 void AddMenuListener(views::MenuListener
* listener
);
74 // Remove a menu listener.
75 void RemoveMenuListener(views::MenuListener
* listener
);
77 virtual bool GetAcceleratorInfo(int id
, ui::Accelerator
* accel
);
79 // Returns the view to which the bookmark bubble should be anchored.
80 views::View
* GetBookmarkBubbleAnchor();
82 // Returns the view to which the Translate bubble should be anchored.
83 views::View
* GetTranslateBubbleAnchor();
85 // Shows the extension's page action, if present.
86 void ShowPageActionPopup(const extensions::Extension
* extension
);
88 // Shows the extension's browser action, if present.
89 void ShowBrowserActionPopup(const extensions::Extension
* extension
);
92 Browser
* browser() const { return browser_
; }
93 BrowserActionsContainer
* browser_actions() const { return browser_actions_
; }
94 ReloadButton
* reload_button() const { return reload_
; }
95 LocationBarView
* location_bar() const { return location_bar_
; }
96 ToolbarOriginChipView
* origin_chip() const { return origin_chip_view_
; }
97 views::MenuButton
* app_menu() const;
99 // Overridden from AccessiblePaneView
100 virtual bool SetPaneFocus(View
* initial_focus
) OVERRIDE
;
101 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
103 // Overridden from views::MenuButtonListener:
104 virtual void OnMenuButtonClicked(views::View
* source
,
105 const gfx::Point
& point
) OVERRIDE
;
107 // Overridden from LocationBarView::Delegate:
108 virtual content::WebContents
* GetWebContents() OVERRIDE
;
109 virtual ToolbarModel
* GetToolbarModel() OVERRIDE
;
110 virtual const ToolbarModel
* GetToolbarModel() const OVERRIDE
;
111 virtual InstantController
* GetInstant() OVERRIDE
;
112 virtual views::Widget
* CreateViewsBubble(
113 views::BubbleDelegateView
* bubble_delegate
) OVERRIDE
;
114 virtual PageActionImageView
* CreatePageActionImageView(
115 LocationBarView
* owner
, ExtensionAction
* action
) OVERRIDE
;
116 virtual ContentSettingBubbleModelDelegate
*
117 GetContentSettingBubbleModelDelegate() OVERRIDE
;
118 virtual void ShowWebsiteSettings(content::WebContents
* web_contents
,
120 const content::SSLStatus
& ssl
) OVERRIDE
;
122 // Overridden from CommandObserver:
123 virtual void EnabledStateChangedForCommand(int id
, bool enabled
) OVERRIDE
;
125 // Overridden from views::ButtonListener:
126 virtual void ButtonPressed(views::Button
* sender
,
127 const ui::Event
& event
) OVERRIDE
;
129 // Overridden from views::WidgetObserver:
130 virtual void OnWidgetVisibilityChanged(views::Widget
* widget
,
131 bool visible
) OVERRIDE
;
133 // Overridden from content::NotificationObserver:
134 virtual void Observe(int type
,
135 const content::NotificationSource
& source
,
136 const content::NotificationDetails
& details
) OVERRIDE
;
138 // Overridden from ui::AcceleratorProvider:
139 virtual bool GetAcceleratorForCommandId(
140 int command_id
, ui::Accelerator
* accelerator
) OVERRIDE
;
142 // Overridden from views::View:
143 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
144 virtual void Layout() OVERRIDE
;
145 virtual bool HitTestRect(const gfx::Rect
& rect
) const OVERRIDE
;
146 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
147 virtual void OnThemeChanged() OVERRIDE
;
148 virtual const char* GetClassName() const OVERRIDE
;
149 virtual bool AcceleratorPressed(const ui::Accelerator
& acc
) OVERRIDE
;
151 // Whether the wrench/hotdogs menu is currently showing.
152 bool IsWrenchMenuShowing() const;
154 // Whether the toolbar view needs its background painted by the
155 // BrowserNonClientFrameView.
156 bool ShouldPaintBackground() const;
159 // The apparent horizontal space between most items, and the vertical
160 // padding above and below them.
161 kStandardSpacing
= 3,
163 // The top of the toolbar has an edge we have to skip over in addition to
164 // the standard spacing.
169 // Overridden from AccessiblePaneView
170 virtual bool SetPaneFocusAndFocusDefault() OVERRIDE
;
171 virtual void RemovePaneFocus() OVERRIDE
;
174 // Types of display mode this toolbar can have.
176 DISPLAYMODE_NORMAL
, // Normal toolbar with buttons, etc.
177 DISPLAYMODE_LOCATION
// Slimline toolbar showing only compact location
178 // bar, used for popups.
181 // Returns true if we should show the upgrade recommended dot.
182 bool ShouldShowUpgradeRecommended();
184 // Returns true if we should show the background page badge.
185 bool ShouldShowBackgroundPageBadge();
187 // Returns true if we should show the warning for incompatible software.
188 bool ShouldShowIncompatibilityWarning();
190 // Returns the number of pixels above the location bar in non-normal display.
191 int PopupTopSpacing() const;
193 // Loads the images for all the child views.
196 bool is_display_mode_normal() const {
197 return display_mode_
== DISPLAYMODE_NORMAL
;
200 // Shows the critical notification bubble against the wrench menu.
201 void ShowCriticalNotification();
203 // Shows the outdated install notification bubble against the wrench menu.
204 void ShowOutdatedInstallNotification();
206 // Updates the badge and the accessible name of the app menu (Wrench).
207 void UpdateAppMenuState();
209 // Updates the severity level on the wrench menu button.
210 void UpdateWrenchButtonSeverity();
212 void OnShowHomeButtonChanged();
214 int content_shadow_height() const;
218 ToolbarButton
* forward_
;
219 ReloadButton
* reload_
;
221 LocationBarView
* location_bar_
;
222 ToolbarOriginChipView
* origin_chip_view_
;
223 BrowserActionsContainer
* browser_actions_
;
224 WrenchToolbarButton
* app_menu_
;
227 // Controls whether or not a home button should be shown on the toolbar.
228 BooleanPrefMember show_home_button_
;
230 // The display mode used when laying out the toolbar.
231 DisplayMode display_mode_
;
233 // Wrench model and menu.
234 // Note that the menu should be destroyed before the model it uses, so the
235 // menu should be listed later.
236 scoped_ptr
<WrenchMenuModel
> wrench_menu_model_
;
237 scoped_ptr
<WrenchMenu
> wrench_menu_
;
239 // A list of listeners to call when the menu opens.
240 ObserverList
<views::MenuListener
> menu_listeners_
;
242 content::NotificationRegistrar registrar_
;
244 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView
);
247 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_