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 "nsHtml5TreeOperation.h"
|
2009-08-13 11:51:06 +04:00
|
|
|
#include "nsContentUtils.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsAttrName.h"
|
|
|
|
#include "nsHtml5TreeBuilder.h"
|
2009-08-13 11:51:06 +04:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "mozAutoDocUpdate.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "nsXBLBinding.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
#include "nsHtml5DocumentMode.h"
|
2009-09-21 15:43:43 +04:00
|
|
|
#include "nsHtml5HtmlAttributes.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsIScriptElement.h"
|
|
|
|
#include "nsIDTD.h"
|
|
|
|
#include "nsTraceRefcnt.h"
|
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2009-11-17 11:52:30 +03:00
|
|
|
#include "nsIMutationObserver.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2009-11-11 11:37:35 +03:00
|
|
|
/**
|
|
|
|
* Helper class that opens a notification batch if the current doc
|
|
|
|
* is different from the executor doc.
|
|
|
|
*/
|
|
|
|
class NS_STACK_CLASS nsHtml5OtherDocUpdate {
|
|
|
|
public:
|
|
|
|
nsHtml5OtherDocUpdate(nsIDocument* aCurrentDoc, nsIDocument* aExecutorDoc)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aCurrentDoc, "Node has no doc?");
|
|
|
|
NS_PRECONDITION(aExecutorDoc, "Executor has no doc?");
|
|
|
|
if (NS_LIKELY(aCurrentDoc == aExecutorDoc)) {
|
|
|
|
mDocument = nsnull;
|
|
|
|
} else {
|
|
|
|
mDocument = aCurrentDoc;
|
|
|
|
aCurrentDoc->BeginUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsHtml5OtherDocUpdate()
|
|
|
|
{
|
|
|
|
if (NS_UNLIKELY(mDocument)) {
|
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
};
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation::nsHtml5TreeOperation()
|
2009-09-21 17:18:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
: mOpCode(eTreeOpUninitialized)
|
|
|
|
#endif
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5TreeOperation::~nsHtml5TreeOperation()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsHtml5TreeOperation);
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_ASSERTION(mOpCode != eTreeOpUninitialized, "Uninitialized tree op.");
|
2009-09-21 15:43:43 +04:00
|
|
|
switch(mOpCode) {
|
|
|
|
case eTreeOpAddAttributes:
|
|
|
|
delete mTwo.attributes;
|
|
|
|
break;
|
|
|
|
case eTreeOpCreateElement:
|
|
|
|
delete mThree.attributes;
|
|
|
|
break;
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpAppendDoctypeToDocument:
|
2009-09-21 15:43:43 +04:00
|
|
|
delete mTwo.stringPair;
|
|
|
|
break;
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpFosterParentText:
|
|
|
|
case eTreeOpAppendText:
|
|
|
|
case eTreeOpAppendComment:
|
|
|
|
case eTreeOpAppendCommentToDocument:
|
2009-09-21 15:43:43 +04:00
|
|
|
delete[] mTwo.unicharPtr;
|
|
|
|
break;
|
2009-09-21 17:18:20 +04:00
|
|
|
case eTreeOpSetDocumentCharset:
|
|
|
|
case eTreeOpNeedsCharsetSwitchTo:
|
|
|
|
delete[] mOne.charPtr;
|
|
|
|
break;
|
2010-02-02 10:43:18 +03:00
|
|
|
case eTreeOpProcessOfflineManifest:
|
|
|
|
nsMemory::Free(mOne.unicharPtr);
|
|
|
|
break;
|
2009-09-21 15:43:43 +04:00
|
|
|
default: // keep the compiler happy
|
|
|
|
break;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendTextToTextNode(PRUnichar* aBuffer,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsIContent* aTextNode,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aTextNode, "Got null text node.");
|
|
|
|
|
|
|
|
if (aBuilder->HaveNotified(aTextNode)) {
|
|
|
|
// This text node has already been notified on, so it's necessary to
|
|
|
|
// notify on the append
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRUint32 oldLength = aTextNode->TextLength();
|
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
PR_TRUE,
|
|
|
|
oldLength,
|
|
|
|
oldLength,
|
|
|
|
aLength
|
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataWillChange(aTextNode, &info);
|
|
|
|
|
|
|
|
rv = aTextNode->AppendText(aBuffer, aLength, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsNodeUtils::CharacterDataChanged(aTextNode, &info);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aTextNode->AppendText(aBuffer, aLength, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendText(PRUnichar* aBuffer,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIContent* lastChild = aParent->GetLastChild();
|
|
|
|
if (lastChild && lastChild->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
nsHtml5OtherDocUpdate update(aParent->GetOwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
return AppendTextToTextNode(aBuffer,
|
|
|
|
aLength,
|
|
|
|
lastChild,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> text;
|
|
|
|
NS_NewTextNode(getter_AddRefs(text), aBuilder->GetNodeInfoManager());
|
|
|
|
NS_ASSERTION(text, "Infallible malloc failed?");
|
|
|
|
rv = text->SetText(aBuffer, aLength, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return Append(text, aParent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::Append(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIDocument* executorDoc = aBuilder->GetDocument();
|
|
|
|
NS_ASSERTION(executorDoc, "Null doc on executor");
|
|
|
|
nsIDocument* parentDoc = aParent->GetOwnerDoc();
|
|
|
|
NS_ASSERTION(parentDoc, "Null owner doc on old node.");
|
|
|
|
|
|
|
|
if (NS_LIKELY(executorDoc == parentDoc)) {
|
|
|
|
// the usual case. the parent is in the parser's doc
|
|
|
|
aBuilder->PostPendingAppendNotification(aParent, aNode);
|
|
|
|
rv = aParent->AppendChildTo(aNode, PR_FALSE);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The parent has been moved to another doc
|
|
|
|
parentDoc->BeginUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
|
|
|
|
PRUint32 childCount = aParent->GetChildCount();
|
|
|
|
rv = aParent->AppendChildTo(aNode, PR_FALSE);
|
|
|
|
nsNodeUtils::ContentAppended(aParent, childCount);
|
|
|
|
|
|
|
|
parentDoc->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendToDocument(nsIContent* aNode,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
|
|
|
nsIDocument* doc = aBuilder->GetDocument();
|
|
|
|
PRUint32 childCount = doc->GetChildCount();
|
|
|
|
rv = doc->AppendChildTo(aNode, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsNodeUtils::ContentInserted(doc, aNode, childCount);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsresult
|
2009-11-06 16:06:48 +03:00
|
|
|
nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
|
|
|
|
nsIContent** aScriptElement)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch(mOpCode) {
|
|
|
|
case eTreeOpAppend: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
2009-11-17 11:52:30 +03:00
|
|
|
return Append(node, parent, aBuilder);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
case eTreeOpDetach: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-06-29 02:44:22 +04:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* parent = node->GetParent();
|
2009-06-29 02:44:22 +04:00
|
|
|
if (parent) {
|
2009-11-11 11:37:35 +03:00
|
|
|
nsHtml5OtherDocUpdate update(parent->GetOwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUint32 pos = parent->IndexOf(node);
|
2009-06-29 02:44:22 +04:00
|
|
|
NS_ASSERTION((pos >= 0), "Element not found as child of its parent");
|
|
|
|
rv = parent->RemoveChildAt(pos, PR_TRUE, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpAppendChildrenToNewParent: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
2009-06-29 02:44:22 +04:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-11-11 11:37:35 +03:00
|
|
|
|
|
|
|
nsHtml5OtherDocUpdate update(parent->GetOwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUint32 childCount = parent->GetChildCount();
|
2009-06-29 02:44:22 +04:00
|
|
|
PRBool didAppend = PR_FALSE;
|
2009-09-21 15:43:43 +04:00
|
|
|
while (node->GetChildCount()) {
|
|
|
|
nsCOMPtr<nsIContent> child = node->GetChildAt(0);
|
|
|
|
rv = node->RemoveChildAt(0, PR_TRUE, PR_FALSE);
|
2009-06-29 02:44:22 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 15:43:43 +04:00
|
|
|
rv = parent->AppendChildTo(child, PR_FALSE);
|
2009-06-29 02:44:22 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
didAppend = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (didAppend) {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsNodeUtils::ContentAppended(parent, childCount);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpFosterParent: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
|
|
|
nsIContent* table = *(mThree.node);
|
|
|
|
nsIContent* foster = table->GetParent();
|
2009-11-11 11:37:35 +03:00
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
if (foster && foster->IsNodeOfType(nsINode::eELEMENT)) {
|
2009-06-29 02:44:22 +04:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-11-11 11:37:35 +03:00
|
|
|
|
|
|
|
nsHtml5OtherDocUpdate update(foster->GetOwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUint32 pos = foster->IndexOf(table);
|
|
|
|
rv = foster->InsertChildAt(node, pos, PR_FALSE);
|
2009-06-29 02:44:22 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 15:43:43 +04:00
|
|
|
nsNodeUtils::ContentInserted(foster, node, pos);
|
2009-11-11 11:37:35 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
return Append(node, parent, aBuilder);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
case eTreeOpAppendToDocument: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-11-17 11:52:30 +03:00
|
|
|
return AppendToDocument(node, aBuilder);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
case eTreeOpAddAttributes: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsHtml5HtmlAttributes* attributes = mTwo.attributes;
|
|
|
|
|
2009-11-11 11:37:35 +03:00
|
|
|
nsHtml5OtherDocUpdate update(node->GetOwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIDocument* document = node->GetCurrentDoc();
|
|
|
|
|
|
|
|
PRInt32 len = attributes->getLength();
|
2009-12-23 11:32:39 +03:00
|
|
|
for (PRInt32 i = len; i > 0;) {
|
|
|
|
--i;
|
2009-09-21 15:43:43 +04:00
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
|
|
|
nsCOMPtr<nsIAtom> localName = Reget(attributes->getLocalName(i));
|
|
|
|
PRInt32 nsuri = attributes->getURI(i);
|
|
|
|
if (!node->HasAttr(nsuri, localName)) {
|
|
|
|
|
2009-08-13 11:51:06 +04:00
|
|
|
// the manual notification code is based on nsGenericElement
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUint32 stateMask = PRUint32(node->IntrinsicState());
|
|
|
|
nsNodeUtils::AttributeWillChange(node,
|
2009-08-13 11:51:06 +04:00
|
|
|
nsuri,
|
|
|
|
localName,
|
|
|
|
static_cast<PRUint8>(nsIDOMMutationEvent::ADDITION));
|
2009-09-21 15:43:43 +04:00
|
|
|
|
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
|
|
|
node->SetAttr(nsuri, localName, attributes->getPrefix(i), *(attributes->getValue(i)), PR_FALSE);
|
|
|
|
// XXX what to do with nsresult?
|
2009-08-13 11:51:06 +04:00
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
if (document || node->HasFlag(NODE_FORCE_XBL_BINDINGS)) {
|
|
|
|
nsIDocument* ownerDoc = node->GetOwnerDoc();
|
2009-08-13 11:51:06 +04:00
|
|
|
if (ownerDoc) {
|
|
|
|
nsRefPtr<nsXBLBinding> binding =
|
2009-09-21 15:43:43 +04:00
|
|
|
ownerDoc->BindingManager()->GetBinding(node);
|
2009-08-13 11:51:06 +04:00
|
|
|
if (binding) {
|
|
|
|
binding->AttributeChanged(localName, nsuri, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
stateMask ^= PRUint32(node->IntrinsicState());
|
2009-08-13 11:51:06 +04:00
|
|
|
if (stateMask && document) {
|
|
|
|
MOZ_AUTO_DOC_UPDATE(document, UPDATE_CONTENT_STATE, PR_TRUE);
|
2009-09-21 15:43:43 +04:00
|
|
|
document->ContentStatesChanged(node, nsnull, stateMask);
|
2009-08-13 11:51:06 +04:00
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
nsNodeUtils::AttributeChanged(node,
|
2009-08-13 11:51:06 +04:00
|
|
|
nsuri,
|
|
|
|
localName,
|
2009-12-11 01:36:04 +03:00
|
|
|
static_cast<PRUint8>(nsIDOMMutationEvent::ADDITION));
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpCreateElement: {
|
|
|
|
nsIContent** target = mOne.node;
|
|
|
|
PRInt32 ns = mInt;
|
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mTwo.atom);
|
|
|
|
nsHtml5HtmlAttributes* attributes = mThree.attributes;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> newContent;
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo = aBuilder->GetNodeInfoManager()->GetNodeInfo(name, nsnull, ns);
|
|
|
|
NS_ASSERTION(nodeInfo, "Got null nodeinfo.");
|
|
|
|
NS_NewElement(getter_AddRefs(newContent), nodeInfo->NamespaceID(), nodeInfo, PR_TRUE);
|
|
|
|
NS_ASSERTION(newContent, "Element creation created null pointer.");
|
|
|
|
|
|
|
|
aBuilder->HoldElement(*target = newContent);
|
|
|
|
|
2009-10-30 11:31:57 +03:00
|
|
|
if (NS_UNLIKELY(name == nsHtml5Atoms::style || name == nsHtml5Atoms::link)) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(newContent));
|
|
|
|
if (ssle) {
|
|
|
|
ssle->InitStyleLinkElement(PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
if (!attributes) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 len = attributes->getLength();
|
2009-12-23 11:32:39 +03:00
|
|
|
for (PRInt32 i = len; i > 0;) {
|
|
|
|
--i;
|
2009-09-21 15:43:43 +04:00
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
|
|
|
nsCOMPtr<nsIAtom> localName = Reget(attributes->getLocalName(i));
|
|
|
|
newContent->SetAttr(attributes->getURI(i), localName, attributes->getPrefix(i), *(attributes->getValue(i)), PR_FALSE);
|
|
|
|
// XXX what to do with nsresult?
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpSetFormElement: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node));
|
2009-10-21 16:28:18 +04:00
|
|
|
// NS_ASSERTION(formControl, "Form-associated element did not implement nsIFormControl.");
|
|
|
|
// TODO: uncomment the above line when <output> (bug 346485) and <keygen> (bug 101019) are supported by Gecko
|
2009-09-21 15:43:43 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(parent));
|
|
|
|
NS_ASSERTION(formElement, "The form element doesn't implement nsIDOMHTMLFormElement.");
|
2009-10-21 16:28:18 +04:00
|
|
|
if (formControl) { // avoid crashing on <output> and <keygen>
|
2009-09-21 15:43:43 +04:00
|
|
|
formControl->SetForm(formElement);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpAppendText: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
|
|
|
PRInt32 length = mInt;
|
|
|
|
return AppendText(buffer, length, parent, aBuilder);
|
|
|
|
}
|
|
|
|
case eTreeOpFosterParentText: {
|
|
|
|
nsIContent* stackParent = *mOne.node;
|
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
|
|
|
PRInt32 length = mInt;
|
|
|
|
nsIContent* table = *mThree.node;
|
|
|
|
|
|
|
|
nsIContent* foster = table->GetParent();
|
|
|
|
|
|
|
|
if (foster && foster->IsNodeOfType(nsINode::eELEMENT)) {
|
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
|
|
|
|
|
|
|
nsHtml5OtherDocUpdate update(foster->GetOwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
|
|
|
PRUint32 pos = foster->IndexOf(table);
|
|
|
|
|
|
|
|
nsIContent* previousSibling = foster->GetChildAt(pos - 1);
|
|
|
|
if (previousSibling && previousSibling->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
return AppendTextToTextNode(buffer,
|
|
|
|
length,
|
|
|
|
previousSibling,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> text;
|
|
|
|
NS_NewTextNode(getter_AddRefs(text), aBuilder->GetNodeInfoManager());
|
|
|
|
NS_ASSERTION(text, "Infallible malloc failed?");
|
|
|
|
rv = text->SetText(buffer, length, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = foster->InsertChildAt(text, pos, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsNodeUtils::ContentInserted(foster, text, pos);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppendText(buffer, length, stackParent, aBuilder);
|
|
|
|
}
|
|
|
|
case eTreeOpAppendComment: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
|
|
|
PRInt32 length = mInt;
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
nsCOMPtr<nsIContent> comment;
|
|
|
|
NS_NewCommentNode(getter_AddRefs(comment), aBuilder->GetNodeInfoManager());
|
|
|
|
NS_ASSERTION(comment, "Infallible malloc failed?");
|
|
|
|
rv = comment->SetText(buffer, length, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 15:43:43 +04:00
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
return Append(comment, parent, aBuilder);
|
2009-09-21 15:43:43 +04:00
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpAppendCommentToDocument: {
|
2009-09-21 15:43:43 +04:00
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
|
|
|
PRInt32 length = mInt;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> comment;
|
|
|
|
NS_NewCommentNode(getter_AddRefs(comment), aBuilder->GetNodeInfoManager());
|
2009-11-17 11:52:30 +03:00
|
|
|
NS_ASSERTION(comment, "Infallible malloc failed?");
|
|
|
|
rv = comment->SetText(buffer, length, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 15:43:43 +04:00
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
return AppendToDocument(comment, aBuilder);
|
2009-09-21 15:43:43 +04:00
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpAppendDoctypeToDocument: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mOne.atom);
|
|
|
|
nsHtml5TreeOperationStringPair* pair = mTwo.stringPair;
|
|
|
|
nsString publicId;
|
|
|
|
nsString systemId;
|
|
|
|
pair->Get(publicId, systemId);
|
|
|
|
|
|
|
|
// Adapted from nsXMLContentSink
|
|
|
|
// Create a new doctype node
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
nsAutoString voidString;
|
|
|
|
voidString.SetIsVoid(PR_TRUE);
|
|
|
|
NS_NewDOMDocumentType(getter_AddRefs(docType),
|
|
|
|
aBuilder->GetNodeInfoManager(),
|
|
|
|
nsnull,
|
|
|
|
name,
|
|
|
|
nsnull,
|
|
|
|
nsnull,
|
|
|
|
publicId,
|
|
|
|
systemId,
|
|
|
|
voidString);
|
|
|
|
NS_ASSERTION(docType, "Doctype creation failed.");
|
|
|
|
nsCOMPtr<nsIContent> asContent = do_QueryInterface(docType);
|
2009-11-17 11:52:30 +03:00
|
|
|
return AppendToDocument(asContent, aBuilder);
|
2009-09-21 15:43:43 +04:00
|
|
|
}
|
|
|
|
case eTreeOpRunScript: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2009-09-21 17:18:20 +04:00
|
|
|
nsAHtml5TreeBuilderState* snapshot = mTwo.state;
|
|
|
|
if (snapshot) {
|
2009-10-28 16:48:37 +03:00
|
|
|
aBuilder->InitializeDocWriteParserState(snapshot, mInt);
|
2009-09-21 17:18:20 +04:00
|
|
|
}
|
2009-11-06 16:06:48 +03:00
|
|
|
*aScriptElement = node;
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2009-12-14 16:51:15 +03:00
|
|
|
case eTreeOpRunScriptAsyncDefer: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
aBuilder->RunScript(node);
|
|
|
|
return rv;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
case eTreeOpDoneAddingChildren: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
node->DoneAddingChildren(aBuilder->HaveNotified(node));
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpDoneCreatingElement: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
node->DoneCreatingElement();
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2009-11-06 16:06:48 +03:00
|
|
|
case eTreeOpFlushPendingAppendNotifications: {
|
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
|
|
|
return rv;
|
|
|
|
}
|
2009-09-21 17:18:20 +04:00
|
|
|
case eTreeOpSetDocumentCharset: {
|
|
|
|
char* str = mOne.charPtr;
|
|
|
|
nsDependentCString dependentString(str);
|
|
|
|
aBuilder->SetDocumentCharset(dependentString);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpNeedsCharsetSwitchTo: {
|
|
|
|
char* str = mOne.charPtr;
|
|
|
|
aBuilder->NeedsCharsetSwitchTo(str);
|
|
|
|
return rv;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
case eTreeOpUpdateStyleSheet: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-10-30 11:31:57 +03:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-09-21 15:43:43 +04:00
|
|
|
aBuilder->UpdateStyleSheet(node);
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpProcessBase: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
rv = aBuilder->ProcessBASETag(node);
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpProcessMeta: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
rv = aBuilder->ProcessMETATag(node);
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpProcessOfflineManifest: {
|
2010-02-02 10:43:18 +03:00
|
|
|
PRUnichar* str = mOne.unicharPtr;
|
|
|
|
nsDependentString dependentString(str);
|
|
|
|
aBuilder->ProcessOfflineManifest(dependentString);
|
2009-09-21 15:43:43 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpMarkMalformedIfScript: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(node);
|
|
|
|
if (sele) {
|
|
|
|
// Make sure to serialize this script correctly, for nice round tripping.
|
|
|
|
sele->SetIsMalformed();
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-21 17:18:20 +04:00
|
|
|
case eTreeOpStreamEnded: {
|
2009-11-06 16:06:48 +03:00
|
|
|
aBuilder->DidBuildModel(PR_FALSE); // this causes a notifications flush anyway
|
2009-09-21 17:18:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
case eTreeOpStartLayout: {
|
2009-11-06 16:06:48 +03:00
|
|
|
aBuilder->StartLayout(); // this causes a notification flush anyway
|
2009-06-29 02:44:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
case eTreeOpDocumentMode: {
|
2009-09-21 15:43:43 +04:00
|
|
|
aBuilder->DocumentMode(mOne.mode);
|
2009-09-18 13:21:47 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2009-10-28 16:48:37 +03:00
|
|
|
case eTreeOpSetStyleLineNumber: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(node);
|
|
|
|
NS_ASSERTION(ssle, "Node didn't QI to style.");
|
|
|
|
ssle->SetLineNumber(mInt);
|
|
|
|
return rv;
|
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpSetScriptLineNumberAndFreeze: {
|
2009-10-28 16:48:37 +03:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(node);
|
|
|
|
NS_ASSERTION(sele, "Node didn't QI to script.");
|
|
|
|
sele->SetScriptLineNumber(mInt);
|
2009-11-17 11:52:30 +03:00
|
|
|
sele->FreezeUriAsyncDefer();
|
2009-10-28 16:48:37 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
default: {
|
|
|
|
NS_NOTREACHED("Bogus tree op");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv; // keep compiler happy
|
|
|
|
}
|