From 31fed68a524d49f99cebf02dca6ad49019e9900c Mon Sep 17 00:00:00 2001 From: jonross Date: Wed, 15 Apr 2015 13:51:15 -0700 Subject: ScreenOrientationController to start observing even without an internal display. Ozone loads display configurations asynchronously. Due to this the internal display is not always known when Maximize Mode is triggered. Update ScreenOrientationController to become an observer even when there is no internal display ready yet. That way, once it becomes ready, it is able to process accelerometer events. TEST=ScreenOrientationControllerTest.InternalDisplayNotAvailableAtStartup BUG=chrome-os-partner:38796 Review URL: https://codereview.chromium.org/1080553002 Cr-Commit-Position: refs/heads/master@{#325298} --- .../screen_orientation_controller_chromeos.cc | 22 ++++++++++++---------- ...een_orientation_controller_chromeos_unittest.cc | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'ash/content') diff --git a/ash/content/display/screen_orientation_controller_chromeos.cc b/ash/content/display/screen_orientation_controller_chromeos.cc index 07659d7c..dbd4465 100644 --- a/ash/content/display/screen_orientation_controller_chromeos.cc +++ b/ash/content/display/screen_orientation_controller_chromeos.cc @@ -196,10 +196,11 @@ void ScreenOrientationController::Unlock(content::WebContents* web_contents) { void ScreenOrientationController::OnDisplayConfigurationChanged() { if (ignore_display_configuration_updates_) return; + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); + if (!display_manager->HasInternalDisplay()) + return; gfx::Display::Rotation user_rotation = - Shell::GetInstance() - ->display_manager() - ->GetDisplayInfo(gfx::Display::InternalDisplayId()) + display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) .rotation(); if (user_rotation != current_rotation_) { // A user may change other display configuration settings. When the user @@ -212,11 +213,14 @@ void ScreenOrientationController::OnDisplayConfigurationChanged() { void ScreenOrientationController::OnMaximizeModeStarted() { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay()) - return; - current_rotation_ = user_rotation_ = - display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) - .rotation(); + // Do not exit early, as the internal display can be determined after Maximize + // Mode has started. (chrome-os-partner:38796) + // Always start observing. + if (display_manager->HasInternalDisplay()) { + current_rotation_ = user_rotation_ = + display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) + .rotation(); + } if (!rotation_locked_) LoadDisplayRotationProperties(); chromeos::AccelerometerReader::GetInstance()->AddObserver(this); @@ -224,8 +228,6 @@ void ScreenOrientationController::OnMaximizeModeStarted() { } void ScreenOrientationController::OnMaximizeModeEnded() { - if (!Shell::GetInstance()->display_manager()->HasInternalDisplay()) - return; chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); Shell::GetInstance()->display_controller()->RemoveObserver(this); if (current_rotation_ != user_rotation_) diff --git a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc index ca02ca3..342e958 100644 --- a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc +++ b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc @@ -589,4 +589,23 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); } +// Tests that when MaximizeMode is triggered before the internal display is +// ready, that ScreenOrientationController still begins listening to events, +// which require an internal display to be acted upon. +TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { + int64 internal_display_id = gfx::Display::InternalDisplayId(); + gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID); + + EnableMaximizeMode(true); + + // Should not crash, even thought there is no internal display. + SetInternalDisplayRotation(gfx::Display::ROTATE_180); + EXPECT_FALSE(RotationLocked()); + + // With an internal display now available, functionality should resume. + gfx::Display::SetInternalDisplayId(internal_display_id); + SetInternalDisplayRotation(gfx::Display::ROTATE_90); + EXPECT_TRUE(RotationLocked()); +} + } // namespace ash -- cgit v1.1