Bug 1584002 [wpt PR 19310] - Add serialization WPT for CSS comparison functions min...
[gecko.git] / editor / nsIEditor.idl
blobe351ee49a84359b6673f6953c867dc81de43c25e
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 [can_run_script]
106 void deleteSelection(in short action, in short stripWrappers);
109 /* ------------ Document info and file methods -------------- */
111 /** Returns true if the document has no *meaningful* content */
112 readonly attribute boolean documentIsEmpty;
114 /** Returns true if the document is modifed and needs saving */
115 readonly attribute boolean documentModified;
117 /** Sets the current 'Save' document character set */
118 [can_run_script] // setter only
119 attribute ACString documentCharacterSet;
121 /** to be used ONLY when we need to override the doc's modification
122 * state (such as when it's saved).
124 [can_run_script]
125 void resetModificationCount();
127 /** Gets the modification count of the document we are editing.
128 * @return the modification count of the document being edited.
129 * Zero means unchanged.
131 long getModificationCount();
133 /** called each time we modify the document.
134 * Increments the modification count of the document.
135 * @param aModCount the number of modifications by which
136 * to increase or decrease the count
138 [can_run_script]
139 void incrementModificationCount(in long aModCount);
141 /* ------------ Transaction methods -------------- */
143 /** transactionManager Get the transaction manager the editor is using.
145 readonly attribute nsITransactionManager transactionManager;
147 /** doTransaction() fires a transaction.
148 * It is provided here so clients can create their own transactions.
149 * If a transaction manager is present, it is used.
150 * Otherwise, the transaction is just executed directly.
152 * @param aTxn the transaction to execute
154 [can_run_script]
155 void doTransaction(in nsITransaction txn);
158 /** turn the undo system on or off
159 * @param aEnable if PR_TRUE, the undo system is turned on if available
160 * if PR_FALSE the undo system is turned off if it
161 * was previously on
162 * @return if aEnable is PR_TRUE, returns NS_OK if
163 * the undo system could be initialized properly
164 * if aEnable is PR_FALSE, returns NS_OK.
166 void enableUndo(in boolean enable);
168 /** undo reverses the effects of the last Do operation,
169 * if Undo is enabled in the editor.
170 * It is provided here so clients need no knowledge of whether
171 * the editor has a transaction manager or not.
172 * If a transaction manager is present, it is told to undo,
173 * and the result of that undo is returned.
174 * Otherwise, the Undo request is ignored and an
175 * error NS_ERROR_NOT_AVAILABLE is returned.
178 [can_run_script]
179 void undo(in unsigned long count);
181 /** returns state information about the undo system.
182 * @param aIsEnabled [OUT] PR_TRUE if undo is enabled
183 * @param aCanUndo [OUT] PR_TRUE if at least one transaction is
184 * currently ready to be undone.
186 void canUndo(out boolean isEnabled, out boolean canUndo);
188 /** redo reverses the effects of the last Undo operation
189 * It is provided here so clients need no knowledge of whether
190 * the editor has a transaction manager or not.
191 * If a transaction manager is present, it is told to redo and the
192 * result of the previously undone transaction is reapplied to the document.
193 * If no transaction is available for Redo, or if the document
194 * has no transaction manager, the Redo request is ignored and an
195 * error NS_ERROR_NOT_AVAILABLE is returned.
198 [can_run_script]
199 void redo(in unsigned long count);
201 /** returns state information about the redo system.
202 * @param aIsEnabled [OUT] PR_TRUE if redo is enabled
203 * @param aCanRedo [OUT] PR_TRUE if at least one transaction is
204 currently ready to be redone.
206 void canRedo(out boolean isEnabled, out boolean canRedo);
208 /** beginTransaction is a signal from the caller to the editor that
209 * the caller will execute multiple updates to the content tree
210 * that should be treated as a single logical operation,
211 * in the most efficient way possible.<br>
212 * All transactions executed between a call to beginTransaction and
213 * endTransaction will be undoable as an atomic action.<br>
214 * endTransaction must be called after beginTransaction.<br>
215 * Calls to beginTransaction can be nested, as long as endTransaction
216 * is called once per beginUpdate.
218 void beginTransaction();
220 /** endTransaction is a signal to the editor that the caller is
221 * finished updating the content model.<br>
222 * beginUpdate must be called before endTransaction is called.<br>
223 * Calls to beginTransaction can be nested, as long as endTransaction
224 * is called once per beginTransaction.
226 [can_run_script]
227 void endTransaction();
230 * While setting the flag with this method to false, CreateElementTransaction,
231 * DeleteRangeTransaction, DeleteTextTransaction, InsertNodeTransaction,
232 * InsertTextTransaction and SplitNodeTransaction won't change Selection
233 * after modifying the DOM tree.
234 * Note that calling this with false does not guarantee that Selection won't
235 * be changed because other transaction may ignore this flag, editor itself
236 * may change selection, and current selection may become invalid after
237 * changing the DOM tree, etc.
238 * After calling this method with true, the caller should guarantee that
239 * Selection should be positioned where user expects.
241 * @param should false if you don't want above transactions to modify
242 * Selection automatically after modifying the DOM tree.
243 * Note that calling this with false does not guarantee
244 * that Selection is never changed.
246 void setShouldTxnSetSelection(in boolean should);
248 /* ------------ Inline Spell Checking methods -------------- */
250 /** Returns the inline spell checker associated with this object. The spell
251 * checker is lazily created, so this function may create the object for
252 * you during this call.
253 * @param autoCreate If true, this will create a spell checker object
254 * if one does not exist yet for this editor. If false
255 * and the object has not been created, this function
256 * WILL RETURN NULL.
258 nsIInlineSpellChecker getInlineSpellChecker(in boolean autoCreate);
260 /** Called when the user manually overrides the spellchecking state for this
261 * editor.
262 * @param enable The new state of spellchecking in this editor, as
263 * requested by the user.
265 void setSpellcheckUserOverride(in boolean enable);
267 /* ------------ Clipboard methods -------------- */
269 /** cut the currently selected text, putting it into the OS clipboard
270 * What if no text is selected?
271 * What about mixed selections?
272 * What are the clipboard formats?
274 [can_run_script]
275 void cut();
278 * canCut() returns true if selected content is allowed to be copied to the
279 * clipboard and to be removed.
280 * Note that this always returns true if the editor is in a non-chrome
281 * HTML/XHTML document.
282 * FYI: Current user in script is only BlueGriffon.
284 boolean canCut();
286 /** copy the currently selected text, putting it into the OS clipboard
287 * What if no text is selected?
288 * What about mixed selections?
289 * What are the clipboard formats?
291 void copy();
294 * canCopy() returns true if selected content is allowed to be copied to
295 * the clipboard.
296 * Note that this always returns true if the editor is in a non-chrome
297 * HTML/XHTML document.
298 * FYI: Current user in script is only BlueGriffon.
300 boolean canCopy();
302 /** paste the text in the OS clipboard at the cursor position, replacing
303 * the selected text (if any)
305 [can_run_script]
306 void paste(in long aClipboardType);
308 /** Paste the text in |aTransferable| at the cursor position, replacing the
309 * selected text (if any).
311 [can_run_script]
312 void pasteTransferable(in nsITransferable aTransferable);
314 /** Can we paste? True if the doc is modifiable, and we have
315 * pasteable data in the clipboard.
317 boolean canPaste(in long aClipboardType);
319 /* ------------ Selection methods -------------- */
321 /** sets the document selection to the entire contents of the document */
322 [can_run_script]
323 void selectAll();
326 * Collapses selection at start of the document. If it's an HTML editor,
327 * collapses selection at start of current editing host (<body> element if
328 * it's in designMode) instead. If there is a non-editable node before any
329 * editable text nodes or inline elements which can have text nodes as their
330 * children, collapses selection at start of the editing host. If there is
331 * an editable text node which is not collapsed, collapses selection at
332 * start of the text node. If there is an editable inline element which
333 * cannot have text nodes as its child, collapses selection at before the
334 * element node. Otherwise, collapses selection at start of the editing
335 * host.
337 void beginningOfDocument();
339 /** sets the document selection to the end of the document */
340 void endOfDocument();
342 /* ------------ Node manipulation methods -------------- */
345 * setAttribute() sets the attribute of aElement.
346 * No checking is done to see if aAttribute is a legal attribute of the node,
347 * or if aValue is a legal value of aAttribute.
349 * @param aElement the content element to operate on
350 * @param aAttribute the string representation of the attribute to set
351 * @param aValue the value to set aAttribute to
353 [can_run_script]
354 void setAttribute(in Element aElement, in AString attributestr,
355 in AString attvalue);
358 * getAttributeValue() retrieves the attribute's value for aElement.
360 * @param aElement the content element to operate on
361 * @param aAttribute the string representation of the attribute to get
362 * @param aResultValue [OUT] the value of aAttribute.
363 * Only valid if aResultIsSet is PR_TRUE
364 * @return PR_TRUE if aAttribute is set on the current node,
365 * PR_FALSE if it is not.
367 boolean getAttributeValue(in Element aElement,
368 in AString attributestr,
369 out AString resultValue);
372 * removeAttribute() deletes aAttribute from the attribute list of aElement.
373 * If aAttribute is not an attribute of aElement, nothing is done.
375 * @param aElement the content element to operate on
376 * @param aAttribute the string representation of the attribute to get
378 [can_run_script]
379 void removeAttribute(in Element aElement,
380 in AString aAttribute);
383 * cloneAttribute() copies the attribute from the source node to
384 * the destination node and delete those not in the source.
386 * The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)
387 * @param aAttribute the name of the attribute to copy
388 * @param aDestElement the destination element to operate on
389 * @param aSourceElement the source element to copy attributes from
390 * @exception NS_ERROR_NULL_POINTER at least one of the elements is null
392 [can_run_script]
393 void cloneAttribute(in AString aAttribute,
394 in Element aDestElement, in Element aSourceElement);
397 * cloneAttributes() is similar to Node::cloneNode(),
398 * it assures the attribute nodes of the destination are identical
399 * with the source node by copying all existing attributes from the
400 * source and deleting those not in the source.
401 * This is used when the destination element already exists
403 * @param aDestNode the destination element to operate on
404 * @param aSourceNode the source element to copy attributes from
406 [can_run_script]
407 void cloneAttributes(in Element aDestElement, in Element aSourceElement);
410 * insertNode inserts aNode into aParent at aPosition.
411 * No checking is done to verify the legality of the insertion.
412 * That is the responsibility of the caller.
413 * @param aNode The DOM Node to insert.
414 * @param aParent The node to insert the new object into
415 * @param aPosition The place in aParent to insert the new node
416 * 0=first child, 1=second child, etc.
417 * any number > number of current children = last child
419 [can_run_script]
420 void insertNode(in Node node,
421 in Node parent,
422 in long aPosition);
426 * splitNode() creates a new node identical to an existing node,
427 * and split the contents between the two nodes
428 * @param aExistingRightNode the node to split.
429 * It will become the new node's next sibling.
430 * @param aOffset the offset of aExistingRightNode's
431 * content|children to do the split at
432 * @param aNewLeftNode [OUT] the new node resulting from the split,
433 * becomes aExistingRightNode's previous sibling.
435 [can_run_script]
436 void splitNode(in Node existingRightNode,
437 in long offset,
438 out Node newLeftNode);
441 * joinNodes() takes 2 nodes and merge their content|children.
442 * @param aLeftNode The left node. It will be deleted.
443 * @param aRightNode The right node. It will remain after the join.
444 * @param aParent The parent of aExistingRightNode
446 * There is no requirement that the two nodes be
447 * of the same type. However, a text node can be
448 * merged only with another text node.
450 [can_run_script]
451 void joinNodes(in Node leftNode,
452 in Node rightNode,
453 in Node parent);
456 * deleteNode removes aChild from aParent.
457 * @param aChild The node to delete
459 [can_run_script]
460 void deleteNode(in Node child);
463 * markNodeDirty() sets a special dirty attribute on the node.
464 * Usually this will be called immediately after creating a new node.
465 * @param aNode The node for which to insert formatting.
467 void markNodeDirty(in Node node);
469 /* ------------ Output methods -------------- */
472 * Output methods:
473 * aFormatType is a mime type, like text/plain.
475 AString outputToString(in AString formatType,
476 in unsigned long flags);
478 /* ------------ Various listeners methods --------------
479 * nsIEditor holds strong references to the editor observers, action listeners
480 * and document state listeners.
483 /** add an EditorObserver to the editors list of observers. */
484 void addEditorObserver(in nsIEditorObserver observer);
486 /** Remove an EditorObserver from the editor's list of observers. */
487 void removeEditorObserver(in nsIEditorObserver observer);
489 /** add an EditActionListener to the editors list of listeners. */
490 void addEditActionListener(in nsIEditActionListener listener);
492 /** Remove an EditActionListener from the editor's list of listeners. */
493 void removeEditActionListener(in nsIEditActionListener listener);
495 /** Add a DocumentStateListener to the editors list of doc state listeners. */
496 void addDocumentStateListener(in nsIDocumentStateListener listener);
498 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
499 void removeDocumentStateListener(in nsIDocumentStateListener listener);
502 * forceCompositionEnd() force the composition end
504 void forceCompositionEnd();
507 * whether this editor has active IME transaction
509 readonly attribute boolean composing;
512 * unmask() is available only when the editor is a passwrod field. This
513 * unmasks characters in specified by aStart and aEnd. If there have
514 * already unmasked characters, they are masked when this is called.
515 * Note that if you calls this without non-zero `aTimeout`, you bear
516 * responsibility for masking password with calling `mask()`. I.e.,
517 * user inputting password won't be masked automacitally. If user types
518 * a new character and echo is enabled, unmasked range is expanded to
519 * including it.
521 * @param aStart Optional, first index to show the character. If you
522 * specify middle of a surrogate pair, this expands the
523 * range to include the prceding high surrogate
524 * automatically.
525 * If omitted, it means that all characters of the
526 * password becomes unmasked.
527 * @param aEnd Optional, next index of last unmasked character. If
528 * you specify middle of a surrogate pair, the expands
529 * the range to include the following low surrogate.
530 * If omitted or negative value, it means unmasking all
531 * characters after aStart. Specifying same index
532 * throws an exception.
533 * @param aTimeout Optional, specify milliseconds to hide the unmasked
534 * characters if you want to show them temporarily.
535 * If omitted or 0, it means this won't mask the characters
536 * automatically.
538 [can_run_script, optional_argc] void unmask(
539 [optional] in unsigned long aStart,
540 [optional] in long long aEnd,
541 [optional] in unsigned long aTimeout);
544 * mask() is available only when the editor is a password field. This masks
545 * all unmasked characters immediately.
547 [can_run_script] void mask();
550 * These attributes are available only when the editor is a password field.
551 * unmaskedStart is first unmasked character index, or 0 if there is no
552 * unmasked characters.
553 * unmaskedEnd is next index of the last unmasked character. 0 means there
554 * is no unmasked characters.
556 readonly attribute unsigned long unmaskedStart;
557 readonly attribute unsigned long unmaskedEnd;
560 * autoMaskingEnabled is true if unmasked range and newly inputted characters
561 * are masked automatically. That's the default state. If false, until
562 * `mask()` is called, unmasked range and newly inputted characters are
563 * unmasked.
565 readonly attribute boolean autoMaskingEnabled;
568 * passwordMask attribute is a mask character which is used to mask password.
570 readonly attribute AString passwordMask;
572 %{C++
574 * AsEditorBase() returns a pointer to EditorBase class.
576 * In order to avoid circular dependency issues, this method is defined
577 * in mozilla/EditorBase.h. Consumers need to #include that header.
579 inline mozilla::EditorBase* AsEditorBase();
580 inline const mozilla::EditorBase* AsEditorBase() const;
583 * AsTextEditor() returns a pointer to TextEditor class.
585 * In order to avoid circular dependency issues, this method is defined
586 * in mozilla/TextEditor.h. Consumers need to #include that header.
588 inline mozilla::TextEditor* AsTextEditor();
589 inline const mozilla::TextEditor* AsTextEditor() const;
592 * AsHTMLEditor() returns a pointer to HTMLEditor class.
594 * In order to avoid circular dependency issues, this method is defined
595 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
597 inline mozilla::HTMLEditor* AsHTMLEditor();
598 inline const mozilla::HTMLEditor* AsHTMLEditor() const;