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

Side by Side Diff: ash/display/screen_position_controller.cc

Issue 37733003: Make GetRootWindow() return a Window instead of a RootWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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
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/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
(...skipping 17 matching lines...) Expand all
28 bool ShouldStayInSameRootWindow(const aura::Window* window) { 28 bool ShouldStayInSameRootWindow(const aura::Window* window) {
29 return window && 29 return window &&
30 (window->GetProperty(internal::kStayInSameRootWindowKey) || 30 (window->GetProperty(internal::kStayInSameRootWindowKey) ||
31 ShouldStayInSameRootWindow(window->parent())); 31 ShouldStayInSameRootWindow(window->parent()));
32 } 32 }
33 33
34 // Move all transient children to |dst_root|, including the ones in 34 // Move all transient children to |dst_root|, including the ones in
35 // the child windows and transient children of the transient children. 35 // the child windows and transient children of the transient children.
36 void MoveAllTransientChildrenToNewRoot(const gfx::Display& display, 36 void MoveAllTransientChildrenToNewRoot(const gfx::Display& display,
37 aura::Window* window) { 37 aura::Window* window) {
38 aura::RootWindow* dst_root = Shell::GetInstance()->display_controller()-> 38 aura::Window* dst_root = Shell::GetInstance()->display_controller()->
39 GetRootWindowForDisplayId(display.id()); 39 GetRootWindowForDisplayId(display.id());
40 aura::Window::Windows transient_children = window->transient_children(); 40 aura::Window::Windows transient_children = window->transient_children();
41 for (aura::Window::Windows::iterator iter = transient_children.begin(); 41 for (aura::Window::Windows::iterator iter = transient_children.begin();
42 iter != transient_children.end(); ++iter) { 42 iter != transient_children.end(); ++iter) {
43 aura::Window* transient_child = *iter; 43 aura::Window* transient_child = *iter;
44 int container_id = transient_child->parent()->id(); 44 int container_id = transient_child->parent()->id();
45 DCHECK_GE(container_id, 0); 45 DCHECK_GE(container_id, 0);
46 aura::Window* container = Shell::GetContainer(dst_root, container_id); 46 aura::Window* container = Shell::GetContainer(dst_root, container_id);
47 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen(); 47 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen();
48 container->AddChild(transient_child); 48 container->AddChild(transient_child);
(...skipping 10 matching lines...) Expand all
59 } 59 }
60 60
61 // Finds the root window at |location| in |window|'s coordinates and returns a 61 // Finds the root window at |location| in |window|'s coordinates and returns a
62 // pair of root window and location in that root window's coordinates. The 62 // pair of root window and location in that root window's coordinates. The
63 // function usually returns |window->GetRootWindow()|, but if the mouse pointer 63 // function usually returns |window->GetRootWindow()|, but if the mouse pointer
64 // is moved outside the |window|'s root while the mouse is captured, it returns 64 // is moved outside the |window|'s root while the mouse is captured, it returns
65 // the other root window. 65 // the other root window.
66 std::pair<aura::RootWindow*, gfx::Point> GetRootWindowRelativeToWindow( 66 std::pair<aura::RootWindow*, gfx::Point> GetRootWindowRelativeToWindow(
67 aura::Window* window, 67 aura::Window* window,
68 const gfx::Point& location) { 68 const gfx::Point& location) {
69 aura::RootWindow* root_window = window->GetRootWindow(); 69 aura::Window* root_window = window->GetRootWindow();
70 gfx::Point location_in_root(location); 70 gfx::Point location_in_root(location);
71 aura::Window::ConvertPointToTarget(window, root_window, &location_in_root); 71 aura::Window::ConvertPointToTarget(window, root_window, &location_in_root);
72 72
73 #if defined(USE_X11) 73 #if defined(USE_X11)
74 if (!root_window->ContainsPointInRoot(location_in_root)) { 74 if (!root_window->ContainsPointInRoot(location_in_root)) {
75 // This conversion is necessary to deal with X's passive input 75 // This conversion is necessary to deal with X's passive input
76 // grab while dragging window. For example, if we have two 76 // grab while dragging window. For example, if we have two
77 // displays, say 1000x1000 (primary) and 500x500 (extended one 77 // displays, say 1000x1000 (primary) and 500x500 (extended one
78 // on the right), and start dragging a window at (999, 123), and 78 // on the right), and start dragging a window at (999, 123), and
79 // then move the pointer to the right, the pointer suddenly 79 // then move the pointer to the right, the pointer suddenly
80 // warps to the extended display. The destination is (0, 123) in 80 // warps to the extended display. The destination is (0, 123) in
81 // the secondary root window's coordinates, or (1000, 123) in 81 // the secondary root window's coordinates, or (1000, 123) in
82 // the screen coordinates. However, since the mouse is captured 82 // the screen coordinates. However, since the mouse is captured
83 // by X during drag, a weird LocatedEvent, something like (0, 1123) 83 // by X during drag, a weird LocatedEvent, something like (0, 1123)
84 // in the *primary* root window's coordinates, is sent to Chrome 84 // in the *primary* root window's coordinates, is sent to Chrome
85 // (Remember that in the native X11 world, the two root windows 85 // (Remember that in the native X11 world, the two root windows
86 // are always stacked vertically regardless of the display 86 // are always stacked vertically regardless of the display
87 // layout in Ash). We need to figure out that (0, 1123) in the 87 // layout in Ash). We need to figure out that (0, 1123) in the
88 // primary root window's coordinates is actually (0, 123) in the 88 // primary root window's coordinates is actually (0, 123) in the
89 // extended root window's coordinates. 89 // extended root window's coordinates.
90 90
91 gfx::Point location_in_native(location_in_root); 91 gfx::Point location_in_native(location_in_root);
92 root_window->ConvertPointToNativeScreen(&location_in_native); 92 root_window->GetDispatcher()->ConvertPointToNativeScreen(
93 &location_in_native);
93 94
94 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 95 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
95 for (size_t i = 0; i < root_windows.size(); ++i) { 96 for (size_t i = 0; i < root_windows.size(); ++i) {
96 const gfx::Rect native_bounds( 97 const gfx::Rect native_bounds(
97 root_windows[i]->GetHostOrigin(), 98 root_windows[i]->GetHostOrigin(),
98 root_windows[i]->GetHostSize()); // in px. 99 root_windows[i]->GetHostSize()); // in px.
99 if (native_bounds.Contains(location_in_native)) { 100 if (native_bounds.Contains(location_in_native)) {
100 root_window = root_windows[i]; 101 root_window = root_windows[i];
101 location_in_root = location_in_native; 102 location_in_root = location_in_native;
102 root_window->ConvertPointFromNativeScreen(&location_in_root); 103 root_window->GetDispatcher()->ConvertPointFromNativeScreen(
104 &location_in_root);
103 break; 105 break;
104 } 106 }
105 } 107 }
106 } 108 }
107 #else 109 #else
108 // TODO(yusukes): Support non-X11 platforms if necessary. 110 // TODO(yusukes): Support non-X11 platforms if necessary.
109 #endif 111 #endif
110 112
111 return std::make_pair(root_window, location_in_root); 113 return std::make_pair(root_window->GetDispatcher(), location_in_root);
112 } 114 }
113 115
114 } // namespace 116 } // namespace
115 117
116 namespace internal { 118 namespace internal {
117 119
118 void ScreenPositionController::ConvertPointToScreen( 120 void ScreenPositionController::ConvertPointToScreen(
119 const aura::Window* window, 121 const aura::Window* window,
120 gfx::Point* point) { 122 gfx::Point* point) {
121 const aura::RootWindow* root = window->GetRootWindow(); 123 const aura::Window* root = window->GetRootWindow();
122 aura::Window::ConvertPointToTarget(window, root, point); 124 aura::Window::ConvertPointToTarget(window, root, point);
123 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( 125 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow(
124 const_cast<aura::RootWindow*>(root)).bounds().origin(); 126 const_cast<aura::Window*>(root)).bounds().origin();
125 point->Offset(display_origin.x(), display_origin.y()); 127 point->Offset(display_origin.x(), display_origin.y());
126 } 128 }
127 129
128 void ScreenPositionController::ConvertPointFromScreen( 130 void ScreenPositionController::ConvertPointFromScreen(
129 const aura::Window* window, 131 const aura::Window* window,
130 gfx::Point* point) { 132 gfx::Point* point) {
131 const aura::RootWindow* root = window->GetRootWindow(); 133 const aura::Window* root = window->GetRootWindow();
132 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( 134 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow(
133 const_cast<aura::RootWindow*>(root)).bounds().origin(); 135 const_cast<aura::Window*>(root)).bounds().origin();
134 point->Offset(-display_origin.x(), -display_origin.y()); 136 point->Offset(-display_origin.x(), -display_origin.y());
135 aura::Window::ConvertPointToTarget(root, window, point); 137 aura::Window::ConvertPointToTarget(root, window, point);
136 } 138 }
137 139
138 void ScreenPositionController::ConvertHostPointToScreen( 140 void ScreenPositionController::ConvertHostPointToScreen(
139 aura::Window* root_window, 141 aura::Window* root_window,
140 gfx::Point* point) { 142 gfx::Point* point) {
141 aura::RootWindow* root = root_window->GetRootWindow(); 143 aura::Window* root = root_window->GetRootWindow();
142 root->ConvertPointFromHost(point); 144 root->GetDispatcher()->ConvertPointFromHost(point);
143 std::pair<aura::RootWindow*, gfx::Point> pair = 145 std::pair<aura::RootWindow*, gfx::Point> pair =
144 GetRootWindowRelativeToWindow(root, *point); 146 GetRootWindowRelativeToWindow(root, *point);
145 *point = pair.second; 147 *point = pair.second;
146 ConvertPointToScreen(pair.first, point); 148 ConvertPointToScreen(pair.first, point);
147 } 149 }
148 150
149 void ScreenPositionController::SetBounds(aura::Window* window, 151 void ScreenPositionController::SetBounds(aura::Window* window,
150 const gfx::Rect& bounds, 152 const gfx::Rect& bounds,
151 const gfx::Display& display) { 153 const gfx::Display& display) {
152 DCHECK_NE(-1, display.id()); 154 DCHECK_NE(-1, display.id());
153 if (!window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { 155 if (!window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) {
154 window->SetBounds(bounds); 156 window->SetBounds(bounds);
155 return; 157 return;
156 } 158 }
157 159
158 // Don't move a window to other root window if: 160 // Don't move a window to other root window if:
159 // a) the window is a transient window. It moves when its 161 // a) the window is a transient window. It moves when its
160 // transient_parent moves. 162 // transient_parent moves.
161 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's 163 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's
162 // intentionally kept in the same root window even if the bounds is 164 // intentionally kept in the same root window even if the bounds is
163 // outside of the display. 165 // outside of the display.
164 if (!window->transient_parent() && 166 if (!window->transient_parent() &&
165 !ShouldStayInSameRootWindow(window)) { 167 !ShouldStayInSameRootWindow(window)) {
166 aura::RootWindow* dst_root = 168 aura::Window* dst_root =
167 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId( 169 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId(
168 display.id()); 170 display.id());
169 DCHECK(dst_root); 171 DCHECK(dst_root);
170 aura::Window* dst_container = NULL; 172 aura::Window* dst_container = NULL;
171 if (dst_root != window->GetRootWindow()) { 173 if (dst_root != window->GetRootWindow()) {
172 int container_id = window->parent()->id(); 174 int container_id = window->parent()->id();
173 // All containers that uses screen coordinates must have valid window ids. 175 // All containers that uses screen coordinates must have valid window ids.
174 DCHECK_GE(container_id, 0); 176 DCHECK_GE(container_id, 0);
175 // Don't move modal background. 177 // Don't move modal background.
176 if (!SystemModalContainerLayoutManager::IsModalBackground(window)) 178 if (!SystemModalContainerLayoutManager::IsModalBackground(window))
(...skipping 13 matching lines...) Expand all
190 if (active && focused != active) 192 if (active && focused != active)
191 tracker.Add(active); 193 tracker.Add(active);
192 194
193 dst_container->AddChild(window); 195 dst_container->AddChild(window);
194 196
195 MoveAllTransientChildrenToNewRoot(display, window); 197 MoveAllTransientChildrenToNewRoot(display, window);
196 198
197 // Restore focused/active window. 199 // Restore focused/active window.
198 if (tracker.Contains(focused)) { 200 if (tracker.Contains(focused)) {
199 aura::client::GetFocusClient(window)->FocusWindow(focused); 201 aura::client::GetFocusClient(window)->FocusWindow(focused);
202 // TODO(beng): replace with GetRootWindow().
200 ash::Shell::GetInstance()->set_target_root_window( 203 ash::Shell::GetInstance()->set_target_root_window(
201 focused->GetRootWindow()); 204 focused->GetDispatcher());
202 } else if (tracker.Contains(active)) { 205 } else if (tracker.Contains(active)) {
203 activation_client->ActivateWindow(active); 206 activation_client->ActivateWindow(active);
204 } 207 }
205 } 208 }
206 } 209 }
207 210
208 gfx::Point origin(bounds.origin()); 211 gfx::Point origin(bounds.origin());
209 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( 212 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow(
210 window).bounds().origin(); 213 window).bounds().origin();
211 origin.Offset(-display_origin.x(), -display_origin.y()); 214 origin.Offset(-display_origin.x(), -display_origin.y());
212 window->SetBounds(gfx::Rect(origin, bounds.size())); 215 window->SetBounds(gfx::Rect(origin, bounds.size()));
213 } 216 }
214 217
215 } // internal 218 } // internal
216 } // ash 219 } // ash
OLDNEW
« no previous file with comments | « ash/display/root_window_transformers_unittest.cc ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698