1999-03-29 10:21:01 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03: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-03-29 10:21:01 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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-03-29 10:21:01 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-03-29 10:21:01 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-03-29 10:21:01 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsHTMLEditRules_h__
|
|
|
|
#define nsHTMLEditRules_h__
|
|
|
|
|
|
|
|
#include "nsTextEditRules.h"
|
1999-11-25 03:19:45 +03:00
|
|
|
#include "nsIEditActionListener.h"
|
1999-07-02 03:41:29 +04:00
|
|
|
#include "nsISupportsArray.h"
|
1999-04-12 16:01:32 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-11-25 03:19:45 +03:00
|
|
|
#include "nsString.h"
|
1999-03-29 10:21:01 +04:00
|
|
|
|
1999-06-16 09:02:43 +04:00
|
|
|
class nsISupportsArray;
|
1999-07-01 17:42:03 +04:00
|
|
|
class nsVoidArray;
|
1999-11-25 03:19:45 +03:00
|
|
|
class nsIDOMElement;
|
1999-06-16 09:02:43 +04:00
|
|
|
|
2000-03-24 03:26:47 +03:00
|
|
|
class nsHTMLEditRules : public nsTextEditRules, nsIEditActionListener
|
1999-03-29 10:21:01 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2000-03-24 03:26:47 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
1999-08-09 22:39:49 +04:00
|
|
|
nsHTMLEditRules();
|
1999-08-09 05:37:50 +04:00
|
|
|
virtual ~nsHTMLEditRules();
|
1999-03-29 10:21:01 +04:00
|
|
|
|
2000-03-24 03:26:47 +03:00
|
|
|
|
|
|
|
// nsIEditRules methods
|
1999-11-25 03:19:45 +03:00
|
|
|
NS_IMETHOD Init(nsHTMLEditor *aEditor, PRUint32 aFlags);
|
2000-03-24 03:26:47 +03:00
|
|
|
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection);
|
|
|
|
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection);
|
1999-10-06 23:34:09 +04:00
|
|
|
NS_IMETHOD WillDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel, PRBool *aHandled);
|
1999-04-12 16:01:32 +04:00
|
|
|
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
|
1999-04-05 21:21:59 +04:00
|
|
|
|
2000-03-24 03:26:47 +03:00
|
|
|
// nsIEditActionListener methods
|
|
|
|
|
|
|
|
NS_IMETHOD WillCreateNode(const nsString& aTag, nsIDOMNode *aParent, PRInt32 aPosition);
|
|
|
|
NS_IMETHOD DidCreateNode(const nsString& aTag, nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aPosition, nsresult aResult);
|
|
|
|
NS_IMETHOD WillInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aPosition);
|
|
|
|
NS_IMETHOD DidInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aPosition, nsresult aResult);
|
|
|
|
NS_IMETHOD WillDeleteNode(nsIDOMNode *aChild);
|
|
|
|
NS_IMETHOD DidDeleteNode(nsIDOMNode *aChild, nsresult aResult);
|
|
|
|
NS_IMETHOD WillSplitNode(nsIDOMNode *aExistingRightNode, PRInt32 aOffset);
|
|
|
|
NS_IMETHOD DidSplitNode(nsIDOMNode *aExistingRightNode, PRInt32 aOffset, nsIDOMNode *aNewLeftNode, nsresult aResult);
|
|
|
|
NS_IMETHOD WillJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMNode *aParent);
|
|
|
|
NS_IMETHOD DidJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMNode *aParent, nsresult aResult);
|
|
|
|
NS_IMETHOD WillInsertText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, const nsString &aString);
|
|
|
|
NS_IMETHOD DidInsertText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, const nsString &aString, nsresult aResult);
|
|
|
|
NS_IMETHOD WillDeleteText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, PRInt32 aLength);
|
|
|
|
NS_IMETHOD DidDeleteText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, PRInt32 aLength, nsresult aResult);
|
|
|
|
NS_IMETHOD WillDeleteSelection(nsIDOMSelection *aSelection);
|
|
|
|
NS_IMETHOD DidDeleteSelection(nsIDOMSelection *aSelection);
|
|
|
|
|
1999-04-05 21:21:59 +04:00
|
|
|
protected:
|
|
|
|
|
1999-06-16 09:02:43 +04:00
|
|
|
enum RulesEndpoint
|
|
|
|
{
|
|
|
|
kStart,
|
|
|
|
kEnd
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-04-05 21:21:59 +04:00
|
|
|
// nsHTMLEditRules implementation methods
|
1999-11-01 18:15:35 +03:00
|
|
|
nsresult WillInsertText( PRInt32 aAction,
|
|
|
|
nsIDOMSelection *aSelection,
|
|
|
|
PRBool *aCancel,
|
|
|
|
PRBool *aHandled,
|
|
|
|
const nsString *inString,
|
|
|
|
nsString *outString,
|
|
|
|
PRInt32 aMaxLength);
|
1999-10-06 23:34:09 +04:00
|
|
|
nsresult WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel, PRBool *aHandled);
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult WillDeleteSelection(nsIDOMSelection *aSelection, nsIEditor::EDirection aAction,
|
1999-10-06 23:34:09 +04:00
|
|
|
PRBool *aCancel, PRBool *aHandled);
|
|
|
|
nsresult WillMakeList(nsIDOMSelection *aSelection, PRBool aOrderd, PRBool *aCancel, PRBool *aHandled);
|
|
|
|
nsresult WillRemoveList(nsIDOMSelection *aSelection, PRBool aOrderd, PRBool *aCancel, PRBool *aHandled);
|
|
|
|
nsresult WillIndent(nsIDOMSelection *aSelection, PRBool *aCancel, PRBool *aHandled);
|
|
|
|
nsresult WillOutdent(nsIDOMSelection *aSelection, PRBool *aCancel, PRBool *aHandled);
|
|
|
|
nsresult WillAlign(nsIDOMSelection *aSelection, const nsString *alignType, PRBool *aCancel, PRBool *aHandled);
|
|
|
|
nsresult WillMakeBasicBlock(nsIDOMSelection *aSelection, const nsString *aBlockType, PRBool *aCancel, PRBool *aHandled);
|
2000-03-31 02:57:19 +04:00
|
|
|
nsresult DidMakeBasicBlock(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
|
1999-04-12 16:01:32 +04:00
|
|
|
|
2000-02-25 07:39:30 +03:00
|
|
|
nsresult AlignTableElement(nsIDOMNode *aNode, const nsString *alignType);
|
|
|
|
nsresult AlignTableCellContents(nsIDOMNode *aNode, const nsString *alignType);
|
|
|
|
nsresult GetTableContent(nsIDOMNode *aNode, nsCOMPtr<nsISupportsArray> *outArrayOfNodes);
|
|
|
|
|
1999-10-06 23:34:09 +04:00
|
|
|
nsresult InsertTab(nsIDOMSelection *aSelection, nsString *outString);
|
1999-04-12 16:01:32 +04:00
|
|
|
|
1999-04-26 18:08:52 +04:00
|
|
|
nsresult ReturnInHeader(nsIDOMSelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset);
|
1999-10-06 23:34:09 +04:00
|
|
|
nsresult ReturnInParagraph(nsIDOMSelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset, PRBool *aCancel, PRBool *aHandled);
|
1999-04-26 18:08:52 +04:00
|
|
|
nsresult ReturnInListItem(nsIDOMSelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset);
|
1999-09-10 02:22:14 +04:00
|
|
|
|
2000-03-29 16:53:23 +04:00
|
|
|
nsresult CreateStyleForInsertText(nsIDOMSelection *aSelection, nsIDOMDocument *aDoc);
|
1999-11-01 18:15:35 +03:00
|
|
|
nsresult IsEmptyBlock(nsIDOMNode *aNode,
|
2000-01-26 03:57:37 +03:00
|
|
|
PRBool *outIsEmptyBlock,
|
|
|
|
PRBool aMozBRDoesntCount = PR_FALSE,
|
|
|
|
PRBool aListItemsNotEmpty = PR_FALSE);
|
1999-11-01 18:15:35 +03:00
|
|
|
nsresult IsEmptyNode(nsIDOMNode *aNode,
|
|
|
|
PRBool *outIsEmptyBlock,
|
|
|
|
PRBool aMozBRDoesntCount = PR_FALSE,
|
|
|
|
PRBool aListItemsNotEmpty = PR_FALSE);
|
1999-07-01 22:42:28 +04:00
|
|
|
PRBool IsFirstNode(nsIDOMNode *aNode);
|
|
|
|
PRBool IsLastNode(nsIDOMNode *aNode);
|
1999-09-30 00:08:15 +04:00
|
|
|
PRBool AtStartOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aBlock);
|
|
|
|
PRBool AtEndOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aBlock);
|
2000-01-26 03:57:37 +03:00
|
|
|
|
1999-07-01 22:42:28 +04:00
|
|
|
nsresult GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset,
|
|
|
|
PRInt32 actionID, nsCOMPtr<nsIDOMNode> *outNode, PRInt32 *outOffset);
|
|
|
|
nsresult GetPromotedRanges(nsIDOMSelection *inSelection,
|
|
|
|
nsCOMPtr<nsISupportsArray> *outArrayOfRanges,
|
|
|
|
PRInt32 inOperationType);
|
1999-11-25 03:19:45 +03:00
|
|
|
nsresult PromoteRange(nsIDOMRange *inRange, PRInt32 inOperationType);
|
1999-08-18 12:13:06 +04:00
|
|
|
nsresult GetNodesForOperation(nsISupportsArray *inArrayOfRanges,
|
1999-07-01 17:42:03 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> *outArrayOfNodes,
|
|
|
|
PRInt32 inOperationType);
|
1999-08-18 12:13:06 +04:00
|
|
|
nsresult GetChildNodesForOperation(nsIDOMNode *inNode,
|
|
|
|
nsCOMPtr<nsISupportsArray> *outArrayOfNodes);
|
2000-04-24 15:51:12 +04:00
|
|
|
nsresult BustUpInlinesAtBRs(nsIDOMNode *inNode,
|
|
|
|
nsCOMPtr<nsISupportsArray> *outArrayOfNodes);
|
1999-08-18 12:13:06 +04:00
|
|
|
nsresult MakeTransitionList(nsISupportsArray *inArrayOfNodes,
|
1999-07-01 17:42:03 +04:00
|
|
|
nsVoidArray *inTransitionArray);
|
1999-08-18 12:13:06 +04:00
|
|
|
|
|
|
|
nsresult ShouldMakeEmptyBlock(nsIDOMSelection *aSelection, const nsString *blockTag, PRBool *outMakeEmpty);
|
|
|
|
nsresult ApplyBlockStyle(nsISupportsArray *arrayOfNodes, const nsString *aBlockTag);
|
2000-04-24 15:51:12 +04:00
|
|
|
nsresult MakeBlockquote(nsISupportsArray *arrayOfNodes);
|
|
|
|
nsresult SplitAsNeeded(const nsString *aTag, nsCOMPtr<nsIDOMNode> *inOutParent, PRInt32 *inOutOffset);
|
|
|
|
nsresult AddTerminatingBR(nsIDOMNode *aBlock);
|
1999-08-18 12:13:06 +04:00
|
|
|
|
1999-09-02 01:23:47 +04:00
|
|
|
nsresult JoinNodesSmart( nsIDOMNode *aNodeLeft,
|
|
|
|
nsIDOMNode *aNodeRight,
|
|
|
|
nsCOMPtr<nsIDOMNode> *aOutMergeParent,
|
|
|
|
PRInt32 *aOutMergeOffset);
|
|
|
|
|
1999-09-06 23:51:59 +04:00
|
|
|
nsresult GetTopEnclosingMailCite(nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutCiteNode);
|
|
|
|
nsresult PopListItem(nsIDOMNode *aListItem, PRBool *aOutOfList);
|
|
|
|
|
1999-11-25 03:19:45 +03:00
|
|
|
nsresult AdjustSpecialBreaks();
|
1999-12-01 00:58:37 +03:00
|
|
|
nsresult AdjustWhitespace(nsIDOMSelection *aSelection);
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult AdjustSelection(nsIDOMSelection *aSelection, nsIEditor::EDirection aAction);
|
2000-01-17 15:41:34 +03:00
|
|
|
nsresult FindNearSelectableNode(nsIDOMNode *aSelNode,
|
|
|
|
PRInt32 aSelOffset,
|
|
|
|
nsIEditor::EDirection aDirection,
|
|
|
|
nsCOMPtr<nsIDOMNode> *outSelectableNode);
|
1999-11-25 03:19:45 +03:00
|
|
|
nsresult RemoveEmptyNodes();
|
2000-02-25 07:39:30 +03:00
|
|
|
nsresult SelectionEndpointInNode(nsIDOMNode *aNode, PRBool *aResult);
|
1999-11-25 03:19:45 +03:00
|
|
|
nsresult DoTextNodeWhitespace(nsIDOMCharacterData *aTextNode, PRInt32 aStart, PRInt32 aEnd);
|
|
|
|
nsresult UpdateDocChangeRange(nsIDOMRange *aRange);
|
|
|
|
|
1999-11-25 03:36:34 +03:00
|
|
|
nsresult ConvertWhitespace(const nsString & inString, nsString & outString);
|
2000-01-10 13:13:58 +03:00
|
|
|
nsresult ConfirmSelectionInBody();
|
1999-11-25 03:19:45 +03:00
|
|
|
|
2000-03-31 02:57:19 +04:00
|
|
|
PRBool IsDescendantOfBody(nsIDOMNode *inNode);
|
|
|
|
nsresult InsertMozBRIfNeeded(nsIDOMNode *aNode);
|
1999-11-25 03:19:45 +03:00
|
|
|
|
|
|
|
// data members
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIDOMRange> mDocChangeRange;
|
2000-03-24 03:26:47 +03:00
|
|
|
PRBool mListenerEnabled;
|
|
|
|
nsCOMPtr<nsIDOMRange> mUtilRange;
|
|
|
|
nsCOMPtr<nsIDOMNode> mBody;
|
|
|
|
PRUint32 mJoinOffset; // need to remember an int across willJoin/didJoin...
|
1999-11-25 03:19:45 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2000-03-24 03:26:47 +03:00
|
|
|
nsresult NS_NewHTMLEditRules(nsIEditRules** aInstancePtrResult);
|
1999-03-29 10:21:01 +04:00
|
|
|
|
|
|
|
#endif //nsHTMLEditRules_h__
|
|
|
|
|