nsIEditor

IID:D4882FFB-E927-408b-96BE-D4391B456FA9
Inherits From:nsISupports

This interface is implemented by the following components:


Constants

PRInt16 eNone = 0
PRInt16 eNext = 1
PRInt16 ePrevious = 2
PRInt16 eNextWord = 3
PRInt16 ePreviousWord = 4
PRInt16 eToBeginningOfLine = 5
PRInt16 eToEndOfLine = 6

Properties

char* contentsMIMEType

The MimeType of the document

readonly nsIDOMDocument document

The DOM Document this editor is associated with, refcounted.

ACString documentCharacterSet

readonly PRBool documentIsEmpty

readonly PRBool documentModified

PRUint32 flags

readonly nsIInlineSpellChecker inlineSpellChecker

readonly PRBool isDocumentEditable

readonly nsIDOMElement rootElement

The body element, i.e. the root of the editable document.

readonly nsISelection selection

readonly nsISelectionController selectionController

The selection controller for the current presentation, refcounted.

readonly nsITransactionManager transactionManager

TransactionManager Get the transaction manager the editor is using.


Methods

void addDocumentStateListener ( nsIDocumentStateListener listener ) void addEditActionListener ( nsIEditActionListener listener ) void addEditorObserver ( nsIEditorObserver observer ) void beginningOfDocument ( ) void beginPlaceHolderTransaction ( nsIAtom name ) void beginTransaction ( ) PRBool canCopy ( ) PRBool canCut ( ) PRBool canDrag ( nsIDOMEvent event ) PRBool canPaste ( PRInt32 selectionType ) void canRedo ( out PRBool isEnabled , out PRBool canRedo ) void canUndo ( out PRBool isEnabled , out PRBool canUndo ) void cloneAttribute ( AString attribute , nsIDOMNode destNode , nsIDOMNode sourceNode ) void cloneAttributes ( nsIDOMNode destNode , nsIDOMNode sourceNode ) void copy ( ) nsIDOMNode createNode ( AString tag , nsIDOMNode parent , PRInt32 position ) void cut ( ) void debugDumpContent ( ) void debugUnitTests ( out PRInt32 outNumTests , out PRInt32 outNumTestsFailed ) void deleteNode ( nsIDOMNode child ) void deleteSelection ( PRInt16 action ) void doDrag ( nsIDOMEvent event ) void doTransaction ( nsITransaction txn ) void dumpContentTree ( ) void enableUndo ( PRBool enable ) void endOfDocument ( ) void endPlaceHolderTransaction ( ) void endTransaction ( ) PRBool getAttributeValue ( nsIDOMElement element , AString attributestr , out AString resultValue ) PRInt32 getModificationCount ( ) void incrementModificationCount ( PRInt32 modCount ) [noscript] void init ( nsIDOMDocument doc , nsIPresShellPtr shell , nsIContentPtr root , nsISelectionController selCon , PRUint32 flags ) void insertFromDrop ( nsIDOMEvent event ) void insertNode ( nsIDOMNode node , nsIDOMNode parent , PRInt32 position ) void joinNodes ( nsIDOMNode leftNode , nsIDOMNode rightNode , nsIDOMNode parent ) void markNodeDirty ( nsIDOMNode node ) void outputToStream ( nsIOutputStream stream , AString formatType , ACString charsetOverride , PRUint32 flags ) AString outputToString ( AString formatType , PRUint32 flags ) void paste ( PRInt32 selectionType ) void postCreate ( ) void preDestroy ( ) void redo ( PRUint32 count ) void removeAttribute ( nsIDOMElement element , AString attribute ) void removeAttributeOrEquivalent ( nsIDOMElement element , DOMString sourceAttrName , PRBool suppressTransaction ) void removeDocumentStateListener ( nsIDocumentStateListener listener ) void removeEditActionListener ( nsIEditActionListener listener ) void removeEditorObserver ( nsIEditorObserver observer ) void resetModificationCount ( ) void selectAll ( ) void setAttribute ( nsIDOMElement element , AString attributestr , AString attvalue ) void setAttributeOrEquivalent ( nsIDOMElement element , AString sourceAttrName , AString sourceAttrValue , PRBool suppressTransaction ) void setShouldTxnSetSelection ( PRBool should ) PRBool shouldTxnSetSelection ( ) void splitNode ( nsIDOMNode existingRightNode , PRInt32 offset , out nsIDOMNode newLeftNode ) void switchTextDirection ( ) void undo ( PRUint32 count )

void addDocumentStateListener ( nsIDocumentStateListener listener )

Arguments:
listener

