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