Index: ash/root_window_controller.cc |
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc |
index 45c0f7a6372d750e7f0a6d9088f6c7024f9a02d4..e878fa9d1a436e70d029c52dede6b4b25bb77d14 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 AdjustBoundsRelativeToSize(const gfx::Size& src_size, |
varkha
2013/12/12 16:20:46
nit: Maybe ShiftOriginRelativeToParentSize or Move
oshima
2013/12/12 19:07:14
Changed to MoveOriginRelativeToSize, as there is n
|
+ 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(); |
+ AdjustBoundsRelativeToSize(src_size, dst_size, &local_bounds); |
+ } |
+ |
+ if (has_restore_bounds) { |
restore_bounds = state->GetRestoreBoundsInParent(); |
+ AdjustBoundsRelativeToSize(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); |
} |