content/media/TextTrackCue.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 et tw=78: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_TextTrackCue_h
michael@0 8 #define mozilla_dom_TextTrackCue_h
michael@0 9
michael@0 10 #include "mozilla/DOMEventTargetHelper.h"
michael@0 11 #include "mozilla/dom/DocumentFragment.h"
michael@0 12 #include "mozilla/dom/VTTCueBinding.h"
michael@0 13 #include "nsCycleCollectionParticipant.h"
michael@0 14 #include "nsIWebVTTParserWrapper.h"
michael@0 15 #include "mozilla/StaticPtr.h"
michael@0 16 #include "nsIDocument.h"
michael@0 17 #include "mozilla/dom/HTMLDivElement.h"
michael@0 18 #include "mozilla/dom/UnionTypes.h"
michael@0 19 #include "mozilla/dom/TextTrack.h"
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22 namespace dom {
michael@0 23
michael@0 24 class HTMLTrackElement;
michael@0 25 class TextTrackRegion;
michael@0 26
michael@0 27 class TextTrackCue MOZ_FINAL : public DOMEventTargetHelper
michael@0 28 {
michael@0 29 public:
michael@0 30 NS_DECL_ISUPPORTS_INHERITED
michael@0 31 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrackCue, DOMEventTargetHelper)
michael@0 32
michael@0 33 // TextTrackCue WebIDL
michael@0 34 // See bug 868509 about splitting out the WebVTT-specific interfaces.
michael@0 35 static already_AddRefed<TextTrackCue>
michael@0 36 Constructor(GlobalObject& aGlobal,
michael@0 37 double aStartTime,
michael@0 38 double aEndTime,
michael@0 39 const nsAString& aText,
michael@0 40 ErrorResult& aRv)
michael@0 41 {
michael@0 42 nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
michael@0 43 nsRefPtr<TextTrackCue> ttcue = new TextTrackCue(window, aStartTime,
michael@0 44 aEndTime, aText, aRv);
michael@0 45 return ttcue.forget();
michael@0 46 }
michael@0 47 TextTrackCue(nsPIDOMWindow* aGlobal, double aStartTime, double aEndTime,
michael@0 48 const nsAString& aText, ErrorResult& aRv);
michael@0 49
michael@0 50 TextTrackCue(nsPIDOMWindow* aGlobal, double aStartTime, double aEndTime,
michael@0 51 const nsAString& aText, HTMLTrackElement* aTrackElement,
michael@0 52 ErrorResult& aRv);
michael@0 53
michael@0 54 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 55
michael@0 56 TextTrack* GetTrack() const
michael@0 57 {
michael@0 58 return mTrack;
michael@0 59 }
michael@0 60
michael@0 61 void GetId(nsAString& aId) const
michael@0 62 {
michael@0 63 aId = mId;
michael@0 64 }
michael@0 65
michael@0 66 void SetId(const nsAString& aId)
michael@0 67 {
michael@0 68 if (mId == aId) {
michael@0 69 return;
michael@0 70 }
michael@0 71
michael@0 72 mId = aId;
michael@0 73 }
michael@0 74
michael@0 75 double StartTime() const
michael@0 76 {
michael@0 77 return mStartTime;
michael@0 78 }
michael@0 79
michael@0 80 void SetStartTime(double aStartTime)
michael@0 81 {
michael@0 82 if (mStartTime == aStartTime) {
michael@0 83 return;
michael@0 84 }
michael@0 85
michael@0 86 mStartTime = aStartTime;
michael@0 87 mReset = true;
michael@0 88 }
michael@0 89
michael@0 90 double EndTime() const
michael@0 91 {
michael@0 92 return mEndTime;
michael@0 93 }
michael@0 94
michael@0 95 void SetEndTime(double aEndTime)
michael@0 96 {
michael@0 97 if (mEndTime == aEndTime) {
michael@0 98 return;
michael@0 99 }
michael@0 100
michael@0 101 mEndTime = aEndTime;
michael@0 102 mReset = true;
michael@0 103 }
michael@0 104
michael@0 105 bool PauseOnExit()
michael@0 106 {
michael@0 107 return mPauseOnExit;
michael@0 108 }
michael@0 109
michael@0 110 void SetPauseOnExit(bool aPauseOnExit)
michael@0 111 {
michael@0 112 if (mPauseOnExit == aPauseOnExit) {
michael@0 113 return;
michael@0 114 }
michael@0 115
michael@0 116 mPauseOnExit = aPauseOnExit;
michael@0 117 }
michael@0 118
michael@0 119 TextTrackRegion* GetRegion();
michael@0 120 void SetRegion(TextTrackRegion* aRegion);
michael@0 121
michael@0 122 DirectionSetting Vertical() const
michael@0 123 {
michael@0 124 return mVertical;
michael@0 125 }
michael@0 126
michael@0 127 void SetVertical(const DirectionSetting& aVertical)
michael@0 128 {
michael@0 129 if (mVertical == aVertical) {
michael@0 130 return;
michael@0 131 }
michael@0 132
michael@0 133 mReset = true;
michael@0 134 mVertical = aVertical;
michael@0 135 }
michael@0 136
michael@0 137 bool SnapToLines()
michael@0 138 {
michael@0 139 return mSnapToLines;
michael@0 140 }
michael@0 141
michael@0 142 void SetSnapToLines(bool aSnapToLines)
michael@0 143 {
michael@0 144 if (mSnapToLines == aSnapToLines) {
michael@0 145 return;
michael@0 146 }
michael@0 147
michael@0 148 mReset = true;
michael@0 149 mSnapToLines = aSnapToLines;
michael@0 150 }
michael@0 151
michael@0 152 void GetLine(OwningLongOrAutoKeyword& aLine) const
michael@0 153 {
michael@0 154 if (mLineIsAutoKeyword) {
michael@0 155 aLine.SetAsAutoKeyword() = AutoKeyword::Auto;
michael@0 156 return;
michael@0 157 }
michael@0 158 aLine.SetAsLong() = mLineLong;
michael@0 159 }
michael@0 160
michael@0 161 void SetLine(const LongOrAutoKeyword& aLine)
michael@0 162 {
michael@0 163 if (aLine.IsLong() &&
michael@0 164 (mLineIsAutoKeyword || (aLine.GetAsLong() != mLineLong))) {
michael@0 165 mLineIsAutoKeyword = false;
michael@0 166 mLineLong = aLine.GetAsLong();
michael@0 167 mReset = true;
michael@0 168 return;
michael@0 169 }
michael@0 170 if (aLine.IsAutoKeyword() && !mLineIsAutoKeyword) {
michael@0 171 mLineIsAutoKeyword = true;
michael@0 172 mReset = true;
michael@0 173 }
michael@0 174 }
michael@0 175
michael@0 176 AlignSetting LineAlign() const
michael@0 177 {
michael@0 178 return mLineAlign;
michael@0 179 }
michael@0 180
michael@0 181 void SetLineAlign(AlignSetting& aLineAlign, ErrorResult& aRv)
michael@0 182 {
michael@0 183 if (mLineAlign == aLineAlign)
michael@0 184 return;
michael@0 185
michael@0 186 if (aLineAlign == AlignSetting::Left ||
michael@0 187 aLineAlign == AlignSetting::Right) {
michael@0 188 return aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
michael@0 189 }
michael@0 190
michael@0 191 mReset = true;
michael@0 192 mLineAlign = aLineAlign;
michael@0 193 }
michael@0 194
michael@0 195 int32_t Position() const
michael@0 196 {
michael@0 197 return mPosition;
michael@0 198 }
michael@0 199
michael@0 200 void SetPosition(int32_t aPosition, ErrorResult& aRv)
michael@0 201 {
michael@0 202 if (mPosition == aPosition) {
michael@0 203 return;
michael@0 204 }
michael@0 205
michael@0 206 if (aPosition > 100 || aPosition < 0){
michael@0 207 aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
michael@0 208 return;
michael@0 209 }
michael@0 210
michael@0 211 mReset = true;
michael@0 212 mPosition = aPosition;
michael@0 213 }
michael@0 214
michael@0 215 AlignSetting PositionAlign() const
michael@0 216 {
michael@0 217 return mPositionAlign;
michael@0 218 }
michael@0 219
michael@0 220 void SetPositionAlign(AlignSetting aPositionAlign, ErrorResult& aRv)
michael@0 221 {
michael@0 222 if (mPositionAlign == aPositionAlign)
michael@0 223 return;
michael@0 224
michael@0 225 if (aPositionAlign == AlignSetting::Left ||
michael@0 226 aPositionAlign == AlignSetting::Right) {
michael@0 227 return aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
michael@0 228 }
michael@0 229
michael@0 230 mReset = true;
michael@0 231 mPositionAlign = aPositionAlign;
michael@0 232 }
michael@0 233
michael@0 234 int32_t Size() const
michael@0 235 {
michael@0 236 return mSize;
michael@0 237 }
michael@0 238
michael@0 239 void SetSize(int32_t aSize, ErrorResult& aRv)
michael@0 240 {
michael@0 241 if (mSize == aSize) {
michael@0 242 return;
michael@0 243 }
michael@0 244
michael@0 245 if (aSize < 0 || aSize > 100) {
michael@0 246 aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
michael@0 247 return;
michael@0 248 }
michael@0 249
michael@0 250 mReset = true;
michael@0 251 mSize = aSize;
michael@0 252 }
michael@0 253
michael@0 254 AlignSetting Align() const
michael@0 255 {
michael@0 256 return mAlign;
michael@0 257 }
michael@0 258
michael@0 259 void SetAlign(AlignSetting& aAlign)
michael@0 260 {
michael@0 261 if (mAlign == aAlign) {
michael@0 262 return;
michael@0 263 }
michael@0 264
michael@0 265 mReset = true;
michael@0 266 mAlign = aAlign;
michael@0 267 }
michael@0 268
michael@0 269 void GetText(nsAString& aText) const
michael@0 270 {
michael@0 271 aText = mText;
michael@0 272 }
michael@0 273
michael@0 274 void SetText(const nsAString& aText)
michael@0 275 {
michael@0 276 if (mText == aText) {
michael@0 277 return;
michael@0 278 }
michael@0 279
michael@0 280 mReset = true;
michael@0 281 mText = aText;
michael@0 282 }
michael@0 283
michael@0 284 IMPL_EVENT_HANDLER(enter)
michael@0 285 IMPL_EVENT_HANDLER(exit)
michael@0 286
michael@0 287 HTMLDivElement* GetDisplayState()
michael@0 288 {
michael@0 289 return static_cast<HTMLDivElement*>(mDisplayState.get());
michael@0 290 }
michael@0 291
michael@0 292 void SetDisplayState(HTMLDivElement* aDisplayState)
michael@0 293 {
michael@0 294 mDisplayState = aDisplayState;
michael@0 295 mReset = false;
michael@0 296 }
michael@0 297
michael@0 298 void Reset()
michael@0 299 {
michael@0 300 mReset = true;
michael@0 301 }
michael@0 302
michael@0 303 bool HasBeenReset()
michael@0 304 {
michael@0 305 return mReset;
michael@0 306 }
michael@0 307
michael@0 308 // Helper functions for implementation.
michael@0 309 bool
michael@0 310 operator==(const TextTrackCue& rhs) const
michael@0 311 {
michael@0 312 return mId.Equals(rhs.mId);
michael@0 313 }
michael@0 314
michael@0 315 const nsAString& Id() const
michael@0 316 {
michael@0 317 return mId;
michael@0 318 }
michael@0 319
michael@0 320 void SetTrack(TextTrack* aTextTrack)
michael@0 321 {
michael@0 322 mTrack = aTextTrack;
michael@0 323 }
michael@0 324
michael@0 325 /**
michael@0 326 * Produces a tree of anonymous content based on the tree of the processed
michael@0 327 * cue text.
michael@0 328 *
michael@0 329 * Returns a DocumentFragment that is the head of the tree of anonymous
michael@0 330 * content.
michael@0 331 */
michael@0 332 already_AddRefed<DocumentFragment> GetCueAsHTML();
michael@0 333
michael@0 334 void SetTrackElement(HTMLTrackElement* aTrackElement);
michael@0 335
michael@0 336 private:
michael@0 337 void SetDefaultCueSettings();
michael@0 338 nsresult StashDocument();
michael@0 339
michael@0 340 nsRefPtr<nsIDocument> mDocument;
michael@0 341 nsString mText;
michael@0 342 double mStartTime;
michael@0 343 double mEndTime;
michael@0 344
michael@0 345 nsRefPtr<TextTrack> mTrack;
michael@0 346 nsRefPtr<HTMLTrackElement> mTrackElement;
michael@0 347 nsString mId;
michael@0 348 int32_t mPosition;
michael@0 349 AlignSetting mPositionAlign;
michael@0 350 int32_t mSize;
michael@0 351 bool mPauseOnExit;
michael@0 352 bool mSnapToLines;
michael@0 353 nsRefPtr<TextTrackRegion> mRegion;
michael@0 354 DirectionSetting mVertical;
michael@0 355 bool mLineIsAutoKeyword;
michael@0 356 long mLineLong;
michael@0 357 AlignSetting mAlign;
michael@0 358 AlignSetting mLineAlign;
michael@0 359
michael@0 360 // Holds the computed DOM elements that represent the parsed cue text.
michael@0 361 // http://www.whatwg.org/specs/web-apps/current-work/#text-track-cue-display-state
michael@0 362 nsRefPtr<nsGenericHTMLElement> mDisplayState;
michael@0 363 // Tells whether or not we need to recompute mDisplayState. This is set
michael@0 364 // anytime a property that relates to the display of the TextTrackCue is
michael@0 365 // changed.
michael@0 366 bool mReset;
michael@0 367
michael@0 368 static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
michael@0 369 };
michael@0 370
michael@0 371 } // namespace dom
michael@0 372 } // namespace mozilla
michael@0 373
michael@0 374 #endif // mozilla_dom_TextTrackCue_h

mercurial