Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / desktop_browser_frame_aura.cc
blob47ca5c4a2b033b92b7801ef57ebcd76818f79298
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 "chrome/browser/web_applications/web_app.h"
12 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/aura/window_observer.h"
16 #include "ui/base/hit_test.h"
17 #include "ui/base/models/simple_menu_model.h"
18 #include "ui/gfx/font.h"
19 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h"
21 #include "ui/wm/core/visibility_controller.h"
23 using aura::Window;
25 ///////////////////////////////////////////////////////////////////////////////
26 // DesktopBrowserFrameAura, public:
28 DesktopBrowserFrameAura::DesktopBrowserFrameAura(
29 BrowserFrame* browser_frame,
30 BrowserView* browser_view)
31 : views::DesktopNativeWidgetAura(browser_frame),
32 browser_view_(browser_view),
33 browser_frame_(browser_frame),
34 browser_desktop_window_tree_host_(nullptr) {
35 GetNativeWindow()->SetName("BrowserFrameAura");
38 ///////////////////////////////////////////////////////////////////////////////
39 // DesktopBrowserFrameAura, protected:
41 DesktopBrowserFrameAura::~DesktopBrowserFrameAura() {
44 ///////////////////////////////////////////////////////////////////////////////
45 // DesktopBrowserFrameAura, views::DesktopNativeWidgetAura overrides:
47 void DesktopBrowserFrameAura::OnHostClosed() {
48 // Destroy any remaining WebContents early on. Doing so may result in
49 // calling back to one of the Views/LayoutManagers or supporting classes of
50 // BrowserView. By destroying here we ensure all said classes are valid.
51 DestroyBrowserWebContents(browser_view_->browser());
52 aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(), nullptr);
53 DesktopNativeWidgetAura::OnHostClosed();
56 void DesktopBrowserFrameAura::InitNativeWidget(
57 const views::Widget::InitParams& params) {
58 browser_desktop_window_tree_host_ =
59 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost(
60 browser_frame_,
61 this,
62 browser_view_,
63 browser_frame_);
64 views::Widget::InitParams modified_params = params;
65 modified_params.desktop_window_tree_host =
66 browser_desktop_window_tree_host_->AsDesktopWindowTreeHost();
67 DesktopNativeWidgetAura::InitNativeWidget(modified_params);
69 visibility_controller_.reset(new wm::VisibilityController);
70 aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(),
71 visibility_controller_.get());
72 wm::SetChildWindowVisibilityChangesAnimated(
73 GetNativeView()->GetRootWindow());
76 ////////////////////////////////////////////////////////////////////////////////
77 // DesktopBrowserFrameAura, NativeBrowserFrame implementation:
79 views::Widget::InitParams DesktopBrowserFrameAura::GetWidgetParams() {
80 views::Widget::InitParams params;
81 params.native_widget = this;
82 return params;
85 bool DesktopBrowserFrameAura::UseCustomFrame() const {
86 return true;
89 bool DesktopBrowserFrameAura::UsesNativeSystemMenu() const {
90 return browser_desktop_window_tree_host_->UsesNativeSystemMenu();
93 int DesktopBrowserFrameAura::GetMinimizeButtonOffset() const {
94 return browser_desktop_window_tree_host_->GetMinimizeButtonOffset();
97 bool DesktopBrowserFrameAura::ShouldSaveWindowPlacement() const {
98 // The placement can always be stored.
99 return true;
102 void DesktopBrowserFrameAura::GetWindowPlacement(
103 gfx::Rect* bounds,
104 ui::WindowShowState* show_state) const {
105 *bounds = GetWidget()->GetRestoredBounds();
106 if (IsMaximized())
107 *show_state = ui::SHOW_STATE_MAXIMIZED;
108 else if (IsMinimized())
109 *show_state = ui::SHOW_STATE_MINIMIZED;
110 else
111 *show_state = ui::SHOW_STATE_NORMAL;