Skip to content

Commit

Permalink
Fixing an empty restore rectangle for V2 apps as well as leaving full…
Browse files Browse the repository at this point in the history
… screen when returning from maximize mode

BUG=369868
TEST=ash_unittests and visual

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268757 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
skuhne@chromium.org committed May 7, 2014
1 parent 5041564 commit 00681f0
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ash/wm/default_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ void DefaultState::ReenterToCurrentState(
WindowState* window_state,
WindowState::State* state_in_previous_mode) {
WindowStateType previous_state_type = state_in_previous_mode->GetType();
if (previous_state_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) {
// A state change should not move a window out of full screen since full
// screen is a "special mode" the user wanted to be in and should be
// respected as such.
state_type_ = wm::WINDOW_STATE_TYPE_FULLSCREEN;
}
window_state->UpdateWindowShowStateFromStateType();
window_state->NotifyPreStateTypeChange(previous_state_type);

Expand Down
74 changes: 70 additions & 4 deletions ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ TEST_F(MaximizeModeWindowManagerTest, KeepFullScreenModeOn) {
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
}

// Check that full screen mode can be turned on in maximized mode.
// Check that full screen mode can be turned on in maximized mode and remains
// upon coming back.
TEST_F(MaximizeModeWindowManagerTest, AllowFullScreenMode) {
gfx::Rect rect(20, 140, 100, 100);
scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
Expand Down Expand Up @@ -828,11 +829,76 @@ TEST_F(MaximizeModeWindowManagerTest, AllowFullScreenMode) {
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());

// With the destruction of the manager we should fall back to the old state.
// With the destruction of the manager we should remain in full screen.
DestroyMaximizeModeWindowManager();
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
}

// Check that the full screen mode will stay active when the maximize mode is
// ended.
TEST_F(MaximizeModeWindowManagerTest,
FullScreenModeRemainsWhenCreatedInMaximizedMode) {
CreateMaximizeModeWindowManager();

gfx::Rect rect(20, 140, 100, 100);
scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
wm::WindowState* window_state = wm::GetWindowState(w1.get());
wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event_full_screen);
EXPECT_TRUE(window_state->IsFullscreen());

// After the maximize mode manager is ended, full screen will remain.
DestroyMaximizeModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
}

// Check that the full screen mode will stay active throughout a maximzied mode
// session.
TEST_F(MaximizeModeWindowManagerTest,
FullScreenModeRemainsThroughMaximizeModeSwitch) {
gfx::Rect rect(20, 140, 100, 100);
scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
wm::WindowState* window_state = wm::GetWindowState(w1.get());
wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event_full_screen);
EXPECT_TRUE(window_state->IsFullscreen());

CreateMaximizeModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
DestroyMaximizeModeWindowManager();
EXPECT_TRUE(window_state->IsFullscreen());
}

// Check that an empty window does not get restored to a tiny size.
TEST_F(MaximizeModeWindowManagerTest,
CreateAndMaximizeInMaximizeModeShouldRetoreToGoodSizeGoingToDefault) {
CreateMaximizeModeWindowManager();
gfx::Rect rect;
scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
w1->Show();
wm::WindowState* window_state = wm::GetWindowState(w1.get());
EXPECT_TRUE(window_state->IsMaximized());

// There is a calling order in which the restore bounds can get set to an
// empty rectangle. We simulate this here.
window_state->SetRestoreBoundsInScreen(rect);
EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty());

// Setting the window to a new size will physically not change the window,
// but the restore size should get updated so that a restore later on will
// return to this size.
gfx::Rect requested_bounds(10, 20, 50, 70);
w1->SetBounds(requested_bounds);
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(requested_bounds.ToString(),
window_state->GetRestoreBoundsInScreen().ToString());

DestroyMaximizeModeWindowManager();

EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString());
}

// Check that snapping operations get ignored.
Expand Down
18 changes: 11 additions & 7 deletions ash/wm/maximize_mode/maximize_mode_window_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,17 @@ void MaximizeModeWindowState::OnWMEvent(wm::WindowState* window_state,
case wm::WM_EVENT_SHOW_INACTIVE:
return;
case wm::WM_EVENT_SET_BOUNDS:
if (window_state->CanResize()) {
// In case the window is resizable and / or maximized we ignore the
// requested bounds change and resize to the biggest possible size.
UpdateBounds(window_state, true);
} else
if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED) {
if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) {
// Having a maximized window, it could have been created with an empty
// size and the caller should get his size upon leaving the maximized
// mode. As such we set the restore bounds to the requested bounds.
gfx::Rect bounds_in_parent =
(static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds();
if (!bounds_in_parent.IsEmpty())
window_state->SetRestoreBoundsInParent(bounds_in_parent);
} else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
// In all other cases (except for minimized windows) we respect the
// requested bounds and center it to a fully visible area on the screen.
gfx::Rect bounds_in_parent =
Expand Down

0 comments on commit 00681f0

Please sign in to comment.