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

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: Refactor Rotation from MaximizeModeController to ScreenOrientationController Created 6 years 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 c2f22ff59c921d1229d8e7b6c6b65aee9f5ddd84..f9b8d8493104c9d125540bfbf7d5a3460b9b213e 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"
@@ -76,17 +75,6 @@ const float kDeviationFromGravityThreshold = 1.0f;
// 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 +103,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 +125,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,24 +156,11 @@ void MaximizeModeController::AddWindow(aura::Window* window) {
maximize_mode_window_manager_->AddWindow(window);
}
-void MaximizeModeController::Shutdown() {
- shutting_down_ = true;
- LeaveMaximizeMode();
oshima 2014/12/11 23:51:28 don't we have to keep this for shutdown?
jonross 2014/12/12 18:30:04 Rob and I discussed this, and I looked into it. A
oshima 2014/12/12 19:59:53 In that case, can you update the document for OnMa
-}
-
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;
-
// 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)) {
@@ -223,6 +169,16 @@ void MaximizeModeController::OnAccelerometerUpdated(
EnterMaximizeMode();
}
} else { // 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.
+ 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;
oshima 2014/12/11 23:51:28 can you define a utility function in ash/accelerom
jonross 2014/12/12 18:30:04 Done.
float base_magnitude =
update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD).Length();
bool base_angle_stable = lid_stable &&
@@ -235,33 +191,6 @@ void MaximizeModeController::OnAccelerometerUpdated(
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;
- }
}
#if defined(OS_CHROMEOS)
@@ -339,106 +268,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 +306,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 +322,6 @@ void MaximizeModeController::OnAppTerminating() {
100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds());
}
}
- Shell::GetInstance()->display_controller()->RemoveObserver(this);
}
bool MaximizeModeController::WasLidOpenedRecently() const {

Powered by Google App Engine
This is Rietveld 408576698