Backed out changeset f56acf83688c (bug 895091) r=bustage CLOSED TREE

This commit is contained in:
Ralph Giles 2013-09-18 13:47:43 -07:00
Родитель aaf5811e76
Коммит 69e9dad50b
4 изменённых файлов: 155 добавлений и 14 удалений

Просмотреть файл

@ -48,6 +48,7 @@ TextTrackCue::TextTrackCue(nsISupports* aGlobal,
: mText(aText)
, mStartTime(aStartTime)
, mEndTime(aEndTime)
, mHead(nullptr)
, mReset(false)
{
SetDefaultCueSettings();
@ -63,13 +64,16 @@ TextTrackCue::TextTrackCue(nsISupports* aGlobal,
double aEndTime,
const nsAString& aText,
HTMLTrackElement* aTrackElement,
webvtt_node* head,
ErrorResult& aRv)
: mText(aText)
, mStartTime(aStartTime)
, mEndTime(aEndTime)
, mTrackElement(aTrackElement)
, mHead(head)
, mReset(false)
{
// Ref mHead here.
SetDefaultCueSettings();
MOZ_ASSERT(aGlobal);
SetIsDOMBinding();
@ -78,6 +82,13 @@ TextTrackCue::TextTrackCue(nsISupports* aGlobal,
}
}
TextTrackCue::~TextTrackCue()
{
if (mHead) {
// Release mHead here.
}
}
/** Save a reference to our creating document so it's available
* even when unlinked during discard/teardown.
*/
@ -151,10 +162,52 @@ TextTrackCue::GetCueAsHTML()
{
MOZ_ASSERT(mDocument);
nsRefPtr<DocumentFragment> frag = mDocument->CreateDocumentFragment();
ConvertNodeTreeToDOMTree(frag);
return frag.forget();
}
struct WebVTTNodeParentPair
{
webvtt_node* mNode;
nsIContent* mParent;
WebVTTNodeParentPair(webvtt_node* aNode, nsIContent* aParent)
: mNode(aNode)
, mParent(aParent)
{}
};
void
TextTrackCue::ConvertNodeTreeToDOMTree(nsIContent* aParentContent)
{
nsTArray<WebVTTNodeParentPair> nodeParentPairStack;
// mHead should actually be the head of a node tree.
// Seed the stack for traversal.
}
already_AddRefed<nsIContent>
TextTrackCue::ConvertInternalNodeToContent(const webvtt_node* aWebVTTNode)
{
nsIAtom* atom = nsGkAtoms::span;
nsCOMPtr<nsIContent> cueTextContent;
mDocument->CreateElem(nsDependentAtomString(atom), nullptr,
kNameSpaceID_XHTML,
getter_AddRefs(cueTextContent));
return cueTextContent.forget();
}
already_AddRefed<nsIContent>
TextTrackCue::ConvertLeafNodeToContent(const webvtt_node* aWebVTTNode)
{
nsCOMPtr<nsIContent> cueTextContent;
// Use mDocument to create nodes on cueTextContent.
return cueTextContent.forget();
}
JSObject*
TextTrackCue::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{

Просмотреть файл

@ -8,11 +8,14 @@
#define mozilla_dom_TextTrackCue_h
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/TextTrack.h"
#include "mozilla/dom/VTTCueBinding.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDOMEventTargetHelper.h"
#include "nsIDocument.h"
struct webvtt_node;
namespace mozilla {
namespace dom {
@ -43,7 +46,9 @@ public:
TextTrackCue(nsISupports* aGlobal, double aStartTime, double aEndTime,
const nsAString& aText, HTMLTrackElement* aTrackElement,
ErrorResult& aRv);
webvtt_node* head, ErrorResult& aRv);
~TextTrackCue();
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
@ -229,6 +234,12 @@ public:
CueChanged();
}
already_AddRefed<DocumentFragment> GetCueAsHTML() const
{
// XXXhumph: todo. Bug 868509.
return nullptr;
}
IMPL_EVENT_HANDLER(enter)
IMPL_EVENT_HANDLER(exit)
@ -245,17 +256,17 @@ public:
}
/**
* Overview of WebVTT cuetext and anonymous content setup.
* Overview of WEBVTT cuetext and anonymous content setup.
*
* WebVTT nodes are the parsed version of WebVTT cuetext. WebVTT cuetext is
* the portion of a WebVTT cue that specifies what the caption will actually
* webvtt_nodes are the parsed version of WEBVTT cuetext. WEBVTT cuetext is
* the portion of a WEBVTT cue that specifies what the caption will actually
* show up as on screen.
*
* WebVTT cuetext can contain markup that loosely relates to HTML markup. It
* WEBVTT cuetext can contain markup that loosely relates to HTML markup. It
* can contain tags like <b>, <u>, <i>, <c>, <v>, <ruby>, <rt>, <lang>,
* including timestamp tags.
*
* When the caption is ready to be displayed the WebVTT nodes are converted
* When the caption is ready to be displayed the webvtt_nodes are converted
* over to anonymous DOM content. <i>, <u>, <b>, <ruby>, and <rt> all become
* HTMLElements of their corresponding HTML markup tags. <c> and <v> are
* converted to <span> tags. Timestamp tags are converted to XML processing
@ -263,7 +274,7 @@ public:
* This takes the form of <foo.class.subclass>. These classes are then parsed
* and set as the anonymous content's class attribute.
*
* Rules on constructing DOM objects from WebVTT nodes can be found here
* Rules on constructing DOM objects from webvtt_nodes can be found here
* http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules.
* Current rules are taken from revision on April 15, 2013.
*/
@ -276,13 +287,39 @@ public:
/**
* Produces a tree of anonymous content based on the tree of the processed
* cue text.
* cue text. This lives in a tree of C nodes whose head is mHead.
*
* Returns a DocumentFragment that is the head of the tree of anonymous
* content.
*/
already_AddRefed<DocumentFragment> GetCueAsHTML();
/**
* Converts mHead to a list of DOM elements and attaches it to aParentContent.
*
* Processes the C node tree in a depth-first pre-order traversal and creates
* a mirrored DOM tree. The conversion rules come from the webvtt DOM
* construction rules:
* http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules
* Current rules taken from revision on May 13, 2013.
*/
void
ConvertNodeTreeToDOMTree(nsIContent* aParentContent);
/**
* Converts an internal webvtt node, i.e. one that has children, to an
* anonymous HTMLElement.
*/
already_AddRefed<nsIContent>
ConvertInternalNodeToContent(const webvtt_node* aWebVTTNode);
/**
* Converts a leaf webvtt node, i.e. one that does not have children, to
* either a text node or processing instruction.
*/
already_AddRefed<nsIContent>
ConvertLeafNodeToContent(const webvtt_node* aWebVTTNode);
private:
void CueChanged();
void SetDefaultCueSettings();
@ -296,6 +333,7 @@ private:
nsRefPtr<TextTrack> mTrack;
nsRefPtr<HTMLTrackElement> mTrackElement;
webvtt_node *mHead;
nsString mId;
int32_t mPosition;
int32_t mSize;

Просмотреть файл

@ -57,6 +57,10 @@ WebVTTLoadListener::LoadResource()
}
LOG("Loading text track resource.");
webvtt_parser_t* parser = nullptr;
// Create parser here.
mParser.own(parser);
NS_ENSURE_TRUE(mParser != nullptr, NS_ERROR_FAILURE);
mElement->mReadyState = HTMLTrackElement::LOADING;
return NS_OK;
@ -126,6 +130,7 @@ WebVTTLoadListener::ParseChunk(nsIInputStream* aInStream, void* aClosure,
const char* aFromSegment, uint32_t aToOffset,
uint32_t aCount, uint32_t* aWriteCount)
{
//WebVTTLoadListener* loadListener = static_cast<WebVTTLoadListener*>(aClosure);
// Call parser incrementally on new data.
if (1) {
LOG("WebVTT parser disabled.");
@ -137,5 +142,32 @@ WebVTTLoadListener::ParseChunk(nsIInputStream* aInStream, void* aClosure,
return NS_OK;
}
void
WebVTTLoadListener::OnParsedCue(webvtt_cue* aCue)
{
nsRefPtr<TextTrackCue> textTrackCue;
// Create a new textTrackCue here.
// Copy settings from the parsed cue here.
mElement->mTrack->AddCue(*textTrackCue);
}
int
WebVTTLoadListener::OnReportError(uint32_t aLine, uint32_t aCol,
webvtt_error aError)
{
#ifdef PR_LOGGING
// Get source webvtt file to display in the log
DOMString wideFile;
mElement->GetSrc(wideFile);
NS_ConvertUTF16toUTF8 file(wideFile);
const char* error = "parser error";
LOG("error: %s(%d:%d) - %s\n", file.get(), aLine, aCol, error);
#endif
return 0;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -13,14 +13,27 @@
#include "nsAutoRef.h"
#include "nsCycleCollectionParticipant.h"
struct webvtt_parser_t;
struct webvtt_cue;
typedef int webvtt_error;
template <>
class nsAutoRefTraits<webvtt_parser_t> : public nsPointerRefTraits<webvtt_parser_t>
{
public:
static void Release(webvtt_parser_t* aParser) {
// Call parser dtor here.
}
};
namespace mozilla {
namespace dom {
class HTMLTrackElement;
/**
* Class that manages the WebVTT parsing library and functions as an
* interface between Gecko and WebVTT.
* Class that manages the libwebvtt parsing library and functions as an
* interface between Gecko and libwebvtt.
*
* Currently it's only designed to work with an HTMLTrackElement. The
* HTMLTrackElement controls the lifetime of the WebVTTLoadListener.
@ -28,10 +41,11 @@ class HTMLTrackElement;
* The workflow of this class is as follows:
* - Gets Loaded via an HTMLTrackElement class.
* - As the HTMLTrackElement class gets new data WebVTTLoadListener's
* OnDataAvailable() function is called and data is passed to the WebVTT
* OnDataAvailable() function is called and data is passed to the libwebvtt
* parser.
* - When the WebVTT parser has finished a cue it will call the callbacks
* that are exposed by the WebVTTLoadListener.
* - When the libwebvtt parser has finished a cue it will call the callbacks
* that are exposed by the WebVTTLoadListener -- OnParsedCueWebVTTCallBack or
* OnReportErrorWebVTTCallBack if it has encountered an error.
* - When it has returned a cue successfully the WebVTTLoadListener will create
* a new TextTrackCue and add it to the HTMLTrackElement's TextTrack.
*/
@ -52,7 +66,7 @@ public:
WebVTTLoadListener(HTMLTrackElement* aElement);
~WebVTTLoadListener();
// Loads the WebVTT parser. Must call this function in order to the
// Loads the libwebvtt parser. Must call this function in order to the
// WebVTTLoadListener to be ready to accept data.
nsresult LoadResource();
@ -62,6 +76,10 @@ private:
uint32_t aCount, uint32_t* aWriteCount);
nsRefPtr<HTMLTrackElement> mElement;
nsAutoRef<webvtt_parser_t> mParser;
void OnParsedCue(webvtt_cue* aCue);
int OnReportError(uint32_t aLine, uint32_t aCol, webvtt_error aError);
};