1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 et tw=78: */ 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_TextTrackRegion_h 8 #define mozilla_dom_TextTrackRegion_h 9 10 #include "nsCycleCollectionParticipant.h" 11 #include "nsString.h" 12 #include "nsWrapperCache.h" 13 #include "mozilla/ErrorResult.h" 14 #include "mozilla/dom/TextTrack.h" 15 #include "mozilla/Preferences.h" 16 17 namespace mozilla { 18 namespace dom { 19 20 class GlobalObject; 21 class TextTrack; 22 23 class TextTrackRegion final : public nsISupports, 24 public nsWrapperCache 25 { 26 public: 27 28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 29 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackRegion) 30 31 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; 32 GetParentObject()33 nsISupports* GetParentObject() const 34 { 35 return mParent; 36 } 37 38 explicit TextTrackRegion(nsISupports* aGlobal); 39 40 /** WebIDL Methods. */ 41 42 static already_AddRefed<TextTrackRegion> 43 Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); 44 Lines()45 double Lines() const 46 { 47 return mLines; 48 } 49 SetLines(double aLines)50 void SetLines(double aLines) 51 { 52 mLines = aLines; 53 } 54 Width()55 double Width() const 56 { 57 return mWidth; 58 } 59 SetWidth(double aWidth,ErrorResult & aRv)60 void SetWidth(double aWidth, ErrorResult& aRv) 61 { 62 if (!InvalidValue(aWidth, aRv)) { 63 mWidth = aWidth; 64 } 65 } 66 RegionAnchorX()67 double RegionAnchorX() const 68 { 69 return mRegionAnchorX; 70 } 71 SetRegionAnchorX(double aVal,ErrorResult & aRv)72 void SetRegionAnchorX(double aVal, ErrorResult& aRv) 73 { 74 if (!InvalidValue(aVal, aRv)) { 75 mRegionAnchorX = aVal; 76 } 77 } 78 RegionAnchorY()79 double RegionAnchorY() const 80 { 81 return mRegionAnchorY; 82 } 83 SetRegionAnchorY(double aVal,ErrorResult & aRv)84 void SetRegionAnchorY(double aVal, ErrorResult& aRv) 85 { 86 if (!InvalidValue(aVal, aRv)) { 87 mRegionAnchorY = aVal; 88 } 89 } 90 ViewportAnchorX()91 double ViewportAnchorX() const 92 { 93 return mViewportAnchorX; 94 } 95 SetViewportAnchorX(double aVal,ErrorResult & aRv)96 void SetViewportAnchorX(double aVal, ErrorResult& aRv) 97 { 98 if (!InvalidValue(aVal, aRv)) { 99 mViewportAnchorX = aVal; 100 } 101 } 102 ViewportAnchorY()103 double ViewportAnchorY() const 104 { 105 return mViewportAnchorY; 106 } 107 SetViewportAnchorY(double aVal,ErrorResult & aRv)108 void SetViewportAnchorY(double aVal, ErrorResult& aRv) 109 { 110 if (!InvalidValue(aVal, aRv)) { 111 mViewportAnchorY = aVal; 112 } 113 } 114 GetScroll(nsAString & aScroll)115 void GetScroll(nsAString& aScroll) const 116 { 117 aScroll = mScroll; 118 } 119 SetScroll(const nsAString & aScroll,ErrorResult & aRv)120 void SetScroll(const nsAString& aScroll, ErrorResult& aRv) 121 { 122 if (!aScroll.EqualsLiteral("") && !aScroll.EqualsLiteral("up")) { 123 aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); 124 return; 125 } 126 127 mScroll = aScroll; 128 } 129 130 /** end WebIDL Methods. */ 131 132 133 // Helper to aid copying of a given TextTrackRegion's width, lines, 134 // anchor, viewport and scroll values. 135 void CopyValues(TextTrackRegion& aRegion); 136 137 // -----helpers------- Scroll()138 const nsAString& Scroll() const 139 { 140 return mScroll; 141 } 142 143 private: ~TextTrackRegion()144 ~TextTrackRegion() {} 145 146 nsCOMPtr<nsISupports> mParent; 147 double mWidth; 148 long mLines; 149 double mRegionAnchorX; 150 double mRegionAnchorY; 151 double mViewportAnchorX; 152 double mViewportAnchorY; 153 nsString mScroll; 154 155 // Helper to ensure new value is in the range: 0.0% - 100.0%; throws 156 // an IndexSizeError otherwise. InvalidValue(double aValue,ErrorResult & aRv)157 inline bool InvalidValue(double aValue, ErrorResult& aRv) 158 { 159 if(aValue < 0.0 || aValue > 100.0) { 160 aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); 161 return true; 162 } 163 164 return false; 165 } 166 167 }; 168 169 } //namespace dom 170 } //namespace mozilla 171 172 #endif //mozilla_dom_TextTrackRegion_h 173