2009-06-29 02:44:22 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
* Henri Sivonen <hsivonen@iki.fi>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsContentErrors.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsEvent.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
|
|
|
|
// this really should be autogenerated...
|
|
|
|
jArray<PRUnichar,PRInt32> nsHtml5TreeBuilder::ISINDEX_PROMPT = jArray<PRUnichar,PRInt32>();
|
2009-09-18 13:21:47 +04:00
|
|
|
nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsHtml5TreeOpExecutor* aExec)
|
|
|
|
: scriptingEnabled(PR_FALSE)
|
2009-06-29 02:44:22 +04:00
|
|
|
, fragment(PR_FALSE)
|
|
|
|
, contextNode(nsnull)
|
|
|
|
, formPointer(nsnull)
|
|
|
|
, headPointer(nsnull)
|
2009-09-18 13:21:47 +04:00
|
|
|
, mExecutor(aExec)
|
2009-09-21 15:43:43 +04:00
|
|
|
, mHandles(new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH])
|
|
|
|
, mHandlesUsed(0)
|
2009-06-29 02:44:22 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mActive(PR_FALSE)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5TreeBuilder::~nsHtml5TreeBuilder()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsHtml5TreeBuilder);
|
|
|
|
NS_ASSERTION(!mActive, "nsHtml5TreeBuilder deleted without ever calling end() on it!");
|
|
|
|
mOpQueue.Clear();
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent**
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent** content = AllocateContentHandle();
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(aNamespace, aName, aAttributes, content);
|
|
|
|
return content;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent**
|
|
|
|
nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes, nsIContent** aFormElement)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent** content = createElement(aNamespace, aName, aAttributes);
|
2009-06-29 02:44:22 +04:00
|
|
|
if (aFormElement) {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpSetFormElement, content, aFormElement);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent**
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeBuilder::createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent** content = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::html, aAttributes);
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpAppendToDocument, content);
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::detachFromParent(nsIContent** aElement)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpDetach, aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::appendElement(nsIContent** aChild, nsIContent** aParent)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(aChild, aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::appendChildrenToNewParent(nsIContent** aOldParent, nsIContent** aNewParent)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpAppendChildrenToNewParent, aOldParent, aNewParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::insertFosterParentedCharacters(PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength, nsIContent** aTable, nsIContent** aStackParent)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
|
|
|
nsIContent** text = AllocateContentHandle();
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-09-21 15:43:43 +04:00
|
|
|
treeOp->Init(eTreeOpCreateTextNode, bufferCopy, aLength, text);
|
|
|
|
|
|
|
|
treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-06-29 02:44:22 +04:00
|
|
|
treeOp->Init(eTreeOpFosterParent, text, aStackParent, aTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::insertFosterParentedChild(nsIContent** aChild, nsIContent** aTable, nsIContent** aStackParent)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpFosterParent, aChild, aStackParent, aTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::appendCharacters(nsIContent** aParent, PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
|
|
|
nsIContent** text = AllocateContentHandle();
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-09-21 15:43:43 +04:00
|
|
|
treeOp->Init(eTreeOpCreateTextNode, bufferCopy, aLength, text);
|
|
|
|
|
|
|
|
treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-06-29 02:44:22 +04:00
|
|
|
treeOp->Init(text, aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::appendComment(nsIContent** aParent, PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
|
|
|
nsIContent** comment = AllocateContentHandle();
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-09-21 15:43:43 +04:00
|
|
|
treeOp->Init(eTreeOpCreateComment, bufferCopy, aLength, comment);
|
|
|
|
|
|
|
|
treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-06-29 02:44:22 +04:00
|
|
|
treeOp->Init(comment, aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::appendCommentToDocument(PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength)
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
|
|
|
nsIContent** comment = AllocateContentHandle();
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-09-21 15:43:43 +04:00
|
|
|
treeOp->Init(eTreeOpCreateComment, bufferCopy, aLength, comment);
|
|
|
|
|
|
|
|
treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-06-29 02:44:22 +04:00
|
|
|
treeOp->Init(eTreeOpAppendToDocument, comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::addAttributesToElement(nsIContent** aElement, nsHtml5HtmlAttributes* aAttributes)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
if (aAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
|
|
|
|
return;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-09-21 15:43:43 +04:00
|
|
|
treeOp->Init(aElement, aAttributes);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::markMalformedIfScript(nsIContent** elt)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpMarkMalformedIfScript, elt);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::start(PRBool fragment)
|
|
|
|
{
|
|
|
|
// XXX check that timer creation didn't fail in constructor
|
2009-09-18 13:21:47 +04:00
|
|
|
if (!fragment) {
|
|
|
|
/*
|
|
|
|
* If you move the following line, be very careful not to cause
|
|
|
|
* WillBuildModel to be called before the document has had its
|
|
|
|
* script global object set.
|
|
|
|
*/
|
|
|
|
mExecutor->WillBuildModel(eDTDMode_unknown);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
mExecutor->Start();
|
2009-06-29 02:44:22 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mActive = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::end()
|
|
|
|
{
|
2009-09-18 13:21:47 +04:00
|
|
|
mExecutor->End();
|
2009-08-27 11:57:57 +04:00
|
|
|
mOpQueue.Clear();
|
2009-06-29 02:44:22 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mActive = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::appendDoctypeToDocument(nsIAtom* aName, nsString* aPublicId, nsString* aSystemId)
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent** content = AllocateContentHandle();
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-09-21 15:43:43 +04:00
|
|
|
treeOp->Init(aName, *aPublicId, *aSystemId, content);
|
|
|
|
|
|
|
|
treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
2009-06-29 02:44:22 +04:00
|
|
|
treeOp->Init(eTreeOpAppendToDocument, content);
|
|
|
|
// nsXMLContentSink can flush here, but what's the point?
|
|
|
|
// It can also interrupt here, but we can't.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::elementPushed(PRInt32 aNamespace, nsIAtom* aName, nsIContent** aElement)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML || aNamespace == kNameSpaceID_SVG || aNamespace == kNameSpaceID_MathML, "Element isn't HTML, SVG or MathML!");
|
|
|
|
NS_ASSERTION(aName, "Element doesn't have local name!");
|
|
|
|
NS_ASSERTION(aElement, "No element!");
|
|
|
|
// Give autoloading links a chance to fire
|
|
|
|
if (aNamespace == kNameSpaceID_XHTML) {
|
|
|
|
if (aName == nsHtml5Atoms::body) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpStartLayout, nsnull);
|
|
|
|
} else if (aName == nsHtml5Atoms::html) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpProcessOfflineManifest, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
mExecutor->MaybeSuspend();
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeBuilder::elementPopped(PRInt32 aNamespace, nsIAtom* aName, nsIContent** aElement)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML || aNamespace == kNameSpaceID_SVG || aNamespace == kNameSpaceID_MathML, "Element isn't HTML, SVG or MathML!");
|
|
|
|
NS_ASSERTION(aName, "Element doesn't have local name!");
|
|
|
|
NS_ASSERTION(aElement, "No element!");
|
2009-09-18 13:21:47 +04:00
|
|
|
mExecutor->MaybeSuspend();
|
2009-06-29 02:44:22 +04:00
|
|
|
if (aNamespace == kNameSpaceID_MathML) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we now have only SVG and HTML
|
|
|
|
if (aName == nsHtml5Atoms::script) {
|
|
|
|
requestSuspension();
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpRunScript, aElement);
|
2009-06-29 02:44:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::title) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::style || (aNamespace == kNameSpaceID_XHTML && aName == nsHtml5Atoms::link)) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpUpdateStyleSheet, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aNamespace == kNameSpaceID_SVG) {
|
|
|
|
#if 0
|
|
|
|
if (aElement->HasAttr(kNameSpaceID_None, nsHtml5Atoms::onload)) {
|
|
|
|
nsEvent event(PR_TRUE, NS_SVG_LOAD);
|
|
|
|
event.eventStructType = NS_SVG_EVENT;
|
|
|
|
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
|
|
|
|
// Do we care about forcing presshell creation if it hasn't happened yet?
|
|
|
|
// That is, should this code flush or something? Does it really matter?
|
|
|
|
// For that matter, do we really want to try getting the prescontext? Does
|
|
|
|
// this event ever want one?
|
|
|
|
nsRefPtr<nsPresContext> ctx;
|
|
|
|
nsCOMPtr<nsIPresShell> shell = parser->GetDocument()->GetPrimaryShell();
|
|
|
|
if (shell) {
|
|
|
|
ctx = shell->GetPresContext();
|
|
|
|
}
|
|
|
|
nsEventDispatcher::Dispatch(aElement, ctx, &event);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we now have only HTML
|
|
|
|
// Some HTML nodes need DoneAddingChildren() called to initialize
|
2009-07-15 15:30:33 +04:00
|
|
|
// properly (e.g. form state restoration).
|
2009-06-29 02:44:22 +04:00
|
|
|
// XXX expose ElementName group here and do switch
|
|
|
|
if (aName == nsHtml5Atoms::select ||
|
|
|
|
aName == nsHtml5Atoms::textarea ||
|
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
aName == nsHtml5Atoms::video ||
|
|
|
|
aName == nsHtml5Atoms::audio ||
|
|
|
|
#endif
|
|
|
|
aName == nsHtml5Atoms::object ||
|
|
|
|
aName == nsHtml5Atoms::applet) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::input ||
|
|
|
|
aName == nsHtml5Atoms::button) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpDoneCreatingElement, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::base) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpProcessBase, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::meta) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(eTreeOpProcessMeta, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::accumulateCharacters(PRUnichar* aBuf, PRInt32 aStart, PRInt32 aLength)
|
|
|
|
{
|
|
|
|
PRInt32 newFillLen = charBufferLen + aLength;
|
|
|
|
if (newFillLen > charBuffer.length) {
|
|
|
|
PRInt32 newAllocLength = newFillLen + (newFillLen >> 1);
|
|
|
|
jArray<PRUnichar,PRInt32> newBuf(newAllocLength);
|
|
|
|
memcpy(newBuf, charBuffer, sizeof(PRUnichar) * charBufferLen);
|
|
|
|
charBuffer.release();
|
|
|
|
charBuffer = newBuf;
|
|
|
|
}
|
|
|
|
memcpy(charBuffer + charBufferLen, aBuf + aStart, sizeof(PRUnichar) * aLength);
|
|
|
|
charBufferLen = newFillLen;
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent**
|
|
|
|
nsHtml5TreeBuilder::AllocateContentHandle()
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
if (mHandlesUsed == NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH) {
|
|
|
|
mOldHandles.AppendElement(mHandles.forget());
|
|
|
|
mHandles = new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH];
|
|
|
|
mHandlesUsed = 0;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
return &mHandles[mHandlesUsed++];
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
PRBool
|
|
|
|
nsHtml5TreeBuilder::HasScript()
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUint32 len = mOpQueue.Length();
|
|
|
|
if (!len) {
|
|
|
|
return PR_FALSE;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
return mOpQueue.ElementAt(len - 1).IsRunScript();
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
// DocumentModeHandler
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::documentMode(nsHtml5DocumentMode m)
|
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
// XXX if null, OOM!
|
|
|
|
treeOp->Init(m);
|
|
|
|
}
|