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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/multi_display_manager.h" | 8 #include "ash/display/multi_display_manager.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/coordinate_conversion.h" |
12 #include "ash/wm/property_util.h" | 13 #include "ash/wm/property_util.h" |
13 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "ui/aura/client/screen_position_client.h" | 16 #include "ui/aura/client/screen_position_client.h" |
16 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
17 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
20 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
21 | 22 |
22 namespace ash { | 23 namespace ash { |
23 namespace internal { | 24 namespace internal { |
24 | 25 |
25 DisplayController::DisplayController() | 26 DisplayController::DisplayController() |
26 : secondary_display_layout_(RIGHT) { | 27 : secondary_display_layout_(RIGHT), |
| 28 dont_warp_mouse_(false) { |
27 aura::Env::GetInstance()->display_manager()->AddObserver(this); | 29 aura::Env::GetInstance()->display_manager()->AddObserver(this); |
28 } | 30 } |
29 | 31 |
30 DisplayController::~DisplayController() { | 32 DisplayController::~DisplayController() { |
31 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | 33 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); |
32 // Delete all root window controllers, which deletes root window | 34 // Delete all root window controllers, which deletes root window |
33 // from the last so that the primary root window gets deleted last. | 35 // from the last so that the primary root window gets deleted last. |
34 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = | 36 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = |
35 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 37 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { |
36 internal::RootWindowController* controller = | 38 internal::RootWindowController* controller = |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 118 |
117 void DisplayController::SetSecondaryDisplayLayout( | 119 void DisplayController::SetSecondaryDisplayLayout( |
118 SecondaryDisplayLayout layout) { | 120 SecondaryDisplayLayout layout) { |
119 secondary_display_layout_ = layout; | 121 secondary_display_layout_ = layout; |
120 UpdateDisplayBoundsForLayout(); | 122 UpdateDisplayBoundsForLayout(); |
121 } | 123 } |
122 | 124 |
123 bool DisplayController::WarpMouseCursorIfNecessary( | 125 bool DisplayController::WarpMouseCursorIfNecessary( |
124 aura::RootWindow* current_root, | 126 aura::RootWindow* current_root, |
125 const gfx::Point& point_in_root) { | 127 const gfx::Point& point_in_root) { |
126 if (root_windows_.size() < 2) | 128 if (root_windows_.size() < 2 || dont_warp_mouse_) |
127 return false; | 129 return false; |
128 | 130 |
| 131 // The pointer might be outside the |current_root|. Get the root window where |
| 132 // the pointer is currently on. |
| 133 std::pair<aura::RootWindow*, gfx::Point> actual_location = |
| 134 wm::GetRootWindowRelativeToWindow(current_root, point_in_root); |
| 135 current_root = actual_location.first; |
| 136 // Don't use |point_in_root| below. Instead, use |actual_location.second| |
| 137 // which is in |actual_location.first|'s coordinates. |
| 138 |
129 gfx::Rect root_bounds = current_root->bounds(); | 139 gfx::Rect root_bounds = current_root->bounds(); |
130 int offset_x = 0; | 140 int offset_x = 0; |
131 int offset_y = 0; | 141 int offset_y = 0; |
132 if (point_in_root.x() <= root_bounds.x()) { | 142 if (actual_location.second.x() <= root_bounds.x()) { |
133 offset_x = -1; | 143 // Use -2, not -1, to avoid infinite loop of pointer warp. |
134 } else if (point_in_root.x() >= root_bounds.right() - 1) { | 144 offset_x = -2; |
135 offset_x = 1; | 145 } else if (actual_location.second.x() >= root_bounds.right() - 1) { |
136 } else if (point_in_root.y() <= root_bounds.y()) { | 146 offset_x = 2; |
137 offset_y = -1; | 147 } else if (actual_location.second.y() <= root_bounds.y()) { |
138 } else if (point_in_root.y() >= root_bounds.bottom() - 1) { | 148 offset_y = -2; |
139 offset_y = 1; | 149 } else if (actual_location.second.y() >= root_bounds.bottom() - 1) { |
| 150 offset_y = 2; |
140 } else { | 151 } else { |
141 return false; | 152 return false; |
142 } | 153 } |
143 | 154 |
144 gfx::Point point_in_screen(point_in_root); | 155 gfx::Point point_in_screen(actual_location.second); |
145 aura::client::ScreenPositionClient* screen_position_client = | 156 wm::ConvertPointToScreen(current_root, &point_in_screen); |
146 aura::client::GetScreenPositionClient(current_root); | |
147 screen_position_client->ConvertPointToScreen(current_root, | |
148 &point_in_screen); | |
149 point_in_screen.Offset(offset_x, offset_y); | 157 point_in_screen.Offset(offset_x, offset_y); |
150 aura::RootWindow* dst_root = Shell::GetRootWindowAt(point_in_screen); | 158 |
| 159 aura::RootWindow* dst_root = wm::GetRootWindowAt(point_in_screen); |
151 gfx::Point point_in_dst_root(point_in_screen); | 160 gfx::Point point_in_dst_root(point_in_screen); |
| 161 wm::ConvertPointFromScreen(dst_root, &point_in_dst_root); |
152 | 162 |
153 screen_position_client->ConvertPointFromScreen(dst_root, | |
154 &point_in_dst_root); | |
155 if (dst_root->bounds().Contains(point_in_dst_root)) { | 163 if (dst_root->bounds().Contains(point_in_dst_root)) { |
156 DCHECK_NE(dst_root, current_root); | 164 DCHECK_NE(dst_root, current_root); |
157 dst_root->MoveCursorTo(point_in_dst_root); | 165 dst_root->MoveCursorTo(point_in_dst_root); |
158 return true; | 166 return true; |
159 } | 167 } |
160 return false; | 168 return false; |
161 } | 169 } |
162 | 170 |
163 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 171 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
164 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 172 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 break; | 258 break; |
251 } | 259 } |
252 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 260 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
253 secondary_display->set_bounds( | 261 secondary_display->set_bounds( |
254 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 262 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
255 secondary_display->UpdateWorkAreaFromInsets(insets); | 263 secondary_display->UpdateWorkAreaFromInsets(insets); |
256 } | 264 } |
257 | 265 |
258 } // namespace internal | 266 } // namespace internal |
259 } // namespace ash | 267 } // namespace ash |
OLD | NEW |