/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/HTMLTrackElement.h" #include "mozilla/dom/TextTrackCue.h" #include "mozilla/dom/TextTrackCueBinding.h" #include "webvtt/cue.h" namespace mozilla { namespace dom { NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(TextTrackCue, mGlobal, mTrack, mTrackElement) NS_IMPL_ADDREF_INHERITED(TextTrackCue, nsDOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(TextTrackCue, nsDOMEventTargetHelper) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrackCue) NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) // Set cue setting defaults based on step 19 & seq. // in http://dev.w3.org/html5/webvtt/#parsing void TextTrackCue::SetDefaultCueSettings() { mPosition = 50; mSize = 100; mPauseOnExit = false; mSnapToLines = true; mLine = WEBVTT_AUTO; mAlign = TextTrackCueAlign::Middle; } TextTrackCue::TextTrackCue(nsISupports* aGlobal, double aStartTime, double aEndTime, const nsAString& aText) : mGlobal(aGlobal) , mText(aText) , mStartTime(aStartTime) , mEndTime(aEndTime) , mHead(nullptr) { SetDefaultCueSettings(); MOZ_ASSERT(aGlobal); SetIsDOMBinding(); } TextTrackCue::TextTrackCue(nsISupports* aGlobal, double aStartTime, double aEndTime, const nsAString& aText, HTMLTrackElement* aTrackElement, webvtt_node* head) : mGlobal(aGlobal) , mText(aText) , mStartTime(aStartTime) , mEndTime(aEndTime) , mTrackElement(aTrackElement) , mHead(head) { // Use the webvtt library's reference counting. webvtt_ref_node(mHead); SetDefaultCueSettings(); MOZ_ASSERT(aGlobal); SetIsDOMBinding(); } TextTrackCue::~TextTrackCue() { if (mHead) { // Release our reference and null mHead. webvtt_release_node(&mHead); } } void TextTrackCue::DisplayCue() { if (mTrackElement) { mTrackElement->DisplayCueText(mHead); } } JSObject* TextTrackCue::WrapObject(JSContext* aCx, JS::Handle aScope) { return TextTrackCueBinding::Wrap(aCx, aScope, this); } void TextTrackCue::CueChanged() { if (mTrack) { mTrack->CueChanged(*this); } } } // namespace dom } // namespace mozilla