Bug 1494333 - index crons just like artifacts r=Callek
[gecko.git] / dom / html / HTMLVideoElement.h
blobd82dc2e8a5c112559e8050fc5f3c636cd6580abd
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/dom/HTMLMediaElement.h"
12 #include "mozilla/StaticPrefs.h"
14 namespace mozilla {
16 class FrameStatistics;
18 namespace dom {
20 class WakeLock;
21 class VideoPlaybackQuality;
23 class HTMLVideoElement final : public HTMLMediaElement
25 public:
26 typedef mozilla::dom::NodeInfo NodeInfo;
28 explicit HTMLVideoElement(already_AddRefed<NodeInfo>&& aNodeInfo);
30 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLVideoElement, video)
32 using HTMLMediaElement::GetPaused;
34 virtual bool IsVideo() const override {
35 return true;
38 virtual bool ParseAttribute(int32_t aNamespaceID,
39 nsAtom* aAttribute,
40 const nsAString& aValue,
41 nsIPrincipal* aMaybeScriptedPrincipal,
42 nsAttrValue& aResult) override;
43 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
45 static void Init();
47 virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
49 virtual nsresult Clone(NodeInfo*, nsINode** aResult) const override;
51 // Set size with the current video frame's height and width.
52 // If there is no video frame, returns NS_ERROR_FAILURE.
53 nsresult GetVideoSize(nsIntSize* size);
55 virtual nsresult SetAcceptHeader(nsIHttpChannel* aChannel) override;
57 // Element
58 virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
60 // WebIDL
62 uint32_t Width() const
64 return GetIntAttr(nsGkAtoms::width, 0);
67 void SetWidth(uint32_t aValue, ErrorResult& aRv)
69 SetUnsignedIntAttr(nsGkAtoms::width, aValue, 0, aRv);
72 uint32_t Height() const
74 return GetIntAttr(nsGkAtoms::height, 0);
77 void SetHeight(uint32_t aValue, ErrorResult& aRv)
79 SetUnsignedIntAttr(nsGkAtoms::height, aValue, 0, aRv);
82 uint32_t VideoWidth() const
84 if (mMediaInfo.HasVideo()) {
85 if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
86 mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
87 return mMediaInfo.mVideo.mDisplay.height;
89 return mMediaInfo.mVideo.mDisplay.width;
91 return 0;
94 uint32_t VideoHeight() const
96 if (mMediaInfo.HasVideo()) {
97 if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
98 mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
99 return mMediaInfo.mVideo.mDisplay.width;
101 return mMediaInfo.mVideo.mDisplay.height;
103 return 0;
106 VideoInfo::Rotation RotationDegrees() const
108 return mMediaInfo.mVideo.mRotation;
111 void GetPoster(nsAString& aValue)
113 GetURIAttr(nsGkAtoms::poster, nullptr, aValue);
115 void SetPoster(const nsAString& aValue, ErrorResult& aRv)
117 SetHTMLAttr(nsGkAtoms::poster, aValue, aRv);
120 uint32_t MozParsedFrames() const;
122 uint32_t MozDecodedFrames() const;
124 uint32_t MozPresentedFrames() const;
126 uint32_t MozPaintedFrames();
128 double MozFrameDelay();
130 bool MozHasAudio() const;
132 // Gives access to the decoder's frame statistics, if present.
133 FrameStatistics* GetFrameStatistics();
135 already_AddRefed<VideoPlaybackQuality> GetVideoPlaybackQuality();
138 bool MozOrientationLockEnabled() const
140 return StaticPrefs::MediaVideocontrolsLockVideoOrientation();
143 bool MozIsOrientationLocked() const
145 return mIsOrientationLocked;
148 void SetMozIsOrientationLocked(bool aLock)
150 mIsOrientationLocked = aLock;
153 protected:
154 virtual ~HTMLVideoElement();
156 virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
159 * We create video wakelock when the video is playing and release it when
160 * video pauses. Note, the actual platform wakelock will automatically be
161 * released when the page is in the background, so we don't need to check the
162 * video's visibility by ourselves.
164 void WakeLockRelease() override;
165 void UpdateWakeLock() override;
167 bool ShouldCreateVideoWakeLock() const;
168 void CreateVideoWakeLockIfNeeded();
169 void ReleaseVideoWakeLockIfExists();
171 RefPtr<WakeLock> mScreenWakeLock;
173 bool mIsOrientationLocked;
175 private:
176 static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
177 MappedDeclarations&);
179 static bool IsVideoStatsEnabled();
180 double TotalPlayTime() const;
183 } // namespace dom
184 } // namespace mozilla
186 #endif // mozilla_dom_HTMLVideoElement_h