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

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: 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 390
388 DeviceOrientation video_orientation = 391 DeviceOrientation video_orientation =
389 locked_orientation_ == kWebScreenOrientationLockPortrait 392 locked_orientation_ == kWebScreenOrientationLockPortrait
390 ? DeviceOrientation::kPortrait 393 ? DeviceOrientation::kPortrait
391 : DeviceOrientation::kLandscape; 394 : DeviceOrientation::kLandscape;
392 395
393 if (device_orientation != video_orientation) 396 if (device_orientation != video_orientation)
394 return; 397 return;
395 398
396 // Job done: the user rotated their device to match the orientation of the 399 // Job done: the user rotated their device to match the orientation of the
397 // video that we locked to, so now we can unlock (and stop listening). 400 // video that we locked to, so now we can stop listening and unlock.
398 MaybeUnlockOrientation(); 401 if (LocalDOMWindow* dom_window = GetDocument().domWindow()) {
402 dom_window->removeEventListener(EventTypeNames::deviceorientation, this,
403 false);
404 }
405 // Delay before unlocking, as a workaround for the case where the device is
406 // initially portrait-primary, then fullscreen orientation lock locks it to
407 // landscape and the screen orientation changes to landscape-primary, but the
408 // user actually rotates the device to landscape-secondary. In that case, if
409 // this delegate unlocks the orientation before Android has detected the
410 // rotation to landscape-secondary (which is slow due to low-pass filtering),
411 // Android would change the screen orientation back to portrait-primary. This
412 // is avoided by delaying unlocking long enough to ensure that Android has
413 // detected the orientation change.
414 unlock_task_ =
415 TaskRunnerHelper::Get(TaskType::kMediaElementEvent, &GetDocument())
416 ->PostDelayedCancellableTask(
417 BLINK_FROM_HERE,
418 WTF::Bind(
419 &MediaControlsOrientationLockDelegate::MaybeUnlockOrientation,
420 WrapPersistent(this)),
421 TimeDelta::FromMilliseconds(kUnlockDelayMs));
399 } 422 }
400 423
401 DEFINE_TRACE(MediaControlsOrientationLockDelegate) { 424 DEFINE_TRACE(MediaControlsOrientationLockDelegate) {
402 EventListener::Trace(visitor); 425 EventListener::Trace(visitor);
403 visitor->Trace(video_element_); 426 visitor->Trace(video_element_);
404 } 427 }
405 428
406 } // namespace blink 429 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698