diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 11:19:32 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 11:19:32 +0000 |
commit | 402af442653bc6011c8221e7dc587e7e406d71c5 (patch) | |
tree | 5966b48d0b4be51d14cb20d2bfb1463397710b44 /ash | |
parent | 338e798c961ac7889552267d8a7397029449de15 (diff) | |
download | chromium_src-402af442653bc6011c8221e7dc587e7e406d71c5.zip chromium_src-402af442653bc6011c8221e7dc587e7e406d71c5.tar.gz chromium_src-402af442653bc6011c8221e7dc587e7e406d71c5.tar.bz2 |
Revert 240542 "Make sure the dragged window is smaller than work..."
Faling in ash_unittests DragWindowResizerTest.WindowDragWithMultiDisplays:
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%281%29/builds/37164
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%28dbg%29%281%29/builds/27462
http://build.chromium.org/p/chromium.memory/builders/Linux%20Chromium%20OS%20ASAN%20Tests%20%281%29/builds/14494
> Make sure the dragged window is smaller than work area in the target display.
>
> - makes sure that minimum amount of window is visible when dropped.
>
> - When moving a window to another due to display disconnect, try to keep relative position in the work are, rather than absolute position to the root window.
>
> BUG=321702
> TEST=covered by test
> RootWindowController::MoveWindows_Basic
> DragWindowResizerTest::WindowDragWithMultiDisplays
>
> Review URL: https://codereview.chromium.org/93873013
TBR=oshima@chromium.org
Review URL: https://codereview.chromium.org/108343005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240587 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/root_window_controller.cc | 34 | ||||
-rw-r--r-- | ash/root_window_controller_unittest.cc | 28 | ||||
-rw-r--r-- | ash/wm/drag_window_resizer.cc | 26 | ||||
-rw-r--r-- | ash/wm/drag_window_resizer_unittest.cc | 51 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager.cc | 22 |
5 files changed, 27 insertions, 134 deletions
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index e439ac3..0ab912a 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -51,7 +51,6 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/drag_drop_client.h" #include "ui/aura/client/tooltip_client.h" -#include "ui/aura/client/window_types.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" @@ -98,46 +97,15 @@ aura::Window* CreateContainer(int window_id, return container; } -float ToRelativeValue(int value, int src, int dst) { - return static_cast<float>(value) / static_cast<float>(src) * dst; -} - -void MoveOriginRelativeToSize(const gfx::Size& src_size, - const gfx::Size& dst_size, - gfx::Rect* bounds_in_out) { - gfx::Point origin = bounds_in_out->origin(); - bounds_in_out->set_origin(gfx::Point( - ToRelativeValue(origin.x(), src_size.width(), dst_size.width()), - ToRelativeValue(origin.y(), src_size.height(), dst_size.height()))); -} - // Reparents |window| to |new_parent|. void ReparentWindow(aura::Window* window, aura::Window* new_parent) { - const gfx::Size src_size = window->parent()->bounds().size(); - const gfx::Size dst_size = new_parent->bounds().size(); // Update the restore bounds to make it relative to the display. wm::WindowState* state = wm::GetWindowState(window); gfx::Rect restore_bounds; bool has_restore_bounds = state->HasRestoreBounds(); - - // TODO(oshima): snapped state should be handled by the layout manager. - bool update_bounds = state->IsNormalShowState() || state->IsMinimized(); - gfx::Rect local_bounds; - if (update_bounds) { - local_bounds = state->window()->bounds(); - MoveOriginRelativeToSize(src_size, dst_size, &local_bounds); - } - - if (has_restore_bounds) { + if (has_restore_bounds) restore_bounds = state->GetRestoreBoundsInParent(); - MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds); - } - new_parent->AddChild(window); - - if (update_bounds) - window->SetBounds(local_bounds); - if (has_restore_bounds) state->SetRestoreBoundsInParent(restore_bounds); } diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc index d80f62d..237a513 100644 --- a/ash/root_window_controller_unittest.cc +++ b/ash/root_window_controller_unittest.cc @@ -127,8 +127,8 @@ class RootWindowControllerTest : public test::AshTestBase { TEST_F(RootWindowControllerTest, MoveWindows_Basic) { if (!SupportsMultipleDisplays()) return; - // Windows origin should be doubled when moved to the 1st display. - UpdateDisplay("600x600,300x300"); + + UpdateDisplay("600x600,500x500"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); internal::RootWindowController* controller = Shell::GetPrimaryRootWindowController(); @@ -146,8 +146,8 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) { views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100)); maximized->Maximize(); EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow()); - EXPECT_EQ("600,0 300x253", maximized->GetWindowBoundsInScreen().ToString()); - EXPECT_EQ("0,0 300x253", + EXPECT_EQ("600,0 500x453", maximized->GetWindowBoundsInScreen().ToString()); + EXPECT_EQ("0,0 500x453", maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); @@ -156,13 +156,13 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) { EXPECT_EQ("800,10 100x100", minimized->GetWindowBoundsInScreen().ToString()); - views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100)); + views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100)); fullscreen->SetFullscreen(true); EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow()); - EXPECT_EQ("600,0 300x300", + EXPECT_EQ("600,0 500x500", fullscreen->GetWindowBoundsInScreen().ToString()); - EXPECT_EQ("0,0 300x300", + EXPECT_EQ("0,0 500x500", fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); views::Widget* unparented_control = new Widget; @@ -197,8 +197,8 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) { EXPECT_FALSE(tracker.Contains(d2)); EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); - EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString()); - EXPECT_EQ("100,20 100x100", + EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString()); + EXPECT_EQ("50,10 100x100", normal->GetNativeView()->GetBoundsInRootWindow().ToString()); // Maximized area on primary display has 3px (given as @@ -223,7 +223,7 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) { maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); - EXPECT_EQ("400,20 100x100", + EXPECT_EQ("200,10 100x100", minimized->GetWindowBoundsInScreen().ToString()); EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); @@ -235,14 +235,14 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) { // Test if the restore bounds are correctly updated. wm::GetWindowState(maximized->GetNativeView())->Restore(); - EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString()); - EXPECT_EQ("200,20 100x100", + EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString()); + EXPECT_EQ("100,10 100x100", maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); fullscreen->SetFullscreen(false); - EXPECT_EQ("500,20 100x100", + EXPECT_EQ("300,10 100x100", fullscreen->GetWindowBoundsInScreen().ToString()); - EXPECT_EQ("500,20 100x100", + EXPECT_EQ("300,10 100x100", fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); // Test if the unparented widget has moved. diff --git a/ash/wm/drag_window_resizer.cc b/ash/wm/drag_window_resizer.cc index a524d67..000d119 100644 --- a/ash/wm/drag_window_resizer.cc +++ b/ash/wm/drag_window_resizer.cc @@ -125,29 +125,9 @@ void DragWindowResizer::CompleteDrag(int event_flags) { if (dst_display.id() != screen->GetDisplayNearestWindow(GetTarget()->GetRootWindow()).id()) { - // Adjust the size and position so that it doesn't exceed the size of - // work area. - const gfx::Size& size = dst_display.work_area().size(); - gfx::Rect bounds = GetTarget()->bounds(); - if (bounds.width() > size.width()) { - int diff = bounds.width() - size.width(); - bounds.set_x(bounds.x() + diff / 2); - bounds.set_width(size.width()); - } - if (bounds.height() > size.height()) - bounds.set_height(size.height()); - - gfx::Rect dst_bounds = - ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), bounds); - - // Adjust the position so that the cursor is on the window. - if (!dst_bounds.Contains(last_mouse_location_in_screen)) { - if (last_mouse_location_in_screen.x() < dst_bounds.x()) - dst_bounds.set_x(last_mouse_location_in_screen.x()); - else if (last_mouse_location_in_screen.x() > dst_bounds.right()) - dst_bounds.set_x( - last_mouse_location_in_screen.x() - dst_bounds.width()); - } + const gfx::Rect dst_bounds = + ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), + GetTarget()->bounds()); GetTarget()->SetBoundsInScreen(dst_bounds, dst_display); } } diff --git a/ash/wm/drag_window_resizer_unittest.cc b/ash/wm/drag_window_resizer_unittest.cc index 72b96e7..04e00f2 100644 --- a/ash/wm/drag_window_resizer_unittest.cc +++ b/ash/wm/drag_window_resizer_unittest.cc @@ -162,7 +162,7 @@ TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplays) { // The secondary display is logically on the right, but on the system (e.g. X) // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. - UpdateDisplay("800x600,400x300"); + UpdateDisplay("800x600,800x600"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); ASSERT_EQ(2U, root_windows.size()); @@ -223,55 +223,6 @@ TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplays) { EXPECT_EQ(base::IntToString(expected_x) + ",10 50x60", window_->bounds().ToString()); } - // Dropping a window that is larger than the destination work area - // will shrink to fit to the work area. - window_->SetBoundsInScreen(gfx::Rect(0, 0, 700, 500), - Shell::GetScreen()->GetPrimaryDisplay()); - EXPECT_EQ(root_windows[0], window_->GetRootWindow()); - { - // Grab the top-right edge of the window and move the pointer to (0, 10) - // in the secondary root window's coordinates. - scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( - window_.get(), gfx::Point(699, 0), HTCAPTION)); - ASSERT_TRUE(resizer.get()); - resizer->Drag(CalculateDragPoint(*resizer, 101, 10), ui::EF_CONTROL_DOWN); - resizer->CompleteDrag(0); - EXPECT_EQ(root_windows[1], window_->GetRootWindow()); - // Window size should be adjusted to fit to the work area - EXPECT_EQ("400x253", window_->bounds().size().ToString()); - gfx::Rect window_bounds_in_screen = window_->GetBoundsInScreen(); - gfx::Rect intersect(window_->GetRootWindow()->GetBoundsInScreen()); - intersect.Intersect(window_bounds_in_screen); - EXPECT_LE(10, intersect.width()); - EXPECT_LE(10, intersect.height()); - EXPECT_TRUE(window_bounds_in_screen.Contains(gfx::Point(800, 10))); - } - - // Dropping a window that is larger than the destination work area - // will shrink to fit to the work area. - window_->SetBoundsInScreen(gfx::Rect(0, 0, 700, 500), - Shell::GetScreen()->GetPrimaryDisplay()); - EXPECT_EQ(root_windows[0], window_->GetRootWindow()); - { - // Grab the top-left edge of the window and move the pointer to (150, 10) - // in the secondary root window's coordinates. Make sure the window is - // shrink in such a way that it keeps the cursor within. - scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( - window_.get(), gfx::Point(0, 0), HTCAPTION)); - ASSERT_TRUE(resizer.get()); - resizer->Drag(CalculateDragPoint(*resizer, 799, 10), ui::EF_CONTROL_DOWN); - resizer->Drag(CalculateDragPoint(*resizer, 850, 10), ui::EF_CONTROL_DOWN); - resizer->CompleteDrag(0); - EXPECT_EQ(root_windows[1], window_->GetRootWindow()); - // Window size should be adjusted to fit to the work area - EXPECT_EQ("400x253", window_->bounds().size().ToString()); - gfx::Rect window_bounds_in_screen = window_->GetBoundsInScreen(); - gfx::Rect intersect(window_->GetRootWindow()->GetBoundsInScreen()); - intersect.Intersect(window_bounds_in_screen); - EXPECT_LE(10, intersect.width()); - EXPECT_LE(10, intersect.height()); - EXPECT_TRUE(window_bounds_in_screen.Contains(gfx::Point(850, 10))); - } } // Verifies that dragging the active window to another display makes the new diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc index f388632..fe7d748 100644 --- a/ash/wm/workspace/workspace_layout_manager.cc +++ b/ash/wm/workspace/workspace_layout_manager.cc @@ -264,28 +264,22 @@ void WorkspaceLayoutManager::AdjustWindowBoundsWhenAdded( if (window_state->window()->bounds().IsEmpty()) return; + if (window_state->is_dragged()) + return; + + if (SetMaximizedOrFullscreenBounds(window_state)) + return; + Window* window = window_state->window(); gfx::Rect bounds = window->bounds(); - + int min_width = bounds.width() * kMinimumPercentOnScreenArea; + int min_height = bounds.height() * kMinimumPercentOnScreenArea; // Use entire display instead of workarea because the workarea can // be further shrunk by the docked area. The logic ensures 30% // visibility which should be enough to see where the window gets // moved. gfx::Rect display_area = ScreenAsh::GetDisplayBoundsInParent(window); - if (window_state->is_dragged()) { - ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility( - display_area, &bounds); - if (window->bounds() != bounds) - window->SetBounds(bounds); - return; - } - - if (SetMaximizedOrFullscreenBounds(window_state)) - return; - - int min_width = bounds.width() * kMinimumPercentOnScreenArea; - int min_height = bounds.height() * kMinimumPercentOnScreenArea; ash::wm::AdjustBoundsToEnsureWindowVisibility( display_area, min_width, min_height, &bounds); AdjustSnappedBounds(window_state, &bounds); |