void addEditActionListener ( nsIEditActionListener listener )

Arguments:
listener

void addEditorObserver ( nsIEditorObserver observer )

Arguments:
observer

void beginningOfDocument ( )


void beginPlaceHolderTransaction ( nsIAtom name )

Arguments:
name

void beginTransaction ( )

BeginTransaction is a signal from the caller to the editor that the caller will execute multiple updates to the content tree that should be treated as a single logical operation, in the most efficient way possible.
All transactions executed between a call to beginTransaction and endTransaction will be undoable as an atomic action.
endTransaction must be called after beginTransaction.
Calls to beginTransaction can be nested, as long as endTransaction is called once per beginUpdate.


PRBool canCopy ( )

Can we copy? True if we have a non-collapsed selection.


PRBool canCut ( )

Can we cut? True if the doc is modifiable, and we have a non- collapsed selection.


PRBool canDrag ( nsIDOMEvent event )

CanDrag decides if a drag should be started (for example, based on the current selection and mousepoint).

Arguments:
event

PRBool canPaste ( PRInt32 selectionType )

Can we paste? True if the doc is modifiable, and we have pasteable data in the clipboard.

Arguments:
selectionType

void canRedo ( out PRBool isEnabled , out PRBool canRedo )

Returns state information about the redo system.

Arguments:
isEnabled: [OUT] PR_TRUE if redo is enabled
canRedo: [OUT] PR_TRUE if at least one transaction is currently ready to be redone.

void canUndo ( out PRBool isEnabled , out PRBool canUndo )

Returns state information about the undo system.

Arguments:
isEnabled: [OUT] PR_TRUE if undo is enabled
canUndo: [OUT] PR_TRUE if at least one transaction is currently ready to be undone.

void cloneAttribute ( AString attribute , nsIDOMNode destNode , nsIDOMNode sourceNode )

CloneAttribute() copies the attribute from the source node to the destination node and delete those not in the source.

The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)

Arguments:
attribute: the name of the attribute to copy
destNode: the destination element to operate on
sourceNode: the source element to copy attributes from

void cloneAttributes ( nsIDOMNode destNode , nsIDOMNode sourceNode )

CloneAttributes() is similar to nsIDOMNode::cloneNode(), it assures the attribute nodes of the destination are identical with the source node by copying all existing attributes from the source and deleting those not in the source. This is used when the destination node (element) already exists

The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)

Arguments:
destNode: the destination element to operate on
sourceNode: the source element to copy attributes from

void copy ( )

Copy the currently selected text, putting it into the OS clipboard What if no text is selected? What about mixed selections? What are the clipboard formats?


nsIDOMNode createNode ( AString tag , nsIDOMNode parent , PRInt32 position )

CreateNode instantiates a new element of type tag and inserts it into parent at position.

Arguments:
tag: The type of object to create
parent: The node to insert the new object into
position: The place in parent to insert the new node
Returns:
The node created. Caller must release aNewNode.

void cut ( )

Cut the currently selected text, putting it into the OS clipboard What if no text is selected? What about mixed selections? What are the clipboard formats?


void debugDumpContent ( )


void debugUnitTests ( out PRInt32 outNumTests , out PRInt32 outNumTestsFailed )

Arguments:
outNumTests
outNumTestsFailed

void deleteNode ( nsIDOMNode child )

DeleteNode removes child from parent.

Arguments:
child: The node to delete

void deleteSelection ( PRInt16 action )

DeleteSelection removes all nodes in the current selection.

Arguments:
action

void doDrag ( nsIDOMEvent event )

DoDrag transfers the relevant data (as appropriate) to a transferable so it can later be dropped.

Arguments:
event

void doTransaction ( nsITransaction txn )

DoTransaction() fires a transaction. It is provided here so clients can create their own transactions. If a transaction manager is present, it is used. Otherwise, the transaction is just executed directly.

Arguments:
txn: the transaction to execute

void dumpContentTree ( )

And a debug method -- show us what the tree looks like right now


void enableUndo ( PRBool enable )

Turn the undo system on or off

Arguments:
enable: if PR_TRUE, the undo system is turned on if available if PR_FALSE the undo system is turned off if it was previously on
Returns:
if aEnable is PR_TRUE, returns NS_OK if the undo system could be initialized properly if aEnable is PR_FALSE, returns NS_OK.

void endOfDocument ( )


void endPlaceHolderTransaction ( )


void endTransaction ( )

EndTransaction is a signal to the editor that the caller is finished updating the content model.
beginUpdate must be called before endTransaction is called.
Calls to beginTransaction can be nested, as long as endTransaction is called once per beginTransaction.


