Bug 1786084 [wpt PR 35538] - Fix bad assertion in css/css-typed-om/stylevalue-normali...
[gecko.git] / editor / nsIEditor.idl
blob8e300c801552de1f1d20bab924830801e16266f6
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 nsIEditActionListener;
18 interface nsIInlineSpellChecker;
19 interface nsITransferable;
21 webidl Document;
22 webidl Element;
23 webidl Node;
24 webidl Selection;
26 %{C++
27 namespace mozilla {
28 class EditorBase;
29 class HTMLEditor;
30 class TextEditor;
31 } // namespace mozilla
34 [scriptable, builtinclass, uuid(094be624-f0bf-400f-89e2-6a84baab9474)]
35 interface nsIEditor : nsISupports
37 %{C++
38 typedef short EDirection;
39 typedef short EStripWrappers;
41 const short eNone = 0;
42 const short eNext = 1;
43 const short ePrevious = 2;
44 const short eNextWord = 3;
45 const short ePreviousWord = 4;
46 const short eToBeginningOfLine = 5;
47 const short eToEndOfLine = 6;
49 const short eStrip = 0;
50 const short eNoStrip = 1;
52 // If you want an HTML editor to behave as a plaintext editor, specify this
53 // flag. Note that this is always set if the instance is a text editor.
54 const long eEditorPlaintextMask = 0x0001;
55 // We don't support single line editor mode with HTML editors. Therefore,
56 // don't specify this for HTML editor.
57 const long eEditorSingleLineMask = 0x0002;
58 // We don't support password editor mode with HTML editors. Therefore,
59 // don't specify this for HTML editor.
60 const long eEditorPasswordMask = 0x0004;
61 // When the editor should be in readonly mode (currently, same as "disabled"),
62 // you can specify this flag with any editor instances. Note that setting
63 // this flag does not change the style of editor. This just changes the
64 // internal editor's readonly state.
65 const long eEditorReadonlyMask = 0x0008;
66 // If you want an HTML editor to work as an email composer, specify this flag.
67 // And you can specify this to text editor too for making spellchecker for
68 // the text editor should work exactly same as email composer's.
69 const long eEditorMailMask = 0x0020;
70 // allow the editor to set font: monospace on the root node
71 const long eEditorEnableWrapHackMask = 0x0040;
72 // If you want to move focus from an HTML editor with tab navigation,
73 // specify this flag. This is not available with text editors becase
74 // it's always tabbable.
75 // Note that if this is not specified, link navigation is also enabled in
76 // the editable content.
77 const long eEditorAllowInteraction = 0x0200;
78 // when this flag is set, the internal direction of the editor is RTL.
79 // if neither of the direction flags are set, the direction is determined
80 // from the text control's content node.
81 const long eEditorRightToLeft = 0x0800;
82 // when this flag is set, the internal direction of the editor is LTR.
83 const long eEditorLeftToRight = 0x1000;
84 // when this flag is set, the editor's text content is not spell checked.
85 const long eEditorSkipSpellCheck = 0x2000;
88 * The valid values for newlines handling.
89 * Can't change the values unless we remove
90 * use of the pref.
92 const long eNewlinesPasteIntact = 0;
93 const long eNewlinesPasteToFirst = 1;
94 const long eNewlinesReplaceWithSpaces = 2;
95 const long eNewlinesStrip = 3;
96 const long eNewlinesReplaceWithCommas = 4;
97 const long eNewlinesStripSurroundingWhitespace = 5;
99 readonly attribute Selection selection;
101 [can_run_script]
102 void setAttributeOrEquivalent(in Element element,
103 in AString sourceAttrName,
104 in AString sourceAttrValue,
105 in boolean aSuppressTransaction);
106 [can_run_script]
107 void removeAttributeOrEquivalent(in Element element,
108 in AString sourceAttrName,
109 in boolean aSuppressTransaction);
111 /** edit flags for this editor. May be set at any time. */
112 [setter_can_run_script] attribute unsigned long flags;
115 * the MimeType of the document
117 attribute AString contentsMIMEType;
119 /** Returns true if we have a document that is not marked read-only */
120 readonly attribute boolean isDocumentEditable;
122 /** Returns true if the current selection anchor is editable */
123 readonly attribute boolean isSelectionEditable;
126 * the DOM Document this editor is associated with, refcounted.
128 readonly attribute Document document;
130 /** the body element, i.e. the root of the editable document.
132 readonly attribute Element rootElement;
135 * the selection controller for the current presentation, refcounted.
137 readonly attribute nsISelectionController selectionController;
140 /* ------------ Selected content removal -------------- */
143 * DeleteSelection removes all nodes in the current selection.
144 * @param aDir if eNext, delete to the right (for example, the DEL key)
145 * if ePrevious, delete to the left (for example, the BACKSPACE key)
146 * @param stripWrappers If eStrip, strip any empty inline elements left
147 * behind after the deletion; if eNoStrip, don't. If in
148 * doubt, pass eStrip -- eNoStrip is only for if you're
149 * about to insert text or similar right after.
151 [can_run_script]
152 void deleteSelection(in short action, in short stripWrappers);
155 /* ------------ Document info and file methods -------------- */
157 /** Returns true if the document has no *meaningful* content */
158 readonly attribute boolean documentIsEmpty;
160 /** Returns true if the document is modifed and needs saving */
161 readonly attribute boolean documentModified;
164 * Sets document's character set. This is available only when the editor
165 * instance is an HTMLEditor since it's odd to change character set of
166 * parent document of `<input>` and `<textarea>`.
168 [setter_can_run_script]
169 attribute ACString documentCharacterSet;
171 /** to be used ONLY when we need to override the doc's modification
172 * state (such as when it's saved).
174 [can_run_script]
175 void resetModificationCount();
177 /** Gets the modification count of the document we are editing.
178 * @return the modification count of the document being edited.
179 * Zero means unchanged.
181 long getModificationCount();
183 /** called each time we modify the document.
184 * Increments the modification count of the document.
185 * @param aModCount the number of modifications by which
186 * to increase or decrease the count
188 [can_run_script]
189 void incrementModificationCount(in long aModCount);
191 /* ------------ Transaction methods -------------- */
193 /** transactionManager Get the transaction manager the editor is using.
195 readonly attribute nsITransactionManager transactionManager;
197 /** turn the undo system on or off
198 * @param aEnable if PR_TRUE, the undo system is turned on if available
199 * if PR_FALSE the undo system is turned off if it
200 * was previously on
201 * @return if aEnable is PR_TRUE, returns NS_OK if
202 * the undo system could be initialized properly
203 * if aEnable is PR_FALSE, returns NS_OK.
205 void enableUndo(in boolean enable);
207 /** undo reverses the effects of the last Do operation,
208 * if Undo is enabled in the editor.
209 * It is provided here so clients need no knowledge of whether
210 * the editor has a transaction manager or not.
211 * If a transaction manager is present, it is told to undo,
212 * and the result of that undo is returned.
213 * Otherwise, the Undo request is ignored and an
214 * error NS_ERROR_NOT_AVAILABLE is returned.
217 [can_run_script]
218 void undo(in unsigned long count);
220 /** returns state information about the undo system.
221 * @param aIsEnabled [OUT] PR_TRUE if undo is enabled
222 * @param aCanUndo [OUT] PR_TRUE if at least one transaction is
223 * currently ready to be undone.
225 void canUndo(out boolean isEnabled, out boolean canUndo);
227 /** redo reverses the effects of the last Undo operation
228 * It is provided here so clients need no knowledge of whether
229 * the editor has a transaction manager or not.
230 * If a transaction manager is present, it is told to redo and the
231 * result of the previously undone transaction is reapplied to the document.
232 * If no transaction is available for Redo, or if the document
233 * has no transaction manager, the Redo request is ignored and an
234 * error NS_ERROR_NOT_AVAILABLE is returned.
237 [can_run_script]
238 void redo(in unsigned long count);
240 /** returns state information about the redo system.
241 * @param aIsEnabled [OUT] PR_TRUE if redo is enabled
242 * @param aCanRedo [OUT] PR_TRUE if at least one transaction is
243 currently ready to be redone.
245 void canRedo(out boolean isEnabled, out boolean canRedo);
247 /** beginTransaction is a signal from the caller to the editor that
248 * the caller will execute multiple updates to the content tree
249 * that should be treated as a single logical operation,
250 * in the most efficient way possible.<br>
251 * All transactions executed between a call to beginTransaction and
252 * endTransaction will be undoable as an atomic action.<br>
253 * endTransaction must be called after beginTransaction.<br>
254 * Calls to beginTransaction can be nested, as long as endTransaction
255 * is called once per beginUpdate.
257 [can_run_script]
258 void beginTransaction();
260 /** endTransaction is a signal to the editor that the caller is
261 * finished updating the content model.<br>
262 * beginUpdate must be called before endTransaction is called.<br>
263 * Calls to beginTransaction can be nested, as long as endTransaction
264 * is called once per beginTransaction.
266 [can_run_script]
267 void endTransaction();
270 * While setting the flag with this method to false, DeleteRangeTransaction,
271 * DeleteTextTransaction, InsertNodeTransaction, InsertTextTransaction and
272 * SplitNodeTransaction won't change Selection after modifying the DOM tree.
273 * Note that calling this with false does not guarantee that Selection won't
274 * be changed because other transaction may ignore this flag, editor itself
275 * may change selection, and current selection may become invalid after
276 * changing the DOM tree, etc.
277 * After calling this method with true, the caller should guarantee that
278 * Selection should be positioned where user expects.
280 * @param should false if you don't want above transactions to modify
281 * Selection automatically after modifying the DOM tree.
282 * Note that calling this with false does not guarantee
283 * that Selection is never changed.
285 void setShouldTxnSetSelection(in boolean should);
287 /* ------------ Inline Spell Checking methods -------------- */
289 /** Returns the inline spell checker associated with this object. The spell
290 * checker is lazily created, so this function may create the object for
291 * you during this call.
292 * @param autoCreate If true, this will create a spell checker object
293 * if one does not exist yet for this editor. If false
294 * and the object has not been created, this function
295 * WILL RETURN NULL.
297 nsIInlineSpellChecker getInlineSpellChecker(in boolean autoCreate);
299 /** Called when the user manually overrides the spellchecking state for this
300 * editor.
301 * @param enable The new state of spellchecking in this editor, as
302 * requested by the user.
304 void setSpellcheckUserOverride(in boolean enable);
306 /* ------------ Clipboard methods -------------- */
308 /** cut the currently selected text, putting it into the OS clipboard
309 * What if no text is selected?
310 * What about mixed selections?
311 * What are the clipboard formats?
313 [can_run_script]
314 void cut();
317 * canCut() returns true if selected content is allowed to be copied to the
318 * clipboard and to be removed.
319 * Note that this always returns true if the editor is in a non-chrome
320 * HTML/XHTML document.
321 * FYI: Current user in script is only BlueGriffon.
323 [can_run_script]
324 boolean canCut();
326 /** copy the currently selected text, putting it into the OS clipboard
327 * What if no text is selected?
328 * What about mixed selections?
329 * What are the clipboard formats?
331 void copy();
334 * canCopy() returns true if selected content is allowed to be copied to
335 * the clipboard.
336 * Note that this always returns true if the editor is in a non-chrome
337 * HTML/XHTML document.
338 * FYI: Current user in script is only BlueGriffon.
340 [can_run_script]
341 boolean canCopy();
343 /** paste the text in the OS clipboard at the cursor position, replacing
344 * the selected text (if any)
346 [can_run_script]
347 void paste(in long aClipboardType);
349 /** Paste the text in |aTransferable| at the cursor position, replacing the
350 * selected text (if any).
352 [can_run_script]
353 void pasteTransferable(in nsITransferable aTransferable);
355 /** Can we paste? True if the doc is modifiable, and we have
356 * pasteable data in the clipboard.
358 boolean canPaste(in long aClipboardType);
360 /* ------------ Selection methods -------------- */
362 /** sets the document selection to the entire contents of the document */
363 [can_run_script]
364 void selectAll();
367 * Collapses selection at start of the document. If it's an HTML editor,
368 * collapses selection at start of current editing host (<body> element if
369 * it's in designMode) instead. If there is a non-editable node before any
370 * editable text nodes or inline elements which can have text nodes as their
371 * children, collapses selection at start of the editing host. If there is
372 * an editable text node which is not collapsed, collapses selection at
373 * start of the text node. If there is an editable inline element which
374 * cannot have text nodes as its child, collapses selection at before the
375 * element node. Otherwise, collapses selection at start of the editing
376 * host.
378 [can_run_script]
379 void beginningOfDocument();
382 * Sets the selection to the end of the last leaf child/descendant or the root
383 * element.
385 [can_run_script]
386 void endOfDocument();
388 /* ------------ Node manipulation methods -------------- */
391 * setAttribute() sets the attribute of aElement.
392 * No checking is done to see if aAttribute is a legal attribute of the node,
393 * or if aValue is a legal value of aAttribute.
395 * @param aElement the content element to operate on
396 * @param aAttribute the string representation of the attribute to set
397 * @param aValue the value to set aAttribute to
399 [can_run_script]
400 void setAttribute(in Element aElement, in AString attributestr,
401 in AString attvalue);
404 * removeAttribute() deletes aAttribute from the attribute list of aElement.
405 * If aAttribute is not an attribute of aElement, nothing is done.
407 * @param aElement the content element to operate on
408 * @param aAttribute the string representation of the attribute to get
410 [can_run_script]
411 void removeAttribute(in Element aElement,
412 in AString aAttribute);
415 * cloneAttributes() is similar to Node::cloneNode(),
416 * it assures the attribute nodes of the destination are identical
417 * with the source node by copying all existing attributes from the
418 * source and deleting those not in the source.
419 * This is used when the destination element already exists
421 * @param aDestNode the destination element to operate on
422 * @param aSourceNode the source element to copy attributes from
424 [can_run_script]
425 void cloneAttributes(in Element aDestElement, in Element aSourceElement);
428 * insertNode inserts aNode into aParent at aPosition.
429 * No checking is done to verify the legality of the insertion.
430 * That is the responsibility of the caller.
431 * @param aNode The DOM Node to insert.
432 * @param aParent The node to insert the new object into
433 * @param aPosition The place in aParent to insert the new node
434 * 0=first child, 1=second child, etc.
435 * any number > number of current children = last child
437 [can_run_script]
438 void insertNode(in Node node,
439 in Node parent,
440 in unsigned long aPosition);
444 * deleteNode removes aChild from aParent.
445 * @param aChild The node to delete
447 [can_run_script]
448 void deleteNode(in Node child);
450 /* ------------ Output methods -------------- */
453 * Output methods:
454 * aFormatType is a mime type, like text/plain.
456 AString outputToString(in AString formatType,
457 in unsigned long flags);
459 /* ------------ Various listeners methods --------------
460 * nsIEditor holds strong references to the editor observers, action listeners
461 * and document state listeners.
464 /** add an EditActionListener to the editors list of listeners. */
465 void addEditActionListener(in nsIEditActionListener listener);
467 /** Remove an EditActionListener from the editor's list of listeners. */
468 void removeEditActionListener(in nsIEditActionListener listener);
470 /** Add a DocumentStateListener to the editors list of doc state listeners. */
471 void addDocumentStateListener(in nsIDocumentStateListener listener);
473 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
474 void removeDocumentStateListener(in nsIDocumentStateListener listener);
477 * forceCompositionEnd() force the composition end
479 void forceCompositionEnd();
482 * whether this editor has active IME transaction
484 readonly attribute boolean composing;
487 * unmask() is available only when the editor is a passwrod field. This
488 * unmasks characters in specified by aStart and aEnd. If there have
489 * already unmasked characters, they are masked when this is called.
490 * Note that if you calls this without non-zero `aTimeout`, you bear
491 * responsibility for masking password with calling `mask()`. I.e.,
492 * user inputting password won't be masked automacitally. If user types
493 * a new character and echo is enabled, unmasked range is expanded to
494 * including it.
496 * @param aStart Optional, first index to show the character. If you
497 * specify middle of a surrogate pair, this expands the
498 * range to include the prceding high surrogate
499 * automatically.
500 * If omitted, it means that all characters of the
501 * password becomes unmasked.
502 * @param aEnd Optional, next index of last unmasked character. If
503 * you specify middle of a surrogate pair, the expands
504 * the range to include the following low surrogate.
505 * If omitted or negative value, it means unmasking all
506 * characters after aStart. Specifying same index
507 * throws an exception.
508 * @param aTimeout Optional, specify milliseconds to hide the unmasked
509 * characters if you want to show them temporarily.
510 * If omitted or 0, it means this won't mask the characters
511 * automatically.
513 [can_run_script, optional_argc] void unmask(
514 [optional] in unsigned long aStart,
515 [optional] in long long aEnd,
516 [optional] in unsigned long aTimeout);
519 * mask() is available only when the editor is a password field. This masks
520 * all unmasked characters immediately.
522 [can_run_script] void mask();
525 * These attributes are available only when the editor is a password field.
526 * unmaskedStart is first unmasked character index, or 0 if there is no
527 * unmasked characters.
528 * unmaskedEnd is next index of the last unmasked character. 0 means there
529 * is no unmasked characters.
531 readonly attribute unsigned long unmaskedStart;
532 readonly attribute unsigned long unmaskedEnd;
535 * autoMaskingEnabled is true if unmasked range and newly inputted characters
536 * are masked automatically. That's the default state. If false, until
537 * `mask()` is called, unmasked range and newly inputted characters are
538 * unmasked.
540 readonly attribute boolean autoMaskingEnabled;
543 * passwordMask attribute is a mask character which is used to mask password.
545 readonly attribute AString passwordMask;
548 * The length of the contents in characters.
550 readonly attribute unsigned long textLength;
552 /** Get and set the body wrap width.
554 * Special values:
555 * 0 = wrap to window width
556 * -1 = no wrap at all
558 attribute long wrapWidth;
560 /** Get and set newline handling.
562 * Values are the constants defined above.
564 attribute long newlineHandling;
567 * Inserts a string at the current location,
568 * given by the selection.
569 * If the selection is not collapsed, the selection is deleted
570 * and the insertion takes place at the resulting collapsed selection.
572 * @param aString the string to be inserted
574 [can_run_script]
575 void insertText(in AString aStringToInsert);
578 * Insert a line break into the content model.
579 * The interpretation of a break is up to the implementation:
580 * it may enter a character, split a node in the tree, etc.
581 * This may be more efficient than calling InsertText with a newline.
583 [can_run_script]
584 void insertLineBreak();
586 %{C++
587 inline bool IsHTMLEditor() const;
588 inline bool IsTextEditor() const;
591 * AsEditorBase() returns a pointer to EditorBase class.
593 * In order to avoid circular dependency issues, this method is defined
594 * in mozilla/EditorBase.h. Consumers need to #include that header.
596 inline mozilla::EditorBase* AsEditorBase();
597 inline const mozilla::EditorBase* AsEditorBase() const;
600 * AsTextEditor() and GetTextEditor() return a pointer to TextEditor class.
601 * AsTextEditor() does not check the concrete class type. So, it never
602 * returns nullptr. GetAsTextEditor() does check the concrete class type.
603 * So, it may return nullptr.
605 * In order to avoid circular dependency issues, this method is defined
606 * in mozilla/TextEditor.h. Consumers need to #include that header.
608 inline mozilla::TextEditor* AsTextEditor();
609 inline const mozilla::TextEditor* AsTextEditor() const;
610 inline mozilla::TextEditor* GetAsTextEditor();
611 inline const mozilla::TextEditor* GetAsTextEditor() const;
614 * AsHTMLEditor() and GetHTMLEditor() return a pointer to HTMLEditor class.
615 * AsHTMLEditor() does not check the concrete class type. So, it never
616 * returns nullptr. GetAsHTMLEditor() does check the concrete class type.
617 * So, it may return nullptr.
619 * In order to avoid circular dependency issues, this method is defined
620 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
622 inline mozilla::HTMLEditor* AsHTMLEditor();
623 inline const mozilla::HTMLEditor* AsHTMLEditor() const;
624 inline mozilla::HTMLEditor* GetAsHTMLEditor();
625 inline const mozilla::HTMLEditor* GetAsHTMLEditor() const;