nsIHTMLEditor

Please add a summary to this article.
Inherits from: nsISupports Last changed in Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2)

Method overview

void addDefaultProperty(in nsIAtom aProperty, in AString aAttribute, in AString aValue);
void addInsertionListener(in nsIContentFilter inFilter);
void align(in AString aAlign);
boolean breakIsVisible(in nsIDOMNode aNode);
boolean canDrag(in nsIDOMEvent aEvent);
void checkSelectionStateForAnonymousButtons(in nsISelection aSelection);
nsIDOMElement createAnonymousElement(in AString aTag, in nsIDOMNode aParentNode, in AString aAnonClass, in boolean aIsCreatedHidden);
nsIDOMElement createElementWithDefaults(in AString aTagName);
void decreaseFontSize();
void doDrag(in nsIDOMEvent aEvent);
void getAlignment(out boolean aMixed, out short aAlign);
AString getBackgroundColorState(out boolean aMixed);
nsIDOMElement getElementOrParentByTagName(in AString aTagName, in nsIDOMNode aNode);
AString getFontColorState(out boolean aMixed);
AString getFontFaceState(out boolean aMixed);
AString getHeadContentsAsHTML();
AString getHighlightColorState(out boolean aMixed);
void getIndentState(out boolean aCanIndent, out boolean aCanOutdent);
void getInlineProperty(in nsIAtom aProperty, in AString aAttribute, in AString aValue, out boolean aFirst, out boolean aAny, out boolean aAll);
AString getInlinePropertyWithAttrValue(in nsIAtom aProperty, in AString aAttribute, in AString aValue, out boolean aFirst, out boolean aAny, out boolean aAll);
nsISupportsArray getLinkedObjects();
void getListItemState(out boolean aMixed, out boolean aLI, out boolean aDT, out boolean aDD);
void getListState(out boolean aMixed, out boolean aOL, out boolean aUL, out boolean aDL);
AString getParagraphState(out boolean aMixed);
nsIDOMElement getSelectedElement(in AString aTagName);
nsIDOMElement getSelectionContainer();
void ignoreSpuriousDragEvent(in boolean aIgnoreSpuriousDragEvent);
void increaseFontSize();
void indent(in AString aIndent);
void insertElementAtSelection(in nsIDOMElement aElement, in boolean aDeleteSelection);
void insertFromDrop(in nsIDOMEvent aEvent);
void insertHTML(in AString aInputString);
void insertHTMLWithContext(in AString aInputString, in AString aContextStr, in AString aInfoStr, in AString aFlavor, in nsIDOMDocument aSourceDoc, in nsIDOMNode aDestinationNode, in long aDestinationOffset, in boolean aDeleteSelection);
void insertLinkAroundSelection(in nsIDOMElement aAnchorElement);
boolean isAnonymousElement(in nsIDOMElement aElement);
void makeOrChangeList(in AString aListType, in boolean entireList, in AString aBulletType);
boolean nodeIsBlock(in nsIDOMNode node);
void pasteNoFormatting(in long aSelectionType);
void rebuildDocumentFromSource(in AString aSourceString);
void removeAllDefaultProperties();
void removeAllInlineProperties();
void removeDefaultProperty(in nsIAtom aProperty, in AString aAttribute, in AString aValue);
void removeInlineProperty(in nsIAtom aProperty, in AString aAttribute);
void removeInsertionListener(in nsIContentFilter inFilter);
void removeList(in AString aListType);
void replaceHeadContentsWithHTML(in AString aSourceToInsert);
void selectElement(in nsIDOMElement aElement);
void setBackgroundColor(in AString aColor);
void setBodyAttribute(in AString aAttr, in AString aValue);
void setCaretAfterElement(in nsIDOMElement aElement);
void setCSSInlineProperty(in nsIAtom aProperty, in AString aAttribute, in AString aValue);
void setDocumentTitle(in AString aTitle);
void setInlineProperty(in nsIAtom aProperty, in AString aAttribute, in AString aValue);
void setParagraphFormat(in AString aParagraphFormat);
void updateBaseURL();

Attributes

