Revise the doc encoder and content sink APIs yet again to make it easier

to add new flags (pass a flag in the constructor, rather than specific
booleans.  This in order to fix:
11249: Add flag to write only the body in html output.
This commit is contained in:
akkana%netscape.com 1999-08-24 18:30:19 +00:00
parent 081a7cb41b
commit ff7a19a5bd
28 changed files with 266 additions and 295 deletions

View File

@ -51,19 +51,27 @@ class nsIDocumentEncoder : public nsISupports
{
public:
/**
* Output methods flag bits:
*/
enum {
OutputSelectionOnly = 1,
OutputFormatted = 2,
OutputNoDoctype = 4,
OutputBodyOnly = 8
};
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
/**
* Initialize with a pointer to the document and the mime type.
*
*/
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, const nsString& aMimeType) = 0;
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, const nsString& aMimeType, PRUint32 flags) = 0;
/**
* If the selection is set to a non-null value, then the
* selection is used for encoding, otherwise the entire
* document is encoded.
*
*/
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection) = 0;
@ -75,22 +83,27 @@ public:
* character set when encoding the document.
*
* Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER
*
*/
NS_IMETHOD SetCharset(const nsString& aCharset) = 0;
/**
* Set a wrap column. This may have no effect in some types of encoders.
*/
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
/**
* The document is encoded, the result is sent to the
* to nsIOutputStream.
*
* Possible result codes are passing along whatever stream errors
* might have been encountered.
*
*/
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream) = 0;
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
};
// XXXXXXXXXXXXXXXX nsITextEncoder is going away! XXXXXXXXXXXXXXXXXXXXXX
#ifdef USE_OBSOLETE_TEXT_ENCODER
// Example of a output service for a particular encoder.
// The text encoder handles XIF, HTML, and plaintext.
class nsITextEncoder : public nsIDocumentEncoder
@ -104,6 +117,7 @@ public:
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
NS_IMETHOD AddHeader(PRBool aYes) = 0;
};
#endif /* USE_OBSOLETE_TEXT_ENCODER */
#endif /* nsIDocumentEncoder_h__ */

View File

@ -2675,7 +2675,7 @@ void nsDocument::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
converter.AddStartTag("section_body");
nsIDOMElement* root = nsnull;
if (NS_OK == GetDocumentElement(&root))
if (NS_SUCCEEDED(GetDocumentElement(&root)))
{
#if 1
ToXIF(converter,root);
@ -2752,10 +2752,10 @@ nsDocument::OutputDocumentAs(nsIOutputStream* aStream, nsIDOMSelection* selectio
switch (aOutputFormat)
{
case eOutputText:
rv = NS_New_HTMLToTXT_SinkStream(getter_AddRefs(sink), aStream, &charsetStr);
rv = NS_New_HTMLToTXT_SinkStream(getter_AddRefs(sink), aStream, &charsetStr, 0);
break;
case eOutputHTML:
rv = NS_New_HTML_ContentSinkStream(getter_AddRefs(sink), aStream, &charsetStr);
rv = NS_New_HTML_ContentSinkStream(getter_AddRefs(sink), aStream, &charsetStr, 0);
break;
default:
rv = NS_ERROR_INVALID_ARG;

View File

@ -38,7 +38,7 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCTextEncoderCID, NS_TEXT_ENCODER_CID);
class nsTextEncoder : public nsITextEncoder
class nsTextEncoder : public nsIDocumentEncoder
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
@ -47,30 +47,32 @@ public:
virtual ~nsTextEncoder();
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
const nsString& aMimeType);
const nsString& aMimeType, PRUint32 aFlags);
/* Interfaces for addref and release and queryinterface */
NS_DECL_ISUPPORTS
// Inherited methods from nsIDocument
// Inherited methods from nsIDocumentEncoder
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD SetCharset(const nsString& aCharset);
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
NS_IMETHOD EncodeToString(nsString& aOutputString);
NS_IMETHOD PrettyPrint(PRBool aYes);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD AddHeader(PRBool aYes);
protected:
// Local methods to the text encoder -- used to be in nsITextEncoder,
// but that interface is obsolete now.
//NS_IMETHOD PrettyPrint(PRBool aYes);
//NS_IMETHOD AddHeader(PRBool aYes);
private:
nsIDocument* mDocument;
nsIDOMSelection* mSelection;
nsIPresShell* mPresShell;
nsString mMimeType;
nsString mCharset;
PRBool mPrettyPrint;
PRUint32 mFlags;
PRUint32 mWrapColumn;
PRBool mAddHeader;
};
@ -83,7 +85,6 @@ nsTextEncoder::nsTextEncoder() : mMimeType("text/plain")
mDocument = 0;
mSelection = 0;
mPresShell = 0;
mAddHeader = PR_FALSE;
}
nsTextEncoder::~nsTextEncoder()
@ -95,7 +96,7 @@ nsTextEncoder::~nsTextEncoder()
NS_IMETHODIMP
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
const nsString& aMimeType)
const nsString& aMimeType, PRUint32 aFlags)
{
if (!aDocument)
return NS_ERROR_INVALID_ARG;
@ -108,6 +109,9 @@ nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
mPresShell = aPresShell;
NS_ADDREF(aPresShell);
mMimeType = aMimeType;
mFlags = aFlags;
return NS_OK;
}
@ -133,13 +137,6 @@ nsresult nsTextEncoder::QueryInterface(REFNSIID aIID,
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::PrettyPrint(PRBool aYes)
{
mPrettyPrint = aYes;
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::SetWrapColumn(PRUint32 aWC)
{
@ -147,13 +144,6 @@ nsTextEncoder::SetWrapColumn(PRUint32 aWC)
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::AddHeader(PRBool aYes)
{
mAddHeader = aYes;
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
{
@ -209,13 +199,11 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
nsIHTMLContentSink* sink = nsnull;
if (mMimeType == "text/html")
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
PR_FALSE,
mSelection ? PR_FALSE : mAddHeader );
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString, mFlags);
else // default to text/plain
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
mWrapColumn, mPrettyPrint);
mWrapColumn, mFlags);
if (sink && NS_SUCCEEDED(rv))
{
@ -270,17 +258,15 @@ nsTextEncoder::EncodeToStream(nsIOutputStream* aStream)
kCParserIID,
(void **)&parser);
if (NS_OK == rv) {
if (NS_SUCCEEDED(rv)) {
nsIHTMLContentSink* sink = nsnull;
if (mMimeType == "text/html")
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset,
PR_FALSE,
mSelection ? PR_FALSE : mAddHeader);
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset, mFlags);
else
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
mWrapColumn, mPrettyPrint);
mWrapColumn, mFlags);
if (sink && NS_SUCCEEDED(rv))
{

View File

@ -469,7 +469,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
#ifdef rickgdebug
nsString outString; // added out. Redirect to stdout if desired -- gpk 04/01/99
rv = NS_New_HTML_ContentSinkStream(&sink,&outString);
rv = NS_New_HTML_ContentSinkStream(&sink,&outString,0);
#else
NS_PRECONDITION(nsnull != aContainer, "No content viewer container");
aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);

