diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 08:21:27 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 08:21:27 +0000 |
commit | 4aa67549b1fad9188397e64bd7ca2358d69cde35 (patch) | |
tree | 0c01f07d815118577ca849f6d24fb753625cf951 /ash/root_window_controller.cc | |
parent | 7ed2e46105ab0ead6ef8477719ada094e163b1b7 (diff) | |
download | chromium_src-4aa67549b1fad9188397e64bd7ca2358d69cde35.zip chromium_src-4aa67549b1fad9188397e64bd7ca2358d69cde35.tar.gz chromium_src-4aa67549b1fad9188397e64bd7ca2358d69cde35.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240542 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/root_window_controller.cc')
-rw-r--r-- | ash/root_window_controller.cc | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index 0ab912a..e439ac3 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -51,6 +51,7 @@ #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" @@ -97,15 +98,46 @@ 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(); - if (has_restore_bounds) + + // 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) { 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); } |