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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/extended_desktop_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/display/screen_position_controller.h" 5 #include "ash/display/screen_position_controller.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/system_modal_container_layout_manager.h"
9 #include "ash/wm/window_properties.h" 11 #include "ash/wm/window_properties.h"
12 #include "ui/aura/client/activation_client.h"
13 #include "ui/aura/client/capture_client.h"
14 #include "ui/aura/client/stacking_client.h"
15 #include "ui/aura/focus_manager.h"
10 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window_tracker.h"
11 #include "ui/gfx/display.h" 18 #include "ui/gfx/display.h"
12 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
13 20
14 namespace ash { 21 namespace ash {
22 namespace {
23
24 // Move all transient children to |dst_root|, including the ones in
25 // the child windows and transient children of the transient children.
26 void MoveAllTransientChildrenToNewRoot(aura::RootWindow* dst_root,
27 aura::Window* window) {
28 aura::Window::Windows transient_children = window->transient_children();
29 for (aura::Window::Windows::iterator iter = transient_children.begin();
30 iter != transient_children.end(); ++iter) {
31 aura::Window* transient_child = *iter;
32 int container_id = transient_child->parent()->id();
33 DCHECK_GE(container_id, 0);
34 aura::Window* container = Shell::GetContainer(dst_root, container_id);
35 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen();
36 container->AddChild(transient_child);
37 transient_child->SetBoundsInScreen(parent_bounds_in_screen);
38
39 // Transient children may have transient children.
40 MoveAllTransientChildrenToNewRoot(dst_root,
41 transient_child);
42 }
43 // Move transient children of the child windows if any.
44 aura::Window::Windows children = window->children();
45 for (aura::Window::Windows::iterator iter = children.begin();
46 iter != children.end(); ++iter)
47 MoveAllTransientChildrenToNewRoot(dst_root, *iter);
48 }
49
50 } // namespace
51
15 namespace internal { 52 namespace internal {
16 53
17 void ScreenPositionController::ConvertPointToScreen( 54 void ScreenPositionController::ConvertPointToScreen(
18 const aura::Window* window, 55 const aura::Window* window,
19 gfx::Point* point) { 56 gfx::Point* point) {
20 const aura::RootWindow* root = window->GetRootWindow(); 57 const aura::RootWindow* root = window->GetRootWindow();
21 aura::Window::ConvertPointToWindow(window, root, point); 58 aura::Window::ConvertPointToWindow(window, root, point);
22 if (DisplayController::IsVirtualScreenCoordinatesEnabled()) { 59 if (DisplayController::IsVirtualScreenCoordinatesEnabled()) {
23 const gfx::Point display_origin = 60 const gfx::Point display_origin =
24 gfx::Screen::GetDisplayNearestWindow( 61 gfx::Screen::GetDisplayNearestWindow(
(...skipping 16 matching lines...) Expand all
41 } 78 }
42 79
43 void ScreenPositionController::SetBounds( 80 void ScreenPositionController::SetBounds(
44 aura::Window* window, 81 aura::Window* window,
45 const gfx::Rect& bounds) { 82 const gfx::Rect& bounds) {
46 if (!DisplayController::IsVirtualScreenCoordinatesEnabled() || 83 if (!DisplayController::IsVirtualScreenCoordinatesEnabled() ||
47 !window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { 84 !window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) {
48 window->SetBounds(bounds); 85 window->SetBounds(bounds);
49 return; 86 return;
50 } 87 }
51 // TODO(oshima): Pick the new root window that most closely shares 88
52 // the bounds. For a new widget, NativeWidgetAura picks the right 89 // Don't move a transient windows to other root window.
53 // root window. 90 // It moves when its transient_parent moves.
91 if (!window->transient_parent()) {
92 aura::RootWindow* dst_root = Shell::GetRootWindowMatching(bounds);
93 aura::Window* dst_container = NULL;
94 if (dst_root != window->GetRootWindow()) {
95 int container_id = window->parent()->id();
96 // All containers that uses screen coordinates must have valid
97 // window ids.
98 DCHECK_GE(container_id, 0);
99 // Don't move modal screen.
100 if (!SystemModalContainerLayoutManager::IsModalScreen(window))
101 dst_container = Shell::GetContainer(dst_root, container_id);
102 }
103
104 if (dst_container && window->parent() != dst_container) {
105 aura::Window* focused = window->GetFocusManager()->GetFocusedWindow();
106 aura::client::ActivationClient* activation_client =
107 aura::client::GetActivationClient(window->GetRootWindow());
108 aura::Window* active = activation_client->GetActiveWindow();
109
110 aura::WindowTracker tracker;
111 if (focused)
112 tracker.Add(focused);
113 if (active && focused != active)
114 tracker.Add(active);
115
116 dst_container->AddChild(window);
117
118 MoveAllTransientChildrenToNewRoot(dst_root, window);
119
120 // Restore focused/active window.
121 if (tracker.Contains(focused))
122 window->GetFocusManager()->SetFocusedWindow(focused, NULL);
123 else if (tracker.Contains(active))
124 activation_client->ActivateWindow(active);
125 }
126 }
127
54 gfx::Point origin(bounds.origin()); 128 gfx::Point origin(bounds.origin());
55 const gfx::Point display_origin = 129 const gfx::Point display_origin =
56 gfx::Screen::GetDisplayNearestWindow(window).bounds().origin(); 130 gfx::Screen::GetDisplayNearestWindow(window).bounds().origin();
57 origin.Offset(-display_origin.x(), -display_origin.y()); 131 origin.Offset(-display_origin.x(), -display_origin.y());
58 window->SetBounds(gfx::Rect(origin, bounds.size())); 132 window->SetBounds(gfx::Rect(origin, bounds.size()));
59 } 133 }
60 134
61 } // internal 135 } // internal
62 } // ash 136 } // ash
OLDNEW
« 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