Attribute Type Description
isCSSEnabled boolean A boolean which is true is the HTMLEditor has been instantiated with CSS knowledge and if the CSS pref is currently checked.
returnInParagraphCreatesNewParagraph boolean A boolean indicating if a return key pressed in a paragraph creates another paragraph or just inserts a <br> at the caret.

Constants

Constant Value Description
eLeft 0  
eCenter 1  
eRight 2  
eJustify 3  

Methods

addDefaultProperty()

Registers a default style property with the editor.

void addDefaultProperty(
  in nsIAtom aProperty,
  in AString aAttribute,
  in AString aValue
);
Parameters
aProperty
The property to set by default.
aAttribute
The attribute of the property, if applicable. May be null. Example: aProperty="font", aAttribute="color"
aValue
If aAttribute is not null, the value of the attribute. Example: aProperty="font", aAttribute="color", aValue="0x00FFFF"

addInsertionListener()

Add listener for insertion override.

void addInsertionListener(
  in nsIContentFilter inFilter
);
Parameters
inFilter
Function which callers want called during insertion.

align()

Document me!

void align(
  in AString aAlign
);
Parameters
aAlign

Requires Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2)

breakIsVisible()

Checks whether a BR node is visible to the user.

boolean breakIsVisible(
  in nsIDOMNode aNode
);
Parameters
aNode
Return value

 

canDrag()

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

boolean canDrag(
  in nsIDOMEvent aEvent
);
Parameters
aEvent
Return value

 

checkSelectionStateForAnonymousButtons()

Checks if the anonymous nodes created by the HTML editor have to be refreshed or hidden depending on a possible new state of the selection.

void checkSelectionStateForAnonymousButtons(
  in nsISelection aSelection
);
Parameters
aSelection
A selection.

createAnonymousElement()

Returns an anonymous nsDOMElement of type aTag, child of aParentNode. If aIsCreatedHidden is true, the class "hidden" is added to the created element. If aAnonClass is not the empty string, it becomes the value of the attribute "_moz_anonclass"

nsIDOMElement createAnonymousElement(
  in AString aTag,
  in nsIDOMNode aParentNode,
  in AString aAnonClass,
  in boolean aIsCreatedHidden
);
Parameters
aTag
A string representing the desired type of the element to create.
aParentNode
The parent node of the created anonymous element.
aAnonClass
Contents of the _moz_anonclass attribute.
aIsCreatedHidden
A boolean specifying if the class "hidden" is to be added to the created anonymous element.
Return value

A DOM Element.

createElementWithDefaults()

Return a new element with default attribute values.

This does not rely on the selection, and is not sensitive to context.

Used primarily to supply new element for various insert element dialogs (Image, Link, NamedAnchor, Table, and HorizontalRule are the only returned elements as of 7/25/99)

nsIDOMElement createElementWithDefaults(
  in AString aTagName
);
Parameters
aTagName
The HTML tagname Special input values for Links and Named anchors: Use "href" to get a link node (an "A" tag with the "href" attribute set) Use "anchor" or "namedanchor" to get a named anchor node (an "A" tag with the "name" attribute set)
Return value

The new element created.

decreaseFontSize()

Decrease font size for text in selection by 1 HTML unit All existing text is scanned for existing <FONT SIZE> attributes so they will be decreased instead of inserting new <FONT> tag.

void decreaseFontSize();
Parameters

None.

doDrag()

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

void doDrag(
  in nsIDOMEvent aEvent
);
Parameters
aEvent

getAlignment()

Returns what alignment is in the selection.

void getAlignment(
  out boolean aMixed,
  out short aAlign
);
Parameters
aMixed
true if there is more than one type of list item, or if there is some list and non-list.
aAlign
Enum value for first encountered alignment (left/center/right)

getBackgroundColorState()

getFontColorState() returns what font face is in the selection.

AString getBackgroundColorState(
  out boolean aMixed
);
Parameters
aMixed
true if there is more than one font color.
Return value

Color string. "" is returned for none.

getElementOrParentByTagName()

Return the input node or a parent matching the given aTagName, starting the search at the supplied node. An example of use is for testing if a node is in a table cell given a selection anchor node.

