From 56cd24d21e327b28590275e71de3b0cfe13d26a1 Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Mon, 22 Feb 2010 14:17:30 +0200 Subject: [PATCH] Bug 545854 - Add the macro to the HTML5 parser. r=bnewman. --HG-- extra : rebase_source : afd36441c60abba7453fd91c32beec4e6e1fd17b --- content/base/src/nsGkAtomList.h | 1 + parser/html/nsHtml5TreeOperation.cpp | 48 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index a43c9583c5b..66f0dae49fd 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -63,6 +63,7 @@ GK_ATOM(_empty, "") GK_ATOM(moz, "_moz") +GK_ATOM(moztype, "_moz-type") GK_ATOM(mozdirty, "_moz_dirty") GK_ATOM(mozeditorbogusnode, "_moz_editor_bogus_node") GK_ATOM(mozgeneratedcontentbefore, "_moz_generated_content_before") diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index f9770238ddd..0b80189f22a 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -58,6 +58,10 @@ #include "nsIStyleSheetLinkingElement.h" #include "nsIDOMDocumentType.h" #include "nsIMutationObserver.h" +#include "nsIFormProcessor.h" +#include "nsIServiceManager.h" + +static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID); /** * Helper class that opens a notification batch if the current doc @@ -363,6 +367,11 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder, nsCOMPtr name = Reget(mTwo.atom); nsHtml5HtmlAttributes* attributes = mThree.attributes; + PRBool isKeygen = (name == nsHtml5Atoms::keygen && ns == kNameSpaceID_XHTML); + if (NS_UNLIKELY(isKeygen)) { + name = nsHtml5Atoms::select; + } + nsCOMPtr newContent; nsCOMPtr nodeInfo = aBuilder->GetNodeInfoManager()->GetNodeInfo(name, nsnull, ns); NS_ASSERTION(nodeInfo, "Got null nodeinfo."); @@ -377,6 +386,44 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder, ssle->InitStyleLinkElement(PR_FALSE); ssle->SetEnableUpdates(PR_FALSE); } + } else if (NS_UNLIKELY(isKeygen)) { + // Adapted from CNavDTD + nsCOMPtr theFormProcessor = + do_GetService(kFormProcessorCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsTArray theContent; + nsAutoString theAttribute; + + (void) theFormProcessor->ProvideContent(NS_LITERAL_STRING("select"), + theContent, + theAttribute); + + newContent->SetAttr(kNameSpaceID_None, + nsGkAtoms::moztype, + nsnull, + theAttribute, + PR_FALSE); + + nsCOMPtr optionNodeInfo = + aBuilder->GetNodeInfoManager()->GetNodeInfo(nsHtml5Atoms::option, + nsnull, + kNameSpaceID_XHTML); + + for (PRUint32 i = 0; i < theContent.Length(); ++i) { + nsCOMPtr optionElt; + NS_NewElement(getter_AddRefs(optionElt), + optionNodeInfo->NamespaceID(), + optionNodeInfo, + PR_TRUE); + nsCOMPtr 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); + } } if (!attributes) { @@ -392,6 +439,7 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder, newContent->SetAttr(attributes->getURI(i), localName, attributes->getPrefix(i), *(attributes->getValue(i)), PR_FALSE); // XXX what to do with nsresult? } + return rv; } case eTreeOpSetFormElement: {