0

Introduce WindowStateDelegate::ToggleFullscreen

Replace kAnimateToFullscreenKey with a boolean flag
  in WindowState

I removed  #if defined(OS_WIN).. #endif in chrome_shell_delegate.cc because you'll never get window in desktop environment there.

Next step. I'll look into if we can change so that WindowState::Restore can restore from fullscreen state properly.

BUG=309837

Review URL: https://codereview.chromium.org/42353002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231903 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
oshima@chromium.org
2013-10-30 20:20:08 +00:00
parent 5b0605321a
commit 4539057c3d
26 changed files with 252 additions and 126 deletions

@ -37,10 +37,16 @@ void ToggleMaximized() {
return;
// Get out of fullscreen when in fullscreen mode.
if (window_state->IsFullscreen())
Shell::GetInstance()->delegate()->ToggleFullscreen();
ToggleFullscreen();
else
window_state->ToggleMaximized();
}
void ToggleFullscreen() {
wm::WindowState* window_state = wm::GetActiveWindowState();
if (window_state)
window_state->ToggleFullscreen();
}
} // namespace accelerators
} // namespace ash

@ -21,6 +21,10 @@ ASH_EXPORT bool ToggleMinimized();
// fullscreen mode.
ASH_EXPORT void ToggleMaximized();
// Toggles the fullscreen state. The behavior can be overridden
// by WindowStateDelegate::ToggleFullscreen().
ASH_EXPORT void ToggleFullscreen();
} // namespace accelerators
} // namespace ash