nsIDOMElement getElementOrParentByTagName(
  in AString aTagName,
  in nsIDOMNode aNode
);
Parameters
aTagName
The HTML tagname Special input values: Use "href" to get a link node (an "A" tag with the "href" attribute set) Use "anchor" or "namedanchor" to get a named anchor node (an "A" tag with the "name" attribute set) Use "list" to get an OL, UL, or DL list node Use "td" to get either a TD or TH cell node.
aNode
The node in the document to start the search. If it is null, the anchor node of the current selection is used.
Return value

NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found (passes NS_SUCCEEDED macro)

getFontColorState()

Returns what font face is in the selection.

AString getFontColorState(
  out boolean aMixed
);
Parameters
aMixed
true if there is more than one font color.
Return value

Color string. "" is returned for none.

getFontFaceState()

Returns what font face is in the selection.

AString getFontFaceState(
  out boolean aMixed
);
Parameters
aMixed
true if there is more than one font face.
Return value

Name of face. Note: "tt" is returned for tt tag. "" is returned for none.

getHeadContentsAsHTML()

Output the contents of the <HEAD> section as text/HTML format.

AString getHeadContentsAsHTML();
Parameters

None.

Return value

 

getHighlightColorState()

Returns what the highlight color of the selection.

AString getHighlightColorState(
  out boolean aMixed
);
Parameters
aMixed
true if there is more than one font color.
Return value

Color string. "" is returned for none.

getIndentState()

Document me!

void getIndentState(
  out boolean aCanIndent,
  out boolean aCanOutdent
);
Parameters
aCanIndent
aCanOutdent

getInlineProperty()

Gets aggregate properties of the current selection. All object in the current selection are scanned and their attributes are represented in a list of Property object.

void getInlineProperty(
  in nsIAtom aProperty,
  in AString aAttribute,
  in AString aValue,
  out boolean aFirst,
  out boolean aAny,
  out boolean aAll
);
Parameters
aProperty
The property to get on the selection.
aAttribute
The attribute of the property, if applicable. May be null. Example: aProperty="font", aAttribute="color"
aValue
If aAttribute is not null, the value of the attribute. May be null. Example: aProperty="font", aAttribute="color", aValue="0x00FFFF"
aFirst
PR_TRUE if the first text node in the selection has the property.
aAny
PR_TRUE if any of the text nodes in the selection have the property.
aAll
PR_TRUE if all of the text nodes in the selection have the property.

getInlinePropertyWithAttrValue()

AString getInlinePropertyWithAttrValue(
  in nsIAtom aProperty,
  in AString aAttribute,
  in AString aValue,
  out boolean aFirst,
  out boolean aAny,
  out boolean aAll
);
Parameters
aProperty
aAttribute
aValue
aFirst
aAny
aAll
Return value

 

getLinkedObjects()

Find all the nodes in the document which contain references to outside URIs (for example a href, img src, script src, and so on.) The objects in the array will be type nsIURIRefObject.

nsISupportsArray getLinkedObjects();
Parameters

None.

Return value

ANodeList the linked nodes found.

getListItemState()

getListItemState returns what list item type is in the selection.

void getListItemState(
  out boolean aMixed,
  out boolean aLI,
  out boolean aDT,
  out boolean aDD
);
Parameters
aMixed
true if there is more than one type of list item, or if there is some list and non-list.
aLI
true if "li" list items are selected.
aDT
true if "dt" list items are selected.
aDD
true if "dd" list items are selected.

getListState()

Returns what list type is in the selection.

void getListState(
  out boolean aMixed,
  out boolean aOL,
  out boolean aUL,
  out boolean aDL
);
Parameters
aMixed
true if there is more than one type of list, or if there is some list and non-list.
aOL
The company that employs me. No, really, it is true if an "ol" list is selected.
aUL
true if an "ul" list is selected.
aDL
true if a "dl" list is selected.

getParagraphState()

Returns what block tag paragraph format is in the selection.

AString getParagraphState(
  out boolean aMixed
);
Parameters
aMixed
true if there is more than one format.
Return value

Name of block tag. "" is returned for none.

getSelectedElement()

Return an element only if it is the only node selected, such as an image, horizontal rule, and so on. The exception is a link, which is more like a text attribute: The Anchor tag is returned if the selection is within the textnode(s) that are children of the "A" node. This could be a collapsed selection, that is, a caret within the link text.

