--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -68,17 +68,17 @@ nsXMLContentSerializer::nsXMLContentSeri
}
nsXMLContentSerializer::~nsXMLContentSerializer()
{
}
NS_IMPL_ISUPPORTS(nsXMLContentSerializer, nsIContentSerializer)
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
const char* aCharSet, bool aIsCopying,
bool aRewriteEncodingDeclaration)
{
mPrefixIndex = 0;
mColPos = 0;
mIndentOverflow = 0;
mIsIndentationAddedOnCurrentLine = false;
@@ -147,17 +147,17 @@ nsXMLContentSerializer::AppendTextData(n
NS_ASSERTION(aStartOffset >= 0, "Negative start offset for text fragment!");
NS_ASSERTION(aStartOffset <= endoffset, "A start offset is beyond the end of the text fragment!");
if (length <= 0) {
// XXX Zero is a legal value, maybe non-zero values should be an
// error.
return NS_OK;
}
-
+
if (frag->Is2b()) {
const char16_t *strStart = frag->Get2b() + aStartOffset;
if (aTranslateEntities) {
NS_ENSURE_TRUE(AppendAndTranslateEntities(Substring(strStart, strStart + length), aStr),
NS_ERROR_OUT_OF_MEMORY);
}
else {
NS_ENSURE_TRUE(aStr.Append(Substring(strStart, strStart + length), mozilla::fallible),
@@ -173,17 +173,17 @@ nsXMLContentSerializer::AppendTextData(n
NS_ENSURE_TRUE(aStr.Append(NS_ConvertASCIItoUTF16(frag->Get1b()+aStartOffset, length), mozilla::fallible),
NS_ERROR_OUT_OF_MEMORY);
}
}
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendText(nsIContent* aText,
int32_t aStartOffset,
int32_t aEndOffset,
nsAString& aStr)
{
NS_ENSURE_ARG(aText);
nsAutoString data;
@@ -204,17 +204,17 @@ nsXMLContentSerializer::AppendText(nsICo
}
else {
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
}
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendCDATASection(nsIContent* aCDATASection,
int32_t aStartOffset,
int32_t aEndOffset,
nsAString& aStr)
{
NS_ENSURE_ARG(aCDATASection);
nsresult rv;
@@ -239,17 +239,17 @@ nsXMLContentSerializer::AppendCDATASecti
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("]]>"), aStr), NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendProcessingInstruction(nsIContent* aPI,
int32_t aStartOffset,
int32_t aEndOffset,
nsAString& aStr)
{
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(aPI);
NS_ENSURE_ARG(pi);
nsresult rv;
@@ -288,17 +288,17 @@ nsXMLContentSerializer::AppendProcessing
}
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("?>"), aStr), NS_ERROR_OUT_OF_MEMORY);
MaybeFlagNewlineForRootNode(aPI);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendComment(nsIContent* aComment,
int32_t aStartOffset,
int32_t aEndOffset,
nsAString& aStr)
{
nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(aComment);
NS_ENSURE_ARG(comment);
nsresult rv;
@@ -345,17 +345,17 @@ nsXMLContentSerializer::AppendComment(ns
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("-->"), aStr), NS_ERROR_OUT_OF_MEMORY);
MaybeFlagNewlineForRootNode(aComment);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendDoctype(nsIContent* aDocType,
nsAString& aStr)
{
nsCOMPtr<nsIDOMDocumentType> docType = do_QueryInterface(aDocType);
NS_ENSURE_ARG(docType);
nsresult rv;
nsAutoString name, publicId, systemId, internalSubset;
@@ -406,23 +406,23 @@ nsXMLContentSerializer::AppendDoctype(ns
else {
quote = char16_t('\'');
}
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(" SYSTEM "), aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(systemId, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
}
-
+
if (!internalSubset.IsEmpty()) {
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(" ["), aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(internalSubset, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(char16_t(']'), aStr), NS_ERROR_OUT_OF_MEMORY);
}
-
+
NS_ENSURE_TRUE(AppendToString(kGreaterThan, aStr), NS_ERROR_OUT_OF_MEMORY);
MaybeFlagNewlineForRootNode(aDocType);
return NS_OK;
}
nsresult
nsXMLContentSerializer::PushNameSpaceDecl(const nsAString& aPrefix,
@@ -511,17 +511,17 @@ nsXMLContentSerializer::ConfirmPrefix(ns
if (!haveSeenOurPrefix && aURI.Equals(decl.mURI)) {
// Just use our uriMatch stuff. That will deal with an empty aPrefix
// the right way. We can break out of the loop now, though.
uriMatch = true;
closestURIMatch = aPrefix;
break;
}
- haveSeenOurPrefix = true;
+ haveSeenOurPrefix = true;
// If they don't, and either:
// 1) We have a prefix (so we'd be redeclaring this prefix to point to a
// different namespace) or
// 2) We're looking at an existing default namespace decl on aElement (so
// we can't create a new default namespace decl for this URI)
// then generate a new prefix. Note that we do NOT generate new prefixes
// if we happen to have aPrefix == decl->mPrefix == "" and mismatching
@@ -539,51 +539,51 @@ nsXMLContentSerializer::ConfirmPrefix(ns
// against the full namespace stack again. Note that just restarting
// the while loop is ok, since we haven't changed aURI, so the
// closestURIMatch and uriMatch state is not affected.
index = count - 1;
haveSeenOurPrefix = false;
continue;
}
}
-
+
// If we've found a URI match, then record the first one
if (!uriMatch && aURI.Equals(decl.mURI)) {
// Need to check that decl->mPrefix is not declared anywhere closer to
// us. If it is, we can't use it.
bool prefixOK = true;
int32_t index2;
for (index2 = count-1; index2 > index && prefixOK; --index2) {
prefixOK = (mNameSpaceStack[index2].mPrefix != decl.mPrefix);
}
-
+
if (prefixOK) {
uriMatch = true;
closestURIMatch.Assign(decl.mPrefix);
}
}
-
+
--index;
}
// At this point the following invariants hold:
// 1) The prefix in closestURIMatch is mapped to aURI in our scope if
// uriMatch is set.
// 2) There is nothing on the namespace stack that has aPrefix as the prefix
// and a _different_ URI, except for the case aPrefix.IsEmpty (and
// possible default namespaces on ancestors)
-
+
// So if uriMatch is set it's OK to use the closestURIMatch prefix. The one
// exception is when closestURIMatch is actually empty (default namespace
// decl) and we must have a prefix.
if (uriMatch && (!mustHavePrefix || !closestURIMatch.IsEmpty())) {
aPrefix.Assign(closestURIMatch);
return false;
}
-
+
if (aPrefix.IsEmpty()) {
// At this point, aPrefix is empty (which means we never had a prefix to
// start with). If we must have a prefix, just generate a new prefix and
// then send it back through the namespace stack checks to make sure it's
// OK.
if (mustHavePrefix) {
GenerateNewPrefix(aPrefix);
return ConfirmPrefix(aPrefix, aURI, aElement, aIsAttribute);
@@ -649,17 +649,17 @@ nsXMLContentSerializer::SerializeAttr(co
}
else {
// Depending on whether the attribute value contains quotes or apostrophes we
// need to select the delimiter character and escape characters using
// character entity references, ignoring the value of aDoEscapeEntities.
// See http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2.2 for
// the standard on character entity references in values. We also have to
// make sure to escape any '&' characters.
-
+
bool bIncludesSingle = false;
bool bIncludesDouble = false;
nsAString::const_iterator iCurr, iEnd;
uint32_t uiSize, i;
aValue.BeginReading(iCurr);
aValue.EndReading(iEnd);
for ( ; iCurr != iEnd; iCurr.advance(uiSize) ) {
const char16_t * buf = iCurr.get();
@@ -681,17 +681,17 @@ nsXMLContentSerializer::SerializeAttr(co
}
// Delimiter and escaping is according to the following table
// bIncludesDouble bIncludesSingle Delimiter Escape Double Quote
// FALSE FALSE " FALSE
// FALSE TRUE " FALSE
// TRUE FALSE ' FALSE
// TRUE TRUE " TRUE
- char16_t cDelimiter =
+ char16_t cDelimiter =
(bIncludesDouble && !bIncludesSingle) ? char16_t('\'') : char16_t('"');
NS_ENSURE_TRUE(attrString.Append(char16_t('='), mozilla::fallible), false);
NS_ENSURE_TRUE(attrString.Append(cDelimiter, mozilla::fallible), false);
nsAutoString sValue(aValue);
NS_ENSURE_TRUE(sValue.ReplaceSubstring(NS_LITERAL_STRING("&"),
NS_LITERAL_STRING("&"), mozilla::fallible), false);
if (bIncludesDouble && bIncludesSingle) {
NS_ENSURE_TRUE(sValue.ReplaceSubstring(NS_LITERAL_STRING("\""),
@@ -711,43 +711,45 @@ nsXMLContentSerializer::SerializeAttr(co
}
else {
NS_ENSURE_TRUE(AppendToStringConvertLF(attrString, aStr), false);
}
return true;
}
-uint32_t
+uint32_t
nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
nsIContent *aOriginalElement,
const nsAString& aTagNamespaceURI)
{
uint32_t index, count;
nsAutoString uriStr, valueStr;
count = aContent->GetAttrCount();
// First scan for namespace declarations, pushing each on the stack
uint32_t skipAttr = count;
for (index = 0; index < count; index++) {
-
- const nsAttrName* name = aContent->GetAttrNameAt(index);
+
+ const nsAttrInfo info = aContent->GetAttrInfoAt(index);
+ const nsAttrName* name = info.mName;
+
int32_t namespaceID = name->NamespaceID();
nsIAtom *attrName = name->LocalName();
-
+
if (namespaceID == kNameSpaceID_XMLNS ||
// Also push on the stack attrs named "xmlns" in the null
// namespace... because once we serialize those out they'll look like
// namespace decls. :(
// XXXbz what if we have both "xmlns" in the null namespace and "xmlns"
// in the xmlns namespace?
(namespaceID == kNameSpaceID_None &&
attrName == nsGkAtoms::xmlns)) {
- aContent->GetAttr(namespaceID, attrName, uriStr);
+ info.mValue->ToString(uriStr);
if (!name->GetPrefix()) {
if (aTagNamespaceURI.IsEmpty() && !uriStr.IsEmpty()) {
// If the element is in no namespace we need to add a xmlns
// attribute to declare that. That xmlns attribute must not have a
// prefix (see http://www.w3.org/TR/REC-xml-names/#dt-prefix), ie it
// must declare the default namespace. We just found an xmlns
// attribute that declares the default namespace to something
@@ -860,36 +862,36 @@ nsXMLContentSerializer::SerializeAttribu
prefixStr.Truncate();
}
bool addNSAttr = false;
if (kNameSpaceID_XMLNS != namespaceID) {
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID, uriStr);
addNSAttr = ConfirmPrefix(prefixStr, uriStr, aOriginalElement, true);
}
-
+
aContent->GetAttr(namespaceID, attrName, valueStr);
nsDependentAtomString nameStr(attrName);
bool isJS = IsJavaScript(aContent, attrName, namespaceID, valueStr);
NS_ENSURE_TRUE(SerializeAttr(prefixStr, nameStr, valueStr, aStr, !isJS), false);
-
+
if (addNSAttr) {
NS_ASSERTION(!prefixStr.IsEmpty(),
"Namespaced attributes must have a prefix");
NS_ENSURE_TRUE(SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, true), false);
PushNameSpaceDecl(prefixStr, uriStr, aOriginalElement);
}
}
return true;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendElementStart(Element* aElement,
Element* aOriginalElement,
nsAString& aStr)
{
NS_ENSURE_ARG(aElement);
nsIContent* content = aElement;
@@ -1021,17 +1023,17 @@ nsXMLContentSerializer::AppendEndOfEleme
if (!AppendToString(kSpace, aStr)) {
return false;
}
}
return AppendToString(NS_LITERAL_STRING("/>"), aStr);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsXMLContentSerializer::AppendElementEnd(Element* aElement,
nsAString& aStr)
{
NS_ENSURE_ARG(aElement);
nsIContent* content = aElement;
bool forceFormat = false, outputElementEnd;
@@ -1045,17 +1047,17 @@ nsXMLContentSerializer::AppendElementEnd
if (!outputElementEnd) {
PopNameSpaceDeclsFor(aElement);
MaybeFlagNewlineForRootNode(aElement);
return NS_OK;
}
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
-
+
aElement->NodeInfo()->GetPrefix(tagPrefix);
aElement->NodeInfo()->GetName(tagLocalName);
aElement->NodeInfo()->GetNamespaceURI(tagNamespaceURI);
#ifdef DEBUG
bool debugNeedToPushNamespace =
#endif
ConfirmPrefix(tagPrefix, tagNamespaceURI, aElement, false);
@@ -1116,17 +1118,17 @@ nsXMLContentSerializer::AppendDocumentSt
aDocument->GetXMLDeclaration(version, encoding, standalone);
if (version.IsEmpty())
return NS_OK; // A declaration must have version, or there is no decl
NS_NAMED_LITERAL_STRING(endQuote, "\"");
aStr += NS_LITERAL_STRING("<?xml version=\"") + version + endQuote;
-
+
if (!mCharset.IsEmpty()) {
aStr += NS_LITERAL_STRING(" encoding=\"") +
NS_ConvertASCIItoUTF16(mCharset) + endQuote;
}
// Otherwise just don't output an encoding attr. Not that we expect
// mCharset to ever be empty.
#ifdef DEBUG
else {
@@ -1362,29 +1364,29 @@ nsXMLContentSerializer::DecrIndentation(
}
bool
nsXMLContentSerializer::LineBreakBeforeOpen(int32_t aNamespaceID, nsIAtom* aName)
{
return mAddSpace;
}
-bool
+bool
nsXMLContentSerializer::LineBreakAfterOpen(int32_t aNamespaceID, nsIAtom* aName)
{
return false;
}
-bool
+bool
nsXMLContentSerializer::LineBreakBeforeClose(int32_t aNamespaceID, nsIAtom* aName)
{
return mAddSpace;
}
-bool
+bool
nsXMLContentSerializer::LineBreakAfterClose(int32_t aNamespaceID, nsIAtom* aName)
{
return false;
}
bool
nsXMLContentSerializer::AppendToStringConvertLF(const nsAString& aStr,
nsAString& aOutputStr)
@@ -1576,21 +1578,21 @@ nsXMLContentSerializer::AppendWrapped_No
// We have not yet reached the max column, we will continue to
// fill the current line in the next outer loop iteration
// (this one in AppendToStringWrapped)
// make sure we return in this outer loop
onceAgainBecauseWeAddedBreakInFront = false;
}
else { // we reach the max column
if (!thisSequenceStartsAtBeginningOfLine &&
- (mAddSpace || (!mDoFormat && aSequenceStartAfterAWhiteSpace))) {
+ (mAddSpace || (!mDoFormat && aSequenceStartAfterAWhiteSpace))) {
// when !mDoFormat, mAddSpace is not used, mAddSpace is always false
// so, in the case where mDoWrap && !mDoFormat, if we want to enter in this condition...
- // We can avoid to wrap. We try to add the whole block
+ // We can avoid to wrap. We try to add the whole block
// in an empty new line
NS_ENSURE_TRUE(AppendNewLineToString(aOutputStr), false);
aPos = aSequenceStart;
thisSequenceStartsAtBeginningOfLine = true;
onceAgainBecauseWeAddedBreakInFront = true;
}
else {