toolbar_view.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
7
8#include <set>
9#include <string>
10
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"
22
23class BackButton;
24class BrowserActionsContainer;
25class Browser;
26class HomeButton;
27class ReloadButton;
28class SiteChipView;
29class ToolbarButton;
30class WrenchMenu;
31class WrenchMenuModel;
32class WrenchToolbarButton;
33
34namespace views {
35class MenuListener;
36}
37
38// The Browser Window's toolbar.
39class 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 {
47 public:
48  // The view class name.
49  static const char kViewClassName[];
50
51  explicit ToolbarView(Browser* browser);
52  virtual ~ToolbarView();
53
54  // Create the contents of the Browser Toolbar.
55  void Init();
56
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)
60  // as well.
61  void Update(content::WebContents* tab);
62
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();
67
68  // Returns true if the app menu is focused.
69  bool IsAppMenuFocused();
70
71  // Add a listener to receive a callback when the menu opens.
72  void AddMenuListener(views::MenuListener* listener);
73
74  // Remove a menu listener.
75  void RemoveMenuListener(views::MenuListener* listener);
76
77  virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
78
79  // Returns the view to which the bookmark bubble should be anchored.
80  views::View* GetBookmarkBubbleAnchor();
81
82  // Returns the view to which the Translate bubble should be anchored.
83  views::View* GetTranslateBubbleAnchor();
84
85  // Accessors...
86  Browser* browser() const { return browser_; }
87  BrowserActionsContainer* browser_actions() const { return browser_actions_; }
88  ReloadButton* reload_button() const { return reload_; }
89  LocationBarView* location_bar() const { return location_bar_; }
90  SiteChipView* site_chip() const { return site_chip_view_; }
91  views::MenuButton* app_menu() const;
92
93  // Overridden from AccessiblePaneView
94  virtual bool SetPaneFocus(View* initial_focus) OVERRIDE;
95  virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
96
97  // Overridden from views::MenuButtonListener:
98  virtual void OnMenuButtonClicked(views::View* source,
99                                   const gfx::Point& point) OVERRIDE;
100
101  // Overridden from LocationBarView::Delegate:
102  virtual content::WebContents* GetWebContents() OVERRIDE;
103  virtual ToolbarModel* GetToolbarModel() OVERRIDE;
104  virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
105  virtual InstantController* GetInstant() OVERRIDE;
106  virtual views::Widget* CreateViewsBubble(
107      views::BubbleDelegateView* bubble_delegate) OVERRIDE;
108  virtual PageActionImageView* CreatePageActionImageView(
109      LocationBarView* owner, ExtensionAction* action) OVERRIDE;
110  virtual ContentSettingBubbleModelDelegate*
111      GetContentSettingBubbleModelDelegate() OVERRIDE;
112  virtual void ShowWebsiteSettings(content::WebContents* web_contents,
113                                   const GURL& url,
114                                   const content::SSLStatus& ssl) OVERRIDE;
115
116  // Overridden from CommandObserver:
117  virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
118
119  // Overridden from views::ButtonListener:
120  virtual void ButtonPressed(views::Button* sender,
121                             const ui::Event& event) OVERRIDE;
122
123  // Overridden from views::WidgetObserver:
124  virtual void OnWidgetVisibilityChanged(views::Widget* widget,
125                                         bool visible) OVERRIDE;
126
127  // Overridden from content::NotificationObserver:
128  virtual void Observe(int type,
129                       const content::NotificationSource& source,
130                       const content::NotificationDetails& details) OVERRIDE;
131
132  // Overridden from ui::AcceleratorProvider:
133  virtual bool GetAcceleratorForCommandId(
134      int command_id, ui::Accelerator* accelerator) OVERRIDE;
135
136  // Overridden from views::View:
137  virtual gfx::Size GetPreferredSize() OVERRIDE;
138  virtual void Layout() OVERRIDE;
139  virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
140  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
141  virtual bool GetDropFormats(
142      int* formats,
143      std::set<OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
144  virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
145  virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
146  virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
147  virtual void OnThemeChanged() OVERRIDE;
148  virtual const char* GetClassName() const OVERRIDE;
149  virtual bool AcceleratorPressed(const ui::Accelerator& acc) OVERRIDE;
150
151  // Whether the wrench/hotdogs menu is currently showing.
152  bool IsWrenchMenuShowing() const;
153
154  // Whether the toolbar view needs its background painted by the
155  // BrowserNonClientFrameView.
156  bool ShouldPaintBackground() const;
157
158  enum {
159    // The apparent horizontal space between most items, and the vertical
160    // padding above and below them.
161    kStandardSpacing = 3,
162
163    // The top of the toolbar has an edge we have to skip over in addition to
164    // the standard spacing.
165    kVertSpacing = 5,
166  };
167
168 protected:
169  // Overridden from AccessiblePaneView
170  virtual bool SetPaneFocusAndFocusDefault() OVERRIDE;
171  virtual void RemovePaneFocus() OVERRIDE;
172
173 private:
174  // Types of display mode this toolbar can have.
175  enum DisplayMode {
176    DISPLAYMODE_NORMAL,       // Normal toolbar with buttons, etc.
177    DISPLAYMODE_LOCATION      // Slimline toolbar showing only compact location
178                              // bar, used for popups.
179  };
180
181  // Returns true if we should show the upgrade recommended dot.
182  bool ShouldShowUpgradeRecommended();
183
184  // Returns true if we should show the background page badge.
185  bool ShouldShowBackgroundPageBadge();
186
187  // Returns true if we should show the warning for incompatible software.
188  bool ShouldShowIncompatibilityWarning();
189
190  // Returns the number of pixels above the location bar in non-normal display.
191  int PopupTopSpacing() const;
192
193  // Loads the images for all the child views.
194  void LoadImages();
195
196  bool is_display_mode_normal() const {
197    return display_mode_ == DISPLAYMODE_NORMAL;
198  }
199
200  // Shows the critical notification bubble against the wrench menu.
201  void ShowCriticalNotification();
202
203  // Shows the outdated install notification bubble against the wrench menu.
204  void ShowOutdatedInstallNotification();
205
206  // Updates the badge and the accessible name of the app menu (Wrench).
207  void UpdateAppMenuState();
208
209  // Updates the severity level on the wrench menu button.
210  void UpdateWrenchButtonSeverity();
211
212  void OnShowHomeButtonChanged();
213
214  int content_shadow_height() const;
215
216  // Controls
217  BackButton* back_;
218  ToolbarButton* forward_;
219  ReloadButton* reload_;
220  HomeButton* home_;
221  LocationBarView* location_bar_;
222  SiteChipView* site_chip_view_;
223  BrowserActionsContainer* browser_actions_;
224  WrenchToolbarButton* app_menu_;
225  Browser* browser_;
226
227  // Controls whether or not a home button should be shown on the toolbar.
228  BooleanPrefMember show_home_button_;
229
230  // The display mode used when laying out the toolbar.
231  DisplayMode display_mode_;
232
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_;
238
239  // A list of listeners to call when the menu opens.
240  ObserverList<views::MenuListener> menu_listeners_;
241
242  content::NotificationRegistrar registrar_;
243
244  DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
245};
246
247#endif  // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
248