nsIDOMElement getSelectedElement(
  in AString aTagName
);
Parameters
aTagName
The HTML tagname or and empty string to get any element (but only if it is the only element selected) Special input values for Links and Named anchors: Use "href" to get a link node (an "A" tag with the "href" attribute set) Use "anchor" or "namedanchor" to get a named anchor node (an "A" tag with the "name" attribute set)
Return value

NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found (passes NS_SUCCEEDED macro)

getSelectionContainer()

Returns the deepest container of the selection.

nsIDOMElement getSelectionContainer();
Parameters

None.

Return value

A DOM Element.

ignoreSpuriousDragEvent()

Used to suppress spurious drag/drop events to workaround bug 50703. Do not use this method! It will go away after first release!

void ignoreSpuriousDragEvent(
  in boolean aIgnoreSpuriousDragEvent
);
Parameters
aIgnoreSpuriousDragEvent

increaseFontSize()

Increase font size for text in selection by 1 HTML unit All existing text is scanned for existing <FONT SIZE> attributes so they will be incremented instead of inserting new <FONT> tag.

void increaseFontSize();
Parameters

None.

indent()

Document me!

void indent(
  in AString aIndent
);
Parameters
aIndent

insertElementAtSelection()

Insert an element, which may have child nodes, at the selection Used primarily to insert a new element for various insert element dialogs, but it enforces the HTML 4.0 DTD "CanContain" rules, so it should be useful for other elements.

void insertElementAtSelection(
  in nsIDOMElement aElement,
  in boolean aDeleteSelection
);
Parameters
aElement
The element to insert.
aDeleteSelection
Delete the selection before inserting If aDeleteSelection is PR_FALSE, then the element is inserted after the end of the selection for all element except Named Anchors, which insert before the selection.

insertFromDrop()

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

void insertFromDrop(
  in nsIDOMEvent aEvent
);
Parameters
aEvent

insertHTML()

Insert some HTML source at the current location.

void insertHTML(
  in AString aInputString
);
Parameters
aInputString
The string to be inserted.

insertHTMLWithContext()

Insert some HTML source, interpreting the string argument according to the given context.

void insertHTMLWithContext(
  in AString aInputString,
  in AString aContextStr,
  in AString aInfoStr,
  in AString aFlavor,
  in nsIDOMDocument aSourceDoc,
  in nsIDOMNode aDestinationNode,
  in long aDestinationOffset,
  in boolean aDeleteSelection
);
Parameters
aInputString
The string to be inserted.
aContextStr
Context of insertion.
aInfoStr
Related info to aInputString.
aFlavor
Transferable flavor, can be ""
aSourceDoc
Document where input was dragged from (may be null)
aDestinationNode
Location for insertion (such as when dropped)
aDestinationOffset
Used with aDestNode to determine insert location.
aDeleteSelection
Used with aDestNode during drag&drop.

insertLinkAroundSelection()

Insert an link element as the parent of the current selection.

void insertLinkAroundSelection(
  in nsIDOMElement aAnchorElement
);
Parameters
aAnchorElement

isAnonymousElement()

boolean isAnonymousElement(
  in nsIDOMElement aElement
);
Parameters
aElement
Return value

 

makeOrChangeList()

void makeOrChangeList(
  in AString aListType,
  in boolean entireList,
  in AString aBulletType
);
Parameters
aListType
entireList
aBulletType

nodeIsBlock()

Tests if a node is a BLOCK element according the the HTML 4.0 DTD. This does NOT consider CSS effect on display type.

boolean nodeIsBlock(
  in nsIDOMNode node
);
Parameters
node
Return value

 

pasteNoFormatting()

Paste the text in the OS clipboard at the cursor position, replacing the selected text (if any), but strip out any HTML styles and formatting.

void pasteNoFormatting(
  in long aSelectionType
);
Parameters
aSelectionType

rebuildDocumentFromSource()

Rebuild the entire document from source HTML Needed to be able to edit HEAD and other outside-of-BODY content.

void rebuildDocumentFromSource(
  in AString aSourceString
);
Parameters
aSourceString
HTML source string of the entire new document.

removeAllDefaultProperties()

