Commit 29c4950c authored by oshima@chromium.org's avatar oshima@chromium.org

Maximize window in the display to be restored.

BUG=268987
TEST=covered by test.

Review URL: https://chromiumcodereview.appspot.com/22394003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216953 0039d316-1c4b-4281-b951-d872f2087c98
parent add5489a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/wm/workspace/workspace_layout_manager.h" #include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/display/display_controller.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/screen_ash.h" #include "ash/screen_ash.h"
#include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_layout_manager.h"
...@@ -41,6 +42,33 @@ bool IsMaximizedState(ui::WindowShowState state) { ...@@ -41,6 +42,33 @@ bool IsMaximizedState(ui::WindowShowState state) {
state == ui::SHOW_STATE_FULLSCREEN; state == ui::SHOW_STATE_FULLSCREEN;
} }
void MoveToDisplayForRestore(aura::Window* window) {
const gfx::Rect* restore_bounds = GetRestoreBoundsInScreen(window);
if (!restore_bounds)
return;
// Move only if the restore bounds is outside of
// the root window. There is no information about in which
// display it should be restored, so this is best guess.
// TODO(oshima): Restore information should contain the
// work area information like WindowResizer does for the
// last window location.
if (!window->GetRootWindow()->GetBoundsInScreen().Intersects(
*restore_bounds)) {
DisplayController* display_controller =
Shell::GetInstance()->display_controller();
const gfx::Display& display =
display_controller->GetDisplayMatching(*restore_bounds);
aura::RootWindow* new_root =
display_controller->GetRootWindowForDisplayId(display.id());
if (new_root != window->GetRootWindow()) {
aura::Window* new_container =
Shell::GetContainer(new_root, window->parent()->id());
new_container->AddChild(window);
}
}
}
} // namespace } // namespace
WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window)
...@@ -285,14 +313,15 @@ void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) { ...@@ -285,14 +313,15 @@ void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) {
} }
case ui::SHOW_STATE_MAXIMIZED: case ui::SHOW_STATE_MAXIMIZED:
MoveToDisplayForRestore(window);
CrossFadeToBounds(window, ScreenAsh::GetMaximizedWindowBoundsInParent( CrossFadeToBounds(window, ScreenAsh::GetMaximizedWindowBoundsInParent(
window->parent()->parent())); window->parent()->parent()));
break; break;
case ui::SHOW_STATE_FULLSCREEN: case ui::SHOW_STATE_FULLSCREEN:
MoveToDisplayForRestore(window);
CrossFadeToBounds(window, ScreenAsh::GetDisplayBoundsInParent( CrossFadeToBounds(window, ScreenAsh::GetDisplayBoundsInParent(
window->parent()->parent())); window->parent()->parent()));
break; break;
default: default:
break; break;
} }
......
...@@ -17,11 +17,35 @@ ...@@ -17,11 +17,35 @@
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/insets.h" #include "ui/gfx/insets.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash { namespace ash {
namespace { namespace {
class MaximizeDelegateView : public views::WidgetDelegateView {
public:
MaximizeDelegateView(const gfx::Rect& initial_bounds)
: initial_bounds_(initial_bounds) {
}
virtual ~MaximizeDelegateView() {}
virtual bool GetSavedWindowPlacement(
gfx::Rect* bounds,
ui::WindowShowState* show_state) const OVERRIDE {
*bounds = initial_bounds_;
*show_state = ui::SHOW_STATE_MAXIMIZED;
return true;
}
private:
const gfx::Rect initial_bounds_;
DISALLOW_COPY_AND_ASSIGN(MaximizeDelegateView);
};
} // namespace
typedef test::AshTestBase WorkspaceLayoutManagerTest; typedef test::AshTestBase WorkspaceLayoutManagerTest;
// Verifies that a window containing a restore coordinate will be restored to // Verifies that a window containing a restore coordinate will be restored to
...@@ -98,6 +122,91 @@ TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { ...@@ -98,6 +122,91 @@ TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); EXPECT_EQ("-20,-30 30x40", window->bounds().ToString());
} }
TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("300x400,400x500");
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
scoped_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
EXPECT_EQ(root_windows[0], window->GetRootWindow());
SetRestoreBoundsInScreen(window.get(), gfx::Rect(400, 0, 30, 40));
// Maximize the window in 2nd display as the restore bounds
// is inside 2nd display.
wm::MaximizeWindow(window.get());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("300,0 400x452", window->GetBoundsInScreen().ToString());
wm::RestoreWindow(window.get());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
// If the restore bounds intersects with the current display,
// don't move.
SetRestoreBoundsInScreen(window.get(), gfx::Rect(280, 0, 30, 40));
wm::MaximizeWindow(window.get());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("300,0 400x452", window->GetBoundsInScreen().ToString());
wm::RestoreWindow(window.get());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString());
// Restoring widget state.
scoped_ptr<views::Widget> w1(new views::Widget);
views::Widget::InitParams params;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40));
params.context = root_windows[0];
w1->Init(params);
w1->Show();
EXPECT_TRUE(w1->IsMaximized());
EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
EXPECT_EQ("300,0 400x452", w1->GetWindowBoundsInScreen().ToString());
w1->Restore();
EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("300x400,400x500");
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
scoped_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
EXPECT_EQ(root_windows[0], window->GetRootWindow());
SetRestoreBoundsInScreen(window.get(), gfx::Rect(400, 0, 30, 40));
// Maximize the window in 2nd display as the restore bounds
// is inside 2nd display.
window->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
wm::RestoreWindow(window.get());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
// If the restore bounds intersects with the current display,
// don't move.
SetRestoreBoundsInScreen(window.get(), gfx::Rect(280, 0, 30, 40));
window->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
wm::RestoreWindow(window.get());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString());
}
// WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver.
// This code mirrors what BrowserFrameAura does. In particular when this code // This code mirrors what BrowserFrameAura does. In particular when this code
// sees the window was maximized it changes the bounds of a secondary // sees the window was maximized it changes the bounds of a secondary
...@@ -250,5 +359,4 @@ TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { ...@@ -250,5 +359,4 @@ TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) {
window->bounds().ToString()); window->bounds().ToString());
} }
} // namespace
} // namespace ash } // namespace ash
...@@ -443,8 +443,8 @@ void NativeWidgetAura::Hide() { ...@@ -443,8 +443,8 @@ void NativeWidgetAura::Hide() {
void NativeWidgetAura::ShowMaximizedWithBounds( void NativeWidgetAura::ShowMaximizedWithBounds(
const gfx::Rect& restored_bounds) { const gfx::Rect& restored_bounds) {
ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED);
SetRestoreBounds(window_, restored_bounds); SetRestoreBounds(window_, restored_bounds);
ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED);
} }
void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment