Commit 85740ef5 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Refactor screen orientation lock into separate function

Minor refactor to make an upcoming CL easier to read.

Change-Id: I3984252128505f7c655cb87b1728168e26498513
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1597908
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661135}
parent 38c637ed
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/stl_util.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
...@@ -339,9 +340,8 @@ void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { ...@@ -339,9 +340,8 @@ void ScreenOrientationController::OnWindowDestroying(aura::Window* window) {
void ScreenOrientationController::OnWindowVisibilityChanged( void ScreenOrientationController::OnWindowVisibilityChanged(
aura::Window* window, aura::Window* window,
bool visible) { bool visible) {
if (lock_info_map_.find(window) == lock_info_map_.end()) if (base::ContainsKey(lock_info_map_, window))
return; ApplyLockForActiveWindow();
ApplyLockForActiveWindow();
} }
void ScreenOrientationController::OnAccelerometerUpdated( void ScreenOrientationController::OnAccelerometerUpdated(
...@@ -594,37 +594,47 @@ void ScreenOrientationController::ApplyLockForActiveWindow() { ...@@ -594,37 +594,47 @@ void ScreenOrientationController::ApplyLockForActiveWindow() {
for (auto* window : mru_windows) { for (auto* window : mru_windows) {
if (!window->TargetVisibility()) if (!window->TargetVisibility())
continue; continue;
for (auto& pair : lock_info_map_) { if (ApplyLockForWindowIfPossible(window))
if (pair.first->TargetVisibility() && window->Contains(pair.first)) { return;
if (pair.second.orientation_lock == OrientationLockType::kCurrent) { }
// If the app requested "current" without previously
// specifying an orientation, use the current rotation. LockRotationToOrientation(user_locked_orientation_);
pair.second.orientation_lock = }
RotationToOrientation(natural_orientation_, current_rotation_);
LockRotationToOrientation(pair.second.orientation_lock); bool ScreenOrientationController::ApplyLockForWindowIfPossible(
} else { const aura::Window* window) {
const auto orientation_lock = ResolveOrientationLock( for (auto& pair : lock_info_map_) {
pair.second.orientation_lock, user_locked_orientation_); const aura::Window* lock_window = pair.first;
LockRotationToOrientation(orientation_lock); LockInfo& lock_info = pair.second;
if (pair.second.lock_completion_behavior == if (lock_window->TargetVisibility() && window->Contains(lock_window)) {
LockCompletionBehavior::DisableSensor) { if (lock_info.orientation_lock == OrientationLockType::kCurrent) {
pair.second.lock_completion_behavior = LockCompletionBehavior::None; // If the app requested "current" without previously
pair.second.orientation_lock = orientation_lock; // specifying an orientation, use the current rotation.
} lock_info.orientation_lock =
RotationToOrientation(natural_orientation_, current_rotation_);
LockRotationToOrientation(lock_info.orientation_lock);
} else {
const auto orientation_lock = ResolveOrientationLock(
lock_info.orientation_lock, user_locked_orientation_);
LockRotationToOrientation(orientation_lock);
if (lock_info.lock_completion_behavior ==
LockCompletionBehavior::DisableSensor) {
lock_info.lock_completion_behavior = LockCompletionBehavior::None;
lock_info.orientation_lock = orientation_lock;
} }
return;
} }
} return true;
// The default orientation for all chrome browser/apps windows is
// ANY, so use the user_locked_orientation_;
if (window->TargetVisibility() &&
static_cast<AppType>(window->GetProperty(aura::client::kAppType)) !=
AppType::OTHERS) {
LockRotationToOrientation(user_locked_orientation_);
return;
} }
} }
LockRotationToOrientation(user_locked_orientation_);
// The default orientation for all chrome browser/apps windows is
// ANY, so use the user_locked_orientation_;
if (static_cast<AppType>(window->GetProperty(aura::client::kAppType)) !=
AppType::OTHERS) {
LockRotationToOrientation(user_locked_orientation_);
return true;
}
return false;
} }
bool ScreenOrientationController::IsRotationAllowedInLockedState( bool ScreenOrientationController::IsRotationAllowedInLockedState(
......
...@@ -68,13 +68,12 @@ class ASH_EXPORT ScreenOrientationController ...@@ -68,13 +68,12 @@ class ASH_EXPORT ScreenOrientationController
virtual ~Observer() {} virtual ~Observer() {}
}; };
// Controls the behavior after lock is applied to the window (when // Controls the behavior after lock is applied to the window (when the window
// the window becomes active window). |DisableSensor| disables // becomes the active window). |DisableSensor| disables the sensor-based
// the sensor based rotation and locks to the specific orientation. // rotation and locks to the specific orientation. For example, PORTRAIT may
// For example, PORTRAIT may rotate to PORTRAIT_PRIMARY or // rotate to PORTRAIT_PRIMARY or PORTRAIT_SECONDARY, and will allow rotation
// PORTRAIT_SECONDARY, and will allow rotate between these two. // between these two. |DisableSensor| disallows the sensor-based rotation by
// |DisableSensor| will lock the orientation to the one of them // locking the rotation to whichever specific orientation is applied.
// after locked to disalow the sensor basd rotation.
enum class LockCompletionBehavior { enum class LockCompletionBehavior {
None, None,
DisableSensor, DisableSensor,
...@@ -206,6 +205,10 @@ class ASH_EXPORT ScreenOrientationController ...@@ -206,6 +205,10 @@ class ASH_EXPORT ScreenOrientationController
// window, and applies it. If there is none, rotation lock will be removed. // window, and applies it. If there is none, rotation lock will be removed.
void ApplyLockForActiveWindow(); void ApplyLockForActiveWindow();
// If there is a rotation lock that can be applied to window, applies it and
// returns true. Otherwise returns false.
bool ApplyLockForWindowIfPossible(const aura::Window* window);
// Both |OrientationLockType::kLandscape| and // Both |OrientationLockType::kLandscape| and
// |OrientationLock::kPortrait| allow for rotation between the // |OrientationLock::kPortrait| allow for rotation between the
// two angles of the same screen orientation // two angles of the same screen orientation
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment