зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1581523: part 1) Remove hack for Thunderbird which parses `nsPlainTextSerializer::mWrapColumn` from `<body>`'s style. r=hsivonen,jorgk
`TextEditor::SetWrapWidth` already sets `nsIDocumentEncoder`'s wrap column which is propagated to `nsPlainTextSerializer`. So this should be a safe change. Differential Revision: https://phabricator.services.mozilla.com/D46008 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
3ba04bcead
Коммит
404c0dae7b
|
@ -684,8 +684,6 @@ nsresult nsPlainTextSerializer::DoOpenContainer(const nsAtom* aTag) {
|
|||
// Trigger on the presence of a "pre-wrap" in the
|
||||
// style attribute. That's a very simplistic way to do
|
||||
// it, but better than nothing.
|
||||
// Also set mWrapColumn to the value given there
|
||||
// (which arguably we should only do if told to do so).
|
||||
nsAutoString style;
|
||||
int32_t whitespace;
|
||||
if (NS_SUCCEEDED(GetAttributeValue(nsGkAtoms::style, style)) &&
|
||||
|
@ -695,28 +693,6 @@ nsresult nsPlainTextSerializer::DoOpenContainer(const nsAtom* aTag) {
|
|||
printf("Set mPreFormattedMail based on style pre-wrap\n");
|
||||
#endif
|
||||
mPreFormattedMail = true;
|
||||
int32_t widthOffset = style.Find("width:");
|
||||
if (widthOffset >= 0) {
|
||||
// We have to search for the ch before the semicolon,
|
||||
// not for the semicolon itself, because nsString::ToInteger()
|
||||
// considers 'c' to be a valid numeric char (even if radix=10)
|
||||
// but then gets confused if it sees it next to the number
|
||||
// when the radix specified was 10, and returns an error code.
|
||||
int32_t semiOffset = style.Find("ch", false, widthOffset + 6);
|
||||
int32_t length = (semiOffset > 0 ? semiOffset - widthOffset - 6
|
||||
: style.Length() - widthOffset);
|
||||
nsAutoString widthstr;
|
||||
style.Mid(widthstr, widthOffset + 6, length);
|
||||
nsresult err;
|
||||
int32_t col = widthstr.ToInteger(&err);
|
||||
|
||||
if (NS_SUCCEEDED(err)) {
|
||||
mWrapColumn = (uint32_t)col;
|
||||
#ifdef DEBUG_preformatted
|
||||
printf("Set wrap column to %d based on style\n", mWrapColumn);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} else if (kNotFound != style.Find("pre", true, whitespace)) {
|
||||
#ifdef DEBUG_preformatted
|
||||
printf("Set mPreFormattedMail based on style pre\n");
|
||||
|
|
|
@ -12,9 +12,11 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsIParserUtils.h"
|
||||
|
||||
void ConvertBufToPlainText(nsString& aConBuf, int aFlag) {
|
||||
const uint32_t kDefaultWrapColumn = 72;
|
||||
|
||||
void ConvertBufToPlainText(nsString& aConBuf, int aFlag, uint32_t aWrapColumn) {
|
||||
nsCOMPtr<nsIParserUtils> utils = do_GetService(NS_PARSERUTILS_CONTRACTID);
|
||||
utils->ConvertToPlainText(aConBuf, aFlag, 72, aConBuf);
|
||||
utils->ConvertToPlainText(aConBuf, aFlag, aWrapColumn, aConBuf);
|
||||
}
|
||||
|
||||
// Test for ASCII with format=flowed; delsp=yes
|
||||
|
@ -30,11 +32,13 @@ TEST(PlainTextSerializer, ASCIIWithFlowedDelSp)
|
|||
"Firefox Firefox Firefox Firefox"
|
||||
"</body></html>");
|
||||
|
||||
ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted |
|
||||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed |
|
||||
nsIDocumentEncoder::OutputFormatDelSp);
|
||||
ConvertBufToPlainText(test,
|
||||
nsIDocumentEncoder::OutputFormatted |
|
||||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed |
|
||||
nsIDocumentEncoder::OutputFormatDelSp,
|
||||
kDefaultWrapColumn);
|
||||
|
||||
// create result case
|
||||
result.AssignLiteral(
|
||||
|
@ -59,11 +63,13 @@ TEST(PlainTextSerializer, CJKWithFlowedDelSp)
|
|||
}
|
||||
test.AppendLiteral("</body></html>");
|
||||
|
||||
ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted |
|
||||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed |
|
||||
nsIDocumentEncoder::OutputFormatDelSp);
|
||||
ConvertBufToPlainText(test,
|
||||
nsIDocumentEncoder::OutputFormatted |
|
||||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed |
|
||||
nsIDocumentEncoder::OutputFormatDelSp,
|
||||
kDefaultWrapColumn);
|
||||
|
||||
// create result case
|
||||
for (uint32_t i = 0; i < 36; i++) {
|
||||
|
@ -97,7 +103,8 @@ TEST(PlainTextSerializer, CJKWithDisallowLineBreaking)
|
|||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed |
|
||||
nsIDocumentEncoder::OutputDisallowLineBreaking);
|
||||
nsIDocumentEncoder::OutputDisallowLineBreaking,
|
||||
kDefaultWrapColumn);
|
||||
|
||||
// create result case
|
||||
for (uint32_t i = 0; i < 400; i++) {
|
||||
|
@ -125,10 +132,12 @@ TEST(PlainTextSerializer, PreformatFlowedQuotes)
|
|||
">> Firefox Firefox Firefox Firefox<br>"
|
||||
"</span></body></html>");
|
||||
|
||||
ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted |
|
||||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed);
|
||||
ConvertBufToPlainText(test,
|
||||
nsIDocumentEncoder::OutputFormatted |
|
||||
nsIDocumentEncoder::OutputCRLineBreak |
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
nsIDocumentEncoder::OutputFormatFlowed,
|
||||
kDefaultWrapColumn);
|
||||
|
||||
// create result case
|
||||
result.AssignLiteral(
|
||||
|
@ -151,7 +160,7 @@ TEST(PlainTextSerializer, PrettyPrintedHtml)
|
|||
" first<br>" NS_LINEBREAK " second<br>" NS_LINEBREAK
|
||||
"</body>" NS_LINEBREAK "</html>");
|
||||
|
||||
ConvertBufToPlainText(test, 0);
|
||||
ConvertBufToPlainText(test, 0, kDefaultWrapColumn);
|
||||
ASSERT_TRUE(test.EqualsLiteral("first" NS_LINEBREAK "second" NS_LINEBREAK))
|
||||
<< "Wrong prettyprinted html to text serialization";
|
||||
}
|
||||
|
@ -164,7 +173,7 @@ TEST(PlainTextSerializer, PreElement)
|
|||
" second" NS_LINEBREAK "</pre>" NS_LINEBREAK
|
||||
"</body>" NS_LINEBREAK "</html>");
|
||||
|
||||
ConvertBufToPlainText(test, 0);
|
||||
ConvertBufToPlainText(test, 0, kDefaultWrapColumn);
|
||||
ASSERT_TRUE(test.EqualsLiteral(" first" NS_LINEBREAK
|
||||
" second" NS_LINEBREAK NS_LINEBREAK))
|
||||
<< "Wrong prettyprinted html to text serialization";
|
||||
|
@ -179,7 +188,7 @@ TEST(PlainTextSerializer, BlockElement)
|
|||
" second" NS_LINEBREAK "</div>" NS_LINEBREAK
|
||||
"</body>" NS_LINEBREAK "</html>");
|
||||
|
||||
ConvertBufToPlainText(test, 0);
|
||||
ConvertBufToPlainText(test, 0, kDefaultWrapColumn);
|
||||
ASSERT_TRUE(test.EqualsLiteral("first" NS_LINEBREAK "second" NS_LINEBREAK))
|
||||
<< "Wrong prettyprinted html to text serialization";
|
||||
}
|
||||
|
@ -188,14 +197,15 @@ TEST(PlainTextSerializer, PreWrapElementForThunderbird)
|
|||
{
|
||||
// This test examines the magic pre-wrap setup that Thunderbird relies on.
|
||||
nsString test;
|
||||
test.AppendLiteral(
|
||||
"<html>" NS_LINEBREAK
|
||||
"<body style=\"white-space: pre-wrap; width: 10ch;\">" NS_LINEBREAK
|
||||
"<pre>" NS_LINEBREAK " first line is too long" NS_LINEBREAK
|
||||
" second line is even loooonger " NS_LINEBREAK "</pre>" NS_LINEBREAK
|
||||
"</body>" NS_LINEBREAK "</html>");
|
||||
test.AppendLiteral("<html>" NS_LINEBREAK
|
||||
"<body style=\"white-space: pre-wrap;\">" NS_LINEBREAK
|
||||
"<pre>" NS_LINEBREAK
|
||||
" first line is too long" NS_LINEBREAK
|
||||
" second line is even loooonger " NS_LINEBREAK
|
||||
"</pre>" NS_LINEBREAK "</body>" NS_LINEBREAK "</html>");
|
||||
|
||||
ConvertBufToPlainText(test, nsIDocumentEncoder::OutputWrap);
|
||||
const uint32_t wrapColumn = 10;
|
||||
ConvertBufToPlainText(test, nsIDocumentEncoder::OutputWrap, wrapColumn);
|
||||
// "\n\n first\nline is\ntoo long\n second\nline is\neven\nloooonger\n\n\n"
|
||||
ASSERT_TRUE(test.EqualsLiteral(
|
||||
NS_LINEBREAK NS_LINEBREAK
|
||||
|
@ -211,7 +221,7 @@ TEST(PlainTextSerializer, Simple)
|
|||
test.AppendLiteral(
|
||||
"<html><base>base</base><head><span>span</span></head>"
|
||||
"<body>body</body></html>");
|
||||
ConvertBufToPlainText(test, 0);
|
||||
ConvertBufToPlainText(test, 0, kDefaultWrapColumn);
|
||||
ASSERT_TRUE(test.EqualsLiteral("basespanbody"))
|
||||
<< "Wrong html to text serialization";
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче