Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / base / nsIDocumentEncoder.idl
blob155e5c375c6efaca2696a58f9255156d2ff1da45
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.idl"
8 interface nsIDOMDocument;
9 interface nsIDOMRange;
10 interface nsISelection;
11 interface nsIDOMNode;
12 interface nsIOutputStream;
14 %{ C++
15 class nsINode;
16 class nsIDocument;
18 [ptr] native nsINodePtr(nsINode);
19 [ptr] native nsIDocumentPtr(nsIDocument);
21 [scriptable, uuid(3d9371d8-a2ad-403e-8b0e-8885ad3562e3)]
22 interface nsIDocumentEncoderNodeFixup : nsISupports
24 /**
25 * Create a fixed up version of a node. This method is called before
26 * each node in a document is about to be persisted. The implementor
27 * may return a new node with fixed up attributes or null. If null is
28 * returned the node should be used as-is.
29 * @param aNode Node to fixup.
30 * @param [OUT] aSerializeCloneKids True if the document encoder should
31 * apply recursive serialization to the children of the fixed up node
32 * instead of the children of the original node.
33 * @return The resulting fixed up node.
35 nsIDOMNode fixupNode(in nsIDOMNode aNode, out boolean aSerializeCloneKids);
38 [scriptable, uuid(1158bd7e-a08b-4ff6-9417-6f99144cfccc)]
39 interface nsIDocumentEncoder : nsISupports
41 // Output methods flag bits. There are a frightening number of these,
42 // because everyone wants something a little bit different
45 /**
46 * Output only the selection (as opposed to the whole document).
48 const unsigned long OutputSelectionOnly = (1 << 0);
50 /** Plaintext output: Convert html to plaintext that looks like the html.
51 * Implies wrap (except inside <pre>), since html wraps.
52 * HTML, XHTML and XML output: do prettyprinting, ignoring existing formatting.
53 * XML output : it doesn't implicitly wrap
55 const unsigned long OutputFormatted = (1 << 1);
57 /** Don't do prettyprinting. Don't do any wrapping that's not in the existing
58 * HTML/XML source. This option overrides OutputFormatted if both are set.
59 * HTML/XHTML output: If neither are set, there won't be prettyprinting too, but
60 * long lines will be wrapped.
61 * Supported also in XML and Plaintext output.
62 * @note This option does not affect entity conversion.
64 const unsigned long OutputRaw = (1 << 2);
66 /**
67 * Do not print html head tags.
68 * XHTML/HTML output only.
70 const unsigned long OutputBodyOnly = (1 << 3);
72 /**
73 * Output as though the content is preformatted
74 * (e.g. maybe it's wrapped in a PRE or PRE_WRAP style tag)
75 * Plaintext output only.
76 * XXXbz How does this interact with
77 * OutputFormatted/OutputRaw/OutputPreformatted/OutputFormatFlowed?
79 const unsigned long OutputPreformatted = (1 << 4);
81 /**
82 * Wrap even if we're not doing formatted output (e.g. for text fields).
83 * Supported in XML, XHTML, HTML and Plaintext output.
84 * Set implicitly in HTML/XHTML output when no OutputRaw.
85 * Ignored when OutputRaw.
86 * XXXLJ: set implicitly in HTML/XHTML output, to keep compatible behaviors
87 * for old callers of this interface
88 * XXXbz How does this interact with OutputFormatFlowed?
90 const unsigned long OutputWrap = (1 << 5);
92 /**
93 * Output for format flowed (RFC 2646). This is used when converting
94 * to text for mail sending. This differs just slightly
95 * but in an important way from normal formatted, and that is that
96 * lines are space stuffed. This can't (correctly) be done later.
97 * PlainText output only.
98 * XXXbz How does this interact with
99 * OutputFormatted/OutputRaw/OutputPreformatted/OutputWrap?
101 const unsigned long OutputFormatFlowed = (1 << 6);
104 * Convert links, image src, and script src to absolute URLs when possible.
105 * XHTML/HTML output only.
107 const unsigned long OutputAbsoluteLinks = (1 << 7);
110 * Attempt to encode entities standardized at W3C (HTML, MathML, etc).
111 * This is a catch-all flag for documents with mixed contents. Beware of
112 * interoperability issues. See below for other flags which might likely
113 * do what you want.
114 * HTML output only.
116 const unsigned long OutputEncodeW3CEntities = (1 << 8);
118 /**
119 * LineBreak processing: if this flag is set than CR line breaks will
120 * be written. If neither this nor OutputLFLineBreak is set, then we
121 * will use platform line breaks. The combination of the two flags will
122 * cause CRLF line breaks to be written.
124 const unsigned long OutputCRLineBreak = (1 << 9);
126 /**
127 * LineBreak processing: if this flag is set than LF line breaks will
128 * be written. If neither this nor OutputCRLineBreak is set, then we
129 * will use platform line breaks. The combination of the two flags will
130 * cause CRLF line breaks to be written.
132 const unsigned long OutputLFLineBreak = (1 << 10);
135 * Output the content of noscript elements (only for serializing
136 * to plaintext).
138 const unsigned long OutputNoScriptContent = (1 << 11);
141 * Output the content of noframes elements (only for serializing
142 * to plaintext). (Used only internally in the plain text serializer;
143 * ignored if passed by the caller.)
145 const unsigned long OutputNoFramesContent = (1 << 12);
148 * Don't allow any formatting nodes (e.g. <br>, <b>) inside a <pre>.
149 * This is used primarily by mail. XHTML/HTML output only.
151 const unsigned long OutputNoFormattingInPre = (1 << 13);
154 * Encode entities when outputting to a string.
155 * E.g. If set, we'll output &nbsp; if clear, we'll output 0xa0.
156 * The basic set is just &nbsp; &amp; &lt; &gt; &quot; for interoperability
157 * with older products that don't support &alpha; and friends.
158 * HTML output only.
160 const unsigned long OutputEncodeBasicEntities = (1 << 14);
163 * Encode entities when outputting to a string.
164 * The Latin1 entity set additionally includes 8bit accented letters
165 * between 128 and 255.
166 * HTML output only.
168 const unsigned long OutputEncodeLatin1Entities = (1 << 15);
171 * Encode entities when outputting to a string.
172 * The HTML entity set additionally includes accented letters, greek
173 * letters, and other special markup symbols as defined in HTML4.
174 * HTML output only.
176 const unsigned long OutputEncodeHTMLEntities = (1 << 16);
179 * Normally &nbsp; is replaced with a space character when
180 * encoding data as plain text, set this flag if that's
181 * not desired.
182 * Plaintext output only.
184 const unsigned long OutputPersistNBSP = (1 << 17);
187 * Normally when serializing the whole document using the HTML or
188 * XHTML serializer, the encoding declaration is rewritten to match.
189 * This flag suppresses that behavior.
191 const unsigned long OutputDontRewriteEncodingDeclaration = (1 << 18);
194 * When using the HTML or XHTML serializer, skip elements that are not
195 * visible when this flag is set. Elements are not visible when they
196 * have CSS style display:none or visibility:collapse, for example.
198 const unsigned long SkipInvisibleContent = (1 << 19);
201 * Output for delsp=yes (RFC 3676). This is used with OutputFormatFlowed
202 * when converting to text for mail sending.
203 * PlainText output only.
205 const unsigned long OutputFormatDelSp = (1 << 20);
208 * Drop <br> elements considered "invisible" by the editor. OutputPreformatted
209 * implies this flag.
211 const unsigned long OutputDropInvisibleBreak = (1 << 21);
214 * Don't check for _moz_dirty attributes when deciding whether to
215 * pretty-print if this flag is set (bug 599983).
217 const unsigned long OutputIgnoreMozDirty = (1 << 22);
220 * Output the content of non-text elements as the placehodler character
221 * U+FFFC (OBJECT REPLACEMENT CHARACTER, only for serializing to plaintext).
223 const unsigned long OutputNonTextContentAsPlaceholder = (1 << 23);
226 * Don't Strip ending spaces from a line (only for serializing to plaintext).
228 const unsigned long OutputDontRemoveLineEndingSpaces = (1 << 24);
231 * Serialize in a way that is suitable for copying a plaintext version of the
232 * document to the clipboard. This can for example cause line endings to be
233 * injected at preformatted block element boundaries.
235 const unsigned long OutputForPlainTextClipboardCopy = (1 << 25);
238 * Initialize with a pointer to the document and the mime type.
239 * @param aDocument Document to encode.
240 * @param aMimeType MimeType to use. May also be set by SetMimeType.
241 * @param aFlags Flags to use while encoding. May also be set by SetFlags.
243 void init(in nsIDOMDocument aDocument,
244 in AString aMimeType,
245 in unsigned long aFlags);
246 [noscript] void nativeInit(in nsIDocumentPtr aDocument,
247 in AString aMimeType,
248 in unsigned long aFlags);
251 * If the selection is set to a non-null value, then the
252 * selection is used for encoding, otherwise the entire
253 * document is encoded.
254 * @param aSelection The selection to encode.
256 void setSelection(in nsISelection aSelection);
259 * If the range is set to a non-null value, then the
260 * range is used for encoding, otherwise the entire
261 * document or selection is encoded.
262 * @param aRange The range to encode.
264 void setRange(in nsIDOMRange aRange);
267 * If the node is set to a non-null value, then the
268 * node is used for encoding, otherwise the entire
269 * document or range or selection is encoded.
270 * @param aNode The node to encode.
272 void setNode(in nsIDOMNode aNode);
273 [noscript] void setNativeNode(in nsINodePtr aNode);
276 * If the container is set to a non-null value, then its
277 * child nodes are used for encoding, otherwise the entire
278 * document or range or selection or node is encoded.
279 * @param aContainer The node which child nodes will be encoded.
281 void setContainerNode(in nsIDOMNode aContainer);
282 [noscript] void setNativeContainerNode(in nsINodePtr aContainer);
285 * Documents typically have an intrinsic character set,
286 * but if no intrinsic value is found, the platform character set
287 * is used. This function overrides both the intrinisc and platform
288 * charset.
289 * @param aCharset Overrides the both the intrinsic or platform
290 * character set when encoding the document.
292 * Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER
294 void setCharset(in ACString aCharset);
297 * Set a wrap column. This may have no effect in some types of encoders.
298 * @param aWrapColumn Column to which to wrap.
300 void setWrapColumn(in unsigned long aWrapColumn);
303 * The mime type preferred by the encoder. This piece of api was
304 * added because the copy encoder may need to switch mime types on you
305 * if you ask it to copy html that really represents plaintext content.
306 * Call this AFTER Init() and SetSelection() have both been called.
308 readonly attribute AString mimeType;
311 * Encode the document and send the result to the nsIOutputStream.
313 * Possible result codes are the stream errors which might have
314 * been encountered.
315 * @param aStream Stream into which to encode.
317 void encodeToStream(in nsIOutputStream aStream);
320 * Encode the document into a string.
322 * @return The document encoded into a string.
324 AString encodeToString();
327 * Encode the document into a string. Stores the extra context information
328 * into the two arguments.
329 * @param [OUT] aContextString The string where the parent hierarchy
330 * information will be stored.
331 * @param [OUT] aInfoString The string where extra context info will
332 * be stored.
333 * @return The document encoded as a string.
336 AString encodeToStringWithContext( out AString aContextString,
337 out AString aInfoString);
340 * Encode the document into a string of limited size.
341 * @param aMaxLength After aMaxLength characters, the encoder will stop
342 * encoding new data.
343 * Only values > 0 will be considered.
344 * The returned string may be slightly larger than
345 * aMaxLength because some serializers (eg. HTML)
346 * may need to close some tags after they stop
347 * encoding new data, or finish a line (72 columns
348 * by default for the plain text serializer).
350 * @return The document encoded into a string.
352 AString encodeToStringWithMaxLength(in unsigned long aMaxLength);
355 * Set the fixup object associated with node persistence.
356 * @param aFixup The fixup object.
358 void setNodeFixup(in nsIDocumentEncoderNodeFixup aFixup);