View File

@ -33,6 +33,7 @@
#include "nsIDOMNSUIEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIEditorMailSupport.h"
#include "nsIDocumentEncoder.h"
// for repainting hack only
#include "nsIView.h"
@ -356,7 +357,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
else
format = "text/html";
res = mEditor->OutputToString(output, format,
nsEditor::EditorOutputFormatted);
nsIDocumentEncoder::OutputFormatted);
if (NS_SUCCEEDED(res))
{
char* buf = output.ToNewCString();

View File

@ -3078,7 +3078,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
}
else
{ // default processing
nsCOMPtr<nsITextEncoder> encoder;
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = new char[strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1];
if (! progid)
return NS_ERROR_OUT_OF_MEMORY;
@ -3109,24 +3109,19 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
rv = GetPresShell(getter_AddRefs(shell));
if (NS_FAILED(rv))
return rv;
rv = encoder->Init(shell, doc, aFormatType);
rv = encoder->Init(shell, doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
if (aFlags & EditorOutputSelectionOnly)
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsIDOMSelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
nsCOMPtr<nsIDOMSelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// Try to set pretty printing, but don't panic if it doesn't work:
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
? PR_TRUE : PR_FALSE);
// Indicate whether we want the comment and doctype headers prepended:
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
? PR_FALSE : PR_TRUE);
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
@ -3156,7 +3151,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
PRUint32 aFlags)
{
nsresult rv;
nsCOMPtr<nsITextEncoder> encoder;
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = new char[strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1];
if (! progid)
return NS_ERROR_OUT_OF_MEMORY;
@ -3190,42 +3185,37 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
rv = GetPresShell(getter_AddRefs(shell));
if (NS_SUCCEEDED(rv)) {
rv = encoder->Init(shell,doc, aFormatType);
rv = encoder->Init(shell,doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
}
if (aFlags & EditorOutputSelectionOnly)
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsIDOMSelection> selection;
nsCOMPtr<nsIDOMSelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// Try to set pretty printing, but don't panic if it doesn't work:
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
? PR_TRUE : PR_FALSE);
// Indicate whether we want the comment and doc type headers prepended:
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
? PR_FALSE : PR_TRUE);
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
return encoder->EncodeToStream(aOutputStream);
}

View File

@ -3078,7 +3078,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
}
else
{ // default processing
nsCOMPtr<nsITextEncoder> encoder;
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = new char[strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1];
if (! progid)
return NS_ERROR_OUT_OF_MEMORY;
@ -3109,24 +3109,19 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
rv = GetPresShell(getter_AddRefs(shell));
if (NS_FAILED(rv))
return rv;
rv = encoder->Init(shell, doc, aFormatType);
rv = encoder->Init(shell, doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
if (aFlags & EditorOutputSelectionOnly)
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsIDOMSelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
nsCOMPtr<nsIDOMSelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// Try to set pretty printing, but don't panic if it doesn't work:
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
? PR_TRUE : PR_FALSE);
// Indicate whether we want the comment and doctype headers prepended:
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
? PR_FALSE : PR_TRUE);
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
@ -3156,7 +3151,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
PRUint32 aFlags)
{
nsresult rv;
nsCOMPtr<nsITextEncoder> encoder;
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = new char[strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1];
if (! progid)
return NS_ERROR_OUT_OF_MEMORY;
@ -3190,42 +3185,37 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
rv = GetPresShell(getter_AddRefs(shell));
if (NS_SUCCEEDED(rv)) {
rv = encoder->Init(shell,doc, aFormatType);
rv = encoder->Init(shell,doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
}
if (aFlags & EditorOutputSelectionOnly)
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsIDOMSelection> selection;
nsCOMPtr<nsIDOMSelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// Try to set pretty printing, but don't panic if it doesn't work:
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
? PR_TRUE : PR_FALSE);
// Indicate whether we want the comment and doc type headers prepended:
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
? PR_FALSE : PR_TRUE);
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
return encoder->EncodeToStream(aOutputStream);
}

