mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
3d52d52549
Add webidl interfaces and implementations of the HTML <track> element and related TextTrack, TextTrackList, TextTrackCue, and TextTrackCueList dom objects. Visibility is controlled by the media.webvtt.enabled pref, which defaults to false. HTMLMediaElement:NewURIFromString() is hoisted to nsGenericHTMLElement so it's available to the track element as well. This patch is primarily work by Dale Karp, David Humphrey and others as Seneca College.
103 lines
2.6 KiB
C++
103 lines
2.6 KiB
C++
/* -*- 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<JSObject*> aScope)
|
|
{
|
|
return TextTrackCueBinding::Wrap(aCx, aScope, this);
|
|
}
|
|
|
|
void
|
|
TextTrackCue::CueChanged()
|
|
{
|
|
if (mTrack) {
|
|
mTrack->CueChanged(*this);
|
|
}
|
|
}
|
|
} // namespace dom
|
|
} // namespace mozilla
|