@ -8,6 +8,12 @@
#include "ash/wm/window_state.h"
#include "ui/aura/window.h"
// Note: The unit tests for |ToggleMaximized()| and
// |ToggleFullscreen()| are in
// chrome/browser/ui/ash/accelerator_commands_browsertests.cc.
// because they depends on chrome implementation of
// |ash::wm::WindowStateDelegate|.
namespace ash {
namespace accelerators {

@ -849,7 +849,7 @@ bool AcceleratorController::PerformAction(int action,
shell->delegate()->RecordUserMetricsAction(
UMA_ACCEL_FULLSCREEN_F4);
}
shell->delegate()->ToggleFullscreen();
accelerators::ToggleFullscreen();
return true;
}
case TOGGLE_MAXIMIZED: {

@ -540,6 +540,8 @@
'wm/window_positioner.h',
'wm/window_state.cc',
'wm/window_state.h',
'wm/window_state_delegate.cc',
'wm/window_state_delegate.h',
'wm/window_state_observer.h',
'wm/window_properties.cc',
'wm/window_properties.h',

@ -89,13 +89,6 @@ void ShellDelegateImpl::Exit() {
base::MessageLoopForUI::current()->Quit();
}
void ShellDelegateImpl::ToggleFullscreen() {
// TODO(oshima): Remove this when crbug.com/309837 is implemented.
wm::WindowState* window_state = wm::GetActiveWindowState();
if (window_state)
window_state->ToggleMaximized();
}
keyboard::KeyboardControllerProxy*
ShellDelegateImpl::CreateKeyboardControllerProxy() {
return new KeyboardControllerProxyStub();

@ -33,7 +33,6 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual void PreInit() OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void Exit() OVERRIDE;
virtual void ToggleFullscreen() OVERRIDE;
virtual keyboard::KeyboardControllerProxy*
CreateKeyboardControllerProxy() OVERRIDE;
virtual content::BrowserContext* GetCurrentBrowserContext() OVERRIDE;

@ -129,9 +129,6 @@ class ASH_EXPORT ShellDelegate {
// Invoked when the user uses Ctrl-Shift-Q to close chrome.
virtual void Exit() = 0;
// Invoked when the user uses Shift+F4 to toggle the window fullscreen state.
virtual void ToggleFullscreen() = 0;
// Create a shell-specific keyboard::KeyboardControllerProxy
virtual keyboard::KeyboardControllerProxy*
CreateKeyboardControllerProxy() = 0;

@ -72,9 +72,6 @@ void TestShellDelegate::Exit() {
num_exit_requests_++;
}
void TestShellDelegate::ToggleFullscreen() {
}
keyboard::KeyboardControllerProxy*
TestShellDelegate::CreateKeyboardControllerProxy() {
return new KeyboardControllerProxyStub();

@ -36,7 +36,6 @@ class TestShellDelegate : public ShellDelegate {
virtual void PreInit() OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void Exit() OVERRIDE;
virtual void ToggleFullscreen() OVERRIDE;
virtual keyboard::KeyboardControllerProxy*
CreateKeyboardControllerProxy() OVERRIDE;
virtual content::BrowserContext* GetCurrentBrowserContext() OVERRIDE;

@ -11,7 +11,6 @@ DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WindowState*);
namespace ash {
namespace internal {
DEFINE_WINDOW_PROPERTY_KEY(bool, kAnimateToFullscreenKey, true);
DEFINE_WINDOW_PROPERTY_KEY(bool, kStayInSameRootWindowKey, false);
DEFINE_WINDOW_PROPERTY_KEY(bool, kUsesScreenCoordinatesKey, false);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(wm::WindowState,

@ -25,10 +25,6 @@ namespace internal {
// Alphabetical sort.
// A property key to suppress the cross-fade animation for the transition to
// the fullscreen state.
extern const aura::WindowProperty<bool>* const kAnimateToFullscreenKey;
// If this is set to true, the window stays in the same root window
// even if the bounds outside of its root window is set.
// This is exported as it's used in the tests.

@ -8,6 +8,7 @@
#include "ash/screen_ash.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_state_delegate.h"
#include "ash/wm/window_state_observer.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_types.h"
@ -39,6 +40,7 @@ WindowState::WindowState(aura::Window* window)
window_resizer_(NULL),
always_restores_to_restore_bounds_(false),
hide_shelf_when_fullscreen_(true),
animate_to_fullscreen_(true),
window_show_type_(ToWindowShowType(GetShowState())) {
window_->AddObserver(this);
}
@ -46,6 +48,11 @@ WindowState::WindowState(aura::Window* window)
WindowState::~WindowState() {
}
void WindowState::SetDelegate(scoped_ptr<WindowStateDelegate> delegate) {
DCHECK(!delegate_.get());
delegate_ = delegate.Pass();
}
ui::WindowShowState WindowState::GetShowState() const {
return window_->GetProperty(aura::client::kShowStateKey);
}
@ -161,6 +168,22 @@ void WindowState::ToggleMaximized() {
Maximize();
}
void WindowState::ToggleFullscreen() {
// Window which cannot be maximized should not be fullscreened.
// It can, however, be restored if it was fullscreened.
bool is_fullscreen = IsFullscreen();
if (!is_fullscreen && !CanMaximize())
return;
if (delegate_ && delegate_->ToggleFullscreen(this))
return;
if (is_fullscreen) {
Restore();
} else {
window_->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
}
}
void WindowState::SetBoundsInScreen(
const gfx::Rect& bounds_in_screen) {
gfx::Rect bounds_in_parent =

@ -25,6 +25,7 @@ namespace ash {
class WindowResizer;
namespace wm {
class WindowStateDelegate;
class WindowStateObserver;
// WindowState manages and defines ash specific window state and
@ -48,6 +49,8 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
aura::Window* window() { return window_; }
const aura::Window* window() const { return window_; }
void SetDelegate(scoped_ptr<WindowStateDelegate> delegate);
// Returns the window's current show state.
ui::WindowShowState GetShowState() const;
@ -84,6 +87,7 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
void Deactivate();
void Restore();
void ToggleMaximized();
void ToggleFullscreen();
void SnapLeft(const gfx::Rect& bounds);
void SnapRight(const gfx::Rect& bounds);
@ -135,6 +139,15 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
hide_shelf_when_fullscreen_ = value;
}
// Sets/gets the flag to suppress the cross-fade animation for
// the transition to the fullscreen state.
bool animate_to_fullscreen() const {
return animate_to_fullscreen_;
}
void set_animate_to_fullscreen(bool value) {
animate_to_fullscreen_ = value;
}
// Gets/Sets the bounds of the window before it was moved by the auto window
// management. As long as it was not auto-managed, it will return NULL.
const gfx::Rect* pre_auto_manage_window_bounds() const {
@ -234,6 +247,7 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
// The owner of this window settings.
aura::Window* window_;
scoped_ptr<WindowStateDelegate> delegate_;
bool tracked_by_workspace_;
bool window_position_managed_;
@ -247,6 +261,7 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
bool always_restores_to_restore_bounds_;
bool hide_shelf_when_fullscreen_;
bool animate_to_fullscreen_;
// A property to remember the window position which was set before the
// auto window position manager changed the window bounds, so that it can get

@ -0,0 +1,21 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/window_state_delegate.h"
namespace ash {
namespace wm {
WindowStateDelegate::WindowStateDelegate() {
}
WindowStateDelegate::~WindowStateDelegate() {
}
bool WindowStateDelegate::ToggleFullscreen(WindowState* window_state) {
return false;
}
} // namespace wm
} // namespace ash

@ -0,0 +1,32 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_WINDOW_STATE_DELEGATE_H_
#define ASH_WM_WINDOW_STATE_DELEGATE_H_
#include "ash/ash_export.h"
#include "base/basictypes.h"
namespace ash {
namespace wm {
class WindowState;
class ASH_EXPORT WindowStateDelegate {
public:
WindowStateDelegate();
virtual ~WindowStateDelegate();
// Invoked when the user uses Shift+F4/F4 to toggle the window
// fullscreen state. The caller (ash::wm::WindowState) falls backs
// to the default implementation if this returns false.
virtual bool ToggleFullscreen(WindowState* window_state);
private:
DISALLOW_COPY_AND_ASSIGN(WindowStateDelegate);
};
} // namespace wm
} // namespace ash
#endif // ASH_WM_WINDOW_STATE_DELEGATE_H_

@ -62,10 +62,6 @@ void CenterWindow(aura::Window* window) {
window->SetBoundsInScreen(center, display);
}
void SetAnimateToFullscreen(aura::Window* window, bool animate) {
window->SetProperty(ash::internal::kAnimateToFullscreenKey, animate);
}
void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area,
gfx::Rect* bounds) {
AdjustBoundsToEnsureWindowVisibility(

@ -47,9 +47,6 @@ ASH_EXPORT bool IsWindowMinimized(aura::Window* window);
// Moves the window to the center of the display.
ASH_EXPORT void CenterWindow(aura::Window* window);
// Change the availability of animation to the fullscreen of the |window|.
ASH_EXPORT void SetAnimateToFullscreen(aura::Window* window, bool animate);
// Move the given bounds inside the given |visible_area| in parent coordinates,
// including a safety margin given by |kMinimumOnScreenArea|.
// This also ensures that the top of the bounds is visible.

@ -349,7 +349,7 @@ void WorkspaceLayoutManager::UpdateBoundsFromShowState(
MoveToDisplayForRestore(window_state);
gfx::Rect new_bounds = ScreenAsh::GetDisplayBoundsInParent(
window->parent()->parent());
if (window->GetProperty(kAnimateToFullscreenKey) &&
if (window_state->animate_to_fullscreen() &&
last_show_state != ui::SHOW_STATE_MINIMIZED) {
CrossFadeToBounds(window, new_bounds);
} else {

@ -1,15 +1,12 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/chrome_shell_delegate.h"
#include "ash/accelerators/accelerator_commands.h"
#include "apps/shell_window.h"
#include "apps/ui/native_app_window.h"
#include "ash/accelerators/accelerator_commands.h"
#include "ash/ash_switches.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wm/window_state.h"
#include "base/command_line.h"
#include "chrome/browser/apps/app_browsertest_util.h"
@ -36,15 +33,11 @@ bool IsInImmersiveFullscreen(BrowserWindow* browser_window) {
} // namespace
typedef InProcessBrowserTest ChromeShellDelegateBrowserTest;
// TODO(oshima): Move these tests to ash once ToggleFullscreen is moved
// to ash. crbug.com/309837.
typedef InProcessBrowserTest AcceleratorCommandsBrowserTest;
// Confirm that toggling window miximized works properly
IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleMaximized) {
ash::ShellDelegate* shell_delegate = ash::Shell::GetInstance()->delegate();
ASSERT_TRUE(shell_delegate);
IN_PROC_BROWSER_TEST_F(AcceleratorCommandsBrowserTest, ToggleMaximized) {
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
ash::wm::WindowState* window_state = ash::wm::GetActiveWindowState();
ASSERT_TRUE(window_state);
@ -70,10 +63,8 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleMaximized) {
}
// Confirm that toggling window fullscren works properly.
IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleFullscreen) {
ash::ShellDelegate* shell_delegate = ash::Shell::GetInstance()->delegate();
ASSERT_TRUE(shell_delegate);
IN_PROC_BROWSER_TEST_F(AcceleratorCommandsBrowserTest, ToggleFullscreen) {
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
// 1) ToggleFullscreen() should toggle whether a tabbed browser window is in
// immersive fullscreen.
ASSERT_TRUE(browser()->is_type_tabbed());
@ -82,11 +73,11 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleFullscreen) {
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(browser_window->IsFullscreen());
EXPECT_TRUE(IsInImmersiveFullscreen(browser_window));
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
@ -94,7 +85,7 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleFullscreen) {
// maximized.
browser_window->GetNativeWindow()->SetProperty(aura::client::kCanMaximizeKey,
false);
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
@ -117,10 +108,10 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleFullscreen) {
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(browser_window->IsMaximized());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
@ -136,11 +127,11 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleFullscreen) {
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(browser_window->IsFullscreen());
EXPECT_FALSE(IsInImmersiveFullscreen(browser_window));
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
@ -156,24 +147,22 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegateBrowserTest, ToggleFullscreen) {
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(browser_window->IsFullscreen());
EXPECT_FALSE(IsInImmersiveFullscreen(browser_window));
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(browser_window->IsMaximized());
EXPECT_FALSE(browser_window->IsFullscreen());
}
typedef extensions::PlatformAppBrowserTest
ChromeShellDelegatePlatformAppBrowserTest;
AcceleratorCommandsPlatformAppBrowserTest;
// Test that ToggleFullscreen() toggles the platform app's fullscreen state.
IN_PROC_BROWSER_TEST_F(ChromeShellDelegatePlatformAppBrowserTest,
IN_PROC_BROWSER_TEST_F(AcceleratorCommandsPlatformAppBrowserTest,
ToggleFullscreenPlatformApp) {
ash::ShellDelegate* shell_delegate = ash::Shell::GetInstance()->delegate();
ASSERT_TRUE(shell_delegate);
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
const extensions::Extension* extension = LoadAndLaunchPlatformApp("minimal");
apps::ShellWindow* shell_window = CreateShellWindow(extension);
apps::NativeAppWindow* app_window = shell_window->GetBaseWindow();
@ -181,10 +170,10 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegatePlatformAppBrowserTest,
EXPECT_FALSE(app_window->IsMaximized());
EXPECT_FALSE(app_window->IsFullscreen());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(app_window->IsFullscreen());
shell_delegate->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(app_window->IsMaximized());
EXPECT_FALSE(app_window->IsFullscreen());

@ -21,7 +21,6 @@
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
#include "chrome/browser/ui/ash/user_action_handler.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/user_metrics.h"
#include "grit/chromium_strings.h"
@ -87,55 +86,6 @@ void ChromeShellDelegate::Exit() {
chrome::AttemptUserExit();
}
void ChromeShellDelegate::ToggleFullscreen() {
// Only toggle if the user has a window open.
aura::Window* window = ash::wm::GetActiveWindow();
if (!window)
return;
ash::wm::WindowState* window_state = ash::wm::GetWindowState(window);
bool is_fullscreen = window_state->IsFullscreen();
// Windows which cannot be maximized should not be fullscreened.
if (!is_fullscreen && !window_state->CanMaximize())
return;
Browser* browser = chrome::FindBrowserWithWindow(window);
if (browser) {
// If a window is fullscreen, exit fullscreen.
if (is_fullscreen) {
chrome::ToggleFullscreenMode(browser);
return;
}
// AppNonClientFrameViewAsh shows only the window controls and no other
// window decorations which is pretty close to fullscreen. Put v1 apps
// into maximized mode instead of fullscreen to avoid showing the ugly
// fullscreen exit bubble.
#if defined(OS_WIN)
if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
chrome::ToggleFullscreenMode(browser);
return;
}
#endif // OS_WIN
if (browser->is_app() && browser->app_type() != Browser::APP_TYPE_CHILD)
window_state->ToggleMaximized();
else
chrome::ToggleFullscreenMode(browser);
return;
}
// |window| may belong to a shell window.
apps::ShellWindow* shell_window = apps::ShellWindowRegistry::
GetShellWindowForNativeWindowAnyProfile(window);
if (shell_window) {
if (is_fullscreen)
shell_window->Restore();
else
shell_window->Fullscreen();
}
}
content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() {
return ProfileManager::GetDefaultProfile();
}

@ -43,7 +43,6 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual void PreInit() OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void Exit() OVERRIDE;
virtual void ToggleFullscreen() OVERRIDE;
virtual keyboard::KeyboardControllerProxy*
CreateKeyboardControllerProxy() OVERRIDE;
virtual content::BrowserContext* GetCurrentBrowserContext() OVERRIDE;

@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/apps/native_app_window_views.h"
#include "apps/shell_window.h"
#include "apps/ui/views/shell_window_frame_view.h"
#include "base/command_line.h"
#include "base/file_util.h"
@ -13,6 +14,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
@ -46,6 +48,7 @@
#include "ash/wm/custom_frame_view_ash.h"
#include "ash/wm/panels/panel_frame_view.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_delegate.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_tree_client.h"
@ -124,6 +127,34 @@ void CreateIconAndSetRelaunchDetails(
}
#endif
#if defined(USE_ASH)
// This class handles a user's fullscreen request (Shift+F4/F4).
class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate {
public:
explicit NativeAppWindowStateDelegate(ShellWindow* shell_window)
: shell_window_(shell_window) {
DCHECK(shell_window_);
}
virtual ~NativeAppWindowStateDelegate(){}
// Overridden from ash::wm::WindowStateDelegate.
virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE {
// Windows which cannot be maximized should not be fullscreened.
DCHECK(window_state->IsFullscreen() || window_state->CanMaximize());
if (window_state->IsFullscreen())
shell_window_->Restore();
else if (window_state->CanMaximize())
shell_window_->Fullscreen();
return true;
}
private:
ShellWindow* shell_window_; // not owned.
DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate);
};
#endif // USE_ASH
} // namespace
NativeAppWindowViews::NativeAppWindowViews(
@ -155,6 +186,14 @@ NativeAppWindowViews::NativeAppWindowViews(
OnViewWasResized();
window_->AddObserver(this);
#if defined(USE_ASH)
if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) ==
chrome::HOST_DESKTOP_TYPE_ASH) {
ash::wm::GetWindowState(GetNativeWindow())->SetDelegate(
scoped_ptr<ash::wm::WindowStateDelegate>(
new NativeAppWindowStateDelegate(shell_window)).Pass());
}
#endif
}
NativeAppWindowViews::~NativeAppWindowViews() {

@ -5,7 +5,10 @@
#include "chrome/browser/ui/views/frame/browser_frame_ash.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_delegate.h"
#include "ash/wm/window_util.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
@ -14,6 +17,64 @@
using aura::Window;
namespace {
// BrowserWindowStateDelegate classe handles a user's fullscreen
// request (Shift+F4/F4) for browser (tabbed/popup) windows.
class BrowserWindowStateDelegate : public ash::wm::WindowStateDelegate {
public:
explicit BrowserWindowStateDelegate(Browser* browser)
: browser_(browser) {
DCHECK(browser_);
}
virtual ~BrowserWindowStateDelegate(){}
// Overridden from ash::wm::WindowStateDelegate.
virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE {
DCHECK(window_state->IsFullscreen() || window_state->CanMaximize());
// Windows which cannot be maximized should not be fullscreened.
if (!window_state->IsFullscreen() && !window_state->CanMaximize())
return true;
chrome::ToggleFullscreenMode(browser_);
return true;
}
private:
Browser* browser_; // not owned.
DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate);
};
// AppNonClientFrameViewAsh shows only the window controls and no
// other window decorations which is pretty close to fullscreen. Put
// v1 apps into maximized mode instead of fullscreen to avoid showing
// the ugly fullscreen exit bubble. This is used for V1 apps.
class AppWindowStateDelegate : public ash::wm::WindowStateDelegate {
public:
explicit AppWindowStateDelegate(Browser* browser)
: browser_(browser) {
DCHECK(browser_);
}
virtual ~AppWindowStateDelegate(){}
// Overridden from ash::wm::WindowStateDelegate.
virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE {
DCHECK(window_state->IsFullscreen() || window_state->CanMaximize());
if (window_state->IsFullscreen())
chrome::ToggleFullscreenMode(browser_);
else
window_state->ToggleMaximized();
return true;
}
private:
Browser* browser_; // not owned.
DISALLOW_COPY_AND_ASSIGN(AppWindowStateDelegate);
};
} // namespace
////////////////////////////////////////////////////////////////////////////////
// BrowserFrameAsh::WindowPropertyWatcher
@ -86,22 +147,29 @@ BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame,
window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) {
GetNativeWindow()->SetName(kWindowName);
GetNativeWindow()->AddObserver(window_property_watcher_.get());
if (browser_view->browser()->is_type_tabbed())
ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false);
Browser* browser = browser_view->browser();
ash::wm::WindowState* window_state =
ash::wm::GetWindowState(GetNativeWindow());
if (browser->is_app() && browser->app_type() != Browser::APP_TYPE_CHILD) {
window_state->SetDelegate(
scoped_ptr<ash::wm::WindowStateDelegate>(
new AppWindowStateDelegate(browser)).Pass());
} else {
window_state->SetDelegate(
scoped_ptr<ash::wm::WindowStateDelegate>(
new BrowserWindowStateDelegate(browser)).Pass());
}
window_state->set_animate_to_fullscreen(!browser->is_type_tabbed());
// Turn on auto window management if we don't need an explicit bounds.
// This way the requested bounds are honored.
if (!browser_view->browser()->bounds_overridden() &&
!browser_view->browser()->is_session_restore())
if (!browser->bounds_overridden() && !browser->is_session_restore())
SetWindowAutoManaged();
#if defined(OS_CHROMEOS)
// For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys
// like brightness, volume, etc. Otherwise these keys are handled by the
// Ash window manager.
if (browser_view->browser()->is_app()) {
ash::wm::GetWindowState(GetNativeWindow())->
set_can_consume_system_keys(true);
}
window_state->set_can_consume_system_keys(browser->is_app());
#endif // defined(OS_CHROMEOS)
}

@ -50,8 +50,7 @@
#include "ui/views/widget/widget.h"
#if defined(USE_ASH)
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/accelerators/accelerator_commands.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/window_state.h"
#include "ui/aura/env.h"
@ -1911,7 +1910,7 @@ void TabDragController::CompleteDrag() {
host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) {
// In fullscreen mode it is only possible to get here if the source
// was in "immersive fullscreen" mode, so toggle it back on.
ash::Shell::GetInstance()->delegate()->ToggleFullscreen();
ash::accelerators::ToggleFullscreen();
}
#endif
} else {

@ -1409,8 +1409,8 @@
'browser/ui/app_list/test/app_list_service_test_api_ash.h',
'browser/ui/app_list/test/app_list_service_test_api_linux.cc',
'browser/ui/app_list/test/app_list_service_test_api_mac.mm',
'browser/ui/ash/accelerator_commands_browsertest.cc',
'browser/ui/ash/caps_lock_delegate_chromeos_browsertest.cc',
'browser/ui/ash/chrome_shell_delegate_browsertest.cc',
'browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc',
'browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc',
'browser/ui/ash/shelf_browsertest.cc',
@ -1855,8 +1855,8 @@
# for win aura builds.
# TODO: enable these for win_ash browser tests.
'browser/chromeos/system/tray_accessibility_browsertest.cc',
'browser/ui/ash/accelerator_commands_browsertest.cc',
'browser/ui/ash/caps_lock_delegate_chromeos_browsertest.cc',
'browser/ui/ash/chrome_shell_delegate_browsertest.cc',
'browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc',
'browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc',
'browser/ui/ash/shelf_browsertest.cc',