| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/wm/window_positioning_utils.h" | 5 #include "ash/wm/window_positioning_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/system_modal_container_layout_manager.h" | 12 #include "ash/wm/system_modal_container_layout_manager.h" |
| 13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/wm_event.h" | 15 #include "ash/wm/wm_event.h" |
| 16 #include "ash/wm_window.h" | 16 #include "ash/wm_window.h" |
| 17 #include "ui/aura/client/focus_client.h" |
| 17 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
| 18 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 19 #include "ui/display/types/display_constants.h" | 20 #include "ui/display/types/display_constants.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 namespace wm { | 25 namespace wm { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 int container_id = window->GetParent()->aura_window()->id(); | 152 int container_id = window->GetParent()->aura_window()->id(); |
| 152 // All containers that uses screen coordinates must have valid window ids. | 153 // All containers that uses screen coordinates must have valid window ids. |
| 153 DCHECK_GE(container_id, 0); | 154 DCHECK_GE(container_id, 0); |
| 154 // Don't move modal background. | 155 // Don't move modal background. |
| 155 if (!SystemModalContainerLayoutManager::IsModalBackground( | 156 if (!SystemModalContainerLayoutManager::IsModalBackground( |
| 156 window->aura_window())) | 157 window->aura_window())) |
| 157 dst_container = dst_root->GetChildByShellWindowId(container_id); | 158 dst_container = dst_root->GetChildByShellWindowId(container_id); |
| 158 } | 159 } |
| 159 | 160 |
| 160 if (dst_container && window->GetParent() != dst_container) { | 161 if (dst_container && window->GetParent() != dst_container) { |
| 161 WmWindow* focused = WmWindow::Get(GetFocusedWindow()); | 162 aura::Window* focused = GetFocusedWindow(); |
| 162 WmWindow* active = WmWindow::Get(GetActiveWindow()); | 163 aura::Window* active = GetActiveWindow(); |
| 163 | 164 |
| 164 aura::WindowTracker tracker; | 165 aura::WindowTracker tracker; |
| 165 if (focused) | 166 if (focused) |
| 166 tracker.Add(focused->aura_window()); | 167 tracker.Add(focused); |
| 167 if (active && focused != active) | 168 if (active && focused != active) |
| 168 tracker.Add(active->aura_window()); | 169 tracker.Add(active); |
| 169 | 170 |
| 170 gfx::Point origin = bounds_in_screen.origin(); | 171 gfx::Point origin = bounds_in_screen.origin(); |
| 171 const gfx::Point display_origin = display.bounds().origin(); | 172 const gfx::Point display_origin = display.bounds().origin(); |
| 172 origin.Offset(-display_origin.x(), -display_origin.y()); | 173 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 173 gfx::Rect new_bounds = gfx::Rect(origin, bounds_in_screen.size()); | 174 gfx::Rect new_bounds = gfx::Rect(origin, bounds_in_screen.size()); |
| 174 | 175 |
| 175 // Set new bounds now so that the container's layout manager can adjust | 176 // Set new bounds now so that the container's layout manager can adjust |
| 176 // the bounds if necessary. | 177 // the bounds if necessary. |
| 177 window->SetBounds(new_bounds); | 178 window->SetBounds(new_bounds); |
| 178 | 179 |
| 179 dst_container->AddChild(window); | 180 dst_container->AddChild(window); |
| 180 | 181 |
| 181 MoveAllTransientChildrenToNewRoot(display, window); | 182 MoveAllTransientChildrenToNewRoot(display, window); |
| 182 | 183 |
| 183 // Restore focused/active window. | 184 // Restore focused/active window. |
| 184 if (focused && tracker.Contains(focused->aura_window())) { | 185 if (focused && tracker.Contains(focused)) { |
| 185 focused->SetFocused(); | 186 aura::client::GetFocusClient(focused)->FocusWindow(focused); |
| 186 Shell::Get()->set_root_window_for_new_windows(focused->GetRootWindow()); | 187 Shell::Get()->set_root_window_for_new_windows(focused->GetRootWindow()); |
| 187 } else if (active && tracker.Contains(active->aura_window())) { | 188 } else if (active && tracker.Contains(active)) { |
| 188 active->Activate(); | 189 wm::ActivateWindow(active); |
| 189 } | 190 } |
| 190 // TODO(oshima): We should not have to update the bounds again | 191 // TODO(oshima): We should not have to update the bounds again |
| 191 // below in theory, but we currently do need as there is a code | 192 // below in theory, but we currently do need as there is a code |
| 192 // that assumes that the bounds will never be overridden by the | 193 // that assumes that the bounds will never be overridden by the |
| 193 // layout mananger. We should have more explicit control how | 194 // layout mananger. We should have more explicit control how |
| 194 // constraints are applied by the layout manager. | 195 // constraints are applied by the layout manager. |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 gfx::Point origin(bounds_in_screen.origin()); | 198 gfx::Point origin(bounds_in_screen.origin()); |
| 198 const gfx::Point display_origin = | 199 const gfx::Point display_origin = |
| 199 window->GetDisplayNearestWindow().bounds().origin(); | 200 window->GetDisplayNearestWindow().bounds().origin(); |
| 200 origin.Offset(-display_origin.x(), -display_origin.y()); | 201 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 201 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); | 202 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); |
| 202 } | 203 } |
| 203 | 204 |
| 204 } // namespace wm | 205 } // namespace wm |
| 205 } // namespace ash | 206 } // namespace ash |
| OLD | NEW |