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 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host.h"
9 #include "chrome/browser/ui/views/frame/browser_shutdown.h"
10 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/aura/window_observer.h"
17 #include "ui/base/hit_test.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/models/simple_menu_model.h"
20 #include "ui/gfx/font.h"
21 #include "ui/views/view.h"
22 #include "ui/wm/core/visibility_controller.h"
26 ///////////////////////////////////////////////////////////////////////////////
27 // DesktopBrowserFrameAura, public:
29 DesktopBrowserFrameAura::DesktopBrowserFrameAura(
30 BrowserFrame
* browser_frame
,
31 BrowserView
* browser_view
)
32 : views::DesktopNativeWidgetAura(browser_frame
),
33 browser_view_(browser_view
),
34 browser_frame_(browser_frame
),
35 browser_desktop_window_tree_host_(NULL
) {
36 GetNativeWindow()->SetName("BrowserFrameAura");
39 ///////////////////////////////////////////////////////////////////////////////
40 // DesktopBrowserFrameAura, protected:
42 DesktopBrowserFrameAura::~DesktopBrowserFrameAura() {
45 ///////////////////////////////////////////////////////////////////////////////
46 // DesktopBrowserFrameAura, views::DesktopNativeWidgetAura overrides:
48 void DesktopBrowserFrameAura::OnHostClosed() {
49 // Destroy any remaining WebContents early on. Doing so may result in
50 // calling back to one of the Views/LayoutManagers or supporting classes of
51 // BrowserView. By destroying here we ensure all said classes are valid.
52 DestroyBrowserWebContents(browser_view_
->browser());
53 aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(), NULL
);
54 DesktopNativeWidgetAura::OnHostClosed();
57 void DesktopBrowserFrameAura::InitNativeWidget(
58 const views::Widget::InitParams
& params
) {
59 browser_desktop_window_tree_host_
=
60 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost(
65 views::Widget::InitParams modified_params
= params
;
66 modified_params
.desktop_window_tree_host
=
67 browser_desktop_window_tree_host_
->AsDesktopWindowTreeHost();
68 DesktopNativeWidgetAura::InitNativeWidget(modified_params
);
70 visibility_controller_
.reset(new wm::VisibilityController
);
71 aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(),
72 visibility_controller_
.get());
73 wm::SetChildWindowVisibilityChangesAnimated(
74 GetNativeView()->GetRootWindow());
77 ////////////////////////////////////////////////////////////////////////////////
78 // DesktopBrowserFrameAura, NativeBrowserFrame implementation:
80 views::NativeWidget
* DesktopBrowserFrameAura::AsNativeWidget() {
84 const views::NativeWidget
* DesktopBrowserFrameAura::AsNativeWidget() const {
88 bool DesktopBrowserFrameAura::UsesNativeSystemMenu() const {
89 return browser_desktop_window_tree_host_
->UsesNativeSystemMenu();
92 int DesktopBrowserFrameAura::GetMinimizeButtonOffset() const {
93 return browser_desktop_window_tree_host_
->GetMinimizeButtonOffset();
96 bool DesktopBrowserFrameAura::ShouldSaveWindowPlacement() const {
97 // The placement can always be stored.
101 void DesktopBrowserFrameAura::GetWindowPlacement(
103 ui::WindowShowState
* show_state
) const {
104 *bounds
= GetWidget()->GetRestoredBounds();
106 *show_state
= ui::SHOW_STATE_MAXIMIZED
;
107 else if (IsMinimized())
108 *show_state
= ui::SHOW_STATE_MINIMIZED
;
110 *show_state
= ui::SHOW_STATE_NORMAL
;