OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_orientation_controller_chromeos.h" | 5 #include "ash/display/screen_orientation_controller_chromeos.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_configuration_controller.h" | 8 #include "ash/display/display_configuration_controller.h" |
9 #include "ash/shared/app_types.h" | 9 #include "ash/shared/app_types.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_port.h" |
11 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
12 #include "ash/wm/mru_window_tracker.h" | 13 #include "ash/wm/mru_window_tracker.h" |
13 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
14 #include "ash/wm_shell.h" | |
15 #include "ash/wm_window.h" | 15 #include "ash/wm_window.h" |
16 #include "base/auto_reset.h" | 16 #include "base/auto_reset.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "chromeos/accelerometer/accelerometer_reader.h" | 18 #include "chromeos/accelerometer/accelerometer_reader.h" |
19 #include "chromeos/accelerometer/accelerometer_types.h" | 19 #include "chromeos/accelerometer/accelerometer_types.h" |
20 #include "ui/chromeos/accelerometer/accelerometer_util.h" | 20 #include "ui/chromeos/accelerometer/accelerometer_util.h" |
21 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
22 #include "ui/display/manager/display_manager.h" | 22 #include "ui/display/manager/display_manager.h" |
23 #include "ui/display/manager/managed_display_info.h" | 23 #include "ui/display/manager/managed_display_info.h" |
24 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
(...skipping 12 matching lines...) Expand all Loading... |
37 // flat and there is very little screen aligned force on it. The value is | 37 // flat and there is very little screen aligned force on it. The value is |
38 // effectively the sine of the rise angle required times the acceleration due | 38 // effectively the sine of the rise angle required times the acceleration due |
39 // to gravity, with the current value requiring at least a 25 degree rise. | 39 // to gravity, with the current value requiring at least a 25 degree rise. |
40 const float kMinimumAccelerationScreenRotation = 4.2f; | 40 const float kMinimumAccelerationScreenRotation = 4.2f; |
41 | 41 |
42 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { | 42 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { |
43 if (!display::Display::HasInternalDisplay()) | 43 if (!display::Display::HasInternalDisplay()) |
44 return blink::kWebScreenOrientationLockLandscape; | 44 return blink::kWebScreenOrientationLockLandscape; |
45 | 45 |
46 display::ManagedDisplayInfo info = | 46 display::ManagedDisplayInfo info = |
47 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); | 47 ShellPort::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); |
48 gfx::Size size = info.size_in_pixel(); | 48 gfx::Size size = info.size_in_pixel(); |
49 switch (info.GetActiveRotation()) { | 49 switch (info.GetActiveRotation()) { |
50 case display::Display::ROTATE_0: | 50 case display::Display::ROTATE_0: |
51 case display::Display::ROTATE_180: | 51 case display::Display::ROTATE_180: |
52 return size.height() >= size.width() | 52 return size.height() >= size.width() |
53 ? blink::kWebScreenOrientationLockPortrait | 53 ? blink::kWebScreenOrientationLockPortrait |
54 : blink::kWebScreenOrientationLockLandscape; | 54 : blink::kWebScreenOrientationLockLandscape; |
55 case display::Display::ROTATE_90: | 55 case display::Display::ROTATE_90: |
56 case display::Display::ROTATE_270: | 56 case display::Display::ROTATE_270: |
57 return size.height() < size.width() | 57 return size.height() < size.width() |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 rotation_locked_(false), | 159 rotation_locked_(false), |
160 rotation_locked_orientation_(blink::kWebScreenOrientationLockAny), | 160 rotation_locked_orientation_(blink::kWebScreenOrientationLockAny), |
161 user_rotation_(display::Display::ROTATE_0), | 161 user_rotation_(display::Display::ROTATE_0), |
162 current_rotation_(display::Display::ROTATE_0) { | 162 current_rotation_(display::Display::ROTATE_0) { |
163 Shell::Get()->AddShellObserver(this); | 163 Shell::Get()->AddShellObserver(this); |
164 } | 164 } |
165 | 165 |
166 ScreenOrientationController::~ScreenOrientationController() { | 166 ScreenOrientationController::~ScreenOrientationController() { |
167 Shell::Get()->RemoveShellObserver(this); | 167 Shell::Get()->RemoveShellObserver(this); |
168 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 168 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
169 WmShell::Get()->RemoveDisplayObserver(this); | 169 ShellPort::Get()->RemoveDisplayObserver(this); |
170 Shell::Get()->activation_client()->RemoveObserver(this); | 170 Shell::Get()->activation_client()->RemoveObserver(this); |
171 for (auto& windows : lock_info_map_) | 171 for (auto& windows : lock_info_map_) |
172 windows.first->aura_window()->RemoveObserver(this); | 172 windows.first->aura_window()->RemoveObserver(this); |
173 } | 173 } |
174 | 174 |
175 void ScreenOrientationController::AddObserver(Observer* observer) { | 175 void ScreenOrientationController::AddObserver(Observer* observer) { |
176 observers_.AddObserver(observer); | 176 observers_.AddObserver(observer); |
177 } | 177 } |
178 | 178 |
179 void ScreenOrientationController::RemoveObserver(Observer* observer) { | 179 void ScreenOrientationController::RemoveObserver(Observer* observer) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 222 } |
223 | 223 |
224 void ScreenOrientationController::ToggleUserRotationLock() { | 224 void ScreenOrientationController::ToggleUserRotationLock() { |
225 if (!display::Display::HasInternalDisplay()) | 225 if (!display::Display::HasInternalDisplay()) |
226 return; | 226 return; |
227 | 227 |
228 if (user_rotation_locked()) { | 228 if (user_rotation_locked()) { |
229 SetLockToOrientation(blink::kWebScreenOrientationLockAny); | 229 SetLockToOrientation(blink::kWebScreenOrientationLockAny); |
230 } else { | 230 } else { |
231 display::Display::Rotation current_rotation = | 231 display::Display::Rotation current_rotation = |
232 WmShell::Get() | 232 ShellPort::Get() |
233 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 233 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
234 .GetActiveRotation(); | 234 .GetActiveRotation(); |
235 SetLockToRotation(current_rotation); | 235 SetLockToRotation(current_rotation); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 void ScreenOrientationController::SetLockToRotation( | 239 void ScreenOrientationController::SetLockToRotation( |
240 display::Display::Rotation rotation) { | 240 display::Display::Rotation rotation) { |
241 if (!display::Display::HasInternalDisplay()) | 241 if (!display::Display::HasInternalDisplay()) |
242 return; | 242 return; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 HandleScreenRotation(update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN)); | 282 HandleScreenRotation(update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN)); |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 void ScreenOrientationController::OnDisplayConfigurationChanged() { | 286 void ScreenOrientationController::OnDisplayConfigurationChanged() { |
287 if (ignore_display_configuration_updates_) | 287 if (ignore_display_configuration_updates_) |
288 return; | 288 return; |
289 if (!display::Display::HasInternalDisplay()) | 289 if (!display::Display::HasInternalDisplay()) |
290 return; | 290 return; |
291 display::Display::Rotation user_rotation = | 291 display::Display::Rotation user_rotation = |
292 WmShell::Get() | 292 ShellPort::Get() |
293 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 293 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
294 .GetActiveRotation(); | 294 .GetActiveRotation(); |
295 if (user_rotation != current_rotation_) { | 295 if (user_rotation != current_rotation_) { |
296 // TODO(oshima): We should disable the orientation change in settings | 296 // TODO(oshima): We should disable the orientation change in settings |
297 // because application may not work correctly. | 297 // because application may not work correctly. |
298 | 298 |
299 // A user may change other display configuration settings. When the user | 299 // A user may change other display configuration settings. When the user |
300 // does change the rotation setting, then lock rotation to prevent the | 300 // does change the rotation setting, then lock rotation to prevent the |
301 // accelerometer from erasing their change. | 301 // accelerometer from erasing their change. |
302 SetRotationLockedInternal(true); | 302 SetRotationLockedInternal(true); |
303 user_rotation_ = current_rotation_ = user_rotation; | 303 user_rotation_ = current_rotation_ = user_rotation; |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 void ScreenOrientationController::OnMaximizeModeStarted() { | 307 void ScreenOrientationController::OnMaximizeModeStarted() { |
308 // Do not exit early, as the internal display can be determined after Maximize | 308 // Do not exit early, as the internal display can be determined after Maximize |
309 // Mode has started. (chrome-os-partner:38796) | 309 // Mode has started. (chrome-os-partner:38796) |
310 // Always start observing. | 310 // Always start observing. |
311 if (display::Display::HasInternalDisplay()) { | 311 if (display::Display::HasInternalDisplay()) { |
312 current_rotation_ = user_rotation_ = | 312 current_rotation_ = user_rotation_ = |
313 WmShell::Get() | 313 ShellPort::Get() |
314 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 314 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
315 .GetActiveRotation(); | 315 .GetActiveRotation(); |
316 } | 316 } |
317 if (!rotation_locked_) | 317 if (!rotation_locked_) |
318 LoadDisplayRotationProperties(); | 318 LoadDisplayRotationProperties(); |
319 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 319 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
320 WmShell::Get()->AddDisplayObserver(this); | 320 ShellPort::Get()->AddDisplayObserver(this); |
321 | 321 |
322 if (!display::Display::HasInternalDisplay()) | 322 if (!display::Display::HasInternalDisplay()) |
323 return; | 323 return; |
324 ApplyLockForActiveWindow(); | 324 ApplyLockForActiveWindow(); |
325 for (auto& observer : observers_) | 325 for (auto& observer : observers_) |
326 observer.OnUserRotationLockChanged(); | 326 observer.OnUserRotationLockChanged(); |
327 } | 327 } |
328 | 328 |
329 void ScreenOrientationController::OnMaximizeModeEnded() { | 329 void ScreenOrientationController::OnMaximizeModeEnded() { |
330 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 330 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
331 WmShell::Get()->RemoveDisplayObserver(this); | 331 ShellPort::Get()->RemoveDisplayObserver(this); |
332 if (!display::Display::HasInternalDisplay()) | 332 if (!display::Display::HasInternalDisplay()) |
333 return; | 333 return; |
334 if (current_rotation_ != user_rotation_) | 334 if (current_rotation_ != user_rotation_) |
335 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 335 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
336 for (auto& observer : observers_) | 336 for (auto& observer : observers_) |
337 observer.OnUserRotationLockChanged(); | 337 observer.OnUserRotationLockChanged(); |
338 } | 338 } |
339 | 339 |
340 void ScreenOrientationController::SetDisplayRotation( | 340 void ScreenOrientationController::SetDisplayRotation( |
341 display::Display::Rotation rotation, | 341 display::Display::Rotation rotation, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 : display::Display::ROTATE_270, | 434 : display::Display::ROTATE_270, |
435 display::Display::ROTATION_SOURCE_ACTIVE); | 435 display::Display::ROTATION_SOURCE_ACTIVE); |
436 } | 436 } |
437 | 437 |
438 void ScreenOrientationController::LockToRotationMatchingOrientation( | 438 void ScreenOrientationController::LockToRotationMatchingOrientation( |
439 blink::WebScreenOrientationLockType lock_orientation) { | 439 blink::WebScreenOrientationLockType lock_orientation) { |
440 if (!display::Display::HasInternalDisplay()) | 440 if (!display::Display::HasInternalDisplay()) |
441 return; | 441 return; |
442 | 442 |
443 display::Display::Rotation rotation = | 443 display::Display::Rotation rotation = |
444 WmShell::Get() | 444 ShellPort::Get() |
445 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 445 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
446 .GetActiveRotation(); | 446 .GetActiveRotation(); |
447 if (natural_orientation_ == lock_orientation) { | 447 if (natural_orientation_ == lock_orientation) { |
448 if (rotation == display::Display::ROTATE_0 || | 448 if (rotation == display::Display::ROTATE_0 || |
449 rotation == display::Display::ROTATE_180) { | 449 rotation == display::Display::ROTATE_180) { |
450 SetRotationLockedInternal(true); | 450 SetRotationLockedInternal(true); |
451 } else { | 451 } else { |
452 LockRotation(display::Display::ROTATE_0, | 452 LockRotation(display::Display::ROTATE_0, |
453 display::Display::ROTATION_SOURCE_ACTIVE); | 453 display::Display::ROTATION_SOURCE_ACTIVE); |
454 } | 454 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 } | 578 } |
579 | 579 |
580 bool ScreenOrientationController::CanRotateInLockedState() { | 580 bool ScreenOrientationController::CanRotateInLockedState() { |
581 return rotation_locked_orientation_ == | 581 return rotation_locked_orientation_ == |
582 blink::kWebScreenOrientationLockLandscape || | 582 blink::kWebScreenOrientationLockLandscape || |
583 rotation_locked_orientation_ == | 583 rotation_locked_orientation_ == |
584 blink::kWebScreenOrientationLockPortrait; | 584 blink::kWebScreenOrientationLockPortrait; |
585 } | 585 } |
586 | 586 |
587 } // namespace ash | 587 } // namespace ash |
OLD | NEW |