Bug 1540028 [wpt PR 16099] - Catch more exceptions in Document-createElement-namespac...
[gecko.git] / editor / nsIEditor.idl
blob741edeeecbddb9247ed4c8c5b1a564c8d8518680
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsISupports.idl"
8 #include "domstubs.idl"
10 interface nsIURI;
11 interface nsIContent;
12 interface nsISelectionController;
13 interface nsIDocumentStateListener;
14 interface nsIOutputStream;
15 interface nsITransactionManager;
16 interface nsITransaction;
17 interface nsIEditorObserver;
18 interface nsIEditActionListener;
19 interface nsIInlineSpellChecker;
20 interface nsITransferable;
22 webidl Document;
23 webidl Element;
24 webidl Node;
25 webidl Selection;
27 %{C++
28 namespace mozilla {
29 class EditorBase;
30 class HTMLEditor;
31 class TextEditor;
32 } // namespace mozilla
35 [scriptable, builtinclass, uuid(094be624-f0bf-400f-89e2-6a84baab9474)]
36 interface nsIEditor : nsISupports
38 %{C++
39 typedef short EDirection;
40 typedef short EStripWrappers;
42 const short eNone = 0;
43 const short eNext = 1;
44 const short ePrevious = 2;
45 const short eNextWord = 3;
46 const short ePreviousWord = 4;
47 const short eToBeginningOfLine = 5;
48 const short eToEndOfLine = 6;
50 const short eStrip = 0;
51 const short eNoStrip = 1;
53 readonly attribute Selection selection;
55 [can_run_script]
56 void setAttributeOrEquivalent(in Element element,
57 in AString sourceAttrName,
58 in AString sourceAttrValue,
59 in boolean aSuppressTransaction);
60 [can_run_script]
61 void removeAttributeOrEquivalent(in Element element,
62 in AString sourceAttrName,
63 in boolean aSuppressTransaction);
65 /** edit flags for this editor. May be set at any time. */
66 attribute unsigned long flags;
68 /**
69 * the MimeType of the document
71 attribute string contentsMIMEType;
73 /** Returns true if we have a document that is not marked read-only */
74 readonly attribute boolean isDocumentEditable;
76 /** Returns true if the current selection anchor is editable */
77 readonly attribute boolean isSelectionEditable;
79 /**
80 * the DOM Document this editor is associated with, refcounted.
82 readonly attribute Document document;
84 /** the body element, i.e. the root of the editable document.
86 readonly attribute Element rootElement;
88 /**
89 * the selection controller for the current presentation, refcounted.
91 readonly attribute nsISelectionController selectionController;
94 /* ------------ Selected content removal -------------- */
96 /**
97 * DeleteSelection removes all nodes in the current selection.
98 * @param aDir if eNext, delete to the right (for example, the DEL key)
99 * if ePrevious, delete to the left (for example, the BACKSPACE key)
100 * @param stripWrappers If eStrip, strip any empty inline elements left
101 * behind after the deletion; if eNoStrip, don't. If in
102 * doubt, pass eStrip -- eNoStrip is only for if you're
103 * about to insert text or similar right after.
105 void deleteSelection(in short action, in short stripWrappers);
108 /* ------------ Document info and file methods -------------- */
110 /** Returns true if the document has no *meaningful* content */
111 readonly attribute boolean documentIsEmpty;
113 /** Returns true if the document is modifed and needs saving */
114 readonly attribute boolean documentModified;
116 /** Sets the current 'Save' document character set */
117 attribute ACString documentCharacterSet;
119 /** to be used ONLY when we need to override the doc's modification
120 * state (such as when it's saved).
122 void resetModificationCount();
124 /** Gets the modification count of the document we are editing.
125 * @return the modification count of the document being edited.
126 * Zero means unchanged.
128 long getModificationCount();
130 /** called each time we modify the document.
131 * Increments the modification count of the document.
132 * @param aModCount the number of modifications by which
133 * to increase or decrease the count
135 void incrementModificationCount(in long aModCount);
137 /* ------------ Transaction methods -------------- */
139 /** transactionManager Get the transaction manager the editor is using.
141 readonly attribute nsITransactionManager transactionManager;
143 /** doTransaction() fires a transaction.
144 * It is provided here so clients can create their own transactions.
145 * If a transaction manager is present, it is used.
146 * Otherwise, the transaction is just executed directly.
148 * @param aTxn the transaction to execute
150 void doTransaction(in nsITransaction txn);
153 /** turn the undo system on or off
154 * @param aEnable if PR_TRUE, the undo system is turned on if available
155 * if PR_FALSE the undo system is turned off if it
156 * was previously on
157 * @return if aEnable is PR_TRUE, returns NS_OK if
158 * the undo system could be initialized properly
159 * if aEnable is PR_FALSE, returns NS_OK.
161 void enableUndo(in boolean enable);
163 /** undo reverses the effects of the last Do operation,
164 * if Undo is enabled in the editor.
165 * It is provided here so clients need no knowledge of whether
166 * the editor has a transaction manager or not.
167 * If a transaction manager is present, it is told to undo,
168 * and the result of that undo is returned.
169 * Otherwise, the Undo request is ignored and an
170 * error NS_ERROR_NOT_AVAILABLE is returned.
173 [can_run_script]
174 void undo(in unsigned long count);
176 /** returns state information about the undo system.
177 * @param aIsEnabled [OUT] PR_TRUE if undo is enabled
178 * @param aCanUndo [OUT] PR_TRUE if at least one transaction is
179 * currently ready to be undone.
181 void canUndo(out boolean isEnabled, out boolean canUndo);
183 /** redo reverses the effects of the last Undo operation
184 * It is provided here so clients need no knowledge of whether
185 * the editor has a transaction manager or not.
186 * If a transaction manager is present, it is told to redo and the
187 * result of the previously undone transaction is reapplied to the document.
188 * If no transaction is available for Redo, or if the document
189 * has no transaction manager, the Redo request is ignored and an
190 * error NS_ERROR_NOT_AVAILABLE is returned.
193 [can_run_script]
194 void redo(in unsigned long count);
196 /** returns state information about the redo system.
197 * @param aIsEnabled [OUT] PR_TRUE if redo is enabled
198 * @param aCanRedo [OUT] PR_TRUE if at least one transaction is
199 currently ready to be redone.
201 void canRedo(out boolean isEnabled, out boolean canRedo);
203 /** beginTransaction is a signal from the caller to the editor that
204 * the caller will execute multiple updates to the content tree
205 * that should be treated as a single logical operation,
206 * in the most efficient way possible.<br>
207 * All transactions executed between a call to beginTransaction and
208 * endTransaction will be undoable as an atomic action.<br>
209 * endTransaction must be called after beginTransaction.<br>
210 * Calls to beginTransaction can be nested, as long as endTransaction
211 * is called once per beginUpdate.
213 void beginTransaction();
215 /** endTransaction is a signal to the editor that the caller is
216 * finished updating the content model.<br>
217 * beginUpdate must be called before endTransaction is called.<br>
218 * Calls to beginTransaction can be nested, as long as endTransaction
219 * is called once per beginTransaction.
221 void endTransaction();
224 * While setting the flag with this method to false, CreateElementTransaction,
225 * DeleteRangeTransaction, DeleteTextTransaction, InsertNodeTransaction,
226 * InsertTextTransaction and SplitNodeTransaction won't change Selection
227 * after modifying the DOM tree.
228 * Note that calling this with false does not guarantee that Selection won't
229 * be changed because other transaction may ignore this flag, editor itself
230 * may change selection, and current selection may become invalid after
231 * changing the DOM tree, etc.
232 * After calling this method with true, the caller should guarantee that
233 * Selection should be positioned where user expects.
235 * @param should false if you don't want above transactions to modify
236 * Selection automatically after modifying the DOM tree.
237 * Note that calling this with false does not guarantee
238 * that Selection is never changed.
240 void setShouldTxnSetSelection(in boolean should);
242 /* ------------ Inline Spell Checking methods -------------- */
244 /** Returns the inline spell checker associated with this object. The spell
245 * checker is lazily created, so this function may create the object for
246 * you during this call.
247 * @param autoCreate If true, this will create a spell checker object
248 * if one does not exist yet for this editor. If false
249 * and the object has not been created, this function
250 * WILL RETURN NULL.
252 nsIInlineSpellChecker getInlineSpellChecker(in boolean autoCreate);
254 /** Called when the user manually overrides the spellchecking state for this
255 * editor.
256 * @param enable The new state of spellchecking in this editor, as
257 * requested by the user.
259 void setSpellcheckUserOverride(in boolean enable);
261 /* ------------ Clipboard methods -------------- */
263 /** cut the currently selected text, putting it into the OS clipboard
264 * What if no text is selected?
265 * What about mixed selections?
266 * What are the clipboard formats?
268 void cut();
270 /** Can we cut? True if the doc is modifiable, and we have a non-
271 * collapsed selection.
273 boolean canCut();
275 /** copy the currently selected text, putting it into the OS clipboard
276 * What if no text is selected?
277 * What about mixed selections?
278 * What are the clipboard formats?
280 void copy();
282 /** Can we copy? True if we have a non-collapsed selection.
284 boolean canCopy();
286 /** Can we delete? True if we have a non-collapsed selection.
288 boolean canDelete();
290 /** paste the text in the OS clipboard at the cursor position, replacing
291 * the selected text (if any)
293 [can_run_script]
294 void paste(in long aSelectionType);
296 /** Paste the text in |aTransferable| at the cursor position, replacing the
297 * selected text (if any).
299 [can_run_script]
300 void pasteTransferable(in nsITransferable aTransferable);
302 /** Can we paste? True if the doc is modifiable, and we have
303 * pasteable data in the clipboard.
305 boolean canPaste(in long aSelectionType);
307 /* ------------ Selection methods -------------- */
309 /** sets the document selection to the entire contents of the document */
310 [can_run_script]
311 void selectAll();
314 * Collapses selection at start of the document. If it's an HTML editor,
315 * collapses selection at start of current editing host (<body> element if
316 * it's in designMode) instead. If there is a non-editable node before any
317 * editable text nodes or inline elements which can have text nodes as their
318 * children, collapses selection at start of the editing host. If there is
319 * an editable text node which is not collapsed, collapses selection at
320 * start of the text node. If there is an editable inline element which
321 * cannot have text nodes as its child, collapses selection at before the
322 * element node. Otherwise, collapses selection at start of the editing
323 * host.
325 void beginningOfDocument();
327 /** sets the document selection to the end of the document */
328 void endOfDocument();
330 /* ------------ Node manipulation methods -------------- */
333 * setAttribute() sets the attribute of aElement.
334 * No checking is done to see if aAttribute is a legal attribute of the node,
335 * or if aValue is a legal value of aAttribute.
337 * @param aElement the content element to operate on
338 * @param aAttribute the string representation of the attribute to set
339 * @param aValue the value to set aAttribute to
341 void setAttribute(in Element aElement, in AString attributestr,
342 in AString attvalue);
345 * getAttributeValue() retrieves the attribute's value for aElement.
347 * @param aElement the content element to operate on
348 * @param aAttribute the string representation of the attribute to get
349 * @param aResultValue [OUT] the value of aAttribute.
350 * Only valid if aResultIsSet is PR_TRUE
351 * @return PR_TRUE if aAttribute is set on the current node,
352 * PR_FALSE if it is not.
354 boolean getAttributeValue(in Element aElement,
355 in AString attributestr,
356 out AString resultValue);
359 * removeAttribute() deletes aAttribute from the attribute list of aElement.
360 * If aAttribute is not an attribute of aElement, nothing is done.
362 * @param aElement the content element to operate on
363 * @param aAttribute the string representation of the attribute to get
365 void removeAttribute(in Element aElement,
366 in AString aAttribute);
369 * cloneAttribute() copies the attribute from the source node to
370 * the destination node and delete those not in the source.
372 * The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)
373 * @param aAttribute the name of the attribute to copy
374 * @param aDestElement the destination element to operate on
375 * @param aSourceElement the source element to copy attributes from
376 * @exception NS_ERROR_NULL_POINTER at least one of the elements is null
378 void cloneAttribute(in AString aAttribute,
379 in Element aDestElement, in Element aSourceElement);
382 * cloneAttributes() is similar to Node::cloneNode(),
383 * it assures the attribute nodes of the destination are identical
384 * with the source node by copying all existing attributes from the
385 * source and deleting those not in the source.
386 * This is used when the destination element already exists
388 * @param aDestNode the destination element to operate on
389 * @param aSourceNode the source element to copy attributes from
391 [can_run_script]
392 void cloneAttributes(in Element aDestElement, in Element aSourceElement);
395 * insertNode inserts aNode into aParent at aPosition.
396 * No checking is done to verify the legality of the insertion.
397 * That is the responsibility of the caller.
398 * @param aNode The DOM Node to insert.
399 * @param aParent The node to insert the new object into
400 * @param aPosition The place in aParent to insert the new node
401 * 0=first child, 1=second child, etc.
402 * any number > number of current children = last child
404 [can_run_script]
405 void insertNode(in Node node,
406 in Node parent,
407 in long aPosition);
411 * splitNode() creates a new node identical to an existing node,
412 * and split the contents between the two nodes
413 * @param aExistingRightNode the node to split.
414 * It will become the new node's next sibling.
415 * @param aOffset the offset of aExistingRightNode's
416 * content|children to do the split at
417 * @param aNewLeftNode [OUT] the new node resulting from the split,
418 * becomes aExistingRightNode's previous sibling.
420 void splitNode(in Node existingRightNode,
421 in long offset,
422 out Node newLeftNode);
425 * joinNodes() takes 2 nodes and merge their content|children.
426 * @param aLeftNode The left node. It will be deleted.
427 * @param aRightNode The right node. It will remain after the join.
428 * @param aParent The parent of aExistingRightNode
430 * There is no requirement that the two nodes be
431 * of the same type. However, a text node can be
432 * merged only with another text node.
434 void joinNodes(in Node leftNode,
435 in Node rightNode,
436 in Node parent);
439 * deleteNode removes aChild from aParent.
440 * @param aChild The node to delete
442 void deleteNode(in Node child);
445 * markNodeDirty() sets a special dirty attribute on the node.
446 * Usually this will be called immediately after creating a new node.
447 * @param aNode The node for which to insert formatting.
449 void markNodeDirty(in Node node);
451 /* ------------ Output methods -------------- */
454 * Output methods:
455 * aFormatType is a mime type, like text/plain.
457 AString outputToString(in AString formatType,
458 in unsigned long flags);
460 /* ------------ Various listeners methods --------------
461 * nsIEditor holds strong references to the editor observers, action listeners
462 * and document state listeners.
465 /** add an EditorObserver to the editors list of observers. */
466 void addEditorObserver(in nsIEditorObserver observer);
468 /** Remove an EditorObserver from the editor's list of observers. */
469 void removeEditorObserver(in nsIEditorObserver observer);
471 /** add an EditActionListener to the editors list of listeners. */
472 void addEditActionListener(in nsIEditActionListener listener);
474 /** Remove an EditActionListener from the editor's list of listeners. */
475 void removeEditActionListener(in nsIEditActionListener listener);
477 /** Add a DocumentStateListener to the editors list of doc state listeners. */
478 void addDocumentStateListener(in nsIDocumentStateListener listener);
480 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
481 void removeDocumentStateListener(in nsIDocumentStateListener listener);
484 * forceCompositionEnd() force the composition end
486 void forceCompositionEnd();
489 * whether this editor has active IME transaction
491 readonly attribute boolean composing;
493 %{C++
495 * AsEditorBase() returns a pointer to EditorBase class.
497 * In order to avoid circular dependency issues, this method is defined
498 * in mozilla/EditorBase.h. Consumers need to #include that header.
500 inline mozilla::EditorBase* AsEditorBase();
501 inline const mozilla::EditorBase* AsEditorBase() const;
504 * AsTextEditor() returns a pointer to TextEditor class.
506 * In order to avoid circular dependency issues, this method is defined
507 * in mozilla/TextEditor.h. Consumers need to #include that header.
509 inline mozilla::TextEditor* AsTextEditor();
510 inline const mozilla::TextEditor* AsTextEditor() const;
513 * AsHTMLEditor() returns a pointer to HTMLEditor class.
515 * In order to avoid circular dependency issues, this method is defined
516 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
518 inline mozilla::HTMLEditor* AsHTMLEditor();
519 inline const mozilla::HTMLEditor* AsHTMLEditor() const;