PRBool getAttributeValue ( nsIDOMElement element , AString attributestr , out AString resultValue )

GetAttributeValue() retrieves the attribute's value for element.

Arguments:
element: the content element to operate on
attributestr
resultValue: [OUT] the value of attribute. Only valid if resultIsSet is PR_TRUE
Returns:
PR_TRUE if aAttribute is set on the current node, PR_FALSE if it is not.

PRInt32 getModificationCount ( )

Gets the modification count of the document we are editing.

Returns:
the modification count of the document being edited. Zero means unchanged.

void incrementModificationCount ( PRInt32 modCount )

Called each time we modify the document. Increments the modification count of the document.

Arguments:
modCount: the number of modifications by which to increase or decrease the count

void init ( nsIDOMDocument doc , nsIPresShellPtr shell , nsIContentPtr root , nsISelectionController selCon , PRUint32 flags )

Init is to tell the implementation of nsIEditor to begin its services

Arguments:
doc: The dom document interface being observed
shell
root: This is the root of the editable section of this document. If it is null then we get root from document body.
selCon: this should be used to get the selection location
flags: A bitmask of flags for specifying the behavior of the editor.

void insertFromDrop ( nsIDOMEvent event )

InsertFromDrop looks for a dragsession and inserts the relevant data in response to a drop.

Arguments:
event

void insertNode ( nsIDOMNode node , nsIDOMNode parent , PRInt32 position )

InsertNode inserts node into parent at position. No checking is done to verify the legality of the insertion. That is the responsibility of the caller.

Arguments:
node: The DOM Node to insert.
parent: The node to insert the new object into
position: The place in parent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child

void joinNodes ( nsIDOMNode leftNode , nsIDOMNode rightNode , nsIDOMNode parent )

JoinNodes() takes 2 nodes and merge their contentchildren.

There is no requirement that the two nodes be of the same type. However, a text node can be merged only with another text node.

Arguments:
leftNode: The left node. It will be deleted.
rightNode: The right node. It will remain after the join.
parent: The parent of existingRightNode

void markNodeDirty ( nsIDOMNode node )

MarkNodeDirty() sets a special dirty attribute on the node. Usually this will be called immediately after creating a new node.

Arguments:
node: The node for which to insert formatting.

void outputToStream ( nsIOutputStream stream , AString formatType , ACString charsetOverride , PRUint32 flags )

Arguments:
stream
formatType
charsetOverride
flags

AString outputToString ( AString formatType , PRUint32 flags )

Output methods: formatType is a mime type, like text/plain.

Arguments:
formatType
flags

void paste ( PRInt32 selectionType )

Paste the text in the OS clipboard at the cursor position, replacing the selected text (if any)

Arguments:
selectionType

void postCreate ( )

PostCreate should be called after Init, and is the time that the editor tells its documentStateObservers that the document has been created.


void preDestroy ( )

PreDestroy is called before the editor goes away, and gives the editor a chance to tell its documentStateObservers that the document is going away.


void redo ( PRUint32 count )

Redo reverses the effects of the last Undo operation It is provided here so clients need no knowledge of whether the editor has a transaction manager or not. If a transaction manager is present, it is told to redo and the result of the previously undone transaction is reapplied to the document. If no transaction is available for Redo, or if the document has no transaction manager, the Redo request is ignored and an error NS_ERROR_NOT_AVAILABLE is returned.

Arguments:
count

void removeAttribute ( nsIDOMElement element , AString attribute )

RemoveAttribute() deletes attribute from the attribute list of element. If attribute is not an attribute of element, nothing is done.

Arguments:
element: the content element to operate on
attribute: the string representation of the attribute to get

void removeAttributeOrEquivalent ( nsIDOMElement element , DOMString sourceAttrName , PRBool suppressTransaction )

Arguments:
element
sourceAttrName
suppressTransaction

void removeDocumentStateListener ( nsIDocumentStateListener listener )

Arguments:
listener

void removeEditActionListener ( nsIEditActionListener listener )

Arguments:
listener

void removeEditorObserver ( nsIEditorObserver observer )

Arguments:
observer

void resetModificationCount ( )

To be used ONLY when we need to override the doc's modification state (such as when it's saved).


void selectAll ( )


void setAttribute ( nsIDOMElement element , AString attributestr , AString attvalue )

SetAttribute() sets the attribute of element. No checking is done to see if attribute is a legal attribute of the node, or if value is a legal value of attribute.

Arguments:
element: the content element to operate on
attributestr
attvalue

