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

Side by Side Diff: third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp

Issue 2919513002: [Media Controls] Prevent fullscreen orientation lock rotate glitch (Closed)
Patch Set: Rebase Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/media_controls/MediaControlsOrientationLockDelegate.h" 5 #include "modules/media_controls/MediaControlsOrientationLockDelegate.h"
6 6
7 #include "core/dom/TaskRunnerHelper.h"
7 #include "core/events/Event.h" 8 #include "core/events/Event.h"
8 #include "core/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/Screen.h" 10 #include "core/frame/Screen.h"
10 #include "core/frame/ScreenOrientationController.h" 11 #include "core/frame/ScreenOrientationController.h"
11 #include "core/html/HTMLVideoElement.h" 12 #include "core/html/HTMLVideoElement.h"
12 #include "core/page/ChromeClient.h" 13 #include "core/page/ChromeClient.h"
13 #include "modules/device_orientation/DeviceOrientationData.h" 14 #include "modules/device_orientation/DeviceOrientationData.h"
14 #include "modules/device_orientation/DeviceOrientationEvent.h" 15 #include "modules/device_orientation/DeviceOrientationEvent.h"
15 #include "modules/screen_orientation/ScreenOrientation.h" 16 #include "modules/screen_orientation/ScreenOrientation.h"
16 #include "modules/screen_orientation/ScreenScreenOrientation.h" 17 #include "modules/screen_orientation/ScreenScreenOrientation.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return; 162 return;
162 163
163 monitor_.reset(); // Cancel any GotIsAutoRotateEnabledByUser Mojo callback. 164 monitor_.reset(); // Cancel any GotIsAutoRotateEnabledByUser Mojo callback.
164 if (LocalDOMWindow* dom_window = GetDocument().domWindow()) { 165 if (LocalDOMWindow* dom_window = GetDocument().domWindow()) {
165 dom_window->removeEventListener(EventTypeNames::deviceorientation, this, 166 dom_window->removeEventListener(EventTypeNames::deviceorientation, this,
166 false); 167 false);
167 } 168 }
168 169
169 ScreenOrientationController::From(*GetDocument().GetFrame())->unlock(); 170 ScreenOrientationController::From(*GetDocument().GetFrame())->unlock();
170 locked_orientation_ = kWebScreenOrientationLockDefault /* unlocked */; 171 locked_orientation_ = kWebScreenOrientationLockDefault /* unlocked */;
172
173 unlock_task_.Cancel();
171 } 174 }
172 175
173 void MediaControlsOrientationLockDelegate::MaybeListenToDeviceOrientation() { 176 void MediaControlsOrientationLockDelegate::MaybeListenToDeviceOrientation() {
174 DCHECK_EQ(state_, State::kMaybeLockedFullscreen); 177 DCHECK_EQ(state_, State::kMaybeLockedFullscreen);
175 DCHECK_NE(locked_orientation_, kWebScreenOrientationLockDefault); 178 DCHECK_NE(locked_orientation_, kWebScreenOrientationLockDefault);
176 179
177 // If the rotate-to-fullscreen feature is also enabled, then start listening 180 // If the rotate-to-fullscreen feature is also enabled, then start listening
178 // to deviceorientation events so the orientation can be unlocked once the 181 // to deviceorientation events so the orientation can be unlocked once the
179 // user rotates the device to match the video's orientation (allowing the user 182 // user rotates the device to match the video's orientation (allowing the user
180 // to then exit fullscreen by rotating their device back to the opposite 183 // to then exit fullscreen by rotating their device back to the opposite
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 399
397 DeviceOrientationType video_orientation = 400 DeviceOrientationType video_orientation =
398 locked_orientation_ == kWebScreenOrientationLockPortrait 401 locked_orientation_ == kWebScreenOrientationLockPortrait
399 ? DeviceOrientationType::kPortrait 402 ? DeviceOrientationType::kPortrait
400 : DeviceOrientationType::kLandscape; 403 : DeviceOrientationType::kLandscape;
401 404
402 if (device_orientation != video_orientation) 405 if (device_orientation != video_orientation)
403 return; 406 return;
404 407
405 // Job done: the user rotated their device to match the orientation of the 408 // Job done: the user rotated their device to match the orientation of the
406 // video that we locked to, so now we can unlock (and stop listening). 409 // video that we locked to, so now we can stop listening and unlock.
407 MaybeUnlockOrientation(); 410 if (LocalDOMWindow* dom_window = GetDocument().domWindow()) {
411 dom_window->removeEventListener(EventTypeNames::deviceorientation, this,
412 false);
413 }
414 // Delay before unlocking, as a workaround for the case where the device is
415 // initially portrait-primary, then fullscreen orientation lock locks it to
416 // landscape and the screen orientation changes to landscape-primary, but the
417 // user actually rotates the device to landscape-secondary. In that case, if
418 // this delegate unlocks the orientation before Android has detected the
419 // rotation to landscape-secondary (which is slow due to low-pass filtering),
420 // Android would change the screen orientation back to portrait-primary. This
421 // is avoided by delaying unlocking long enough to ensure that Android has
422 // detected the orientation change.
423 unlock_task_ =
424 TaskRunnerHelper::Get(TaskType::kMediaElementEvent, &GetDocument())
425 ->PostDelayedCancellableTask(
426 BLINK_FROM_HERE,
427 WTF::Bind(
428 &MediaControlsOrientationLockDelegate::MaybeUnlockOrientation,
429 WrapPersistent(this)),
430 TimeDelta::FromMilliseconds(kUnlockDelayMs));
408 } 431 }
409 432
410 DEFINE_TRACE(MediaControlsOrientationLockDelegate) { 433 DEFINE_TRACE(MediaControlsOrientationLockDelegate) {
411 EventListener::Trace(visitor); 434 EventListener::Trace(visitor);
412 visitor->Trace(video_element_); 435 visitor->Trace(video_element_);
413 } 436 }
414 437
415 } // namespace blink 438 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698