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 #include "MediaControlsOrientationLockDelegate.h" | 5 #include "MediaControlsOrientationLockDelegate.h" |
6 | 6 |
7 #include "core/events/Event.h" | 7 #include "core/events/Event.h" |
8 #include "core/frame/ScreenOrientationController.h" | 8 #include "core/frame/ScreenOrientationController.h" |
9 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
10 #include "core/page/ChromeClient.h" | 10 #include "core/page/ChromeClient.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 MediaControlsOrientationLockDelegate::MediaControlsOrientationLockDelegate( | 64 MediaControlsOrientationLockDelegate::MediaControlsOrientationLockDelegate( |
65 HTMLVideoElement& video) | 65 HTMLVideoElement& video) |
66 : EventListener(CPPEventListenerType), m_videoElement(video) { | 66 : EventListener(CPPEventListenerType), m_videoElement(video) { |
67 if (videoElement().isConnected()) | 67 if (videoElement().isConnected()) |
68 attach(); | 68 attach(); |
69 } | 69 } |
70 | 70 |
71 void MediaControlsOrientationLockDelegate::attach() { | 71 void MediaControlsOrientationLockDelegate::attach() { |
72 DCHECK(videoElement().isConnected()); | 72 DCHECK(videoElement().isConnected()); |
73 | 73 |
74 document().addEventListener(EventTypeNames::fullscreenchange, this, true); | |
75 videoElement().addEventListener(EventTypeNames::webkitfullscreenchange, this, | |
76 true); | |
77 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true); | 74 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true); |
78 } | 75 } |
79 | 76 |
80 void MediaControlsOrientationLockDelegate::detach() { | 77 void MediaControlsOrientationLockDelegate::detach() { |
81 DCHECK(!videoElement().isConnected()); | 78 DCHECK(!videoElement().isConnected()); |
82 | 79 |
83 document().removeEventListener(EventTypeNames::fullscreenchange, this, true); | |
84 videoElement().removeEventListener(EventTypeNames::webkitfullscreenchange, | |
85 this, true); | |
86 videoElement().removeEventListener(EventTypeNames::loadedmetadata, this, | 80 videoElement().removeEventListener(EventTypeNames::loadedmetadata, this, |
87 true); | 81 true); |
88 } | 82 } |
89 | 83 |
| 84 void MediaControlsOrientationLockDelegate::didEnterFullscreen() { |
| 85 if (m_state == State::PendingFullscreen) |
| 86 maybeLockOrientation(); |
| 87 } |
| 88 |
| 89 void MediaControlsOrientationLockDelegate::didExitFullscreen() { |
| 90 if (m_state != State::PendingFullscreen) |
| 91 maybeUnlockOrientation(); |
| 92 } |
| 93 |
90 bool MediaControlsOrientationLockDelegate::operator==( | 94 bool MediaControlsOrientationLockDelegate::operator==( |
91 const EventListener& other) const { | 95 const EventListener& other) const { |
92 return this == &other; | 96 return this == &other; |
93 } | 97 } |
94 | 98 |
95 void MediaControlsOrientationLockDelegate::maybeLockOrientation() { | 99 void MediaControlsOrientationLockDelegate::maybeLockOrientation() { |
96 DCHECK(m_state != State::MaybeLockedFullscreen); | 100 DCHECK(m_state != State::MaybeLockedFullscreen); |
97 | 101 |
98 if (videoElement().getReadyState() == HTMLMediaElement::kHaveNothing) { | 102 if (videoElement().getReadyState() == HTMLMediaElement::kHaveNothing) { |
99 recordMetadataAvailability(MetadataAvailabilityMetrics::Missing); | 103 recordMetadataAvailability(MetadataAvailabilityMetrics::Missing); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return *m_videoElement; | 148 return *m_videoElement; |
145 } | 149 } |
146 | 150 |
147 Document& MediaControlsOrientationLockDelegate::document() const { | 151 Document& MediaControlsOrientationLockDelegate::document() const { |
148 return videoElement().document(); | 152 return videoElement().document(); |
149 } | 153 } |
150 | 154 |
151 void MediaControlsOrientationLockDelegate::handleEvent( | 155 void MediaControlsOrientationLockDelegate::handleEvent( |
152 ExecutionContext* executionContext, | 156 ExecutionContext* executionContext, |
153 Event* event) { | 157 Event* event) { |
154 if (event->type() == EventTypeNames::fullscreenchange || | |
155 event->type() == EventTypeNames::webkitfullscreenchange) { | |
156 if (videoElement().isFullscreen()) { | |
157 if (m_state == State::PendingFullscreen) | |
158 maybeLockOrientation(); | |
159 } else { | |
160 if (m_state != State::PendingFullscreen) | |
161 maybeUnlockOrientation(); | |
162 } | |
163 | |
164 return; | |
165 } | |
166 | |
167 if (event->type() == EventTypeNames::loadedmetadata) { | 158 if (event->type() == EventTypeNames::loadedmetadata) { |
168 if (m_state == State::PendingMetadata) | 159 if (m_state == State::PendingMetadata) |
169 maybeLockOrientation(); | 160 maybeLockOrientation(); |
170 | 161 |
171 return; | 162 return; |
172 } | 163 } |
173 | 164 |
174 NOTREACHED(); | 165 NOTREACHED(); |
175 } | 166 } |
176 | 167 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 NOTREACHED(); | 200 NOTREACHED(); |
210 return WebScreenOrientationLockLandscape; | 201 return WebScreenOrientationLockLandscape; |
211 } | 202 } |
212 | 203 |
213 DEFINE_TRACE(MediaControlsOrientationLockDelegate) { | 204 DEFINE_TRACE(MediaControlsOrientationLockDelegate) { |
214 EventListener::trace(visitor); | 205 EventListener::trace(visitor); |
215 visitor->trace(m_videoElement); | 206 visitor->trace(m_videoElement); |
216 } | 207 } |
217 | 208 |
218 } // namespace blink | 209 } // namespace blink |
OLD | NEW |