void setAttributeOrEquivalent ( nsIDOMElement element , AString sourceAttrName , AString sourceAttrValue , PRBool suppressTransaction )

Arguments:
element
sourceAttrName
sourceAttrValue
suppressTransaction

void setShouldTxnSetSelection ( PRBool should )

Set the flag that prevents insertElementTxn from changing the selection

Arguments:
should: Set false to suppress changing the selection; i.e., before using InsertElement() to insert under element WARNING: You must be very careful to reset back to PR_TRUE after setting PR_FALSE, else selection/caret is trashed for further editing.

PRBool shouldTxnSetSelection ( )


void splitNode ( nsIDOMNode existingRightNode , PRInt32 offset , out nsIDOMNode newLeftNode )

SplitNode() creates a new node identical to an existing node, and split the contents between the two nodes

Arguments:
existingRightNode: the node to split. It will become the new node's next sibling.
offset: the offset of existingRightNode's content|children to do the split at
newLeftNode: [OUT] the new node resulting from the split, becomes existingRightNode's previous sibling.

void switchTextDirection ( )

Switches the editor element direction; from "Left-to-Right" to "Right-to-Left", and vice versa.


void undo ( PRUint32 count )

Undo reverses the effects of the last Do operation, if Undo is enabled in the editor. It is provided here so clients need no knowledge of whether the editor has a transaction manager or not. If a transaction manager is present, it is told to undo, and the result of that undo is returned. Otherwise, the Undo request is ignored and an error NS_ERROR_NOT_AVAILABLE is returned.

Arguments:
count

References

This interface is the type of the following properties:

nsIDOMNSEditableElement.editor, nsIEditorDocShell.editor, nsIMsgCompose.editor

This interface is passed as an argument to the following methods:

nsIEditingSession.setEditorOnControllers, nsIEditorSpellCheck.InitSpellChecker, nsIInlineSpellChecker.init, nsIMsgCompose.initEditor, nsIMsgSend.createAndSendMessage

This interface is returned from the following methods:

nsIEditingSession.getEditorForWindow

Reference documentation is generated from Mozilla's source.

Add a note User Contributed Notes
August 23, 2005, 8:56 pm surkov at dc dot baikal dot ru
flags of outputToString() and outputToStream() methods are (from nsIDocumentEncoder)

Output only the selection (as opposed to the whole document).
OutputSelectionOnly = 1

Plaintext output: Convert html to plaintext that looks like the html. Implies wrap (except inside <pre>), since html wraps. HTML output: always do prettyprinting, ignoring existing formatting.
OutputFormatted = 2

Don't do prettyprinting of HTML. Don't do any wrapping that's not in the existing HTML source. This option overrides OutputFormatted if both are set. Note that this option does not affect entity conversion.
OutputRaw = 4

No html head tags
OutputBodyOnly = 8

Wrap even if we're not doing formatted output (e.g. for text fields)
OutputPreformatted = 16

Output as though the content is preformatted (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag)
OutputWrap = 32

Output for format flowed (RFC 2646). This is used when converting to text for mail sending. This differs just slightly but in an important way from normal formatted, and that is that lines are space stuffed. This can't (correctly) be done later.
OutputFormatFlowed = 64

Convert links, image src, and script src to absolute URLs when possible
OutputAbsoluteLinks = 128

Attempt to encode entities standardized at W3C (HTML, MathML, etc). This is a catch-all flag for documents with mixed contents. Beware of interoperability issues. See below for other flags which might likely do what you want.
OutputEncodeW3CEntities = 256

LineBreak processing: we can do either platform line breaks, CR, LF, or CRLF. If neither of these flags is set, then we will use platform line breaks.
OutputCRLineBreak = 512,
OutputLFLineBreak = 1024

Output the content of noscript elements (only for serializing to plaintext).
OutputNoScriptContent = 2048

Output the content of noframes elements (only for serializing to plaintext).
OutputNoFramesContent = 4096

Don't allow any formatting nodes (e.g. <br>, <b>) inside a <pre>. This is used primarily by mail.
OutputNoFormattingInPre = 8192

Encode entities when outputting to a string. E.g. If set, we'll output   if clear, we'll output 0xa0. The basic set is just   & < > " for interoperability with older products that don't support α and friends. The Latin1 entity set additionally includes 8bit accented letters between 128 and 255. The HTML entity set additionally includes accented letters, greek letters, and other special markup symbols as defined in HTML4.
OutputEncodeBasicEntities = 16384,
OutputEncodeLatin1Entities = 32768,
OutputEncodeHTMLEntities = 65536

Copyright © 1999 - 2005 XULPlanet.com