From 83d378bf95664d1daf37c8be0ebe2e45a7836cb7 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Mon, 7 Feb 2005 17:24:05 +0000 Subject: [PATCH] Fix the HTML serializer to not do fancy linebreaking when "raw" output is requested. Use this in innerHTML. Bug 89780, r+sr=peterv git-svn-id: svn://10.0.0.236/trunk@168919 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocumentEncoder.h | 13 ++++++++++++- .../content/base/src/nsHTMLContentSerializer.cpp | 12 ++++++------ .../html/content/src/nsGenericHTMLElement.cpp | 5 ++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/mozilla/content/base/public/nsIDocumentEncoder.h b/mozilla/content/base/public/nsIDocumentEncoder.h index 54cacc92cf6..06bbf1f10d1 100644 --- a/mozilla/content/base/public/nsIDocumentEncoder.h +++ b/mozilla/content/base/public/nsIDocumentEncoder.h @@ -117,23 +117,34 @@ public: // (Probably not well tested for HTML output.) OutputFormatted = 2, - // OutputRaw is used by copying text from widgets + // Don't do prettyprinting of HTML. Don't do any wrapping that's not in + // the existing HTML source. This option overrides OutputFormatted if both + // are set. Note that this option does not affect entity conversion. OutputRaw = 4, // No html head tags OutputBodyOnly = 8, // Wrap even if we're not doing formatted output (e.g. for text fields) + // XXXbz this doesn't seem to be used by all serializers... document? How + // does this interact with + // OutputFormatted/OutputRaw/OutputWrap/OutputFormatFlowed? OutputPreformatted = 16, // Output as though the content is preformatted // (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag) + // XXXbz this doesn't seem to be used by all serializers... document? How + // does this interact with + // OutputFormatted/OutputRaw/OutputPreformatted/OutputFormatFlowed? OutputWrap = 32, // Output for format flowed (RFC 2646). This is used when converting // to text for mail sending. This differs just slightly // but in an important way from normal formatted, and that is that // lines are space stuffed. This can't (correctly) be done later. + // XXXbz this doesn't seem to be used by all serializers... document? How + // does this interact with + // OutputFormatted/OutputRaw/OutputPreformatted/OutputWrap? OutputFormatFlowed = 64, // Convert links, image src, and script src to absolute URLs when possible diff --git a/mozilla/content/base/src/nsHTMLContentSerializer.cpp b/mozilla/content/base/src/nsHTMLContentSerializer.cpp index 7575afffbf0..8beab61fa5f 100644 --- a/mozilla/content/base/src/nsHTMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsHTMLContentSerializer.cpp @@ -189,6 +189,12 @@ nsHTMLContentSerializer::AppendText(nsIDOMText* aText, if (mPreLevel > 0) { AppendToStringConvertLF(data, aStr); } + else if (mFlags & nsIDocumentEncoder::OutputRaw) { + PRInt32 lastNewlineOffset = data.RFindChar('\n'); + AppendToString(data, aStr); + if (lastNewlineOffset != kNotFound) + mColPos = data.Length() - lastNewlineOffset; + } else if (!mDoFormat) { PRInt32 lastNewlineOffset = kNotFound; PRBool hasLongLines = HasLongLines(data, lastNewlineOffset); @@ -202,12 +208,6 @@ nsHTMLContentSerializer::AppendText(nsIDOMText* aText, AppendToStringConvertLF(data, aStr); } } - else if (mFlags & nsIDocumentEncoder::OutputRaw) { - PRInt32 lastNewlineOffset = data.RFindChar('\n'); - AppendToString(data, aStr); - if (lastNewlineOffset != kNotFound) - mColPos = data.Length() - lastNewlineOffset; - } else { AppendToStringWrapped(data, aStr, PR_FALSE); } diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index fc6e5740ce5..f9d61601cb3 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -888,7 +888,10 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML) docEncoder->Init(doc, NS_LITERAL_STRING("text/html"), nsIDocumentEncoder::OutputEncodeBasicEntities | - nsIDocumentEncoder::OutputLFLineBreak); + // Output DOM-standard newlines + nsIDocumentEncoder::OutputLFLineBreak | + // Don't do linebreaking that's not present in the source + nsIDocumentEncoder::OutputRaw); nsCOMPtr range(new nsRange); NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);