Index: ash/display/screen_position_controller.cc |
diff --git a/ash/display/screen_position_controller.cc b/ash/display/screen_position_controller.cc |
index 3c464b407d126fb6d884a48e620af7cb47c53e20..80091efd60a35172e2727984852a7d6f383e2705 100644 |
--- a/ash/display/screen_position_controller.cc |
+++ b/ash/display/screen_position_controller.cc |
@@ -5,13 +5,50 @@ |
#include "ash/display/screen_position_controller.h" |
#include "ash/display/display_controller.h" |
+#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
+#include "ash/wm/system_modal_container_layout_manager.h" |
#include "ash/wm/window_properties.h" |
+#include "ui/aura/client/activation_client.h" |
+#include "ui/aura/client/capture_client.h" |
+#include "ui/aura/client/stacking_client.h" |
+#include "ui/aura/focus_manager.h" |
#include "ui/aura/root_window.h" |
+#include "ui/aura/window_tracker.h" |
#include "ui/gfx/display.h" |
#include "ui/gfx/screen.h" |
namespace ash { |
+namespace { |
+ |
+// Move all transient children to |dst_root|, including the ones in |
+// the child windows and transient children of the transient children. |
+void MoveAllTransientChildrenToNewRoot(aura::RootWindow* dst_root, |
+ aura::Window* window) { |
+ aura::Window::Windows transient_children = window->transient_children(); |
+ for (aura::Window::Windows::iterator iter = transient_children.begin(); |
+ iter != transient_children.end(); ++iter) { |
+ aura::Window* transient_child = *iter; |
+ int container_id = transient_child->parent()->id(); |
+ DCHECK_GE(container_id, 0); |
+ aura::Window* container = Shell::GetContainer(dst_root, container_id); |
+ gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen(); |
+ container->AddChild(transient_child); |
+ transient_child->SetBoundsInScreen(parent_bounds_in_screen); |
+ |
+ // Transient children may have transient children. |
+ MoveAllTransientChildrenToNewRoot(dst_root, |
+ transient_child); |
+ } |
+ // Move transient children of the child windows if any. |
+ aura::Window::Windows children = window->children(); |
+ for (aura::Window::Windows::iterator iter = children.begin(); |
+ iter != children.end(); ++iter) |
+ MoveAllTransientChildrenToNewRoot(dst_root, *iter); |
+} |
+ |
+} // namespace |
+ |
namespace internal { |
void ScreenPositionController::ConvertPointToScreen( |
@@ -48,9 +85,46 @@ void ScreenPositionController::SetBounds( |
window->SetBounds(bounds); |
return; |
} |
- // TODO(oshima): Pick the new root window that most closely shares |
- // the bounds. For a new widget, NativeWidgetAura picks the right |
- // root window. |
+ |
+ // Don't move a transient windows to other root window. |
+ // It moves when its transient_parent moves. |
+ if (!window->transient_parent()) { |
+ aura::RootWindow* dst_root = Shell::GetRootWindowMatching(bounds); |
+ aura::Window* dst_container = NULL; |
+ if (dst_root != window->GetRootWindow()) { |
+ int container_id = window->parent()->id(); |
+ // All containers that uses screen coordinates must have valid |
+ // window ids. |
+ DCHECK_GE(container_id, 0); |
+ // Don't move modal screen. |
+ if (!SystemModalContainerLayoutManager::IsModalScreen(window)) |
+ dst_container = Shell::GetContainer(dst_root, container_id); |
+ } |
+ |
+ if (dst_container && window->parent() != dst_container) { |
+ aura::Window* focused = window->GetFocusManager()->GetFocusedWindow(); |
+ aura::client::ActivationClient* activation_client = |
+ aura::client::GetActivationClient(window->GetRootWindow()); |
+ aura::Window* active = activation_client->GetActiveWindow(); |
+ |
+ aura::WindowTracker tracker; |
+ if (focused) |
+ tracker.Add(focused); |
+ if (active && focused != active) |
+ tracker.Add(active); |
+ |
+ dst_container->AddChild(window); |
+ |
+ MoveAllTransientChildrenToNewRoot(dst_root, window); |
+ |
+ // Restore focused/active window. |
+ if (tracker.Contains(focused)) |
+ window->GetFocusManager()->SetFocusedWindow(focused, NULL); |
+ else if (tracker.Contains(active)) |
+ activation_client->ActivateWindow(active); |
+ } |
+ } |
+ |
gfx::Point origin(bounds.origin()); |
const gfx::Point display_origin = |
gfx::Screen::GetDisplayNearestWindow(window).bounds().origin(); |