Commit 578fb750 authored by jackhou's avatar jackhou Committed by Commit bot

[Ash] Only snap windows that can maximize.

Previously, windows that have only one of maxWidth or maxHeight defined
could not be maximized by the user, but they would still snap when
dragged to the edge of the screen.

This changes WindowState::CanSnap to use CanMaximize which is false
when there is a maxWidth or maxHeight, or when the window is not
resizable.

BUG=412610, 408737

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

Cr-Commit-Position: refs/heads/master@{#295657}
parent 07cf0298
......@@ -141,7 +141,15 @@ bool WindowState::IsDocked() const {
}
bool WindowState::CanMaximize() const {
return window_->GetProperty(aura::client::kCanMaximizeKey);
// Window must have the kCanMaximizeKey and have no maximum width or height.
if (!window()->GetProperty(aura::client::kCanMaximizeKey))
return false;
if (!window()->delegate())
return true;
gfx::Size max_size = window_->delegate()->GetMaximumSize();
return !max_size.width() && !max_size.height();
}
bool WindowState::CanMinimize() const {
......@@ -168,10 +176,10 @@ bool WindowState::CanSnap() const {
if (!CanResize() || window_->type() == ui::wm::WINDOW_TYPE_PANEL ||
::wm::GetTransientParent(window_))
return false;
// If a window has a maximum size defined, snapping may make it too big.
// TODO(oshima): We probably should snap if possible.
return window_->delegate() ? window_->delegate()->GetMaximumSize().IsEmpty() :
true;
// If a window cannot be maximized, assume it cannot snap either.
// TODO(oshima): We should probably snap if the maximum size is greater than
// the snapped size.
return CanMaximize();
}
bool WindowState::HasRestoreBounds() const {
......
......@@ -9,6 +9,7 @@
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
......@@ -124,9 +125,14 @@ TEST_F(WindowStateTest, SnapWindowMinimumSize) {
kWorkAreaBounds.height());
EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
// It should not be possible to snap a window with a maximum size.
delegate.set_minimum_size(gfx::Size());
delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX));
// It should not be possible to snap a window with a maximum size, or if it
// cannot be maximized.
delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0));
EXPECT_FALSE(window_state->CanSnap());
delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1));
EXPECT_FALSE(window_state->CanSnap());
delegate.set_maximum_size(gfx::Size());
window->SetProperty(aura::client::kCanMaximizeKey, false);
EXPECT_FALSE(window_state->CanSnap());
}
......
......@@ -556,6 +556,7 @@ TEST_F(WorkspaceWindowResizerTest, Edge) {
// http://crbug.com/292238.
// Window is wide enough not to get docked right away.
window_->SetBounds(gfx::Rect(20, 30, 400, 60));
window_->SetProperty(aura::client::kCanMaximizeKey, true);
wm::WindowState* window_state = wm::GetWindowState(window_.get());
{
......@@ -1415,6 +1416,7 @@ TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) {
// Test that the user user moved window flag is getting properly set.
TEST_F(WorkspaceWindowResizerTest, CheckUserWindowManagedFlags) {
window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
window_->SetProperty(aura::client::kCanMaximizeKey, true);
std::vector<aura::Window*> no_attached_windows;
// Check that an abort doesn't change anything.
......
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