diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 22:44:37 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 22:44:37 +0000 |
commit | fa9d49ff4622e53722a971ec2c3d50674b1e541a (patch) | |
tree | 578d93871db645f9e924fad2e1468f3d7c4758db /ash | |
parent | 1e4ebc60c886041ba2c3101349f068bdba4c2785 (diff) | |
download | chromium_src-fa9d49ff4622e53722a971ec2c3d50674b1e541a.zip chromium_src-fa9d49ff4622e53722a971ec2c3d50674b1e541a.tar.gz chromium_src-fa9d49ff4622e53722a971ec2c3d50674b1e541a.tar.bz2 |
Fixes a couple of bugs related to window sizing:
. Make RenderWidgetHostViewAura pass down the work area.
. Makes ash force the window to no bigger than the work area. The last
one is a bit dubious and may bite us at some point, but it seems we
should enforce some constraint.
BUG=155629
TEST=covered by tests
R=ben@chromium.org,oshima@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11253002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163940 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/screen_ash.h | 1 | ||||
-rw-r--r-- | ash/wm/workspace/colored_window_controller.cc | 10 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager2.cc | 18 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager2_unittest.cc | 20 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_window_resizer_unittest.cc | 18 |
5 files changed, 43 insertions, 24 deletions
diff --git a/ash/screen_ash.h b/ash/screen_ash.h index 89220e2..b737bfc 100644 --- a/ash/screen_ash.h +++ b/ash/screen_ash.h @@ -56,7 +56,6 @@ class ASH_EXPORT ScreenAsh : public gfx::Screen { static const gfx::Display& GetDisplayForId(int64 display_id); protected: - // Implementation of gfx::Screen: virtual bool IsDIPEnabled() OVERRIDE; virtual gfx::Point GetCursorScreenPoint() OVERRIDE; diff --git a/ash/wm/workspace/colored_window_controller.cc b/ash/wm/workspace/colored_window_controller.cc index 0918ea2..3ecfe29 100644 --- a/ash/wm/workspace/colored_window_controller.cc +++ b/ash/wm/workspace/colored_window_controller.cc @@ -5,6 +5,7 @@ #include "ash/wm/workspace/colored_window_controller.h" #include "ash/shell_window_ids.h" +#include "ash/wm/property_util.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" #include "ui/gfx/canvas.h" @@ -62,12 +63,15 @@ ColoredWindowController::ColoredWindowController(aura::Window* parent, params.accept_events = false; params.layer_type = ui::LAYER_SOLID_COLOR; widget->Init(params); + // Do this so the parent doesn't attempt to enforce any bounds constraints on + // us. + SetTrackedByWorkspace(widget->GetNativeView(), false); widget->GetNativeView()->SetProperty(aura::client::kAnimationsDisabledKey, true); widget->GetNativeView()->SetName(window_name); - // Sometimes |parent| has kUsesScreenCoordinatesKey which causes a crash - // if parent belongs to the secondary display. - widget->GetNativeWindow()->SetBounds(parent->bounds()); + // The bounds should match the parent exactly. We don't go through + // Widget::SetBounds() as that may try to place on a different display. + widget->GetNativeWindow()->SetBounds(gfx::Rect(parent->bounds())); } ColoredWindowController::~ColoredWindowController() { diff --git a/ash/wm/workspace/workspace_layout_manager2.cc b/ash/wm/workspace/workspace_layout_manager2.cc index 29e4c6c..ecc5227 100644 --- a/ash/wm/workspace/workspace_layout_manager2.cc +++ b/ash/wm/workspace/workspace_layout_manager2.cc @@ -136,8 +136,14 @@ void WorkspaceLayoutManager2::SetChildBounds( } gfx::Rect child_bounds(requested_bounds); // Some windows rely on this to set their initial bounds. - if (!SetMaximizedOrFullscreenBounds(child)) + if (!SetMaximizedOrFullscreenBounds(child)) { + // Non-maximized/full-screen windows have their size constrained to the + // work-area. + child_bounds.set_width(std::min(work_area_.width(), child_bounds.width())); + child_bounds.set_height( + std::min(work_area_.height(), child_bounds.height())); SetChildBoundsDirect(child, child_bounds); + } workspace_manager()->OnWorkspaceWindowChildBoundsChanged(workspace_, child); } @@ -293,9 +299,11 @@ void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange( bounds.AdjustToFit(work_area_); window->SetBounds(bounds); } else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) { - // If the window is completely outside the display work area, then move it - // enough to be visible again. + // Make sure the window isn't bigger than the display work area and that + // at least a portion of it is visible. gfx::Rect bounds = window->bounds(); + bounds.set_width(std::min(bounds.width(), work_area_.width())); + bounds.set_height(std::min(bounds.height(), work_area_.height())); if (!work_area_.Intersects(bounds)) { int y_offset = 0; if (work_area_.bottom() < bounds.y()) { @@ -310,10 +318,10 @@ void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange( } else if (bounds.right() < work_area_.x()) { x_offset = work_area_.x() - bounds.right() + kMinimumOnScreenArea; } - bounds.Offset(x_offset, y_offset); - window->SetBounds(bounds); } + if (window->bounds() != bounds) + window->SetBounds(bounds); } } } diff --git a/ash/wm/workspace/workspace_layout_manager2_unittest.cc b/ash/wm/workspace/workspace_layout_manager2_unittest.cc index 799e013..b559a3c 100644 --- a/ash/wm/workspace/workspace_layout_manager2_unittest.cc +++ b/ash/wm/workspace/workspace_layout_manager2_unittest.cc @@ -13,7 +13,9 @@ #include "ui/aura/root_window.h" #include "ui/aura/test/test_windows.h" #include "ui/aura/window.h" +#include "ui/gfx/display.h" #include "ui/gfx/insets.h" +#include "ui/gfx/screen.h" namespace ash { @@ -136,6 +138,24 @@ TEST_F(WorkspaceLayoutManager2Test, WindowShouldBeOnScreenWhenAdded) { EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds)); } +// Verifies the size of a window is enforced to be smaller than the work area. +TEST_F(WorkspaceLayoutManager2Test, SizeToWorkArea) { + // Normal window bounds shouldn't be changed. + gfx::Size work_area( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size()); + const gfx::Rect window_bounds( + 100, 101, work_area.width() + 1, work_area.height() + 2); + scoped_ptr<aura::Window> window(CreateTestWindow(window_bounds)); + EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), + window->bounds().ToString()); + + // Directly setting the bounds triggers a slightly different code path. Verify + // that too. + window->SetBounds(window_bounds); + EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), + window->bounds().ToString()); +} + } // namespace } // namespace ash diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc index f625df7..bbc6c53 100644 --- a/ash/wm/workspace/workspace_window_resizer_unittest.cc +++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc @@ -1026,19 +1026,6 @@ TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) { EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); } -// Verifies a window taller than work area height doesn't snap above the top of -// the work area. -TEST_F(WorkspaceWindowResizerTest, TallWindow) { - aura::RootWindow* root = Shell::GetPrimaryRootWindow(); - Shell::GetInstance()->SetDisplayWorkAreaInsets( - root, gfx::Insets(0, 0, 50, 0)); - window_->SetBounds(gfx::Rect(0, 0, 320, 560)); - scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( - window_.get(), gfx::Point(), HTCAPTION, empty_windows())); - resizer->Drag(CalculateDragPoint(*resizer, 0, 9), 0); - EXPECT_EQ("0,9 320x560", window_->bounds().ToString()); -} - TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) { window_->SetBounds(gfx::Rect(96, 112, 320, 160)); scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( @@ -1108,7 +1095,8 @@ TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) { // Verifies that a dragged window will restore to its pre-maximized size. TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) { - window_->SetBounds(gfx::Rect(0, 0, 1000, 1000)); + const gfx::Rect initial_bounds(0, 0, 200, 400); + window_->SetBounds(initial_bounds); SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160)); scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( window_.get(), gfx::Point(), HTCAPTION, empty_windows())); @@ -1117,7 +1105,7 @@ TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) { // the window should get restored. resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0); resizer->RevertDrag(); - EXPECT_EQ("0,0 1000x1000", window_->bounds().ToString()); + EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString()); EXPECT_EQ("96,112 320x160", GetRestoreBoundsInScreen(window_.get())->ToString()); } |