Bug 1797237 [wpt PR 36637] - Screen orientation: simplify onchange-event.html, a...
[gecko.git] / editor / nsIEditor.idl
blob4dbf3f4261922fcb51db2e9747176c9e001a5b03
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 nsISelectionController;
11 interface nsIDocumentStateListener;
12 interface nsIEditActionListener;
13 interface nsIInlineSpellChecker;
14 interface nsITransferable;
16 webidl Document;
17 webidl Element;
18 webidl Node;
19 webidl Selection;
21 %{C++
22 namespace mozilla {
23 class EditorBase;
24 class HTMLEditor;
25 class TextEditor;
26 } // namespace mozilla
29 [scriptable, builtinclass, uuid(094be624-f0bf-400f-89e2-6a84baab9474)]
30 interface nsIEditor : nsISupports
32 %{C++
33 typedef short EDirection;
34 typedef short EStripWrappers;
36 const short eNone = 0;
37 const short eNext = 1;
38 const short ePrevious = 2;
39 const short eNextWord = 3;
40 const short ePreviousWord = 4;
41 const short eToBeginningOfLine = 5;
42 const short eToEndOfLine = 6;
44 const short eStrip = 0;
45 const short eNoStrip = 1;
47 // If you want an HTML editor to behave as a plaintext editor, specify this
48 // flag. Note that this is always set if the instance is a text editor.
49 const long eEditorPlaintextMask = 0x0001;
50 // We don't support single line editor mode with HTML editors. Therefore,
51 // don't specify this for HTML editor.
52 const long eEditorSingleLineMask = 0x0002;
53 // We don't support password editor mode with HTML editors. Therefore,
54 // don't specify this for HTML editor.
55 const long eEditorPasswordMask = 0x0004;
56 // When the editor should be in readonly mode (currently, same as "disabled"),
57 // you can specify this flag with any editor instances. Note that setting
58 // this flag does not change the style of editor. This just changes the
59 // internal editor's readonly state.
60 const long eEditorReadonlyMask = 0x0008;
61 // If you want an HTML editor to work as an email composer, specify this flag.
62 // And you can specify this to text editor too for making spellchecker for
63 // the text editor should work exactly same as email composer's.
64 const long eEditorMailMask = 0x0020;
65 // allow the editor to set font: monospace on the root node
66 const long eEditorEnableWrapHackMask = 0x0040;
67 // If you want to move focus from an HTML editor with tab navigation,
68 // specify this flag. This is not available with text editors becase
69 // it's always tabbable.
70 // Note that if this is not specified, link navigation is also enabled in
71 // the editable content.
72 const long eEditorAllowInteraction = 0x0200;
73 // when this flag is set, the internal direction of the editor is RTL.
74 // if neither of the direction flags are set, the direction is determined
75 // from the text control's content node.
76 const long eEditorRightToLeft = 0x0800;
77 // when this flag is set, the internal direction of the editor is LTR.
78 const long eEditorLeftToRight = 0x1000;
79 // when this flag is set, the editor's text content is not spell checked.
80 const long eEditorSkipSpellCheck = 0x2000;
83 * The valid values for newlines handling.
84 * Can't change the values unless we remove
85 * use of the pref.
87 const long eNewlinesPasteIntact = 0;
88 const long eNewlinesPasteToFirst = 1;
89 const long eNewlinesReplaceWithSpaces = 2;
90 const long eNewlinesStrip = 3;
91 const long eNewlinesReplaceWithCommas = 4;
92 const long eNewlinesStripSurroundingWhitespace = 5;
94 readonly attribute Selection selection;
96 [can_run_script]
97 void setAttributeOrEquivalent(in Element element,
98 in AString sourceAttrName,
99 in AString sourceAttrValue,
100 in boolean aSuppressTransaction);
101 [can_run_script]
102 void removeAttributeOrEquivalent(in Element element,
103 in AString sourceAttrName,
104 in boolean aSuppressTransaction);
106 /** edit flags for this editor. May be set at any time. */
107 [setter_can_run_script] attribute unsigned long flags;
110 * the MimeType of the document
112 attribute AString contentsMIMEType;
114 /** Returns true if we have a document that is not marked read-only */
115 readonly attribute boolean isDocumentEditable;
117 /** Returns true if the current selection anchor is editable */
118 readonly attribute boolean isSelectionEditable;
121 * the DOM Document this editor is associated with, refcounted.
123 readonly attribute Document document;
125 /** the body element, i.e. the root of the editable document.
127 readonly attribute Element rootElement;
130 * the selection controller for the current presentation, refcounted.
132 readonly attribute nsISelectionController selectionController;
135 /* ------------ Selected content removal -------------- */
138 * DeleteSelection removes all nodes in the current selection.
139 * @param aDir if eNext, delete to the right (for example, the DEL key)
140 * if ePrevious, delete to the left (for example, the BACKSPACE key)
141 * @param stripWrappers If eStrip, strip any empty inline elements left
142 * behind after the deletion; if eNoStrip, don't. If in
143 * doubt, pass eStrip -- eNoStrip is only for if you're
144 * about to insert text or similar right after.
146 [can_run_script]
147 void deleteSelection(in short action, in short stripWrappers);
150 /* ------------ Document info and file methods -------------- */
152 /** Returns true if the document has no *meaningful* content */
153 readonly attribute boolean documentIsEmpty;
155 /** Returns true if the document is modifed and needs saving */
156 readonly attribute boolean documentModified;
159 * Sets document's character set. This is available only when the editor
160 * instance is an HTMLEditor since it's odd to change character set of
161 * parent document of `<input>` and `<textarea>`.
163 [setter_can_run_script]
164 attribute ACString documentCharacterSet;
166 /** to be used ONLY when we need to override the doc's modification
167 * state (such as when it's saved).
169 [can_run_script]
170 void resetModificationCount();
172 /** Gets the modification count of the document we are editing.
173 * @return the modification count of the document being edited.
174 * Zero means unchanged.
176 long getModificationCount();
178 /** called each time we modify the document.
179 * Increments the modification count of the document.
180 * @param aModCount the number of modifications by which
181 * to increase or decrease the count
183 [can_run_script]
184 void incrementModificationCount(in long aModCount);
186 /* ------------ Transaction methods -------------- */
188 /** turn the undo system on or off
189 * @param aEnable if PR_TRUE, the undo system is turned on if available
190 * if PR_FALSE the undo system is turned off if it
191 * was previously on
192 * @return if aEnable is PR_TRUE, returns NS_OK if
193 * the undo system could be initialized properly
194 * if aEnable is PR_FALSE, returns NS_OK.
196 void enableUndo(in boolean enable);
199 * Returns true when undo/redo is enabled (by default).
201 [infallible] readonly attribute boolean undoRedoEnabled;
204 * Retruns true when undo/redo is enabled and there is one or more transaction
205 * in the undo stack.
207 [infallible] readonly attribute boolean canUndo;
210 * Returns true when undo/redo is enabled and there is one or more transaction
211 * in the redo stack.
213 [infallible] readonly attribute boolean canRedo;
216 * Clears the transactions both for undo and redo.
217 * This may fail if you call this while editor is handling something, i.e.,
218 * don't call this from a legacy mutation event listeners, then, you won't
219 * see any exceptions.
221 [binaryname(ClearUndoRedoXPCOM)]
222 void clearUndoRedo();
225 * Undo the topmost transaction in the undo stack.
226 * This may throw exception when this is called while editor is handling
227 * transactions.
229 [can_run_script]
230 void undo();
233 * Undo all transactions in the undo stack.
234 * This may throw exception when this is called while editor is handling
235 * transactions.
237 [can_run_script]
238 void undoAll();
241 * Redo the topmost transaction in the redo stack.
242 * This may throw exception when this is called while editor is handling
243 * transactions.
245 [can_run_script]
246 void redo();
248 /** beginTransaction is a signal from the caller to the editor that
249 * the caller will execute multiple updates to the content tree
250 * that should be treated as a single logical operation,
251 * in the most efficient way possible.<br>
252 * All transactions executed between a call to beginTransaction and
253 * endTransaction will be undoable as an atomic action.<br>
254 * endTransaction must be called after beginTransaction.<br>
255 * Calls to beginTransaction can be nested, as long as endTransaction
256 * is called once per beginUpdate.
258 [can_run_script]
259 void beginTransaction();
261 /** endTransaction is a signal to the editor that the caller is
262 * finished updating the content model.<br>
263 * beginUpdate must be called before endTransaction is called.<br>
264 * Calls to beginTransaction can be nested, as long as endTransaction
265 * is called once per beginTransaction.
267 [can_run_script]
268 void endTransaction();
271 * While setting the flag with this method to false, DeleteRangeTransaction,
272 * DeleteTextTransaction, InsertNodeTransaction, InsertTextTransaction and
273 * SplitNodeTransaction won't change Selection 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();
383 * Sets the selection to the end of the last leaf child/descendant or the root
384 * element.
386 [can_run_script]
387 void endOfDocument();
389 /* ------------ Node manipulation methods -------------- */
392 * setAttribute() sets the attribute of aElement.
393 * No checking is done to see if aAttribute is a legal attribute of the node,
394 * or if aValue is a legal value of aAttribute.
396 * @param aElement the content element to operate on
397 * @param aAttribute the string representation of the attribute to set
398 * @param aValue the value to set aAttribute to
400 [can_run_script]
401 void setAttribute(in Element aElement, in AString attributestr,
402 in AString attvalue);
405 * removeAttribute() deletes aAttribute from the attribute list of aElement.
406 * If aAttribute is not an attribute of aElement, nothing is done.
408 * @param aElement the content element to operate on
409 * @param aAttribute the string representation of the attribute to get
411 [can_run_script]
412 void removeAttribute(in Element aElement,
413 in AString aAttribute);
416 * cloneAttributes() is similar to Node::cloneNode(),
417 * it assures the attribute nodes of the destination are identical
418 * with the source node by copying all existing attributes from the
419 * source and deleting those not in the source.
420 * This is used when the destination element already exists
422 * @param aDestNode the destination element to operate on
423 * @param aSourceNode the source element to copy attributes from
425 [can_run_script]
426 void cloneAttributes(in Element aDestElement, in Element aSourceElement);
429 * insertNode inserts aNode into aParent at aPosition.
430 * No checking is done to verify the legality of the insertion.
431 * That is the responsibility of the caller.
432 * @param aNode The DOM Node to insert.
433 * @param aParent The node to insert the new object into
434 * @param aPosition The place in aParent to insert the new node
435 * 0=first child, 1=second child, etc.
436 * any number > number of current children = last child
438 [can_run_script]
439 void insertNode(in Node node,
440 in Node parent,
441 in unsigned long aPosition);
445 * deleteNode removes aChild from aParent.
446 * @param aChild The node to delete
448 [can_run_script]
449 void deleteNode(in Node child);
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 EditActionListener to the editors list of listeners. */
466 void addEditActionListener(in nsIEditActionListener listener);
468 /** Remove an EditActionListener from the editor's list of listeners. */
469 void removeEditActionListener(in nsIEditActionListener listener);
471 /** Add a DocumentStateListener to the editors list of doc state listeners. */
472 void addDocumentStateListener(in nsIDocumentStateListener listener);
474 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
475 void removeDocumentStateListener(in nsIDocumentStateListener listener);
478 * forceCompositionEnd() force the composition end
480 void forceCompositionEnd();
483 * whether this editor has active IME transaction
485 readonly attribute boolean composing;
488 * unmask() is available only when the editor is a passwrod field. This
489 * unmasks characters in specified by aStart and aEnd. If there have
490 * already unmasked characters, they are masked when this is called.
491 * Note that if you calls this without non-zero `aTimeout`, you bear
492 * responsibility for masking password with calling `mask()`. I.e.,
493 * user inputting password won't be masked automacitally. If user types
494 * a new character and echo is enabled, unmasked range is expanded to
495 * including it.
497 * @param aStart Optional, first index to show the character. If you
498 * specify middle of a surrogate pair, this expands the
499 * range to include the prceding high surrogate
500 * automatically.
501 * If omitted, it means that all characters of the
502 * password becomes unmasked.
503 * @param aEnd Optional, next index of last unmasked character. If
504 * you specify middle of a surrogate pair, the expands
505 * the range to include the following low surrogate.
506 * If omitted or negative value, it means unmasking all
507 * characters after aStart. Specifying same index
508 * throws an exception.
509 * @param aTimeout Optional, specify milliseconds to hide the unmasked
510 * characters if you want to show them temporarily.
511 * If omitted or 0, it means this won't mask the characters
512 * automatically.
514 [can_run_script, optional_argc] void unmask(
515 [optional] in unsigned long aStart,
516 [optional] in long long aEnd,
517 [optional] in unsigned long aTimeout);
520 * mask() is available only when the editor is a password field. This masks
521 * all unmasked characters immediately.
523 [can_run_script] void mask();
526 * These attributes are available only when the editor is a password field.
527 * unmaskedStart is first unmasked character index, or 0 if there is no
528 * unmasked characters.
529 * unmaskedEnd is next index of the last unmasked character. 0 means there
530 * is no unmasked characters.
532 readonly attribute unsigned long unmaskedStart;
533 readonly attribute unsigned long unmaskedEnd;
536 * autoMaskingEnabled is true if unmasked range and newly inputted characters
537 * are masked automatically. That's the default state. If false, until
538 * `mask()` is called, unmasked range and newly inputted characters are
539 * unmasked.
541 readonly attribute boolean autoMaskingEnabled;
544 * passwordMask attribute is a mask character which is used to mask password.
546 readonly attribute AString passwordMask;
549 * The length of the contents in characters.
551 readonly attribute unsigned long textLength;
553 /** Get and set the body wrap width.
555 * Special values:
556 * 0 = wrap to window width
557 * -1 = no wrap at all
559 attribute long wrapWidth;
561 /** Get and set newline handling.
563 * Values are the constants defined above.
565 attribute long newlineHandling;
568 * Inserts a string at the current location,
569 * given by the selection.
570 * If the selection is not collapsed, the selection is deleted
571 * and the insertion takes place at the resulting collapsed selection.
573 * @param aString the string to be inserted
575 [can_run_script]
576 void insertText(in AString aStringToInsert);
579 * Insert a line break into the content model.
580 * The interpretation of a break is up to the implementation:
581 * it may enter a character, split a node in the tree, etc.
582 * This may be more efficient than calling InsertText with a newline.
584 [can_run_script]
585 void insertLineBreak();
587 %{C++
588 inline bool IsHTMLEditor() const;
589 inline bool IsTextEditor() const;
592 * AsEditorBase() returns a pointer to EditorBase class.
594 * In order to avoid circular dependency issues, this method is defined
595 * in mozilla/EditorBase.h. Consumers need to #include that header.
597 inline mozilla::EditorBase* AsEditorBase();
598 inline const mozilla::EditorBase* AsEditorBase() const;
601 * AsTextEditor() and GetTextEditor() return a pointer to TextEditor class.
602 * AsTextEditor() does not check the concrete class type. So, it never
603 * returns nullptr. GetAsTextEditor() does check the concrete class type.
604 * So, it may return nullptr.
606 * In order to avoid circular dependency issues, this method is defined
607 * in mozilla/TextEditor.h. Consumers need to #include that header.
609 inline mozilla::TextEditor* AsTextEditor();
610 inline const mozilla::TextEditor* AsTextEditor() const;
611 inline mozilla::TextEditor* GetAsTextEditor();
612 inline const mozilla::TextEditor* GetAsTextEditor() const;
615 * AsHTMLEditor() and GetHTMLEditor() return a pointer to HTMLEditor class.
616 * AsHTMLEditor() does not check the concrete class type. So, it never
617 * returns nullptr. GetAsHTMLEditor() does check the concrete class type.
618 * So, it may return nullptr.
620 * In order to avoid circular dependency issues, this method is defined
621 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
623 inline mozilla::HTMLEditor* AsHTMLEditor();
624 inline const mozilla::HTMLEditor* AsHTMLEditor() const;
625 inline mozilla::HTMLEditor* GetAsHTMLEditor();
626 inline const mozilla::HTMLEditor* GetAsHTMLEditor() const;