| 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/content/display/screen_orientation_controller_chromeos.h" | 5 #include "ash/content/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_info.h" | 8 #include "ash/display/display_info.h" |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/rotator/screen_rotation_animator.h" | 10 #include "ash/rotator/screen_rotation_animator.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); | 337 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); |
| 338 float lid_flattened_length = lid_flattened.Length(); | 338 float lid_flattened_length = lid_flattened.Length(); |
| 339 // When the lid is close to being flat, don't change rotation as it is too | 339 // When the lid is close to being flat, don't change rotation as it is too |
| 340 // sensitive to slight movements. | 340 // sensitive to slight movements. |
| 341 if (lid_flattened_length < kMinimumAccelerationScreenRotation) | 341 if (lid_flattened_length < kMinimumAccelerationScreenRotation) |
| 342 return; | 342 return; |
| 343 | 343 |
| 344 // The reference vector is the angle of gravity when the device is rotated | 344 // The reference vector is the angle of gravity when the device is rotated |
| 345 // clockwise by 45 degrees. Computing the angle between this vector and | 345 // clockwise by 45 degrees. Computing the angle between this vector and |
| 346 // gravity we can easily determine the expected display rotation. | 346 // gravity we can easily determine the expected display rotation. |
| 347 static const gfx::Vector3dF rotation_reference(-1.0f, -1.0f, 0.0f); | 347 static const gfx::Vector3dF rotation_reference(-1.0f, 1.0f, 0.0f); |
| 348 | 348 |
| 349 // Set the down vector to match the expected direction of gravity given the | 349 // Set the down vector to match the expected direction of gravity given the |
| 350 // last configured rotation. This is used to enforce a stickiness that the | 350 // last configured rotation. This is used to enforce a stickiness that the |
| 351 // user must overcome to rotate the display and prevents frequent rotations | 351 // user must overcome to rotate the display and prevents frequent rotations |
| 352 // when holding the device near 45 degrees. | 352 // when holding the device near 45 degrees. |
| 353 gfx::Vector3dF down(0.0f, 0.0f, 0.0f); | 353 gfx::Vector3dF down(0.0f, 0.0f, 0.0f); |
| 354 if (current_rotation_ == gfx::Display::ROTATE_0) | 354 if (current_rotation_ == gfx::Display::ROTATE_0) |
| 355 down.set_y(1.0f); |
| 356 else if (current_rotation_ == gfx::Display::ROTATE_90) |
| 357 down.set_x(1.0f); |
| 358 else if (current_rotation_ == gfx::Display::ROTATE_180) |
| 355 down.set_y(-1.0f); | 359 down.set_y(-1.0f); |
| 356 else if (current_rotation_ == gfx::Display::ROTATE_90) | 360 else |
| 357 down.set_x(-1.0f); | 361 down.set_x(-1.0f); |
| 358 else if (current_rotation_ == gfx::Display::ROTATE_180) | |
| 359 down.set_y(1.0f); | |
| 360 else | |
| 361 down.set_x(1.0f); | |
| 362 | 362 |
| 363 // Don't rotate if the screen has not passed the threshold. | 363 // Don't rotate if the screen has not passed the threshold. |
| 364 if (gfx::AngleBetweenVectorsInDegrees(down, lid_flattened) < | 364 if (gfx::AngleBetweenVectorsInDegrees(down, lid_flattened) < |
| 365 kDisplayRotationStickyAngleDegrees) { | 365 kDisplayRotationStickyAngleDegrees) { |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 | 368 |
| 369 float angle = gfx::ClockwiseAngleBetweenVectorsInDegrees( | 369 float angle = gfx::ClockwiseAngleBetweenVectorsInDegrees( |
| 370 rotation_reference, lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); | 370 rotation_reference, lid_flattened, gfx::Vector3dF(0.0f, 0.0f, 1.0f)); |
| 371 | 371 |
| 372 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; | 372 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_270; |
| 373 if (angle < 90.0f) | 373 if (angle < 90.0f) |
| 374 new_rotation = gfx::Display::ROTATE_0; | 374 new_rotation = gfx::Display::ROTATE_0; |
| 375 else if (angle < 180.0f) | 375 else if (angle < 180.0f) |
| 376 new_rotation = gfx::Display::ROTATE_270; | 376 new_rotation = gfx::Display::ROTATE_90; |
| 377 else if (angle < 270.0f) | 377 else if (angle < 270.0f) |
| 378 new_rotation = gfx::Display::ROTATE_180; | 378 new_rotation = gfx::Display::ROTATE_180; |
| 379 | 379 |
| 380 if (new_rotation != current_rotation_ && | 380 if (new_rotation != current_rotation_ && |
| 381 IsRotationAllowedInLockedState(new_rotation)) | 381 IsRotationAllowedInLockedState(new_rotation)) { |
| 382 SetDisplayRotation(new_rotation, | 382 SetDisplayRotation(new_rotation, |
| 383 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); | 383 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); |
| 384 } |
| 384 } | 385 } |
| 385 | 386 |
| 386 void ScreenOrientationController::LoadDisplayRotationProperties() { | 387 void ScreenOrientationController::LoadDisplayRotationProperties() { |
| 387 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 388 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 388 if (!display_manager->registered_internal_display_rotation_lock()) | 389 if (!display_manager->registered_internal_display_rotation_lock()) |
| 389 return; | 390 return; |
| 390 SetDisplayRotation(display_manager->registered_internal_display_rotation(), | 391 SetDisplayRotation(display_manager->registered_internal_display_rotation(), |
| 391 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); | 392 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); |
| 392 SetRotationLocked(true); | 393 SetRotationLocked(true); |
| 393 } | 394 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 433 } |
| 433 | 434 |
| 434 bool ScreenOrientationController::CanRotateInLockedState() { | 435 bool ScreenOrientationController::CanRotateInLockedState() { |
| 435 return rotation_locked_orientation_ == | 436 return rotation_locked_orientation_ == |
| 436 blink::WebScreenOrientationLockLandscape || | 437 blink::WebScreenOrientationLockLandscape || |
| 437 rotation_locked_orientation_ == | 438 rotation_locked_orientation_ == |
| 438 blink::WebScreenOrientationLockPortrait; | 439 blink::WebScreenOrientationLockPortrait; |
| 439 } | 440 } |
| 440 | 441 |
| 441 } // namespace ash | 442 } // namespace ash |
| OLD | NEW |