From bb34612c13a4ee999e5291352e13a72572571ed3 Mon Sep 17 00:00:00 2001 From: jonross Date: Tue, 28 Apr 2015 07:05:54 -0700 Subject: [PATCH] Merge Prevent DisplayPreferences from saving incorrect rotations. Refactor DisplayInfo::rotation_ to track different sources of rotations Currently DisplayInfo only tracks the active rotation for the given display. DisplayPreferences however saves a user rotation, as well as an accelerometer rotation. DisplayController::Observer::OnDisplayConfigurationChanged triggers the saving of display preferences. This has been leading to active accelerometer rotations being saved as user preferences, and being re-applied upon reboot. This change refactors DisplayInfo to track one rotation per source of rotation changes. DisplayPreferences has been updated to save based on these states. TEST=DisplayPreferencesTest.DontSaveMaximizeModeControllerRotations, also ran ash_unittests, and unit_tests BUG=chrome-os-partner:37555, 469752, 466861 TBR=oshima@chromium.org, mukai@chromium.org, kalman@chromium.org NOTRY=true NOPRESUBMIT=true Review URL: https://codereview.chromium.org/1071353003 Cr-Commit-Position: refs/heads/master@{#326614} (cherry picked from commit d01de7f9b271d29dc1fe9126357a36c5563f0ff0) Review URL: https://codereview.chromium.org/1107383002 Cr-Commit-Position: refs/branch-heads/2357@{#248} Cr-Branched-From: 59d4494849b405682265ed5d3f5164573b9a939b-refs/heads/master@{#323860} --- ash/accelerators/accelerator_controller.cc | 3 +- .../screen_orientation_controller_chromeos.cc | 41 ++++--- .../screen_orientation_controller_chromeos.h | 10 +- ...rientation_controller_chromeos_unittest.cc | 115 ++++++++---------- ash/display/display_controller.cc | 4 +- ash/display/display_controller_unittest.cc | 40 +++--- ash/display/display_info.cc | 30 +++-- ash/display/display_info.h | 17 ++- ash/display/display_info_unittest.cc | 10 +- ash/display/display_manager.cc | 14 ++- ash/display/display_manager.h | 7 +- ash/display/root_window_transformers.cc | 8 +- .../root_window_transformers_unittest.cc | 32 +++-- ash/rotator/screen_rotation_animator.cc | 18 +-- ash/rotator/screen_rotation_animator.h | 6 +- ash/system/audio/tray_audio.cc | 2 +- ash/system/chromeos/tray_display.cc | 15 +-- .../overview/overview_button_tray_unittest.cc | 2 +- ash/test/ash_test_base.cc | 11 ++ ash/test/ash_test_base.h | 7 ++ ash/wm/lock_layout_manager_unittest.cc | 6 +- .../maximize_mode_controller_unittest.cc | 10 -- .../chromeos/display/display_preferences.cc | 9 +- .../display/display_preferences_unittest.cc | 51 ++++---- .../display_info_provider_chromeos.cc | 3 +- ...display_info_provider_chromeos_unittest.cc | 9 +- .../chromeos/display_options_handler.cc | 5 +- ui/gfx/display.h | 12 ++ 28 files changed, 284 insertions(+), 213 deletions(-) diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 076df1edf83db..5a6dba781a213 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -295,7 +295,8 @@ void HandleRotateScreen() { const DisplayInfo& display_info = Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); ash::ScreenRotationAnimator(display.id()) - .Rotate(GetNextRotation(display_info.rotation())); + .Rotate(GetNextRotation(display_info.GetActiveRotation()), + gfx::Display::ROTATION_SOURCE_USER); } // Rotate the active window. diff --git a/ash/content/display/screen_orientation_controller_chromeos.cc b/ash/content/display/screen_orientation_controller_chromeos.cc index dbd44652a2e6b..859c6f8f9ed81 100644 --- a/ash/content/display/screen_orientation_controller_chromeos.cc +++ b/ash/content/display/screen_orientation_controller_chromeos.cc @@ -45,7 +45,7 @@ blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { ash::DisplayInfo info = display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); gfx::Size size = info.size_in_pixel(); - switch (info.rotation()) { + switch (info.GetActiveRotation()) { case gfx::Display::ROTATE_0: case gfx::Display::ROTATE_180: return size.height() >= size.width() @@ -112,7 +112,8 @@ void ScreenOrientationController::SetRotationLocked(bool rotation_locked) { } void ScreenOrientationController::SetDisplayRotation( - gfx::Display::Rotation rotation) { + gfx::Display::Rotation rotation, + gfx::Display::RotationSource source) { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); if (!display_manager->HasInternalDisplay()) return; @@ -120,7 +121,7 @@ void ScreenOrientationController::SetDisplayRotation( base::AutoReset auto_ignore_display_configuration_updates( &ignore_display_configuration_updates_, true); ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) - .Rotate(rotation); + .Rotate(rotation, source); } void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active, @@ -201,7 +202,7 @@ void ScreenOrientationController::OnDisplayConfigurationChanged() { return; gfx::Display::Rotation user_rotation = display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) - .rotation(); + .GetActiveRotation(); if (user_rotation != current_rotation_) { // A user may change other display configuration settings. When the user // does change the rotation setting, then lock rotation to prevent the @@ -219,7 +220,7 @@ void ScreenOrientationController::OnMaximizeModeStarted() { if (display_manager->HasInternalDisplay()) { current_rotation_ = user_rotation_ = display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) - .rotation(); + .GetActiveRotation(); } if (!rotation_locked_) LoadDisplayRotationProperties(); @@ -231,13 +232,14 @@ void ScreenOrientationController::OnMaximizeModeEnded() { chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); Shell::GetInstance()->display_controller()->RemoveObserver(this); if (current_rotation_ != user_rotation_) - SetDisplayRotation(user_rotation_); + SetDisplayRotation(user_rotation_, gfx::Display::ROTATION_SOURCE_USER); } void ScreenOrientationController::LockRotation( - gfx::Display::Rotation rotation) { + gfx::Display::Rotation rotation, + gfx::Display::RotationSource source) { SetRotationLocked(true); - SetDisplayRotation(rotation); + SetDisplayRotation(rotation, source); } void ScreenOrientationController::LockRotationToOrientation( @@ -270,7 +272,8 @@ void ScreenOrientationController::LockRotationToOrientation( blink::WebScreenOrientationLockLandscape); break; case blink::WebScreenOrientationLockNatural: - LockRotation(gfx::Display::ROTATE_0); + LockRotation(gfx::Display::ROTATE_0, + gfx::Display::ROTATION_SOURCE_ACTIVE); break; default: NOTREACHED(); @@ -282,14 +285,16 @@ void ScreenOrientationController::LockRotationToPrimaryOrientation( blink::WebScreenOrientationLockType lock_orientation) { LockRotation(natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_0 - : gfx::Display::ROTATE_90); + : gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); } void ScreenOrientationController::LockRotationToSecondaryOrientation( blink::WebScreenOrientationLockType lock_orientation) { LockRotation(natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_180 - : gfx::Display::ROTATE_270); + : gfx::Display::ROTATE_270, + gfx::Display::ROTATION_SOURCE_ACTIVE); } void ScreenOrientationController::LockToRotationMatchingOrientation( @@ -300,20 +305,22 @@ void ScreenOrientationController::LockToRotationMatchingOrientation( gfx::Display::Rotation rotation = display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) - .rotation(); + .GetActiveRotation(); if (natural_orientation_ == lock_orientation) { if (rotation == gfx::Display::ROTATE_0 || rotation == gfx::Display::ROTATE_180) { SetRotationLocked(true); } else { - LockRotation(gfx::Display::ROTATE_0); + LockRotation(gfx::Display::ROTATE_0, + gfx::Display::ROTATION_SOURCE_ACTIVE); } } else { if (rotation == gfx::Display::ROTATE_90 || rotation == gfx::Display::ROTATE_270) { SetRotationLocked(true); } else { - LockRotation(gfx::Display::ROTATE_90); + LockRotation(gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); } } } @@ -365,14 +372,16 @@ void ScreenOrientationController::HandleScreenRotation( if (new_rotation != current_rotation_ && IsRotationAllowedInLockedState(new_rotation)) - SetDisplayRotation(new_rotation); + SetDisplayRotation(new_rotation, + gfx::Display::ROTATION_SOURCE_ACCELEROMETER); } void ScreenOrientationController::LoadDisplayRotationProperties() { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); if (!display_manager->registered_internal_display_rotation_lock()) return; - SetDisplayRotation(display_manager->registered_internal_display_rotation()); + SetDisplayRotation(display_manager->registered_internal_display_rotation(), + gfx::Display::ROTATION_SOURCE_ACCELEROMETER); SetRotationLocked(true); } diff --git a/ash/content/display/screen_orientation_controller_chromeos.h b/ash/content/display/screen_orientation_controller_chromeos.h index aa45734a24d31..0a84b8cd29640 100644 --- a/ash/content/display/screen_orientation_controller_chromeos.h +++ b/ash/content/display/screen_orientation_controller_chromeos.h @@ -69,8 +69,11 @@ class ASH_EXPORT ScreenOrientationController // display rotation. void SetRotationLocked(bool rotation_locked); - // Sets the display rotation and suppresses display notifications. - void SetDisplayRotation(gfx::Display::Rotation rotation); + // Sets the display rotation for the given |source|. The new |rotation| will + // also become active. Display changed notifications are surpressed for this + // change. + void SetDisplayRotation(gfx::Display::Rotation rotation, + gfx::Display::RotationSource source); // aura::client::ActivationChangeObserver: void OnWindowActivated(aura::Window* gained_active, @@ -102,7 +105,8 @@ class ASH_EXPORT ScreenOrientationController // Sets the display rotation to |rotation|. Future accelerometer updates // should not be used to change the rotation. SetRotationLocked(false) removes // the rotation lock. - void LockRotation(gfx::Display::Rotation rotation); + void LockRotation(gfx::Display::Rotation rotation, + gfx::Display::RotationSource source); // Sets the display rotation based on |lock_orientation|. Future accelerometer // updates should not be used to change the rotation. SetRotationLocked(false) diff --git a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc index 342e9585b8e2a..27ec3d609a0ea 100644 --- a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc +++ b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc @@ -41,20 +41,6 @@ void EnableMaximizeMode(bool enable) { ->EnableMaximizeModeWindowManager(enable); } -gfx::Display::Rotation GetInternalDisplayRotation() { - return Shell::GetInstance() - ->display_manager() - ->GetDisplayInfo(gfx::Display::InternalDisplayId()) - .rotation(); -} - -gfx::Display::Rotation Rotation() { - return Shell::GetInstance() - ->display_manager() - ->GetDisplayInfo(gfx::Display::InternalDisplayId()) - .rotation(); -} - bool RotationLocked() { return Shell::GetInstance() ->screen_orientation_controller() @@ -63,7 +49,8 @@ bool RotationLocked() { void SetInternalDisplayRotation(gfx::Display::Rotation rotation) { Shell::GetInstance()->display_manager()->SetDisplayRotation( - gfx::Display::InternalDisplayId(), rotation); + gfx::Display::InternalDisplayId(), rotation, + gfx::Display::ROTATION_SOURCE_USER); } void SetRotationLocked(bool rotation_locked) { @@ -166,12 +153,12 @@ TEST_F(ScreenOrientationControllerTest, LockOrientation) { scoped_ptr content(CreateWebContents()); scoped_ptr focus_window(CreateTestWindowInShellWithId(0)); ASSERT_NE(nullptr, content->GetNativeView()); - ASSERT_EQ(gfx::Display::ROTATE_0, Rotation()); + ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); ASSERT_FALSE(RotationLocked()); AttachAndActivateWebContents(content.get(), focus_window.get()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); - EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_TRUE(RotationLocked()); } @@ -180,12 +167,12 @@ TEST_F(ScreenOrientationControllerTest, Unlock) { scoped_ptr content(CreateWebContents()); scoped_ptr focus_window(CreateTestWindowInShellWithId(0)); ASSERT_NE(nullptr, content->GetNativeView()); - ASSERT_EQ(gfx::Display::ROTATE_0, Rotation()); + ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); ASSERT_FALSE(RotationLocked()); AttachAndActivateWebContents(content.get(), focus_window.get()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); - EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_TRUE(RotationLocked()); delegate()->Unlock(content.get()); @@ -198,16 +185,16 @@ TEST_F(ScreenOrientationControllerTest, OrientationChanges) { scoped_ptr content(CreateWebContents()); scoped_ptr focus_window(CreateTestWindowInShellWithId(0)); ASSERT_NE(nullptr, content->GetNativeView()); - ASSERT_EQ(gfx::Display::ROTATE_0, Rotation()); + ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); ASSERT_FALSE(RotationLocked()); AttachAndActivateWebContents(content.get(), focus_window.get()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); - EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); EXPECT_TRUE(RotationLocked()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); - EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that orientation can only be set by the first content::WebContents that @@ -223,7 +210,7 @@ TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { AttachWebContents(content2.get(), focus_window2.get()); delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); - EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that only the content::WebContents that set a rotation lock can perform @@ -274,17 +261,17 @@ TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); aura::client::ActivationClient* activation_client = Shell::GetInstance()->activation_client(); activation_client->ActivateWindow(focus_window2.get()); EXPECT_TRUE(RotationLocked()); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); activation_client->ActivateWindow(focus_window1.get()); EXPECT_TRUE(RotationLocked()); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that a rotation lock is removed when the setting window is hidden, and @@ -334,13 +321,13 @@ TEST_F(ScreenOrientationControllerTest, DisplayRotation) { EnableMaximizeMode(true); // Now test rotating in all directions. TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that low angles are ignored by the accelerometer (i.e. when the device @@ -348,15 +335,15 @@ TEST_F(ScreenOrientationControllerTest, DisplayRotation) { TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { EnableMaximizeMode(true); TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that the display will stick to the current orientation beyond the @@ -365,7 +352,7 @@ TEST_F(ScreenOrientationControllerTest, RotationSticky) { EnableMaximizeMode(true); gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); TriggerLidUpdate(gravity); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); // Turn past half-way point to next direction and rotation should remain // the same. @@ -373,14 +360,14 @@ TEST_F(ScreenOrientationControllerTest, RotationSticky) { gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); TriggerLidUpdate(gravity); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); // Turn more and the screen should rotate. degrees = 70.0; gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); TriggerLidUpdate(gravity); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); // Turn back just beyond the half-way point and the new rotation should // still be in effect. @@ -388,7 +375,7 @@ TEST_F(ScreenOrientationControllerTest, RotationSticky) { gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); TriggerLidUpdate(gravity); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); } // Tests that the display will stick to its current orientation when the @@ -403,11 +390,11 @@ TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { -cos(degrees * kDegreesToRadians) * kMeanGravity, 0.0f); TriggerLidUpdate(gravity); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); SetRotationLocked(false); TriggerLidUpdate(gravity); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); } // The TrayDisplay class that is responsible for adding/updating MessageCenter @@ -429,10 +416,10 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { // Make sure notifications are still displayed when // adjusting the screen rotation directly when in maximize mode - ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); + ASSERT_NE(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); SetInternalDisplayRotation(gfx::Display::ROTATE_270); SetRotationLocked(false); - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(1u, message_center->NotificationCount()); EXPECT_TRUE(message_center->HasPopupNotifications()); @@ -444,9 +431,9 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { // Make sure notifications are blocked when adjusting the screen rotation // via the accelerometer while in maximize mode // Rotate the screen 90 degrees - ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + ASSERT_NE(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); - ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + ASSERT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); EXPECT_EQ(0u, message_center->NotificationCount()); EXPECT_FALSE(message_center->HasPopupNotifications()); @@ -457,11 +444,11 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { SetInternalDisplayRotation(gfx::Display::ROTATE_0); // Clear all notifications message_center->RemoveAllNotifications(false); - ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + ASSERT_NE(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); ASSERT_EQ(0u, message_center->NotificationCount()); ASSERT_FALSE(message_center->HasPopupNotifications()); SetInternalDisplayRotation(gfx::Display::ROTATE_180); - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); EXPECT_EQ(1u, message_center->NotificationCount()); EXPECT_TRUE(message_center->HasPopupNotifications()); } @@ -473,10 +460,10 @@ TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { EnableMaximizeMode(true); TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); EnableMaximizeMode(false); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); } // Tests that if a user sets a display rotation that accelerometer rotation @@ -499,7 +486,7 @@ TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { // maximize mode was activated. SetInternalDisplayRotation(gfx::Display::ROTATE_0); EnableMaximizeMode(false); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that when the orientation lock is set to Landscape, that rotation can @@ -511,18 +498,18 @@ TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { AttachAndActivateWebContents(content.get(), focus_window.get()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); - EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_TRUE(RotationLocked()); // Inverse of orientation is allowed TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); // Display rotations between are not allowed TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); } // Tests that when the orientation lock is set to Portrait, that rotaiton can be @@ -534,18 +521,18 @@ TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { AttachAndActivateWebContents(content.get(), focus_window.get()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); - EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); EXPECT_TRUE(RotationLocked()); // Inverse of orientation is allowed TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); // Display rotations between are not allowed TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); } // Tests that for an orientation lock which does not allow rotation, that the @@ -558,16 +545,16 @@ TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { AttachAndActivateWebContents(content.get(), focus_window.get()); delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortraitPrimary); - EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); EXPECT_TRUE(RotationLocked()); // Rotation does not change. TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); } // Tests that after a content::WebContents has applied an orientation lock which @@ -583,10 +570,10 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { SetRotationLocked(true); EXPECT_TRUE(RotationLocked()); - EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); } // Tests that when MaximizeMode is triggered before the internal display is diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc index 166a76f0cdc26..da51923c8e146 100644 --- a/ash/display/display_controller.cc +++ b/ash/display/display_controller.cc @@ -109,7 +109,7 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, const char kInternalProp[] = "_CHROME_DISPLAY_INTERNAL"; const char kCARDINAL[] = "CARDINAL"; int xrandr_rotation = RR_Rotate_0; - switch (info.rotation()) { + switch (info.GetActiveRotation()) { case gfx::Display::ROTATE_0: xrandr_rotation = RR_Rotate_0; break; @@ -140,7 +140,7 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, scale *= kCursorMultiplierForExternalDisplays; ui::CursorController::GetInstance()->SetCursorConfigForWindow( - host->GetAcceleratedWidget(), info.rotation(), scale); + host->GetAcceleratedWidget(), info.GetActiveRotation(), scale); #endif #endif scoped_ptr transformer( diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc index 6945fac2c30fc..6f38a3e64e87c 100644 --- a/ash/display/display_controller_unittest.cc +++ b/ash/display/display_controller_unittest.cc @@ -352,10 +352,6 @@ class TestEventHandler : public ui::EventHandler { DISALLOW_COPY_AND_ASSIGN(TestEventHandler); }; -gfx::Display::Rotation GetStoredRotation(int64 id) { - return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); -} - float GetStoredUIScale(int64 id) { return Shell::GetInstance()->display_manager()->GetDisplayInfo(id). GetEffectiveUIScale(); @@ -557,7 +553,7 @@ DisplayInfo CreateDisplayInfo(int64 id, gfx::Display::Rotation rotation) { DisplayInfo info(id, "", false); info.SetBounds(gfx::Rect(0, y, 500, 500)); - info.set_rotation(rotation); + info.SetRotation(rotation, gfx::Display::ROTATION_SOURCE_ACTIVE); return info; } @@ -686,12 +682,14 @@ TEST_F(DisplayControllerTest, BoundsUpdated) { // Rotation observer.GetRotationChangedCountAndReset(); // we only want to reset. int64 primary_id = GetPrimaryDisplay().id(); - display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); + display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); EXPECT_EQ(1, observer.CountAndReset()); EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); - display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); + display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); EXPECT_EQ(0, observer.CountAndReset()); EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); @@ -1046,20 +1044,20 @@ TEST_F(DisplayControllerTest, Rotate) { ScreenUtil::GetSecondaryDisplay().bounds().ToString()); generator1.MoveMouseToInHost(50, 40); EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); - EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); - display_manager->SetDisplayRotation(display1.id(), - gfx::Display::ROTATE_90); + display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); EXPECT_EQ("200,0 150x200", ScreenUtil::GetSecondaryDisplay().bounds().ToString()); generator1.MoveMouseToInHost(50, 40); EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); - EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); @@ -1067,30 +1065,30 @@ TEST_F(DisplayControllerTest, Rotate) { EXPECT_EQ("50,120 150x200", ScreenUtil::GetSecondaryDisplay().bounds().ToString()); - display_manager->SetDisplayRotation(display2_id, - gfx::Display::ROTATE_270); + display_manager->SetDisplayRotation(display2_id, gfx::Display::ROTATE_270, + gfx::Display::ROTATION_SOURCE_ACTIVE); EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); EXPECT_EQ("50,120 200x150", ScreenUtil::GetSecondaryDisplay().bounds().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_270, GetActiveDisplayRotation(display2_id)); EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); #if !defined(OS_WIN) ui::test::EventGenerator generator2(root_windows[1]); generator2.MoveMouseToInHost(50, 40); EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); - display_manager->SetDisplayRotation(display1.id(), - gfx::Display::ROTATE_180); + display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_180, + gfx::Display::ROTATION_SOURCE_ACTIVE); EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); // Dislay must share at least 100, so the x's offset becomes 20. EXPECT_EQ("20,200 200x150", ScreenUtil::GetSecondaryDisplay().bounds().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_180, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_270, GetActiveDisplayRotation(display2_id)); EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); generator1.MoveMouseToInHost(50, 40); diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc index e812633bc2a6e..e58b51a0e6ac4 100644 --- a/ash/display/display_info.cc +++ b/ash/display/display_info.cc @@ -207,7 +207,7 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, DisplayInfo display_info( id, base::StringPrintf("Display-%d", static_cast(id)), has_overscan); display_info.set_device_scale_factor(device_scale_factor); - display_info.set_rotation(rotation); + display_info.SetRotation(rotation, gfx::Display::ROTATION_SOURCE_ACTIVE); display_info.set_configured_ui_scale(ui_scale); display_info.SetBounds(bounds_in_native); display_info.SetDisplayModes(display_modes); @@ -228,7 +228,6 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, DisplayInfo::DisplayInfo() : id_(gfx::Display::kInvalidDisplayID), has_overscan_(false), - rotation_(gfx::Display::ROTATE_0), touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), touch_device_id_(0), device_scale_factor_(1.0f), @@ -246,7 +245,6 @@ DisplayInfo::DisplayInfo(int64 id, : id_(id), name_(name), has_overscan_(has_overscan), - rotation_(gfx::Display::ROTATE_0), touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), touch_device_id_(0), device_scale_factor_(1.0f), @@ -261,6 +259,23 @@ DisplayInfo::DisplayInfo(int64 id, DisplayInfo::~DisplayInfo() { } +void DisplayInfo::SetRotation(gfx::Display::Rotation rotation, + gfx::Display::RotationSource source) { + rotations_[source] = rotation; + rotations_[gfx::Display::ROTATION_SOURCE_ACTIVE] = rotation; +} + +gfx::Display::Rotation DisplayInfo::GetActiveRotation() const { + return GetRotation(gfx::Display::ROTATION_SOURCE_ACTIVE); +} + +gfx::Display::Rotation DisplayInfo::GetRotation( + gfx::Display::RotationSource source) const { + if (rotations_.find(source) == rotations_.end()) + return gfx::Display::ROTATE_0; + return rotations_.at(source); +} + void DisplayInfo::Copy(const DisplayInfo& native_info) { DCHECK(id_ == native_info.id_); name_ = native_info.name_; @@ -287,7 +302,7 @@ void DisplayInfo::Copy(const DisplayInfo& native_info) { else if (!native_info.overscan_insets_in_dip_.empty()) overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; - rotation_ = native_info.rotation_; + rotations_ = native_info.rotations_; configured_ui_scale_ = native_info.configured_ui_scale_; color_profile_ = native_info.color_profile(); } @@ -325,9 +340,10 @@ void DisplayInfo::UpdateDisplaySize() { overscan_insets_in_dip_.Set(0, 0, 0, 0); } - if (rotation_ == gfx::Display::ROTATE_90 || - rotation_ == gfx::Display::ROTATE_270) + if (GetActiveRotation() == gfx::Display::ROTATE_90 || + GetActiveRotation() == gfx::Display::ROTATE_270) { size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); + } gfx::SizeF size_f(size_in_pixel_); size_f.Scale(GetEffectiveUIScale()); size_in_pixel_ = gfx::ToFlooredSize(size_f); @@ -358,7 +374,7 @@ gfx::Size DisplayInfo::GetNativeModeSize() const { } std::string DisplayInfo::ToString() const { - int rotation_degree = static_cast(rotation_) * 90; + int rotation_degree = static_cast(GetActiveRotation()) * 90; return base::StringPrintf( "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " diff --git a/ash/display/display_info.h b/ash/display/display_info.h index 427355b801296..34f229927c170 100644 --- a/ash/display/display_info.h +++ b/ash/display/display_info.h @@ -5,6 +5,7 @@ #ifndef ASH_DISPLAY_DISPLAY_INFO_H_ #define ASH_DISPLAY_DISPLAY_INFO_H_ +#include #include #include @@ -103,9 +104,6 @@ class ASH_EXPORT DisplayInfo { // actual overscan automatically, but used in the message. bool has_overscan() const { return has_overscan_; } - void set_rotation(gfx::Display::Rotation rotation) { rotation_ = rotation; } - gfx::Display::Rotation rotation() const { return rotation_; } - void set_touch_support(gfx::Display::TouchSupport support) { touch_support_ = support; } @@ -139,6 +137,17 @@ class ASH_EXPORT DisplayInfo { float configured_ui_scale() const { return configured_ui_scale_; } void set_configured_ui_scale(float scale) { configured_ui_scale_ = scale; } + // Sets the rotation for the given |source|. Setting a new rotation will also + // have it become the active rotation. + void SetRotation(gfx::Display::Rotation rotation, + gfx::Display::RotationSource source); + + // Returns the currently active rotation for this display. + gfx::Display::Rotation GetActiveRotation() const; + + // Returns the rotation set by a given |source|. + gfx::Display::Rotation GetRotation(gfx::Display::RotationSource source) const; + // Returns the ui scale and device scale factor actually used to create // display that chrome sees. This can be different from one obtained // from dispaly or one specified by a user in following situation. @@ -231,7 +240,7 @@ class ASH_EXPORT DisplayInfo { int64 id_; std::string name_; bool has_overscan_; - gfx::Display::Rotation rotation_; + std::map rotations_; gfx::Display::TouchSupport touch_support_; // If the display is also a touch device, it will have a positive diff --git a/ash/display/display_info_unittest.cc b/ash/display/display_info_unittest.cc index 01362b43ceaa6..7c5da69f402c3 100644 --- a/ash/display/display_info_unittest.cc +++ b/ash/display/display_info_unittest.cc @@ -29,32 +29,32 @@ TEST_F(DisplayInfoTest, CreateFromSpec) { EXPECT_EQ(10, info.id()); EXPECT_EQ("0,0 200x100", info.bounds_in_native().ToString()); EXPECT_EQ("200x100", info.size_in_pixel().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, info.GetActiveRotation()); EXPECT_EQ("0,0,0,0", info.overscan_insets_in_dip().ToString()); EXPECT_EQ(1.0f, info.configured_ui_scale()); info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/o", 10); EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString()); EXPECT_EQ("288x380", info.size_in_pixel().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, info.GetActiveRotation()); EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString()); info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/ob", 10); EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString()); EXPECT_EQ("288x380", info.size_in_pixel().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation()); + EXPECT_EQ(gfx::Display::ROTATE_0, info.GetActiveRotation()); EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString()); info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/or", 10); EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString()); EXPECT_EQ("380x288", info.size_in_pixel().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_90, info.rotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, info.GetActiveRotation()); // TODO(oshima): This should be rotated too. Fix this. EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString()); info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/l@1.5", 10); EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_270, info.rotation()); + EXPECT_EQ(gfx::Display::ROTATE_270, info.GetActiveRotation()); EXPECT_EQ(1.5f, info.configured_ui_scale()); info = DisplayInfo::CreateFromSpecWithID( diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index b731ded75629b..e1b6551e8e958 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -343,15 +343,18 @@ void DisplayManager::SetOverscanInsets(int64 display_id, } void DisplayManager::SetDisplayRotation(int64 display_id, - gfx::Display::Rotation rotation) { + gfx::Display::Rotation rotation, + gfx::Display::RotationSource source) { DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { DisplayInfo info = GetDisplayInfo(iter->id()); if (info.id() == display_id) { - if (info.rotation() == rotation) + if (info.GetRotation(source) == rotation && + info.GetActiveRotation() == rotation) { return; - info.set_rotation(rotation); + } + info.SetRotation(rotation, source); } display_info_list.push_back(info); } @@ -469,7 +472,8 @@ void DisplayManager::RegisterDisplayProperty( if (display_info_.find(display_id) == display_info_.end()) display_info_[display_id] = DisplayInfo(display_id, std::string(), false); - display_info_[display_id].set_rotation(rotation); + display_info_[display_id].SetRotation(rotation, + gfx::Display::ROTATION_SOURCE_ACTIVE); display_info_[display_id].SetColorProfile(color_profile); // Just in case the preference file was corrupted. // TODO(mukai): register |display_modes_| here as well, so the lookup for the @@ -1152,7 +1156,7 @@ gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64 id) { // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. new_display.SetScaleAndBounds( device_scale_factor, gfx::Rect(bounds_in_native.size())); - new_display.set_rotation(display_info.rotation()); + new_display.set_rotation(display_info.GetActiveRotation()); new_display.set_touch_support(display_info.touch_support()); return new_display; } diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index 092d2b0029612..dc7f15258ee2e 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -151,8 +151,11 @@ class ASH_EXPORT DisplayManager // display's bounds change. void SetOverscanInsets(int64 display_id, const gfx::Insets& insets_in_dip); - // Sets the display's rotation. - void SetDisplayRotation(int64 display_id, gfx::Display::Rotation rotation); + // Sets the display's rotation for the given |source|. The new |rotation| will + // also become active. + void SetDisplayRotation(int64 display_id, + gfx::Display::Rotation rotation, + gfx::Display::RotationSource source); // Sets the display's ui scale. Returns true if it's successful, or // false otherwise. TODO(mukai): remove this and merge into diff --git a/ash/display/root_window_transformers.cc b/ash/display/root_window_transformers.cc index 509bb8e215e64..8a028b37a1061 100644 --- a/ash/display/root_window_transformers.cc +++ b/ash/display/root_window_transformers.cc @@ -62,16 +62,18 @@ gfx::Transform CreateRotationTransform(aura::Window* root_window, // updating the transform results in incorrectly resizing // the root window. Don't apply the transform unless // necessary so that unit tests pass on win8 bots. - if (info.rotation() == root_window->GetProperty(kRotationPropertyKey)) + if (info.GetActiveRotation() == + root_window->GetProperty(kRotationPropertyKey)) { return gfx::Transform(); - root_window->SetProperty(kRotationPropertyKey, info.rotation()); + } + root_window->SetProperty(kRotationPropertyKey, info.GetActiveRotation()); #endif gfx::Transform rotate; // The origin is (0, 0), so the translate width/height must be reduced by // 1 pixel. float one_pixel = 1.0f / display.device_scale_factor(); - switch (info.rotation()) { + switch (info.GetActiveRotation()) { case gfx::Display::ROTATE_0: break; case gfx::Display::ROTATE_90: diff --git a/ash/display/root_window_transformers_unittest.cc b/ash/display/root_window_transformers_unittest.cc index 17c8b36310e3d..6639ec943add2 100644 --- a/ash/display/root_window_transformers_unittest.cc +++ b/ash/display/root_window_transformers_unittest.cc @@ -107,10 +107,6 @@ class TestEventHandler : public ui::EventHandler { DISALLOW_COPY_AND_ASSIGN(TestEventHandler); }; -gfx::Display::Rotation GetStoredRotation(int64 id) { - return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); -} - float GetStoredUIScale(int64 id) { return Shell::GetInstance()->display_manager()->GetDisplayInfo(id). GetEffectiveUIScale(); @@ -158,12 +154,12 @@ TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) { EXPECT_EQ("50,90", event_handler.GetLocationAndReset()); EXPECT_EQ("50,90", aura::Env::GetInstance()->last_mouse_location().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); magnifier->SetEnabled(false); - display_manager->SetDisplayRotation(display1.id(), - gfx::Display::ROTATE_90); + display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); // Move the cursor to the center of the first root window. generator1.MoveMouseToInHost(59, 100); @@ -177,8 +173,8 @@ TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) { EXPECT_EQ("110,70", event_handler.GetLocationAndReset()); EXPECT_EQ("110,70", aura::Env::GetInstance()->last_mouse_location().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); magnifier->SetEnabled(false); DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); @@ -186,8 +182,8 @@ TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) { EXPECT_EQ("50,120 150x200", ScreenUtil::GetSecondaryDisplay().bounds().ToString()); - display_manager->SetDisplayRotation(display2_id, - gfx::Display::ROTATE_270); + display_manager->SetDisplayRotation(display2_id, gfx::Display::ROTATE_270, + gfx::Display::ROTATION_SOURCE_ACTIVE); // Move the cursor to the center of the second root window. generator2.MoveMouseToInHost(151, 199); @@ -200,12 +196,12 @@ TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) { EXPECT_EQ("95,80", event_handler.GetLocationAndReset()); EXPECT_EQ("145,200", aura::Env::GetInstance()->last_mouse_location().ToString()); - EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_270, GetActiveDisplayRotation(display2_id)); magnifier->SetEnabled(false); - display_manager->SetDisplayRotation(display1.id(), - gfx::Display::ROTATE_180); + display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_180, + gfx::Display::ROTATION_SOURCE_ACTIVE); // Move the cursor to the center of the first root window. generator1.MoveMouseToInHost(59, 99); @@ -217,8 +213,8 @@ TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) { ScreenUtil::GetSecondaryDisplay().bounds().ToString()); generator1.MoveMouseToInHost(39, 59); EXPECT_EQ("70,120", event_handler.GetLocationAndReset()); - EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); - EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); + EXPECT_EQ(gfx::Display::ROTATE_180, GetActiveDisplayRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_270, GetActiveDisplayRotation(display2_id)); magnifier->SetEnabled(false); Shell::GetInstance()->RemovePreTargetHandler(&event_handler); diff --git a/ash/rotator/screen_rotation_animator.cc b/ash/rotator/screen_rotation_animator.cc index ed37b7f1da31b..87562191ae5e1 100644 --- a/ash/rotator/screen_rotation_animator.cc +++ b/ash/rotator/screen_rotation_animator.cc @@ -67,7 +67,7 @@ gfx::Display::Rotation GetCurrentRotation(int64 display_id) { return Shell::GetInstance() ->display_manager() ->GetDisplayInfo(display_id) - .rotation(); + .GetActiveRotation(); } // Returns true if the rotation between |initial_rotation| and |new_rotation| is @@ -154,6 +154,7 @@ void LayerCleanupObserver::OnDetachedFromSequence( // animate the change. void RotateScreen(int64 display_id, gfx::Display::Rotation new_rotation, + gfx::Display::RotationSource source, base::TimeDelta duration, int rotation_degrees, int rotation_degree_offset, @@ -181,8 +182,8 @@ void RotateScreen(int64 display_id, scoped_ptr layer_cleanup_observer( new LayerCleanupObserver(old_layer_tree.Pass())); - Shell::GetInstance()->display_manager()->SetDisplayRotation(display_id, - new_rotation); + Shell::GetInstance()->display_manager()->SetDisplayRotation( + display_id, new_rotation, source); const gfx::RectF rotated_screen_bounds = root_window->GetTargetBounds(); const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, @@ -267,7 +268,8 @@ ScreenRotationAnimator::ScreenRotationAnimator(int64 display_id) ScreenRotationAnimator::~ScreenRotationAnimator() { } -void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation) { +void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation, + gfx::Display::RotationSource source) { const gfx::Display::Rotation current_rotation = GetCurrentRotation(display_id_); @@ -279,8 +281,8 @@ void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation) { switches::kAshEnableScreenRotationAnimation); if (switch_value == kRotationAnimation_None) { - Shell::GetInstance()->display_manager()->SetDisplayRotation(display_id_, - new_rotation); + Shell::GetInstance()->display_manager()->SetDisplayRotation( + display_id_, new_rotation, source); } else if (kRotationAnimation_Default == switch_value || kRotationAnimation_Partial == switch_value) { const int rotation_degree_offset = @@ -288,7 +290,7 @@ void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation) { ? 180 - kPartialRotationDegrees : 90 - kPartialRotationDegrees; - RotateScreen(display_id_, new_rotation, + RotateScreen(display_id_, new_rotation, source, base::TimeDelta::FromMilliseconds(kRotationDurationInMs), kPartialRotationDegrees, rotation_degree_offset, gfx::Tween::FAST_OUT_LINEAR_IN, false /* should_scale */); @@ -296,7 +298,7 @@ void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation) { const int rotation_degrees = Is180DegreeFlip(current_rotation, new_rotation) ? 180 : 90; - RotateScreen(display_id_, new_rotation, + RotateScreen(display_id_, new_rotation, source, base::TimeDelta::FromMilliseconds(kRotationDurationInMs), rotation_degrees, 0 /* rotation_degree_offset */, gfx::Tween::FAST_OUT_LINEAR_IN, true /* should_scale */); diff --git a/ash/rotator/screen_rotation_animator.h b/ash/rotator/screen_rotation_animator.h index 055e755906dc4..89c17848f4612 100644 --- a/ash/rotator/screen_rotation_animator.h +++ b/ash/rotator/screen_rotation_animator.h @@ -17,8 +17,10 @@ class ASH_EXPORT ScreenRotationAnimator { explicit ScreenRotationAnimator(int64 display_id); ~ScreenRotationAnimator(); - // Rotates |display_| to the |new_rotation| orientation. - void Rotate(gfx::Display::Rotation new_rotation); + // Rotates |display_| to the |new_rotation| orientation, for the given + // |source|. The rotation will also become active. + void Rotate(gfx::Display::Rotation new_rotation, + gfx::Display::RotationSource source); private: // The id of the display to rotate. diff --git a/ash/system/audio/tray_audio.cc b/ash/system/audio/tray_audio.cc index 21c2163c4d560..7260fc01fe82e 100644 --- a/ash/system/audio/tray_audio.cc +++ b/ash/system/audio/tray_audio.cc @@ -167,7 +167,7 @@ void TrayAudio::ChangeInternalSpeakerChannelMode() { const DisplayInfo& display_info = Shell::GetInstance()->display_manager()->GetDisplayInfo( gfx::Display::InternalDisplayId()); - if (display_info.rotation() == gfx::Display::ROTATE_180) + if (display_info.GetActiveRotation() == gfx::Display::ROTATE_180) channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; } diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/tray_display.cc index 10f9ede1839ad..c964645800f32 100644 --- a/ash/system/chromeos/tray_display.cc +++ b/ash/system/chromeos/tray_display.cc @@ -207,7 +207,7 @@ class DisplayView : public ActionableView { base::string16 name = GetDisplayName(external_id); const DisplayInfo& display_info = display_manager->GetDisplayInfo(external_id); - if (display_info.rotation() != gfx::Display::ROTATE_0 || + if (display_info.GetActiveRotation() != gfx::Display::ROTATE_0 || display_info.configured_ui_scale() != 1.0f || !display_info.overscan_insets_in_dip().empty()) { name = l10n_util::GetStringFUTF16( @@ -263,10 +263,10 @@ class DisplayView : public ActionableView { bool ShouldShowFirstDisplayInfo() const { const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo( GetDisplayManager()->first_display_id()); - return display_info.rotation() != gfx::Display::ROTATE_0 || - display_info.configured_ui_scale() != 1.0f || - !display_info.overscan_insets_in_dip().empty() || - display_info.has_overscan(); + return display_info.GetActiveRotation() != gfx::Display::ROTATE_0 || + display_info.configured_ui_scale() != 1.0f || + !display_info.overscan_insets_in_dip().empty() || + display_info.has_overscan(); } // Overridden from ActionableView. @@ -340,9 +340,10 @@ bool TrayDisplay::GetDisplayMessageForNotification( GetDisplaySize(iter->first)); return true; } - if (iter->second.rotation() != old_iter->second.rotation()) { + if (iter->second.GetActiveRotation() != + old_iter->second.GetActiveRotation()) { int rotation_text_id = 0; - switch (iter->second.rotation()) { + switch (iter->second.GetActiveRotation()) { case gfx::Display::ROTATE_0: rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION; break; diff --git a/ash/system/overview/overview_button_tray_unittest.cc b/ash/system/overview/overview_button_tray_unittest.cc index 516a5ba37f7d9..3268b7b068989 100644 --- a/ash/system/overview/overview_button_tray_unittest.cc +++ b/ash/system/overview/overview_button_tray_unittest.cc @@ -189,7 +189,7 @@ TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletes) { new ui::ScopedAnimationDurationScaleMode( ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) - .Rotate(gfx::Display::ROTATE_270); + .Rotate(gfx::Display::ROTATE_270, gfx::Display::ROTATION_SOURCE_ACTIVE); RunAllPendingInMessageLoop(); EXPECT_FALSE(GetTray()->visible()); diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index ef7fba32473c0..153eea5cae6a6 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -202,6 +202,17 @@ ui::test::EventGenerator& AshTestBase::GetEventGenerator() { return *event_generator_.get(); } +gfx::Display::Rotation AshTestBase::GetActiveDisplayRotation(int64 id) { + return Shell::GetInstance() + ->display_manager() + ->GetDisplayInfo(id) + .GetActiveRotation(); +} + +gfx::Display::Rotation AshTestBase::GetCurrentInternalDisplayRotation() { + return GetActiveDisplayRotation(gfx::Display::InternalDisplayId()); +} + bool AshTestBase::SupportsMultipleDisplays() { return AshTestHelper::SupportsMultipleDisplays(); } diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index e877eec5e9698..bc59cbc9fb390 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -13,6 +13,7 @@ #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/display.h" #include "ui/wm/public/window_types.h" #if defined(OS_WIN) @@ -99,6 +100,12 @@ class AshTestBase : public testing::Test { NUMBER_OF_BLOCK_REASONS }; + // Returns the rotation currentl active for the display |id|. + static gfx::Display::Rotation GetActiveDisplayRotation(int64 id); + + // Returns the rotation currently active for the internal display. + static gfx::Display::Rotation GetCurrentInternalDisplayRotation(); + // Proxy to AshTestHelper::SupportsMultipleDisplays(). static bool SupportsMultipleDisplays(); diff --git a/ash/wm/lock_layout_manager_unittest.cc b/ash/wm/lock_layout_manager_unittest.cc index fc097fb303cd6..17994161281d3 100644 --- a/ash/wm/lock_layout_manager_unittest.cc +++ b/ash/wm/lock_layout_manager_unittest.cc @@ -212,12 +212,14 @@ TEST_F(LockLayoutManagerTest, KeyboardBounds) { ash::DisplayManager* display_manager = Shell::GetInstance()->display_manager(); display_manager->SetDisplayRotation(primary_display.id(), - gfx::Display::ROTATE_90); + gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_ACTIVE); primary_display = Shell::GetScreen()->GetPrimaryDisplay(); screen_bounds = primary_display.bounds(); EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); display_manager->SetDisplayRotation(primary_display.id(), - gfx::Display::ROTATE_0); + gfx::Display::ROTATE_0, + gfx::Display::ROTATION_SOURCE_ACTIVE); // When virtual keyboard overscroll is disabled keyboard bounds do // affect window bounds. diff --git a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc index d4096f492c3fa..847e71a27d05e 100644 --- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc +++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc @@ -162,16 +162,6 @@ class MaximizeModeControllerTest : public test::AshTestBase { return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled(); } - gfx::Display::Rotation GetInternalDisplayRotation() const { - return Shell::GetInstance()->display_manager()->GetDisplayInfo( - gfx::Display::InternalDisplayId()).rotation(); - } - - void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const { - Shell::GetInstance()->display_manager()-> - SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation); - } - // Attaches a SimpleTestTickClock to the MaximizeModeController with a non // null value initial value. void AttachTickClockForTest() { diff --git a/chrome/browser/chromeos/display/display_preferences.cc b/chrome/browser/chromeos/display/display_preferences.cc index a71342ddcd4b3..067d582e533c4 100644 --- a/chrome/browser/chromeos/display/display_preferences.cc +++ b/chrome/browser/chromeos/display/display_preferences.cc @@ -251,7 +251,9 @@ void StoreCurrentDisplayProperties() { scoped_ptr property_value( new base::DictionaryValue()); - property_value->SetInteger("rotation", static_cast(info.rotation())); + property_value->SetInteger( + "rotation", + static_cast(info.GetRotation(gfx::Display::ROTATION_SOURCE_USER))); property_value->SetInteger( "ui-scale", static_cast(info.configured_ui_scale() * 1000)); @@ -356,8 +358,9 @@ void StoreDisplayRotationPrefs(bool rotation_lock) { DictionaryPrefUpdate update(local_state, prefs::kDisplayRotationLock); base::DictionaryValue* pref_data = update.Get(); pref_data->SetBoolean("lock", rotation_lock); - gfx::Display::Rotation rotation = display_manager-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation rotation = + display_manager->->GetDisplayInfo(gfx::Display::InternalDisplayId()) + .GetRotation(gfx::Display::ROTATION_SOURCE_ACCELEROMETER); pref_data->SetInteger("orientation", static_cast(rotation)); } diff --git a/chrome/browser/chromeos/display/display_preferences_unittest.cc b/chrome/browser/chromeos/display/display_preferences_unittest.cc index d38e5723c070c..96c08ad7371f9 100644 --- a/chrome/browser/chromeos/display/display_preferences_unittest.cc +++ b/chrome/browser/chromeos/display/display_preferences_unittest.cc @@ -245,7 +245,8 @@ TEST_F(DisplayPreferencesTest, BasicStores) { EXPECT_NE(dummy_id, ash::Shell::GetScreen()->GetPrimaryDisplay().id()); display_controller->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); - display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90); + display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_USER); EXPECT_TRUE(display_manager->SetDisplayUIScale(id1, 1.25f)); EXPECT_FALSE(display_manager->SetDisplayUIScale(id2, 1.25f)); @@ -576,7 +577,8 @@ TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { display_controller->SetOverscanInsets( new_primary, gfx::Insets(10, 11, 12, 13)); - display_manager->SetDisplayRotation(new_primary, gfx::Display::ROTATE_90); + display_manager->SetDisplayRotation(new_primary, gfx::Display::ROTATE_90, + gfx::Display::ROTATION_SOURCE_USER); // Does not store the preferences locally. EXPECT_FALSE(local_state()->FindPreference( @@ -599,7 +601,7 @@ TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { const ash::DisplayInfo& info_primary = display_manager->GetDisplayInfo(new_primary); - EXPECT_EQ(gfx::Display::ROTATE_90, info_primary.rotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, info_primary.GetActiveRotation()); EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); } @@ -669,10 +671,12 @@ TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { LoggedInAsUser(); // Populate the properties. display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), - gfx::Display::ROTATE_180); + gfx::Display::ROTATE_180, + gfx::Display::ROTATION_SOURCE_USER); // Reset property to avoid rotation lock display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), - gfx::Display::ROTATE_0); + gfx::Display::ROTATE_0, + gfx::Display::ROTATION_SOURCE_USER); // Open up 270 degrees to trigger maximize mode scoped_refptr update( @@ -690,8 +694,7 @@ TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); controller->OnAccelerometerUpdated(update); shell->screen_orientation_controller()->OnAccelerometerUpdated(update); - EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); const base::DictionaryValue* properties = local_state()->GetDictionary(prefs::kDisplayProperties); @@ -701,6 +704,17 @@ TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { int rotation = -1; EXPECT_TRUE(property->GetInteger("rotation", &rotation)); EXPECT_EQ(gfx::Display::ROTATE_0, rotation); + + // Trigger a save, the acceleration rotation should not be saved as the user + // rotation. + StoreDisplayPrefs(); + properties = local_state()->GetDictionary(prefs::kDisplayProperties); + property = NULL; + EXPECT_TRUE(properties->GetDictionary( + base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); + rotation = -1; + EXPECT_TRUE(property->GetInteger("rotation", &rotation)); + EXPECT_EQ(gfx::Display::ROTATE_0, rotation); } // Tests that the rotation state is saved without a user being logged in. @@ -720,9 +734,7 @@ TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { EXPECT_EQ(current_rotation_lock, rotation_lock); int orientation; - gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> - display_manager()-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation current_rotation = GetCurrentInternalDisplayRotation(); EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); EXPECT_EQ(current_rotation, orientation); } @@ -745,9 +757,7 @@ TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { EXPECT_EQ(current_rotation_lock, rotation_lock); int orientation; - gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> - display_manager()-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation current_rotation = GetCurrentInternalDisplayRotation(); EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); EXPECT_EQ(current_rotation, orientation); } @@ -770,9 +780,7 @@ TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { EXPECT_EQ(current_rotation_lock, rotation_lock); int orientation; - gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> - display_manager()-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation current_rotation = GetCurrentInternalDisplayRotation(); EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); EXPECT_EQ(current_rotation, orientation); } @@ -788,8 +796,7 @@ TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { bool initial_rotation_lock = IsRotationLocked(); ASSERT_FALSE(initial_rotation_lock); ash::DisplayManager* display_manager = shell->display_manager(); - gfx::Display::Rotation initial_rotation = display_manager-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation initial_rotation = GetCurrentInternalDisplayRotation(); ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); StoreDisplayRotationPrefs(initial_rotation_lock); @@ -806,8 +813,8 @@ TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); bool rotation_lock = IsRotationLocked(); - gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation before_maximize_mode_rotation = + GetCurrentInternalDisplayRotation(); // Settings should not be applied until maximize mode activates EXPECT_FALSE(rotation_lock); @@ -824,8 +831,8 @@ TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { maximize_mode_controller->OnAccelerometerUpdated(update); EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); bool screen_orientation_rotation_lock = IsRotationLocked(); - gfx::Display::Rotation maximize_mode_rotation = display_manager-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation maximize_mode_rotation = + GetCurrentInternalDisplayRotation(); EXPECT_TRUE(screen_orientation_rotation_lock); EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); } diff --git a/chrome/browser/extensions/display_info_provider_chromeos.cc b/chrome/browser/extensions/display_info_provider_chromeos.cc index 60c6e6cc3d813..b9d083de48046 100644 --- a/chrome/browser/extensions/display_info_provider_chromeos.cc +++ b/chrome/browser/extensions/display_info_provider_chromeos.cc @@ -334,7 +334,8 @@ bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str, // Process 'rotation' parameter. if (info.rotation) { display_manager->SetDisplayRotation(display_id, - DegreesToRotation(*info.rotation)); + DegreesToRotation(*info.rotation), + gfx::Display::ROTATION_SOURCE_ACTIVE); } // Process new display origin parameters. diff --git a/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc b/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc index 493e54c4ac7ca..caef15fbb5df5 100644 --- a/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc +++ b/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc @@ -121,7 +121,8 @@ TEST_F(DisplayInfoProviderChromeosTest, GetRotation) { EXPECT_EQ("0,0 600x500", SystemInfoDisplayBoundsToString(result[0]->bounds)); EXPECT_EQ(90, result[0]->rotation); - GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_270); + GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_270, + gfx::Display::ROTATION_SOURCE_ACTIVE); result = DisplayInfoProvider::Get()->GetAllDisplaysInfo(); @@ -131,7 +132,8 @@ TEST_F(DisplayInfoProviderChromeosTest, GetRotation) { EXPECT_EQ("0,0 600x500", SystemInfoDisplayBoundsToString(result[0]->bounds)); EXPECT_EQ(270, result[0]->rotation); - GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_180); + GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_180, + gfx::Display::ROTATION_SOURCE_ACTIVE); result = DisplayInfoProvider::Get()->GetAllDisplaysInfo(); @@ -141,7 +143,8 @@ TEST_F(DisplayInfoProviderChromeosTest, GetRotation) { EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result[0]->bounds)); EXPECT_EQ(180, result[0]->rotation); - GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_0); + GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_0, + gfx::Display::ROTATION_SOURCE_ACTIVE); result = DisplayInfoProvider::Get()->GetAllDisplaysInfo(); diff --git a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc index d354743822091..db256f162a739 100644 --- a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc @@ -279,7 +279,7 @@ void DisplayOptionsHandler::SendDisplayInfo( js_display->SetBoolean("isPrimary", display.id() == primary_id); js_display->SetBoolean("isInternal", display.IsInternal()); js_display->SetInteger("orientation", - static_cast(display_info.rotation())); + static_cast(display_info.GetActiveRotation())); base::ListValue* js_resolutions = new base::ListValue(); for (const ash::DisplayMode& display_mode : display_info.display_modes()) { @@ -438,7 +438,8 @@ void DisplayOptionsHandler::HandleSetOrientation(const base::ListValue* args) { content::RecordAction( base::UserMetricsAction("Options_DisplaySetOrientation")); - ash::ScreenRotationAnimator(display_id).Rotate(new_rotation); + ash::ScreenRotationAnimator(display_id) + .Rotate(new_rotation, gfx::Display::ROTATION_SOURCE_USER); } void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { diff --git a/ui/gfx/display.h b/ui/gfx/display.h index fe2a40cf632b6..f6c23c1fbbac8 100644 --- a/ui/gfx/display.h +++ b/ui/gfx/display.h @@ -30,6 +30,18 @@ class GFX_EXPORT Display { ROTATE_270, }; + // The display rotation can have multiple causes for change. A user can set a + // preference. On devices with accelerometers, they can change the rotation. + // RotationSource allows for the tracking of a Rotation per source of the + // change. ROTATION_SOURCE_ACTIVE is the current rotation of the display. + // Rotation changes not due to an accelerometer, nor the user, are to use this + // source directly. + enum RotationSource { + ROTATION_SOURCE_ACCELEROMETER = 0, + ROTATION_SOURCE_ACTIVE, + ROTATION_SOURCE_USER, + }; + // Touch support for the display. enum TouchSupport { TOUCH_SUPPORT_UNKNOWN,