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/wm/window_state.h"
8 #include "ash/wm/window_state_delegate.h"
9 #include "ash/wm/window_util.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/views/frame/browser_shutdown.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_observer.h"
17 #include "ui/views/view.h"
23 // BrowserWindowStateDelegate class handles a user's fullscreen
24 // request (Shift+F4/F4).
25 class BrowserWindowStateDelegate : public ash::wm::WindowStateDelegate {
27 explicit BrowserWindowStateDelegate(Browser* browser)
31 virtual ~BrowserWindowStateDelegate(){}
33 // Overridden from ash::wm::WindowStateDelegate.
34 virtual 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())
39 chrome::ToggleFullscreenMode(browser_);
43 Browser* browser_; // not owned.
45 DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate);
50 ///////////////////////////////////////////////////////////////////////////////
51 // BrowserFrameAsh, public:
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 if (browser->is_type_tabbed()) {
74 // Animating to immersive fullscreen does not look good. Immersive
75 // fullscreen is the default fullscreen type on ChromeOS for tabbed browser
76 // windows. The WindowState constructor disables animating to fullscreen
77 // completely when switches::UseImmersiveFullscreenForAllWindows() returns
79 window_state->set_animate_to_fullscreen(false);
82 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys
83 // like brightness, volume, etc. Otherwise these keys are handled by the
84 // Ash window manager.
85 window_state->set_can_consume_system_keys(browser->is_app());
86 #endif // defined(OS_CHROMEOS)
89 ///////////////////////////////////////////////////////////////////////////////
90 // BrowserFrameAsh, views::NativeWidgetAura overrides:
92 void BrowserFrameAsh::OnWindowDestroying() {
93 // Destroy any remaining WebContents early on. Doing so may result in
94 // calling back to one of the Views/LayoutManagers or supporting classes of
95 // BrowserView. By destroying here we ensure all said classes are valid.
96 DestroyBrowserWebContents(browser_view_->browser());
97 NativeWidgetAura::OnWindowDestroying();
100 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool visible) {
102 // Once the window has been shown we know the requested bounds
103 // (if provided) have been honored and we can switch on window management.
104 SetWindowAutoManaged();
106 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible);
109 ////////////////////////////////////////////////////////////////////////////////
110 // BrowserFrameAsh, NativeBrowserFrame implementation:
112 views::NativeWidget* BrowserFrameAsh::AsNativeWidget() {
116 const views::NativeWidget* BrowserFrameAsh::AsNativeWidget() const {
120 bool BrowserFrameAsh::UsesNativeSystemMenu() const {
124 int BrowserFrameAsh::GetMinimizeButtonOffset() const {
128 BrowserFrameAsh::~BrowserFrameAsh() {
131 ///////////////////////////////////////////////////////////////////////////////
132 // BrowserFrameAsh, private:
134 void BrowserFrameAsh::SetWindowAutoManaged() {
135 if (browser_view_->browser()->type() != Browser::TYPE_POPUP ||
136 browser_view_->browser()->is_app()) {
137 ash::wm::GetWindowState(GetNativeWindow())->
138 set_window_position_managed(true);