mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Backed out changeset 55f62128b50b (bug 1577425) for bustages complaining about nsPlainTextSerializer.h CLOSED TREE
This commit is contained in:
parent
e0b09c55fe
commit
19972acbe5
@ -105,6 +105,7 @@ static void DetermineLineBreak(const int32_t aFlags, nsAString& aLineBreak) {
|
||||
nsPlainTextSerializer::CurrentLineContent::CurrentLineContent(
|
||||
const int32_t aFlags)
|
||||
: mFlags(aFlags) {
|
||||
DetermineLineBreak(mFlags, mLineBreak);
|
||||
}
|
||||
|
||||
void nsPlainTextSerializer::CurrentLineContent::MaybeReplaceNbsps() {
|
||||
@ -115,28 +116,8 @@ void nsPlainTextSerializer::CurrentLineContent::MaybeReplaceNbsps() {
|
||||
}
|
||||
}
|
||||
|
||||
nsPlainTextSerializer::OutputManager::OutputManager(const int32_t aFlags,
|
||||
nsAString& aOutput)
|
||||
: mOutput{aOutput}, mAtFirstColumn{true} {
|
||||
MOZ_ASSERT(aOutput.IsEmpty());
|
||||
|
||||
DetermineLineBreak(aFlags, mLineBreak);
|
||||
}
|
||||
|
||||
void nsPlainTextSerializer::OutputManager::Append(const nsAString& aString) {
|
||||
if (!aString.IsEmpty()) {
|
||||
mOutput.Append(aString);
|
||||
mAtFirstColumn = false;
|
||||
}
|
||||
}
|
||||
|
||||
void nsPlainTextSerializer::OutputManager::AppendLineBreak() {
|
||||
mOutput.Append(mLineBreak);
|
||||
mAtFirstColumn = true;
|
||||
}
|
||||
|
||||
uint32_t nsPlainTextSerializer::OutputManager::GetOutputLength() const {
|
||||
return mOutput.Length();
|
||||
void nsPlainTextSerializer::CurrentLineContent::AppendLineBreak() {
|
||||
mValue.Append(mLineBreak);
|
||||
}
|
||||
|
||||
nsPlainTextSerializer::nsPlainTextSerializer()
|
||||
@ -145,7 +126,9 @@ nsPlainTextSerializer::nsPlainTextSerializer()
|
||||
mLineBreakDue(false),
|
||||
kSpace(NS_LITERAL_STRING(" ")) // Init of "constant"
|
||||
{
|
||||
mOutput = nullptr;
|
||||
mHeadLevel = 0;
|
||||
mAtFirstColumn = true;
|
||||
mIndent = 0;
|
||||
mCiteQuoteLevel = 0;
|
||||
mHasWrittenCiteBlockquote = false;
|
||||
@ -232,9 +215,9 @@ nsPlainTextSerializer::Init(const uint32_t aFlags, uint32_t aWrapColumn,
|
||||
"Can't do formatted and preformatted output at the same time!");
|
||||
}
|
||||
#endif
|
||||
mOutput = &aOutput;
|
||||
*aNeedsPreformatScanning = true;
|
||||
mSettings.Init(aFlags);
|
||||
mOutputManager.emplace(mSettings.GetFlags(), aOutput);
|
||||
mWrapColumn = aWrapColumn;
|
||||
|
||||
if (MayWrap() && MayBreakLines()) {
|
||||
@ -307,6 +290,8 @@ static bool IsIgnorableScriptOrStyle(Element* aElement) {
|
||||
NS_IMETHODIMP
|
||||
nsPlainTextSerializer::AppendText(nsIContent* aText, int32_t aStartOffset,
|
||||
int32_t aEndOffset) {
|
||||
NS_ENSURE_STATE(mOutput);
|
||||
|
||||
if (mIgnoreAboveIndex != (uint32_t)kNotFound) {
|
||||
return NS_OK;
|
||||
}
|
||||
@ -403,6 +388,7 @@ NS_IMETHODIMP
|
||||
nsPlainTextSerializer::AppendElementStart(Element* aElement,
|
||||
Element* aOriginalElement) {
|
||||
NS_ENSURE_ARG(aElement);
|
||||
NS_ENSURE_STATE(mOutput);
|
||||
|
||||
mElement = aElement;
|
||||
|
||||
@ -430,6 +416,7 @@ NS_IMETHODIMP
|
||||
nsPlainTextSerializer::AppendElementEnd(Element* aElement,
|
||||
Element* aOriginalElement) {
|
||||
NS_ENSURE_ARG(aElement);
|
||||
NS_ENSURE_STATE(mOutput);
|
||||
|
||||
mElement = aElement;
|
||||
|
||||
@ -461,16 +448,18 @@ nsPlainTextSerializer::FlushAndFinish() {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlainTextSerializer::Finish() {
|
||||
mOutputManager.reset();
|
||||
NS_ENSURE_STATE(mOutput);
|
||||
|
||||
mOutput = nullptr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlainTextSerializer::GetOutputLength(uint32_t& aLength) const {
|
||||
MOZ_ASSERT(mOutputManager);
|
||||
NS_ENSURE_STATE(mOutput);
|
||||
|
||||
aLength = mOutputManager->GetOutputLength();
|
||||
aLength = mOutput->Length();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1138,19 +1127,24 @@ void nsPlainTextSerializer::EnsureVerticalSpace(int32_t noOfRows) {
|
||||
*/
|
||||
void nsPlainTextSerializer::FlushLine() {
|
||||
if (!mCurrentLineContent.mValue.IsEmpty()) {
|
||||
MOZ_ASSERT(mOutputManager);
|
||||
|
||||
if (mOutputManager->IsAtFirstColumn()) {
|
||||
if (mAtFirstColumn) {
|
||||
OutputQuotesAndIndent(); // XXX: Should we always do this? Bug?
|
||||
}
|
||||
|
||||
mCurrentLineContent.MaybeReplaceNbsps();
|
||||
mOutputManager->Append(mCurrentLineContent.mValue);
|
||||
Output(mCurrentLineContent.mValue);
|
||||
mAtFirstColumn = false;
|
||||
mCurrentLineContent.mValue.Truncate();
|
||||
mCurrentLineContent.mWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void nsPlainTextSerializer::Output(nsString& aString) {
|
||||
MOZ_ASSERT(mOutput);
|
||||
|
||||
mOutput->Append(aString);
|
||||
}
|
||||
|
||||
static bool IsSpaceStuffable(const char16_t* s) {
|
||||
if (s[0] == '>' || s[0] == ' ' || s[0] == kNBSP ||
|
||||
NS_strncmp(s, u"From ", 5) == 0)
|
||||
@ -1393,9 +1387,7 @@ void nsPlainTextSerializer::EndLine(bool aSoftlinebreak, bool aBreakBySpace) {
|
||||
mEmptyLines++;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mOutputManager);
|
||||
|
||||
if (mOutputManager->IsAtFirstColumn()) {
|
||||
if (mAtFirstColumn) {
|
||||
// If we don't have anything "real" to output we have to
|
||||
// make sure the indent doesn't end in a space since that
|
||||
// would trick a format=flowed-aware receiver.
|
||||
@ -1404,10 +1396,11 @@ void nsPlainTextSerializer::EndLine(bool aSoftlinebreak, bool aBreakBySpace) {
|
||||
}
|
||||
|
||||
mCurrentLineContent.MaybeReplaceNbsps();
|
||||
mOutputManager->Append(mCurrentLineContent.mValue);
|
||||
mOutputManager->AppendLineBreak();
|
||||
mCurrentLineContent.AppendLineBreak();
|
||||
Output(mCurrentLineContent.mValue);
|
||||
mCurrentLineContent.mValue.Truncate();
|
||||
mCurrentLineContent.mWidth = 0;
|
||||
mAtFirstColumn = true;
|
||||
mInWhitespace = true;
|
||||
mLineBreakDue = false;
|
||||
mFloatingLines = -1;
|
||||
@ -1420,8 +1413,6 @@ void nsPlainTextSerializer::EndLine(bool aSoftlinebreak, bool aBreakBySpace) {
|
||||
*/
|
||||
void nsPlainTextSerializer::OutputQuotesAndIndent(
|
||||
bool stripTrailingSpaces /* = false */) {
|
||||
MOZ_ASSERT(mOutputManager);
|
||||
|
||||
nsAutoString stringToOutput;
|
||||
|
||||
// Put the mail quote "> " chars in, if appropriate:
|
||||
@ -1466,7 +1457,8 @@ void nsPlainTextSerializer::OutputQuotesAndIndent(
|
||||
}
|
||||
|
||||
if (!stringToOutput.IsEmpty()) {
|
||||
mOutputManager->Append(stringToOutput);
|
||||
Output(stringToOutput);
|
||||
mAtFirstColumn = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1538,9 +1530,7 @@ void nsPlainTextSerializer::Write(const nsAString& aStr) {
|
||||
// Put the mail quote "> " chars in, if appropriate.
|
||||
// Have to put it in before every line.
|
||||
while (bol < totLen) {
|
||||
MOZ_ASSERT(mOutputManager);
|
||||
|
||||
const bool outputQuotes = mOutputManager->IsAtFirstColumn();
|
||||
const bool outputQuotes = mAtFirstColumn;
|
||||
bool outputLineBreak = false;
|
||||
bool spacesOnly = true;
|
||||
|
||||
@ -1605,17 +1595,17 @@ void nsPlainTextSerializer::Write(const nsAString& aStr) {
|
||||
mCurrentLineContent.mValue.Append(stringpart);
|
||||
|
||||
if (outputQuotes) {
|
||||
// Note: this call messes with mAtFirstColumn
|
||||
OutputQuotesAndIndent();
|
||||
}
|
||||
|
||||
mCurrentLineContent.MaybeReplaceNbsps();
|
||||
|
||||
MOZ_ASSERT(mOutputManager);
|
||||
|
||||
mOutputManager->Append(mCurrentLineContent.mValue);
|
||||
if (outputLineBreak) {
|
||||
mOutputManager->AppendLineBreak();
|
||||
mCurrentLineContent.AppendLineBreak();
|
||||
}
|
||||
Output(mCurrentLineContent.mValue);
|
||||
|
||||
mAtFirstColumn = outputLineBreak;
|
||||
}
|
||||
|
||||
// Reset mCurrentLineContent.mValue.
|
||||
|
@ -15,7 +15,6 @@
|
||||
#define nsPlainTextSerializer_h__
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/intl/LineBreaker.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAtom.h"
|
||||
@ -151,6 +150,7 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
|
||||
|
||||
private:
|
||||
uint32_t mHeadLevel;
|
||||
bool mAtFirstColumn;
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
@ -203,6 +203,8 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
|
||||
|
||||
void MaybeReplaceNbsps();
|
||||
|
||||
void AppendLineBreak();
|
||||
|
||||
nsString mValue;
|
||||
|
||||
// The width of the line as it will appear on the screen (approx.).
|
||||
@ -211,38 +213,11 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
|
||||
private:
|
||||
// As defined in nsIDocumentEncoder.idl.
|
||||
int32_t mFlags;
|
||||
};
|
||||
|
||||
CurrentLineContent mCurrentLineContent;
|
||||
|
||||
class OutputManager {
|
||||
public:
|
||||
/**
|
||||
* @param aFlags As defined in nsIDocumentEncoder.idl.
|
||||
* @param aOutput An empty string.
|
||||
*/
|
||||
OutputManager(int32_t aFlags, nsAString& aOutput);
|
||||
|
||||
/**
|
||||
* @param aString Last character is expected to not be a line break.
|
||||
*/
|
||||
void Append(const nsAString& aString);
|
||||
|
||||
void AppendLineBreak();
|
||||
|
||||
bool IsAtFirstColumn() const { return mAtFirstColumn; }
|
||||
|
||||
uint32_t GetOutputLength() const;
|
||||
|
||||
private:
|
||||
nsAString& mOutput;
|
||||
|
||||
bool mAtFirstColumn;
|
||||
|
||||
nsString mLineBreak;
|
||||
};
|
||||
|
||||
Maybe<OutputManager> mOutputManager;
|
||||
CurrentLineContent mCurrentLineContent;
|
||||
|
||||
// If we've just written out a cite blockquote, we need to remember it
|
||||
// so we don't duplicate spaces before a <pre wrap> (which mail uses to quote
|
||||
|
Loading…
Reference in New Issue
Block a user