summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-20 15:23:32 +0000
committerjonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-20 15:25:04 +0000
commit62e90d40bc221a4465987938e2089da1bf30e2d1 (patch)
treeb961f2bc301a4daa766bec58437724c6f38c97ec
parentfe120441b24c53afc87733c9f533f3bd5fc955ef (diff)
downloadchromium_src-62e90d40bc221a4465987938e2089da1bf30e2d1.zip
chromium_src-62e90d40bc221a4465987938e2089da1bf30e2d1.tar.gz
chromium_src-62e90d40bc221a4465987938e2089da1bf30e2d1.tar.bz2
Rotation Locked saved through device shutdown
Add display rotation preferences to DisplayPreferences. Save the current rotation locked state, along with the screen orientation. These are re-applied upon device reboot, while the device is in maximize mode. Leaving maximize mode clears these settings. TEST=DisplayPreferencesTest.StoreRotationStateNoLogin, DisplayPreferencesTest.StoreRotationStateGuest, DisplayPreferencesTest.StoreRotationStateNormalUser, DisplayPreferencesTest.LoadRotationNoLogin, DisplayPreferencesTest.LoadRotationIgnoredInNormalMode, DisplayPreferencesTest.RotationLockTriggersSTore BUG=chrome-os-partner:30681 Review URL: https://codereview.chromium.org/440773005 Cr-Commit-Position: refs/heads/master@{#290842} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290842 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/display/display_manager.cc14
-rw-r--r--ash/display/display_manager.h22
-rw-r--r--ash/shell.cc3
-rw-r--r--ash/system/chromeos/tray_display.cc2
-rw-r--r--ash/wm/maximize_mode/maximize_mode_controller.cc56
-rw-r--r--ash/wm/maximize_mode/maximize_mode_controller.h18
-rw-r--r--chrome/browser/chromeos/display/display_preferences.cc40
-rw-r--r--chrome/browser/chromeos/display/display_preferences.h4
-rw-r--r--chrome/browser/chromeos/display/display_preferences_unittest.cc183
-rw-r--r--chrome/common/pref_names.cc4
-rw-r--r--chrome/common/pref_names.h1
11 files changed, 327 insertions, 20 deletions
diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc
index 6d64f36..8ad5738 100644
--- a/ash/display/display_manager.cc
+++ b/ash/display/display_manager.cc
@@ -161,7 +161,9 @@ DisplayManager::DisplayManager()
force_bounds_changed_(false),
change_display_upon_host_resize_(false),
second_display_mode_(EXTENDED),
- mirrored_display_id_(gfx::Display::kInvalidDisplayID) {
+ mirrored_display_id_(gfx::Display::kInvalidDisplayID),
+ registered_internal_display_rotation_lock_(false),
+ registered_internal_display_rotation_(gfx::Display::ROTATE_0) {
#if defined(OS_CHROMEOS)
change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS();
#endif
@@ -581,6 +583,16 @@ DisplayMode DisplayManager::GetActiveModeForDisplayId(int64 display_id) const {
return selected_mode;
}
+void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock,
+ gfx::Display::Rotation rotation) {
+ if (delegate_)
+ delegate_->PreDisplayConfigurationChange(false);
+ registered_internal_display_rotation_lock_ = rotation_lock;
+ registered_internal_display_rotation_ = rotation;
+ if (delegate_)
+ delegate_->PostDisplayConfigurationChange();
+}
+
bool DisplayManager::GetSelectedModeForDisplayId(int64 id,
DisplayMode* mode_out) const {
std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id);
diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h
index 9c57fde21..a0ab7af 100644
--- a/ash/display/display_manager.h
+++ b/ash/display/display_manager.h
@@ -185,6 +185,22 @@ class ASH_EXPORT DisplayManager
float device_scale_factor,
ui::ColorCalibrationProfile color_profile);
+ // Register stored rotation properties for the internal display.
+ void RegisterDisplayRotationProperties(bool rotation_lock,
+ gfx::Display::Rotation rotation);
+
+ // Returns the stored rotation lock preference if it has been loaded,
+ // otherwise false.
+ bool registered_internal_display_rotation_lock() const {
+ return registered_internal_display_rotation_lock_;
+ }
+
+ // Returns the stored rotation preference for the internal display if it has
+ // been loaded, otherwise |gfx::Display::Rotate_0|.
+ gfx::Display::Rotation registered_internal_display_rotation() const {
+ return registered_internal_display_rotation_;
+ }
+
// Returns the display mode of |display_id| which is currently used.
DisplayMode GetActiveModeForDisplayId(int64 display_id) const;
@@ -375,6 +391,12 @@ private:
int64 mirrored_display_id_;
gfx::Display non_desktop_display_;
+ // User preference for rotation lock of the internal display.
+ bool registered_internal_display_rotation_lock_;
+
+ // User preference for the rotation of the internal display.
+ gfx::Display::Rotation registered_internal_display_rotation_;
+
DISALLOW_COPY_AND_ASSIGN(DisplayManager);
};
diff --git a/ash/shell.cc b/ash/shell.cc
index 453a008..3889571 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -485,7 +485,8 @@ void Shell::RemoveShellObserver(ShellObserver* observer) {
#if defined(OS_CHROMEOS)
bool Shell::ShouldSaveDisplaySettings() {
return !((maximize_mode_controller_->IsMaximizeModeWindowManagerEnabled() &&
- maximize_mode_controller_->in_set_screen_rotation()) ||
+ maximize_mode_controller_->
+ ignore_display_configuration_updates()) ||
resolution_notification_controller_->DoesNotificationTimeout());
}
#endif
diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/tray_display.cc
index d8cafb9..a02e0c8 100644
--- a/ash/system/chromeos/tray_display.cc
+++ b/ash/system/chromeos/tray_display.cc
@@ -381,7 +381,7 @@ void TrayDisplay::CreateOrUpdateNotification(
// Don't display notifications for accelerometer triggered screen rotations.
// See http://crbug.com/364949
if (Shell::GetInstance()->maximize_mode_controller()->
- in_set_screen_rotation()) {
+ ignore_display_configuration_updates()) {
return;
}
diff --git a/ash/wm/maximize_mode/maximize_mode_controller.cc b/ash/wm/maximize_mode/maximize_mode_controller.cc
index add7fb3..6f655b2 100644
--- a/ash/wm/maximize_mode/maximize_mode_controller.cc
+++ b/ash/wm/maximize_mode/maximize_mode_controller.cc
@@ -156,7 +156,8 @@ void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) {
MaximizeModeController::MaximizeModeController()
: rotation_locked_(false),
have_seen_accelerometer_data_(false),
- in_set_screen_rotation_(false),
+ ignore_display_configuration_updates_(false),
+ shutting_down_(false),
user_rotation_(gfx::Display::ROTATE_0),
last_touchview_transition_time_(base::Time::Now()),
tick_clock_(new base::DefaultTickClock()),
@@ -181,7 +182,11 @@ MaximizeModeController::~MaximizeModeController() {
void MaximizeModeController::SetRotationLocked(bool rotation_locked) {
if (rotation_locked_ == rotation_locked)
return;
+ base::AutoReset<bool> auto_ignore_display_configuration_updates(
+ &ignore_display_configuration_updates_, true);
rotation_locked_ = rotation_locked;
+ Shell::GetInstance()->display_manager()->
+ RegisterDisplayRotationProperties(rotation_locked_, current_rotation_);
FOR_EACH_OBSERVER(Observer, observers_,
OnRotationLockChanged(rotation_locked_));
}
@@ -226,13 +231,14 @@ void MaximizeModeController::AddWindow(aura::Window* window) {
}
void MaximizeModeController::Shutdown() {
- maximize_mode_window_manager_.reset();
- Shell::GetInstance()->OnMaximizeModeEnded();
+ shutting_down_ = true;
+ LeaveMaximizeMode();
}
void MaximizeModeController::OnAccelerometerUpdated(
const gfx::Vector3dF& base,
const gfx::Vector3dF& lid) {
+ bool first_accelerometer_update = !have_seen_accelerometer_data_;
have_seen_accelerometer_data_ = true;
// Ignore the reading if it appears unstable. The reading is considered
@@ -250,10 +256,18 @@ void MaximizeModeController::OnAccelerometerUpdated(
// affects screen rotation, so we handle hinge rotation first.
HandleHingeRotation(base, lid);
HandleScreenRotation(lid);
+
+ if (first_accelerometer_update) {
+ // On the first accelerometer update we will know if we have entered
+ // maximize mode or not. Update the preferences to reflect the current
+ // state.
+ Shell::GetInstance()->display_manager()->
+ RegisterDisplayRotationProperties(rotation_locked_, current_rotation_);
+ }
}
void MaximizeModeController::OnDisplayConfigurationChanged() {
- if (in_set_screen_rotation_)
+ if (ignore_display_configuration_updates_)
return;
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
gfx::Display::Rotation user_rotation = display_manager->
@@ -398,8 +412,8 @@ void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) {
void MaximizeModeController::SetDisplayRotation(
DisplayManager* display_manager,
gfx::Display::Rotation rotation) {
- base::AutoReset<bool> auto_in_set_screen_rotation(
- &in_set_screen_rotation_, true);
+ base::AutoReset<bool> auto_ignore_display_configuration_updates(
+ &ignore_display_configuration_updates_, true);
current_rotation_ = rotation;
display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
rotation);
@@ -409,8 +423,11 @@ void MaximizeModeController::EnterMaximizeMode() {
if (IsMaximizeModeWindowManagerEnabled())
return;
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- current_rotation_ = user_rotation_ = display_manager->
- GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ if (display_manager->HasInternalDisplay()) {
+ current_rotation_ = user_rotation_ = display_manager->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ LoadDisplayRotationProperties();
+ }
EnableMaximizeModeWindowManager(true);
#if defined(USE_X11)
event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11);
@@ -425,11 +442,14 @@ void MaximizeModeController::LeaveMaximizeMode() {
if (!IsMaximizeModeWindowManagerEnabled())
return;
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- gfx::Display::Rotation current_rotation = display_manager->
- GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
- if (current_rotation != user_rotation_)
- SetDisplayRotation(display_manager, user_rotation_);
- rotation_locked_ = false;
+ if (display_manager->HasInternalDisplay()) {
+ gfx::Display::Rotation current_rotation = display_manager->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ if (current_rotation != user_rotation_)
+ SetDisplayRotation(display_manager, user_rotation_);
+ }
+ if (!shutting_down_)
+ SetRotationLocked(false);
EnableMaximizeModeWindowManager(false);
event_blocker_.reset();
event_handler_.reset();
@@ -462,6 +482,16 @@ void MaximizeModeController::RecordTouchViewStateTransition() {
}
}
+void MaximizeModeController::LoadDisplayRotationProperties() {
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager();
+ if (!display_manager->registered_internal_display_rotation_lock())
+ return;
+
+ SetDisplayRotation(display_manager,
+ display_manager->registered_internal_display_rotation());
+ SetRotationLocked(true);
+}
+
void MaximizeModeController::OnAppTerminating() {
if (CanEnterMaximizeMode()) {
RecordTouchViewStateTransition();
diff --git a/ash/wm/maximize_mode/maximize_mode_controller.h b/ash/wm/maximize_mode/maximize_mode_controller.h
index bc4b224..326e8f8 100644
--- a/ash/wm/maximize_mode/maximize_mode_controller.h
+++ b/ash/wm/maximize_mode/maximize_mode_controller.h
@@ -62,8 +62,8 @@ class ASH_EXPORT MaximizeModeController
MaximizeModeController();
virtual ~MaximizeModeController();
- bool in_set_screen_rotation() const {
- return in_set_screen_rotation_;
+ bool ignore_display_configuration_updates() const {
+ return ignore_display_configuration_updates_;
}
// True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not
@@ -164,6 +164,10 @@ class ASH_EXPORT MaximizeModeController
// Record UMA stats tracking touchview usage.
void RecordTouchViewStateTransition();
+ // Checks DisplayManager for registered rotation lock, and rotation,
+ // preferences. These are then applied.
+ void LoadDisplayRotationProperties();
+
// The maximized window manager (if enabled).
scoped_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_;
@@ -180,8 +184,14 @@ class ASH_EXPORT MaximizeModeController
// Whether we have ever seen accelerometer data.
bool have_seen_accelerometer_data_;
- // True when the screen's orientation is being changed.
- bool in_set_screen_rotation_;
+ // True when changes being applied cause OnDisplayConfigurationChanged() to be
+ // called, and for which these changes should be ignored.
+ bool ignore_display_configuration_updates_;
+
+ // True when Shutdown has been called. When shutting down the non maximize
+ // mode state should be restored, however user preferences should not be
+ // altered.
+ bool shutting_down_;
// The rotation of the display set by the user. This rotation will be
// restored upon exiting maximize mode.
diff --git a/chrome/browser/chromeos/display/display_preferences.cc b/chrome/browser/chromeos/display/display_preferences.cc
index 9614c15..a92d9a3 100644
--- a/chrome/browser/chromeos/display/display_preferences.cc
+++ b/chrome/browser/chromeos/display/display_preferences.cc
@@ -189,6 +189,23 @@ void LoadDisplayProperties() {
}
}
+void LoadDisplayRotationState() {
+ PrefService* local_state = g_browser_process->local_state();
+ const base::DictionaryValue* properties =
+ local_state->GetDictionary(prefs::kDisplayRotationLock);
+
+ bool rotation_lock = false;
+ if (!properties->GetBoolean("lock", &rotation_lock))
+ return;
+
+ int rotation = gfx::Display::ROTATE_0;
+ if (!properties->GetInteger("orientation", &rotation))
+ return;
+
+ GetDisplayManager()->RegisterDisplayRotationProperties(rotation_lock,
+ static_cast<gfx::Display::Rotation>(rotation));
+}
+
void StoreDisplayLayoutPref(const ash::DisplayIdPair& pair,
const ash::DisplayLayout& display_layout) {
std::string name =
@@ -294,6 +311,12 @@ void StoreCurrentDisplayPowerState() {
ash::Shell::GetInstance()->display_configurator()->power_state());
}
+void StoreCurrentDisplayRotationLockPrefs() {
+ bool rotation_lock = ash::Shell::GetInstance()->display_manager()->
+ registered_internal_display_rotation_lock();
+ StoreDisplayRotationPrefs(rotation_lock);
+}
+
} // namespace
void RegisterDisplayLocalStatePrefs(PrefRegistrySimple* registry) {
@@ -303,6 +326,7 @@ void RegisterDisplayLocalStatePrefs(PrefRegistrySimple* registry) {
DisplayPowerStateToStringMap::const_iterator iter =
GetDisplayPowerStateToStringMap()->find(chromeos::DISPLAY_POWER_ALL_ON);
registry->RegisterStringPref(prefs::kDisplayPowerState, iter->second);
+ registry->RegisterDictionaryPref(prefs::kDisplayRotationLock);
}
void StoreDisplayPrefs() {
@@ -310,6 +334,7 @@ void StoreDisplayPrefs() {
// state respects to the current status (close/open) of the lid which can be
// changed in any situation. See crbug.com/285360
StoreCurrentDisplayPowerState();
+ StoreCurrentDisplayRotationLockPrefs();
// Do not store prefs when the confirmation dialog is shown.
if (!UserCanSaveDisplayPreference() ||
@@ -321,6 +346,20 @@ void StoreDisplayPrefs() {
StoreCurrentDisplayProperties();
}
+void StoreDisplayRotationPrefs(bool rotation_lock) {
+ ash::DisplayManager* display_manager = GetDisplayManager();
+ if (!display_manager->HasInternalDisplay())
+ return;
+
+ PrefService* local_state = g_browser_process->local_state();
+ 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();
+ pref_data->SetInteger("orientation", static_cast<int>(rotation));
+}
+
void SetCurrentDisplayLayout(const ash::DisplayLayout& layout) {
GetDisplayManager()->SetLayoutForCurrentDisplays(layout);
}
@@ -328,6 +367,7 @@ void SetCurrentDisplayLayout(const ash::DisplayLayout& layout) {
void LoadDisplayPreferences(bool first_run_after_boot) {
LoadDisplayLayouts();
LoadDisplayProperties();
+ LoadDisplayRotationState();
if (!first_run_after_boot) {
PrefService* local_state = g_browser_process->local_state();
// Restore DisplayPowerState:
diff --git a/chrome/browser/chromeos/display/display_preferences.h b/chrome/browser/chromeos/display/display_preferences.h
index c96e824..eb40a21 100644
--- a/chrome/browser/chromeos/display/display_preferences.h
+++ b/chrome/browser/chromeos/display/display_preferences.h
@@ -29,6 +29,10 @@ void RegisterDisplayLocalStatePrefs(PrefRegistrySimple* registry);
// dispay layout).
void StoreDisplayPrefs();
+// If there is an internal display, stores |rotation_lock| along with the
+// current rotation of the internal display. Otherwise no data is stored.
+void StoreDisplayRotationPrefs(bool rotation_lock);
+
// Sets the display layout for the current displays.
void SetCurrentDisplayLayout(const ash::DisplayLayout& layout);
diff --git a/chrome/browser/chromeos/display/display_preferences_unittest.cc b/chrome/browser/chromeos/display/display_preferences_unittest.cc
index 658ec54..31ff620 100644
--- a/chrome/browser/chromeos/display/display_preferences_unittest.cc
+++ b/chrome/browser/chromeos/display/display_preferences_unittest.cc
@@ -142,6 +142,14 @@ class DisplayPreferencesTest : public ash::test::AshTestBase {
pref_data->Set(name, property);
}
+ void StoreDisplayRotationPrefsForTest(bool rotation_lock,
+ gfx::Display::Rotation rotation) {
+ DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock);
+ base::DictionaryValue* pref_data = update.Get();
+ pref_data->SetBoolean("lock", rotation_lock);
+ pref_data->SetInteger("orientation", static_cast<int>(rotation));
+ }
+
std::string GetRegisteredDisplayLayoutStr(int64 id1, int64 id2) {
ash::DisplayIdPair pair;
pair.first = id1;
@@ -675,4 +683,179 @@ TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) {
EXPECT_EQ(gfx::Display::ROTATE_0, rotation);
}
+// Tests that the rotation state is saved without a user being logged in.
+TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) {
+ gfx::Display::SetInternalDisplayId(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
+ EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ bool current_rotation_lock =
+ ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked();
+ StoreDisplayRotationPrefs(current_rotation_lock);
+ EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ const base::DictionaryValue* properties =
+ local_state()->GetDictionary(prefs::kDisplayRotationLock);
+ bool rotation_lock;
+ EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
+ EXPECT_EQ(current_rotation_lock, rotation_lock);
+
+ int orientation;
+ gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()->
+ display_manager()->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ EXPECT_TRUE(properties->GetInteger("orientation", &orientation));
+ EXPECT_EQ(current_rotation, orientation);
+}
+
+// Tests that the rotation state is saved when a guest is logged in.
+TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) {
+ gfx::Display::SetInternalDisplayId(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
+ EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+ LoggedInAsGuest();
+
+ bool current_rotation_lock =
+ ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked();
+ StoreDisplayRotationPrefs(current_rotation_lock);
+ EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ const base::DictionaryValue* properties =
+ local_state()->GetDictionary(prefs::kDisplayRotationLock);
+ bool rotation_lock;
+ EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
+ EXPECT_EQ(current_rotation_lock, rotation_lock);
+
+ int orientation;
+ gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()->
+ display_manager()->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ EXPECT_TRUE(properties->GetInteger("orientation", &orientation));
+ EXPECT_EQ(current_rotation, orientation);
+}
+
+// Tests that the rotation state is saved when a normal user is logged in.
+TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) {
+ gfx::Display::SetInternalDisplayId(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
+ EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+ LoggedInAsGuest();
+
+ bool current_rotation_lock =
+ ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked();
+ StoreDisplayRotationPrefs(current_rotation_lock);
+ EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ const base::DictionaryValue* properties =
+ local_state()->GetDictionary(prefs::kDisplayRotationLock);
+ bool rotation_lock;
+ EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
+ EXPECT_EQ(current_rotation_lock, rotation_lock);
+
+ int orientation;
+ gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()->
+ display_manager()->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ EXPECT_TRUE(properties->GetInteger("orientation", &orientation));
+ EXPECT_EQ(current_rotation, orientation);
+}
+
+// Tests that rotation state is loaded without a user being logged in, and that
+// entering maximize mode applies the state.
+TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) {
+ gfx::Display::SetInternalDisplayId(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
+ ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ ash::Shell* shell = ash::Shell::GetInstance();
+ ash::MaximizeModeController* maximize_mode_controller =
+ shell->maximize_mode_controller();
+ bool initial_rotation_lock = maximize_mode_controller->rotation_locked();
+ ASSERT_FALSE(initial_rotation_lock);
+ ash::DisplayManager* display_manager = shell->display_manager();
+ gfx::Display::Rotation initial_rotation = display_manager->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation);
+
+ StoreDisplayRotationPrefs(initial_rotation_lock);
+ ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90);
+ LoadDisplayPreferences(false);
+
+ bool display_rotation_lock =
+ display_manager->registered_internal_display_rotation_lock();
+ bool display_rotation =
+ display_manager->registered_internal_display_rotation();
+ EXPECT_TRUE(display_rotation_lock);
+ EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation);
+
+ bool rotation_lock = maximize_mode_controller->rotation_locked();
+ gfx::Display::Rotation before_maximize_mode_rotation = display_manager->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+
+ // Settings should not be applied until maximize mode activates
+ EXPECT_FALSE(rotation_lock);
+ EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation);
+
+ // Open up 270 degrees to trigger maximize mode
+ maximize_mode_controller->
+ OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
+ gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
+ EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled());
+ bool maximize_mode_rotation_lock =
+ maximize_mode_controller->rotation_locked();
+ gfx::Display::Rotation maximize_mode_rotation = display_manager->
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
+ EXPECT_TRUE(maximize_mode_rotation_lock);
+ EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation);
+}
+
+// Tests that loaded rotation state is ignored if the device starts in normal
+// mode, and that they are not applied upon first entering maximize mode.
+TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) {
+ gfx::Display::SetInternalDisplayId(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
+ ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+ StoreDisplayRotationPrefs(false /* rotation_lock*/);
+ ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90);
+ LoadDisplayPreferences(false);
+
+ ash::MaximizeModeController* maximize_mode_controller =
+ ash::Shell::GetInstance()->maximize_mode_controller();
+ // Lid open to 90 degrees
+ maximize_mode_controller->
+ OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
+ gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
+ EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled());
+ EXPECT_FALSE(maximize_mode_controller->rotation_locked());
+
+ // Open up 270 degrees to trigger maximize mode
+ maximize_mode_controller->
+ OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
+ gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
+ EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled());
+ EXPECT_FALSE(maximize_mode_controller->rotation_locked());
+}
+
+// Tests that rotation lock being set causes the rotation state to be saved.
+TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) {
+ gfx::Display::SetInternalDisplayId(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
+ ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ ash::MaximizeModeController* maximize_mode_controller =
+ ash::Shell::GetInstance()->maximize_mode_controller();
+ maximize_mode_controller->SetRotationLocked(true);
+
+ EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
+
+ const base::DictionaryValue* properties =
+ local_state()->GetDictionary(prefs::kDisplayRotationLock);
+ bool rotation_lock;
+ EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
+}
+
} // namespace chromeos
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 8847ae3..103e972 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -680,6 +680,10 @@ const char kDisplayProperties[] = "settings.display.properties";
// layout/offset information.
const char kSecondaryDisplays[] = "settings.display.secondary_displays";
+// A dictionary pref that specifies the state of the rotation lock, and the
+// display orientation, for the internal display.
+const char kDisplayRotationLock[] = "settings.display.rotation_lock";
+
// A boolean pref indicating whether user activity has been observed in the
// current session already. The pref is used to restore information about user
// activity after browser crashes.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index c95ca68..2ebc826 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -229,6 +229,7 @@ extern const char kUseSharedProxies[];
extern const char kDisplayPowerState[];
extern const char kDisplayProperties[];
extern const char kSecondaryDisplays[];
+extern const char kDisplayRotationLock[];
extern const char kSessionUserActivitySeen[];
extern const char kSessionStartTime[];
extern const char kSessionLengthLimit[];