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 c2f22ff59c921d1229d8e7b6c6b65aee9f5ddd84..1e7f64e8e16cfbb68cb3d556e151e387de47005e 100644 |
| --- a/ash/wm/maximize_mode/maximize_mode_controller.cc |
| +++ b/ash/wm/maximize_mode/maximize_mode_controller.cc |
| @@ -12,7 +12,6 @@ |
| #include "ash/shell.h" |
| #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" |
| -#include "base/auto_reset.h" |
| #include "base/command_line.h" |
| #include "base/metrics/histogram.h" |
| #include "base/time/default_tick_clock.h" |
| @@ -55,9 +54,6 @@ const float kMaxStableAngle = 340.0f; |
| const base::TimeDelta kLidRecentlyOpenedDuration = |
| base::TimeDelta::FromSeconds(2); |
| -// The mean acceleration due to gravity on Earth in m/s^2. |
| -const float kMeanGravity = 9.80665f; |
| - |
| // When the device approaches vertical orientation (i.e. portrait orientation) |
| // the accelerometers for the base and lid approach the same values (i.e. |
| // gravity pointing in the direction of the hinge). When this happens we cannot |
| @@ -66,27 +62,12 @@ const float kMeanGravity = 9.80665f; |
| // detect hinge angle in m/s^2. |
| const float kHingeAngleDetectionThreshold = 2.5f; |
| -// The maximum deviation from the acceleration expected due to gravity under |
| -// which to detect hinge angle and screen rotation in m/s^2 |
| -const float kDeviationFromGravityThreshold = 1.0f; |
| - |
| // The maximum deviation between the magnitude of the two accelerometers under |
| // which to detect hinge angle and screen rotation in m/s^2. These |
| // accelerometers are attached to the same physical device and so should be |
| // under the same acceleration. |
| const float kNoisyMagnitudeDeviation = 1.0f; |
| -// The angle which the screen has to be rotated past before the display will |
| -// rotate to match it (i.e. 45.0f is no stickiness). |
| -const float kDisplayRotationStickyAngleDegrees = 60.0f; |
| - |
| -// The minimum acceleration in m/s^2 in a direction required to trigger screen |
| -// rotation. This prevents rapid toggling of rotation when the device is near |
| -// flat and there is very little screen aligned force on it. The value is |
| -// effectively the sine of the rise angle required times the acceleration due |
| -// to gravity, with the current value requiring at least a 25 degree rise. |
| -const float kMinimumAccelerationScreenRotation = 4.2f; |
| - |
| const float kRadiansToDegrees = 180.0f / 3.14159265f; |
| // Returns the angle between |base| and |other| in degrees. |
| @@ -115,12 +96,8 @@ float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
| } // namespace |
| MaximizeModeController::MaximizeModeController() |
| - : rotation_locked_(false), |
| - have_seen_accelerometer_data_(false), |
| - ignore_display_configuration_updates_(false), |
| + : have_seen_accelerometer_data_(false), |
| lid_open_past_180_(false), |
| - shutting_down_(false), |
| - user_rotation_(gfx::Display::ROTATE_0), |
| last_touchview_transition_time_(base::Time::Now()), |
| tick_clock_(new base::DefaultTickClock()), |
| lid_is_closed_(false) { |
| @@ -141,31 +118,6 @@ MaximizeModeController::~MaximizeModeController() { |
| #endif // OS_CHROMEOS |
| } |
| -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_)); |
| -} |
| - |
| -void MaximizeModeController::LockRotation(gfx::Display::Rotation rotation) { |
| - SetRotationLocked(true); |
| - SetDisplayRotation(Shell::GetInstance()->display_manager(), rotation); |
| -} |
| - |
| -void MaximizeModeController::AddObserver(Observer* observer) { |
| - observers_.AddObserver(observer); |
| -} |
| - |
| -void MaximizeModeController::RemoveObserver(Observer* observer) { |
| - observers_.RemoveObserver(observer); |
| -} |
| - |
| bool MaximizeModeController::CanEnterMaximizeMode() { |
| // If we have ever seen accelerometer data, then HandleHingeRotation may |
| // trigger maximize mode at some point in the future. |
| @@ -197,23 +149,13 @@ void MaximizeModeController::AddWindow(aura::Window* window) { |
| maximize_mode_window_manager_->AddWindow(window); |
| } |
| -void MaximizeModeController::Shutdown() { |
| - shutting_down_ = true; |
| - LeaveMaximizeMode(); |
| -} |
| - |
| void MaximizeModeController::OnAccelerometerUpdated( |
| const ui::AccelerometerUpdate& update) { |
| bool first_accelerometer_update = !have_seen_accelerometer_data_; |
| have_seen_accelerometer_data_ = true; |
| - // Ignore the reading if it appears unstable. The reading is considered |
| - // unstable if it deviates too much from gravity and/or the magnitude of the |
| - // reading from the lid differs too much from the reading from the base. |
| - float lid_magnitude = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) ? |
| - update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() : 0.0f; |
| - bool lid_stable = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) && |
| - std::abs(lid_magnitude - kMeanGravity) <= kDeviationFromGravityThreshold; |
| + if (!update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) |
| + return; |
| // Whether or not we enter maximize mode affects whether we handle screen |
| // rotation, so determine whether to enter maximize mode first. |
| @@ -222,45 +164,19 @@ void MaximizeModeController::OnAccelerometerUpdated( |
| update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) { |
|
flackr
2014/12/12 20:46:06
nit: already checked that it has source screen on
jonross
2015/01/06 19:56:10
Done.
|
| EnterMaximizeMode(); |
| } |
| - } else { // update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) |
| - float base_magnitude = |
| - update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD).Length(); |
| - bool base_angle_stable = lid_stable && |
| - std::abs(base_magnitude - lid_magnitude) <= kNoisyMagnitudeDeviation && |
| - std::abs(base_magnitude - kMeanGravity) <= |
| - kDeviationFromGravityThreshold; |
| - if (base_angle_stable) { |
| - HandleHingeRotation( |
| - update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD), |
| - update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); |
| - } |
| - } |
| - |
| - if (lid_stable) |
| - HandleScreenRotation(update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); |
| - |
| - 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 (ignore_display_configuration_updates_) |
| - return; |
| - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| - gfx::Display::Rotation user_rotation = display_manager-> |
| - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| - 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 |
| - // accelerometer from erasing their change. |
| - SetRotationLocked(true); |
| - user_rotation_ = user_rotation; |
| - current_rotation_ = user_rotation; |
| + } else if (update.IsReadingStable(ui::ACCELEROMETER_SOURCE_SCREEN) && |
| + update.IsReadingStable( |
| + ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) && |
| + std::abs(update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) |
| + .Length() - |
| + update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length()) <= |
| + kNoisyMagnitudeDeviation) { |
| + // update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) |
| + // Ignore the reading if it appears unstable. The reading is considered |
| + // unstable if it deviates too much from gravity and/or the magnitude of the |
| + // reading from the lid differs too much from the reading from the base. |
| + HandleHingeRotation(update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD), |
| + update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); |
| } |
| } |
| @@ -339,106 +255,16 @@ void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| } |
| } |
| -void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| - bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| - |
| - // TODO(jonross): track the updated rotation angle even when locked. So that |
| - // when rotation lock is removed the accelerometer rotation can be applied |
| - // without waiting for the next update. |
| - 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(); |
| - |
| - // After determining maximize mode state, determine if the screen should |
| - // be rotated. |
| - gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
| - float lid_flattened_length = lid_flattened.Length(); |
| - // When the lid is close to being flat, don't change rotation as it is too |
| - // sensitive to slight movements. |
| - if (lid_flattened_length < kMinimumAccelerationScreenRotation) |
| - return; |
| - |
| - // The reference vector is the angle of gravity when the device is rotated |
| - // clockwise by 45 degrees. Computing the angle between this vector and |
| - // gravity we can easily determine the expected display rotation. |
| - static const gfx::Vector3dF rotation_reference(-1.0f, -1.0f, 0.0f); |
| - |
| - // Set the down vector to match the expected direction of gravity given the |
| - // last configured rotation. This is used to enforce a stickiness that the |
| - // user must overcome to rotate the display and prevents frequent rotations |
| - // when holding the device near 45 degrees. |
| - gfx::Vector3dF down(0.0f, 0.0f, 0.0f); |
| - if (current_rotation == gfx::Display::ROTATE_0) |
| - down.set_y(-1.0f); |
| - else if (current_rotation == gfx::Display::ROTATE_90) |
| - down.set_x(-1.0f); |
| - else if (current_rotation == gfx::Display::ROTATE_180) |
| - down.set_y(1.0f); |
| - else |
| - down.set_x(1.0f); |
| - |
| - // Don't rotate if the screen has not passed the threshold. |
| - if (AngleBetweenVectorsInDegrees(down, lid_flattened) < |
| - kDisplayRotationStickyAngleDegrees) { |
| - return; |
| - } |
| - |
| - float angle = ClockwiseAngleBetweenVectorsInDegrees(rotation_reference, |
| - lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); |
| - |
| - gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; |
| - if (angle < 90.0f) |
| - new_rotation = gfx::Display::ROTATE_0; |
| - else if (angle < 180.0f) |
| - new_rotation = gfx::Display::ROTATE_270; |
| - else if (angle < 270.0f) |
| - new_rotation = gfx::Display::ROTATE_180; |
| - |
| - if (new_rotation != current_rotation) |
| - SetDisplayRotation(display_manager, new_rotation); |
| -} |
| - |
| -void MaximizeModeController::SetDisplayRotation( |
| - DisplayManager* display_manager, |
| - gfx::Display::Rotation rotation) { |
| - base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| - &ignore_display_configuration_updates_, true); |
| - current_rotation_ = rotation; |
| - display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| - rotation); |
| -} |
| - |
| void MaximizeModeController::EnterMaximizeMode() { |
| if (IsMaximizeModeWindowManagerEnabled()) |
| return; |
| - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| - if (display_manager->HasInternalDisplay()) { |
| - current_rotation_ = user_rotation_ = display_manager-> |
| - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| - LoadDisplayRotationProperties(); |
| - } |
| EnableMaximizeModeWindowManager(true); |
| - Shell::GetInstance()->display_controller()->AddObserver(this); |
| } |
| void MaximizeModeController::LeaveMaximizeMode() { |
| if (!IsMaximizeModeWindowManagerEnabled()) |
| return; |
| - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| - 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); |
| - Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| } |
| // Called after maximize mode has started, windows might still animate though. |
| @@ -467,16 +293,6 @@ 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(); |
| @@ -493,7 +309,6 @@ void MaximizeModeController::OnAppTerminating() { |
| 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); |
| } |
| } |
| - Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| } |
| bool MaximizeModeController::WasLidOpenedRecently() const { |