Bug 1745819 - Require origin permission for content scripts in mv3 r=robwu
[gecko.git] / editor / nsIEditor.idl
blobe557011236e9eb9d4e4249589232764322e6fd53
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();
381 /** sets the document selection to the end of the document */
382 void endOfDocument();
384 /* ------------ Node manipulation methods -------------- */
387 * setAttribute() sets the attribute of aElement.
388 * No checking is done to see if aAttribute is a legal attribute of the node,
389 * or if aValue is a legal value of aAttribute.
391 * @param aElement the content element to operate on
392 * @param aAttribute the string representation of the attribute to set
393 * @param aValue the value to set aAttribute to
395 [can_run_script]
396 void setAttribute(in Element aElement, in AString attributestr,
397 in AString attvalue);
400 * removeAttribute() deletes aAttribute from the attribute list of aElement.
401 * If aAttribute is not an attribute of aElement, nothing is done.
403 * @param aElement the content element to operate on
404 * @param aAttribute the string representation of the attribute to get
406 [can_run_script]
407 void removeAttribute(in Element aElement,
408 in AString aAttribute);
411 * cloneAttributes() is similar to Node::cloneNode(),
412 * it assures the attribute nodes of the destination are identical
413 * with the source node by copying all existing attributes from the
414 * source and deleting those not in the source.
415 * This is used when the destination element already exists
417 * @param aDestNode the destination element to operate on
418 * @param aSourceNode the source element to copy attributes from
420 [can_run_script]
421 void cloneAttributes(in Element aDestElement, in Element aSourceElement);
424 * insertNode inserts aNode into aParent at aPosition.
425 * No checking is done to verify the legality of the insertion.
426 * That is the responsibility of the caller.
427 * @param aNode The DOM Node to insert.
428 * @param aParent The node to insert the new object into
429 * @param aPosition The place in aParent to insert the new node
430 * 0=first child, 1=second child, etc.
431 * any number > number of current children = last child
433 [can_run_script]
434 void insertNode(in Node node,
435 in Node parent,
436 in unsigned long aPosition);
440 * deleteNode removes aChild from aParent.
441 * @param aChild The node to delete
443 [can_run_script]
444 void deleteNode(in Node child);
446 /* ------------ Output methods -------------- */
449 * Output methods:
450 * aFormatType is a mime type, like text/plain.
452 AString outputToString(in AString formatType,
453 in unsigned long flags);
455 /* ------------ Various listeners methods --------------
456 * nsIEditor holds strong references to the editor observers, action listeners
457 * and document state listeners.
460 /** add an EditActionListener to the editors list of listeners. */
461 void addEditActionListener(in nsIEditActionListener listener);
463 /** Remove an EditActionListener from the editor's list of listeners. */
464 void removeEditActionListener(in nsIEditActionListener listener);
466 /** Add a DocumentStateListener to the editors list of doc state listeners. */
467 void addDocumentStateListener(in nsIDocumentStateListener listener);
469 /** Remove a DocumentStateListener to the editors list of doc state listeners. */
470 void removeDocumentStateListener(in nsIDocumentStateListener listener);
473 * forceCompositionEnd() force the composition end
475 void forceCompositionEnd();
478 * whether this editor has active IME transaction
480 readonly attribute boolean composing;
483 * unmask() is available only when the editor is a passwrod field. This
484 * unmasks characters in specified by aStart and aEnd. If there have
485 * already unmasked characters, they are masked when this is called.
486 * Note that if you calls this without non-zero `aTimeout`, you bear
487 * responsibility for masking password with calling `mask()`. I.e.,
488 * user inputting password won't be masked automacitally. If user types
489 * a new character and echo is enabled, unmasked range is expanded to
490 * including it.
492 * @param aStart Optional, first index to show the character. If you
493 * specify middle of a surrogate pair, this expands the
494 * range to include the prceding high surrogate
495 * automatically.
496 * If omitted, it means that all characters of the
497 * password becomes unmasked.
498 * @param aEnd Optional, next index of last unmasked character. If
499 * you specify middle of a surrogate pair, the expands
500 * the range to include the following low surrogate.
501 * If omitted or negative value, it means unmasking all
502 * characters after aStart. Specifying same index
503 * throws an exception.
504 * @param aTimeout Optional, specify milliseconds to hide the unmasked
505 * characters if you want to show them temporarily.
506 * If omitted or 0, it means this won't mask the characters
507 * automatically.
509 [can_run_script, optional_argc] void unmask(
510 [optional] in unsigned long aStart,
511 [optional] in long long aEnd,
512 [optional] in unsigned long aTimeout);
515 * mask() is available only when the editor is a password field. This masks
516 * all unmasked characters immediately.
518 [can_run_script] void mask();
521 * These attributes are available only when the editor is a password field.
522 * unmaskedStart is first unmasked character index, or 0 if there is no
523 * unmasked characters.
524 * unmaskedEnd is next index of the last unmasked character. 0 means there
525 * is no unmasked characters.
527 readonly attribute unsigned long unmaskedStart;
528 readonly attribute unsigned long unmaskedEnd;
531 * autoMaskingEnabled is true if unmasked range and newly inputted characters
532 * are masked automatically. That's the default state. If false, until
533 * `mask()` is called, unmasked range and newly inputted characters are
534 * unmasked.
536 readonly attribute boolean autoMaskingEnabled;
539 * passwordMask attribute is a mask character which is used to mask password.
541 readonly attribute AString passwordMask;
544 * The length of the contents in characters.
546 readonly attribute unsigned long textLength;
548 /** Get and set the body wrap width.
550 * Special values:
551 * 0 = wrap to window width
552 * -1 = no wrap at all
554 attribute long wrapWidth;
556 /** Get and set newline handling.
558 * Values are the constants defined above.
560 attribute long newlineHandling;
563 * Inserts a string at the current location,
564 * given by the selection.
565 * If the selection is not collapsed, the selection is deleted
566 * and the insertion takes place at the resulting collapsed selection.
568 * @param aString the string to be inserted
570 [can_run_script]
571 void insertText(in AString aStringToInsert);
574 * Insert a line break into the content model.
575 * The interpretation of a break is up to the implementation:
576 * it may enter a character, split a node in the tree, etc.
577 * This may be more efficient than calling InsertText with a newline.
579 [can_run_script]
580 void insertLineBreak();
582 %{C++
583 inline bool IsHTMLEditor() const;
584 inline bool IsTextEditor() const;
587 * AsEditorBase() returns a pointer to EditorBase class.
589 * In order to avoid circular dependency issues, this method is defined
590 * in mozilla/EditorBase.h. Consumers need to #include that header.
592 inline mozilla::EditorBase* AsEditorBase();
593 inline const mozilla::EditorBase* AsEditorBase() const;
596 * AsTextEditor() and GetTextEditor() return a pointer to TextEditor class.
597 * AsTextEditor() does not check the concrete class type. So, it never
598 * returns nullptr. GetAsTextEditor() does check the concrete class type.
599 * So, it may return nullptr.
601 * In order to avoid circular dependency issues, this method is defined
602 * in mozilla/TextEditor.h. Consumers need to #include that header.
604 inline mozilla::TextEditor* AsTextEditor();
605 inline const mozilla::TextEditor* AsTextEditor() const;
606 inline mozilla::TextEditor* GetAsTextEditor();
607 inline const mozilla::TextEditor* GetAsTextEditor() const;
610 * AsHTMLEditor() and GetHTMLEditor() return a pointer to HTMLEditor class.
611 * AsHTMLEditor() does not check the concrete class type. So, it never
612 * returns nullptr. GetAsHTMLEditor() does check the concrete class type.
613 * So, it may return nullptr.
615 * In order to avoid circular dependency issues, this method is defined
616 * in mozilla/HTMLEditor.h. Consumers need to #include that header.
618 inline mozilla::HTMLEditor* AsHTMLEditor();
619 inline const mozilla::HTMLEditor* AsHTMLEditor() const;
620 inline mozilla::HTMLEditor* GetAsHTMLEditor();
621 inline const mozilla::HTMLEditor* GetAsHTMLEditor() const;