OLD | NEW |
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 #ifndef MediaControlsOrientationLockDelegate_h | 5 #ifndef MediaControlsOrientationLockDelegate_h |
6 #define MediaControlsOrientationLockDelegate_h | 6 #define MediaControlsOrientationLockDelegate_h |
7 | 7 |
8 #include "core/events/EventListener.h" | 8 #include "core/events/EventListener.h" |
9 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom-b
link.h" | 9 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom-b
link.h" |
10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
| 11 #include "platform/wtf/Optional.h" |
11 #include "public/platform/modules/screen_orientation/WebScreenOrientationLockTyp
e.h" | 12 #include "public/platform/modules/screen_orientation/WebScreenOrientationLockTyp
e.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
| 16 class DeviceOrientationData; |
15 class DeviceOrientationEvent; | 17 class DeviceOrientationEvent; |
16 class Document; | 18 class Document; |
17 class HTMLVideoElement; | 19 class HTMLVideoElement; |
18 | 20 |
19 // MediaControlsOrientationLockDelegate is implementing the orientation lock | 21 // MediaControlsOrientationLockDelegate is implementing the orientation lock |
20 // feature when a <video> is fullscreen. It is meant to be created by | 22 // feature when a <video> is fullscreen. It is meant to be created by |
21 // `MediaControlsImpl` when the feature applies. Once created, it will use | 23 // `MediaControlsImpl` when the feature applies. Once created, it will use |
22 // events to change state. | 24 // events to change state. |
23 // | 25 // |
24 // The behavior depends on whether MediaControlsRotateToFullscreenDelegate is | 26 // The behavior depends on whether MediaControlsRotateToFullscreenDelegate is |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // object to be garbage collected. | 64 // object to be garbage collected. |
63 void Detach(); | 65 void Detach(); |
64 | 66 |
65 // EventListener implementation. | 67 // EventListener implementation. |
66 bool operator==(const EventListener&) const override; | 68 bool operator==(const EventListener&) const override; |
67 | 69 |
68 DECLARE_VIRTUAL_TRACE(); | 70 DECLARE_VIRTUAL_TRACE(); |
69 | 71 |
70 private: | 72 private: |
71 friend class MediaControlsOrientationLockDelegateTest; | 73 friend class MediaControlsOrientationLockDelegateTest; |
| 74 friend class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest; |
72 | 75 |
73 enum class State { | 76 enum class State { |
74 kPendingFullscreen, | 77 kPendingFullscreen, |
75 kPendingMetadata, | 78 kPendingMetadata, |
76 kMaybeLockedFullscreen, | 79 kMaybeLockedFullscreen, |
77 }; | 80 }; |
78 | 81 |
| 82 enum class DeviceOrientationType { |
| 83 kUnknown, |
| 84 kFlat, |
| 85 kDiagonal, |
| 86 kPortrait, |
| 87 kLandscape |
| 88 }; |
| 89 |
79 // EventListener implementation. | 90 // EventListener implementation. |
80 void handleEvent(ExecutionContext*, Event*) override; | 91 void handleEvent(ExecutionContext*, Event*) override; |
81 | 92 |
82 HTMLVideoElement& VideoElement() const; | 93 HTMLVideoElement& VideoElement() const; |
83 Document& GetDocument() const; | 94 Document& GetDocument() const; |
84 | 95 |
85 // Returns the orientation in which the video should be locked based on its | 96 // Returns the orientation in which the video should be locked based on its |
86 // size. | 97 // size. |
87 MODULES_EXPORT WebScreenOrientationLockType ComputeOrientationLock() const; | 98 MODULES_EXPORT WebScreenOrientationLockType ComputeOrientationLock() const; |
88 | 99 |
89 // Locks the screen orientation if the video has metadata information | 100 // Locks the screen orientation if the video has metadata information |
90 // available. Delays locking orientation until metadata are available | 101 // available. Delays locking orientation until metadata are available |
91 // otherwise. | 102 // otherwise. |
92 void MaybeLockOrientation(); | 103 void MaybeLockOrientation(); |
93 | 104 |
94 // Unlocks the screen orientation if the screen orientation was previously | 105 // Unlocks the screen orientation if the screen orientation was previously |
95 // locked. | 106 // locked. |
96 void MaybeUnlockOrientation(); | 107 void MaybeUnlockOrientation(); |
97 | 108 |
98 void MaybeListenToDeviceOrientation(); | 109 void MaybeListenToDeviceOrientation(); |
99 void GotIsAutoRotateEnabledByUser(bool enabled); | 110 void GotIsAutoRotateEnabledByUser(bool enabled); |
100 | 111 |
| 112 MODULES_EXPORT DeviceOrientationType |
| 113 ComputeDeviceOrientation(DeviceOrientationData*) const; |
| 114 |
101 void MaybeUnlockIfDeviceOrientationMatchesVideo(DeviceOrientationEvent*); | 115 void MaybeUnlockIfDeviceOrientationMatchesVideo(DeviceOrientationEvent*); |
102 | 116 |
103 // Current state of the object. See comment at the top of the file for a | 117 // Current state of the object. See comment at the top of the file for a |
104 // detailed description. | 118 // detailed description. |
105 State state_ = State::kPendingFullscreen; | 119 State state_ = State::kPendingFullscreen; |
106 | 120 |
107 // Which lock is currently applied by this delegate. | 121 // Which lock is currently applied by this delegate. |
108 WebScreenOrientationLockType locked_orientation_ = | 122 WebScreenOrientationLockType locked_orientation_ = |
109 kWebScreenOrientationLockDefault /* unlocked */; | 123 kWebScreenOrientationLockDefault /* unlocked */; |
110 | 124 |
111 device::mojom::blink::ScreenOrientationListenerPtr monitor_; | 125 device::mojom::blink::ScreenOrientationListenerPtr monitor_; |
112 | 126 |
| 127 WTF::Optional<bool> is_auto_rotate_enabled_by_user_override_for_testing_; |
| 128 |
113 // `video_element_` owns MediaControlsImpl that owns |this|. | 129 // `video_element_` owns MediaControlsImpl that owns |this|. |
114 Member<HTMLVideoElement> video_element_; | 130 Member<HTMLVideoElement> video_element_; |
115 }; | 131 }; |
116 | 132 |
117 } // namespace blink | 133 } // namespace blink |
118 | 134 |
119 #endif // MediaControlsOrientationLockDelegate_h | 135 #endif // MediaControlsOrientationLockDelegate_h |
OLD | NEW |