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 applies. 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 // Called by MediaControls when the HTMLMediaElement is added to a document | |
47 // document. All event listeners should be added. | |
48 void attach(); | |
49 | |
50 // Called by MediaControls when the HTMLMediaElement is no longer in the | |
51 // document. All event listeners should be removed in order to prepare the | |
52 // object to be garbage collected. | |
53 void detach(); | |
54 | |
55 // EventListener implementation. | |
56 bool operator==(const EventListener&) const override; | |
57 | |
58 DECLARE_VIRTUAL_TRACE(); | |
59 | |
60 private: | |
61 friend class MediaControlsOrientationLockDelegateTest; | |
62 | |
63 enum class State { | |
64 PendingFullscreen, | |
65 PendingMetadata, | |
66 MaybeLockedFullscreen, | |
67 }; | |
68 | |
69 // EventListener implementation. | |
70 void handleEvent(ExecutionContext*, Event*) override; | |
71 | |
72 HTMLVideoElement& videoElement() const; | |
73 Document& document() const; | |
74 | |
75 // Returns the orientation in which the video should be locked based on its | |
76 // size. | |
77 WebScreenOrientationLockType computeOrientationLock() const; | |
78 | |
79 // Locks the screen orientation if the video has metadata information | |
80 // available. Delays locking orientation until metadata are available | |
81 // otherwise. | |
82 void maybeLockOrientation(); | |
83 | |
84 // Unlocks the screen orientation if the screen orientation was previously | |
85 // locked. | |
86 void maybeUnlockOrientation(); | |
87 | |
88 // Current state of the object. See comment at the top of the file for a | |
89 // detailed description. | |
90 State m_state = State::PendingFullscreen; | |
91 | |
92 // Whether the controls should unlock the screen orientation when possible. | |
93 // In other words, whether the orientation was locked. | |
94 bool m_shouldUnlockOrientation = false; | |
95 | |
96 // `m_videoElement` owns MediaControls that owns |this|. | |
97 Member<HTMLVideoElement> m_videoElement; | |
98 }; | |
99 | |
100 } // namespace blink | |
101 | |
102 #endif // MediaControlsOrientationLockDelegate_h | |
OLD | NEW |