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_view.h"
13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_observer.h"
16 #include "ui/views/view.h"
22 // BrowserWindowStateDelegate class handles a user's fullscreen
23 // request (Shift+F4/F4).
24 class BrowserWindowStateDelegate
: public ash::wm::WindowStateDelegate
{
26 explicit BrowserWindowStateDelegate(Browser
* browser
)
30 virtual ~BrowserWindowStateDelegate(){}
32 // Overridden from ash::wm::WindowStateDelegate.
33 virtual bool ToggleFullscreen(ash::wm::WindowState
* window_state
) OVERRIDE
{
34 DCHECK(window_state
->IsFullscreen() || window_state
->CanMaximize());
35 // Windows which cannot be maximized should not be fullscreened.
36 if (!window_state
->IsFullscreen() && !window_state
->CanMaximize())
38 chrome::ToggleFullscreenMode(browser_
);
42 Browser
* browser_
; // not owned.
44 DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate
);
49 ///////////////////////////////////////////////////////////////////////////////
50 // BrowserFrameAsh, public:
53 const char BrowserFrameAsh::kWindowName
[] = "BrowserFrameAsh";
55 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame
* browser_frame
,
56 BrowserView
* browser_view
)
57 : views::NativeWidgetAura(browser_frame
),
58 browser_view_(browser_view
) {
59 GetNativeWindow()->SetName(kWindowName
);
60 Browser
* browser
= browser_view
->browser();
61 ash::wm::WindowState
* window_state
=
62 ash::wm::GetWindowState(GetNativeWindow());
63 window_state
->SetDelegate(
64 scoped_ptr
<ash::wm::WindowStateDelegate
>(
65 new BrowserWindowStateDelegate(browser
)).Pass());
67 // Turn on auto window management if we don't need an explicit bounds.
68 // This way the requested bounds are honored.
69 if (!browser
->bounds_overridden() && !browser
->is_session_restore())
70 SetWindowAutoManaged();
71 #if defined(OS_CHROMEOS)
72 if (browser
->is_type_tabbed()) {
73 // Animating to immersive fullscreen does not look good. Immersive
74 // fullscreen is the default fullscreen type on ChromeOS for tabbed browser
75 // windows. The WindowState constructor disables animating to fullscreen
76 // completely when switches::UseImmersiveFullscreenForAllWindows() returns
78 window_state
->set_animate_to_fullscreen(false);
81 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys
82 // like brightness, volume, etc. Otherwise these keys are handled by the
83 // Ash window manager.
84 window_state
->set_can_consume_system_keys(browser
->is_app());
85 #endif // defined(OS_CHROMEOS)
88 ///////////////////////////////////////////////////////////////////////////////
89 // BrowserFrameAsh, views::NativeWidgetAura overrides:
91 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool 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 ////////////////////////////////////////////////////////////////////////////////
101 // BrowserFrameAsh, NativeBrowserFrame implementation:
103 views::NativeWidget
* BrowserFrameAsh::AsNativeWidget() {
107 const views::NativeWidget
* BrowserFrameAsh::AsNativeWidget() const {
111 bool BrowserFrameAsh::UsesNativeSystemMenu() const {
115 int BrowserFrameAsh::GetMinimizeButtonOffset() const {
119 BrowserFrameAsh::~BrowserFrameAsh() {
122 ///////////////////////////////////////////////////////////////////////////////
123 // BrowserFrameAsh, private:
125 void BrowserFrameAsh::SetWindowAutoManaged() {
126 if (browser_view_
->browser()->type() != Browser::TYPE_POPUP
||
127 browser_view_
->browser()->is_app()) {
128 ash::wm::GetWindowState(GetNativeWindow())->
129 set_window_position_managed(true);