| 1 | /* |
| 2 | * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(VIDEO) |
| 29 | |
| 30 | #include "HTMLMediaElement.h" |
| 31 | #include <memory> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | class HTMLImageLoader; |
| 36 | class RenderVideo; |
| 37 | |
| 38 | class HTMLVideoElement final : public HTMLMediaElement { |
| 39 | WTF_MAKE_ISO_ALLOCATED(HTMLVideoElement); |
| 40 | public: |
| 41 | WEBCORE_EXPORT static Ref<HTMLVideoElement> create(Document&); |
| 42 | static Ref<HTMLVideoElement> create(const QualifiedName&, Document&, bool createdByParser); |
| 43 | |
| 44 | WEBCORE_EXPORT unsigned videoWidth() const; |
| 45 | WEBCORE_EXPORT unsigned videoHeight() const; |
| 46 | |
| 47 | WEBCORE_EXPORT ExceptionOr<void> webkitEnterFullscreen(); |
| 48 | WEBCORE_EXPORT void webkitExitFullscreen(); |
| 49 | WEBCORE_EXPORT bool webkitSupportsFullscreen(); |
| 50 | WEBCORE_EXPORT bool webkitDisplayingFullscreen(); |
| 51 | |
| 52 | void ancestorWillEnterFullscreen() final; |
| 53 | |
| 54 | #if ENABLE(WIRELESS_PLAYBACK_TARGET) |
| 55 | bool webkitWirelessVideoPlaybackDisabled() const; |
| 56 | void setWebkitWirelessVideoPlaybackDisabled(bool); |
| 57 | #endif |
| 58 | |
| 59 | #if ENABLE(MEDIA_STATISTICS) |
| 60 | unsigned webkitDecodedFrameCount() const; |
| 61 | unsigned webkitDroppedFrameCount() const; |
| 62 | #endif |
| 63 | |
| 64 | #if ENABLE(FULLSCREEN_API) && PLATFORM(IOS_FAMILY) |
| 65 | void webkitRequestFullscreen() override; |
| 66 | #endif |
| 67 | |
| 68 | // Used by canvas to gain raw pixel access |
| 69 | void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&); |
| 70 | |
| 71 | NativeImagePtr nativeImageForCurrentTime(); |
| 72 | |
| 73 | // Used by WebGL to do GPU-GPU textures copy if possible. |
| 74 | // See more details at MediaPlayer::copyVideoTextureToPlatformTexture() defined in Source/WebCore/platform/graphics/MediaPlayer.h. |
| 75 | bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject texture, GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool flipY); |
| 76 | |
| 77 | bool shouldDisplayPosterImage() const { return displayMode() == Poster || displayMode() == PosterWaitingForVideo; } |
| 78 | |
| 79 | URL posterImageURL() const; |
| 80 | RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; |
| 81 | |
| 82 | #if ENABLE(VIDEO_PRESENTATION_MODE) |
| 83 | enum class VideoPresentationMode { Fullscreen, PictureInPicture, Inline }; |
| 84 | WEBCORE_EXPORT bool webkitSupportsPresentationMode(VideoPresentationMode) const; |
| 85 | void webkitSetPresentationMode(VideoPresentationMode); |
| 86 | VideoPresentationMode webkitPresentationMode() const; |
| 87 | void setFullscreenMode(VideoFullscreenMode); |
| 88 | void fullscreenModeChanged(VideoFullscreenMode) final; |
| 89 | #endif |
| 90 | |
| 91 | #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) |
| 92 | void exitToFullscreenModeWithoutAnimationIfPossible(HTMLMediaElementEnums::VideoFullscreenMode fromMode, HTMLMediaElementEnums::VideoFullscreenMode toMode); |
| 93 | #endif |
| 94 | |
| 95 | RenderVideo* renderer() const; |
| 96 | |
| 97 | private: |
| 98 | HTMLVideoElement(const QualifiedName&, Document&, bool createdByParser); |
| 99 | |
| 100 | void scheduleResizeEvent() final; |
| 101 | void scheduleResizeEventIfSizeChanged() final; |
| 102 | bool rendererIsNeeded(const RenderStyle&) final; |
| 103 | void didAttachRenderers() final; |
| 104 | void parseAttribute(const QualifiedName&, const AtomicString&) final; |
| 105 | bool isPresentationAttribute(const QualifiedName&) const final; |
| 106 | void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) final; |
| 107 | bool isVideo() const final { return true; } |
| 108 | bool hasVideo() const final { return player() && player()->hasVideo(); } |
| 109 | bool supportsFullscreen(HTMLMediaElementEnums::VideoFullscreenMode) const final; |
| 110 | bool isURLAttribute(const Attribute&) const final; |
| 111 | const AtomicString& imageSourceURL() const final; |
| 112 | |
| 113 | bool hasAvailableVideoFrame() const; |
| 114 | void updateDisplayState() final; |
| 115 | void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final; |
| 116 | void setDisplayMode(DisplayMode) final; |
| 117 | |
| 118 | PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession::Video; } |
| 119 | |
| 120 | std::unique_ptr<HTMLImageLoader> m_imageLoader; |
| 121 | |
| 122 | AtomicString m_defaultPosterURL; |
| 123 | |
| 124 | unsigned m_lastReportedVideoWidth { 0 }; |
| 125 | unsigned m_lastReportedVideoHeight { 0 }; |
| 126 | }; |
| 127 | |
| 128 | } // namespace WebCore |
| 129 | |
| 130 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLVideoElement) |
| 131 | static bool isType(const WebCore::HTMLMediaElement& element) { return element.hasTagName(WebCore::HTMLNames::videoTag); } |
| 132 | static bool isType(const WebCore::Element& element) { return is<WebCore::HTMLMediaElement>(element) && isType(downcast<WebCore::HTMLMediaElement>(element)); } |
| 133 | static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLMediaElement>(node) && isType(downcast<WebCore::HTMLMediaElement>(node)); } |
| 134 | SPECIALIZE_TYPE_TRAITS_END() |
| 135 | |
| 136 | #endif // ENABLE(VIDEO) |
| 137 | |