nsIEditor 编辑

« XPCOM API Reference

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

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

ConstantValueDescription
eNone0 
eNext1 
ePrevious2 
eNextWord3 
ePreviousWord4 
eToBeginningOfLine5 
eToEndOfLine6 

Attributes

 

AttributeTypeDescription
contentsMIMETypestringThe MIME type of the document.
documentDocumentRead only. The DOM Document this editor is associated with.
documentCharacterSetACStringSets the current 'Save' document character set.
documentIsEmptybooleanRead only. Returns true if the document has no *meaningful* content.
documentModifiedbooleanRead only. Returns true if the document is modifed and needs saving.
flagsunsigned longEdit flags for this editor. May be set at any time.
isDocumentEditablePRBoolRead only. Returns true if we have a document that is not marked read-only.
isSelectionEditablebooleanRead 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.
rootElementnsIDOMElementRead only. The root editable element, which for a document is its body.
selectionnsISelectionRead only. The selection/caret for this editor. In the case of a design mode document, this is the same as the window's selection.
selectionControllernsISelectionControllerRead 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:101 次

字数:18079

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文