2013-05-21 16:14:00 +00: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-04-01 06:13:50 +00:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-05-21 16:14:00 +00:00
|
|
|
#include "mozilla/dom/DocumentFragment.h"
|
2013-08-27 20:07:00 +00:00
|
|
|
#include "mozilla/dom/VTTCueBinding.h"
|
2013-05-21 16:14:00 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-09-19 15:26:00 +00:00
|
|
|
#include "nsIWebVTTParserWrapper.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-10-02 11:40:07 +00:00
|
|
|
#include "nsIDocument.h"
|
2013-12-12 16:27:30 +00:00
|
|
|
#include "mozilla/dom/HTMLDivElement.h"
|
2014-04-02 16:16:00 +00:00
|
|
|
#include "mozilla/dom/TextTrack.h"
|
2013-07-10 00:02:00 +00:00
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class HTMLTrackElement;
|
2014-03-11 17:33:58 +00:00
|
|
|
class TextTrackRegion;
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class TextTrackCue final : public DOMEventTargetHelper
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrackCue, DOMEventTargetHelper)
|
2013-05-21 16:14:00 +00: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 17:58:38 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
nsRefPtr<TextTrackCue> ttcue = new TextTrackCue(window, aStartTime,
|
2013-07-17 05:14:40 +00:00
|
|
|
aEndTime, aText, aRv);
|
2013-05-21 16:14:00 +00:00
|
|
|
return ttcue.forget();
|
|
|
|
}
|
2014-04-07 17:58:38 +00:00
|
|
|
TextTrackCue(nsPIDOMWindow* aGlobal, double aStartTime, double aEndTime,
|
2013-07-17 05:14:40 +00:00
|
|
|
const nsAString& aText, ErrorResult& aRv);
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2014-04-07 17:58:38 +00:00
|
|
|
TextTrackCue(nsPIDOMWindow* aGlobal, double aStartTime, double aEndTime,
|
2013-05-21 16:14:00 +00:00
|
|
|
const nsAString& aText, HTMLTrackElement* aTrackElement,
|
2013-09-10 13:53:00 +00:00
|
|
|
ErrorResult& aRv);
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-05-21 16:14:00 +00: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 19:49:22 +00:00
|
|
|
if (mStartTime == aStartTime) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
mStartTime = aStartTime;
|
2014-01-29 17:57:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double EndTime() const
|
|
|
|
{
|
|
|
|
return mEndTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetEndTime(double aEndTime)
|
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mEndTime == aEndTime) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
mEndTime = aEndTime;
|
2014-01-29 17:57:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PauseOnExit()
|
|
|
|
{
|
|
|
|
return mPauseOnExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPauseOnExit(bool aPauseOnExit)
|
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mPauseOnExit == aPauseOnExit) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
mPauseOnExit = aPauseOnExit;
|
|
|
|
}
|
|
|
|
|
2014-03-11 17:33:58 +00:00
|
|
|
TextTrackRegion* GetRegion();
|
|
|
|
void SetRegion(TextTrackRegion* aRegion);
|
2013-09-18 17:29:20 +00:00
|
|
|
|
2013-09-12 14:07:14 +00:00
|
|
|
DirectionSetting Vertical() const
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2013-09-12 14:07:14 +00:00
|
|
|
return mVertical;
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 14:07:14 +00:00
|
|
|
void SetVertical(const DirectionSetting& aVertical)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mVertical == aVertical) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2013-07-04 21:24:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
mVertical = aVertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SnapToLines()
|
|
|
|
{
|
|
|
|
return mSnapToLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSnapToLines(bool aSnapToLines)
|
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mSnapToLines == aSnapToLines) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2013-07-04 21:24:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
mSnapToLines = aSnapToLines;
|
|
|
|
}
|
|
|
|
|
2014-01-15 16:04:00 +00:00
|
|
|
void GetLine(OwningLongOrAutoKeyword& aLine) const
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2014-01-15 16:04:00 +00:00
|
|
|
if (mLineIsAutoKeyword) {
|
|
|
|
aLine.SetAsAutoKeyword() = AutoKeyword::Auto;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aLine.SetAsLong() = mLineLong;
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 16:04:00 +00:00
|
|
|
void SetLine(const LongOrAutoKeyword& aLine)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2014-01-15 16:04:00 +00: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 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 14:29:15 +00: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 16:14:00 +00:00
|
|
|
int32_t Position() const
|
|
|
|
{
|
|
|
|
return mPosition;
|
|
|
|
}
|
|
|
|
|
2013-07-24 18:18:54 +00:00
|
|
|
void SetPosition(int32_t aPosition, ErrorResult& aRv)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mPosition == aPosition) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2013-07-24 18:18:54 +00:00
|
|
|
if (aPosition > 100 || aPosition < 0){
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-04 21:24:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
mPosition = aPosition;
|
|
|
|
}
|
|
|
|
|
2013-12-13 17:57:48 +00: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 16:14:00 +00:00
|
|
|
int32_t Size() const
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2013-07-24 18:18:54 +00:00
|
|
|
void SetSize(int32_t aSize, ErrorResult& aRv)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
|
|
|
if (mSize == aSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSize < 0 || aSize > 100) {
|
2013-07-24 18:18:54 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 21:24:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
mSize = aSize;
|
|
|
|
}
|
|
|
|
|
2013-12-13 14:44:50 +00:00
|
|
|
AlignSetting Align() const
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
|
|
|
return mAlign;
|
|
|
|
}
|
|
|
|
|
2013-12-13 14:44:50 +00:00
|
|
|
void SetAlign(AlignSetting& aAlign)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mAlign == aAlign) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2013-07-04 21:24:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
mAlign = aAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetText(nsAString& aText) const
|
|
|
|
{
|
|
|
|
aText = mText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetText(const nsAString& aText)
|
|
|
|
{
|
2013-12-16 19:49:22 +00:00
|
|
|
if (mText == aText) {
|
2013-05-21 16:14:00 +00:00
|
|
|
return;
|
2013-12-16 19:49:22 +00:00
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2013-07-04 21:24:43 +00:00
|
|
|
mReset = true;
|
2013-05-21 16:14:00 +00:00
|
|
|
mText = aText;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(enter)
|
|
|
|
IMPL_EVENT_HANDLER(exit)
|
|
|
|
|
2013-12-12 16:27:30 +00:00
|
|
|
HTMLDivElement* GetDisplayState()
|
|
|
|
{
|
|
|
|
return static_cast<HTMLDivElement*>(mDisplayState.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDisplayState(HTMLDivElement* aDisplayState)
|
|
|
|
{
|
|
|
|
mDisplayState = aDisplayState;
|
2014-02-03 20:27:51 +00:00
|
|
|
mReset = false;
|
2013-12-12 16:27:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 19:42:33 +00:00
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mReset = true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 18:13:38 +00:00
|
|
|
bool HasBeenReset()
|
|
|
|
{
|
|
|
|
return mReset;
|
|
|
|
}
|
|
|
|
|
2013-05-21 16:14:00 +00: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 16:16:00 +00:00
|
|
|
void SetTrack(TextTrack* aTextTrack)
|
|
|
|
{
|
|
|
|
mTrack = aTextTrack;
|
|
|
|
}
|
|
|
|
|
2013-06-10 15:30:00 +00:00
|
|
|
/**
|
|
|
|
* Produces a tree of anonymous content based on the tree of the processed
|
2013-09-10 13:53:00 +00:00
|
|
|
* cue text.
|
2013-06-10 15:30:00 +00:00
|
|
|
*
|
|
|
|
* Returns a DocumentFragment that is the head of the tree of anonymous
|
|
|
|
* content.
|
|
|
|
*/
|
|
|
|
already_AddRefed<DocumentFragment> GetCueAsHTML();
|
|
|
|
|
2013-09-19 15:26:00 +00:00
|
|
|
void SetTrackElement(HTMLTrackElement* aTrackElement);
|
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
private:
|
2014-07-08 21:23:16 +00:00
|
|
|
~TextTrackCue();
|
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
void SetDefaultCueSettings();
|
2014-04-07 17:58:38 +00:00
|
|
|
nsresult StashDocument();
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2013-07-17 05:14:40 +00:00
|
|
|
nsRefPtr<nsIDocument> mDocument;
|
2013-05-21 16:14:00 +00:00
|
|
|
nsString mText;
|
|
|
|
double mStartTime;
|
|
|
|
double mEndTime;
|
|
|
|
|
|
|
|
nsRefPtr<TextTrack> mTrack;
|
|
|
|
nsRefPtr<HTMLTrackElement> mTrackElement;
|
|
|
|
nsString mId;
|
|
|
|
int32_t mPosition;
|
2013-12-13 17:57:48 +00:00
|
|
|
AlignSetting mPositionAlign;
|
2013-05-21 16:14:00 +00:00
|
|
|
int32_t mSize;
|
|
|
|
bool mPauseOnExit;
|
|
|
|
bool mSnapToLines;
|
2014-03-11 17:33:58 +00:00
|
|
|
nsRefPtr<TextTrackRegion> mRegion;
|
2013-09-12 14:07:14 +00:00
|
|
|
DirectionSetting mVertical;
|
2014-01-15 16:04:00 +00:00
|
|
|
bool mLineIsAutoKeyword;
|
|
|
|
long mLineLong;
|
2013-12-13 14:44:50 +00:00
|
|
|
AlignSetting mAlign;
|
2013-12-13 14:29:15 +00:00
|
|
|
AlignSetting mLineAlign;
|
2013-06-10 15:30:00 +00:00
|
|
|
|
2013-07-04 21:24:43 +00: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 16:27:30 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mDisplayState;
|
2013-07-04 21:24:43 +00: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 15:26:00 +00:00
|
|
|
|
|
|
|
static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
|
2013-05-21 16:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_TextTrackCue_h
|