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

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.h

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

Powered by Google App Engine
This is Rietveld 408576698