nsIHTMLEditor

Methods

addDefaultProperty(aProperty, aAttribute, aValue)

AddDefaultProperty() registers a default style property with the editor

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"

removeDefaultProperty(aProperty, aAttribute, aValue)

RemoveDefaultProperty() unregisters a default style property with the editor

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"

removeAllDefaultProperties()

RemoveAllDefaultProperties() unregisters all default style properties with the editor

setInlineProperty(aProperty, aAttribute, aValue)

SetInlineProperty() sets the aggregate properties on the current selection

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"

getInlineProperty(aProperty, aAttribute, aValue, aFirst, aAny, aAll)

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.

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 [OUT] PR_TRUE if the first text node in the selection has the property
aAny [OUT] PR_TRUE if any of the text nodes in the selection have the property
aAll [OUT] PR_TRUE if all of the text nodes in the selection have the property

getInlinePropertyWithAttrValue(aProperty, aAttribute, aValue, aFirst, aAny, aAll)

removeAllInlineProperties()

removeAllInlineProperties() deletes all the inline properties from all
text in the current selection.

removeInlineProperty(aProperty, aAttribute)

removeInlineProperty() deletes the properties from all text in the current
selection. If aProperty is not set on the selection, nothing is done.

Parameters

aProperty the property to remove from the selection All atoms are for normal HTML tags (e.g.: 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.

increaseFontSize()

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

decreaseFontSize()

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

nodeIsBlock(node)

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

Parameters

aNode the node to test

insertHTML(aInputString)

Insert some HTML source at the current location

Parameters

aInputString the string to be inserted

pasteNoFormatting(aSelectionType)

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

rebuildDocumentFromSource(aSourceString)

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

Parameters

aSourceString HTML source string of the entire new document

insertHTMLWithContext(aInputString, aContextStr, aInfoStr, aFlavor, aSourceDoc, aDestinationNode, aDestinationOffset, aDeleteSelection)

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

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
aCollapseSelection used with aDestNode during drag&drop

insertElementAtSelection(aElement, aDeleteSelection)

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.

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

setDocumentTitle(aTitle)

Set the documents title.

updateBaseURL()

Set the BaseURL for the document to the current URL
but only if the page doesn’t have a 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

selectElement(aElement)

Set the selection at the suppled element

Parameters

aElement An element in the document

setCaretAfterElement(aElement)

Create a collapsed selection just after aElement

XXX could we parameterize SelectElement(before/select/after>?

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.

Parameters

aElement An element in the document

setParagraphFormat(aParagraphFormat)

SetParagraphFormat Insert a block paragraph tag around selection

Parameters

aParagraphFormat "p", "h1" to "h6", "address", "pre", or "blockquote"

getParagraphState(aMixed)

getParagraphState returns what block tag paragraph format is in
the selection.

Parameters

aMixed True if there is more than one format

Returns

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

getFontFaceState(aMixed)

getFontFaceState returns what font face is in the selection.

Parameters

aMixed True if there is more than one font face

Returns

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

getFontColorState(aMixed)

getFontColorState returns what font face is in the selection.

Parameters

aMixed True if there is more than one font color

Returns

Color string. "" is returned for none.

getBackgroundColorState(aMixed)

getFontColorState returns what font face is in the selection.

Parameters

aMixed True if there is more than one font color

Returns

Color string. "" is returned for none.

getHighlightColorState(aMixed)

getHighlightColorState returns what the highlight color of the selection.

Parameters

aMixed True if there is more than one font color

Returns

Color string. "" is returned for none.

getListState(aMixed, aOL, aUL, aDL)

getListState returns what list type is in the selection.

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's true if an "ol" list is selected.
aUL true if an "ul" list is selected.
aDL true if a "dl" list is selected.

getListItemState(aMixed, aLI, aDT, aDD)

getListItemState returns what list item type is in the selection.

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.

getAlignment(aMixed, aAlign)

getAlignment returns what alignment is in the selection.

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)

getIndentState(aCanIndent, aCanOutdent)

Document me!

makeOrChangeList(aListType, entireList, aBulletType)

Document me!

removeList(aListType)

Document me!

indent(aIndent)

Document me!

align(aAlign)

Document me!

getElementOrParentByTagName(aTagName, aNode)

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.

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.

Returns

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

getSelectedElement(aTagName)

Return an element only if it is the only node selected,
such as an image, horizontal rule, etc.
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, i.e., a caret
within the link text.

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)

Returns

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

getHeadContentsAsHTML()

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

replaceHeadContentsWithHTML(aSourceToInsert)

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

createElementWithDefaults(aTagName)

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)

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)

Returns

The new element created.

insertLinkAroundSelection(aAnchorElement)

Insert an link element as the parent of the current selection

Parameters

aElement An "A" element with a non-empty "href" attribute

setBackgroundColor(aColor)

Set the value of the “bgcolor” attribute on the document’s <body> element

Parameters

aColor The HTML color string, such as "#ffccff" or "yellow"

setBodyAttribute(aAttr, aValue)

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

8/31/00 THIS ISN’T BEING USED? SHOULD WE DROP IT?

Parameters

aAttr The attribute to be set
aValue The value of the attribute

getLinkedObjects()

Find all the nodes in the document which contain references
to outside URIs (e.g. a href, img src, script src, etc.)
The objects in the array will be type nsIURIRefObject.

Returns

aNodeList the linked nodes found

addInsertionListener(inFilter)

Add listener for insertion override

Parameters

inFilter function which callers want called during insertion

removeInsertionListener(inFilter)

Remove listener for insertion override

Parameters

inFilter function which callers do not want called during insertion

createAnonymousElement(aTag, aParentNode, aAnonClass, aIsCreatedHidden)

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”

Parameters

aTag [IN] a string representing the desired type of the element to create
aParentNode [IN] the parent node of the created anonymous element
aAnonClass [IN] contents of the _moz_anonclass attribute
aIsCreatedHidden [IN] a boolean specifying if the class "hidden" is to be added to the created anonymous element

Returns

a DOM Element

getSelectionContainer()

returns the deepest container of the selection

Returns

a DOM Element

checkSelectionStateForAnonymousButtons(aSelection)

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

Parameters

aSelection [IN] a selection

isAnonymousElement(aElement)

breakIsVisible(aNode)

Checks whether a BR node is visible to the user.

GetActiveEditingHost()

Get an active editor’s editing host in DOM window. If this editor isn’t
active in the DOM window, this returns NULL.

Attributes

isCSSEnabled

A boolean which is true is the HTMLEditor has been instantiated
with CSS knowledge and if the CSS pref is currently checked

@return true if CSS handled and enabled

returnInParagraphCreatesNewParagraph

A boolean indicating if a return key pressed in a paragraph creates
another paragraph or just inserts a
at the caret

@return true if CR in a paragraph creates a new paragraph

Constants

eLeft

eCenter

eRight

eJustify