1 // Copyright (c) 2012 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_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_VIEW_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/api/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 "chrome/browser/ui/views/reload_button.h"
18 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/animation/slide_animation.h"
20 #include "ui/views/accessible_pane_view.h"
21 #include "ui/views/controls/button/menu_button.h"
22 #include "ui/views/controls/button/menu_button_listener.h"
23 #include "ui/views/view.h"
25 class BrowserActionsContainer
;
28 class WrenchMenuModel
;
34 // The Browser Window's toolbar.
35 class ToolbarView
: public views::AccessiblePaneView
,
36 public views::MenuButtonListener
,
37 public ui::AcceleratorProvider
,
38 public LocationBarView::Delegate
,
39 public content::NotificationObserver
,
40 public CommandObserver
,
41 public views::ButtonListener
,
42 public views::WidgetObserver
{
44 // The view class name.
45 static const char kViewClassName
[];
47 explicit ToolbarView(Browser
* browser
);
48 virtual ~ToolbarView();
50 // Create the contents of the Browser Toolbar.
53 // Updates the toolbar (and transitively the location bar) with the states of
54 // the specified |tab|. If |should_restore_state| is true, we're switching
55 // (back?) to this tab and should restore any previous location bar state
56 // (such as user editing) as well.
57 void Update(content::WebContents
* tab
, bool should_restore_state
);
59 // Set focus to the toolbar with complete keyboard access, with the
60 // focus initially set to the app menu. Focus will be restored
61 // to the last focused view if the user escapes.
62 void SetPaneFocusAndFocusAppMenu();
64 // Returns true if the app menu is focused.
65 bool IsAppMenuFocused();
67 // Add a listener to receive a callback when the menu opens.
68 void AddMenuListener(views::MenuListener
* listener
);
70 // Remove a menu listener.
71 void RemoveMenuListener(views::MenuListener
* listener
);
73 // Gets an image with the icon for the app menu and any overlaid notification
75 gfx::ImageSkia
GetAppMenuIcon(views::CustomButton::ButtonState state
);
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();
83 Browser
* browser() const { return browser_
; }
84 BrowserActionsContainer
* browser_actions() const { return browser_actions_
; }
85 ReloadButton
* reload_button() const { return reload_
; }
86 LocationBarView
* location_bar() const { return location_bar_
; }
87 views::MenuButton
* app_menu() const { return app_menu_
; }
89 // Overridden from AccessiblePaneView
90 virtual bool SetPaneFocus(View
* initial_focus
) OVERRIDE
;
91 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
93 // Overridden from views::MenuButtonListener:
94 virtual void OnMenuButtonClicked(views::View
* source
,
95 const gfx::Point
& point
) OVERRIDE
;
97 // Overridden from LocationBarView::Delegate:
98 virtual TabContents
* GetTabContents() const OVERRIDE
;
99 virtual InstantController
* GetInstant() OVERRIDE
;
100 virtual views::Widget
* CreateViewsBubble(
101 views::BubbleDelegateView
* bubble_delegate
) OVERRIDE
;
102 virtual PageActionImageView
* CreatePageActionImageView(
103 LocationBarView
* owner
, ExtensionAction
* action
) OVERRIDE
;
104 virtual ContentSettingBubbleModelDelegate
*
105 GetContentSettingBubbleModelDelegate() OVERRIDE
;
106 virtual void ShowPageInfo(content::WebContents
* web_contents
,
108 const content::SSLStatus
& ssl
,
109 bool show_history
) OVERRIDE
;
110 virtual void OnInputInProgress(bool in_progress
) OVERRIDE
;
112 // Overridden from CommandObserver:
113 virtual void EnabledStateChangedForCommand(int id
, bool enabled
) OVERRIDE
;
115 // Overridden from views::ButtonListener:
116 virtual void ButtonPressed(views::Button
* sender
,
117 const ui::Event
& event
) OVERRIDE
;
119 // Overridden from views::WidgetObserver:
120 virtual void OnWidgetVisibilityChanged(views::Widget
* widget
,
121 bool visible
) OVERRIDE
;
123 // Overridden from content::NotificationObserver:
124 virtual void Observe(int type
,
125 const content::NotificationSource
& source
,
126 const content::NotificationDetails
& details
) OVERRIDE
;
128 // Overridden from ui::AcceleratorProvider:
129 virtual bool GetAcceleratorForCommandId(
130 int command_id
, ui::Accelerator
* accelerator
) OVERRIDE
;
132 // Overridden from views::View:
133 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
134 virtual void Layout() OVERRIDE
;
135 virtual bool HitTestRect(const gfx::Rect
& rect
) const OVERRIDE
;
136 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
137 virtual bool GetDropFormats(
139 std::set
<OSExchangeData::CustomFormat
>* custom_formats
) OVERRIDE
;
140 virtual bool CanDrop(const ui::OSExchangeData
& data
) OVERRIDE
;
141 virtual int OnDragUpdated(const ui::DropTargetEvent
& event
) OVERRIDE
;
142 virtual int OnPerformDrop(const ui::DropTargetEvent
& event
) OVERRIDE
;
143 virtual void OnThemeChanged() OVERRIDE
;
144 virtual std::string
GetClassName() const OVERRIDE
;
145 virtual bool AcceleratorPressed(const ui::Accelerator
& acc
) OVERRIDE
;
147 // Whether the wrench/hotdogs menu is currently showing.
148 bool IsWrenchMenuShowing() const;
150 // The apparent horizontal space between most items, and the vertical padding
151 // above and below them.
152 static const int kStandardSpacing
;
153 // The top of the toolbar has an edge we have to skip over in addition to the
155 static const int kVertSpacing
;
158 // Overridden from AccessiblePaneView
159 virtual bool SetPaneFocusAndFocusDefault() OVERRIDE
;
160 virtual void RemovePaneFocus() OVERRIDE
;
163 // Types of display mode this toolbar can have.
165 DISPLAYMODE_NORMAL
, // Normal toolbar with buttons, etc.
166 DISPLAYMODE_LOCATION
// Slimline toolbar showing only compact location
167 // bar, used for popups.
170 // Returns true if we should show the upgrade recommended dot.
171 bool ShouldShowUpgradeRecommended();
173 // Returns true if we should show the background page badge.
174 bool ShouldShowBackgroundPageBadge();
176 // Returns true if we should show the warning for incompatible software.
177 bool ShouldShowIncompatibilityWarning();
179 // Returns the number of pixels above the location bar in non-normal display.
180 int PopupTopSpacing() const;
182 // Loads the images for all the child views.
185 bool is_display_mode_normal() const {
186 return display_mode_
== DISPLAYMODE_NORMAL
;
189 // Shows the critical notification bubble against the wrench menu.
190 void ShowCriticalNotification();
192 // Updates the badge and the accessible name of the app menu (Wrench).
193 void UpdateAppMenuState();
195 // Gets a badge for the wrench icon corresponding to the number of
196 // unacknowledged background pages in the system.
197 gfx::ImageSkia
GetBackgroundPageBadge();
199 // The model that contains the security level, text, icon to display...
200 ToolbarModel
* model_
;
203 views::ImageButton
* back_
;
204 views::ImageButton
* forward_
;
205 ReloadButton
* reload_
;
206 views::ImageButton
* home_
;
207 LocationBarView
* location_bar_
;
208 BrowserActionsContainer
* browser_actions_
;
209 views::MenuButton
* app_menu_
;
212 // Contents of the profiles menu to populate with profile names.
213 scoped_ptr
<ui::SimpleMenuModel
> profiles_menu_contents_
;
215 // Controls whether or not a home button should be shown on the toolbar.
216 BooleanPrefMember show_home_button_
;
218 // A pref that counts how often the bubble has been shown.
219 IntegerPrefMember sideload_wipeout_bubble_shown_
;
221 // The display mode used when laying out the toolbar.
222 DisplayMode display_mode_
;
225 scoped_ptr
<WrenchMenu
> wrench_menu_
;
226 scoped_ptr
<WrenchMenuModel
> wrench_menu_model_
;
228 // A list of listeners to call when the menu opens.
229 ObserverList
<views::MenuListener
> menu_listeners_
;
231 content::NotificationRegistrar registrar_
;
233 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView
);
236 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_VIEW_H_