Back to index

lightning-sunbird  0.9+nobinonly
nsIDocumentEncoder.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsIDocumentEncoder_h__
00039 #define nsIDocumentEncoder_h__
00040 
00041 #include "nsISupports.h"
00042 #include "nsString.h"
00043 
00044 class nsIDocumentEncoder;
00045 class nsIDocument;
00046 class nsIDOMRange;
00047 class nsISelection;
00048 class nsIOutputStream;
00049 class nsISupportsArray;
00050 class nsIDOMNode;
00051 
00052 
00053 #define NS_IDOCUMENT_ENCODER_IID                     \
00054 { /* a6cf9103-15b3-11d2-932e-00805f8add32 */         \
00055     0xa6cf9103,                                      \
00056     0x15b3,                                          \
00057     0x11d2,                                          \
00058     {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
00059   }
00060 
00061 #define NS_TEXT_ENCODER_CID                          \
00062 { /* e7ba1480-1dea-11d3-830f-00104bed045e */         \
00063     0xe7ba1480,                                      \
00064     0x1dea,                                          \
00065     0x11d3,                                          \
00066     {0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
00067 }
00068 
00069 #define NS_DOC_ENCODER_CONTRACTID_BASE "@mozilla.org/layout/documentEncoder;1?type="
00070 
00071 // {7f915b01-98fc-11d4-8eb0-a803f80ff1bc}
00072 #define NS_HTMLCOPY_TEXT_ENCODER_CID                      \
00073 { 0x7f915b01, 0x98fc, 0x11d4, { 0x8e, 0xb0, 0xa8, 0x03, 0xf8, 0x0f, 0xf1, 0xbc } }
00074 
00075 // {0BC1FAC0-B710-11d4-959F-0020183BF181}
00076 #define NS_IDOCUMENTENCODERNODEFIXUP_IID                     \
00077 { 0xbc1fac0, 0xb710, 0x11d4, { 0x95, 0x9f, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
00078   
00079 #define NS_HTMLCOPY_ENCODER_CONTRACTID "@mozilla.org/layout/htmlCopyEncoder;1"
00080 
00081 class nsIDocumentEncoderNodeFixup : public nsISupports
00082 {
00083 public:
00084 
00085   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENTENCODERNODEFIXUP_IID)
00086 
00087   
00092   NS_IMETHOD FixupNode(nsIDOMNode *aNode, nsIDOMNode **aOutNode) = 0;
00093 };
00094 
00095 class nsIDocumentEncoder : public nsISupports
00096 {
00097 public:
00098 
00099   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_ENCODER_IID)
00100 
00101   
00110   enum {
00111     // Output only the selection (as opposed to the whole document).
00112     OutputSelectionOnly = 1,
00113 
00114     // Plaintext output: Convert html to plaintext that looks like the html.
00115     // Implies wrap (except inside <pre>), since html wraps.
00116     // HTML output: always do prettyprinting, ignoring existing formatting.
00117     // (Probably not well tested for HTML output.)
00118     OutputFormatted     = 2,
00119 
00120     // Don't do prettyprinting of HTML.  Don't do any wrapping that's not in
00121     // the existing HTML source.  This option overrides OutputFormatted if both
00122     // are set.  Note that this option does not affect entity conversion.
00123     OutputRaw           = 4,
00124 
00125     // No html head tags
00126     OutputBodyOnly      = 8,
00127 
00128     // Wrap even if we're not doing formatted output (e.g. for text fields)
00129     // XXXbz this doesn't seem to be used by all serializers... document?  How
00130     // does this interact with
00131     // OutputFormatted/OutputRaw/OutputWrap/OutputFormatFlowed?
00132     OutputPreformatted  = 16,
00133 
00134     // Output as though the content is preformatted
00135     // (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag)
00136     // XXXbz this doesn't seem to be used by all serializers... document?  How
00137     // does this interact with
00138     // OutputFormatted/OutputRaw/OutputPreformatted/OutputFormatFlowed?
00139     OutputWrap          = 32,
00140 
00141     // Output for format flowed (RFC 2646). This is used when converting
00142     // to text for mail sending. This differs just slightly
00143     // but in an important way from normal formatted, and that is that
00144     // lines are space stuffed. This can't (correctly) be done later.
00145     // XXXbz this doesn't seem to be used by all serializers... document?  How
00146     // does this interact with
00147     // OutputFormatted/OutputRaw/OutputPreformatted/OutputWrap?
00148     OutputFormatFlowed  = 64,
00149 
00150     // Convert links, image src, and script src to absolute URLs when possible
00151     OutputAbsoluteLinks = 128,
00152 
00153     // Attempt to encode entities standardized at W3C (HTML, MathML, etc).
00154     // This is a catch-all flag for documents with mixed contents. Beware of
00155     // interoperability issues. See below for other flags which might likely
00156     // do what you want.
00157     OutputEncodeW3CEntities = 256,
00158 
00159     // LineBreak processing: we can do either platform line breaks,
00160     // CR, LF, or CRLF.  If neither of these flags is set, then we
00161     // will use platform line breaks.
00162     OutputCRLineBreak = 512,
00163     OutputLFLineBreak = 1024,
00164 
00165     // Output the content of noscript elements (only for serializing
00166     // to plaintext).
00167     OutputNoScriptContent = 2048,
00168 
00169     // Output the content of noframes elements (only for serializing
00170     // to plaintext).
00171     OutputNoFramesContent = 4096,
00172 
00173     // Don't allow any formatting nodes (e.g. <br>, <b>) inside a <pre>.
00174     // This is used primarily by mail.
00175     OutputNoFormattingInPre = 8192,
00176 
00177     // Encode entities when outputting to a string.
00178     // E.g. If set, we'll output &nbsp; if clear, we'll output 0xa0.
00179     // The basic set is just &nbsp; &amp; &lt; &gt; &quot; for interoperability
00180     // with older products that don't support &alpha; and friends.
00181     // The Latin1 entity set additionally includes 8bit accented letters
00182     // between 128 and 255.
00183     // The HTML entity set additionally includes accented letters, greek
00184     // letters, and other special markup symbols as defined in HTML4.
00185     OutputEncodeBasicEntities = 16384,
00186     OutputEncodeLatin1Entities = 32768,
00187     OutputEncodeHTMLEntities = 65536
00188   };
00189 
00193   NS_IMETHOD Init(nsIDocument* aDocument, const nsAString& aMimeType,
00194                   PRUint32 flags) = 0;
00195 
00201   NS_IMETHOD SetSelection(nsISelection* aSelection) = 0;
00202 
00208   NS_IMETHOD SetRange(nsIDOMRange* aRange) = 0;
00209 
00215   NS_IMETHOD SetNode(nsIDOMNode* aNode) = 0;
00216 
00226   NS_IMETHOD SetCharset(const nsACString& aCharset) = 0;
00227 
00231   NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
00232 
00239   NS_IMETHOD GetMimeType(nsAString& aMimeType) = 0;
00240   
00248   NS_IMETHOD EncodeToStream(nsIOutputStream* aStream) = 0;
00249   NS_IMETHOD EncodeToString(nsAString& aOutputString) = 0;
00250 
00257   NS_IMETHOD EncodeToStringWithContext(nsAString& aEncodedString, 
00258                                        nsAString& aContextString, 
00259                                        nsAString& aInfoString) = 0;
00260 
00264   NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup) = 0;
00265 };
00266 
00267 #endif /* nsIDocumentEncoder_h__ */
00268