Chromium Code Reviews| Index: ash/wm/maximize_mode/maximize_mode_controller.cc |
| diff --git a/ash/wm/maximize_mode/maximize_mode_controller.cc b/ash/wm/maximize_mode/maximize_mode_controller.cc |
| index 61ce2f2205611a724a838ebb705b713a088f2055..97642c845ba36c1a4b18142e5149f13010b3e9fd 100644 |
| --- a/ash/wm/maximize_mode/maximize_mode_controller.cc |
| +++ b/ash/wm/maximize_mode/maximize_mode_controller.cc |
| @@ -131,8 +131,10 @@ void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) { |
| } // namespace |
| MaximizeModeController::MaximizeModeController() |
| - : rotation_locked_(false), |
| - have_seen_accelerometer_data_(false) { |
| + : accelerometer_setting_rotation_(false), |
| + rotation_locked_(false), |
| + have_seen_accelerometer_data_(false), |
| + user_rotation_(gfx::Display::ROTATE_0) { |
| Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| } |
| @@ -203,16 +205,10 @@ void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| if (maximize_mode_engaged && |
| angle > kFullyOpenAngleErrorTolerance && |
| angle < kExitMaximizeModeAngle) { |
| - Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
| - event_blocker_.reset(); |
| - event_handler_.reset(); |
| + LeaveMaximizeMode(); |
| } else if (!maximize_mode_engaged && |
| angle > kEnterMaximizeModeAngle) { |
| - Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
| - event_blocker_.reset(new MaximizeModeEventBlocker); |
| -#if defined(OS_CHROMEOS) |
| - event_handler_.reset(new ScreenshotActionHandler); |
| -#endif |
| + EnterMaximizeMode(); |
| } |
| } |
| @@ -220,31 +216,14 @@ void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| bool maximize_mode_engaged = |
| Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
| + if (!maximize_mode_engaged || rotation_locked_) |
| + return; |
| + |
| DisplayManager* display_manager = |
| Shell::GetInstance()->display_manager(); |
| gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
| gfx::Display::InternalDisplayId()).rotation(); |
| - // If maximize mode is not engaged, ensure the screen is not rotated and |
| - // do not rotate to match the current device orientation. |
| - if (!maximize_mode_engaged) { |
| - if (current_rotation != gfx::Display::ROTATE_0) { |
| - // TODO(flackr): Currently this will prevent setting a manual rotation on |
| - // the screen of a device with an accelerometer, this should only set it |
| - // back to ROTATE_0 if it was last set by the accelerometer. |
| - // Also, SetDisplayRotation will save the setting to the local store, |
| - // this should be stored in a way that we can distinguish what the |
| - // rotation was set by. |
| - display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| - gfx::Display::ROTATE_0); |
| - } |
| - rotation_locked_ = false; |
| - return; |
| - } |
| - |
| - if (rotation_locked_) |
| - return; |
| - |
| // After determining maximize mode state, determine if the screen should |
| // be rotated. |
| gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
| @@ -290,13 +269,43 @@ void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| else if (angle < 270.0f) |
| new_rotation = gfx::Display::ROTATE_180; |
| - // When exiting maximize mode return rotation to 0. When entering, rotate to |
| - // match screen orientation. |
| - if (new_rotation == gfx::Display::ROTATE_0 || |
| - maximize_mode_engaged) { |
| + // When setting a new rotation set flag so that display configuration changes |
| + // are not saved. |
| + if (new_rotation != current_rotation) { |
| + accelerometer_setting_rotation_ = true; |
|
flackr
2014/05/23 15:30:58
nit: use base::AutoReset.
|
| display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| new_rotation); |
| + accelerometer_setting_rotation_ = false; |
| + } |
| +} |
| + |
| +void MaximizeModeController::EnterMaximizeMode() { |
| + // TODO(jonross): Listen for display configuration changes. If the user |
| + // causes a rotation change a rotation lock should be applied. |
| + // https://crbug.com/369505 |
| + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| + user_rotation_ = display_manager-> |
| + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| + rotation_locked_ = user_rotation_ != gfx::Display::ROTATE_0; |
|
flackr
2014/05/23 15:30:58
I think the consensus was that we don't want to lo
jonross
2014/05/23 19:07:20
Done.
|
| + Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
| + event_blocker_.reset(new MaximizeModeEventBlocker); |
| +#if defined(OS_CHROMEOS) |
| + event_handler_.reset(new ScreenshotActionHandler); |
| +#endif |
| +} |
| + |
| +void MaximizeModeController::LeaveMaximizeMode() { |
| + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| + DisplayInfo info = display_manager-> |
| + GetDisplayInfo(gfx::Display::InternalDisplayId()); |
| + gfx::Display::Rotation current_rotation = info.rotation(); |
| + if (current_rotation != user_rotation_) { |
| + display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| + user_rotation_); |
| } |
| + Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
| + event_blocker_.reset(); |
| + event_handler_.reset(); |
| } |
| } // namespace ash |