content/media/TextTrackRegion.h

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

mercurial