Bug 1735777 [wpt PR 31236] - webrtc wpt: fix invalid unicode indexOf method call...
[gecko.git] / editor / nsIEditor.idl
blob4f7fa742e84f0520cc4941aff748cf19c2fb7ccd
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, CreateElementTransaction,
271 * DeleteRangeTransaction, DeleteTextTransaction, InsertNodeTransaction,
272 * InsertTextTransaction and SplitNodeTransaction won't change Selection
273 * after modifying the DOM tree.
274 * Note that calling this with false does not guarantee that Selection won't
275 * be changed because other transaction may ignore this flag, editor itself
276 * may change selection, and current selection may become invalid after
277 * changing the DOM tree, etc.
278 * After calling this method with true, the caller should guarantee that
279 * Selection should be positioned where user expects.
281 * @param should false if you don't want above transactions to modify
282 * Selection automatically after modifying the DOM tree.
283 * Note that calling this with false does not guarantee
284 * that Selection is never changed.
286 void setShouldTxnSetSelection(in boolean should);
288 /* ------------ Inline Spell Checking methods -------------- */
290 /** Returns the inline spell checker associated with this object. The spell
291 * checker is lazily created, so this function may create the object for
292 * you during this call.
293 * @param autoCreate If true, this will create a spell checker object
294 * if one does not exist yet for this editor. If false
295 * and the object has not been created, this function
296 * WILL RETURN NULL.
298 nsIInlineSpellChecker getInlineSpellChecker(in boolean autoCreate);
300 /** Called when the user manually overrides the spellchecking state for this
301 * editor.
302 * @param enable The new state of spellchecking in this editor, as
303 * requested by the user.
305 void setSpellcheckUserOverride(in boolean enable);
307 /* ------------ Clipboard methods -------------- */
309 /** cut the currently selected text, putting it into the OS clipboard
310 * What if no text is selected?
311 * What about mixed selections?
312 * What are the clipboard formats?
314 [can_run_script]
315 void cut();
318 * canCut() returns true if selected content is allowed to be copied to the
319 * clipboard and to be removed.
320 * Note that this always returns true if the editor is in a non-chrome
321 * HTML/XHTML document.
322 * FYI: Current user in script is only BlueGriffon.
324 [can_run_script]
325 boolean canCut();
327 /** copy the currently selected text, putting it into the OS clipboard
328 * What if no text is selected?
329 * What about mixed selections?
330 * What are the clipboard formats?
332 void copy();
335 * canCopy() returns true if selected content is allowed to be copied to
336 * the clipboard.
337 * Note that this always returns true if the editor is in a non-chrome
338 * HTML/XHTML document.
339 * FYI: Current user in script is only BlueGriffon.
341 [can_run_script]
342 boolean canCopy();
344 /** paste the text in the OS clipboard at the cursor position, replacing
345 * the selected text (if any)
347 [can_run_script]
348 void paste(in long aClipboardType);
350 /** Paste the text in |aTransferable| at the cursor position, replacing the
351 * selected text (if any).
353 [can_run_script]
354 void pasteTransferable(in nsITransferable aTransferable);
356 /** Can we paste? True if the doc is modifiable, and we have
357 * pasteable data in the clipboard.
359 boolean canPaste(in long aClipboardType);
361 /* ------------ Selection methods -------------- */
363 /** sets the document selection to the entire contents of the document */
364 [can_run_script]
365 void selectAll();
368 * Collapses selection at start of the document. If it's an HTML editor,
369 * collapses selection at start of current editing host (<body> element if
370 * it's in designMode) instead. If there is a non-editable node before any
371 * editable text nodes or inline elements which can have text nodes as their
372 * children, collapses selection at start of the editing host. If there is
373 * an editable text node which is not collapsed, collapses selection at
374 * start of the text node. If there is an editable inline element which
375 * cannot have text nodes as its child, collapses selection at before the
376 * element node. Otherwise, collapses selection at start of the editing
377 * host.
379 [can_run_script]
380 void beginningOfDocument();
382 /** sets the document selection to the end of the document */
383 void endOfDocument();
385 /* ------------ Node manipulation methods -------------- */
388 * setAttribute() sets the attribute of aElement.
389 * No checking is done to see if aAttribute is a legal attribute of the node,
390 * or if aValue is a legal value of aAttribute.
392 * @param aElement the content element to operate on
393 * @param aAttribute the string representation of the attribute to set
394 * @param aValue the value to set aAttribute to
396 [can_run_script]
397 void setAttribute(in Element aElement, in AString attributestr,
398 in AString attvalue);
401 * removeAttribute() deletes aAttribute from the attribute list of aElement.
402 * If aAttribute is not an attribute of aElement, nothing is done.
404 * @param aElement the content element to operate on
405 * @param aAttribute the string representation of the attribute to get
407 [can_run_script]
408 void removeAttribute(in Element aElement,
409 in AString aAttribute);
412 * cloneAttributes() is similar to Node::cloneNode(),
413 * it assures the attribute nodes of the destination are identical
414 * with the source node by copying all existing attributes from the
415 * source and deleting those not in the source.
416 * This is used when the destination element already exists
418 * @param aDestNode the destination element to operate on
419 * @param aSourceNode the source element to copy attributes from
421 [can_run_script]
422 void cloneAttributes(in Element aDestElement, in Element aSourceElement);
425 * insertNode inserts aNode into aParent at aPosition.
426 * No checking is done to verify the legality of the insertion.
427 * That is the responsibility of the caller.
428 * @param aNode The DOM Node to insert.
429 * @param aParent The node to insert the new object into
430 * @param aPosition The place in aParent to insert the new node
431 * 0=first child, 1=second child, etc.
432 * any number > number of current children = last child
434 [can_run_script]
435 void insertNode(in Node node,
436 in Node parent,
437 in unsigned long aPosition);
441 * deleteNode removes aChild from aParent.
442 * @param aChild The node to delete
444 [can_run_script]
445 void deleteNode(in Node child);
447 /* ------------ Output methods -------------- */
450 * Output methods:
451 * aFormatType is a mime type, like text/plain.
453 AString outputToString(in AString formatType,
454 in unsigned long flags);
456 /* ------------ Various listeners methods --------------
457 * nsIEditor holds strong references to the editor observers, action listeners
458 * and document state listeners.
461 /** add an EditActionListener to the editors list of listeners. */
462 void addEditActionListener(in nsIEditActionListener listener);
464 /** Remove an EditActionListener from the editor's list of listeners. */
465 void removeEditActionListener(in nsIEditActionListener listener);
467 /** Add a DocumentStateListener to the editors list of doc state listeners. */
468 void addDocumentStateListener(in nsIDocumentStateListener listener);
470 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
471 void removeDocumentStateListener(in nsIDocumentStateListener listener);
474 * forceCompositionEnd() force the composition end
476 void forceCompositionEnd();
479 * whether this editor has active IME transaction
481 readonly attribute boolean composing;
484 * unmask() is available only when the editor is a passwrod field. This
485 * unmasks characters in specified by aStart and aEnd. If there have
486 * already unmasked characters, they are masked when this is called.
487 * Note that if you calls this without non-zero `aTimeout`, you bear
488 * responsibility for masking password with calling `mask()`. I.e.,
489 * user inputting password won't be masked automacitally. If user types
490 * a new character and echo is enabled, unmasked range is expanded to
491 * including it.
493 * @param aStart Optional, first index to show the character. If you
494 * specify middle of a surrogate pair, this expands the
495 * range to include the prceding high surrogate
496 * automatically.
497 * If omitted, it means that all characters of the
498 * password becomes unmasked.
499 * @param aEnd Optional, next index of last unmasked character. If
500 * you specify middle of a surrogate pair, the expands
501 * the range to include the following low surrogate.
502 * If omitted or negative value, it means unmasking all
503 * characters after aStart. Specifying same index
504 * throws an exception.
505 * @param aTimeout Optional, specify milliseconds to hide the unmasked
506 * characters if you want to show them temporarily.
507 * If omitted or 0, it means this won't mask the characters
508 * automatically.
510 [can_run_script, optional_argc] void unmask(
511 [optional] in unsigned long aStart,
512 [optional] in long long aEnd,
513 [optional] in unsigned long aTimeout);
516 * mask() is available only when the editor is a password field. This masks
517 * all unmasked characters immediately.
519 [can_run_script] void mask();
522 * These attributes are available only when the editor is a password field.
523 * unmaskedStart is first unmasked character index, or 0 if there is no
524 * unmasked characters.
525 * unmaskedEnd is next index of the last unmasked character. 0 means there
526 * is no unmasked characters.
528 readonly attribute unsigned long unmaskedStart;
529 readonly attribute unsigned long unmaskedEnd;
532 * autoMaskingEnabled is true if unmasked range and newly inputted characters
533 * are masked automatically. That's the default state. If false, until
534 * `mask()` is called, unmasked range and newly inputted characters are
535 * unmasked.
537 readonly attribute boolean autoMaskingEnabled;
540 * passwordMask attribute is a mask character which is used to mask password.
542 readonly attribute AString passwordMask;
545 * The length of the contents in characters.
547 readonly attribute unsigned long textLength;
549 /** Get and set the body wrap width.
551 * Special values:
552 * 0 = wrap to window width
553 * -1 = no wrap at all
555 attribute long wrapWidth;
557 /** Get and set newline handling.
559 * Values are the constants defined above.
561 attribute long newlineHandling;
564 * Inserts a string at the current location,
565 * given by the selection.
566 * If the selection is not collapsed, the selection is deleted
567 * and the insertion takes place at the resulting collapsed selection.
569 * @param aString the string to be inserted
571 [can_run_script]
572 void insertText(in AString aStringToInsert);
575 * Insert a line break into the content model.
576 * The interpretation of a break is up to the implementation:
577 * it may enter a character, split a node in the tree, etc.
578 * This may be more efficient than calling InsertText with a newline.
580 [can_run_script]
581 void insertLineBreak();
583 %{C++
584 inline bool IsHTMLEditor() const;
585 inline bool IsTextEditor() const;
588 * AsEditorBase() returns a pointer to EditorBase class.
590 * In order to avoid circular dependency issues, this method is defined
591 * in mozilla/EditorBase.h. Consumers need to #include that header.
593 inline mozilla::EditorBase* AsEditorBase();
594 inline const mozilla::EditorBase* AsEditorBase() const;
597 * AsTextEditor() and GetTextEditor() return a pointer to TextEditor class.
598 * AsTextEditor() does not check the concrete class type. So, it never
599 * returns nullptr. GetAsTextEditor() does check the concrete class type.
600 * So, it may return nullptr.
602 * In order to avoid circular dependency issues, this method is defined
603 * in mozilla/TextEditor.h. Consumers need to #include that header.
605 inline mozilla::TextEditor* AsTextEditor();
606 inline const mozilla::TextEditor* AsTextEditor() const;
607 inline mozilla::TextEditor* GetAsTextEditor();
608 inline const mozilla::TextEditor* GetAsTextEditor() const;
611 * AsHTMLEditor() and GetHTMLEditor() return a pointer to HTMLEditor class.
612 * AsHTMLEditor() does not check the concrete class type. So, it never
613 * returns nullptr. GetAsHTMLEditor() does check the concrete class type.
614 * So, it may return nullptr.
616 * In order to avoid circular dependency issues, this method is defined
617 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
619 inline mozilla::HTMLEditor* AsHTMLEditor();
620 inline const mozilla::HTMLEditor* AsHTMLEditor() const;
621 inline mozilla::HTMLEditor* GetAsHTMLEditor();
622 inline const mozilla::HTMLEditor* GetAsHTMLEditor() const;