Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_frame_ash.cc
blobb48a51bc5e8f76a4c0a36e940c6c4e759c38d7a7
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.
5 #include "chrome/browser/ui/views/frame/browser_frame_ash.h"
7 #include "ash/shell.h"
8 #include "ash/wm/window_properties.h"
9 #include "ash/wm/window_state.h"
10 #include "ash/wm/window_state_delegate.h"
11 #include "ash/wm/window_util.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/views/frame/browser_shutdown.h"
15 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_observer.h"
19 #include "ui/views/view.h"
21 namespace {
23 // BrowserWindowStateDelegate class handles a user's fullscreen
24 // request (Shift+F4/F4).
25 class BrowserWindowStateDelegate : public ash::wm::WindowStateDelegate {
26 public:
27 explicit BrowserWindowStateDelegate(Browser* browser)
28 : browser_(browser) {
29 DCHECK(browser_);
31 ~BrowserWindowStateDelegate() override {}
33 // Overridden from ash::wm::WindowStateDelegate.
34 bool ToggleFullscreen(ash::wm::WindowState* window_state) override {
35 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize());
36 // Windows which cannot be maximized should not be fullscreened.
37 if (!window_state->IsFullscreen() && !window_state->CanMaximize())
38 return true;
39 chrome::ToggleFullscreenMode(browser_);
40 return true;
42 private:
43 Browser* browser_; // not owned.
45 DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate);
48 } // namespace
50 ///////////////////////////////////////////////////////////////////////////////
51 // BrowserFrameAsh, public:
53 // static
54 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh";
56 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame,
57 BrowserView* browser_view)
58 : views::NativeWidgetAura(browser_frame),
59 browser_view_(browser_view) {
60 GetNativeWindow()->SetName(kWindowName);
61 Browser* browser = browser_view->browser();
62 ash::wm::WindowState* window_state =
63 ash::wm::GetWindowState(GetNativeWindow());
64 window_state->SetDelegate(
65 scoped_ptr<ash::wm::WindowStateDelegate>(
66 new BrowserWindowStateDelegate(browser)).Pass());
68 // Turn on auto window management if we don't need an explicit bounds.
69 // This way the requested bounds are honored.
70 if (!browser->bounds_overridden() && !browser->is_session_restore())
71 SetWindowAutoManaged();
72 #if defined(OS_CHROMEOS)
73 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys
74 // like brightness, volume, etc. Otherwise these keys are handled by the
75 // Ash window manager.
76 window_state->set_can_consume_system_keys(browser->is_app());
77 #endif // defined(OS_CHROMEOS)
80 ///////////////////////////////////////////////////////////////////////////////
81 // BrowserFrameAsh, views::NativeWidgetAura overrides:
83 void BrowserFrameAsh::OnWindowDestroying(aura::Window* window) {
84 // Destroy any remaining WebContents early on. Doing so may result in
85 // calling back to one of the Views/LayoutManagers or supporting classes of
86 // BrowserView. By destroying here we ensure all said classes are valid.
87 DestroyBrowserWebContents(browser_view_->browser());
88 NativeWidgetAura::OnWindowDestroying(window);
91 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool visible) {
92 if (visible) {
93 // Once the window has been shown we know the requested bounds
94 // (if provided) have been honored and we can switch on window management.
95 SetWindowAutoManaged();
97 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible);
100 bool BrowserFrameAsh::ShouldSaveWindowPlacement() const {
101 return nullptr == GetWidget()->GetNativeWindow()->GetProperty(
102 ash::kRestoreBoundsOverrideKey);
105 void BrowserFrameAsh::GetWindowPlacement(
106 gfx::Rect* bounds,
107 ui::WindowShowState* show_state) const {
108 gfx::Rect* override_bounds = GetWidget()->GetNativeWindow()->GetProperty(
109 ash::kRestoreBoundsOverrideKey);
110 if (override_bounds && !override_bounds->IsEmpty()) {
111 *bounds = *override_bounds;
112 *show_state = GetWidget()->GetNativeWindow()->GetProperty(
113 ash::kRestoreShowStateOverrideKey);
114 } else {
115 *bounds = GetWidget()->GetRestoredBounds();
116 *show_state = GetWidget()->GetNativeWindow()->GetProperty(
117 aura::client::kShowStateKey);
120 if (*show_state != ui::SHOW_STATE_MAXIMIZED &&
121 *show_state != ui::SHOW_STATE_MINIMIZED) {
122 *show_state = ui::SHOW_STATE_NORMAL;
126 ////////////////////////////////////////////////////////////////////////////////
127 // BrowserFrameAsh, NativeBrowserFrame implementation:
129 views::Widget::InitParams BrowserFrameAsh::GetWidgetParams() {
130 views::Widget::InitParams params;
131 params.native_widget = this;
133 params.context = ash::Shell::GetPrimaryRootWindow();
134 #if defined(OS_WIN)
135 // If this window is under ASH on Windows, we need it to be translucent.
136 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
137 #endif
139 return params;
142 bool BrowserFrameAsh::UseCustomFrame() const {
143 return true;
146 bool BrowserFrameAsh::UsesNativeSystemMenu() const {
147 return false;
150 int BrowserFrameAsh::GetMinimizeButtonOffset() const {
151 return 0;
154 BrowserFrameAsh::~BrowserFrameAsh() {
157 ///////////////////////////////////////////////////////////////////////////////
158 // BrowserFrameAsh, private:
160 void BrowserFrameAsh::SetWindowAutoManaged() {
161 if (!browser_view_->browser()->is_type_popup() ||
162 browser_view_->browser()->is_app()) {
163 ash::wm::GetWindowState(GetNativeWindow())->
164 set_window_position_managed(true);