| 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/display/window_tree_host_manager.h" | 7 #include "ash/display/window_tree_host_manager.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" |
| 11 #include "ash/wm/common/window_state.h" | 11 #include "ash/wm/common/window_state.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_properties.h" | 13 #include "ash/wm/window_properties.h" |
| 14 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
| 15 #include "ui/aura/client/focus_client.h" | 15 #include "ui/aura/client/focus_client.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
| 19 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
| 20 #include "ui/compositor/dip_util.h" | 20 #include "ui/compositor/dip_util.h" |
| 21 #include "ui/gfx/display.h" | 21 #include "ui/display/display.h" |
| 22 #include "ui/gfx/screen.h" | 22 #include "ui/display/screen.h" |
| 23 #include "ui/wm/core/window_util.h" | 23 #include "ui/wm/core/window_util.h" |
| 24 #include "ui/wm/public/activation_client.h" | 24 #include "ui/wm/public/activation_client.h" |
| 25 | 25 |
| 26 namespace ash { | 26 namespace ash { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Return true if the window or its ancestor has |kStayInSameRootWindowkey| | 29 // Return true if the window or its ancestor has |kStayInSameRootWindowkey| |
| 30 // property. | 30 // property. |
| 31 bool ShouldStayInSameRootWindow(const aura::Window* window) { | 31 bool ShouldStayInSameRootWindow(const aura::Window* window) { |
| 32 return window && (window->GetProperty(kStayInSameRootWindowKey) || | 32 return window && (window->GetProperty(kStayInSameRootWindowKey) || |
| 33 ShouldStayInSameRootWindow(window->parent())); | 33 ShouldStayInSameRootWindow(window->parent())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Move all transient children to |dst_root|, including the ones in | 36 // Move all transient children to |dst_root|, including the ones in |
| 37 // the child windows and transient children of the transient children. | 37 // the child windows and transient children of the transient children. |
| 38 void MoveAllTransientChildrenToNewRoot(const gfx::Display& display, | 38 void MoveAllTransientChildrenToNewRoot(const display::Display& display, |
| 39 aura::Window* window) { | 39 aura::Window* window) { |
| 40 aura::Window* dst_root = Shell::GetInstance() | 40 aura::Window* dst_root = Shell::GetInstance() |
| 41 ->window_tree_host_manager() | 41 ->window_tree_host_manager() |
| 42 ->GetRootWindowForDisplayId(display.id()); | 42 ->GetRootWindowForDisplayId(display.id()); |
| 43 aura::Window::Windows transient_children = | 43 aura::Window::Windows transient_children = |
| 44 ::wm::GetTransientChildren(window); | 44 ::wm::GetTransientChildren(window); |
| 45 for (aura::Window::Windows::iterator iter = transient_children.begin(); | 45 for (aura::Window::Windows::iterator iter = transient_children.begin(); |
| 46 iter != transient_children.end(); ++iter) { | 46 iter != transient_children.end(); ++iter) { |
| 47 aura::Window* transient_child = *iter; | 47 aura::Window* transient_child = *iter; |
| 48 int container_id = transient_child->parent()->id(); | 48 int container_id = transient_child->parent()->id(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 *target_root = root_window; | 116 *target_root = root_window; |
| 117 *point = point_in_root; | 117 *point = point_in_root; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ScreenPositionController::ConvertPointToScreen( | 120 void ScreenPositionController::ConvertPointToScreen( |
| 121 const aura::Window* window, | 121 const aura::Window* window, |
| 122 gfx::Point* point) { | 122 gfx::Point* point) { |
| 123 const aura::Window* root = window->GetRootWindow(); | 123 const aura::Window* root = window->GetRootWindow(); |
| 124 aura::Window::ConvertPointToTarget(window, root, point); | 124 aura::Window::ConvertPointToTarget(window, root, point); |
| 125 const gfx::Point display_origin = | 125 const gfx::Point display_origin = |
| 126 gfx::Screen::GetScreen() | 126 display::Screen::GetScreen() |
| 127 ->GetDisplayNearestWindow(const_cast<aura::Window*>(root)) | 127 ->GetDisplayNearestWindow(const_cast<aura::Window*>(root)) |
| 128 .bounds() | 128 .bounds() |
| 129 .origin(); | 129 .origin(); |
| 130 point->Offset(display_origin.x(), display_origin.y()); | 130 point->Offset(display_origin.x(), display_origin.y()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void ScreenPositionController::ConvertPointFromScreen( | 133 void ScreenPositionController::ConvertPointFromScreen( |
| 134 const aura::Window* window, | 134 const aura::Window* window, |
| 135 gfx::Point* point) { | 135 gfx::Point* point) { |
| 136 const aura::Window* root = window->GetRootWindow(); | 136 const aura::Window* root = window->GetRootWindow(); |
| 137 const gfx::Point display_origin = | 137 const gfx::Point display_origin = |
| 138 gfx::Screen::GetScreen() | 138 display::Screen::GetScreen() |
| 139 ->GetDisplayNearestWindow(const_cast<aura::Window*>(root)) | 139 ->GetDisplayNearestWindow(const_cast<aura::Window*>(root)) |
| 140 .bounds() | 140 .bounds() |
| 141 .origin(); | 141 .origin(); |
| 142 point->Offset(-display_origin.x(), -display_origin.y()); | 142 point->Offset(-display_origin.x(), -display_origin.y()); |
| 143 aura::Window::ConvertPointToTarget(root, window, point); | 143 aura::Window::ConvertPointToTarget(root, window, point); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void ScreenPositionController::ConvertHostPointToScreen( | 146 void ScreenPositionController::ConvertHostPointToScreen( |
| 147 aura::Window* root_window, | 147 aura::Window* root_window, |
| 148 gfx::Point* point) { | 148 gfx::Point* point) { |
| 149 aura::Window* root = root_window->GetRootWindow(); | 149 aura::Window* root = root_window->GetRootWindow(); |
| 150 aura::Window* target_root = nullptr; | 150 aura::Window* target_root = nullptr; |
| 151 ConvertHostPointToRelativeToRootWindow(root, Shell::GetAllRootWindows(), | 151 ConvertHostPointToRelativeToRootWindow(root, Shell::GetAllRootWindows(), |
| 152 point, &target_root); | 152 point, &target_root); |
| 153 ConvertPointToScreen(target_root, point); | 153 ConvertPointToScreen(target_root, point); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void ScreenPositionController::SetBounds(aura::Window* window, | 156 void ScreenPositionController::SetBounds(aura::Window* window, |
| 157 const gfx::Rect& bounds, | 157 const gfx::Rect& bounds, |
| 158 const gfx::Display& display) { | 158 const display::Display& display) { |
| 159 DCHECK_NE(-1, display.id()); | 159 DCHECK_NE(-1, display.id()); |
| 160 if (!window->parent()->GetProperty(kUsesScreenCoordinatesKey)) { | 160 if (!window->parent()->GetProperty(kUsesScreenCoordinatesKey)) { |
| 161 window->SetBounds(bounds); | 161 window->SetBounds(bounds); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Don't move a window to other root window if: | 165 // Don't move a window to other root window if: |
| 166 // a) the window is a transient window. It moves when its | 166 // a) the window is a transient window. It moves when its |
| 167 // transient_parent moves. | 167 // transient_parent moves. |
| 168 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's | 168 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 activation_client->ActivateWindow(active); | 220 activation_client->ActivateWindow(active); |
| 221 } | 221 } |
| 222 // TODO(oshima): We should not have to update the bounds again | 222 // TODO(oshima): We should not have to update the bounds again |
| 223 // below in theory, but we currently do need as there is a code | 223 // below in theory, but we currently do need as there is a code |
| 224 // that assumes that the bounds will never be overridden by the | 224 // that assumes that the bounds will never be overridden by the |
| 225 // layout mananger. We should have more explicit control how | 225 // layout mananger. We should have more explicit control how |
| 226 // constraints are applied by the layout manager. | 226 // constraints are applied by the layout manager. |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 gfx::Point origin(bounds.origin()); | 229 gfx::Point origin(bounds.origin()); |
| 230 const gfx::Point display_origin = gfx::Screen::GetScreen() | 230 const gfx::Point display_origin = display::Screen::GetScreen() |
| 231 ->GetDisplayNearestWindow(window) | 231 ->GetDisplayNearestWindow(window) |
| 232 .bounds() | 232 .bounds() |
| 233 .origin(); | 233 .origin(); |
| 234 origin.Offset(-display_origin.x(), -display_origin.y()); | 234 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 235 window->SetBounds(gfx::Rect(origin, bounds.size())); | 235 window->SetBounds(gfx::Rect(origin, bounds.size())); |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace ash | 238 } // namespace ash |
| OLD | NEW |