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"
11 #include
"mozilla/Debug.h"
14 interface nsISelectionController
;
15 interface nsIDocumentStateListener
;
16 interface nsIEditActionListener
;
17 interface nsIInlineSpellChecker
;
18 interface nsITransferable
;
30 } // namespace mozilla
33 [scriptable
, builtinclass
, uuid(094be624
-f0bf
-400f
-89e2
-6a84baab9474
)]
34 interface nsIEditor
: nsISupports
37 typedef short EDirection
;
38 typedef short EStripWrappers
;
40 const short eNone
= 0;
41 const short eNext
= 1;
42 const short ePrevious
= 2;
43 const short eNextWord
= 3;
44 const short ePreviousWord
= 4;
45 const short eToBeginningOfLine
= 5;
46 const short eToEndOfLine
= 6;
49 static bool EDirectionIsValid
(EDirection aDirectionAndAmount
) {
50 return aDirectionAndAmount
== nsIEditor
::eNone ||
51 aDirectionAndAmount
== nsIEditor
::eNext ||
52 aDirectionAndAmount
== nsIEditor
::ePrevious ||
53 aDirectionAndAmount
== nsIEditor
::eNextWord ||
54 aDirectionAndAmount
== nsIEditor
::ePreviousWord ||
55 aDirectionAndAmount
== nsIEditor
::eToBeginningOfLine ||
56 aDirectionAndAmount
== nsIEditor
::eToEndOfLine
;
58 static bool EDirectionIsValidExceptNone
(EDirection aDirectionAndAmount
) {
59 return aDirectionAndAmount
!= nsIEditor
::eNone
&&
60 EDirectionIsValid
(aDirectionAndAmount
);
64 * Return true if nsIEditor::EDirection value means the direction of pressing
67 [[nodiscard
]] static bool DirectionIsBackspace
(
68 EDirection aDirectionAndAmount
) {
69 MOZ_ASSERT
(EDirectionIsValid
(aDirectionAndAmount
));
70 return aDirectionAndAmount
== nsIEditor
::ePrevious ||
71 aDirectionAndAmount
== nsIEditor
::ePreviousWord ||
72 aDirectionAndAmount
== nsIEditor
::eToBeginningOfLine
;
76 * Return true if nsIEditor::EDirection value means the direction of pressing
77 * `Delete` key (forwardDelete).
79 [[nodiscard
]] static bool DirectionIsDelete
(
80 EDirection aDirectionAndAmount
) {
81 MOZ_ASSERT
(EDirectionIsValid
(aDirectionAndAmount
));
82 return aDirectionAndAmount
== nsIEditor
::eNext ||
83 aDirectionAndAmount
== nsIEditor
::eNextWord ||
84 aDirectionAndAmount
== nsIEditor
::eToEndOfLine
;
88 const short eStrip
= 0;
89 const short eNoStrip
= 1;
91 // If you want an HTML editor to behave as a plaintext editor, specify this
92 // flag. Note that this is always set if the instance is a text editor.
93 const long eEditorPlaintextMask
= 0x0001;
94 // We don't support single line editor mode with HTML editors. Therefore,
95 // don't specify this for HTML editor.
96 const long eEditorSingleLineMask
= 0x0002;
97 // We don't support password editor mode with HTML editors. Therefore,
98 // don't specify this for HTML editor.
99 const long eEditorPasswordMask
= 0x0004;
100 // When the editor should be in readonly mode (currently, same as "disabled"),
101 // you can specify this flag with any editor instances.
102 // NOTE: Setting this flag does not change the style of editor. This just
103 // changes the internal editor's readonly state.
104 // NOTE: The readonly mode does NOT block XPCOM APIs which modify the editor
105 // content. This just blocks edit operations from user input and editing
106 // commands (both HTML Document.execCommand and the XUL commands).
107 // FIXME: XPCOM methods of TextEditor may be blocked by this flag. If you
108 // find it, file a bug.
109 const long eEditorReadonlyMask
= 0x0008;
110 // If you want an HTML editor to work as an email composer, specify this flag.
111 // And you can specify this to text editor too for making spellchecker for
112 // the text editor should work exactly same as email composer's.
113 const long eEditorMailMask
= 0x0020;
114 // allow the editor to set font: monospace on the root node
115 const long eEditorEnableWrapHackMask
= 0x0040;
116 // If you want to move focus from an HTML editor with tab navigation,
117 // specify this flag. This is not available with text editors becase
118 // it's always tabbable.
119 // Note that if this is not specified, link navigation is also enabled in
120 // the editable content.
121 const long eEditorAllowInteraction
= 0x0200;
122 // when this flag is set, the internal direction of the editor is RTL.
123 // if neither of the direction flags are set, the direction is determined
124 // from the text control's content node.
125 const long eEditorRightToLeft
= 0x0800;
126 // when this flag is set, the internal direction of the editor is LTR.
127 const long eEditorLeftToRight
= 0x1000;
128 // when this flag is set, the editor's text content is not spell checked.
129 const long eEditorSkipSpellCheck
= 0x2000;
132 * The valid values for newlines handling.
133 * Can't change the values unless we remove
136 const long eNewlinesPasteIntact
= 0;
137 const long eNewlinesPasteToFirst
= 1;
138 const long eNewlinesReplaceWithSpaces
= 2;
139 const long eNewlinesStrip
= 3;
140 const long eNewlinesReplaceWithCommas
= 4;
141 const long eNewlinesStripSurroundingWhitespace
= 5;
143 readonly attribute Selection selection
;
146 void setAttributeOrEquivalent
(in Element element
,
147 in AString sourceAttrName
,
148 in AString sourceAttrValue
,
149 in boolean aSuppressTransaction
);
151 void removeAttributeOrEquivalent
(in Element element
,
152 in AString sourceAttrName
,
153 in boolean aSuppressTransaction
);
155 /** edit flags for this editor. May be set at any time. */
156 [setter_can_run_script
] attribute
unsigned long flags
;
159 * the MimeType of the document
161 attribute AString contentsMIMEType
;
163 /** Returns true if we have a document that is not marked read-only */
164 readonly attribute
boolean isDocumentEditable
;
166 /** Returns true if the current selection anchor is editable */
167 readonly attribute
boolean isSelectionEditable
;
170 * the DOM Document this editor is associated with, refcounted.
172 readonly attribute Document document
;
174 /** the body element, i.e. the root of the editable document.
176 readonly attribute Element rootElement
;
179 * the selection controller for the current presentation, refcounted.
181 readonly attribute nsISelectionController selectionController
;
184 /* ------------ Selected content removal -------------- */
187 * DeleteSelection removes all nodes in the current selection.
188 * @param aDir if eNext, delete to the right (for example, the DEL key)
189 * if ePrevious, delete to the left (for example, the BACKSPACE key)
190 * @param stripWrappers If eStrip, strip any empty inline elements left
191 * behind after the deletion; if eNoStrip, don't. If in
192 * doubt, pass eStrip -- eNoStrip is only for if you're
193 * about to insert text or similar right after.
196 void deleteSelection
(in short action
, in short stripWrappers
);
199 /* ------------ Document info and file methods -------------- */
201 /** Returns true if the document has no *meaningful* content */
202 readonly attribute
boolean documentIsEmpty
;
204 /** Returns true if the document is modifed and needs saving */
205 readonly attribute
boolean documentModified
;
208 * Sets document's character set. This is available only when the editor
209 * instance is an HTMLEditor since it's odd to change character set of
210 * parent document of `<input>` and `<textarea>`.
212 [setter_can_run_script
]
213 attribute ACString documentCharacterSet
;
215 /** to be used ONLY when we need to override the doc's modification
216 * state (such as when it's saved).
219 void resetModificationCount
();
221 /** Gets the modification count of the document we are editing.
222 * @return the modification count of the document being edited.
223 * Zero means unchanged.
225 long getModificationCount
();
227 /** called each time we modify the document.
228 * Increments the modification count of the document.
229 * @param aModCount the number of modifications by which
230 * to increase or decrease the count
233 void incrementModificationCount
(in long aModCount
);
235 /* ------------ Transaction methods -------------- */
237 /** turn the undo system on or off
238 * @param aEnable if PR_TRUE, the undo system is turned on if available
239 * if PR_FALSE the undo system is turned off if it
241 * @return if aEnable is PR_TRUE, returns NS_OK if
242 * the undo system could be initialized properly
243 * if aEnable is PR_FALSE, returns NS_OK.
245 void enableUndo
(in boolean enable
);
248 * Returns true when undo/redo is enabled (by default).
250 [infallible
] readonly attribute
boolean undoRedoEnabled
;
253 * Retruns true when undo/redo is enabled and there is one or more transaction
256 [infallible
] readonly attribute
boolean canUndo
;
259 * Returns true when undo/redo is enabled and there is one or more transaction
262 [infallible
] readonly attribute
boolean canRedo
;
265 * Clears the transactions both for undo and redo.
266 * This may fail if you call this while editor is handling something, i.e.,
267 * don't call this from a legacy mutation event listeners, then, you won't
268 * see any exceptions.
270 [binaryname
(ClearUndoRedoXPCOM
)]
271 void clearUndoRedo
();
274 * Undo the topmost transaction in the undo stack.
275 * This may throw exception when this is called while editor is handling
282 * Undo all transactions in the undo stack.
283 * This may throw exception when this is called while editor is handling
290 * Redo the topmost transaction in the redo stack.
291 * This may throw exception when this is called while editor is handling
297 /** beginTransaction is a signal from the caller to the editor that
298 * the caller will execute multiple updates to the content tree
299 * that should be treated as a single logical operation,
300 * in the most efficient way possible.<br>
301 * All transactions executed between a call to beginTransaction and
302 * endTransaction will be undoable as an atomic action.<br>
303 * endTransaction must be called after beginTransaction.<br>
304 * Calls to beginTransaction can be nested, as long as endTransaction
305 * is called once per beginUpdate.
308 void beginTransaction
();
310 /** endTransaction is a signal to the editor that the caller is
311 * finished updating the content model.<br>
312 * beginUpdate must be called before endTransaction is called.<br>
313 * Calls to beginTransaction can be nested, as long as endTransaction
314 * is called once per beginTransaction.
317 void endTransaction
();
320 * While setting the flag with this method to false, DeleteRangeTransaction,
321 * DeleteTextTransaction, InsertNodeTransaction, InsertTextTransaction and
322 * SplitNodeTransaction won't change Selection after modifying the DOM tree.
323 * Note that calling this with false does not guarantee that Selection won't
324 * be changed because other transaction may ignore this flag, editor itself
325 * may change selection, and current selection may become invalid after
326 * changing the DOM tree, etc.
327 * After calling this method with true, the caller should guarantee that
328 * Selection should be positioned where user expects.
330 * @param should false if you don't want above transactions to modify
331 * Selection automatically after modifying the DOM tree.
332 * Note that calling this with false does not guarantee
333 * that Selection is never changed.
335 void setShouldTxnSetSelection
(in boolean should
);
337 /* ------------ Inline Spell Checking methods -------------- */
339 /** Returns the inline spell checker associated with this object. The spell
340 * checker is lazily created, so this function may create the object for
341 * you during this call.
342 * @param autoCreate If true, this will create a spell checker object
343 * if one does not exist yet for this editor. If false
344 * and the object has not been created, this function
347 nsIInlineSpellChecker getInlineSpellChecker
(in boolean autoCreate
);
349 /** Called when the user manually overrides the spellchecking state for this
351 * @param enable The new state of spellchecking in this editor, as
352 * requested by the user.
354 void setSpellcheckUserOverride
(in boolean enable
);
356 /* ------------ Clipboard methods -------------- */
358 /** cut the currently selected text, putting it into the OS clipboard
359 * What if no text is selected?
360 * What about mixed selections?
361 * What are the clipboard formats?
367 * canCut() returns true if selected content is allowed to be copied to the
368 * clipboard and to be removed.
369 * Note that this always returns true if the editor is in a non-chrome
370 * HTML/XHTML document.
371 * FYI: Current user in script is only BlueGriffon.
376 /** copy the currently selected text, putting it into the OS clipboard
377 * What if no text is selected?
378 * What about mixed selections?
379 * What are the clipboard formats?
385 * canCopy() returns true if selected content is allowed to be copied to
387 * Note that this always returns true if the editor is in a non-chrome
388 * HTML/XHTML document.
389 * FYI: Current user in script is only BlueGriffon.
394 /** paste the text in the OS clipboard at the cursor position, replacing
395 * the selected text (if any)
398 void paste
(in long aClipboardType
);
400 /** Paste the text in |aTransferable| at the cursor position, replacing the
401 * selected text (if any).
404 void pasteTransferable
(in nsITransferable aTransferable
);
406 /** Can we paste? True if the doc is modifiable, and we have
407 * pasteable data in the clipboard.
409 boolean canPaste
(in long aClipboardType
);
411 /* ------------ Selection methods -------------- */
413 /** sets the document selection to the entire contents of the document */
418 * Collapses selection at start of the document. If it's an HTML editor,
419 * collapses selection at start of current editing host (<body> element if
420 * it's in designMode) instead. If there is a non-editable node before any
421 * editable text nodes or inline elements which can have text nodes as their
422 * children, collapses selection at start of the editing host. If there is
423 * an editable text node which is not collapsed, collapses selection at
424 * start of the text node. If there is an editable inline element which
425 * cannot have text nodes as its child, collapses selection at before the
426 * element node. Otherwise, collapses selection at start of the editing
430 void beginningOfDocument
();
433 * Sets the selection to the end of the last leaf child/descendant or the root
437 void endOfDocument
();
439 /* ------------ Node manipulation methods -------------- */
442 * setAttribute() sets the attribute of aElement.
443 * No checking is done to see if aAttribute is a legal attribute of the node,
444 * or if aValue is a legal value of aAttribute.
446 * @param aElement the content element to operate on
447 * @param aAttribute the string representation of the attribute to set
448 * @param aValue the value to set aAttribute to
451 void setAttribute
(in Element aElement
, in AString attributestr
,
452 in AString attvalue
);
455 * removeAttribute() deletes aAttribute from the attribute list of aElement.
456 * If aAttribute is not an attribute of aElement, nothing is done.
458 * @param aElement the content element to operate on
459 * @param aAttribute the string representation of the attribute to get
462 void removeAttribute
(in Element aElement
,
463 in AString aAttribute
);
466 * cloneAttributes() is similar to Node::cloneNode(),
467 * it assures the attribute nodes of the destination are identical
468 * with the source node by copying all existing attributes from the
469 * source and deleting those not in the source.
470 * This is used when the destination element already exists
472 * @param aDestNode the destination element to operate on
473 * @param aSourceNode the source element to copy attributes from
476 void cloneAttributes
(in Element aDestElement
, in Element aSourceElement
);
479 * insertNode inserts aNode into aParent at aPosition.
480 * No checking is done to verify the legality of the insertion.
481 * That is the responsibility of the caller.
482 * @param aNode The DOM Node to insert.
483 * @param aParent The node to insert the new object into
484 * @param aPosition The place in aParent to insert the new node
485 * 0=first child, 1=second child, etc.
486 * any number > number of current children = last child
489 void insertNode
(in Node node
,
491 in unsigned long aPosition
);
495 * deleteNode removes aChild from aParent.
496 * @param aChild The node to delete
499 void deleteNode
(in Node child
);
501 /* ------------ Output methods -------------- */
505 * aFormatType is a mime type, like text/plain.
507 AString outputToString
(in AString formatType
,
508 in unsigned long flags
);
510 /* ------------ Various listeners methods --------------
511 * nsIEditor holds strong references to the editor observers, action listeners
512 * and document state listeners.
515 /** add an EditActionListener to the editors list of listeners. */
516 void addEditActionListener
(in nsIEditActionListener listener
);
518 /** Remove an EditActionListener from the editor's list of listeners. */
519 void removeEditActionListener
(in nsIEditActionListener listener
);
521 /** Add a DocumentStateListener to the editors list of doc state listeners. */
522 void addDocumentStateListener
(in nsIDocumentStateListener listener
);
524 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
525 void removeDocumentStateListener
(in nsIDocumentStateListener listener
);
528 * forceCompositionEnd() force the composition end
530 void forceCompositionEnd
();
533 * whether this editor has active IME transaction
535 readonly attribute
boolean composing
;
538 * unmask() is available only when the editor is a passwrod field. This
539 * unmasks characters in specified by aStart and aEnd. If there have
540 * already unmasked characters, they are masked when this is called.
541 * Note that if you calls this without non-zero `aTimeout`, you bear
542 * responsibility for masking password with calling `mask()`. I.e.,
543 * user inputting password won't be masked automacitally. If user types
544 * a new character and echo is enabled, unmasked range is expanded to
547 * @param aStart Optional, first index to show the character. If you
548 * specify middle of a surrogate pair, this expands the
549 * range to include the prceding high surrogate
551 * If omitted, it means that all characters of the
552 * password becomes unmasked.
553 * @param aEnd Optional, next index of last unmasked character. If
554 * you specify middle of a surrogate pair, the expands
555 * the range to include the following low surrogate.
556 * If omitted or negative value, it means unmasking all
557 * characters after aStart. Specifying same index
558 * throws an exception.
559 * @param aTimeout Optional, specify milliseconds to hide the unmasked
560 * characters if you want to show them temporarily.
561 * If omitted or 0, it means this won't mask the characters
564 [can_run_script
, optional_argc
] void unmask
(
565 [optional] in unsigned long aStart
,
566 [optional] in long long aEnd
,
567 [optional] in unsigned long aTimeout
);
570 * mask() is available only when the editor is a password field. This masks
571 * all unmasked characters immediately.
573 [can_run_script
] void mask
();
576 * These attributes are available only when the editor is a password field.
577 * unmaskedStart is first unmasked character index, or 0 if there is no
578 * unmasked characters.
579 * unmaskedEnd is next index of the last unmasked character. 0 means there
580 * is no unmasked characters.
582 readonly attribute
unsigned long unmaskedStart
;
583 readonly attribute
unsigned long unmaskedEnd
;
586 * autoMaskingEnabled is true if unmasked range and newly inputted characters
587 * are masked automatically. That's the default state. If false, until
588 * `mask()` is called, unmasked range and newly inputted characters are
591 readonly attribute
boolean autoMaskingEnabled
;
594 * passwordMask attribute is a mask character which is used to mask password.
596 readonly attribute AString passwordMask
;
599 * The length of the contents in characters.
601 readonly attribute
unsigned long textLength
;
603 /** Get and set the body wrap width.
606 * 0 = wrap to window width
607 * -1 = no wrap at all
609 attribute
long wrapWidth
;
611 /** Get and set newline handling.
613 * Values are the constants defined above.
615 attribute
long newlineHandling
;
618 * Inserts a string at the current location,
619 * given by the selection.
620 * If the selection is not collapsed, the selection is deleted
621 * and the insertion takes place at the resulting collapsed selection.
623 * @param aString the string to be inserted
626 void insertText
(in AString aStringToInsert
);
629 * Insert a line break into the content model.
630 * The interpretation of a break is up to the implementation:
631 * it may enter a character, split a node in the tree, etc.
632 * This may be more efficient than calling InsertText with a newline.
635 void insertLineBreak
();
638 inline bool IsHTMLEditor
() const;
639 inline bool IsTextEditor
() const;
642 * AsEditorBase() returns a pointer to EditorBase class.
644 * In order to avoid circular dependency issues, this method is defined
645 * in mozilla/EditorBase.h. Consumers need to #include that header.
647 inline mozilla
::EditorBase
* AsEditorBase
();
648 inline
const mozilla
::EditorBase
* AsEditorBase
() const;
651 * AsTextEditor() and GetTextEditor() return a pointer to TextEditor class.
652 * AsTextEditor() does not check the concrete class type. So, it never
653 * returns nullptr. GetAsTextEditor() does check the concrete class type.
654 * So, it may return nullptr.
656 * In order to avoid circular dependency issues, this method is defined
657 * in mozilla/TextEditor.h. Consumers need to #include that header.
659 inline mozilla
::TextEditor
* AsTextEditor
();
660 inline
const mozilla
::TextEditor
* AsTextEditor
() const;
661 inline mozilla
::TextEditor
* GetAsTextEditor
();
662 inline
const mozilla
::TextEditor
* GetAsTextEditor
() const;
665 * AsHTMLEditor() and GetHTMLEditor() return a pointer to HTMLEditor class.
666 * AsHTMLEditor() does not check the concrete class type. So, it never
667 * returns nullptr. GetAsHTMLEditor() does check the concrete class type.
668 * So, it may return nullptr.
670 * In order to avoid circular dependency issues, this method is defined
671 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
673 inline mozilla
::HTMLEditor
* AsHTMLEditor
();
674 inline
const mozilla
::HTMLEditor
* AsHTMLEditor
() const;
675 inline mozilla
::HTMLEditor
* GetAsHTMLEditor
();
676 inline
const mozilla
::HTMLEditor
* GetAsHTMLEditor
() const;