Skip to content

Commit

Permalink
Makes windows obey their maximum size constraints on chromeos.
Browse files Browse the repository at this point in the history
- Prevents windows from resizing bigger than their max size
- Prevents windows from snapping when they have max size defined
- Prevents windows from maximizing when they have max size defined


BUG=152065


Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=168447

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169402 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
koz@chromium.org committed Nov 26, 2012
1 parent 3da11ba commit fa574b6
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ash/wm/custom_frame_view_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ gfx::Size CustomFrameViewAsh::GetMinimumSize() {
return frame_painter_->GetMinimumSize(this);
}

gfx::Size CustomFrameViewAsh::GetMaximumSize() {
return frame_painter_->GetMaximumSize(this);
}

////////////////////////////////////////////////////////////////////////////////
// views::ButtonListener overrides:
void CustomFrameViewAsh::ButtonPressed(views::Button* sender,
Expand Down
1 change: 1 addition & 0 deletions ash/wm/custom_frame_view_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
virtual std::string GetClassName() const OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual gfx::Size GetMinimumSize() OVERRIDE;
virtual gfx::Size GetMaximumSize() OVERRIDE;

// views::ButtonListener overrides:
virtual void ButtonPressed(views::Button* sender,
Expand Down
4 changes: 4 additions & 0 deletions ash/wm/frame_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ gfx::Size FramePainter::GetMinimumSize(views::NonClientFrameView* view) {
return min_size;
}

gfx::Size FramePainter::GetMaximumSize(views::NonClientFrameView* view) {
return frame_->client_view()->GetMaximumSize();
}

int FramePainter::GetRightInset() const {
gfx::Size close_size = close_button_->GetPreferredSize();
gfx::Size size_button_size = size_button_->GetPreferredSize();
Expand Down
1 change: 1 addition & 0 deletions ash/wm/frame_painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ASH_EXPORT FramePainter : public aura::WindowObserver,
int NonClientHitTest(views::NonClientFrameView* view,
const gfx::Point& point);
gfx::Size GetMinimumSize(views::NonClientFrameView* view);
gfx::Size GetMaximumSize(views::NonClientFrameView* view);

// Returns the inset from the right edge.
int GetRightInset() const;
Expand Down
6 changes: 6 additions & 0 deletions ash/wm/window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ int WindowResizer::GetWidthForDrag(const Details& details,
// And don't let the window go bigger than the display.
int max_width = Shell::GetScreen()->GetDisplayNearestWindow(
details.window).bounds().width();
gfx::Size max_size = details.window->delegate()->GetMaximumSize();
if (max_size.width() != 0)
max_width = std::min(max_width, max_size.width());
if (width > max_width) {
width = max_width;
*delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() -
Expand Down Expand Up @@ -354,6 +357,9 @@ int WindowResizer::GetHeightForDrag(const Details& details,
// And don't let the window go bigger than the display.
int max_height = Shell::GetScreen()->GetDisplayNearestWindow(
details.window).bounds().height();
gfx::Size max_size = details.window->delegate()->GetMaximumSize();
if (max_size.height() != 0)
max_height = std::min(max_height, max_size.height());
if (height > max_height) {
height = max_height;
*delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() -
Expand Down
6 changes: 6 additions & 0 deletions ash/wm/window_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
Expand Down Expand Up @@ -83,6 +84,11 @@ bool CanResizeWindow(const aura::Window* window) {
return window->GetProperty(aura::client::kCanResizeKey);
}

bool CanSnapWindow(aura::Window* window) {
// If a window has a maximum size defined, snapping may make it too big.
return window->delegate()->GetMaximumSize().IsEmpty();
}

bool IsWindowNormal(const aura::Window* window) {
return IsWindowStateNormal(window->GetProperty(aura::client::kShowStateKey));
}
Expand Down
3 changes: 3 additions & 0 deletions ash/wm/window_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ASH_EXPORT bool CanMaximizeWindow(const aura::Window* window);
// Returns true if |window| can be resized.
ASH_EXPORT bool CanResizeWindow(const aura::Window* window);

// Returns true if |window| can be snapped to the left or right.
ASH_EXPORT bool CanSnapWindow(aura::Window* window);

// Returns true if |window| is normal or default.
ASH_EXPORT bool IsWindowNormal(const aura::Window* window);

Expand Down
3 changes: 3 additions & 0 deletions ash/wm/workspace/workspace_window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location,
if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
return;

if (!wm::CanSnapWindow(window()))
return;

SnapType last_type = snap_type_;
snap_type_ = GetSnapType(location);
if (snap_type_ == SNAP_NONE || snap_type_ != last_type) {
Expand Down
1 change: 1 addition & 0 deletions ash/wm/workspace/workspace_window_resizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
private:
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomStyle);
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, CancelSnapPhantom);
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomSnapMaxSize);

// Type of snapping.
enum SnapType {
Expand Down
58 changes: 58 additions & 0 deletions ash/wm/workspace/workspace_window_resizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ class TestWindowDelegate : public aura::test::TestWindowDelegate {
min_size_ = size;
}

void set_max_size(const gfx::Size& size) {
max_size_ = size;
}

private:
// Overridden from aura::Test::TestWindowDelegate:
virtual gfx::Size GetMinimumSize() const OVERRIDE {
return min_size_;
}

virtual gfx::Size GetMaximumSize() const OVERRIDE {
return max_size_;
}

gfx::Size min_size_;
gfx::Size max_size_;

DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
};
Expand Down Expand Up @@ -1465,5 +1474,54 @@ TEST_F(WorkspaceWindowResizerTest, CheckUserWindowMangedFlags) {
}
}

// Test that a window with a specified max size doesn't exceed it when dragged.
TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) {
window_->SetBounds(gfx::Rect(0, 0, 400, 300));
delegate_.set_max_size(gfx::Size(401, 301));

scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
EXPECT_EQ(401, window_->bounds().width());
EXPECT_EQ(301, window_->bounds().height());
}

// Test that a window with a specified max width doesn't restrict its height.
TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) {
window_->SetBounds(gfx::Rect(0, 0, 400, 300));
delegate_.set_max_size(gfx::Size(401, 0));

scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
EXPECT_EQ(401, window_->bounds().width());
EXPECT_EQ(302, window_->bounds().height());
}

// Test that a window with a specified max size can't be snapped.
TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) {
{
// With max size not set we get a phantom window controller for dragging off
// the right hand side.
window_->SetBounds(gfx::Rect(0, 0, 300, 200));

scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
EXPECT_TRUE(resizer->snap_phantom_window_controller_.get());
}
{
// With max size defined, we get no phantom window.
window_->SetBounds(gfx::Rect(0, 0, 300, 200));
delegate_.set_max_size(gfx::Size(300, 200));

scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
}
}

} // namespace internal
} // namespace ash
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/extensions/shell_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ bool ShellWindowViews::CanResize() const {
}