View File

@ -33,6 +33,7 @@
#include "nsIDOMNSUIEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIEditorMailSupport.h"
#include "nsIDocumentEncoder.h"
// for repainting hack only
#include "nsIView.h"
@ -356,7 +357,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
else
format = "text/html";
res = mEditor->OutputToString(output, format,
nsEditor::EditorOutputFormatted);
nsIDocumentEncoder::OutputFormatted);
if (NS_SUCCEEDED(res))
{
char* buf = output.ToNewCString();

View File

@ -328,15 +328,6 @@ public:
/* ------------ Output methods -------------- */
/**
* Output methods flags:
*/
enum {
EditorOutputSelectionOnly = 1,
EditorOutputFormatted = 2,
EditorOutputNoDoctype = 4
};
/**
* Output methods:
* aFormatType is a mime type, like text/plain.

View File

@ -398,7 +398,7 @@ function EditorGetHTML()
{
if (editorShell) {
dump("Getting HTML\n");
var outputHTML = editorShell.GetContentsAs("text/html", 2);
var outputHTML = editorShell.GetContentsAs("text/html", 0);
dump(outputHTML + "\n");
}
}

View File

@ -35,6 +35,7 @@
#include "nsIParser.h"
#include "nsHTMLEntities.h"
#include "nsCRT.h"
#include "nsIDocumentEncoder.h" // for output flags
#include "nsIUnicodeEncoder.h"
#include "nsICharsetAlias.h"
@ -248,16 +249,14 @@ NS_IMPL_RELEASE(nsHTMLContentSinkStream)
*/
NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride,
PRBool aDoFormat,
PRBool aDoHeader)
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride,
PRUint32 aFlags)
{
nsHTMLContentSinkStream* it = new nsHTMLContentSinkStream(aOutStream,
nsnull,
aCharsetOverride,
aDoFormat,
aDoHeader);
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -274,15 +273,13 @@ NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
*/
NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aOutString,
PRBool aDoFormat,
PRBool aDoHeader)
nsString* aOutString,
PRUint32 aFlags)
{
nsHTMLContentSinkStream* it = new nsHTMLContentSinkStream(nsnull,
aOutString,
nsnull,
aDoFormat,
aDoHeader);
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -352,16 +349,21 @@ nsresult nsHTMLContentSinkStream::InitEncoder(const nsString& aCharset)
nsHTMLContentSinkStream::nsHTMLContentSinkStream(nsIOutputStream* aOutStream,
nsString* aOutString,
const nsString* aCharsetOverride,
PRBool aDoFormat,
PRBool aDoHeader) {
PRUint32 aFlags)
{
NS_INIT_REFCNT();
mLowerCaseTags = PR_TRUE;
memset(mHTMLTagStack,0,sizeof(mHTMLTagStack));
mHTMLStackPos = 0;
mColPos = 0;
mIndent = 0;
mDoFormat = aDoFormat;
mDoHeader = aDoHeader;
mDoFormat = (aFlags & nsIDocumentEncoder::OutputFormatted) ? PR_TRUE
: PR_FALSE;
mBodyOnly = (aFlags & nsIDocumentEncoder::OutputBodyOnly) ? PR_TRUE
: PR_FALSE;
mDoHeader = (!mBodyOnly) && (mDoFormat) &&
((aFlags & nsIDocumentEncoder::OutputNoDoctype) ? PR_FALSE
: PR_TRUE);
mBuffer = nsnull;
mBufferSize = 0;
mUnicodeEncoder = nsnull;
@ -510,8 +512,11 @@ void nsHTMLContentSinkStream::EncodeToBuffer(const nsString& aSrc)
void nsHTMLContentSinkStream::Write(const nsString& aString)
{
if (mBodyOnly && !mInBody)
return;
// No need to re-encode strings, since they're going from UCS2 to UCS2
if (mString != nsnull)
if (mString)
mString->Append(aString);
if (!mStream)
@ -536,6 +541,9 @@ void nsHTMLContentSinkStream::Write(const nsString& aString)
void nsHTMLContentSinkStream::Write(const char* aData)
{
if (mBodyOnly && !mInBody)
return;
if (mStream)
{
nsOutputStream out(mStream);
@ -549,6 +557,9 @@ void nsHTMLContentSinkStream::Write(const char* aData)
void nsHTMLContentSinkStream::Write(char aData)
{
if (mBodyOnly && !mInBody)
return;
if (mStream)
{
nsOutputStream out(mStream);
@ -863,7 +874,6 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
const nsString& name = aNode.GetText();
nsString tagName;
if (tag == eHTMLTag_body)
mInBody = PR_TRUE;
@ -875,7 +885,6 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
else
tagName.ToUpperCase();
if ((mDoFormat || !mInBody) && mColPos != 0 && BreakBeforeOpen(tag))
{
Write(NS_LINEBREAK);

View File

@ -70,8 +70,7 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSink {
nsHTMLContentSinkStream(nsIOutputStream* aOutStream,
nsString* aOutString,
const nsString* aCharsetOverride,
PRBool aDoFormat,
PRBool aDoHeader);
PRUint32 aFlags);
/**
* virtual destructor
@ -146,7 +145,8 @@ protected:
protected:
nsIOutputStream* mStream;
nsString* mString;
nsString mStreamBuffer;
nsString* mString;
int mTabLevel;
@ -159,6 +159,7 @@ protected:
PRBool mDoFormat;
PRBool mDoHeader;
PRBool mBodyOnly;;
char* mBuffer;
PRInt32 mBufferLength; // The length of the data in the buffer
@ -172,19 +173,12 @@ protected:
extern NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride=nsnull,
PRBool aDoFormat = PR_FALSE,
PRBool aDoHeader = PR_FALSE);
const nsString* aCharsetOverride,
PRUint32 aFlags);
extern NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aOutString,
PRBool aDoFormat = PR_FALSE,
PRBool aDoHeader = PR_FALSE);
nsString* aOutString, PRUint32 aFlags);
#endif

View File

@ -34,7 +34,7 @@
#include "nsHTMLEntities.h"
#include "nsXIFDTD.h"
#include "prprf.h" // For PR_snprintf()
#include "nsIDocumentEncoder.h" // for output flags
#include "nsIUnicodeEncoder.h"
#include "nsICharsetAlias.h"
#include "nsIServiceManager.h"
@ -160,16 +160,15 @@ NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aStream,
const nsString* aCharsetOverride,
PRUint32 aWrapColumn,
PRBool aPrettyPrint)
PRUint32 aWrapColumn, PRUint32 aFlags)
{
NS_ASSERTION(aStream != nsnull, "a valid stream is required");
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(aStream, nsnull);
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(aStream, nsnull,
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetWrapColumn(aWrapColumn);
it->DoPrettyPrint(aPrettyPrint);
if (aCharsetOverride != nsnull)
it->SetCharsetOverride(aCharsetOverride);
return it->QueryInterface(kIHTMLContentSinkIID, (void **)aInstancePtrResult);
@ -185,16 +184,15 @@ NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aString,
PRUint32 aWrapColumn,
PRBool aPrettyPrint)
PRUint32 aWrapColumn, PRUint32 aFlags)
{
NS_ASSERTION(aString != nsnull, "a valid stream is required");
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(nsnull, aString);
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(nsnull, aString,
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetWrapColumn(aWrapColumn);
it->DoPrettyPrint(aPrettyPrint);
nsString ucs2("ucs2");
it->SetCharsetOverride(&ucs2);
return it->QueryInterface(kIHTMLContentSinkIID, (void **)aInstancePtrResult);
@ -211,7 +209,8 @@ static const PRUint32 OLStackSize = 100;
* @return
*/
nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream(nsIOutputStream* aStream,
nsString* aString)
nsString* aString,
PRUint32 aFlags)
{
NS_INIT_REFCNT();
mStream = aStream;
@ -224,7 +223,7 @@ nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream(nsIOutputStream* aStream,
mUnicodeEncoder = nsnull;
mStream = aStream;
mString = aString;
mPrettyPrint = PR_FALSE;
mFlags = aFlags;
mWrapColumn = 72; // XXX magic number, we expect someone to reset this
// initialize the tag stack to zero:
@ -754,7 +753,7 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode)
{
if (mColPos != 0)
{
if (mPrettyPrint)
if (mFlags & nsIDocumentEncoder::OutputFormatted)
{
nsString temp(NS_LINEBREAK);
Write(temp);
@ -792,7 +791,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
mColPos++;
}
if (mPrettyPrint)
if (mFlags & nsIDocumentEncoder::OutputFormatted)
WriteWrapped(text);
else
{
@ -813,7 +812,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
}
else if (type == eHTMLTag_br)
{
if (mPrettyPrint)
if (mFlags & nsIDocumentEncoder::OutputFormatted)
{
nsString temp (NS_LINEBREAK);
Write(temp);
@ -825,7 +824,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
// Otherwise, either we're collapsing to minimal text, or we're
// prettyprinting to mimic the html format, and in neither case
// does the formatting of the html source help us.
else if (mPrettyPrint
else if ((mFlags & nsIDocumentEncoder::OutputFormatted)
&& (mTagStackIndex > 0)
&& (mTagStack[mTagStackIndex-1] == eHTMLTag_pre))
{

View File

@ -57,7 +57,8 @@ class nsHTMLToTXTSinkStream : public nsIHTMLContentSink
* Standard constructor
* @update gpk02/03/99
*/
nsHTMLToTXTSinkStream(nsIOutputStream* aOutStream, nsString* aOutString);
nsHTMLToTXTSinkStream(nsIOutputStream* aOutStream, nsString* aOutString,
PRUint32 aFlags);
/**
* virtual destructor
@ -113,7 +114,6 @@ class nsHTMLToTXTSinkStream : public nsIHTMLContentSink
* The following methods are specific to this class.
*******************************************************************/
NS_IMETHOD SetWrapColumn(PRUint32 aWrapCol) { mWrapColumn = aWrapCol; return NS_OK; };
NS_IMETHOD DoPrettyPrint(PRBool aPP) { mPrettyPrint = aPP; return NS_OK; };
protected:
void EnsureBufferSize(PRInt32 aNewSize);
@ -131,7 +131,7 @@ protected:
PRInt32 mIndent;
PRInt32 mColPos;
PRBool mDoOutput;
PRBool mPrettyPrint;
PRInt32 mFlags;
PRUint32 mWrapColumn;
// The tag stack: the stack of tags we're operating on, so we can nest:
@ -154,17 +154,13 @@ extern NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride=nsnull,
PRUint32 aWrapColumn=0,
PRBool aPrettyPrint=PR_FALSE);
PRUint32 aWrapColumn=0, PRUint32 aFlags=0);
extern NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aOutString,
PRUint32 aWrapColumn=0,
PRBool aPrettyPrint=PR_FALSE);
PRUint32 aWrapColumn=0, PRUint32 aFlags=0);
#endif

View File

@ -818,7 +818,7 @@ PRBool nsParser::IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aSta
nsString theOutput("");
nsIHTMLContentSink* theSink=0;
nsresult theResult=NS_New_HTML_ContentSinkStream(&theSink,&theOutput,PR_FALSE,PR_FALSE);
nsresult theResult=NS_New_HTML_ContentSinkStream(&theSink,&theOutput,0);
SetContentSink(theSink);
theResult=Parse(theBuffer,(void*)&theBuffer,aContentType,PR_FALSE,PR_TRUE);
theOutput.StripWhitespace();

View File

@ -51,19 +51,27 @@ class nsIDocumentEncoder : public nsISupports
{
public:
/**
* Output methods flag bits:
*/
enum {
OutputSelectionOnly = 1,
OutputFormatted = 2,
OutputNoDoctype = 4,
OutputBodyOnly = 8
};
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
/**
* Initialize with a pointer to the document and the mime type.
*
*/
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, const nsString& aMimeType) = 0;
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, const nsString& aMimeType, PRUint32 flags) = 0;
/**
* If the selection is set to a non-null value, then the
* selection is used for encoding, otherwise the entire
* document is encoded.
*
*/
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection) = 0;
@ -75,22 +83,27 @@ public:
* character set when encoding the document.
*
* Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER
*
*/
NS_IMETHOD SetCharset(const nsString& aCharset) = 0;
/**
* Set a wrap column. This may have no effect in some types of encoders.
*/
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
/**
* The document is encoded, the result is sent to the
* to nsIOutputStream.
*
* Possible result codes are passing along whatever stream errors
* might have been encountered.
*
*/
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream) = 0;
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
};
// XXXXXXXXXXXXXXXX nsITextEncoder is going away! XXXXXXXXXXXXXXXXXXXXXX
#ifdef USE_OBSOLETE_TEXT_ENCODER
// Example of a output service for a particular encoder.
// The text encoder handles XIF, HTML, and plaintext.
class nsITextEncoder : public nsIDocumentEncoder
@ -104,6 +117,7 @@ public:
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
NS_IMETHOD AddHeader(PRBool aYes) = 0;
};
#endif /* USE_OBSOLETE_TEXT_ENCODER */
#endif /* nsIDocumentEncoder_h__ */

View File

@ -2675,7 +2675,7 @@ void nsDocument::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
converter.AddStartTag("section_body");
nsIDOMElement* root = nsnull;
if (NS_OK == GetDocumentElement(&root))
if (NS_SUCCEEDED(GetDocumentElement(&root)))
{
#if 1
ToXIF(converter,root);
@ -2752,10 +2752,10 @@ nsDocument::OutputDocumentAs(nsIOutputStream* aStream, nsIDOMSelection* selectio
switch (aOutputFormat)
{
case eOutputText:
rv = NS_New_HTMLToTXT_SinkStream(getter_AddRefs(sink), aStream, &charsetStr);
rv = NS_New_HTMLToTXT_SinkStream(getter_AddRefs(sink), aStream, &charsetStr, 0);
break;
case eOutputHTML:
rv = NS_New_HTML_ContentSinkStream(getter_AddRefs(sink), aStream, &charsetStr);
rv = NS_New_HTML_ContentSinkStream(getter_AddRefs(sink), aStream, &charsetStr, 0);
break;
default:
rv = NS_ERROR_INVALID_ARG;

View File

@ -38,7 +38,7 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCTextEncoderCID, NS_TEXT_ENCODER_CID);
class nsTextEncoder : public nsITextEncoder
class nsTextEncoder : public nsIDocumentEncoder
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
@ -47,30 +47,32 @@ public:
virtual ~nsTextEncoder();
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
const nsString& aMimeType);
const nsString& aMimeType, PRUint32 aFlags);
/* Interfaces for addref and release and queryinterface */
NS_DECL_ISUPPORTS
// Inherited methods from nsIDocument
// Inherited methods from nsIDocumentEncoder
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD SetCharset(const nsString& aCharset);
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
NS_IMETHOD EncodeToString(nsString& aOutputString);
NS_IMETHOD PrettyPrint(PRBool aYes);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD AddHeader(PRBool aYes);
protected:
// Local methods to the text encoder -- used to be in nsITextEncoder,
// but that interface is obsolete now.
//NS_IMETHOD PrettyPrint(PRBool aYes);
//NS_IMETHOD AddHeader(PRBool aYes);
private:
nsIDocument* mDocument;
nsIDOMSelection* mSelection;
nsIPresShell* mPresShell;
nsString mMimeType;
nsString mCharset;
PRBool mPrettyPrint;
PRUint32 mFlags;
PRUint32 mWrapColumn;
PRBool mAddHeader;
};
@ -83,7 +85,6 @@ nsTextEncoder::nsTextEncoder() : mMimeType("text/plain")
mDocument = 0;
mSelection = 0;
mPresShell = 0;
mAddHeader = PR_FALSE;
}
nsTextEncoder::~nsTextEncoder()
@ -95,7 +96,7 @@ nsTextEncoder::~nsTextEncoder()
NS_IMETHODIMP
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
const nsString& aMimeType)
const nsString& aMimeType, PRUint32 aFlags)
{
if (!aDocument)
return NS_ERROR_INVALID_ARG;
@ -108,6 +109,9 @@ nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
mPresShell = aPresShell;
NS_ADDREF(aPresShell);
mMimeType = aMimeType;
mFlags = aFlags;
return NS_OK;
}
@ -133,13 +137,6 @@ nsresult nsTextEncoder::QueryInterface(REFNSIID aIID,
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::PrettyPrint(PRBool aYes)
{
mPrettyPrint = aYes;
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::SetWrapColumn(PRUint32 aWC)
{
@ -147,13 +144,6 @@ nsTextEncoder::SetWrapColumn(PRUint32 aWC)
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::AddHeader(PRBool aYes)
{
mAddHeader = aYes;
return NS_OK;
}
NS_IMETHODIMP
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
{
@ -209,13 +199,11 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
nsIHTMLContentSink* sink = nsnull;
if (mMimeType == "text/html")
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
PR_FALSE,
mSelection ? PR_FALSE : mAddHeader );
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString, mFlags);
else // default to text/plain
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
mWrapColumn, mPrettyPrint);
mWrapColumn, mFlags);
if (sink && NS_SUCCEEDED(rv))
{
@ -270,17 +258,15 @@ nsTextEncoder::EncodeToStream(nsIOutputStream* aStream)
kCParserIID,
(void **)&parser);
if (NS_OK == rv) {
if (NS_SUCCEEDED(rv)) {
nsIHTMLContentSink* sink = nsnull;
if (mMimeType == "text/html")
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset,
PR_FALSE,
mSelection ? PR_FALSE : mAddHeader);
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset, mFlags);
else
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
mWrapColumn, mPrettyPrint);
mWrapColumn, mFlags);
if (sink && NS_SUCCEEDED(rv))
{

View File

@ -469,7 +469,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
#ifdef rickgdebug
nsString outString; // added out. Redirect to stdout if desired -- gpk 04/01/99
rv = NS_New_HTML_ContentSinkStream(&sink,&outString);
rv = NS_New_HTML_ContentSinkStream(&sink,&outString,0);
#else
NS_PRECONDITION(nsnull != aContainer, "No content viewer container");
aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);

