Chromium Code Reviews| Index: third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp |
| diff --git a/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp b/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp |
| index 03ab1310b9f332678b20a8ba090b856abbedd8f6..9762a2b28b91da9ad43f895a041c882d9869778c 100644 |
| --- a/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp |
| +++ b/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp |
| @@ -184,6 +184,12 @@ void MediaControlsOrientationLockDelegate::MaybeListenToDeviceOrientation() { |
| if (!RuntimeEnabledFeatures::videoRotateToFullscreenEnabled()) |
| return; |
| + if (is_auto_rotate_enabled_by_user_for_testing_ != -1) { |
| + GotIsAutoRotateEnabledByUser( |
| + static_cast<bool>(is_auto_rotate_enabled_by_user_for_testing_)); |
| + return; |
| + } |
| + |
| // Check whether the user locked screen orientation at the OS level. |
| #if OS(ANDROID) |
| DCHECK(!monitor_.is_bound()); |
| @@ -297,21 +303,17 @@ MediaControlsOrientationLockDelegate::ComputeOrientationLock() const { |
| return kWebScreenOrientationLockLandscape; |
| } |
| -void MediaControlsOrientationLockDelegate:: |
| - MaybeUnlockIfDeviceOrientationMatchesVideo(DeviceOrientationEvent* event) { |
| - DCHECK_EQ(state_, State::kMaybeLockedFullscreen); |
| - DCHECK_NE(locked_orientation_, kWebScreenOrientationLockDefault); |
| - |
| +MediaControlsOrientationLockDelegate::DeviceOrientation |
| +MediaControlsOrientationLockDelegate::ComputeDeviceOrientation( |
| + DeviceOrientationData* data) const { |
| LocalDOMWindow* dom_window = GetDocument().domWindow(); |
| if (!dom_window) |
| - return; |
| + return DeviceOrientation::kUnknown; |
| - if (!event->Orientation()->CanProvideBeta() || |
| - !event->Orientation()->CanProvideGamma()) { |
| - return; |
| - } |
| - double beta = event->Orientation()->Beta(); |
| - double gamma = event->Orientation()->Gamma(); |
| + if (!data->CanProvideBeta() || !data->CanProvideGamma()) |
| + return DeviceOrientation::kUnknown; |
| + double beta = data->Beta(); |
| + double gamma = data->Gamma(); |
| // Calculate the projection of the up vector (normal to the earth's surface) |
| // onto the device's screen in its natural orientation. (x,y) will lie within |
| @@ -336,16 +338,14 @@ void MediaControlsOrientationLockDelegate:: |
| constexpr double kMinElevationAngle = 24; // degrees from horizontal plane |
| if (r < std::sin(deg2rad(kMinElevationAngle))) |
| - return; // Device is too flat to reliably determine orientation. |
| + return DeviceOrientation::kFlat; // Can't reliably determine orientation. |
| // device_orientation_angle snapped to nearest multiple of 90. |
| int device_orientation_angle90 = |
| std::lround(device_orientation_angle / 90) * 90; |
| - if (std::abs(device_orientation_angle - device_orientation_angle90) > 23) { |
| - // Device is diagonal (within 44 degree hysteresis zone). |
| - return; |
| - } |
| + if (std::abs(device_orientation_angle - device_orientation_angle90) > 23) |
|
timvolodine
2017/05/31 18:07:21
nit: not really related to this CL, but how was th
johnme
2017/06/01 13:15:10
I expanded the comment.
|
| + return DeviceOrientation::kDiagonal; // Within 44 degree hysteresis zone. |
| // screen.orientation.angle is the standardized replacement for |
| // window.orientation. They are equal, except -90 was replaced by 270. |
| @@ -355,8 +355,8 @@ void MediaControlsOrientationLockDelegate:: |
| ->angle(); |
| // This is equivalent to screen.orientation.type.startsWith('landscape'). |
| - bool screen_orientation_is_landscape = |
| - dom_window->screen()->width() > dom_window->screen()->height(); |
| + bool screen_orientation_is_portrait = |
| + dom_window->screen()->width() <= dom_window->screen()->height(); |
| // The natural orientation of the device could either be portrait (almost |
| // all phones, and some tablets like Nexus 7) or landscape (other tablets |
| @@ -364,21 +364,33 @@ void MediaControlsOrientationLockDelegate:: |
| // TODO(johnme): This might get confused on square screens. |
| bool screen_orientation_is_natural_or_flipped_natural = |
| screen_orientation_angle % 180 == 0; |
| - bool natural_orientation_is_landscape = |
| - screen_orientation_is_landscape == |
| + bool natural_orientation_is_portrait = |
| + screen_orientation_is_portrait == |
| screen_orientation_is_natural_or_flipped_natural; |
| - bool natural_orientation_matches_video = |
| - natural_orientation_is_landscape == |
| - (locked_orientation_ == kWebScreenOrientationLockLandscape); |
| + // If natural_orientation_is_portrait_, then angles 0 and 180 are portrait, |
| + // otherwise angles 90 and 270 are portrait. |
| + int portrait_angle_mod_180 = natural_orientation_is_portrait ? 0 : 90; |
| + return device_orientation_angle90 % 180 == portrait_angle_mod_180 |
| + ? DeviceOrientation::kPortrait |
| + : DeviceOrientation::kLandscape; |
| +} |
| + |
| +void MediaControlsOrientationLockDelegate:: |
| + MaybeUnlockIfDeviceOrientationMatchesVideo(DeviceOrientationEvent* event) { |
| + DCHECK_EQ(state_, State::kMaybeLockedFullscreen); |
| + DCHECK(locked_orientation_ == kWebScreenOrientationLockPortrait || |
| + locked_orientation_ == kWebScreenOrientationLockLandscape); |
| + |
| + DeviceOrientation device_orientation = |
| + ComputeDeviceOrientation(event->Orientation()); |
| - // If natural_orientation_matches_video, then 0 and 180 match video, otherwise |
| - // 90 and 270 match video. |
| - bool device_orientation_matches_video = |
| - (device_orientation_angle90 % 180) == |
| - (natural_orientation_matches_video ? 0 : 90); |
| + DeviceOrientation video_orientation = |
| + locked_orientation_ == kWebScreenOrientationLockPortrait |
| + ? DeviceOrientation::kPortrait |
| + : DeviceOrientation::kLandscape; |
| - if (!device_orientation_matches_video) |
| + if (device_orientation != video_orientation) |
| return; |
| // Job done: the user rotated their device to match the orientation of the |