1999-02-12 17:18:58 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-02-12 17:18:58 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-02-12 17:18:58 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-02-12 17:18:58 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-02-12 17:18:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __editor_h__
|
|
|
|
#define __editor_h__
|
|
|
|
|
1999-08-09 01:37:50 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-04-27 07:37:12 +00:00
|
|
|
#include "nsWeakReference.h"
|
1999-08-09 01:37:50 +00:00
|
|
|
|
1999-02-12 17:18:58 +00:00
|
|
|
#include "nsIEditor.h"
|
1999-08-09 01:37:50 +00:00
|
|
|
#include "nsIEditorIMESupport.h"
|
|
|
|
|
1999-02-12 17:18:58 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
1999-09-01 19:58:25 +00:00
|
|
|
#include "nsIDiskDocument.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
1999-07-01 18:42:28 +00:00
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-02-12 17:18:58 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
1999-05-03 22:57:48 +00:00
|
|
|
#include "nsIDOMRange.h"
|
1999-08-06 02:32:13 +00:00
|
|
|
#include "nsIPrivateTextRange.h"
|
1999-02-12 17:18:58 +00:00
|
|
|
#include "nsITransactionManager.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-07-28 02:55:40 +00:00
|
|
|
#include "nsISupportsArray.h"
|
1999-06-30 00:52:25 +00:00
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-07-02 05:20:31 +00:00
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-07-19 22:49:21 +00:00
|
|
|
#include "nsIDTD.h"
|
2000-01-10 10:44:18 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2000-01-31 10:30:12 +00:00
|
|
|
#include "nsVoidArray.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
#include "nsSelectionState.h"
|
1999-02-12 17:18:58 +00:00
|
|
|
|
1999-04-27 17:14:28 +00:00
|
|
|
class nsIEditActionListener;
|
1999-07-28 02:55:40 +00:00
|
|
|
class nsIDocumentStateListener;
|
1999-02-12 17:18:58 +00:00
|
|
|
class nsIDOMCharacterData;
|
|
|
|
class nsIDOMRange;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsIViewManager;
|
|
|
|
class ChangeAttributeTxn;
|
|
|
|
class CreateElementTxn;
|
1999-02-24 17:24:37 +00:00
|
|
|
class InsertElementTxn;
|
1999-02-12 17:18:58 +00:00
|
|
|
class DeleteElementTxn;
|
|
|
|
class InsertTextTxn;
|
|
|
|
class DeleteTextTxn;
|
|
|
|
class SplitElementTxn;
|
|
|
|
class JoinElementTxn;
|
|
|
|
class EditAggregateTxn;
|
|
|
|
class nsVoidArray;
|
1999-05-05 04:05:19 +00:00
|
|
|
class nsISupportsArray;
|
1999-06-09 01:27:08 +00:00
|
|
|
class nsILocale;
|
1999-06-29 20:31:22 +00:00
|
|
|
class IMETextTxn;
|
1999-07-02 03:57:50 +00:00
|
|
|
class AddStyleSheetTxn;
|
|
|
|
class RemoveStyleSheetTxn;
|
2001-01-09 22:47:02 +00:00
|
|
|
class nsIFile;
|
2000-04-28 06:20:36 +00:00
|
|
|
class nsISelectionController;
|
|
|
|
|
2000-03-24 00:26:47 +00:00
|
|
|
/** implementation of an editor object. it will be the controller/focal point
|
1999-02-12 17:18:58 +00:00
|
|
|
* for the main editor services. i.e. the GUIManager, publishing, transaction
|
|
|
|
* manager, event interfaces. the idea for the event interfaces is to have them
|
|
|
|
* delegate the actual commands to the editor independent of the XPFE implementation.
|
|
|
|
*/
|
1999-08-09 01:37:50 +00:00
|
|
|
class nsEditor : public nsIEditor,
|
2000-04-27 07:37:12 +00:00
|
|
|
public nsIEditorIMESupport,
|
|
|
|
public nsSupportsWeakReference
|
1999-02-12 17:18:58 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-05-05 04:05:19 +00:00
|
|
|
|
1999-05-17 12:22:31 +00:00
|
|
|
enum IterDirection
|
|
|
|
{
|
|
|
|
kIterForward,
|
|
|
|
kIterBackward
|
|
|
|
};
|
|
|
|
|
1999-12-07 08:30:19 +00:00
|
|
|
enum OperationID
|
|
|
|
{
|
|
|
|
kOpIgnore = -1,
|
|
|
|
kOpNone = 0,
|
|
|
|
kOpUndo,
|
|
|
|
kOpRedo,
|
|
|
|
kOpInsertNode,
|
|
|
|
kOpCreateNode,
|
|
|
|
kOpDeleteNode,
|
|
|
|
kOpSplitNode,
|
|
|
|
kOpJoinNode,
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
kOpDeleteSelection,
|
2001-01-28 20:13:07 +00:00
|
|
|
// text commands
|
|
|
|
kOpInsertBreak = 1000,
|
|
|
|
kOpInsertText = 1001,
|
|
|
|
kOpInsertIMEText = 1002,
|
|
|
|
kOpDeleteText = 1003
|
1999-12-07 08:30:19 +00:00
|
|
|
};
|
|
|
|
|
1999-05-05 23:27:17 +00:00
|
|
|
static const char* kMOZEditorBogusNodeAttr;
|
|
|
|
static const char* kMOZEditorBogusNodeValue;
|
1999-05-05 04:05:19 +00:00
|
|
|
|
1999-02-12 17:18:58 +00:00
|
|
|
/** The default constructor. This should suffice. the setting of the interfaces is done
|
|
|
|
* after the construction of the editor class.
|
|
|
|
*/
|
|
|
|
nsEditor();
|
|
|
|
/** The default destructor. This should suffice. Should this be pure virtual
|
|
|
|
* for someone to derive from the nsEditor later? I dont believe so.
|
|
|
|
*/
|
|
|
|
virtual ~nsEditor();
|
|
|
|
|
1999-03-05 21:05:35 +00:00
|
|
|
//Interfaces for addref and release and queryinterface
|
1999-04-13 01:33:32 +00:00
|
|
|
//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
|
1999-02-12 17:18:58 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-04-07 00:45:26 +00:00
|
|
|
/* ------------ utility methods -------------- */
|
1999-08-09 01:37:50 +00:00
|
|
|
NS_IMETHOD GetPresShell(nsIPresShell **aPS);
|
2001-04-07 00:45:26 +00:00
|
|
|
void NotifyEditorObservers(void);
|
|
|
|
/* ------------ nsIEditor methods -------------- */
|
|
|
|
NS_DECL_NSIEDITOR
|
1999-08-09 01:37:50 +00:00
|
|
|
/* ------------ nsIEditorIMESupport methods -------------- */
|
|
|
|
|
1999-08-31 01:20:32 +00:00
|
|
|
NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
|
1999-12-07 01:29:00 +00:00
|
|
|
NS_IMETHOD QueryComposition(nsTextEventReply* aReply);
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD SetCompositionString(const nsAReadableString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply);
|
1999-08-09 01:37:50 +00:00
|
|
|
NS_IMETHOD EndComposition(void);
|
1999-12-08 03:39:36 +00:00
|
|
|
NS_IMETHOD ForceCompositionEnd(void);
|
2000-08-04 21:43:29 +00:00
|
|
|
NS_IMETHOD GetReconversionString(nsReconversionEventReply *aReply);
|
1999-08-09 01:37:50 +00:00
|
|
|
|
|
|
|
public:
|
1999-02-12 17:18:58 +00:00
|
|
|
|
1999-07-02 03:57:50 +00:00
|
|
|
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD InsertTextImpl(const nsAReadableString& aStringToInsert,
|
2000-03-24 00:26:47 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> *aInOutNode,
|
|
|
|
PRInt32 *aInOutOffset,
|
|
|
|
nsIDOMDocument *aDoc);
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD InsertTextIntoTextNodeImpl(const nsAReadableString& aStringToInsert,
|
2000-03-24 00:26:47 +00:00
|
|
|
nsIDOMCharacterData *aTextNode,
|
|
|
|
PRInt32 aOffset);
|
1999-12-07 08:30:19 +00:00
|
|
|
NS_IMETHOD DeleteSelectionImpl(EDirection aAction);
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD DeleteSelectionAndCreateNode(const nsAReadableString& aTag,
|
2001-01-28 20:13:07 +00:00
|
|
|
nsIDOMNode ** aNewNode);
|
1999-08-09 01:37:50 +00:00
|
|
|
|
2000-03-24 00:26:47 +00:00
|
|
|
/* helper routines for node/parent manipulations */
|
|
|
|
nsresult ReplaceContainer(nsIDOMNode *inNode,
|
|
|
|
nsCOMPtr<nsIDOMNode> *outNode,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString &aNodeType,
|
|
|
|
const nsAReadableString *aAttribute = nsnull,
|
|
|
|
const nsAReadableString *aValue = nsnull,
|
2000-06-22 05:39:54 +00:00
|
|
|
PRBool aCloneAttributes = PR_FALSE);
|
|
|
|
|
2000-03-24 00:26:47 +00:00
|
|
|
nsresult RemoveContainer(nsIDOMNode *inNode);
|
|
|
|
nsresult InsertContainerAbove(nsIDOMNode *inNode,
|
|
|
|
nsCOMPtr<nsIDOMNode> *outNode,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString &aNodeType,
|
|
|
|
const nsAReadableString *aAttribute = nsnull,
|
|
|
|
const nsAReadableString *aValue = nsnull);
|
2000-03-24 00:26:47 +00:00
|
|
|
nsresult MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
2000-07-13 23:15:41 +00:00
|
|
|
/* Method to replace certain CreateElementNS() calls.
|
|
|
|
Arguments:
|
|
|
|
nsString& aTag - tag you want
|
|
|
|
nsIContent** aContent - returned Content that was created with above namespace.
|
|
|
|
*/
|
2001-04-07 00:45:26 +00:00
|
|
|
nsresult CreateHTMLContent(const nsAReadableString& aTag, nsIContent** aContent);
|
2000-07-13 23:15:41 +00:00
|
|
|
|
1999-02-12 17:18:58 +00:00
|
|
|
protected:
|
1999-08-09 01:37:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
NS_IMETHOD SetProperties(nsVoidArray *aPropList);
|
|
|
|
NS_IMETHOD GetProperties(nsVoidArray *aPropList);
|
|
|
|
*/
|
|
|
|
|
1999-03-10 19:48:13 +00:00
|
|
|
/** create a transaction for setting aAttribute to aValue on aElement
|
|
|
|
*/
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForSetAttribute(nsIDOMElement *aElement,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString & aAttribute,
|
|
|
|
const nsAReadableString & aValue,
|
1999-03-02 05:30:53 +00:00
|
|
|
ChangeAttributeTxn ** aTxn);
|
|
|
|
|
1999-03-10 19:48:13 +00:00
|
|
|
/** create a transaction for removing aAttribute on aElement
|
|
|
|
*/
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString & aAttribute,
|
1999-03-02 05:30:53 +00:00
|
|
|
ChangeAttributeTxn ** aTxn);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
1999-03-10 19:48:13 +00:00
|
|
|
/** create a transaction for creating a new child node of aParent of type aTag.
|
|
|
|
*/
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD CreateTxnForCreateElement(const nsAReadableString & aTag,
|
1999-03-02 05:30:53 +00:00
|
|
|
nsIDOMNode *aParent,
|
|
|
|
PRInt32 aPosition,
|
|
|
|
CreateElementTxn ** aTxn);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
1999-03-10 19:48:13 +00:00
|
|
|
/** create a transaction for inserting aNode as a child of aParent.
|
|
|
|
*/
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForInsertElement(nsIDOMNode * aNode,
|
|
|
|
nsIDOMNode * aParent,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
InsertElementTxn ** aTxn);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
1999-03-10 19:48:13 +00:00
|
|
|
/** create a transaction for removing aElement from its parent.
|
|
|
|
*/
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForDeleteElement(nsIDOMNode * aElement,
|
|
|
|
DeleteElementTxn ** aTxn);
|
1999-02-24 17:24:37 +00:00
|
|
|
|
1999-08-09 01:37:50 +00:00
|
|
|
|
1999-12-07 08:30:19 +00:00
|
|
|
NS_IMETHOD CreateTxnForDeleteSelection(EDirection aAction,
|
1999-08-09 01:37:50 +00:00
|
|
|
EditAggregateTxn ** aTxn);
|
|
|
|
|
|
|
|
NS_IMETHOD CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
1999-12-07 08:30:19 +00:00
|
|
|
EDirection aAction,
|
1999-08-09 01:37:50 +00:00
|
|
|
EditAggregateTxn *aTxn);
|
|
|
|
|
|
|
|
|
1999-03-10 19:48:13 +00:00
|
|
|
/** create a transaction for inserting aStringToInsert into aTextNode
|
|
|
|
* if aTextNode is null, the string is inserted at the current selection.
|
|
|
|
*/
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD CreateTxnForInsertText(const nsAReadableString & aStringToInsert,
|
1999-03-10 19:48:13 +00:00
|
|
|
nsIDOMCharacterData *aTextNode,
|
1999-10-26 18:54:47 +00:00
|
|
|
PRInt32 aOffset,
|
1999-03-02 05:30:53 +00:00
|
|
|
InsertTextTxn ** aTxn);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
2001-04-07 00:45:26 +00:00
|
|
|
NS_IMETHOD CreateTxnForIMEText(const nsAReadableString & aStringToInsert,
|
1999-06-29 20:31:22 +00:00
|
|
|
IMETextTxn ** aTxn);
|
|
|
|
|
1999-07-02 03:57:50 +00:00
|
|
|
/** create a transaction for adding a style sheet
|
|
|
|
*/
|
|
|
|
NS_IMETHOD CreateTxnForAddStyleSheet(nsICSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn);
|
|
|
|
|
|
|
|
/** create a transaction for removing a style sheet
|
|
|
|
*/
|
|
|
|
NS_IMETHOD CreateTxnForRemoveStyleSheet(nsICSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn);
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD DeleteText(nsIDOMCharacterData *aElement,
|
|
|
|
PRUint32 aOffset,
|
|
|
|
PRUint32 aLength);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
2001-05-11 12:43:22 +00:00
|
|
|
// NS_IMETHOD DeleteRange(nsIDOMRange *aRange);
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
|
|
|
|
PRUint32 aOffset,
|
|
|
|
PRUint32 aLength,
|
|
|
|
DeleteTextTxn **aTxn);
|
1999-08-09 01:37:50 +00:00
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForSplitNode(nsIDOMNode *aNode,
|
|
|
|
PRUint32 aOffset,
|
|
|
|
SplitElementTxn **aTxn);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHOD CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
|
|
|
|
nsIDOMNode *aRightNode,
|
|
|
|
JoinElementTxn **aTxn);
|
1999-02-17 19:42:29 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
NS_IMETHOD DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parentSelectedNode,
|
|
|
|
PRInt32& offsetOfNewNode);
|
1999-04-04 18:01:35 +00:00
|
|
|
|
1999-05-12 22:24:47 +00:00
|
|
|
// called each time we modify the document. Increments the mod
|
|
|
|
// count of the doc.
|
|
|
|
NS_IMETHOD IncDocModCount(PRInt32 inNumMods);
|
|
|
|
|
|
|
|
// return the mod count of the doc we are editing. Zero means unchanged.
|
|
|
|
NS_IMETHOD GetDocModCount(PRInt32 &outModCount);
|
|
|
|
|
|
|
|
// called ONLY when we need to override the doc's modification
|
|
|
|
// state. This should already be handled by nsIDiskDocument.
|
|
|
|
NS_IMETHOD ResetDocModCount();
|
|
|
|
|
1999-05-27 04:10:04 +00:00
|
|
|
// called after a transaction is done successfully
|
|
|
|
NS_IMETHOD DoAfterDoTransaction(nsITransaction *aTxn);
|
|
|
|
// called after a transaction is undone successfully
|
|
|
|
NS_IMETHOD DoAfterUndoTransaction();
|
1999-07-14 22:29:39 +00:00
|
|
|
// called after a transaction is redone successfully
|
|
|
|
NS_IMETHOD DoAfterRedoTransaction();
|
|
|
|
|
|
|
|
// called after the document has been saved
|
|
|
|
NS_IMETHOD DoAfterDocumentSave();
|
|
|
|
|
1999-08-03 00:58:38 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
eDocumentCreated,
|
|
|
|
eDocumentToBeDestroyed,
|
|
|
|
eDocumentStateChanged
|
|
|
|
} TDocumentListenerNotification;
|
|
|
|
|
1999-07-28 02:55:40 +00:00
|
|
|
// tell the doc state listeners that the doc state has changed
|
1999-08-03 00:58:38 +00:00
|
|
|
NS_IMETHOD NotifyDocumentListeners(TDocumentListenerNotification aNotificationType);
|
1999-07-28 02:55:40 +00:00
|
|
|
|
1999-06-25 22:57:26 +00:00
|
|
|
/** make the given selection span the entire document */
|
2000-09-14 11:45:01 +00:00
|
|
|
NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
|
2001-01-08 21:01:29 +00:00
|
|
|
|
|
|
|
/* Helper for output routines -- we expect subclasses to override this */
|
|
|
|
NS_IMETHOD GetWrapWidth(PRInt32* aWrapCol);
|
|
|
|
|
1999-03-14 00:31:35 +00:00
|
|
|
protected:
|
|
|
|
// XXXX: Horrible hack! We are doing this because
|
|
|
|
// of an error in Gecko which is not rendering the
|
|
|
|
// document after a change via the DOM - gpk 2/13/99
|
|
|
|
void HACKForceRedraw(void);
|
1999-05-03 22:57:48 +00:00
|
|
|
|
1999-08-09 01:37:50 +00:00
|
|
|
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin);
|
1999-03-14 00:31:35 +00:00
|
|
|
|
1999-05-05 04:05:19 +00:00
|
|
|
public:
|
1999-08-09 01:37:50 +00:00
|
|
|
|
1999-12-07 08:30:19 +00:00
|
|
|
/** All editor operations which alter the doc should be prefaced
|
|
|
|
* with a call to StartOperation, naming the action and direction */
|
|
|
|
NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
|
|
|
|
|
|
|
|
/** All editor operations which alter the doc should be followed
|
2000-08-14 02:39:37 +00:00
|
|
|
* with a call to EndOperation */
|
|
|
|
NS_IMETHOD EndOperation();
|
1999-12-07 08:30:19 +00:00
|
|
|
|
2000-08-26 04:03:50 +00:00
|
|
|
/** routines for managing the preservation of selection across
|
|
|
|
* various editor actions */
|
|
|
|
PRBool ArePreservingSelection();
|
2000-09-14 11:45:01 +00:00
|
|
|
nsresult PreserveSelectionAcrossActions(nsISelection *aSel);
|
|
|
|
nsresult RestorePreservedSelection(nsISelection *aSel);
|
2000-08-26 04:03:50 +00:00
|
|
|
void StopPreservingSelection();
|
|
|
|
|
|
|
|
|
1999-08-30 22:12:11 +00:00
|
|
|
/** return the string that represents text nodes in the content tree */
|
2001-04-07 00:45:26 +00:00
|
|
|
static nsresult GetTextNodeTag(nsAWritableString& aOutString);
|
1999-08-09 01:37:50 +00:00
|
|
|
|
1999-05-05 04:05:19 +00:00
|
|
|
/**
|
|
|
|
* SplitNode() creates a new node identical to an existing node, and split the contents between the two nodes
|
|
|
|
* @param aExistingRightNode the node to split. It will become the new node's next sibling.
|
|
|
|
* @param aOffset the offset of aExistingRightNode's content|children to do the split at
|
|
|
|
* @param aNewLeftNode [OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
|
|
|
|
* @param aParent the parent of aExistingRightNode
|
|
|
|
*/
|
2000-01-04 03:09:41 +00:00
|
|
|
nsresult SplitNodeImpl(nsIDOMNode *aExistingRightNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
nsIDOMNode *aNewLeftNode,
|
|
|
|
nsIDOMNode *aParent);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JoinNodes() takes 2 nodes and merge their content|children.
|
|
|
|
* @param aNodeToKeep The node that will remain after the join.
|
|
|
|
* @param aNodeToJoin The node that will be joined with aNodeToKeep.
|
|
|
|
* There is no requirement that the two nodes be of the same type.
|
1999-08-19 13:30:48 +00:00
|
|
|
* @param aParent The parent of aNodeToKeep
|
1999-05-05 04:05:19 +00:00
|
|
|
* @param aNodeToKeepIsFirst if PR_TRUE, the contents|children of aNodeToKeep come before the
|
|
|
|
* contents|children of aNodeToJoin, otherwise their positions are switched.
|
|
|
|
*/
|
2000-01-04 03:09:41 +00:00
|
|
|
nsresult JoinNodesImpl(nsIDOMNode *aNodeToKeep,
|
|
|
|
nsIDOMNode *aNodeToJoin,
|
|
|
|
nsIDOMNode *aParent,
|
|
|
|
PRBool aNodeToKeepIsFirst);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set aOffset to the offset of aChild in aParent.
|
|
|
|
* Returns an error if aChild is not an immediate child of aParent.
|
|
|
|
*/
|
|
|
|
static nsresult GetChildOffset(nsIDOMNode *aChild,
|
|
|
|
nsIDOMNode *aParent,
|
|
|
|
PRInt32 &aOffset);
|
|
|
|
|
1999-06-16 05:02:43 +00:00
|
|
|
/**
|
|
|
|
* Set aParent to the parent of aChild.
|
|
|
|
* Set aOffset to the offset of aChild in aParent.
|
|
|
|
*/
|
|
|
|
static nsresult GetNodeLocation(nsIDOMNode *aChild,
|
|
|
|
nsCOMPtr<nsIDOMNode> *aParent,
|
|
|
|
PRInt32 *aOffset);
|
|
|
|
|
1999-05-05 04:05:19 +00:00
|
|
|
/** returns the number of things inside aNode in the out-param aCount.
|
|
|
|
* @param aNode is the node to get the length of.
|
|
|
|
* If aNode is text, returns number of characters.
|
|
|
|
* If not, returns number of children nodes.
|
|
|
|
* @param aCount [OUT] the result of the above calculation.
|
|
|
|
*/
|
|
|
|
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, PRUint32 &aCount);
|
|
|
|
|
1999-05-05 04:51:54 +00:00
|
|
|
/** get the node immediately prior to aCurrentNode
|
|
|
|
* @param aCurrentNode the node from which we start the search
|
|
|
|
* @param aEditableNode if PR_TRUE, only return an editable node
|
|
|
|
* @param aResultNode [OUT] the node that occurs before aCurrentNode in the tree,
|
|
|
|
* skipping non-editable nodes if aEditableNode is PR_TRUE.
|
|
|
|
* If there is no prior node, aResultNode will be nsnull.
|
|
|
|
*/
|
1999-07-01 18:42:28 +00:00
|
|
|
nsresult GetPriorNode(nsIDOMNode *aCurrentNode,
|
|
|
|
PRBool aEditableNode,
|
2001-08-22 05:32:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> *aResultNode,
|
|
|
|
PRBool bNoBlockCrossing = PR_FALSE);
|
1999-05-05 04:51:54 +00:00
|
|
|
|
1999-08-31 13:55:18 +00:00
|
|
|
// and another version that takes a {parent,offset} pair rather than a node
|
|
|
|
nsresult GetPriorNode(nsIDOMNode *aParentNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
PRBool aEditableNode,
|
2001-08-22 05:32:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> *aResultNode,
|
|
|
|
PRBool bNoBlockCrossing = PR_FALSE);
|
1999-08-31 13:55:18 +00:00
|
|
|
|
1999-05-05 04:51:54 +00:00
|
|
|
/** get the node immediately after to aCurrentNode
|
|
|
|
* @param aCurrentNode the node from which we start the search
|
|
|
|
* @param aEditableNode if PR_TRUE, only return an editable node
|
|
|
|
* @param aResultNode [OUT] the node that occurs after aCurrentNode in the tree,
|
|
|
|
* skipping non-editable nodes if aEditableNode is PR_TRUE.
|
|
|
|
* If there is no prior node, aResultNode will be nsnull.
|
|
|
|
*/
|
1999-07-01 18:42:28 +00:00
|
|
|
nsresult GetNextNode(nsIDOMNode *aCurrentNode,
|
|
|
|
PRBool aEditableNode,
|
2001-08-22 05:32:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> *aResultNode,
|
|
|
|
PRBool bNoBlockCrossing = PR_FALSE);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
1999-08-31 13:55:18 +00:00
|
|
|
// and another version that takes a {parent,offset} pair rather than a node
|
|
|
|
nsresult GetNextNode(nsIDOMNode *aParentNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
PRBool aEditableNode,
|
2001-08-22 05:32:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> *aResultNode,
|
|
|
|
PRBool bNoBlockCrossing = PR_FALSE);
|
|
|
|
|
|
|
|
// stub. see comment in source.
|
|
|
|
PRBool IsBlockNode(nsIDOMNode *aNode);
|
|
|
|
|
|
|
|
/** Get the rightmost child of aCurrentNode;
|
|
|
|
* return nsnull if aCurrentNode has no children.
|
1999-05-05 04:51:54 +00:00
|
|
|
*/
|
2001-08-22 05:32:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> GetRightmostChild(nsIDOMNode *aCurrentNode,
|
|
|
|
PRBool bNoBlockCrossing = PR_FALSE);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
2001-08-22 05:32:44 +00:00
|
|
|
/** Get the leftmost child of aCurrentNode;
|
|
|
|
* return nsnull if aCurrentNode has no children.
|
1999-05-05 04:51:54 +00:00
|
|
|
*/
|
2001-08-22 05:32:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> GetLeftmostChild(nsIDOMNode *aCurrentNode,
|
|
|
|
PRBool bNoBlockCrossing = PR_FALSE);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
|
|
|
/** GetFirstTextNode ADDREFFS and will get the next available text node from the passed
|
|
|
|
* in node parameter it can also return NS_ERROR_FAILURE if no text nodes are available
|
|
|
|
* now it simply returns the first node in the dom
|
|
|
|
* @param nsIDOMNode *aNode is the node to start looking from
|
|
|
|
* @param nsIDOMNode **aRetNode is the return location of the text dom node
|
|
|
|
*
|
|
|
|
* NOTE: this method will probably be removed.
|
|
|
|
*/
|
|
|
|
static nsresult GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode);
|
|
|
|
|
|
|
|
/** GetFirstNodeOfType ADDREFFS and will get the next available node from the passed
|
|
|
|
* in aStartNode parameter of type aTag.
|
|
|
|
* It can also return NS_ERROR_FAILURE if no such nodes are available
|
|
|
|
* @param aStartNode is the node to start looking from
|
|
|
|
* @param aTag is the type of node we are searching for
|
|
|
|
* @param aResult is the node we found, or nsnull if there is none
|
|
|
|
*/
|
|
|
|
static nsresult GetFirstNodeOfType(nsIDOMNode *aStartNode,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString &aTag,
|
1999-05-05 04:05:19 +00:00
|
|
|
nsIDOMNode **aResult);
|
|
|
|
|
|
|
|
/** returns PR_TRUE if aNode is of the type implied by aTag */
|
|
|
|
static PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag);
|
2001-04-07 00:45:26 +00:00
|
|
|
static PRBool NodeIsType(nsIDOMNode *aNode, const nsAReadableString &aTag);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
1999-07-19 22:49:21 +00:00
|
|
|
/** returns PR_TRUE if aParent can contain a child of type aTag */
|
2001-04-07 00:45:26 +00:00
|
|
|
PRBool CanContainTag(nsIDOMNode* aParent, const nsAReadableString &aTag);
|
|
|
|
PRBool TagCanContain(const nsAReadableString &aParentTag, nsIDOMNode* aChild);
|
|
|
|
virtual PRBool TagCanContainTag(const nsAReadableString &aParentTag, const nsAReadableString &aChildTag);
|
2000-02-08 12:53:34 +00:00
|
|
|
|
2000-05-09 21:06:49 +00:00
|
|
|
/** returns PR_TRUE if aNode is a descendant of our root node */
|
|
|
|
PRBool IsDescendantOfBody(nsIDOMNode *inNode);
|
|
|
|
|
1999-09-29 20:08:15 +00:00
|
|
|
/** returns PR_TRUE if aNode is a container */
|
|
|
|
PRBool IsContainer(nsIDOMNode *aNode);
|
|
|
|
|
1999-05-05 04:05:19 +00:00
|
|
|
/** returns PR_TRUE if aNode is an editable node */
|
1999-07-01 18:42:28 +00:00
|
|
|
PRBool IsEditable(nsIDOMNode *aNode);
|
1999-05-05 04:05:19 +00:00
|
|
|
|
2000-01-18 23:45:35 +00:00
|
|
|
/** returns PR_TRUE if aNode is a MozEditorBogus node */
|
|
|
|
PRBool IsMozEditorBogusNode(nsIDOMNode *aNode);
|
|
|
|
|
1999-09-29 20:08:15 +00:00
|
|
|
/** returns PR_TRUE if content is an merely formatting whitespacce */
|
|
|
|
PRBool IsEmptyTextContent(nsIContent* aContent);
|
|
|
|
|
1999-06-25 09:33:02 +00:00
|
|
|
/** counts number of editable child nodes */
|
1999-07-01 18:42:28 +00:00
|
|
|
nsresult CountEditableChildren(nsIDOMNode *aNode, PRUint32 &outCount);
|
1999-06-25 09:33:02 +00:00
|
|
|
|
1999-09-22 01:23:58 +00:00
|
|
|
/** Find the deep first and last children. Returned nodes are AddReffed */
|
1999-11-17 11:03:25 +00:00
|
|
|
nsresult GetFirstEditableNode(nsIDOMNode *aRoot, nsCOMPtr<nsIDOMNode> *outFirstNode);
|
|
|
|
nsresult GetLastEditableNode(nsIDOMNode *aRoot, nsCOMPtr<nsIDOMNode> *outLastNode);
|
1999-06-22 21:42:44 +00:00
|
|
|
|
|
|
|
|
1999-05-17 12:22:31 +00:00
|
|
|
/** from html rules code - migration in progress */
|
2001-04-07 00:45:26 +00:00
|
|
|
static nsresult GetTagString(nsIDOMNode *aNode, nsAWritableString& outString);
|
1999-05-17 12:22:31 +00:00
|
|
|
static nsCOMPtr<nsIAtom> GetTag(nsIDOMNode *aNode);
|
|
|
|
static PRBool NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2);
|
|
|
|
static PRBool IsTextOrElementNode(nsIDOMNode *aNode);
|
|
|
|
static PRBool IsTextNode(nsIDOMNode *aNode);
|
|
|
|
|
|
|
|
static PRInt32 GetIndexOf(nsIDOMNode *aParent, nsIDOMNode *aChild);
|
|
|
|
static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset);
|
|
|
|
|
2000-09-14 11:45:01 +00:00
|
|
|
static nsresult GetStartNodeAndOffset(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> *outStartNode, PRInt32 *outStartOffset);
|
|
|
|
static nsresult GetEndNodeAndOffset(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> *outEndNode, PRInt32 *outEndOffset);
|
1999-06-09 01:27:08 +00:00
|
|
|
|
2000-02-10 05:14:52 +00:00
|
|
|
// Helpers to add a node to the selection.
|
|
|
|
// Used by table cell selection methods
|
|
|
|
nsresult CreateRange(nsIDOMNode *aStartParent, PRInt32 aStartOffset,
|
|
|
|
nsIDOMNode *aEndParent, PRInt32 aEndOffset,
|
|
|
|
nsIDOMRange **aRange);
|
|
|
|
// Gets the node at the StartOffset of StartParent in aRange
|
|
|
|
// (this is a table cell in cell selection mode)
|
|
|
|
nsresult GetFirstNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aNode);
|
|
|
|
// Creates a range with just the supplied node and appends that to the selection
|
|
|
|
nsresult AppendNodeToSelectionAsRange(nsIDOMNode *aNode);
|
|
|
|
// When you are using AppendNodeToSelectionAsRange, call this first to start a new selection
|
|
|
|
nsresult ClearSelection();
|
|
|
|
|
1999-05-17 12:22:31 +00:00
|
|
|
nsresult IsPreformatted(nsIDOMNode *aNode, PRBool *aResult);
|
|
|
|
|
2000-04-24 11:51:12 +00:00
|
|
|
nsresult SplitNodeDeep(nsIDOMNode *aNode,
|
|
|
|
nsIDOMNode *aSplitPointParent,
|
|
|
|
PRInt32 aSplitPointOffset,
|
|
|
|
PRInt32 *outOffset,
|
2000-08-26 04:03:50 +00:00
|
|
|
PRBool aNoEmptyContainers = PR_FALSE,
|
2000-04-24 11:51:12 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> *outLeftNode = 0,
|
|
|
|
nsCOMPtr<nsIDOMNode> *outRightNode = 0);
|
1999-08-31 13:55:18 +00:00
|
|
|
nsresult JoinNodeDeep(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsCOMPtr<nsIDOMNode> *aOutJoinNode, PRInt32 *outOffset);
|
|
|
|
|
2001-04-07 00:45:26 +00:00
|
|
|
nsresult GetString(const nsAReadableString& name, nsAWritableString& value);
|
1999-05-03 22:57:48 +00:00
|
|
|
|
1999-06-14 20:02:46 +00:00
|
|
|
nsresult BeginUpdateViewBatch(void);
|
|
|
|
nsresult EndUpdateViewBatch(void);
|
1999-02-12 17:18:58 +00:00
|
|
|
|
2000-01-04 03:09:41 +00:00
|
|
|
PRBool GetShouldTxnSetSelection();
|
1999-02-12 17:18:58 +00:00
|
|
|
|
2001-04-05 23:48:01 +00:00
|
|
|
public:
|
|
|
|
// Argh! These transaction names are used by PlaceholderTxn and
|
|
|
|
// nsPlaintextEditor. They should be localized to those classes.
|
|
|
|
static nsIAtom *gTypingTxnName;
|
|
|
|
static nsIAtom *gIMETxnName;
|
|
|
|
static nsIAtom *gDeleteTxnName;
|
|
|
|
|
1999-08-09 01:37:50 +00:00
|
|
|
protected:
|
1999-06-03 05:58:20 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
PRUint32 mFlags; // behavior flags. See nsPlaintextEditor.h for the flags we use.
|
1999-08-09 01:37:50 +00:00
|
|
|
|
1999-08-25 10:51:55 +00:00
|
|
|
nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell
|
2000-04-28 06:20:36 +00:00
|
|
|
nsWeakPtr mSelConWeak; // weak reference to the nsISelectionController
|
1999-08-09 01:37:50 +00:00
|
|
|
nsIViewManager *mViewManager;
|
1999-09-02 20:37:19 +00:00
|
|
|
PRInt32 mUpdateCount;
|
1999-08-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsITransactionManager> mTxnMgr;
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> mLastStyleSheet; // is owning this dangerous?
|
2000-08-26 04:03:50 +00:00
|
|
|
nsWeakPtr mPlaceHolderTxn; // weak reference to placeholder for begin/end batch purposes
|
|
|
|
nsIAtom *mPlaceHolderName; // name of placeholder transaction
|
|
|
|
PRInt32 mPlaceHolderBatch; // nesting count for batching
|
|
|
|
nsSelectionState *mSelState; // saved selection state for placeholder txn batching
|
|
|
|
nsSelectionState mSavedSel; // cached selection for nsAutoSelectionReset
|
|
|
|
nsRangeUpdater mRangeUpdater; // utility class object for maintaining preserved ranges
|
|
|
|
PRBool mShouldTxnSetSelection; // turn off for conservative selection adjustment by txns
|
2000-01-10 10:13:58 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> mBodyElement; // cached body node
|
2000-08-26 04:03:50 +00:00
|
|
|
PRInt32 mAction; // the current editor action
|
|
|
|
EDirection mDirection; // the current direction of editor action
|
2000-08-14 02:39:37 +00:00
|
|
|
|
1999-08-09 01:37:50 +00:00
|
|
|
// data necessary to build IME transactions
|
1999-10-26 18:54:47 +00:00
|
|
|
PRBool mInIMEMode; // are we inside an IME composition?
|
|
|
|
nsIPrivateTextRangeList* mIMETextRangeList; // IME special selection ranges
|
|
|
|
nsCOMPtr<nsIDOMCharacterData> mIMETextNode; // current IME text node
|
|
|
|
PRUint32 mIMETextOffset; // offset in text node where IME comp string begins
|
|
|
|
PRUint32 mIMEBufferLength; // current length of IME comp string
|
1999-08-09 01:37:50 +00:00
|
|
|
|
2000-08-14 02:39:37 +00:00
|
|
|
// various listeners
|
2000-07-16 06:36:27 +00:00
|
|
|
nsVoidArray* mActionListeners; // listens to all low level actions on the doc
|
|
|
|
nsVoidArray* mEditorObservers; // just notify once per high level change
|
|
|
|
nsCOMPtr<nsISupportsArray> mDocStateListeners;// listen to overall doc state (dirty or not, just created, etc)
|
1999-08-09 01:37:50 +00:00
|
|
|
|
|
|
|
PRInt8 mDocDirtyState; // -1 = not initialized
|
1999-08-25 10:51:55 +00:00
|
|
|
nsWeakPtr mDocWeak; // weak reference to the nsIDOMDocument
|
1999-08-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIDTD> mDTD;
|
|
|
|
|
|
|
|
static PRInt32 gInstanceCount;
|
|
|
|
|
|
|
|
friend PRBool NSCanUnload(nsISupports* serviceMgr);
|
2000-01-04 03:09:41 +00:00
|
|
|
friend class nsAutoTxnsConserveSelection;
|
2000-03-24 00:26:47 +00:00
|
|
|
friend class nsAutoSelectionReset;
|
2000-08-14 02:39:37 +00:00
|
|
|
friend class nsAutoRules;
|
1999-06-08 06:04:51 +00:00
|
|
|
};
|
|
|
|
|
1999-06-03 05:58:20 +00:00
|
|
|
|
1999-02-18 12:14:59 +00:00
|
|
|
#endif
|