Unregisters all default style properties with the editor.

void removeAllDefaultProperties();
Parameters

None.

removeAllInlineProperties()

Deletes all the inline properties from all text in the current selection.

void removeAllInlineProperties();
Parameters

None.

removeDefaultProperty()

Unregisters a default style property with the editor.

void removeDefaultProperty(
  in nsIAtom aProperty,
  in AString aAttribute,
  in AString aValue
);
Parameters
aProperty
The property to remove from defaults.
aAttribute
The attribute of the property, if applicable. May be null. Example: aProperty="font", aAttribute="color"
aValue
If aAttribute is not null, the value of the attribute. Example: aProperty="font", aAttribute="color", aValue="0x00FFFF"

removeInlineProperty()

Deletes the properties from all text in the current selection. If aProperty is not set on the selection, nothing is done.

void removeInlineProperty(
  in nsIAtom aProperty,
  in AString aAttribute
);
Parameters
aProperty
The property to remove from the selection All atoms are for normal HTML tags (for example nsIEditorProperty.font()) except when you want to remove just links and not named anchors. For that, use nsIEditorProperty.href().
aAttribute
The attribute of the property, if applicable. May be null. Example: aProperty=nsIEditorProptery.font(), aAttribute="color" nsIEditProperty.allAttributes() is special. It indicates that all content-based text properties are to be removed from the selection.

removeInsertionListener()

Remove listener for insertion override.

void removeInsertionListener(
  in nsIContentFilter inFilter
);
Parameters
inFilter
Function which callers do not want called during insertion.

removeList()

Document me!

void removeList(
  in AString aListType
);
Parameters
aListType

replaceHeadContentsWithHTML()

Replace all children of <HEAD> with string of HTML source.

void replaceHeadContentsWithHTML(
  in AString aSourceToInsert
);
Parameters
aSourceToInsert

selectElement()

Set the selection at the suppled element.

void selectElement(
  in nsIDOMElement aElement
);
Parameters
aElement
An element in the document.

setBackgroundColor()

Set the value of the "bgcolor" attribute on the document's <body> element.

void setBackgroundColor(
  in AString aColor
);
Parameters
aColor
The HTML color string, such as "#ffccff" or "yellow"

setBodyAttribute()

Set an attribute on the document's <body> element such as text, link, background colors.

void setBodyAttribute(
  in AString aAttr,
  in AString aValue
);
Parameters
aAttr
The attribute to be set.
aValue
The value of the attribute.

setCaretAfterElement()

Create a collapsed selection just after aElement.

The selection is set to parent-of-aElement with an offset 1 greater than aElement's offset but it enforces the HTML 4.0 DTD "CanContain" rules, so it should be useful for other elements.

void setCaretAfterElement(
  in nsIDOMElement aElement
);
Parameters
aElement
An element in the document.

setCSSInlineProperty()

SetInlineProperty() sets the aggregate properties on the current selection.

void setCSSInlineProperty(
  in nsIAtom aProperty,
  in AString aAttribute,
  in AString aValue
);
Parameters
aProperty
The property to set on the selection.
aAttribute
The attribute of the property, if applicable. May be null. Example: aProperty="font", aAttribute="color"
aValue
If aAttribute is not null, the value of the attribute. May be null. Example: aProperty="font", aAttribute="color", aValue="0x00FFFF"

setDocumentTitle()

Set the documents title.

void setDocumentTitle(
  in AString aTitle
);
Parameters
aTitle

setInlineProperty()

void setInlineProperty(
  in nsIAtom aProperty,
  in AString aAttribute,
  in AString aValue
);
Parameters
aProperty
aAttribute
aValue

setParagraphFormat()

Insert a block paragraph tag around selection.

void setParagraphFormat(
  in AString aParagraphFormat
);
Parameters
aParagraphFormat
"p", "h1" to "h6", "address", "pre", or "blockquote"

updateBaseURL()

Set the BaseURL for the document to the current URL but only if the page doesn't have a <base> tag This should be done after the document URL has changed, such as after saving a file This is used as base for relativizing link and image urls.

void updateBaseURL();
Parameters

None.

Document Tags and Contributors

Contributors to this page: Sheppy, trevorh
Last updated by: Sheppy,