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"
|
2010-08-28 09:54:57 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2009-11-17 11:52:30 +03:00
|
|
|
#include "nsIMutationObserver.h"
|
2010-02-22 15:17:30 +03:00
|
|
|
#include "nsIFormProcessor.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2010-07-30 14:08:36 +04:00
|
|
|
#include "nsEscape.h"
|
2010-08-24 11:06:07 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-07-19 02:07:54 +04:00
|
|
|
#include "nsHtml5SVGLoadDispatcher.h"
|
|
|
|
|
2010-08-24 11:06:07 +04:00
|
|
|
namespace dom = mozilla::dom;
|
|
|
|
|
2010-02-22 15:17:30 +03:00
|
|
|
static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
|
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;
|
2010-06-09 10:44:25 +04:00
|
|
|
case eTreeOpCreateElementNetwork:
|
|
|
|
case eTreeOpCreateElementNotNetwork:
|
2009-09-21 15:43:43 +04:00
|
|
|
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 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
|
2010-06-11 19:08:13 +04:00
|
|
|
nsHtml5TreeOperation::AppendTextToTextNode(const PRUnichar* aBuffer,
|
2011-08-22 23:35:19 +04:00
|
|
|
PRUint32 aLength,
|
2009-11-17 11:52:30 +03:00
|
|
|
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
|
2010-06-11 19:08:13 +04:00
|
|
|
nsHtml5TreeOperation::AppendText(const PRUnichar* aBuffer,
|
2011-08-22 23:35:19 +04:00
|
|
|
PRUint32 aLength,
|
2009-11-17 11:52:30 +03:00
|
|
|
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
|
|
|
|
rv = aParent->AppendChildTo(aNode, PR_FALSE);
|
2011-07-21 00:22:27 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aBuilder->PostPendingAppendNotification(aParent, aNode);
|
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
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);
|
2011-07-21 00:22:27 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsNodeUtils::ContentAppended(aParent, aNode, childCount);
|
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
parentDoc->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-08-28 09:54:57 +04:00
|
|
|
class nsDocElementCreatedNotificationRunner : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDocElementCreatedNotificationRunner(nsIDocument* aDoc)
|
|
|
|
: mDoc(aDoc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsContentSink::NotifyDocElementCreated(mDoc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> mDoc;
|
|
|
|
};
|
|
|
|
|
2009-11-17 11:52:30 +03:00
|
|
|
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);
|
2010-08-28 09:54:57 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Someone forgot to block scripts");
|
2011-04-08 10:07:28 +04:00
|
|
|
if (aNode->IsElement()) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsDocElementCreatedNotificationRunner(doc));
|
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
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");
|
2011-05-25 21:58:23 +04:00
|
|
|
rv = parent->RemoveChildAt(pos, PR_TRUE);
|
2009-06-29 02:44:22 +04:00
|
|
|
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);
|
2011-05-25 21:58:23 +04:00
|
|
|
rv = node->RemoveChildAt(0, PR_TRUE);
|
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) {
|
2010-05-11 05:12:34 +04:00
|
|
|
nsNodeUtils::ContentAppended(parent, parent->GetChildAt(childCount),
|
|
|
|
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
|
|
|
|
2010-04-30 17:12:06 +04:00
|
|
|
if (foster && foster->IsElement()) {
|
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: {
|
2010-08-24 11:06:07 +04:00
|
|
|
dom::Element* node = (*(mOne.node))->AsElement();
|
2009-09-21 15:43:43 +04:00
|
|
|
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
|
|
|
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)) {
|
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
2011-05-25 21:58:23 +04:00
|
|
|
node->SetAttr(nsuri, localName, attributes->getPrefix(i), *(attributes->getValue(i)), PR_TRUE);
|
2009-09-21 15:43:43 +04:00
|
|
|
// XXX what to do with nsresult?
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2010-06-09 10:44:25 +04:00
|
|
|
case eTreeOpCreateElementNetwork:
|
|
|
|
case eTreeOpCreateElementNotNetwork: {
|
2009-09-21 15:43:43 +04:00
|
|
|
nsIContent** target = mOne.node;
|
|
|
|
PRInt32 ns = mInt;
|
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mTwo.atom);
|
|
|
|
nsHtml5HtmlAttributes* attributes = mThree.attributes;
|
|
|
|
|
2010-02-22 15:17:30 +03:00
|
|
|
PRBool isKeygen = (name == nsHtml5Atoms::keygen && ns == kNameSpaceID_XHTML);
|
|
|
|
if (NS_UNLIKELY(isKeygen)) {
|
|
|
|
name = nsHtml5Atoms::select;
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
nsCOMPtr<nsIContent> newContent;
|
2011-06-14 11:56:49 +04:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo = aBuilder->GetNodeInfoManager()->
|
|
|
|
GetNodeInfo(name, nsnull, ns, nsIDOMNode::ELEMENT_NODE);
|
2009-09-21 15:43:43 +04:00
|
|
|
NS_ASSERTION(nodeInfo, "Got null nodeinfo.");
|
2010-06-09 10:44:25 +04:00
|
|
|
NS_NewElement(getter_AddRefs(newContent),
|
2010-07-23 13:49:57 +04:00
|
|
|
ns, nodeInfo.forget(),
|
2010-06-09 10:44:25 +04:00
|
|
|
(mOpCode == eTreeOpCreateElementNetwork ?
|
2010-10-25 16:17:38 +04:00
|
|
|
dom::FROM_PARSER_NETWORK
|
2010-06-09 10:44:25 +04:00
|
|
|
: (aBuilder->IsFragmentMode() ?
|
2010-10-25 16:17:38 +04:00
|
|
|
dom::FROM_PARSER_FRAGMENT :
|
|
|
|
dom::FROM_PARSER_DOCUMENT_WRITE)));
|
2009-09-21 15:43:43 +04:00
|
|
|
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);
|
|
|
|
}
|
2010-02-22 15:17:30 +03:00
|
|
|
} else if (NS_UNLIKELY(isKeygen)) {
|
|
|
|
// Adapted from CNavDTD
|
|
|
|
nsCOMPtr<nsIFormProcessor> theFormProcessor =
|
|
|
|
do_GetService(kFormProcessorCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsTArray<nsString> theContent;
|
|
|
|
nsAutoString theAttribute;
|
|
|
|
|
|
|
|
(void) theFormProcessor->ProvideContent(NS_LITERAL_STRING("select"),
|
|
|
|
theContent,
|
|
|
|
theAttribute);
|
|
|
|
|
|
|
|
newContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::moztype,
|
|
|
|
nsnull,
|
|
|
|
theAttribute,
|
|
|
|
PR_FALSE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> optionNodeInfo =
|
|
|
|
aBuilder->GetNodeInfoManager()->GetNodeInfo(nsHtml5Atoms::option,
|
|
|
|
nsnull,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-02-22 15:17:30 +03:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < theContent.Length(); ++i) {
|
|
|
|
nsCOMPtr<nsIContent> optionElt;
|
2010-07-23 13:49:57 +04:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = optionNodeInfo;
|
2010-02-22 15:17:30 +03:00
|
|
|
NS_NewElement(getter_AddRefs(optionElt),
|
|
|
|
optionNodeInfo->NamespaceID(),
|
2010-07-23 13:49:57 +04:00
|
|
|
ni.forget(),
|
2010-10-25 16:17:38 +04:00
|
|
|
(mOpCode == eTreeOpCreateElementNetwork ?
|
|
|
|
dom::FROM_PARSER_NETWORK
|
|
|
|
: (aBuilder->IsFragmentMode() ?
|
|
|
|
dom::FROM_PARSER_FRAGMENT :
|
|
|
|
dom::FROM_PARSER_DOCUMENT_WRITE)));
|
2010-02-22 15:17:30 +03:00
|
|
|
nsCOMPtr<nsIContent> optionText;
|
|
|
|
NS_NewTextNode(getter_AddRefs(optionText),
|
|
|
|
aBuilder->GetNodeInfoManager());
|
|
|
|
(void) optionText->SetText(theContent[i], PR_FALSE);
|
|
|
|
optionElt->AppendChildTo(optionText, PR_FALSE);
|
|
|
|
newContent->AppendChildTo(optionElt, PR_FALSE);
|
|
|
|
newContent->DoneAddingChildren(PR_FALSE);
|
|
|
|
}
|
2010-02-22 15:17:33 +03:00
|
|
|
} else if (name == nsHtml5Atoms::frameset && ns == kNameSpaceID_XHTML) {
|
|
|
|
nsIDocument* doc = aBuilder->GetDocument();
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc);
|
|
|
|
if (htmlDocument) {
|
|
|
|
// It seems harmless to call this multiple times, since this
|
|
|
|
// is a simple field setter
|
|
|
|
htmlDocument->SetIsFrameset(PR_TRUE);
|
|
|
|
}
|
2009-10-30 11:31:57 +03:00
|
|
|
}
|
|
|
|
|
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));
|
2010-07-30 14:08:36 +04:00
|
|
|
if (ns == kNameSpaceID_XHTML &&
|
|
|
|
nsHtml5Atoms::a == name &&
|
|
|
|
nsHtml5Atoms::name == localName) {
|
|
|
|
// This is an HTML5-incompliant Geckoism.
|
|
|
|
// Remove when fixing bug 582361
|
|
|
|
NS_ConvertUTF16toUTF8 cname(*(attributes->getValue(i)));
|
|
|
|
NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting()));
|
|
|
|
newContent->SetAttr(attributes->getURI(i), localName,
|
|
|
|
attributes->getPrefix(i), uv, PR_FALSE);
|
|
|
|
} else {
|
|
|
|
newContent->SetAttr(attributes->getURI(i), localName,
|
|
|
|
attributes->getPrefix(i), *(attributes->getValue(i)), PR_FALSE);
|
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
}
|
2010-02-22 15:17:30 +03:00
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
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.");
|
2010-08-24 05:11:04 +04:00
|
|
|
// TODO: uncomment the above line when <keygen> (bug 101019) is 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.");
|
2010-08-24 05:11:04 +04:00
|
|
|
// avoid crashing on <keygen>
|
|
|
|
if (formControl &&
|
|
|
|
!node->HasAttr(kNameSpaceID_None, nsGkAtoms::form)) {
|
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;
|
2011-08-22 23:35:19 +04:00
|
|
|
PRUint32 length = mInt;
|
2009-11-17 11:52:30 +03:00
|
|
|
return AppendText(buffer, length, parent, aBuilder);
|
|
|
|
}
|
2010-06-11 19:08:13 +04:00
|
|
|
case eTreeOpAppendIsindexPrompt: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
|
|
|
nsXPIDLString prompt;
|
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"IsIndexPromptWithSpace", prompt);
|
|
|
|
PRUint32 len = prompt.Length();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (!len) {
|
|
|
|
// Don't bother appending a zero-length text node.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return AppendText(prompt.BeginReading(), len, parent, aBuilder);
|
|
|
|
}
|
2009-11-17 11:52:30 +03:00
|
|
|
case eTreeOpFosterParentText: {
|
|
|
|
nsIContent* stackParent = *mOne.node;
|
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
2011-08-22 23:35:19 +04:00
|
|
|
PRUint32 length = mInt;
|
2009-11-17 11:52:30 +03:00
|
|
|
nsIContent* table = *mThree.node;
|
|
|
|
|
|
|
|
nsIContent* foster = table->GetParent();
|
|
|
|
|
2010-04-30 17:12:06 +04:00
|
|
|
if (foster && foster->IsElement()) {
|
2009-11-17 11:52:30 +03:00
|
|
|
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,
|
|
|
|
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 eTreeOpNeedsCharsetSwitchTo: {
|
|
|
|
char* str = mOne.charPtr;
|
2011-02-11 13:33:32 +03:00
|
|
|
PRInt32 charsetSource = mInt;
|
|
|
|
aBuilder->NeedsCharsetSwitchTo(str, charsetSource);
|
2009-09-21 17:18:20 +04:00
|
|
|
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 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: {
|
2010-03-15 15:04:42 +03:00
|
|
|
aBuilder->SetDocumentMode(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;
|
|
|
|
}
|
2010-07-19 02:07:54 +04:00
|
|
|
case eTreeOpSvgLoad: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(node);
|
|
|
|
if (NS_FAILED(NS_DispatchToMainThread(event))) {
|
|
|
|
NS_WARNING("failed to dispatch svg load dispatcher");
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
default: {
|
|
|
|
NS_NOTREACHED("Bogus tree op");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv; // keep compiler happy
|
|
|
|
}
|