View File

@ -56,6 +56,7 @@
#include "nsWidgetsCID.h"
#include "nsIHTMLEditor.h"
#include "nsIDocumentEncoder.h"
#include "nsIEditorMailSupport.h"
#include "nsEditorCID.h"
#include "nsIDOMNode.h"
@ -612,7 +613,7 @@ void nsGfxTextControlFrame::GetTextControlFrameState(nsString& aValue)
PRUint32 flags = 0;
if (PR_TRUE==IsPlainTextControl()) {
flags |= nsIEditor::EditorOutputNoDoctype;
flags |= nsIDocumentEncoder::OutputNoDoctype;
}
nsString wrap;
@ -621,7 +622,7 @@ void nsGfxTextControlFrame::GetTextControlFrameState(nsString& aValue)
{
if (kTextControl_Wrap_Hard.EqualsIgnoreCase(wrap))
{
flags |= nsIEditor::EditorOutputFormatted;
flags |= nsIDocumentEncoder::OutputFormatted;
}
}

View File

@ -27,7 +27,7 @@
#include "nsIMessage.h" //temporary!
#include "nsMsgQuote.h"
#include "nsIPref.h"
#include "nsIEditor.h" // for output flags
#include "nsIDocumentEncoder.h" // for editor output flags
#include "nsXPIDLString.h"
#include "nsIParser.h"
#include "nsParserCIID.h"
@ -367,7 +367,7 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode,
format = "text/html";
else
{
flags = nsIEditor::EditorOutputFormatted;
flags = nsIDocumentEncoder::OutputFormatted;
format = "text/plain";
}
m_editor->GetContentsAs(format.GetUnicode(), flags, &bodyText);
@ -723,7 +723,7 @@ ConvertBufToPlainText(nsString &aConBuf, const char *charSet)
{
nsHTMLToTXTSinkStream *sink = nsnull;
rv = NS_New_HTMLToTXT_SinkStream((nsIHTMLContentSink **)&sink, &convertedText, PR_TRUE);
rv = NS_New_HTMLToTXT_SinkStream((nsIHTMLContentSink **)&sink, &convertedText, 0, 0);
if (sink && NS_SUCCEEDED(rv))
{
sink->DoFragment(PR_TRUE);

View File

@ -35,6 +35,7 @@
#include "nsIParser.h"
#include "nsHTMLEntities.h"
#include "nsCRT.h"
#include "nsIDocumentEncoder.h" // for output flags
#include "nsIUnicodeEncoder.h"
#include "nsICharsetAlias.h"
@ -248,16 +249,14 @@ NS_IMPL_RELEASE(nsHTMLContentSinkStream)
*/
NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride,
PRBool aDoFormat,
PRBool aDoHeader)
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride,
PRUint32 aFlags)
{
nsHTMLContentSinkStream* it = new nsHTMLContentSinkStream(aOutStream,
nsnull,
aCharsetOverride,
aDoFormat,
aDoHeader);
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -274,15 +273,13 @@ NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
*/
NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aOutString,
PRBool aDoFormat,
PRBool aDoHeader)
nsString* aOutString,
PRUint32 aFlags)
{
nsHTMLContentSinkStream* it = new nsHTMLContentSinkStream(nsnull,
aOutString,
nsnull,
aDoFormat,
aDoHeader);
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -352,16 +349,21 @@ nsresult nsHTMLContentSinkStream::InitEncoder(const nsString& aCharset)
nsHTMLContentSinkStream::nsHTMLContentSinkStream(nsIOutputStream* aOutStream,
nsString* aOutString,
const nsString* aCharsetOverride,
PRBool aDoFormat,
PRBool aDoHeader) {
PRUint32 aFlags)
{
NS_INIT_REFCNT();
mLowerCaseTags = PR_TRUE;
memset(mHTMLTagStack,0,sizeof(mHTMLTagStack));
mHTMLStackPos = 0;
mColPos = 0;
mIndent = 0;
mDoFormat = aDoFormat;
mDoHeader = aDoHeader;
mDoFormat = (aFlags & nsIDocumentEncoder::OutputFormatted) ? PR_TRUE
: PR_FALSE;
mBodyOnly = (aFlags & nsIDocumentEncoder::OutputBodyOnly) ? PR_TRUE
: PR_FALSE;
mDoHeader = (!mBodyOnly) && (mDoFormat) &&
((aFlags & nsIDocumentEncoder::OutputNoDoctype) ? PR_FALSE
: PR_TRUE);
mBuffer = nsnull;
mBufferSize = 0;
mUnicodeEncoder = nsnull;
@ -510,8 +512,11 @@ void nsHTMLContentSinkStream::EncodeToBuffer(const nsString& aSrc)
void nsHTMLContentSinkStream::Write(const nsString& aString)
{
if (mBodyOnly && !mInBody)
return;
// No need to re-encode strings, since they're going from UCS2 to UCS2
if (mString != nsnull)
if (mString)
mString->Append(aString);
if (!mStream)
@ -536,6 +541,9 @@ void nsHTMLContentSinkStream::Write(const nsString& aString)
void nsHTMLContentSinkStream::Write(const char* aData)
{
if (mBodyOnly && !mInBody)
return;
if (mStream)
{
nsOutputStream out(mStream);
@ -549,6 +557,9 @@ void nsHTMLContentSinkStream::Write(const char* aData)
void nsHTMLContentSinkStream::Write(char aData)
{
if (mBodyOnly && !mInBody)
return;
if (mStream)
{
nsOutputStream out(mStream);
@ -863,7 +874,6 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
const nsString& name = aNode.GetText();
nsString tagName;
if (tag == eHTMLTag_body)
mInBody = PR_TRUE;
@ -875,7 +885,6 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
else
tagName.ToUpperCase();
if ((mDoFormat || !mInBody) && mColPos != 0 && BreakBeforeOpen(tag))
{
Write(NS_LINEBREAK);

View File

@ -70,8 +70,7 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSink {
nsHTMLContentSinkStream(nsIOutputStream* aOutStream,
nsString* aOutString,
const nsString* aCharsetOverride,
PRBool aDoFormat,
PRBool aDoHeader);
PRUint32 aFlags);
/**
* virtual destructor
@ -146,7 +145,8 @@ protected:
protected:
nsIOutputStream* mStream;
nsString* mString;
nsString mStreamBuffer;
nsString* mString;
int mTabLevel;
@ -159,6 +159,7 @@ protected:
PRBool mDoFormat;
PRBool mDoHeader;
PRBool mBodyOnly;;
char* mBuffer;
PRInt32 mBufferLength; // The length of the data in the buffer
@ -172,19 +173,12 @@ protected:
extern NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride=nsnull,
PRBool aDoFormat = PR_FALSE,
PRBool aDoHeader = PR_FALSE);
const nsString* aCharsetOverride,
PRUint32 aFlags);
extern NS_HTMLPARS nsresult
NS_New_HTML_ContentSinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aOutString,
PRBool aDoFormat = PR_FALSE,
PRBool aDoHeader = PR_FALSE);
nsString* aOutString, PRUint32 aFlags);
#endif

View File

@ -34,7 +34,7 @@
#include "nsHTMLEntities.h"
#include "nsXIFDTD.h"
#include "prprf.h" // For PR_snprintf()
#include "nsIDocumentEncoder.h" // for output flags
#include "nsIUnicodeEncoder.h"
#include "nsICharsetAlias.h"
#include "nsIServiceManager.h"
@ -160,16 +160,15 @@ NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aStream,
const nsString* aCharsetOverride,
PRUint32 aWrapColumn,
PRBool aPrettyPrint)
PRUint32 aWrapColumn, PRUint32 aFlags)
{
NS_ASSERTION(aStream != nsnull, "a valid stream is required");
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(aStream, nsnull);
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(aStream, nsnull,
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetWrapColumn(aWrapColumn);
it->DoPrettyPrint(aPrettyPrint);
if (aCharsetOverride != nsnull)
it->SetCharsetOverride(aCharsetOverride);
return it->QueryInterface(kIHTMLContentSinkIID, (void **)aInstancePtrResult);
@ -185,16 +184,15 @@ NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aString,
PRUint32 aWrapColumn,
PRBool aPrettyPrint)
PRUint32 aWrapColumn, PRUint32 aFlags)
{
NS_ASSERTION(aString != nsnull, "a valid stream is required");
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(nsnull, aString);
nsHTMLToTXTSinkStream* it = new nsHTMLToTXTSinkStream(nsnull, aString,
aFlags);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetWrapColumn(aWrapColumn);
it->DoPrettyPrint(aPrettyPrint);
nsString ucs2("ucs2");
it->SetCharsetOverride(&ucs2);
return it->QueryInterface(kIHTMLContentSinkIID, (void **)aInstancePtrResult);
@ -211,7 +209,8 @@ static const PRUint32 OLStackSize = 100;
* @return
*/
nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream(nsIOutputStream* aStream,
nsString* aString)
nsString* aString,
PRUint32 aFlags)
{
NS_INIT_REFCNT();
mStream = aStream;
@ -224,7 +223,7 @@ nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream(nsIOutputStream* aStream,
mUnicodeEncoder = nsnull;
mStream = aStream;
mString = aString;
mPrettyPrint = PR_FALSE;
mFlags = aFlags;
mWrapColumn = 72; // XXX magic number, we expect someone to reset this
// initialize the tag stack to zero:
@ -754,7 +753,7 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode)
{
if (mColPos != 0)
{
if (mPrettyPrint)
if (mFlags & nsIDocumentEncoder::OutputFormatted)
{
nsString temp(NS_LINEBREAK);
Write(temp);
@ -792,7 +791,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
mColPos++;
}
if (mPrettyPrint)
if (mFlags & nsIDocumentEncoder::OutputFormatted)
WriteWrapped(text);
else
{
@ -813,7 +812,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
}
else if (type == eHTMLTag_br)
{
if (mPrettyPrint)
if (mFlags & nsIDocumentEncoder::OutputFormatted)
{
nsString temp (NS_LINEBREAK);
Write(temp);
@ -825,7 +824,7 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
// Otherwise, either we're collapsing to minimal text, or we're
// prettyprinting to mimic the html format, and in neither case
// does the formatting of the html source help us.
else if (mPrettyPrint
else if ((mFlags & nsIDocumentEncoder::OutputFormatted)
&& (mTagStackIndex > 0)
&& (mTagStack[mTagStackIndex-1] == eHTMLTag_pre))
{

View File

@ -57,7 +57,8 @@ class nsHTMLToTXTSinkStream : public nsIHTMLContentSink
* Standard constructor
* @update gpk02/03/99
*/
nsHTMLToTXTSinkStream(nsIOutputStream* aOutStream, nsString* aOutString);
nsHTMLToTXTSinkStream(nsIOutputStream* aOutStream, nsString* aOutString,
PRUint32 aFlags);
/**
* virtual destructor
@ -113,7 +114,6 @@ class nsHTMLToTXTSinkStream : public nsIHTMLContentSink
* The following methods are specific to this class.
*******************************************************************/
NS_IMETHOD SetWrapColumn(PRUint32 aWrapCol) { mWrapColumn = aWrapCol; return NS_OK; };
NS_IMETHOD DoPrettyPrint(PRBool aPP) { mPrettyPrint = aPP; return NS_OK; };
protected:
void EnsureBufferSize(PRInt32 aNewSize);
@ -131,7 +131,7 @@ protected:
PRInt32 mIndent;
PRInt32 mColPos;
PRBool mDoOutput;
PRBool mPrettyPrint;
PRInt32 mFlags;
PRUint32 mWrapColumn;
// The tag stack: the stack of tags we're operating on, so we can nest:
@ -154,17 +154,13 @@ extern NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsIOutputStream* aOutStream,
const nsString* aCharsetOverride=nsnull,
PRUint32 aWrapColumn=0,
PRBool aPrettyPrint=PR_FALSE);
PRUint32 aWrapColumn=0, PRUint32 aFlags=0);
extern NS_HTMLPARS nsresult
NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult,
nsString* aOutString,
PRUint32 aWrapColumn=0,
PRBool aPrettyPrint=PR_FALSE);
PRUint32 aWrapColumn=0, PRUint32 aFlags=0);
#endif

View File

@ -818,7 +818,7 @@ PRBool nsParser::IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aSta
nsString theOutput("");
nsIHTMLContentSink* theSink=0;
nsresult theResult=NS_New_HTML_ContentSinkStream(&theSink,&theOutput,PR_FALSE,PR_FALSE);
nsresult theResult=NS_New_HTML_ContentSinkStream(&theSink,&theOutput,0);
SetContentSink(theSink);
theResult=Parse(theBuffer,(void*)&theBuffer,aContentType,PR_FALSE,PR_TRUE);
theOutput.StripWhitespace();

View File

@ -25,6 +25,7 @@
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsITableEditor.h"
#include "nsIDocumentEncoder.h" // for output flags
#include "nsEditorCID.h"
@ -86,13 +87,13 @@ static nsresult PrintEditorOutput(nsIEditor* editor, PRInt32 aCommandID)
nsString outString;
char* cString;
nsString formatString;
PRUint32 flags;
PRUint32 flags = 0;
switch (aCommandID)
{
case VIEWER_DISPLAYTEXT:
formatString = "text/plain";
flags = nsIEditor::EditorOutputFormatted;
flags = nsIDocumentEncoder::OutputFormatted;
editor->OutputToString(outString, formatString, flags);
break;

View File

@ -224,7 +224,7 @@ NS_IMETHODIMP nsXIFFormatConverter::ConvertFromXIFToText(const nsString & aFromS
nsIHTMLContentSink* sink = nsnull;
rv = NS_New_HTMLToTXT_SinkStream(&sink,&aToStr);
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aToStr, 0);
if (NS_OK == rv) {
parser->SetContentSink(sink);
@ -262,7 +262,7 @@ NS_IMETHODIMP nsXIFFormatConverter::ConvertFromXIFToHTML(const nsString & aFromS
nsIHTMLContentSink* sink = nsnull;
rv = NS_New_HTML_ContentSinkStream(&sink,&aToStr);
rv = NS_New_HTML_ContentSinkStream(&sink, &aToStr, 0);
if (NS_OK == rv) {
parser->SetContentSink(sink);