Commit 37aa3836 authored by skuhne@chromium.org's avatar skuhne@chromium.org

Ignoring minimum size requirements for maximized windows, full screen windows and too small screens

BUG=366315
TEST=ash_unittest's and visual tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267084 0039d316-1c4b-4281-b951-d872f2087c98
parent 533ef3d3
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ui/compositor/layer_tree_owner.h" #include "ui/compositor/layer_tree_owner.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/display.h" #include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
namespace ash { namespace ash {
...@@ -357,7 +358,21 @@ void WindowState::NotifyPostStateTypeChange( ...@@ -357,7 +358,21 @@ void WindowState::NotifyPostStateTypeChange(
} }
void WindowState::SetBoundsDirect(const gfx::Rect& bounds) { void WindowState::SetBoundsDirect(const gfx::Rect& bounds) {
BoundsSetter().SetBounds(window_, bounds); gfx::Rect actual_new_bounds(bounds);
// Ensure we don't go smaller than our minimum bounds in "normal" window
// modes
if (window_->delegate() && !IsMaximized() && !IsFullscreen()) {
// Get the minimum usable size of the minimum size and the screen size.
gfx::Size min_size = window_->delegate()->GetMinimumSize();
min_size.SetToMin(gfx::Screen::GetScreenFor(
window_)->GetDisplayNearestWindow(window_).work_area().size());
actual_new_bounds.set_width(
std::max(min_size.width(), actual_new_bounds.width()));
actual_new_bounds.set_height(
std::max(min_size.height(), actual_new_bounds.height()));
}
BoundsSetter().SetBounds(window_, actual_new_bounds);
} }
void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) { void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) {
......
...@@ -130,6 +130,67 @@ TEST_F(WindowStateTest, SnapWindowMinimumSize) { ...@@ -130,6 +130,67 @@ TEST_F(WindowStateTest, SnapWindowMinimumSize) {
EXPECT_FALSE(window_state->CanSnap()); EXPECT_FALSE(window_state->CanSnap());
} }
// Test that the minimum size specified by aura::WindowDelegate gets respected.
TEST_F(WindowStateTest, TestRespectMinimumSize) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("0+0-1024x768");
aura::test::TestWindowDelegate delegate;
const gfx::Size minimum_size(gfx::Size(500, 300));
delegate.set_minimum_size(minimum_size);
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate, -1, gfx::Rect(0, 100, 100, 100)));
// Check that the window has the correct minimum size.
EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString());
// Set the size to something bigger - that should work.
gfx::Rect bigger_bounds(700, 500, 700, 500);
window->SetBounds(bigger_bounds);
EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString());
// Set the size to something smaller - that should only resize to the smallest
// possible size.
gfx::Rect smaller_bounds(700, 500, 100, 100);
window->SetBounds(smaller_bounds);
EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString());
}
// Test that the minimum window size specified by aura::WindowDelegate does not
// exceed the screen size.
TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("0+0-1024x768");
const gfx::Size work_area_size =
ash::Shell::GetScreen()->GetPrimaryDisplay().work_area().size();
const gfx::Size illegal_size(1280, 960);
const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size);
aura::test::TestWindowDelegate delegate;
const gfx::Size minimum_size(illegal_size);
delegate.set_minimum_size(minimum_size);
// The creation should force the window to respect the screen size.
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate, -1, illegal_bounds));
EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString());
// Trying to set the size to something bigger then the screen size should be
// ignored.
window->SetBounds(illegal_bounds);
EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString());
// Maximizing the window should not allow it to go bigger than that either.
WindowState* window_state = GetWindowState(window.get());
window_state->Maximize();
EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString());
}
// Test that setting the bounds of a snapped window keeps its snapped. // Test that setting the bounds of a snapped window keeps its snapped.
TEST_F(WindowStateTest, SnapWindowSetBounds) { TEST_F(WindowStateTest, SnapWindowSetBounds) {
if (!SupportsHostWindowResize()) if (!SupportsHostWindowResize())
......
...@@ -426,8 +426,17 @@ Window::SetEventTargeter(scoped_ptr<ui::EventTargeter> targeter) { ...@@ -426,8 +426,17 @@ Window::SetEventTargeter(scoped_ptr<ui::EventTargeter> targeter) {
void Window::SetBounds(const gfx::Rect& new_bounds) { void Window::SetBounds(const gfx::Rect& new_bounds) {
if (parent_ && parent_->layout_manager()) if (parent_ && parent_->layout_manager())
parent_->layout_manager()->SetChildBounds(this, new_bounds); parent_->layout_manager()->SetChildBounds(this, new_bounds);
else else {
SetBoundsInternal(new_bounds); // Ensure we don't go smaller than our minimum bounds.
gfx::Rect final_bounds(new_bounds);
if (delegate_) {
const gfx::Size& min_size = delegate_->GetMinimumSize();
final_bounds.set_width(std::max(min_size.width(), final_bounds.width()));
final_bounds.set_height(std::max(min_size.height(),
final_bounds.height()));
}
SetBoundsInternal(final_bounds);
}
} }
void Window::SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen, void Window::SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen,
...@@ -865,16 +874,6 @@ bool Window::HitTest(const gfx::Point& local_point) { ...@@ -865,16 +874,6 @@ bool Window::HitTest(const gfx::Point& local_point) {
void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
gfx::Rect actual_new_bounds(new_bounds); gfx::Rect actual_new_bounds(new_bounds);
// Ensure we don't go smaller than our minimum bounds.
if (delegate_) {
const gfx::Size& min_size = delegate_->GetMinimumSize();
actual_new_bounds.set_width(
std::max(min_size.width(), actual_new_bounds.width()));
actual_new_bounds.set_height(
std::max(min_size.height(), actual_new_bounds.height()));
}
gfx::Rect old_bounds = GetTargetBounds(); gfx::Rect old_bounds = GetTargetBounds();
// Always need to set the layer's bounds -- even if it is to the same thing. // Always need to set the layer's bounds -- even if it is to the same thing.
......
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