Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_HTMLVideoElement_h
8 : #define mozilla_dom_HTMLVideoElement_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/dom/HTMLMediaElement.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 : class WakeLock;
17 : class VideoPlaybackQuality;
18 :
19 : class HTMLVideoElement final : public HTMLMediaElement
20 : {
21 : public:
22 : typedef mozilla::dom::NodeInfo NodeInfo;
23 :
24 : explicit HTMLVideoElement(already_AddRefed<NodeInfo>& aNodeInfo);
25 :
26 0 : NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLVideoElement, video)
27 :
28 : using HTMLMediaElement::GetPaused;
29 :
30 0 : NS_IMETHOD_(bool) IsVideo() override {
31 0 : return true;
32 : }
33 :
34 : virtual bool ParseAttribute(int32_t aNamespaceID,
35 : nsIAtom* aAttribute,
36 : const nsAString& aValue,
37 : nsAttrValue& aResult) override;
38 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
39 :
40 : static void Init();
41 :
42 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
43 :
44 : virtual nsresult Clone(NodeInfo *aNodeInfo, nsINode **aResult,
45 : bool aPreallocateChildren) const override;
46 :
47 : // Set size with the current video frame's height and width.
48 : // If there is no video frame, returns NS_ERROR_FAILURE.
49 : nsresult GetVideoSize(nsIntSize* size);
50 :
51 : virtual nsresult SetAcceptHeader(nsIHttpChannel* aChannel) override;
52 :
53 : // Element
54 : virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
55 :
56 : // WebIDL
57 :
58 0 : uint32_t Width() const
59 : {
60 0 : return GetIntAttr(nsGkAtoms::width, 0);
61 : }
62 :
63 0 : void SetWidth(uint32_t aValue, ErrorResult& aRv)
64 : {
65 0 : SetUnsignedIntAttr(nsGkAtoms::width, aValue, 0, aRv);
66 0 : }
67 :
68 0 : uint32_t Height() const
69 : {
70 0 : return GetIntAttr(nsGkAtoms::height, 0);
71 : }
72 :
73 0 : void SetHeight(uint32_t aValue, ErrorResult& aRv)
74 : {
75 0 : SetUnsignedIntAttr(nsGkAtoms::height, aValue, 0, aRv);
76 0 : }
77 :
78 0 : uint32_t VideoWidth() const
79 : {
80 0 : if (mMediaInfo.HasVideo()) {
81 0 : if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
82 0 : mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
83 0 : return mMediaInfo.mVideo.mDisplay.height;
84 : }
85 0 : return mMediaInfo.mVideo.mDisplay.width;
86 : }
87 0 : return 0;
88 : }
89 :
90 0 : uint32_t VideoHeight() const
91 : {
92 0 : if (mMediaInfo.HasVideo()) {
93 0 : if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
94 0 : mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
95 0 : return mMediaInfo.mVideo.mDisplay.width;
96 : }
97 0 : return mMediaInfo.mVideo.mDisplay.height;
98 : }
99 0 : return 0;
100 : }
101 :
102 0 : VideoInfo::Rotation RotationDegrees() const
103 : {
104 0 : return mMediaInfo.mVideo.mRotation;
105 : }
106 :
107 0 : void GetPoster(nsAString& aValue)
108 : {
109 0 : GetURIAttr(nsGkAtoms::poster, nullptr, aValue);
110 0 : }
111 0 : void SetPoster(const nsAString& aValue, ErrorResult& aRv)
112 : {
113 0 : SetHTMLAttr(nsGkAtoms::poster, aValue, aRv);
114 0 : }
115 :
116 : uint32_t MozParsedFrames() const;
117 :
118 : uint32_t MozDecodedFrames() const;
119 :
120 : uint32_t MozPresentedFrames() const;
121 :
122 : uint32_t MozPaintedFrames();
123 :
124 : double MozFrameDelay();
125 :
126 : bool MozHasAudio() const;
127 :
128 : bool MozUseScreenWakeLock() const;
129 :
130 : void SetMozUseScreenWakeLock(bool aValue);
131 :
132 : void NotifyOwnerDocumentActivityChanged() override;
133 :
134 : // Gives access to the decoder's frame statistics, if present.
135 : FrameStatistics* GetFrameStatistics();
136 :
137 : already_AddRefed<VideoPlaybackQuality> GetVideoPlaybackQuality();
138 :
139 : protected:
140 : virtual ~HTMLVideoElement();
141 :
142 : virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
143 :
144 : virtual void WakeLockCreate() override;
145 : virtual void WakeLockRelease() override;
146 : void UpdateScreenWakeLock();
147 :
148 : bool mUseScreenWakeLock;
149 : RefPtr<WakeLock> mScreenWakeLock;
150 :
151 : private:
152 : static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
153 : GenericSpecifiedValues* aGenericData);
154 : };
155 :
156 : } // namespace dom
157 : } // namespace mozilla
158 :
159 : #endif // mozilla_dom_HTMLVideoElement_h
|