gecko-dev/editor/public/nsIHTMLEditor.h

340 lines
14 KiB
C
Raw Normal View History

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL")=0; you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIHTMLEditor_h__
#define nsIHTMLEditor_h__
#define NS_IHTMLEDITOR_IID \
{/*BD62F311-CB8A-11d2-983A-00805F8AA8B8*/ \
0xbd62f311, 0xcb8a, 0x11d2, \
{ 0x98, 0x3a, 0x0, 0x80, 0x5f, 0x8a, 0xa8, 0xb8 } }
#include "nsIEditor.h"
#include "nscore.h"
//#include "nsIDOMDocumentFragment.h"
class nsIEditorCallback;
class nsISupportsArray;
class nsStringArray;
class nsIAtom;
class nsIOutputStream;
class nsIDOMWindow;
class nsIFileSpec;
/**
* The HTML editor interface.
* <P>
* Use to edit text and other HTML objects represented as a DOM tree.
*/
class nsIHTMLEditor : public nsISupports{
public:
1999-03-03 19:48:57 +00:00
static const nsIID& GetIID() { static nsIID iid = NS_IHTMLEDITOR_IID; return iid; }
1999-05-07 05:02:35 +00:00
typedef enum {eSaveFileText = 0, eSaveFileHTML = 1 } ESaveFileType;
Preparation for ender-based text control * added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start. We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to another app. * added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the rules system deal with those flags. The flags I added are: TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus. TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus. * added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line behavior. * cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the ownership model on the listeners, it was a big help. * added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-28 21:24:18 +00:00
/** Initialize the HTML editor
*
*/
Preparation for ender-based text control * added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start. We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to another app. * added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the rules system deal with those flags. The flags I added are: TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus. TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus. * added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line behavior. * cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the ownership model on the listeners, it was a big help. * added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-28 21:24:18 +00:00
NS_IMETHOD Init(nsIDOMDocument *aDoc,
nsIPresShell *aPresShell)=0;
// Methods shared with nsITextEditor (see nsITextEditor.h for details)
NS_IMETHOD SetTextProperty(nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue)=0;
NS_IMETHOD GetTextProperty(nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue,
PRBool &aFirst, PRBool &aAll, PRBool &aAny)=0;
NS_IMETHOD GetParagraphFormat(nsString& aParagraphFormat)=0;
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat)=0;
NS_IMETHOD RemoveTextProperty(nsIAtom *aProperty, const nsString *aAttribute)=0;
NS_IMETHOD DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction)=0;
NS_IMETHOD InsertText(const nsString& aStringToInsert)=0;
NS_IMETHOD InsertBreak()=0;
NS_IMETHOD EnableUndo(PRBool aEnable)=0;
NS_IMETHOD Undo(PRUint32 aCount)=0;
NS_IMETHOD CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)=0;
NS_IMETHOD Redo(PRUint32 aCount)=0;
NS_IMETHOD CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)=0;
NS_IMETHOD BeginTransaction()=0;
NS_IMETHOD EndTransaction()=0;
NS_IMETHOD MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)=0;
NS_IMETHOD MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)=0;
NS_IMETHOD MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)=0;
NS_IMETHOD MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)=0;
NS_IMETHOD SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)=0;
NS_IMETHOD SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)=0;
1999-03-11 19:33:37 +00:00
NS_IMETHOD SelectAll()=0;
NS_IMETHOD BeginningOfDocument()=0;
NS_IMETHOD EndOfDocument()=0;
NS_IMETHOD ScrollUp(nsIAtom *aIncrement)=0;
NS_IMETHOD ScrollDown(nsIAtom *aIncrement)=0;
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0;
1999-05-07 05:02:35 +00:00
NS_IMETHOD Save()=0;
NS_IMETHOD SaveAs(PRBool aSavingCopy)=0;
NS_IMETHOD Cut()=0;
NS_IMETHOD Copy()=0;
NS_IMETHOD Paste()=0;
1999-05-27 00:08:15 +00:00
NS_IMETHOD PasteAsQuotation()=0;
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation)=0;
1999-05-27 00:08:15 +00:00
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText)=0;
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCitation)=0;
1999-05-27 00:08:15 +00:00
NS_IMETHOD InsertHTML(const nsString &aInputString)=0;
/**
* Output methods:
* aFormatType is a mime type, like text/plain.
*/
NS_IMETHOD OutputToString(nsString& aOutputString,
const nsString& aFormatType,
PRUint32 aFlags) = 0;
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
PRUint32 aFlags) = 0;
NS_IMETHOD ApplyStyleSheet(const nsString& aURL)=0;
// Miscellaneous Methods
/** Set the background color of the selected table cell, row, columne, or table,
* or the document background if not in a table
*/
NS_IMETHOD SetBackgroundColor(const nsString& aColor)=0;
/** Set any BODY element attribute
*/
NS_IMETHOD SetBodyAttribute(const nsString& aAttr, const nsString& aValue)=0;
/*
NS_IMETHOD CheckSpelling()=0;
NS_IMETHOD SpellingLanguage(nsIAtom *aLanguage)=0;
*/
/* The editor doesn't know anything about specific services like SpellChecking.
* Services can be invoked on the content, and these services can use the editor if they choose
* to get transactioning/undo/redo.
* For things like auto-spellcheck, the App should implement nsIDocumentObserver and
* trigger off of ContentChanged notifications.
*/
NS_IMETHOD GetParagraphStyle(nsStringArray *aTagList)=0;
/** Add a block parent node around the selected content.
* Only legal nestings are allowed.
* An example of use is for indenting using blockquote nodes.
*
* @param aParentTag The tag from which the new parent is created.
*/
NS_IMETHOD AddBlockParent(nsString& aParentTag)=0;
/** Replace the block parent node around the selected content with a new block
* parent node of type aParentTag.
* Only legal replacements are allowed.
* An example of use are is transforming H1 to LI ("paragraph type transformations").
* For containing block transformations (transforming UL to OL, for example),
* the caller should RemoveParent("UL"), set the selection appropriately,
* and call AddBlockParent("OL").
*
* @param aParentTag The tag from which the new parent is created.
*/
NS_IMETHOD ReplaceBlockParent(nsString& aParentTag)=0;
/** remove the paragraph style from the selection */
NS_IMETHOD RemoveParagraphStyle()=0;
1999-04-22 14:45:48 +00:00
/** remove block parent of type aTagToRemove from the selection.
* if aTagToRemove is null, the nearest enclosing block that
* is <B>not</B> a root is removed.
*/
1999-04-22 14:45:48 +00:00
NS_IMETHOD RemoveParent(const nsString &aParentTag)=0;
1999-05-17 13:10:29 +00:00
NS_IMETHOD InsertList(const nsString& aListType)=0;
NS_IMETHOD Indent(const nsString& aIndent)=0;
NS_IMETHOD Align(const nsString& aAlign)=0;
1999-05-17 12:22:31 +00:00
/** 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.
*
* @param aTagName The HTML tagname
* Special input values for Links and Named anchors:
* Use "link" or "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)
*
* @param aNode The node in the document to start the search
* If it is null, the anchor node of the current selection is used
*/
NS_IMETHOD GetElementOrParentByTagName(const nsString& aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn)=0;
/** 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 Ancho 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.
*
* @param aTagName The HTML tagname
* Special input values for Links and Named anchors:
* Use "link" or "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)
*/
NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn)=0;
/** Return a new element with default attribute values
* 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)
*
* @param aTagName The HTML tagname
* Special input values for Links and Named anchors:
* Use "link" or "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)
*/
NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn)=0;
/** 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.
*
* @param aElement The element to insert
* @param 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
*/
NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection)=0;
/** Save the attributes of a Horizontal Rule in user preferences
* These prefs are used when the user inserts a new Horizontal line
*
* @param aElement An HR element
*/
NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement)=0;
/** Insert an link element as the parent of the current selection
* be useful for other elements.
*
* @param aElement An "A" element with a non-empty "href" attribute
*/
1999-05-07 22:26:23 +00:00
NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)=0;
/** Set the selection at the suppled element
*
* @param aElement An element in the document
*/
NS_IMETHOD SelectElement(nsIDOMElement* aElement)=0;
/** 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.
*
* @param aElement An element in the document
*/
NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement)=0;
// MHTML helper methods
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList)=0;
// Table editing Methods
/** Not implemented yet
*/
NS_IMETHOD InsertTable()=0;
NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool aAfter)=0;
NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool aAfter)=0;
NS_IMETHOD InsertTableRow(PRInt32 aNumber, PRBool aAfter)=0;
NS_IMETHOD DeleteTable()=0;
NS_IMETHOD DeleteTableCell(PRInt32 aNumber)=0;
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber)=0;
NS_IMETHOD DeleteTableRow(PRInt32 aNumber)=0;
NS_IMETHOD JoinTableCells(PRBool aCellToRight)=0;
/** Get the row an column index from the layout's cellmap
* If aTable is null, it will try to find enclosing table of selection ancho
*
*/
NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32& aRowIndex, PRInt32& aColIndex)=0;
/** Get the number of rows and columns in a table from the layout's cellmap
* If aTable is null, it will try to find enclosing table of selection ancho
* Note that all rows in table will not have this many because of
* ROWSPAN effects or if table is not "rectangular" (has short rows)
*/
NS_IMETHOD GetTableSize(nsIDOMElement *aTable, PRInt32& aRowCount, PRInt32& aColCount)=0;
/** Get a cell element at cellmap grid coordinates
* A cell that spans across multiple cellmap locations will
* be returned multiple times, once for each location it occupies
*
* @param aTable A table in the document
* @param aRowIndex, aColIndex The 0-based cellmap indexes
*
* Note that this returns NS_TABLELAYOUT_CELL_NOT_FOUND
* when a cell is not found at the given indexes,
* but this passes the NS_SUCCEEDED() test,
* so you can scan for all cells in a row or column
* by iterating through the appropriate indexes
* until the returned aCell is null
*/
NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell)=0;
/** Get a cell at cellmap grid coordinates and associated data
* A cell that spans across multiple cellmap locations will
* be returned multiple times, once for each location it occupies
* Examine the returned aStartRowIndex and aStartColIndex to see
* if it is in the same layout column or layout row:
* A "layout row" is all cells sharing the same top edge
* A "layout column" is all cells sharing the same left edge
* This is important to determine what to do when inserting or deleting a column or row
*
* @param aTable A table in the document
* @param aRowIndex, aColIndex The 0-based cellmap indexes
*
* Note that this returns NS_TABLELAYOUT_CELL_NOT_FOUND
* when a cell is not found at the given indexes (see note for GetCellAt())
*/
NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell,
PRInt32& aStartRowIndex, PRInt32& aStartColIndex,
PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected)=0;
// IME editing Methods
NS_IMETHOD BeginComposition(void)=0;
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRangeList)=0;
NS_IMETHOD EndComposition(void)=0;
// Logging Methods
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile)=0;
NS_IMETHOD StopLogging()=0;
};
#endif //nsIEditor_h__