2000-09-11 05:10:32 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsPlainTextSerializer_h__
|
|
|
|
#define nsPlainTextSerializer_h__
|
|
|
|
|
|
|
|
#include "nsIContentSerializer.h"
|
|
|
|
#include "nsIHTMLContentSink.h"
|
|
|
|
#include "nsHTMLTags.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsILineBreaker.h"
|
|
|
|
#include "nsIParserService.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIAtom.h"
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
#include "nsIHTMLToTextSink.h"
|
|
|
|
|
2000-09-11 05:10:32 +00:00
|
|
|
|
|
|
|
class nsPlainTextSerializer : public nsIContentSerializer,
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
public nsIHTMLContentSink,
|
|
|
|
public nsIHTMLToTextSink
|
2000-09-11 05:10:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPlainTextSerializer();
|
|
|
|
virtual ~nsPlainTextSerializer();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIContentSerializer
|
|
|
|
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn);
|
|
|
|
|
|
|
|
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
|
|
|
|
PRInt32 aEndOffset, nsAWritableString& aStr);
|
|
|
|
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection,
|
|
|
|
PRInt32 aStartOffset, PRInt32 aEndOffset,
|
|
|
|
nsAWritableString& aStr) { return NS_OK; }
|
|
|
|
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI,
|
|
|
|
PRInt32 aStartOffset,
|
|
|
|
PRInt32 aEndOffset,
|
|
|
|
nsAWritableString& aStr) { return NS_OK; }
|
|
|
|
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset,
|
|
|
|
PRInt32 aEndOffset, nsAWritableString& aStr) { return NS_OK; }
|
|
|
|
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype,
|
|
|
|
nsAWritableString& aStr) { return NS_OK; }
|
|
|
|
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
|
|
|
|
nsAWritableString& aStr);
|
|
|
|
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,
|
|
|
|
nsAWritableString& aStr);
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
NS_IMETHOD Flush(nsAWritableString& aStr);
|
2000-09-11 05:10:32 +00:00
|
|
|
|
|
|
|
// nsIContentSink
|
|
|
|
NS_IMETHOD WillBuildModel(void) { return NS_OK; }
|
|
|
|
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel) { return NS_OK; }
|
|
|
|
NS_IMETHOD WillInterrupt(void) { return NS_OK; }
|
|
|
|
NS_IMETHOD WillResume(void) { return NS_OK; }
|
|
|
|
NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }
|
|
|
|
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD NotifyError(const nsParserError* aError) { return NS_OK; }
|
|
|
|
NS_IMETHOD AddComment(const nsIParserNode& aNode) { return NS_OK; }
|
|
|
|
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) { return NS_OK; }
|
|
|
|
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0) { return NS_OK; }
|
|
|
|
NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
|
|
|
|
|
|
|
|
// nsIHTMLContentSink
|
|
|
|
NS_IMETHOD SetTitle(const nsString& aValue) { return NS_OK; }
|
|
|
|
NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseHTML(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenHead(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseHead(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenBody(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseBody(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenForm(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseForm(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenMap(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseMap(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseFrameset(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenNoscript(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseNoscript(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD DoFragment(PRBool aFlag);
|
|
|
|
NS_IMETHOD BeginContext(PRInt32 aPosition) { return NS_OK; }
|
|
|
|
NS_IMETHOD EndContext(PRInt32 aPosition) { return NS_OK; }
|
|
|
|
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
// nsIHTMLToTextSink
|
|
|
|
NS_IMETHOD Initialize(nsAWritableString* aOutString,
|
|
|
|
PRUint32 aFlags, PRUint32 aWrapCol);
|
|
|
|
|
2000-09-11 05:10:32 +00:00
|
|
|
protected:
|
|
|
|
nsresult GetAttributeValue(nsIAtom* aName, nsString& aValueRet);
|
|
|
|
void AddToLine(const PRUnichar* aStringToAdd, PRInt32 aLength);
|
|
|
|
void EndLine(PRBool softlinebreak);
|
|
|
|
void EnsureVerticalSpace(PRInt32 noOfRows);
|
|
|
|
void FlushLine();
|
|
|
|
void WriteQuotesAndIndent();
|
|
|
|
void WriteSimple(nsString& aString);
|
2000-12-12 21:58:13 +00:00
|
|
|
void Write(const nsAReadableString& aString);
|
2000-09-11 05:10:32 +00:00
|
|
|
PRBool DoOutput();
|
|
|
|
PRBool MayWrap();
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
PRBool IsBlockLevel(PRInt32 aId);
|
|
|
|
PRBool IsContainer(PRInt32 aId);
|
2000-11-04 20:51:33 +00:00
|
|
|
PRBool IsInPre();
|
2000-09-11 05:10:32 +00:00
|
|
|
PRBool IsCurrentNodeConverted();
|
|
|
|
nsresult GetIdForContent(nsIContent* aContent, PRInt32* aID);
|
|
|
|
nsresult GetParserService(nsIParserService** aParserService);
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
nsresult DoOpenContainer(PRInt32 aTag);
|
|
|
|
nsresult DoCloseContainer(PRInt32 aTag);
|
2000-12-12 21:58:13 +00:00
|
|
|
nsresult DoAddLeaf(PRInt32 aTag, const nsAReadableString& aText);
|
2000-09-11 05:10:32 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsString mCurrentLine;
|
|
|
|
|
|
|
|
PRBool mInHead;
|
|
|
|
PRInt32 mIndent;
|
|
|
|
// mInIndentString keeps a header that has to be written in the indent.
|
|
|
|
// That could be, for instance, the bullet in a bulleted list.
|
|
|
|
nsString mInIndentString;
|
|
|
|
PRInt32 mCiteQuoteLevel;
|
|
|
|
PRInt32 mColPos;
|
|
|
|
PRInt32 mFlags;
|
|
|
|
|
|
|
|
// The wrap column is how many standard sized chars (western languages)
|
|
|
|
// should be allowed on a line. There could be less chars if the chars
|
|
|
|
// are wider than latin chars of more if the chars are more narrow.
|
|
|
|
PRUint32 mWrapColumn;
|
|
|
|
|
|
|
|
// The width of the line as it will appear on the screen (approx.)
|
|
|
|
PRUint32 mCurrentLineWidth;
|
|
|
|
|
|
|
|
PRBool mDoFragment;
|
|
|
|
PRInt32 mEmptyLines; // Will be the number of empty lines before
|
|
|
|
// the current. 0 if we are starting a new
|
|
|
|
// line and -1 if we are in a line.
|
|
|
|
PRBool mInWhitespace;
|
|
|
|
PRBool mPreFormatted;
|
|
|
|
PRBool mCacheLine; // If the line should be cached before output. This makes it possible to do smarter wrapping.
|
|
|
|
PRBool mStartedOutput; // we've produced at least a character
|
|
|
|
|
|
|
|
nsString mURL;
|
|
|
|
PRBool mStructs; // Output structs (pref)
|
|
|
|
PRInt32 mHeaderStrategy; /* Header strategy (pref)
|
|
|
|
0 = no indention
|
|
|
|
1 = indention, increased with
|
|
|
|
header level (default)
|
|
|
|
2 = numbering and slight indention */
|
|
|
|
PRInt32 mHeaderCounter[7]; /* For header-numbering:
|
|
|
|
Number of previous headers of
|
|
|
|
the same depth and in the same
|
|
|
|
section.
|
|
|
|
mHeaderCounter[1] for <h1> etc. */
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
|
|
|
nsIParserNode* mParserNode;
|
|
|
|
|
|
|
|
nsAWritableString* mOutputString;
|
|
|
|
|
|
|
|
// The tag stack: the stack of tags we're operating on, so we can nest:
|
|
|
|
nsHTMLTag *mTagStack;
|
|
|
|
PRUint32 mTagStackIndex;
|
|
|
|
|
|
|
|
// The stack for ordered lists:
|
|
|
|
PRInt32 *mOLStack;
|
|
|
|
PRUint32 mOLStackIndex;
|
|
|
|
|
|
|
|
nsString mLineBreak;
|
|
|
|
nsCOMPtr<nsILineBreaker> mLineBreaker;
|
|
|
|
nsCOMPtr<nsIParserService> mParserService;
|
|
|
|
};
|
|
|
|
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
extern nsresult NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer);
|
|
|
|
|
2000-09-11 05:10:32 +00:00
|
|
|
#endif
|