bool ShellWindowViews::CanMaximize() const {
return CanResize();
return maximum_size_.IsEmpty();
}

views::View* ShellWindowViews::GetContentsView() {
Expand Down
4 changes: 4 additions & 0 deletions content/browser/renderer_host/render_widget_host_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,10 @@ gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
return gfx::Size();
}

gfx::Size RenderWidgetHostViewAura::GetMaximumSize() const {
return gfx::Size();
}

void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
// We care about this only in fullscreen mode, where there is no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class RenderWidgetHostViewAura

// Overridden from aura::WindowDelegate:
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE;
Expand Down
4 changes: 4 additions & 0 deletions content/browser/web_contents/web_contents_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ gfx::Size WebContentsViewAura::GetMinimumSize() const {
return gfx::Size();
}

gfx::Size WebContentsViewAura::GetMaximumSize() const {
return gfx::Size();
}

void WebContentsViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
SizeChangedCommon(new_bounds.size());
Expand Down
1 change: 1 addition & 0 deletions content/browser/web_contents/web_contents_view_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class CONTENT_EXPORT WebContentsViewAura

// Overridden from aura::WindowDelegate:
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE;
Expand Down
5 changes: 5 additions & 0 deletions ui/aura/demo/demo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class DemoWindowDelegate : public aura::WindowDelegate {
virtual gfx::Size GetMinimumSize() const OVERRIDE {
return gfx::Size();
}

virtual gfx::Size GetMaximumSize() const OVERRIDE {
return gfx::Size();
}

virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE {}
virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE {}
Expand Down
4 changes: 4 additions & 0 deletions ui/aura/test/test_window_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ gfx::Size TestWindowDelegate::GetMinimumSize() const {
return gfx::Size();
}

gfx::Size TestWindowDelegate::GetMaximumSize() const {
return gfx::Size();
}

void TestWindowDelegate::OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
}
Expand Down
1 change: 1 addition & 0 deletions ui/aura/test/test_window_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestWindowDelegate : public WindowDelegate {

// Overridden from WindowDelegate:
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnFocus(Window* old_focused_window) OVERRIDE;
Expand Down
3 changes: 3 additions & 0 deletions ui/aura/window_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class AURA_EXPORT WindowDelegate : public ui::EventHandler {
// Returns the window's minimum size, or size 0,0 if there is no limit.
virtual gfx::Size GetMinimumSize() const = 0;

// Returns the window's maximum size, or size 0,0 if there is no limit.
virtual gfx::Size GetMaximumSize() const = 0;

// Called when the Window's position and/or size changes.
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) = 0;
Expand Down
4 changes: 4 additions & 0 deletions ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ gfx::Size DesktopNativeWidgetAura::GetMinimumSize() const {
return native_widget_delegate_->GetMinimumSize();
}

gfx::Size DesktopNativeWidgetAura::GetMaximumSize() const {
return native_widget_delegate_->GetMaximumSize();
}

void DesktopNativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
if (old_bounds.origin() != new_bounds.origin())
Expand Down
1 change: 1 addition & 0 deletions ui/views/widget/desktop_aura/desktop_native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class VIEWS_EXPORT DesktopNativeWidgetAura

// Overridden from aura::WindowDelegate:
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE;
Expand Down
4 changes: 4 additions & 0 deletions ui/views/widget/native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ gfx::Size NativeWidgetAura::GetMinimumSize() const {
return delegate_->GetMinimumSize();
}

gfx::Size NativeWidgetAura::GetMaximumSize() const {
return delegate_->GetMaximumSize();
}

void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
if (old_bounds.origin() != new_bounds.origin())
Expand Down
1 change: 1 addition & 0 deletions ui/views/widget/native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,

// Overridden from aura::WindowDelegate:
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE;
Expand Down

0 comments on commit fa574b6

Please sign in to comment.