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