Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

This article needs a technical review. How you can help.

« XPCOM API Reference

Provides methods and attributes used when editing page content.
28
Introduced
Gecko 1.0
Inherits from: nsISupports Last changed in Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15 / Firefox OS 1.0.1)

Method overview

[noscript] void init(in nsIDOMDocument doc, in nsIContent aRoot, in nsISelectionController aSelCon, in unsigned long aFlags);
void setAttributeOrEquivalent(in nsIDOMElement element, in AString sourceAttrName, in AString sourceAttrValue, in boolean aSuppressTransaction);
void removeAttributeOrEquivalent(in nsIDOMElement element, in DOMString sourceAttrName, in boolean aSuppressTransaction);
void postCreate();
void preDestroy(in boolean aDestroyingFrames);
Selected Content Removal
void deleteSelection(in short action, in short stripWrappers);
Document Info and File Methods
void resetModificationCount();
long getModificationCount();
void incrementModificationCount(in long aModCount);
void incrementModificationCount(in long aModCount);
Transaction Methods
void doTransaction(in nsITransaction txn);
void enableUndo(in boolean enable);
void undo(in unsigned long count);
void canUndo(out boolean isEnabled, out boolean canUndo);
void redo(in unsigned long count);
void canRedo(out boolean isEnabled, out boolean canRedo);
void beginTransaction();
void endTransaction();
void beginPlaceHolderTransaction(in nsIAtom name);
void endPlaceHolderTransaction();
boolean shouldTxnSetSelection();
void setShouldTxnSetSelection(in boolean should);
Inline Spellchecking Methods
nsIInlineSpellChecker getInlineSpellChecker(in boolean autoCreate);
void syncRealTimeSpell();
void setSpellcheckUserOverride(in boolean enable);
Clipboard Methods
void cut();
boolean canCut();
void copy();
boolean canCopy();
void paste(in long aSelectionType);
boolean canPaste(in long aSelectionType);
Selection Methods
void selectAll();
void beginningOfDocument();
void endOfDocument();
Drag/Drop Methods
boolean canDrag(in nsIDOMEvent aEvent);
void doDrag(in nsIDOMEvent aEvent);
void insertFromDrop(in nsIDOMEvent aEvent);
Node Manipulation Methods
void setAttribute(in nsIDOMElement aElement, in AString attributestr,in AString attvalue);
boolean getAttributeValue(in nsIDOMElement aElement, in AString attributestr, out AString resultValue);
void removeAttribute(in nsIDOMElement aElement, in AString aAttribute);
void cloneAttribute(in AString aAttribute, in nsIDOMNode aSourceNode);
void cloneAttributes(in nsIDOMNode destNode, in nsIDOMNode sourceNode);
nsIDOMNode createNode(in AString tag, in nsIDOMNode parent, in long position);
void insertNode(in nsIDOMNode node, in nsIDOMNode parent, in long aPosition);
void splitNode(in nsIDOMNode existingRightNode, in long offset, out nsIDOMNode newLeftNode);
void joinNodes(in nsIDOMNode leftNode, in nsIDOMNode rightNode, in nsIDOMNode parent);
void deleteNode(in nsIDOMNode child);
void markNodeDirty(in nsIDOMNode node);
Direction Controller
void switchTextDirection();
Output Methods

AString outputToString(in AString formatType, in unsigned long flags);

Example:
// flags are declared in base/public/nsIDocumentEncoder.idl
// OutputSelectionOnly = 1,         OutputFormatted = 2, 
// OutputRaw = 4,                   OutputBodyOnly = 8,
// OutputPreformatted = 16,         OutputWrap = 32, 
// OutputFormatFlowed = 64,         OutputAbsoluteLinks = 258, 
// OutputEncodeW3CEntities = 256,   OutputCRLineBreak = 512, 
// OutputLFLineBreak = 1024,        OutputNoScriptContent = 2048, 
// OutputNoFramesContent = 4096,    OutputNoFormattingInPre = 8192, 
// OutputEncodeBasicEntities=16384, OutputEncodeLatin1Entities=32768, 
// OutputEncodeHTMLEntities=65536,  OutputPersistNBSP=131072

editorAPI.outputToString('text/html', 2);
editorAPI.outputToString('text/plain', 4);

// output the body tag, body children and the html end tag (</html>). 
// tag name are in lower case  with <br>.
editorAPI.outputToString('text/html', 8); 

// XML: all in xml with _moz_dirty="" in new tags, HTML tags are in upper case 
// application/xhtml+xml format do the same
editorAPI.outputToString('text/xml', 2); // the body is not recognized, everything is printed 
void outputToStream(in nsIOutputStream aStream, in AString formatType, in ACString charsetOverride, in unsigned long flags);
Listener Methods
void addEditorObserver(in nsIEditorObserver observer);Obsolete since Gecko 18
void setEditorObserver(in EditActionListener observer);
void removeEditorObserver(in nsIEditorObserver observer Obsolete since Gecko 18);
void addEditActionListener(in nsIEditActionListener listener);
void removeEditActionListener(in nsIEditActionListener listener);
void addDocumentStateListener(in nsIDocumentStateListener listener);
void removeDocumentStateListener(in nsIDocumentStateListener listener);
Debug Methods
void dumpContentTree();
void debugDumpContent() ;
void debugUnitTests(out long outNumTests, out long outNumTestsFailed);
[notxpcom] boolean isModifiableNode(in nsIDOMNode aNode);

Constants

Load Flags

Constant Value Description
eNone 0  
eNext 1  
ePrevious 2  
eNextWord 3  
ePreviousWord 4  
eToBeginningOfLine 5  
eToEndOfLine 6  

Attributes

 

Attribute Type Description
contentsMIMEType string The MIME type of the document.
document Document Read only. The DOM Document this editor is associated with.
documentCharacterSet ACString Sets the current 'Save' document character set.
documentIsEmpty boolean Read only. Returns true if the document has no *meaningful* content.
documentModified boolean Read only. Returns true if the document is modifed and needs saving.
flags unsigned long Edit flags for this editor. May be set at any time.
isDocumentEditable PRBool Read only. Returns true if we have a document that is not marked read-only.
isSelectionEditable boolean Read only. true if the current selection anchor is editable; otherwise false. This helps to support cases where only parts of the document are editable, by letting you see if the current selection is in an editable section.
rootElement nsIDOMElement Read only. The root editable element, which for a document is its body.
selection nsISelection Read only. The selection/caret for this editor. In the case of a design mode document, this is the same as the window's selection.
selectionController nsISelectionController Read only. The selection controller for the current presentation.

 

Methods

Native code only!

init

Initializes the editor's services.

[noscript] void init(
  in nsIDOMDocument doc,
  in nsIPresShellPtr shell, Obsolete since Gecko 5
  in nsIContent aRoot,
  in nsISelectionController aSelCon,
  in unsigned long aFlags
);
Parameters
doc
The document to observe.
shell Obsolete since Gecko 5.0
The nsIPresShellPtr representing the presentation shell displaying the document. This parameter was removed in Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2).
aRoot
The root of the editable section of this document; if it's null, the editor gets its root from document.body.
aSelCon
The nsISelectionController object used to get selection location information. This should be null for HTML editors.
aFlags
A bit mask of flags controlling the editor's behavior. Need to document what the possible values are.

Document Tags and Contributors

 Last updated by: Sheppy,