2013-05-21 09:14:00 -07:00
|
|
|
/* -*- 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"
|
2014-03-11 10:33:58 -07:00
|
|
|
#include "mozilla/dom/TextTrackRegion.h"
|
2013-09-19 08:26:00 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-09-24 12:17:15 -07:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2013-07-09 17:02:00 -07:00
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrackCue,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mDocument,
|
|
|
|
mTrack,
|
|
|
|
mTrackElement,
|
|
|
|
mDisplayState,
|
|
|
|
mRegion)
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrackCue, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrackCue, DOMEventTargetHelper)
|
2013-05-21 09:14:00 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrackCue)
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2013-09-19 08:26:00 -07:00
|
|
|
StaticRefPtr<nsIWebVTTParserWrapper> TextTrackCue::sParserWrapper;
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
// Set cue setting defaults based on step 19 & seq.
|
|
|
|
// in http://dev.w3.org/html5/webvtt/#parsing
|
|
|
|
void
|
|
|
|
TextTrackCue::SetDefaultCueSettings()
|
|
|
|
{
|
|
|
|
mPosition = 50;
|
2013-12-13 09:57:48 -08:00
|
|
|
mPositionAlign = AlignSetting::Middle;
|
2013-05-21 09:14:00 -07:00
|
|
|
mSize = 100;
|
|
|
|
mPauseOnExit = false;
|
|
|
|
mSnapToLines = true;
|
2014-01-15 08:04:00 -08:00
|
|
|
mLineIsAutoKeyword = true;
|
2013-12-13 06:44:50 -08:00
|
|
|
mAlign = AlignSetting::Middle;
|
2013-12-13 06:29:15 -08:00
|
|
|
mLineAlign = AlignSetting::Start;
|
2013-09-12 07:07:14 -07:00
|
|
|
mVertical = DirectionSetting::_empty;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrackCue::TextTrackCue(nsPIDOMWindow* aOwnerWindow,
|
2013-05-21 09:14:00 -07:00
|
|
|
double aStartTime,
|
|
|
|
double aEndTime,
|
2013-07-16 22:14:40 -07:00
|
|
|
const nsAString& aText,
|
|
|
|
ErrorResult& aRv)
|
2014-04-07 10:58:38 -07:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
|
|
|
, mText(aText)
|
2013-05-21 09:14:00 -07:00
|
|
|
, mStartTime(aStartTime)
|
|
|
|
, mEndTime(aEndTime)
|
2013-07-04 14:24:43 -07:00
|
|
|
, mReset(false)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
|
|
|
SetDefaultCueSettings();
|
2014-04-07 10:58:38 -07:00
|
|
|
MOZ_ASSERT(aOwnerWindow);
|
|
|
|
if (NS_FAILED(StashDocument())) {
|
2013-07-16 22:14:40 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrackCue::TextTrackCue(nsPIDOMWindow* aOwnerWindow,
|
2013-05-21 09:14:00 -07:00
|
|
|
double aStartTime,
|
|
|
|
double aEndTime,
|
|
|
|
const nsAString& aText,
|
|
|
|
HTMLTrackElement* aTrackElement,
|
2013-07-16 22:14:40 -07:00
|
|
|
ErrorResult& aRv)
|
2014-04-07 10:58:38 -07:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
|
|
|
, mText(aText)
|
2013-05-21 09:14:00 -07:00
|
|
|
, mStartTime(aStartTime)
|
|
|
|
, mEndTime(aEndTime)
|
|
|
|
, mTrackElement(aTrackElement)
|
2013-07-04 14:24:43 -07:00
|
|
|
, mReset(false)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
|
|
|
SetDefaultCueSettings();
|
2014-04-07 10:58:38 -07:00
|
|
|
MOZ_ASSERT(aOwnerWindow);
|
|
|
|
if (NS_FAILED(StashDocument())) {
|
2013-07-16 22:14:40 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-12 08:31:18 -07:00
|
|
|
TextTrackCue::~TextTrackCue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:00:00 -08:00
|
|
|
/** Save a reference to our creating document so we don't have to
|
|
|
|
* keep getting it from our window.
|
2013-07-16 22:14:40 -07:00
|
|
|
*/
|
|
|
|
nsresult
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrackCue::StashDocument()
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2014-04-07 10:58:38 -07:00
|
|
|
nsPIDOMWindow* window = GetOwner();
|
2013-07-16 22:14:40 -07:00
|
|
|
if (!window) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
2013-06-19 11:02:04 -07:00
|
|
|
}
|
2013-07-16 22:14:40 -07:00
|
|
|
mDocument = window->GetDoc();
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2013-06-19 11:02:04 -07:00
|
|
|
}
|
2013-07-16 22:14:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-10 08:30:00 -07:00
|
|
|
already_AddRefed<DocumentFragment>
|
|
|
|
TextTrackCue::GetCueAsHTML()
|
|
|
|
{
|
2014-02-14 10:00:00 -08:00
|
|
|
// mDocument may be null during cycle collector shutdown.
|
|
|
|
// See bug 941701.
|
|
|
|
if (!mDocument) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-06-10 08:30:00 -07:00
|
|
|
|
2013-09-19 08:26:00 -07:00
|
|
|
if (!sParserWrapper) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
|
|
|
|
do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return mDocument->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
sParserWrapper = parserWrapper;
|
2013-09-24 12:17:15 -07:00
|
|
|
ClearOnShutdown(&sParserWrapper);
|
2013-09-19 08:26:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow* window = mDocument->GetWindow();
|
|
|
|
if (!window) {
|
|
|
|
return mDocument->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> div;
|
|
|
|
sParserWrapper->ConvertCueToDOMTree(window, this,
|
|
|
|
getter_AddRefs(div));
|
|
|
|
if (!div) {
|
|
|
|
return mDocument->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
nsRefPtr<DocumentFragment> docFrag = mDocument->CreateDocumentFragment();
|
|
|
|
nsCOMPtr<nsIDOMNode> throwAway;
|
|
|
|
docFrag->AppendChild(div, getter_AddRefs(throwAway));
|
|
|
|
|
|
|
|
return docFrag.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrackCue::SetTrackElement(HTMLTrackElement* aTrackElement)
|
|
|
|
{
|
|
|
|
mTrackElement = aTrackElement;
|
2013-06-10 08:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
TextTrackCue::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return VTTCueBinding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-11 10:33:58 -07:00
|
|
|
TextTrackRegion*
|
|
|
|
TextTrackCue::GetRegion()
|
|
|
|
{
|
|
|
|
return mRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrackCue::SetRegion(TextTrackRegion* aRegion)
|
|
|
|
{
|
|
|
|
if (mRegion == aRegion) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRegion = aRegion;
|
|
|
|
mReset = true;
|
|
|
|
}
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|