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