summaryrefslogtreecommitdiffstats
path: root/ash/content
diff options
context:
space:
mode:
authorjonross <jonross@chromium.org>2015-04-15 13:51:15 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-15 20:52:41 +0000
commit31fed68a524d49f99cebf02dca6ad49019e9900c (patch)
tree183bab170b8f13ebf3f25593ec1c31e00051f987 /ash/content
parent31a66f3e705d20a39033a7b7d7f09a60517e6b9d (diff)
downloadchromium_src-31fed68a524d49f99cebf02dca6ad49019e9900c.zip
chromium_src-31fed68a524d49f99cebf02dca6ad49019e9900c.tar.gz
chromium_src-31fed68a524d49f99cebf02dca6ad49019e9900c.tar.bz2
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}
Diffstat (limited to 'ash/content')
-rw-r--r--ash/content/display/screen_orientation_controller_chromeos.cc22
-rw-r--r--ash/content/display/screen_orientation_controller_chromeos_unittest.cc19
2 files changed, 31 insertions, 10 deletions
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