| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MediaControlsOrientationLockDelegate_h |
| 6 #define MediaControlsOrientationLockDelegate_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/events/EventListener.h" |
| 10 #include "public/platform/modules/screen_orientation/WebScreenOrientationLockTyp
e.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class Document; |
| 15 class HTMLVideoElement; |
| 16 |
| 17 // MediaControlsOrientationLockDelegate is implementing the orientation lock |
| 18 // feature when a <video> is fullscreen. It is meant to be created by |
| 19 // `MediaControls` when the feature apply. Once created, it will use events to |
| 20 // change state. |
| 21 // |
| 22 // The different states of the class are: |
| 23 // - PendingFullscreen: the object is created and is waiting for the associated |
| 24 // <video> to go fullscreen in order to apply an orientation lock; |
| 25 // - PendingMetadata: the <video> is fullscreen but the metadata have not been |
| 26 // downloaded yet. It can happen because of network latency or because the |
| 27 // <video> went fullscreen before playback and download started; |
| 28 // - MaybeLockedFullscreen: the <video> is fullscreen and a screen orientation |
| 29 // lock was applied. |
| 30 // |
| 31 // The possible state transitions are: |
| 32 // - PendingFullscreen => PendingMetadata: on fullscreenchange event (entering |
| 33 // fullscreen) when metadata are not available; |
| 34 // - PendingFullscreen => MaybeLockedFullscreen: on fullscreenchange event |
| 35 // (entering fullscreen) when metadata are available; |
| 36 // - PendingMetadata => MaybeLockedFullscreen: on loadedmetadata; |
| 37 // - PendingMetadata => PendingFullscreen: on fullscreenchange event (leaving |
| 38 // fullscreen); |
| 39 // - MaybeLockedFullscreen => PendingFullscreen: on fullscreenchange event |
| 40 // (leaving fullscreen). |
| 41 class CORE_EXPORT MediaControlsOrientationLockDelegate final |
| 42 : public EventListener { |
| 43 public: |
| 44 explicit MediaControlsOrientationLockDelegate(HTMLVideoElement&); |
| 45 |
| 46 // EventListener implementation. |
| 47 bool operator==(const EventListener&) const override; |
| 48 |
| 49 DECLARE_VIRTUAL_TRACE(); |
| 50 |
| 51 private: |
| 52 friend class MediaControlsOrientationLockDelegateTest; |
| 53 |
| 54 enum class State { |
| 55 PendingFullscreen, |
| 56 PendingMetadata, |
| 57 MaybeLockedFullscreen, |
| 58 }; |
| 59 |
| 60 // EventListener implementation. |
| 61 void handleEvent(ExecutionContext*, Event*) override; |
| 62 |
| 63 HTMLVideoElement& videoElement() const; |
| 64 Document& document() const; |
| 65 |
| 66 // Returns the orientation in which the video should be locked based on its |
| 67 // size. |
| 68 WebScreenOrientationLockType computeOrientationLock() const; |
| 69 |
| 70 // Locks the screen orientation if the video has metadata information |
| 71 // available. Delays locking orientation until metadata are available |
| 72 // otherwise. |
| 73 void maybeLockOrientation(); |
| 74 |
| 75 // Unlocks the screen orientation if the screen orientation was previously |
| 76 // locked. |
| 77 void maybeUnlockOrientation(); |
| 78 |
| 79 // Current state of the object. See comment at the top of the file for a |
| 80 // detailed description. |
| 81 State m_state = State::PendingFullscreen; |
| 82 |
| 83 // Whether the controls should unlock the screen orientation when possible. |
| 84 // In other words, whether the orientation was locked. |
| 85 bool m_shouldUnlockOrientation = false; |
| 86 |
| 87 // `m_videoElement` owns MediaControls that owns |this|. |
| 88 Member<HTMLVideoElement> m_videoElement; |
| 89 }; |
| 90 |
| 91 } // namespace blink |
| 92 |
| 93 #endif // MediaControlsOrientationLockDelegate_h |
| OLD | NEW |