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..4ac525d0d6b3c34a40fe3f59f81260aebb3e8c64 100644 |
--- a/ash/display/screen_position_controller.cc |
+++ b/ash/display/screen_position_controller.cc |
@@ -5,13 +5,49 @@ |
#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/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 MoveAllTransientChildToNewRoot(aura::RootWindow* dst_root, |
sky
2012/07/20 15:06:07
Child->Children or MoveAllTransientsToNewRoot
oshima
2012/07/20 17:03:11
Done.
|
+ aura::Window* window) { |
+ aura::Window::Windows transient_children = window->transient_children(); |
+ for (aura::Window::Windows::iterator iter = transient_children.begin(); |
sky
2012/07/20 15:06:07
I'm worried that all this moving might have side e
oshima
2012/07/20 17:03:11
I do too, but transient children needs to be in th
|
+ 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. |
+ MoveAllTransientChildToNewRoot(dst_root, |
+ transient_child); |
+ } |
+ // Move transient children of the child wnidows if any. |
sky
2012/07/20 15:06:07
wnidows -> windows
oshima
2012/07/20 17:03:11
Done.
|
+ aura::Window::Windows children = window->children(); |
+ for (aura::Window::Windows::iterator iter = children.begin(); |
+ iter != children.end(); ++iter) |
+ MoveAllTransientChildToNewRoot(dst_root, *iter); |
+} |
+ |
+} // namespace |
+ |
namespace internal { |
void ScreenPositionController::ConvertPointToScreen( |
@@ -48,9 +84,44 @@ 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* suggested_container = NULL; |
sky
2012/07/20 15:06:07
suggested_container -> dest_container
oshima
2012/07/20 17:03:11
Done.
|
+ if (dst_root != window->GetRootWindow()) { |
+ int container_id = window->parent()->id(); |
+ // All containers that uses screen coordinates must have non zero |
+ // id. |
+ DCHECK_GE(container_id, 0); |
sky
2012/07/20 15:06:07
DCHECK_GT
oshima
2012/07/20 17:03:11
Sorry, comment was wrong. 0 is valid container id.
|
+ suggested_container = Shell::GetContainer(dst_root, container_id); |
+ } |
+ |
+ if (suggested_container && window->parent() != suggested_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; |
sky
2012/07/20 15:06:07
Why do you need to do this for focus/activation? I
oshima
2012/07/20 17:03:11
Moving window may reset the focus, and focused wid
|
+ if (focused) |
+ tracker.Add(focused); |
+ if (active && focused != active) |
+ tracker.Add(active); |
+ |
+ suggested_container->AddChild(window); |
+ |
+ MoveAllTransientChildToNewRoot(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(); |