2013-05-21 09:14:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 et tw=78: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_TextTrackCue_h
|
|
|
|
#define mozilla_dom_TextTrackCue_h
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-05-21 09:14:00 -07:00
|
|
|
#include "mozilla/dom/DocumentFragment.h"
|
2013-08-27 13:07:00 -07:00
|
|
|
#include "mozilla/dom/VTTCueBinding.h"
|
2013-05-21 09:14:00 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-09-19 08:26:00 -07:00
|
|
|
#include "nsIWebVTTParserWrapper.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-10-02 04:40:07 -07:00
|
|
|
#include "nsIDocument.h"
|
2013-12-12 08:27:30 -08:00
|
|
|
#include "mozilla/dom/HTMLDivElement.h"
|
2014-01-15 08:04:00 -08:00
|
|
|
#include "mozilla/dom/UnionTypes.h"
|
2014-04-02 09:16:00 -07:00
|
|
|
#include "mozilla/dom/TextTrack.h"
|
2013-07-09 17:02:00 -07:00
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class HTMLTrackElement;
|
2014-03-11 10:33:58 -07:00
|
|
|
class TextTrackRegion;
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
class TextTrackCue MOZ_FINAL : public DOMEventTargetHelper
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrackCue, DOMEventTargetHelper)
|
2013-05-21 09:14:00 -07:00
|
|
|
|
|
|
|
// TextTrackCue WebIDL
|
|
|
|
// See bug 868509 about splitting out the WebVTT-specific interfaces.
|
|
|
|
static already_AddRefed<TextTrackCue>
|
|
|
|
Constructor(GlobalObject& aGlobal,
|
|
|
|
double aStartTime,
|
|
|
|
double aEndTime,
|
|
|
|
const nsAString& aText,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-04-07 10:58:38 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
nsRefPtr<TextTrackCue> ttcue = new TextTrackCue(window, aStartTime,
|
2013-07-16 22:14:40 -07:00
|
|
|
aEndTime, aText, aRv);
|
2013-05-21 09:14:00 -07:00
|
|
|
return ttcue.forget();
|
|
|
|
}
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrackCue(nsPIDOMWindow* aGlobal, double aStartTime, double aEndTime,
|
2013-07-16 22:14:40 -07:00
|
|
|
const nsAString& aText, ErrorResult& aRv);
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrackCue(nsPIDOMWindow* aGlobal, double aStartTime, double aEndTime,
|
2013-05-21 09:14:00 -07:00
|
|
|
const nsAString& aText, HTMLTrackElement* aTrackElement,
|
2013-09-10 06:53:00 -07:00
|
|
|
ErrorResult& aRv);
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2014-06-12 08:31:18 -07:00
|
|
|
~TextTrackCue();
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-05-21 09:14:00 -07:00
|
|
|
|
|
|
|
TextTrack* GetTrack() const
|
|
|
|
{
|
|
|
|
return mTrack;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetId(nsAString& aId) const
|
|
|
|
{
|
|
|
|
aId = mId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetId(const nsAString& aId)
|
|
|
|
{
|
|
|
|
if (mId == aId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mId = aId;
|
|
|
|
}
|
|
|
|
|
|
|
|
double StartTime() const
|
|
|
|
{
|
|
|
|
return mStartTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetStartTime(double aStartTime)
|
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mStartTime == aStartTime) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
|
|
|
mStartTime = aStartTime;
|
2014-01-29 09:57:43 -08:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
double EndTime() const
|
|
|
|
{
|
|
|
|
return mEndTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetEndTime(double aEndTime)
|
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mEndTime == aEndTime) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
|
|
|
mEndTime = aEndTime;
|
2014-01-29 09:57:43 -08:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PauseOnExit()
|
|
|
|
{
|
|
|
|
return mPauseOnExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPauseOnExit(bool aPauseOnExit)
|
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mPauseOnExit == aPauseOnExit) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
|
|
|
mPauseOnExit = aPauseOnExit;
|
|
|
|
}
|
|
|
|
|
2014-03-11 10:33:58 -07:00
|
|
|
TextTrackRegion* GetRegion();
|
|
|
|
void SetRegion(TextTrackRegion* aRegion);
|
2013-09-18 10:29:20 -07:00
|
|
|
|
2013-09-12 07:07:14 -07:00
|
|
|
DirectionSetting Vertical() const
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2013-09-12 07:07:14 -07:00
|
|
|
return mVertical;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-12 07:07:14 -07:00
|
|
|
void SetVertical(const DirectionSetting& aVertical)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mVertical == aVertical) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
mVertical = aVertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapToLines()
|
|
|
|
{
|
|
|
|
return mSnapToLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSnapToLines(bool aSnapToLines)
|
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mSnapToLines == aSnapToLines) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
mSnapToLines = aSnapToLines;
|
|
|
|
}
|
|
|
|
|
2014-01-15 08:04:00 -08:00
|
|
|
void GetLine(OwningLongOrAutoKeyword& aLine) const
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2014-01-15 08:04:00 -08:00
|
|
|
if (mLineIsAutoKeyword) {
|
|
|
|
aLine.SetAsAutoKeyword() = AutoKeyword::Auto;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aLine.SetAsLong() = mLineLong;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-01-15 08:04:00 -08:00
|
|
|
void SetLine(const LongOrAutoKeyword& aLine)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2014-01-15 08:04:00 -08:00
|
|
|
if (aLine.IsLong() &&
|
|
|
|
(mLineIsAutoKeyword || (aLine.GetAsLong() != mLineLong))) {
|
|
|
|
mLineIsAutoKeyword = false;
|
|
|
|
mLineLong = aLine.GetAsLong();
|
|
|
|
mReset = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aLine.IsAutoKeyword() && !mLineIsAutoKeyword) {
|
|
|
|
mLineIsAutoKeyword = true;
|
|
|
|
mReset = true;
|
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-13 06:29:15 -08:00
|
|
|
AlignSetting LineAlign() const
|
|
|
|
{
|
|
|
|
return mLineAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetLineAlign(AlignSetting& aLineAlign, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (mLineAlign == aLineAlign)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aLineAlign == AlignSetting::Left ||
|
|
|
|
aLineAlign == AlignSetting::Right) {
|
|
|
|
return aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
mReset = true;
|
|
|
|
mLineAlign = aLineAlign;
|
|
|
|
}
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
int32_t Position() const
|
|
|
|
{
|
|
|
|
return mPosition;
|
|
|
|
}
|
|
|
|
|
2013-07-24 11:18:54 -07:00
|
|
|
void SetPosition(int32_t aPosition, ErrorResult& aRv)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mPosition == aPosition) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-07-24 11:18:54 -07:00
|
|
|
if (aPosition > 100 || aPosition < 0){
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
mPosition = aPosition;
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:57:48 -08:00
|
|
|
AlignSetting PositionAlign() const
|
|
|
|
{
|
|
|
|
return mPositionAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPositionAlign(AlignSetting aPositionAlign, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (mPositionAlign == aPositionAlign)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aPositionAlign == AlignSetting::Left ||
|
|
|
|
aPositionAlign == AlignSetting::Right) {
|
|
|
|
return aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
mReset = true;
|
|
|
|
mPositionAlign = aPositionAlign;
|
|
|
|
}
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
int32_t Size() const
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2013-07-24 11:18:54 -07:00
|
|
|
void SetSize(int32_t aSize, ErrorResult& aRv)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
|
|
|
if (mSize == aSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSize < 0 || aSize > 100) {
|
2013-07-24 11:18:54 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
mSize = aSize;
|
|
|
|
}
|
|
|
|
|
2013-12-13 06:44:50 -08:00
|
|
|
AlignSetting Align() const
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
|
|
|
return mAlign;
|
|
|
|
}
|
|
|
|
|
2013-12-13 06:44:50 -08:00
|
|
|
void SetAlign(AlignSetting& aAlign)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mAlign == aAlign) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
mAlign = aAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetText(nsAString& aText) const
|
|
|
|
{
|
|
|
|
aText = mText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetText(const nsAString& aText)
|
|
|
|
{
|
2013-12-16 11:49:22 -08:00
|
|
|
if (mText == aText) {
|
2013-05-21 09:14:00 -07:00
|
|
|
return;
|
2013-12-16 11:49:22 -08:00
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
mReset = true;
|
2013-05-21 09:14:00 -07:00
|
|
|
mText = aText;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(enter)
|
|
|
|
IMPL_EVENT_HANDLER(exit)
|
|
|
|
|
2013-12-12 08:27:30 -08:00
|
|
|
HTMLDivElement* GetDisplayState()
|
|
|
|
{
|
|
|
|
return static_cast<HTMLDivElement*>(mDisplayState.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDisplayState(HTMLDivElement* aDisplayState)
|
|
|
|
{
|
|
|
|
mDisplayState = aDisplayState;
|
2014-02-03 12:27:51 -08:00
|
|
|
mReset = false;
|
2013-12-12 08:27:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-07 12:42:33 -07:00
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mReset = true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 10:13:38 -08:00
|
|
|
bool HasBeenReset()
|
|
|
|
{
|
|
|
|
return mReset;
|
|
|
|
}
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
// Helper functions for implementation.
|
|
|
|
bool
|
|
|
|
operator==(const TextTrackCue& rhs) const
|
|
|
|
{
|
|
|
|
return mId.Equals(rhs.mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& Id() const
|
|
|
|
{
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2014-04-02 09:16:00 -07:00
|
|
|
void SetTrack(TextTrack* aTextTrack)
|
|
|
|
{
|
|
|
|
mTrack = aTextTrack;
|
|
|
|
}
|
|
|
|
|
2013-06-10 08:30:00 -07:00
|
|
|
/**
|
|
|
|
* Produces a tree of anonymous content based on the tree of the processed
|
2013-09-10 06:53:00 -07:00
|
|
|
* cue text.
|
2013-06-10 08:30:00 -07:00
|
|
|
*
|
|
|
|
* Returns a DocumentFragment that is the head of the tree of anonymous
|
|
|
|
* content.
|
|
|
|
*/
|
|
|
|
already_AddRefed<DocumentFragment> GetCueAsHTML();
|
|
|
|
|
2013-09-19 08:26:00 -07:00
|
|
|
void SetTrackElement(HTMLTrackElement* aTrackElement);
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
private:
|
|
|
|
void SetDefaultCueSettings();
|
2014-04-07 10:58:38 -07:00
|
|
|
nsresult StashDocument();
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-07-16 22:14:40 -07:00
|
|
|
nsRefPtr<nsIDocument> mDocument;
|
2013-05-21 09:14:00 -07:00
|
|
|
nsString mText;
|
|
|
|
double mStartTime;
|
|
|
|
double mEndTime;
|
|
|
|
|
|
|
|
nsRefPtr<TextTrack> mTrack;
|
|
|
|
nsRefPtr<HTMLTrackElement> mTrackElement;
|
|
|
|
nsString mId;
|
|
|
|
int32_t mPosition;
|
2013-12-13 09:57:48 -08:00
|
|
|
AlignSetting mPositionAlign;
|
2013-05-21 09:14:00 -07:00
|
|
|
int32_t mSize;
|
|
|
|
bool mPauseOnExit;
|
|
|
|
bool mSnapToLines;
|
2014-03-11 10:33:58 -07:00
|
|
|
nsRefPtr<TextTrackRegion> mRegion;
|
2013-09-12 07:07:14 -07:00
|
|
|
DirectionSetting mVertical;
|
2014-01-15 08:04:00 -08:00
|
|
|
bool mLineIsAutoKeyword;
|
|
|
|
long mLineLong;
|
2013-12-13 06:44:50 -08:00
|
|
|
AlignSetting mAlign;
|
2013-12-13 06:29:15 -08:00
|
|
|
AlignSetting mLineAlign;
|
2013-06-10 08:30:00 -07:00
|
|
|
|
2013-07-04 14:24:43 -07:00
|
|
|
// Holds the computed DOM elements that represent the parsed cue text.
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/#text-track-cue-display-state
|
2013-12-12 08:27:30 -08:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mDisplayState;
|
2013-07-04 14:24:43 -07:00
|
|
|
// Tells whether or not we need to recompute mDisplayState. This is set
|
|
|
|
// anytime a property that relates to the display of the TextTrackCue is
|
|
|
|
// changed.
|
|
|
|
bool mReset;
|
2013-09-19 08:26:00 -07:00
|
|
|
|
|
|
|
static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
|
2013-05-21 09:14:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_TextTrackCue_h
|