Chromium Code Reviews| 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 allow_warp_during_lock_(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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 117 } |
| 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, |
| 128 bool is_cursor_locked) { | |
|
sky
2012/08/03 17:07:18
Can't DisplayController determine if the cursor is
Yusuke Sato
2012/08/03 23:18:45
Done.
| |
| 129 if (is_cursor_locked && !allow_warp_during_lock_) | |
| 130 return false; | |
| 131 | |
| 126 if (root_windows_.size() < 2) | 132 if (root_windows_.size() < 2) |
| 127 return false; | 133 return false; |
| 128 | 134 |
| 135 // The cursor might be outside the |current_root|. Get the root window where | |
| 136 // the cursor is currently on. | |
| 137 std::pair<aura::RootWindow*, gfx::Point> actual_location = | |
| 138 wm::GetRootWindowRelativeToWindow(current_root, point_in_root); | |
| 139 current_root = actual_location.first; | |
| 140 // Don't use |point_in_root| below. Instead, use |actual_location.second| | |
| 141 // which is in |actual_location.first|'s coordinates. | |
| 142 | |
| 129 gfx::Rect root_bounds = current_root->bounds(); | 143 gfx::Rect root_bounds = current_root->bounds(); |
| 130 int offset_x = 0; | 144 int offset_x = 0; |
| 131 int offset_y = 0; | 145 int offset_y = 0; |
| 132 if (point_in_root.x() <= root_bounds.x()) { | 146 if (actual_location.second.x() <= root_bounds.x()) { |
| 133 offset_x = -1; | 147 // Use -2, not -1, to avoid infinite loop of pointer warp. |
| 134 } else if (point_in_root.x() >= root_bounds.right() - 1) { | 148 offset_x = -2; |
| 135 offset_x = 1; | 149 } else if (actual_location.second.x() >= root_bounds.right() - 1) { |
| 136 } else if (point_in_root.y() <= root_bounds.y()) { | 150 offset_x = 2; |
| 137 offset_y = -1; | 151 } else if (actual_location.second.y() <= root_bounds.y()) { |
| 138 } else if (point_in_root.y() >= root_bounds.bottom() - 1) { | 152 offset_y = -2; |
| 139 offset_y = 1; | 153 } else if (actual_location.second.y() >= root_bounds.bottom() - 1) { |
| 154 offset_y = 2; | |
| 140 } else { | 155 } else { |
| 141 return false; | 156 return false; |
| 142 } | 157 } |
| 143 | 158 |
| 144 gfx::Point point_in_screen(point_in_root); | 159 gfx::Point point_in_screen(actual_location.second); |
| 145 aura::client::ScreenPositionClient* screen_position_client = | 160 aura::client::ScreenPositionClient* screen_position_client = |
| 146 aura::client::GetScreenPositionClient(current_root); | 161 aura::client::GetScreenPositionClient(current_root); |
| 147 screen_position_client->ConvertPointToScreen(current_root, | 162 screen_position_client->ConvertPointToScreen(current_root, |
| 148 &point_in_screen); | 163 &point_in_screen); |
| 149 point_in_screen.Offset(offset_x, offset_y); | 164 point_in_screen.Offset(offset_x, offset_y); |
| 150 aura::RootWindow* dst_root = Shell::GetRootWindowAt(point_in_screen); | 165 aura::RootWindow* dst_root = wm::GetRootWindowAt(point_in_screen); |
| 151 gfx::Point point_in_dst_root(point_in_screen); | 166 gfx::Point point_in_dst_root(point_in_screen); |
| 152 | 167 |
| 153 screen_position_client->ConvertPointFromScreen(dst_root, | 168 screen_position_client->ConvertPointFromScreen(dst_root, |
| 154 &point_in_dst_root); | 169 &point_in_dst_root); |
| 155 if (dst_root->bounds().Contains(point_in_dst_root)) { | 170 if (dst_root->bounds().Contains(point_in_dst_root)) { |
| 156 DCHECK_NE(dst_root, current_root); | 171 DCHECK_NE(dst_root, current_root); |
| 157 dst_root->MoveCursorTo(point_in_dst_root); | 172 dst_root->MoveCursorTo(point_in_dst_root); |
| 158 return true; | 173 return true; |
| 159 } | 174 } |
| 160 return false; | 175 return false; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 break; | 265 break; |
| 251 } | 266 } |
| 252 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 267 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 253 secondary_display->set_bounds( | 268 secondary_display->set_bounds( |
| 254 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 269 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 255 secondary_display->UpdateWorkAreaFromInsets(insets); | 270 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 256 } | 271 } |
| 257 | 272 |
| 258 } // namespace internal | 273 } // namespace internal |
| 259 } // namespace ash | 274 } // namespace ash |
| OLD | NEW |