Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2348)

Unified Diff: ash/display/screen_position_controller.cc

Issue 10795027: Move a window if the sceren bounds being set is in other display. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adjust for win_aura Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ash/extended_desktop_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « no previous file | ash/extended_desktop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698