| OLD | NEW |
| 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/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
| 9 #include "ash/common/wm/system_modal_container_layout_manager.h" | 9 #include "ash/common/wm/window_positioning_utils.h" |
| 10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
| 13 #include "ash/display/window_tree_host_manager.h" | 13 #include "ash/display/window_tree_host_manager.h" |
| 14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/wm/window_properties.h" | 16 #include "ash/wm/window_properties.h" |
| 17 #include "ui/aura/client/capture_client.h" | 17 #include "ui/aura/client/capture_client.h" |
| 18 #include "ui/aura/client/focus_client.h" | 18 #include "ui/aura/client/focus_client.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/aura/window_tracker.h" | 21 #include "ui/aura/window_tracker.h" |
| 22 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 23 #include "ui/compositor/dip_util.h" | 23 #include "ui/compositor/dip_util.h" |
| 24 #include "ui/display/display.h" | 24 #include "ui/display/display.h" |
| 25 #include "ui/display/screen.h" | 25 #include "ui/display/screen.h" |
| 26 #include "ui/wm/core/window_util.h" | 26 #include "ui/wm/core/window_util.h" |
| 27 #include "ui/wm/public/activation_client.h" | 27 #include "ui/wm/public/activation_client.h" |
| 28 | 28 |
| 29 namespace ash { | 29 namespace ash { |
| 30 namespace { | |
| 31 | |
| 32 // Return true if the window or its ancestor has |kStayInSameRootWindowkey| | |
| 33 // property. | |
| 34 bool ShouldStayInSameRootWindow(const aura::Window* window) { | |
| 35 return window && (window->GetProperty(kStayInSameRootWindowKey) || | |
| 36 ShouldStayInSameRootWindow(window->parent())); | |
| 37 } | |
| 38 | |
| 39 // Move all transient children to |dst_root|, including the ones in | |
| 40 // the child windows and transient children of the transient children. | |
| 41 void MoveAllTransientChildrenToNewRoot(const display::Display& display, | |
| 42 aura::Window* window) { | |
| 43 aura::Window* dst_root = Shell::GetInstance() | |
| 44 ->window_tree_host_manager() | |
| 45 ->GetRootWindowForDisplayId(display.id()); | |
| 46 aura::Window::Windows transient_children = ::wm::GetTransientChildren(window); | |
| 47 for (aura::Window::Windows::iterator iter = transient_children.begin(); | |
| 48 iter != transient_children.end(); ++iter) { | |
| 49 aura::Window* transient_child = *iter; | |
| 50 int container_id = transient_child->parent()->id(); | |
| 51 DCHECK_GE(container_id, 0); | |
| 52 aura::Window* container = Shell::GetContainer(dst_root, container_id); | |
| 53 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen(); | |
| 54 container->AddChild(transient_child); | |
| 55 transient_child->SetBoundsInScreen(parent_bounds_in_screen, display); | |
| 56 | |
| 57 // Transient children may have transient children. | |
| 58 MoveAllTransientChildrenToNewRoot(display, transient_child); | |
| 59 } | |
| 60 // Move transient children of the child windows if any. | |
| 61 aura::Window::Windows children = window->children(); | |
| 62 for (aura::Window::Windows::iterator iter = children.begin(); | |
| 63 iter != children.end(); ++iter) | |
| 64 MoveAllTransientChildrenToNewRoot(display, *iter); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | 30 |
| 69 // static | 31 // static |
| 70 void ScreenPositionController::ConvertHostPointToRelativeToRootWindow( | 32 void ScreenPositionController::ConvertHostPointToRelativeToRootWindow( |
| 71 aura::Window* root_window, | 33 aura::Window* root_window, |
| 72 const aura::Window::Windows& root_windows, | 34 const aura::Window::Windows& root_windows, |
| 73 gfx::Point* point, | 35 gfx::Point* point, |
| 74 aura::Window** target_root) { | 36 aura::Window** target_root) { |
| 75 DCHECK(!root_window->parent()); | 37 DCHECK(!root_window->parent()); |
| 76 gfx::Point point_in_root(*point); | 38 gfx::Point point_in_root(*point); |
| 77 root_window->GetHost()->ConvertPointFromHost(&point_in_root); | 39 root_window->GetHost()->ConvertPointFromHost(&point_in_root); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 aura::Window* root = root_window->GetRootWindow(); | 112 aura::Window* root = root_window->GetRootWindow(); |
| 151 aura::Window* target_root = nullptr; | 113 aura::Window* target_root = nullptr; |
| 152 ConvertHostPointToRelativeToRootWindow(root, Shell::GetAllRootWindows(), | 114 ConvertHostPointToRelativeToRootWindow(root, Shell::GetAllRootWindows(), |
| 153 point, &target_root); | 115 point, &target_root); |
| 154 ConvertPointToScreen(target_root, point); | 116 ConvertPointToScreen(target_root, point); |
| 155 } | 117 } |
| 156 | 118 |
| 157 void ScreenPositionController::SetBounds(aura::Window* window, | 119 void ScreenPositionController::SetBounds(aura::Window* window, |
| 158 const gfx::Rect& bounds, | 120 const gfx::Rect& bounds, |
| 159 const display::Display& display) { | 121 const display::Display& display) { |
| 160 DCHECK_NE(-1, display.id()); | |
| 161 if (!window->parent()->GetProperty(kUsesScreenCoordinatesKey)) { | 122 if (!window->parent()->GetProperty(kUsesScreenCoordinatesKey)) { |
| 162 window->SetBounds(bounds); | 123 window->SetBounds(bounds); |
| 163 return; | 124 return; |
| 164 } | 125 } |
| 165 | 126 |
| 166 // Don't move a window to other root window if: | 127 wm::SetBoundsInScreen(WmWindowAura::Get(window), bounds, display); |
| 167 // a) the window is a transient window. It moves when its | |
| 168 // transient_parent moves. | |
| 169 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's | |
| 170 // intentionally kept in the same root window even if the bounds is | |
| 171 // outside of the display. | |
| 172 if (!::wm::GetTransientParent(window) && | |
| 173 !ShouldStayInSameRootWindow(window)) { | |
| 174 aura::Window* dst_root = Shell::GetInstance() | |
| 175 ->window_tree_host_manager() | |
| 176 ->GetRootWindowForDisplayId(display.id()); | |
| 177 DCHECK(dst_root); | |
| 178 aura::Window* dst_container = NULL; | |
| 179 if (dst_root != window->GetRootWindow()) { | |
| 180 int container_id = window->parent()->id(); | |
| 181 // All containers that uses screen coordinates must have valid window ids. | |
| 182 DCHECK_GE(container_id, 0); | |
| 183 // Don't move modal background. | |
| 184 if (!SystemModalContainerLayoutManager::IsModalBackground( | |
| 185 WmWindowAura::Get(window))) | |
| 186 dst_container = Shell::GetContainer(dst_root, container_id); | |
| 187 } | |
| 188 | |
| 189 if (dst_container && window->parent() != dst_container) { | |
| 190 aura::Window* focused = | |
| 191 aura::client::GetFocusClient(window)->GetFocusedWindow(); | |
| 192 aura::client::ActivationClient* activation_client = | |
| 193 aura::client::GetActivationClient(window->GetRootWindow()); | |
| 194 aura::Window* active = activation_client->GetActiveWindow(); | |
| 195 | |
| 196 aura::WindowTracker tracker; | |
| 197 if (focused) | |
| 198 tracker.Add(focused); | |
| 199 if (active && focused != active) | |
| 200 tracker.Add(active); | |
| 201 | |
| 202 // Set new bounds now so that the container's layout manager | |
| 203 // can adjust the bounds if necessary. | |
| 204 gfx::Point origin = bounds.origin(); | |
| 205 const gfx::Point display_origin = display.bounds().origin(); | |
| 206 origin.Offset(-display_origin.x(), -display_origin.y()); | |
| 207 gfx::Rect new_bounds = gfx::Rect(origin, bounds.size()); | |
| 208 | |
| 209 window->SetBounds(new_bounds); | |
| 210 | |
| 211 dst_container->AddChild(window); | |
| 212 | |
| 213 MoveAllTransientChildrenToNewRoot(display, window); | |
| 214 | |
| 215 // Restore focused/active window. | |
| 216 if (tracker.Contains(focused)) { | |
| 217 aura::client::GetFocusClient(window)->FocusWindow(focused); | |
| 218 // TODO(beng): replace with GetRootWindow(). | |
| 219 WmShell::Get()->set_root_window_for_new_windows( | |
| 220 WmWindowAura::Get(focused->GetRootWindow())); | |
| 221 } else if (tracker.Contains(active)) { | |
| 222 activation_client->ActivateWindow(active); | |
| 223 } | |
| 224 // TODO(oshima): We should not have to update the bounds again | |
| 225 // below in theory, but we currently do need as there is a code | |
| 226 // that assumes that the bounds will never be overridden by the | |
| 227 // layout mananger. We should have more explicit control how | |
| 228 // constraints are applied by the layout manager. | |
| 229 } | |
| 230 } | |
| 231 gfx::Point origin(bounds.origin()); | |
| 232 const gfx::Point display_origin = display::Screen::GetScreen() | |
| 233 ->GetDisplayNearestWindow(window) | |
| 234 .bounds() | |
| 235 .origin(); | |
| 236 origin.Offset(-display_origin.x(), -display_origin.y()); | |
| 237 window->SetBounds(gfx::Rect(origin, bounds.size())); | |
| 238 } | 128 } |
| 239 | 129 |
| 240 } // namespace ash | 130 } // namespace ash |
| OLD | NEW |