summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/dock/docked_window_layout_manager.cc11
-rw-r--r--ash/wm/panels/panel_layout_manager.cc7
-rw-r--r--ash/wm/window_state.cc17
-rw-r--r--ash/wm/window_state_unittest.cc61
4 files changed, 94 insertions, 2 deletions
diff --git a/ash/wm/dock/docked_window_layout_manager.cc b/ash/wm/dock/docked_window_layout_manager.cc
index 063c467c..daddd1f 100644
--- a/ash/wm/dock/docked_window_layout_manager.cc
+++ b/ash/wm/dock/docked_window_layout_manager.cc
@@ -707,8 +707,17 @@ void DockedWindowLayoutManager::OnChildWindowVisibilityChanged(
void DockedWindowLayoutManager::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
+ // The minimum constraints have to be applied first by the layout manager.
+ gfx::Rect actual_new_bounds(requested_bounds);
+ if (child->delegate()) {
+ const gfx::Size& min_size = child->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()));
+ }
// Whenever one of our windows is moved or resized enforce layout.
- SetChildBoundsDirect(child, requested_bounds);
+ SetChildBoundsDirect(child, actual_new_bounds);
if (IsPopupOrTransient(child))
return;
ShelfLayoutManager* shelf_layout =
diff --git a/ash/wm/panels/panel_layout_manager.cc b/ash/wm/panels/panel_layout_manager.cc
index 8954e57..5a8d2e9 100644
--- a/ash/wm/panels/panel_layout_manager.cc
+++ b/ash/wm/panels/panel_layout_manager.cc
@@ -27,6 +27,7 @@
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tracker.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
@@ -433,6 +434,12 @@ void PanelLayoutManager::SetChildBounds(aura::Window* child,
panel_windows_.insert(new_position, dragged_panel_info);
}
}
+ // Respect the minimum size of the window.
+ if (child->delegate()) {
+ const gfx::Size& min_size = child->delegate()->GetMinimumSize();
+ bounds.set_width(std::max(min_size.width(), bounds.width()));
+ bounds.set_height(std::max(min_size.height(), bounds.height()));
+ }
SetChildBoundsDirect(child, bounds);
Relayout();
diff --git a/ash/wm/window_state.cc b/ash/wm/window_state.cc
index f0bed4b..7c5c167 100644
--- a/ash/wm/window_state.cc
+++ b/ash/wm/window_state.cc
@@ -24,6 +24,7 @@
#include "ui/compositor/layer_tree_owner.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/display.h"
+#include "ui/gfx/screen.h"
#include "ui/wm/core/window_util.h"
namespace ash {
@@ -357,7 +358,21 @@ void WindowState::NotifyPostStateTypeChange(
}
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) {
diff --git a/ash/wm/window_state_unittest.cc b/ash/wm/window_state_unittest.cc
index 2b4e8a3..b81f4ca 100644
--- a/ash/wm/window_state_unittest.cc
+++ b/ash/wm/window_state_unittest.cc
@@ -130,6 +130,67 @@ TEST_F(WindowStateTest, SnapWindowMinimumSize) {
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_F(WindowStateTest, SnapWindowSetBounds) {
if (!SupportsHostWindowResize())