| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "core/html/MediaCustomControlsFullscreenDetector.h" | 5 #include "core/html/MediaCustomControlsFullscreenDetector.h" |
| 6 | 6 |
| 7 #include "core/dom/Fullscreen.h" | 7 #include "core/dom/Fullscreen.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/html/HTMLVideoElement.h" | 10 #include "core/html/HTMLVideoElement.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 MediaCustomControlsFullscreenDetector::MediaCustomControlsFullscreenDetector( | 23 MediaCustomControlsFullscreenDetector::MediaCustomControlsFullscreenDetector( |
| 24 HTMLVideoElement& video) | 24 HTMLVideoElement& video) |
| 25 : EventListener(CPPEventListenerType), | 25 : EventListener(CPPEventListenerType), |
| 26 m_videoElement(video), | 26 m_videoElement(video), |
| 27 m_checkViewportIntersectionTimer( | 27 m_checkViewportIntersectionTimer( |
| 28 TaskRunnerHelper::get(TaskType::Unthrottled, &video.document()), | 28 TaskRunnerHelper::get(TaskType::Unthrottled, &video.document()), |
| 29 this, | 29 this, |
| 30 &MediaCustomControlsFullscreenDetector:: | 30 &MediaCustomControlsFullscreenDetector:: |
| 31 onCheckViewportIntersectionTimerFired) { | 31 onCheckViewportIntersectionTimerFired) { |
| 32 videoElement().addEventListener(EventTypeNames::DOMNodeInsertedIntoDocument, | 32 if (videoElement().isConnected()) |
| 33 this, false); | 33 attach(); |
| 34 videoElement().addEventListener(EventTypeNames::DOMNodeRemovedFromDocument, | |
| 35 this, false); | |
| 36 | |
| 37 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true); | |
| 38 } | 34 } |
| 39 | 35 |
| 40 bool MediaCustomControlsFullscreenDetector::operator==( | 36 bool MediaCustomControlsFullscreenDetector::operator==( |
| 41 const EventListener& other) const { | 37 const EventListener& other) const { |
| 42 return this == &other; | 38 return this == &other; |
| 43 } | 39 } |
| 44 | 40 |
| 45 void MediaCustomControlsFullscreenDetector::attach() { | 41 void MediaCustomControlsFullscreenDetector::attach() { |
| 42 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true); |
| 46 videoElement().document().addEventListener( | 43 videoElement().document().addEventListener( |
| 47 EventTypeNames::webkitfullscreenchange, this, true); | 44 EventTypeNames::webkitfullscreenchange, this, true); |
| 48 videoElement().document().addEventListener(EventTypeNames::fullscreenchange, | 45 videoElement().document().addEventListener(EventTypeNames::fullscreenchange, |
| 49 this, true); | 46 this, true); |
| 50 } | 47 } |
| 51 | 48 |
| 52 void MediaCustomControlsFullscreenDetector::detach() { | 49 void MediaCustomControlsFullscreenDetector::detach() { |
| 50 videoElement().removeEventListener(EventTypeNames::loadedmetadata, this, |
| 51 true); |
| 53 videoElement().document().removeEventListener( | 52 videoElement().document().removeEventListener( |
| 54 EventTypeNames::webkitfullscreenchange, this, true); | 53 EventTypeNames::webkitfullscreenchange, this, true); |
| 55 videoElement().document().removeEventListener( | 54 videoElement().document().removeEventListener( |
| 56 EventTypeNames::fullscreenchange, this, true); | 55 EventTypeNames::fullscreenchange, this, true); |
| 57 m_checkViewportIntersectionTimer.stop(); | 56 m_checkViewportIntersectionTimer.stop(); |
| 58 | 57 |
| 59 if (videoElement().webMediaPlayer()) | 58 if (videoElement().webMediaPlayer()) |
| 60 videoElement().webMediaPlayer()->setIsEffectivelyFullscreen(false); | 59 videoElement().webMediaPlayer()->setIsEffectivelyFullscreen(false); |
| 61 } | 60 } |
| 62 | 61 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 kMostlyFillViewportThresholdOfVisibleProportion < | 91 kMostlyFillViewportThresholdOfVisibleProportion < |
| 93 intersectionRect.height(); | 92 intersectionRect.height(); |
| 94 } | 93 } |
| 95 return targetRect.width() * kMostlyFillViewportThresholdOfVisibleProportion < | 94 return targetRect.width() * kMostlyFillViewportThresholdOfVisibleProportion < |
| 96 intersectionRect.width(); | 95 intersectionRect.width(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 void MediaCustomControlsFullscreenDetector::handleEvent( | 98 void MediaCustomControlsFullscreenDetector::handleEvent( |
| 100 ExecutionContext* context, | 99 ExecutionContext* context, |
| 101 Event* event) { | 100 Event* event) { |
| 102 DCHECK(event->type() == EventTypeNames::DOMNodeInsertedIntoDocument || | 101 DCHECK(event->type() == EventTypeNames::loadedmetadata || |
| 103 event->type() == EventTypeNames::DOMNodeRemovedFromDocument || | |
| 104 event->type() == EventTypeNames::loadedmetadata || | |
| 105 event->type() == EventTypeNames::webkitfullscreenchange || | 102 event->type() == EventTypeNames::webkitfullscreenchange || |
| 106 event->type() == EventTypeNames::fullscreenchange); | 103 event->type() == EventTypeNames::fullscreenchange); |
| 107 | 104 |
| 108 // Don't early return when the video is inserted into/removed from the | |
| 109 // document, as the document might already be in fullscreen. | |
| 110 if (event->type() == EventTypeNames::DOMNodeInsertedIntoDocument) { | |
| 111 attach(); | |
| 112 } else if (event->type() == EventTypeNames::DOMNodeRemovedFromDocument) { | |
| 113 detach(); | |
| 114 } | |
| 115 | |
| 116 // Video is not loaded yet. | 105 // Video is not loaded yet. |
| 117 if (videoElement().getReadyState() < HTMLMediaElement::kHaveMetadata) | 106 if (videoElement().getReadyState() < HTMLMediaElement::kHaveMetadata) |
| 118 return; | 107 return; |
| 119 | 108 |
| 120 if (!videoElement().isConnected() || !isVideoOrParentFullscreen()) { | 109 if (!videoElement().isConnected() || !isVideoOrParentFullscreen()) { |
| 121 m_checkViewportIntersectionTimer.stop(); | 110 m_checkViewportIntersectionTimer.stop(); |
| 122 | 111 |
| 123 if (videoElement().webMediaPlayer()) | 112 if (videoElement().webMediaPlayer()) |
| 124 videoElement().webMediaPlayer()->setIsEffectivelyFullscreen(false); | 113 videoElement().webMediaPlayer()->setIsEffectivelyFullscreen(false); |
| 125 | 114 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 150 |
| 162 return fullscreenElement->contains(&videoElement()); | 151 return fullscreenElement->contains(&videoElement()); |
| 163 } | 152 } |
| 164 | 153 |
| 165 DEFINE_TRACE(MediaCustomControlsFullscreenDetector) { | 154 DEFINE_TRACE(MediaCustomControlsFullscreenDetector) { |
| 166 EventListener::trace(visitor); | 155 EventListener::trace(visitor); |
| 167 visitor->trace(m_videoElement); | 156 visitor->trace(m_videoElement); |
| 168 } | 157 } |
| 169 | 158 |
| 170 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |