browser_frame.h revision 010d83a9304c5a91596085d917d248abff47903a
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
6#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
7
8#include "base/compiler_specific.h"
9#include "base/logging.h"
10#include "base/prefs/pref_member.h"
11#include "build/build_config.h"
12#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
13#include "ui/views/context_menu_controller.h"
14#include "ui/views/widget/widget.h"
15
16class AvatarMenuButton;
17class BrowserRootView;
18class BrowserView;
19class NativeBrowserFrame;
20class NewAvatarButton;
21class NonClientFrameView;
22class SystemMenuModelBuilder;
23
24namespace gfx {
25class FontList;
26class Rect;
27}
28
29namespace ui {
30class EventHandler;
31class MenuModel;
32class ThemeProvider;
33}
34
35namespace views {
36class MenuRunner;
37class View;
38}
39
40// This is a virtual interface that allows system specific browser frames.
41class BrowserFrame
42    : public views::Widget,
43      public views::ContextMenuController {
44 public:
45  explicit BrowserFrame(BrowserView* browser_view);
46  virtual ~BrowserFrame();
47
48  static const gfx::FontList& GetTitleFontList();
49
50  // Initialize the frame (creates the underlying native window).
51  void InitBrowserFrame();
52
53  // Sets the ThemeProvider returned from GetThemeProvider().
54  void SetThemeProvider(scoped_ptr<ui::ThemeProvider> provider);
55
56  // Determine the distance of the left edge of the minimize button from the
57  // left edge of the window. Used in our Non-Client View's Layout.
58  int GetMinimizeButtonOffset() const;
59
60  // Retrieves the bounds, in non-client view coordinates for the specified
61  // TabStrip view.
62  gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const;
63
64  // Returns the inset of the topmost view in the client view from the top of
65  // the non-client view. The topmost view depends on the window type. The
66  // topmost view is the tab strip for tabbed browser windows, the toolbar for
67  // popups, the web contents for app windows and varies for fullscreen windows
68  int GetTopInset() const;
69
70  // Returns the amount that the theme background should be inset.
71  int GetThemeBackgroundXInset() const;
72
73  // Tells the frame to update the throbber.
74  void UpdateThrobber(bool running);
75
76  // Returns the NonClientFrameView of this frame.
77  views::View* GetFrameView() const;
78
79  // Returns |true| if we should use the custom frame.
80  bool UseCustomFrame() const;
81
82  // Returns true when the window placement should be saved.
83  bool ShouldSaveWindowPlacement() const;
84
85  // Retrieves the window placement (show state and bounds) for restoring.
86  void GetWindowPlacement(gfx::Rect* bounds,
87                          ui::WindowShowState* show_state) const;
88
89  // Overridden from views::Widget:
90  virtual views::internal::RootView* CreateRootView() OVERRIDE;
91  virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
92  virtual bool GetAccelerator(int command_id,
93                              ui::Accelerator* accelerator) OVERRIDE;
94  virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE;
95  virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
96  virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE;
97
98  // Overridden from views::ContextMenuController:
99  virtual void ShowContextMenuForView(views::View* source,
100                                      const gfx::Point& p,
101                                      ui::MenuSourceType source_type) OVERRIDE;
102
103  // Returns true if we should leave any offset at the frame caption. Typically
104  // when the frame is maximized/full screen we want to leave no offset at the
105  // top.
106  bool ShouldLeaveOffsetNearTopBorder();
107
108  AvatarMenuButton* GetAvatarMenuButton();
109
110  NewAvatarButton* GetNewAvatarMenuButton();
111
112  // Returns the menu model. BrowserFrame owns the returned model.
113  // Note that in multi user mode this will upon each call create a new model.
114  ui::MenuModel* GetSystemMenuModel();
115
116 private:
117  // Called when the preference changes.
118  void OnUseCustomChromeFrameChanged();
119
120  NativeBrowserFrame* native_browser_frame_;
121
122  // A weak reference to the root view associated with the window. We save a
123  // copy as a BrowserRootView to avoid evil casting later, when we need to call
124  // functions that only exist on BrowserRootView (versus RootView).
125  BrowserRootView* root_view_;
126
127  // A pointer to our NonClientFrameView as a BrowserNonClientFrameView.
128  BrowserNonClientFrameView* browser_frame_view_;
129
130  // The BrowserView is our ClientView. This is a pointer to it.
131  BrowserView* browser_view_;
132
133  scoped_ptr<SystemMenuModelBuilder> menu_model_builder_;
134
135  // Used to show the system menu. Only used if
136  // NativeBrowserFrame::UsesNativeSystemMenu() returns false.
137  scoped_ptr<views::MenuRunner> menu_runner_;
138
139  // SetThemeProvider() triggers setting both |owned_theme_provider_| and
140  // |theme_provider_|. Initially |theme_provider_| is set to the ThemeService
141  // and |owned_theme_provider_| is NULL (as ThemeServices lifetime is managed
142  // externally).
143  scoped_ptr<ui::ThemeProvider> owned_theme_provider_;
144  ui::ThemeProvider* theme_provider_;
145
146  // Whether the custom Chrome frame preference is set.
147  BooleanPrefMember use_custom_frame_pref_;
148
149  scoped_ptr<ui::EventHandler> browser_command_handler_;
150
151  DISALLOW_COPY_AND_ASSIGN(BrowserFrame);
152};
153
154#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
155