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 @@
#include "ash/wm/window_state.h"
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/stl_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
......@@ -339,9 +340,8 @@ void ScreenOrientationController::OnWindowDestroying(aura::Window* window) {
void ScreenOrientationController::OnWindowVisibilityChanged(
aura::Window* window,
bool visible) {
if (lock_info_map_.find(window) == lock_info_map_.end())
return;
ApplyLockForActiveWindow();
if (base::ContainsKey(lock_info_map_, window))
ApplyLockForActiveWindow();
}
void ScreenOrientationController::OnAccelerometerUpdated(
......@@ -594,37 +594,47 @@ void ScreenOrientationController::ApplyLockForActiveWindow() {
for (auto* window : mru_windows) {
if (!window->TargetVisibility())
continue;
for (auto& pair : lock_info_map_) {
if (pair.first->TargetVisibility() && window->Contains(pair.first)) {
if (pair.second.orientation_lock == OrientationLockType::kCurrent) {
// If the app requested "current" without previously
// specifying an orientation, use the current rotation.
pair.second.orientation_lock =
RotationToOrientation(natural_orientation_, current_rotation_);
LockRotationToOrientation(pair.second.orientation_lock);
} else {
const auto orientation_lock = ResolveOrientationLock(
pair.second.orientation_lock, user_locked_orientation_);
LockRotationToOrientation(orientation_lock);
if (pair.second.lock_completion_behavior ==
LockCompletionBehavior::DisableSensor) {
pair.second.lock_completion_behavior = LockCompletionBehavior::None;
pair.second.orientation_lock = orientation_lock;
}
if (ApplyLockForWindowIfPossible(window))
return;
}
LockRotationToOrientation(user_locked_orientation_);
}
bool ScreenOrientationController::ApplyLockForWindowIfPossible(
const aura::Window* window) {
for (auto& pair : lock_info_map_) {
const aura::Window* lock_window = pair.first;
LockInfo& lock_info = pair.second;
if (lock_window->TargetVisibility() && window->Contains(lock_window)) {
if (lock_info.orientation_lock == OrientationLockType::kCurrent) {
// If the app requested "current" without previously
// 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;
}
}
// 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;
return true;
}
}
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(
......
......@@ -68,13 +68,12 @@ class ASH_EXPORT ScreenOrientationController
virtual ~Observer() {}
};
// Controls the behavior after lock is applied to the window (when
// the window becomes active window). |DisableSensor| disables
// the sensor based rotation and locks to the specific orientation.
// For example, PORTRAIT may rotate to PORTRAIT_PRIMARY or
// PORTRAIT_SECONDARY, and will allow rotate between these two.
// |DisableSensor| will lock the orientation to the one of them
// after locked to disalow the sensor basd rotation.
// Controls the behavior after lock is applied to the window (when the window
// becomes the active window). |DisableSensor| disables the sensor-based
// rotation and locks to the specific orientation. For example, PORTRAIT may
// rotate to PORTRAIT_PRIMARY or PORTRAIT_SECONDARY, and will allow rotation
// between these two. |DisableSensor| disallows the sensor-based rotation by
// locking the rotation to whichever specific orientation is applied.
enum class LockCompletionBehavior {
None,
DisableSensor,
......@@ -206,6 +205,10 @@ class ASH_EXPORT ScreenOrientationController
// window, and applies it. If there is none, rotation lock will be removed.
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
// |OrientationLock::kPortrait| allow for rotation between the
// 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