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