Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: ash/wm/maximize_mode/maximize_mode_controller.cc

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Linux Compile Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 511df7b94d65201e23329e30b5aea7c71f6ed56b..388f350ec6cadd8d0b1dea2aaef9739f4beabc8d 100644
--- a/ash/wm/maximize_mode/maximize_mode_controller.cc
+++ b/ash/wm/maximize_mode/maximize_mode_controller.cc
@@ -11,7 +11,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"
@@ -63,13 +62,6 @@ const base::TimeDelta kLidRecentlyOpenedDuration =
const float kHingeAngleDetectionThreshold = 2.5f;
#if defined(OS_CHROMEOS)
-// The mean acceleration due to gravity on Earth in m/s^2.
-const float kMeanGravity = 9.80665f;
-
-// 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
@@ -77,51 +69,11 @@ const float kDeviationFromGravityThreshold = 1.0f;
const float kNoisyMagnitudeDeviation = 1.0f;
#endif
-// 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.
-float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
- const gfx::Vector3dF& other) {
- return acos(gfx::DotProduct(base, other) /
- base.Length() / other.Length()) * kRadiansToDegrees;
-}
-
-// Returns the clockwise angle between |base| and |other| where |normal| is the
-// normal of the virtual surface to measure clockwise according to.
-float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
- const gfx::Vector3dF& other,
- const gfx::Vector3dF& normal) {
- float angle = AngleBetweenVectorsInDegrees(base, other);
- gfx::Vector3dF cross(base);
- cross.Cross(other);
- // If the dot product of this cross product is normal, it means that the
- // shortest angle between |base| and |other| was counterclockwise with respect
- // to the surface represented by |normal| and this angle must be reversed.
- if (gfx::DotProduct(cross, normal) > 0.0f)
- angle = 360.0f - angle;
- return angle;
-}
-
} // 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) {
@@ -142,31 +94,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.
@@ -198,72 +125,34 @@ void MaximizeModeController::AddWindow(aura::Window* window) {
maximize_mode_window_manager_->AddWindow(window);
}
-void MaximizeModeController::Shutdown() {
- shutting_down_ = true;
- LeaveMaximizeMode();
-}
-
-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;
- }
-}
-
#if defined(OS_CHROMEOS)
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.
if (!update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) {
- if (first_accelerometer_update &&
- update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) {
+ if (first_accelerometer_update)
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_);
+ } else if (chromeos::AccelerometerReader::IsReadingStable(
+ update, ui::ACCELEROMETER_SOURCE_SCREEN) &&
+ chromeos::AccelerometerReader::IsReadingStable(
+ update, 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));
}
}
@@ -304,8 +193,8 @@ void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base,
}
// Compute the angle between the base and the lid.
- float lid_angle = 180.0f - ClockwiseAngleBetweenVectorsInDegrees(
- base_flattened, lid_flattened, hinge_vector);
+ float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees(
+ base_flattened, lid_flattened, hinge_vector);
if (lid_angle < 0.0f)
lid_angle += 360.0f;
@@ -341,106 +230,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.
@@ -469,16 +268,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();
@@ -495,7 +284,6 @@ void MaximizeModeController::OnAppTerminating() {
100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds());
}
}
- Shell::GetInstance()->display_controller()->RemoveObserver(this);
}
bool MaximizeModeController::WasLidOpenedRecently() const {
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.h ('k') | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698