2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-03-19 16:27:35 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_HTMLVideoElement_h
|
|
|
|
#define mozilla_dom_HTMLVideoElement_h
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-03-19 16:23:54 +04:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_media.h"
|
2020-11-03 22:54:41 +03:00
|
|
|
#include "Units.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
namespace mozilla {
|
2017-08-15 08:09:06 +03:00
|
|
|
|
|
|
|
class FrameStatistics;
|
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2014-01-07 16:16:07 +04:00
|
|
|
class WakeLock;
|
2013-10-22 01:23:33 +04:00
|
|
|
class VideoPlaybackQuality;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLVideoElement final : public HTMLMediaElement {
|
2019-11-22 15:52:48 +03:00
|
|
|
class SecondaryVideoOutput;
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
public:
|
2019-03-02 01:36:17 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLVideoElement, HTMLMediaElement)
|
|
|
|
|
2014-07-13 06:20:42 +04:00
|
|
|
typedef mozilla::dom::NodeInfo NodeInfo;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit HTMLVideoElement(already_AddRefed<NodeInfo>&& aNodeInfo);
|
2011-12-04 01:50:16 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLVideoElement, video)
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
using HTMLMediaElement::GetPaused;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2023-05-17 00:30:29 +03:00
|
|
|
void Invalidate(ImageSizeChanged aImageSizeChanged,
|
2023-04-03 11:36:39 +03:00
|
|
|
const Maybe<nsIntSize>& aNewIntrinsicSize,
|
2023-05-17 00:30:29 +03:00
|
|
|
ForceInvalidate aForceInvalidate) override;
|
2019-03-02 01:37:16 +03:00
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
virtual bool IsVideo() const override { return true; }
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2014-07-13 06:20:42 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2013-06-11 19:23:13 +04:00
|
|
|
|
2023-05-15 04:07:29 +03:00
|
|
|
nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
|
2009-02-26 10:04:42 +03:00
|
|
|
|
2023-05-15 04:07:29 +03:00
|
|
|
nsresult Clone(NodeInfo*, nsINode** aResult) const override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2023-05-15 04:07:29 +03:00
|
|
|
void UnbindFromTree(bool aNullParent = true) override;
|
2019-03-02 01:36:40 +03:00
|
|
|
|
2020-11-03 22:54:41 +03:00
|
|
|
mozilla::Maybe<mozilla::CSSIntSize> GetVideoSize() const;
|
2010-07-23 13:49:57 +04:00
|
|
|
|
2023-05-15 04:07:29 +03:00
|
|
|
void UpdateMediaSize(const nsIntSize& aSize) override;
|
2019-03-02 01:36:40 +03:00
|
|
|
|
2023-05-15 04:07:29 +03:00
|
|
|
nsresult SetAcceptHeader(nsIHttpChannel* aChannel) override;
|
2010-07-29 08:58:07 +04:00
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
// Element
|
2023-05-15 04:07:29 +03:00
|
|
|
bool IsInteractiveHTMLContent() const override;
|
2015-01-20 23:39:28 +03:00
|
|
|
|
2013-03-19 16:28:34 +04:00
|
|
|
// WebIDL
|
|
|
|
|
2019-06-29 00:01:35 +03:00
|
|
|
uint32_t Width() const {
|
|
|
|
return GetDimensionAttrAsUnsignedInt(nsGkAtoms::width, 0);
|
|
|
|
}
|
2013-03-19 16:28:34 +04:00
|
|
|
|
|
|
|
void SetWidth(uint32_t aValue, ErrorResult& aRv) {
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::width, aValue, 0, aRv);
|
2013-03-19 16:28:34 +04:00
|
|
|
}
|
|
|
|
|
2019-06-29 00:01:35 +03:00
|
|
|
uint32_t Height() const {
|
|
|
|
return GetDimensionAttrAsUnsignedInt(nsGkAtoms::height, 0);
|
|
|
|
}
|
2013-03-19 16:28:34 +04:00
|
|
|
|
|
|
|
void SetHeight(uint32_t aValue, ErrorResult& aRv) {
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::height, aValue, 0, aRv);
|
2013-03-19 16:28:34 +04:00
|
|
|
}
|
|
|
|
|
2022-07-11 16:32:40 +03:00
|
|
|
uint32_t VideoWidth();
|
2013-03-19 16:28:34 +04:00
|
|
|
|
2022-07-11 16:32:40 +03:00
|
|
|
uint32_t VideoHeight();
|
2016-05-11 20:54:52 +03:00
|
|
|
|
|
|
|
VideoInfo::Rotation RotationDegrees() const {
|
|
|
|
return mMediaInfo.mVideo.mRotation;
|
2013-03-19 16:28:34 +04:00
|
|
|
}
|
|
|
|
|
2019-04-10 11:08:26 +03:00
|
|
|
bool HasAlpha() const { return mMediaInfo.mVideo.HasAlpha(); }
|
|
|
|
|
2014-07-13 06:20:42 +04:00
|
|
|
void GetPoster(nsAString& aValue) {
|
|
|
|
GetURIAttr(nsGkAtoms::poster, nullptr, aValue);
|
|
|
|
}
|
2013-03-19 16:28:34 +04:00
|
|
|
void SetPoster(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::poster, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t MozParsedFrames() const;
|
|
|
|
|
|
|
|
uint32_t MozDecodedFrames() const;
|
|
|
|
|
2022-07-11 16:32:40 +03:00
|
|
|
uint32_t MozPresentedFrames();
|
2013-03-19 16:28:34 +04:00
|
|
|
|
|
|
|
uint32_t MozPaintedFrames();
|
|
|
|
|
|
|
|
double MozFrameDelay();
|
|
|
|
|
|
|
|
bool MozHasAudio() const;
|
|
|
|
|
2013-07-05 04:24:35 +04:00
|
|
|
already_AddRefed<VideoPlaybackQuality> GetVideoPlaybackQuality();
|
2013-06-21 07:14:18 +04:00
|
|
|
|
2017-08-25 09:23:03 +03:00
|
|
|
bool MozOrientationLockEnabled() const {
|
2019-06-13 12:00:59 +03:00
|
|
|
return StaticPrefs::media_videocontrols_lock_video_orientation();
|
2017-08-25 09:23:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MozIsOrientationLocked() const { return mIsOrientationLocked; }
|
|
|
|
|
|
|
|
void SetMozIsOrientationLocked(bool aLock) { mIsOrientationLocked = aLock; }
|
|
|
|
|
2019-11-22 15:52:48 +03:00
|
|
|
already_AddRefed<Promise> CloneElementVisually(HTMLVideoElement& aTarget,
|
|
|
|
ErrorResult& rv);
|
2019-03-02 01:36:40 +03:00
|
|
|
|
2019-03-13 04:43:07 +03:00
|
|
|
void StopCloningElementVisually();
|
|
|
|
|
|
|
|
bool IsCloningElementVisually() const { return !!mVisualCloneTarget; }
|
|
|
|
|
2019-11-22 15:52:48 +03:00
|
|
|
void OnSecondaryVideoContainerInstalled(
|
|
|
|
const RefPtr<VideoFrameContainer>& aSecondaryContainer) override;
|
|
|
|
|
2020-08-26 17:25:40 +03:00
|
|
|
void OnSecondaryVideoOutputFirstFrameRendered();
|
|
|
|
|
2022-12-06 21:21:39 +03:00
|
|
|
void OnVisibilityChange(Visibility aNewVisibility) override;
|
|
|
|
|
2013-03-19 16:28:34 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLVideoElement();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-05-10 16:42:39 +04:00
|
|
|
|
2018-10-02 20:56:21 +03:00
|
|
|
/**
|
|
|
|
* We create video wakelock when the video is playing and release it when
|
|
|
|
* video pauses. Note, the actual platform wakelock will automatically be
|
|
|
|
* released when the page is in the background, so we don't need to check the
|
|
|
|
* video's visibility by ourselves.
|
|
|
|
*/
|
|
|
|
void WakeLockRelease() override;
|
|
|
|
void UpdateWakeLock() override;
|
|
|
|
|
2018-10-02 20:55:50 +03:00
|
|
|
bool ShouldCreateVideoWakeLock() const;
|
2018-10-02 20:56:21 +03:00
|
|
|
void CreateVideoWakeLockIfNeeded();
|
|
|
|
void ReleaseVideoWakeLockIfExists();
|
2013-05-10 16:42:39 +04:00
|
|
|
|
2022-07-11 16:32:40 +03:00
|
|
|
gfx::IntSize GetVideoIntrinsicDimensions();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WakeLock> mScreenWakeLock;
|
2013-11-19 23:21:29 +04:00
|
|
|
|
2017-08-25 09:23:03 +03:00
|
|
|
bool mIsOrientationLocked;
|
|
|
|
|
2020-08-26 17:25:40 +03:00
|
|
|
WatchManager<HTMLVideoElement> mVideoWatchManager;
|
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
private:
|
2019-11-22 15:52:48 +03:00
|
|
|
bool SetVisualCloneTarget(
|
|
|
|
RefPtr<HTMLVideoElement> aVisualCloneTarget,
|
|
|
|
RefPtr<Promise> aVisualCloneTargetPromise = nullptr);
|
|
|
|
bool SetVisualCloneSource(RefPtr<HTMLVideoElement> aVisualCloneSource);
|
2019-03-02 01:36:17 +03:00
|
|
|
|
|
|
|
// For video elements, we can clone the frames being played to
|
|
|
|
// a secondary video element. If we're doing that, we hold a
|
|
|
|
// reference to the video element we're cloning to in
|
|
|
|
// mVisualCloneSource.
|
|
|
|
//
|
|
|
|
// Please don't set this to non-nullptr values directly - use
|
|
|
|
// SetVisualCloneTarget() instead.
|
|
|
|
RefPtr<HTMLVideoElement> mVisualCloneTarget;
|
2019-11-22 15:52:48 +03:00
|
|
|
// Set when mVisualCloneTarget is set, and resolved (and unset) when the
|
|
|
|
// secondary container has been applied to the underlying resource.
|
|
|
|
RefPtr<Promise> mVisualCloneTargetPromise;
|
2020-08-26 17:25:40 +03:00
|
|
|
// Set when beginning to clone visually and we are playing a MediaStream.
|
|
|
|
// This is the output wrapping the VideoFrameContainer of mVisualCloneTarget,
|
|
|
|
// so we can render its first frame, and resolve mVisualCloneTargetPromise as
|
|
|
|
// we do.
|
|
|
|
RefPtr<FirstFrameVideoOutput> mSecondaryVideoOutput;
|
2019-03-02 01:36:17 +03:00
|
|
|
// If this video is the clone target of another video element,
|
|
|
|
// then mVisualCloneSource points to that originating video
|
|
|
|
// element.
|
|
|
|
//
|
|
|
|
// Please don't set this to non-nullptr values directly - use
|
|
|
|
// SetVisualCloneTarget() instead.
|
|
|
|
RefPtr<HTMLVideoElement> mVisualCloneSource;
|
|
|
|
|
2023-06-22 20:22:03 +03:00
|
|
|
static void MapAttributesIntoRule(MappedDeclarationsBuilder&);
|
2017-06-19 09:43:26 +03:00
|
|
|
|
|
|
|
static bool IsVideoStatsEnabled();
|
2017-07-17 10:13:55 +03:00
|
|
|
double TotalPlayTime() const;
|
2019-03-02 01:36:40 +03:00
|
|
|
|
|
|
|
virtual void MaybeBeginCloningVisually() override;
|
|
|
|
void EndCloningVisually();
|
2008-07-09 12:22:20 +04:00
|
|
|
};
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLVideoElement_h
|