2009-06-28 15:44:22 -07: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 "nsEvent.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
|
2010-05-20 02:03:11 -07:00
|
|
|
#define NS_HTML5_TREE_DEPTH_LIMIT 200
|
|
|
|
|
2010-04-10 13:10:12 -07:00
|
|
|
class nsPresContext;
|
|
|
|
|
2010-02-01 23:43:18 -08:00
|
|
|
nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsAHtml5TreeOpSink* aOpSink,
|
2010-02-26 01:18:38 -08:00
|
|
|
nsHtml5TreeOpStage* aStage)
|
2009-09-18 02:21:47 -07:00
|
|
|
: scriptingEnabled(PR_FALSE)
|
2009-06-28 15:44:22 -07:00
|
|
|
, fragment(PR_FALSE)
|
|
|
|
, contextNode(nsnull)
|
|
|
|
, formPointer(nsnull)
|
|
|
|
, headPointer(nsnull)
|
2009-09-21 06:18:20 -07:00
|
|
|
, mOpSink(aOpSink)
|
2009-09-21 04:43:43 -07:00
|
|
|
, mHandles(new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH])
|
|
|
|
, mHandlesUsed(0)
|
2010-02-26 01:18:38 -08:00
|
|
|
, mSpeculativeLoadStage(aStage)
|
2009-11-17 00:52:30 -08:00
|
|
|
, mCurrentHtmlScriptIsAsyncOrDefer(PR_FALSE)
|
2009-06-28 15:44:22 -07: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 04:43:43 -07:00
|
|
|
nsIContent**
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
2009-10-12 06:08:04 -07:00
|
|
|
NS_PRECONDITION(aAttributes, "Got null attributes.");
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aName, "Got null name.");
|
|
|
|
NS_PRECONDITION(aNamespace == kNameSpaceID_XHTML ||
|
|
|
|
aNamespace == kNameSpaceID_SVG ||
|
|
|
|
aNamespace == kNameSpaceID_MathML,
|
|
|
|
"Bogus namespace.");
|
2009-10-28 06:48:37 -07:00
|
|
|
|
|
|
|
nsIContent** content = AllocateContentHandle();
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2010-06-08 23:44:25 -07:00
|
|
|
treeOp->Init(aNamespace,
|
|
|
|
aName,
|
|
|
|
aAttributes,
|
|
|
|
content,
|
|
|
|
!!mSpeculativeLoadStage);
|
|
|
|
// mSpeculativeLoadStage is non-null only in the off-the-main-thread
|
|
|
|
// tree builder, which handles the network stream
|
2009-10-12 06:08:04 -07:00
|
|
|
|
2009-10-28 06:48:37 -07:00
|
|
|
// Start wall of code for speculative loading and line numbers
|
2009-10-12 06:08:04 -07:00
|
|
|
|
2010-02-26 01:18:38 -08:00
|
|
|
if (mSpeculativeLoadStage) {
|
2009-10-12 06:08:04 -07:00
|
|
|
switch (aNamespace) {
|
|
|
|
case kNameSpaceID_XHTML:
|
|
|
|
if (nsHtml5Atoms::img == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC);
|
|
|
|
if (url) {
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitImage(*url);
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::script == aName) {
|
2009-10-28 06:48:37 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(eTreeOpSetScriptLineNumberAndFreeze, content, tokenizer->getLineNumber());
|
2009-10-28 06:48:37 -07:00
|
|
|
|
2009-10-12 06:08:04 -07:00
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC);
|
|
|
|
if (url) {
|
|
|
|
nsString* charset = aAttributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
|
|
|
|
nsString* type = aAttributes->getValue(nsHtml5AttributeName::ATTR_TYPE);
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitScript(*url,
|
|
|
|
(charset) ? *charset : EmptyString(),
|
|
|
|
(type) ? *type : EmptyString());
|
2009-11-17 00:52:30 -08:00
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer =
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC) ||
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER);
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::link == aName) {
|
|
|
|
nsString* rel = aAttributes->getValue(nsHtml5AttributeName::ATTR_REL);
|
|
|
|
// Not splitting on space here is bogus but the old parser didn't even
|
|
|
|
// do a case-insensitive check.
|
|
|
|
if (rel && rel->LowerCaseEqualsASCII("stylesheet")) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
|
|
|
|
if (url) {
|
|
|
|
nsString* charset = aAttributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitStyle(*url,
|
|
|
|
(charset) ? *charset : EmptyString());
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::video == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_POSTER);
|
|
|
|
if (url) {
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitImage(*url);
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
2009-10-28 06:48:37 -07:00
|
|
|
} else if (nsHtml5Atoms::style == aName) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-28 06:48:37 -07:00
|
|
|
treeOp->Init(eTreeOpSetStyleLineNumber, content, tokenizer->getLineNumber());
|
2010-02-01 23:43:18 -08:00
|
|
|
} else if (nsHtml5Atoms::html == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_MANIFEST);
|
|
|
|
if (url) {
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitManifest(*url);
|
2011-05-13 01:31:12 -07:00
|
|
|
} else {
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitManifest(EmptyString());
|
2010-02-01 23:43:18 -08:00
|
|
|
}
|
2011-01-03 08:18:23 -08:00
|
|
|
} else if (nsHtml5Atoms::base == aName) {
|
2010-07-26 04:18:43 -07:00
|
|
|
nsString* url =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
|
|
|
|
if (url) {
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitBase(*url);
|
|
|
|
}
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kNameSpaceID_SVG:
|
|
|
|
if (nsHtml5Atoms::image == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
|
|
|
|
if (url) {
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitImage(*url);
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::script == aName) {
|
2009-10-28 06:48:37 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(eTreeOpSetScriptLineNumberAndFreeze, content, tokenizer->getLineNumber());
|
2009-10-28 06:48:37 -07:00
|
|
|
|
2009-10-12 06:08:04 -07:00
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
|
|
|
|
if (url) {
|
|
|
|
nsString* type = aAttributes->getValue(nsHtml5AttributeName::ATTR_TYPE);
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitScript(*url,
|
|
|
|
EmptyString(),
|
|
|
|
(type) ? *type : EmptyString());
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::style == aName) {
|
2009-10-28 06:48:37 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-28 06:48:37 -07:00
|
|
|
treeOp->Init(eTreeOpSetStyleLineNumber, content, tokenizer->getLineNumber());
|
|
|
|
|
2009-10-12 06:08:04 -07:00
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
|
|
|
|
if (url) {
|
2010-02-26 01:18:38 -08:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitStyle(*url, EmptyString());
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-10-28 06:48:37 -07:00
|
|
|
} else if (aNamespace != kNameSpaceID_MathML) {
|
2009-11-17 00:52:30 -08:00
|
|
|
// No speculative loader--just line numbers and defer/async check
|
2009-10-28 06:48:37 -07:00
|
|
|
if (nsHtml5Atoms::style == aName) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-28 06:48:37 -07:00
|
|
|
treeOp->Init(eTreeOpSetStyleLineNumber, content, tokenizer->getLineNumber());
|
|
|
|
} else if (nsHtml5Atoms::script == aName) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(eTreeOpSetScriptLineNumberAndFreeze, content, tokenizer->getLineNumber());
|
2009-11-17 00:52:30 -08:00
|
|
|
if (aNamespace == kNameSpaceID_XHTML) {
|
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer =
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_SRC) &&
|
|
|
|
(aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC) ||
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER));
|
|
|
|
}
|
2010-02-01 23:43:18 -08:00
|
|
|
} else if (aNamespace == kNameSpaceID_XHTML && nsHtml5Atoms::html == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_MANIFEST);
|
2011-05-13 01:31:12 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2010-02-01 23:43:18 -08:00
|
|
|
if (url) {
|
|
|
|
treeOp->Init(eTreeOpProcessOfflineManifest, *url);
|
2011-05-13 01:31:12 -07:00
|
|
|
} else {
|
|
|
|
treeOp->Init(eTreeOpProcessOfflineManifest, EmptyString());
|
2010-02-01 23:43:18 -08:00
|
|
|
}
|
2009-10-28 06:48:37 -07:00
|
|
|
}
|
2009-10-12 06:08:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// End wall of code for speculative loading
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
return content;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent**
|
|
|
|
nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes, nsIContent** aFormElement)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent** content = createElement(aNamespace, aName, aAttributes);
|
2009-06-28 15:44:22 -07:00
|
|
|
if (aFormElement) {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-21 04:43:43 -07:00
|
|
|
treeOp->Init(eTreeOpSetFormElement, content, aFormElement);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent**
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeBuilder::createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent** content = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::html, aAttributes);
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpAppendToDocument, content);
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::detachFromParent(nsIContent** aElement)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aElement, "Null element");
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpDetach, aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::appendElement(nsIContent** aChild, nsIContent** aParent)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aChild, "Null child");
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
2010-09-06 00:41:26 -07:00
|
|
|
if (deepTreeSurrogateParent) {
|
2010-05-20 02:03:11 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-21 06:18:20 -07:00
|
|
|
treeOp->Init(eTreeOpAppend, aChild, aParent);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::appendChildrenToNewParent(nsIContent** aOldParent, nsIContent** aNewParent)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aOldParent, "Null old parent");
|
|
|
|
NS_PRECONDITION(aNewParent, "Null new parent");
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpAppendChildrenToNewParent, aOldParent, aNewParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::insertFosterParentedCharacters(PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength, nsIContent** aTable, nsIContent** aStackParent)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
NS_PRECONDITION(aTable, "Null table");
|
|
|
|
NS_PRECONDITION(aStackParent, "Null stack parent");
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(eTreeOpFosterParentText, bufferCopy, aLength, aStackParent, aTable);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::insertFosterParentedChild(nsIContent** aChild, nsIContent** aTable, nsIContent** aStackParent)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aChild, "Null child");
|
|
|
|
NS_PRECONDITION(aTable, "Null table");
|
|
|
|
NS_PRECONDITION(aStackParent, "Null stack parent");
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpFosterParent, aChild, aStackParent, aTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::appendCharacters(nsIContent** aParent, PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2010-05-20 02:03:11 -07:00
|
|
|
treeOp->Init(eTreeOpAppendText, bufferCopy, aLength,
|
2010-09-06 00:41:26 -07:00
|
|
|
deepTreeSurrogateParent ? deepTreeSurrogateParent : aParent);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 08:08:13 -07:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::appendIsindexPrompt(nsIContent** aParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
|
|
|
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpAppendIsindexPrompt, aParent);
|
|
|
|
}
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::appendComment(nsIContent** aParent, PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
2010-09-06 00:41:26 -07:00
|
|
|
if (deepTreeSurrogateParent) {
|
2010-05-20 02:03:11 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-10-30 04:47:17 -07:00
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(eTreeOpAppendComment, bufferCopy, aLength, aParent);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::appendCommentToDocument(PRUnichar* aBuffer, PRInt32 aStart, PRInt32 aLength)
|
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUnichar* bufferCopy = new PRUnichar[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(eTreeOpAppendCommentToDocument, bufferCopy, aLength);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::addAttributesToElement(nsIContent** aElement, nsHtml5HtmlAttributes* aAttributes)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aElement, "Null element");
|
|
|
|
NS_PRECONDITION(aAttributes, "Null attributes");
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
if (aAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
|
|
|
|
return;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-21 04:43:43 -07:00
|
|
|
treeOp->Init(aElement, aAttributes);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-30 04:47:17 -07:00
|
|
|
nsHtml5TreeBuilder::markMalformedIfScript(nsIContent** aElement)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aElement, "Null element");
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpMarkMalformedIfScript, aElement);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::start(PRBool fragment)
|
|
|
|
{
|
2009-11-17 00:52:30 -08:00
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer = PR_FALSE;
|
2010-09-06 00:41:26 -07:00
|
|
|
deepTreeSurrogateParent = nsnull;
|
2009-06-28 15:44:22 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
mActive = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::end()
|
|
|
|
{
|
2009-08-27 00:57:57 -07:00
|
|
|
mOpQueue.Clear();
|
2009-06-28 15:44:22 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
mActive = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::appendDoctypeToDocument(nsIAtom* aName, nsString* aPublicId, nsString* aSystemId)
|
|
|
|
{
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_PRECONDITION(aName, "Null name");
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 00:52:30 -08:00
|
|
|
treeOp->Init(aName, *aPublicId, *aSystemId);
|
2009-06-28 15:44:22 -07:00
|
|
|
// nsXMLContentSink can flush here, but what's the point?
|
|
|
|
// It can also interrupt here, but we can't.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::elementPushed(PRInt32 aNamespace, nsIAtom* aName, nsIContent** aElement)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2010-02-22 04:17:33 -08: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!");
|
2010-05-20 02:03:11 -07:00
|
|
|
/*
|
|
|
|
* The frame constructor uses recursive algorithms, so it can't deal with
|
|
|
|
* arbitrarily deep trees. This is especially a problem on Windows where
|
|
|
|
* the permitted depth of the runtime stack is rather small.
|
|
|
|
*
|
|
|
|
* The following is a protection against author incompetence--not against
|
|
|
|
* malice. There are other ways to make the DOM deep anyway.
|
|
|
|
*
|
|
|
|
* The basic idea is that when the tree builder stack gets too deep,
|
|
|
|
* append operations no longer append to the node that the HTML parsing
|
|
|
|
* algorithm says they should but instead text nodes are append to the last
|
|
|
|
* element that was seen before a magic tree builder stack threshold was
|
|
|
|
* reached and element and comment nodes aren't appended to the DOM at all.
|
|
|
|
*
|
|
|
|
* However, for security reasons, non-child descendant text nodes inside an
|
|
|
|
* SVG script or style element should not become children. Also, non-cell
|
|
|
|
* table elements shouldn't be used as surrogate parents for user experience
|
|
|
|
* reasons.
|
|
|
|
*/
|
2010-09-06 00:41:26 -07:00
|
|
|
if (!deepTreeSurrogateParent && currentPtr >= NS_HTML5_TREE_DEPTH_LIMIT &&
|
2010-05-20 02:03:11 -07:00
|
|
|
!(aName == nsHtml5Atoms::script ||
|
|
|
|
aName == nsHtml5Atoms::table ||
|
|
|
|
aName == nsHtml5Atoms::thead ||
|
|
|
|
aName == nsHtml5Atoms::tfoot ||
|
|
|
|
aName == nsHtml5Atoms::tbody ||
|
|
|
|
aName == nsHtml5Atoms::tr ||
|
|
|
|
aName == nsHtml5Atoms::colgroup ||
|
|
|
|
aName == nsHtml5Atoms::style)) {
|
2010-09-06 00:41:26 -07:00
|
|
|
deepTreeSurrogateParent = aElement;
|
2010-05-20 02:03:11 -07:00
|
|
|
}
|
2010-02-22 04:17:33 -08:00
|
|
|
if (aNamespace != kNameSpaceID_XHTML) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::body || aName == nsHtml5Atoms::frameset) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpStartLayout);
|
|
|
|
return;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeBuilder::elementPopped(PRInt32 aNamespace, nsIAtom* aName, nsIContent** aElement)
|
2009-06-28 15:44:22 -07: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!");
|
2010-09-06 00:41:26 -07:00
|
|
|
if (deepTreeSurrogateParent && currentPtr <= NS_HTML5_TREE_DEPTH_LIMIT) {
|
|
|
|
deepTreeSurrogateParent = nsnull;
|
2010-05-20 02:03:11 -07:00
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
if (aNamespace == kNameSpaceID_MathML) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we now have only SVG and HTML
|
|
|
|
if (aName == nsHtml5Atoms::script) {
|
2009-11-17 00:52:30 -08:00
|
|
|
if (mCurrentHtmlScriptIsAsyncOrDefer) {
|
|
|
|
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML,
|
|
|
|
"Only HTML scripts may be async/defer.");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpRunScriptAsyncDefer, aElement);
|
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer = PR_FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
requestSuspension();
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-12 06:08:04 -07:00
|
|
|
treeOp->InitScript(aElement);
|
2009-06-28 15:44:22 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::title) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::style || (aNamespace == kNameSpaceID_XHTML && aName == nsHtml5Atoms::link)) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpUpdateStyleSheet, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aNamespace == kNameSpaceID_SVG) {
|
2010-07-18 15:07:54 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
if (aName == nsHtml5Atoms::svg) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpSvgLoad, aElement);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we now have only HTML
|
|
|
|
// Some HTML nodes need DoneAddingChildren() called to initialize
|
2009-07-15 04:30:33 -07:00
|
|
|
// properly (e.g. form state restoration).
|
2009-06-28 15:44:22 -07:00
|
|
|
// XXX expose ElementName group here and do switch
|
2010-09-02 17:03:03 -07:00
|
|
|
if (aName == nsHtml5Atoms::object ||
|
2010-01-20 05:43:58 -08:00
|
|
|
aName == nsHtml5Atoms::applet) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::select ||
|
|
|
|
aName == nsHtml5Atoms::textarea) {
|
|
|
|
if (!formPointer) {
|
|
|
|
// If form inputs don't belong to a form, their state preservation
|
|
|
|
// won't work right without an append notification flush at this
|
|
|
|
// point. See bug 497861 and bug 539895.
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpFlushPendingAppendNotifications);
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::input ||
|
|
|
|
aName == nsHtml5Atoms::button) {
|
2009-11-06 05:06:48 -08:00
|
|
|
if (!formPointer) {
|
|
|
|
// If form inputs don't belong to a form, their state preservation
|
|
|
|
// won't work right without an append notification flush at this
|
|
|
|
// point. See bug 497861.
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpFlushPendingAppendNotifications);
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpDoneCreatingElement, aElement);
|
|
|
|
return;
|
|
|
|
}
|
2010-10-13 00:12:55 -07:00
|
|
|
if (aName == nsHtml5Atoms::meta && !fragment) {
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 15:44:22 -07:00
|
|
|
treeOp->Init(eTreeOpProcessMeta, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-10 01:23:35 -08:00
|
|
|
nsHtml5TreeBuilder::accumulateCharacters(const PRUnichar* aBuf, PRInt32 aStart, PRInt32 aLength)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2010-03-30 01:21:36 -07:00
|
|
|
PRInt32 newFillLen = charBufferLen + aLength;
|
|
|
|
if (newFillLen > charBuffer.length) {
|
|
|
|
PRInt32 newAllocLength = newFillLen + (newFillLen >> 1);
|
2010-09-28 00:32:31 -07:00
|
|
|
jArray<PRUnichar,PRInt32> newBuf = jArray<PRUnichar,PRInt32>::newJArray(newAllocLength);
|
2010-03-30 01:21:36 -07:00
|
|
|
memcpy(newBuf, charBuffer, sizeof(PRUnichar) * charBufferLen);
|
|
|
|
charBuffer = newBuf;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
memcpy(charBuffer + charBufferLen, aBuf + aStart, sizeof(PRUnichar) * aLength);
|
2010-03-30 01:21:36 -07:00
|
|
|
charBufferLen = newFillLen;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent**
|
|
|
|
nsHtml5TreeBuilder::AllocateContentHandle()
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-09-21 04:43:43 -07: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-28 15:44:22 -07:00
|
|
|
}
|
2009-10-30 04:47:17 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
mHandles[mHandlesUsed] = (nsIContent*)0xC0DEDBAD;
|
|
|
|
#endif
|
2009-09-21 04:43:43 -07:00
|
|
|
return &mHandles[mHandlesUsed++];
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
PRBool
|
|
|
|
nsHtml5TreeBuilder::HasScript()
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUint32 len = mOpQueue.Length();
|
|
|
|
if (!len) {
|
|
|
|
return PR_FALSE;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
2009-09-21 04:43:43 -07:00
|
|
|
return mOpQueue.ElementAt(len - 1).IsRunScript();
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2009-11-17 00:52:30 -08:00
|
|
|
PRBool
|
2009-09-21 06:18:20 -07:00
|
|
|
nsHtml5TreeBuilder::Flush()
|
|
|
|
{
|
2010-03-15 05:04:41 -07:00
|
|
|
flushCharacters();
|
2010-02-26 01:18:38 -08:00
|
|
|
FlushLoads();
|
2010-11-18 00:23:48 -08:00
|
|
|
if (mOpSink) {
|
|
|
|
PRBool hasOps = !mOpQueue.IsEmpty();
|
|
|
|
if (hasOps) {
|
|
|
|
mOpSink->MoveOpsFrom(mOpQueue);
|
|
|
|
}
|
|
|
|
return hasOps;
|
2009-11-17 00:52:30 -08:00
|
|
|
}
|
2010-11-18 00:23:48 -08:00
|
|
|
// no op sink: throw away ops
|
|
|
|
mOpQueue.Clear();
|
|
|
|
return PR_FALSE;
|
2009-09-21 06:18:20 -07:00
|
|
|
}
|
|
|
|
|
2010-02-26 01:18:38 -08:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::FlushLoads()
|
|
|
|
{
|
|
|
|
if (!mSpeculativeLoadQueue.IsEmpty()) {
|
|
|
|
mSpeculativeLoadStage->MoveSpeculativeLoadsFrom(mSpeculativeLoadQueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-21 06:18:20 -07:00
|
|
|
void
|
2010-03-09 04:39:32 -08:00
|
|
|
nsHtml5TreeBuilder::SetDocumentCharset(nsACString& aCharset,
|
|
|
|
PRInt32 aCharsetSource)
|
2009-09-21 06:18:20 -07:00
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2010-03-09 04:39:32 -08:00
|
|
|
treeOp->Init(eTreeOpSetDocumentCharset, aCharset, aCharsetSource);
|
2009-09-21 06:18:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::StreamEnded()
|
|
|
|
{
|
2009-10-12 06:08:04 -07:00
|
|
|
// The fragment mode calls DidBuildModel from nsHtml5Parser.
|
2009-09-21 06:18:20 -07:00
|
|
|
// Letting DidBuildModel be called from the executor in the fragment case
|
|
|
|
// confuses the EndLoad logic of nsHTMLDocument, since nsHTMLDocument
|
|
|
|
// thinks it is dealing with document.written content as opposed to
|
|
|
|
// innerHTML content.
|
|
|
|
if (!fragment) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-21 06:18:20 -07:00
|
|
|
treeOp->Init(eTreeOpStreamEnded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-11 02:33:32 -08:00
|
|
|
nsHtml5TreeBuilder::NeedsCharsetSwitchTo(const nsACString& aCharset,
|
|
|
|
PRInt32 aCharsetSource)
|
2009-09-21 06:18:20 -07:00
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2011-02-11 02:33:32 -08:00
|
|
|
treeOp->Init(eTreeOpNeedsCharsetSwitchTo, aCharset, aCharsetSource);
|
2009-09-21 06:18:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-28 06:48:37 -07:00
|
|
|
nsHtml5TreeBuilder::AddSnapshotToScript(nsAHtml5TreeBuilderState* aSnapshot, PRInt32 aLine)
|
2009-09-21 06:18:20 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(HasScript(), "No script to add a snapshot to!");
|
2009-10-12 06:08:04 -07:00
|
|
|
NS_PRECONDITION(aSnapshot, "Got null snapshot.");
|
2009-10-28 06:48:37 -07:00
|
|
|
mOpQueue.ElementAt(mOpQueue.Length() - 1).SetSnapshot(aSnapshot, aLine);
|
2009-09-21 06:18:20 -07:00
|
|
|
}
|
|
|
|
|
2009-11-17 00:52:30 -08:00
|
|
|
PRBool
|
|
|
|
nsHtml5TreeBuilder::IsDiscretionaryFlushSafe()
|
|
|
|
{
|
|
|
|
return !(charBufferLen &&
|
|
|
|
currentPtr >= 0 &&
|
2010-12-09 01:27:57 -08:00
|
|
|
stack[currentPtr]->isFosterParenting());
|
2009-11-17 00:52:30 -08:00
|
|
|
}
|
|
|
|
|
2010-11-18 00:19:59 -08:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::DropHandles()
|
|
|
|
{
|
|
|
|
mOldHandles.Clear();
|
|
|
|
mHandlesUsed = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-18 02:21:47 -07:00
|
|
|
// DocumentModeHandler
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::documentMode(nsHtml5DocumentMode m)
|
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 04:47:17 -07:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-18 02:21:47 -07:00
|
|
|
treeOp->Init(m);
|
|
|
|
}
|