| 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/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 Loading... |
| 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 Loading... |
| 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 101 location_in_root = location_in_native; | 101 location_in_root = location_in_native; |
| 102 root_window->ConvertPointFromNativeScreen(&location_in_root); | 102 root_window->ConvertPointFromNativeScreen(&location_in_root); |
| 103 break; | 103 break; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 #else | 107 #else |
| 108 // TODO(yusukes): Support non-X11 platforms if necessary. | 108 // TODO(yusukes): Support non-X11 platforms if necessary. |
| 109 #endif | 109 #endif |
| 110 | 110 |
| 111 return std::make_pair(root_window, location_in_root); | 111 return std::make_pair(root_window->GetDispatcher(), location_in_root); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace | 114 } // namespace |
| 115 | 115 |
| 116 namespace internal { | 116 namespace internal { |
| 117 | 117 |
| 118 void ScreenPositionController::ConvertPointToScreen( | 118 void ScreenPositionController::ConvertPointToScreen( |
| 119 const aura::Window* window, | 119 const aura::Window* window, |
| 120 gfx::Point* point) { | 120 gfx::Point* point) { |
| 121 const aura::RootWindow* root = window->GetRootWindow(); | 121 const aura::Window* root = window->GetRootWindow(); |
| 122 aura::Window::ConvertPointToTarget(window, root, point); | 122 aura::Window::ConvertPointToTarget(window, root, point); |
| 123 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( | 123 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( |
| 124 const_cast<aura::RootWindow*>(root)).bounds().origin(); | 124 const_cast<aura::Window*>(root)).bounds().origin(); |
| 125 point->Offset(display_origin.x(), display_origin.y()); | 125 point->Offset(display_origin.x(), display_origin.y()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ScreenPositionController::ConvertPointFromScreen( | 128 void ScreenPositionController::ConvertPointFromScreen( |
| 129 const aura::Window* window, | 129 const aura::Window* window, |
| 130 gfx::Point* point) { | 130 gfx::Point* point) { |
| 131 const aura::RootWindow* root = window->GetRootWindow(); | 131 const aura::Window* root = window->GetRootWindow(); |
| 132 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( | 132 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( |
| 133 const_cast<aura::RootWindow*>(root)).bounds().origin(); | 133 const_cast<aura::Window*>(root)).bounds().origin(); |
| 134 point->Offset(-display_origin.x(), -display_origin.y()); | 134 point->Offset(-display_origin.x(), -display_origin.y()); |
| 135 aura::Window::ConvertPointToTarget(root, window, point); | 135 aura::Window::ConvertPointToTarget(root, window, point); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void ScreenPositionController::ConvertHostPointToScreen( | 138 void ScreenPositionController::ConvertHostPointToScreen( |
| 139 aura::Window* root_window, | 139 aura::Window* root_window, |
| 140 gfx::Point* point) { | 140 gfx::Point* point) { |
| 141 aura::RootWindow* root = root_window->GetRootWindow(); | 141 aura::Window* root = root_window->GetRootWindow(); |
| 142 root->ConvertPointFromHost(point); | 142 root->GetDispatcher()->ConvertPointFromHost(point); |
| 143 std::pair<aura::RootWindow*, gfx::Point> pair = | 143 std::pair<aura::RootWindow*, gfx::Point> pair = |
| 144 GetRootWindowRelativeToWindow(root, *point); | 144 GetRootWindowRelativeToWindow(root, *point); |
| 145 *point = pair.second; | 145 *point = pair.second; |
| 146 ConvertPointToScreen(pair.first, point); | 146 ConvertPointToScreen(pair.first, point); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void ScreenPositionController::SetBounds(aura::Window* window, | 149 void ScreenPositionController::SetBounds(aura::Window* window, |
| 150 const gfx::Rect& bounds, | 150 const gfx::Rect& bounds, |
| 151 const gfx::Display& display) { | 151 const gfx::Display& display) { |
| 152 DCHECK_NE(-1, display.id()); | 152 DCHECK_NE(-1, display.id()); |
| 153 if (!window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { | 153 if (!window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { |
| 154 window->SetBounds(bounds); | 154 window->SetBounds(bounds); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Don't move a window to other root window if: | 158 // Don't move a window to other root window if: |
| 159 // a) the window is a transient window. It moves when its | 159 // a) the window is a transient window. It moves when its |
| 160 // transient_parent moves. | 160 // transient_parent moves. |
| 161 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's | 161 // b) if the window or its ancestor has kStayInSameRootWindowkey. It's |
| 162 // intentionally kept in the same root window even if the bounds is | 162 // intentionally kept in the same root window even if the bounds is |
| 163 // outside of the display. | 163 // outside of the display. |
| 164 if (!window->transient_parent() && | 164 if (!window->transient_parent() && |
| 165 !ShouldStayInSameRootWindow(window)) { | 165 !ShouldStayInSameRootWindow(window)) { |
| 166 aura::RootWindow* dst_root = | 166 aura::Window* dst_root = |
| 167 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId( | 167 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId( |
| 168 display.id()); | 168 display.id()); |
| 169 DCHECK(dst_root); | 169 DCHECK(dst_root); |
| 170 aura::Window* dst_container = NULL; | 170 aura::Window* dst_container = NULL; |
| 171 if (dst_root != window->GetRootWindow()) { | 171 if (dst_root != window->GetRootWindow()) { |
| 172 int container_id = window->parent()->id(); | 172 int container_id = window->parent()->id(); |
| 173 // All containers that uses screen coordinates must have valid window ids. | 173 // All containers that uses screen coordinates must have valid window ids. |
| 174 DCHECK_GE(container_id, 0); | 174 DCHECK_GE(container_id, 0); |
| 175 // Don't move modal background. | 175 // Don't move modal background. |
| 176 if (!SystemModalContainerLayoutManager::IsModalBackground(window)) | 176 if (!SystemModalContainerLayoutManager::IsModalBackground(window)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 190 if (active && focused != active) | 190 if (active && focused != active) |
| 191 tracker.Add(active); | 191 tracker.Add(active); |
| 192 | 192 |
| 193 dst_container->AddChild(window); | 193 dst_container->AddChild(window); |
| 194 | 194 |
| 195 MoveAllTransientChildrenToNewRoot(display, window); | 195 MoveAllTransientChildrenToNewRoot(display, window); |
| 196 | 196 |
| 197 // Restore focused/active window. | 197 // Restore focused/active window. |
| 198 if (tracker.Contains(focused)) { | 198 if (tracker.Contains(focused)) { |
| 199 aura::client::GetFocusClient(window)->FocusWindow(focused); | 199 aura::client::GetFocusClient(window)->FocusWindow(focused); |
| 200 // TODO(beng): replace with GetRootWindow(). |
| 200 ash::Shell::GetInstance()->set_target_root_window( | 201 ash::Shell::GetInstance()->set_target_root_window( |
| 201 focused->GetRootWindow()); | 202 focused->GetDispatcher()); |
| 202 } else if (tracker.Contains(active)) { | 203 } else if (tracker.Contains(active)) { |
| 203 activation_client->ActivateWindow(active); | 204 activation_client->ActivateWindow(active); |
| 204 } | 205 } |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 | 208 |
| 208 gfx::Point origin(bounds.origin()); | 209 gfx::Point origin(bounds.origin()); |
| 209 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( | 210 const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow( |
| 210 window).bounds().origin(); | 211 window).bounds().origin(); |
| 211 origin.Offset(-display_origin.x(), -display_origin.y()); | 212 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 212 window->SetBounds(gfx::Rect(origin, bounds.size())); | 213 window->SetBounds(gfx::Rect(origin, bounds.size())); |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // internal | 216 } // internal |
| 216 } // ash | 217 } // ash |
| OLD | NEW |