1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_HTMLVideoElement_h
8 #define mozilla_dom_HTMLVideoElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/dom/HTMLMediaElement.h"
13 #include "mozilla/StaticPrefs_media.h"
18 class FrameStatistics
;
23 class VideoPlaybackQuality
;
25 class HTMLVideoElement final
: public HTMLMediaElement
{
26 class SecondaryVideoOutput
;
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLVideoElement
, HTMLMediaElement
)
32 typedef mozilla::dom::NodeInfo NodeInfo
;
34 explicit HTMLVideoElement(already_AddRefed
<NodeInfo
>&& aNodeInfo
);
36 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLVideoElement
, video
)
38 using HTMLMediaElement::GetPaused
;
40 void Invalidate(ImageSizeChanged aImageSizeChanged
,
41 const Maybe
<nsIntSize
>& aNewIntrinsicSize
,
42 ForceInvalidate aForceInvalidate
) override
;
44 virtual bool IsVideo() const override
{ return true; }
46 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
47 const nsAString
& aValue
,
48 nsIPrincipal
* aMaybeScriptedPrincipal
,
49 nsAttrValue
& aResult
) override
;
50 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
52 nsMapRuleToAttributesFunc
GetAttributeMappingFunction() const override
;
54 nsresult
Clone(NodeInfo
*, nsINode
** aResult
) const override
;
56 void UnbindFromTree(UnbindContext
&) override
;
58 mozilla::Maybe
<mozilla::CSSIntSize
> GetVideoSize() const;
60 void UpdateMediaSize(const nsIntSize
& aSize
) override
;
62 nsresult
SetAcceptHeader(nsIHttpChannel
* aChannel
) override
;
65 bool IsInteractiveHTMLContent() const override
;
69 uint32_t Width() const {
70 return GetDimensionAttrAsUnsignedInt(nsGkAtoms::width
, 0);
73 void SetWidth(uint32_t aValue
, ErrorResult
& aRv
) {
74 SetUnsignedIntAttr(nsGkAtoms::width
, aValue
, 0, aRv
);
77 uint32_t Height() const {
78 return GetDimensionAttrAsUnsignedInt(nsGkAtoms::height
, 0);
81 void SetHeight(uint32_t aValue
, ErrorResult
& aRv
) {
82 SetUnsignedIntAttr(nsGkAtoms::height
, aValue
, 0, aRv
);
85 uint32_t VideoWidth();
87 uint32_t VideoHeight();
89 VideoRotation
RotationDegrees() const { return mMediaInfo
.mVideo
.mRotation
; }
91 bool HasAlpha() const { return mMediaInfo
.mVideo
.HasAlpha(); }
93 void GetPoster(nsAString
& aValue
) {
94 GetURIAttr(nsGkAtoms::poster
, nullptr, aValue
);
96 void SetPoster(const nsAString
& aValue
, ErrorResult
& aRv
) {
97 SetHTMLAttr(nsGkAtoms::poster
, aValue
, aRv
);
100 uint32_t MozParsedFrames() const;
102 uint32_t MozDecodedFrames() const;
104 uint32_t MozPresentedFrames();
106 uint32_t MozPaintedFrames();
108 double MozFrameDelay();
110 bool MozHasAudio() const;
112 already_AddRefed
<VideoPlaybackQuality
> GetVideoPlaybackQuality();
114 already_AddRefed
<Promise
> CloneElementVisually(HTMLVideoElement
& aTarget
,
117 void StopCloningElementVisually();
119 bool IsCloningElementVisually() const { return !!mVisualCloneTarget
; }
121 void OnSecondaryVideoContainerInstalled(
122 const RefPtr
<VideoFrameContainer
>& aSecondaryContainer
) override
;
124 void OnSecondaryVideoOutputFirstFrameRendered();
126 void OnVisibilityChange(Visibility aNewVisibility
) override
;
128 bool DisablePictureInPicture() const {
129 return GetBoolAttr(nsGkAtoms::disablepictureinpicture
);
132 void SetDisablePictureInPicture(bool aValue
, ErrorResult
& aError
) {
133 SetHTMLBoolAttr(nsGkAtoms::disablepictureinpicture
, aValue
, aError
);
137 virtual ~HTMLVideoElement();
139 virtual JSObject
* WrapNode(JSContext
* aCx
,
140 JS::Handle
<JSObject
*> aGivenProto
) override
;
143 * We create video wakelock when the video is playing and release it when
144 * video pauses. Note, the actual platform wakelock will automatically be
145 * released when the page is in the background, so we don't need to check the
146 * video's visibility by ourselves.
148 void WakeLockRelease() override
;
149 void UpdateWakeLock() override
;
151 bool ShouldCreateVideoWakeLock() const;
152 void CreateVideoWakeLockIfNeeded();
153 void ReleaseVideoWakeLockIfExists();
155 gfx::IntSize
GetVideoIntrinsicDimensions();
157 RefPtr
<WakeLock
> mScreenWakeLock
;
159 WatchManager
<HTMLVideoElement
> mVideoWatchManager
;
162 bool SetVisualCloneTarget(
163 RefPtr
<HTMLVideoElement
> aVisualCloneTarget
,
164 RefPtr
<Promise
> aVisualCloneTargetPromise
= nullptr);
165 bool SetVisualCloneSource(RefPtr
<HTMLVideoElement
> aVisualCloneSource
);
167 // For video elements, we can clone the frames being played to
168 // a secondary video element. If we're doing that, we hold a
169 // reference to the video element we're cloning to in
170 // mVisualCloneSource.
172 // Please don't set this to non-nullptr values directly - use
173 // SetVisualCloneTarget() instead.
174 RefPtr
<HTMLVideoElement
> mVisualCloneTarget
;
175 // Set when mVisualCloneTarget is set, and resolved (and unset) when the
176 // secondary container has been applied to the underlying resource.
177 RefPtr
<Promise
> mVisualCloneTargetPromise
;
178 // Set when beginning to clone visually and we are playing a MediaStream.
179 // This is the output wrapping the VideoFrameContainer of mVisualCloneTarget,
180 // so we can render its first frame, and resolve mVisualCloneTargetPromise as
182 RefPtr
<FirstFrameVideoOutput
> mSecondaryVideoOutput
;
183 // If this video is the clone target of another video element,
184 // then mVisualCloneSource points to that originating video
187 // Please don't set this to non-nullptr values directly - use
188 // SetVisualCloneTarget() instead.
189 RefPtr
<HTMLVideoElement
> mVisualCloneSource
;
191 static void MapAttributesIntoRule(MappedDeclarationsBuilder
&);
193 static bool IsVideoStatsEnabled();
194 double TotalPlayTime() const;
196 virtual void MaybeBeginCloningVisually() override
;
197 void EndCloningVisually();
201 } // namespace mozilla
203 #endif // mozilla_dom_HTMLVideoElement_h