/* -*- 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.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/ * * 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. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ #ifndef __wsrunobject_h__ #define __wsrunobject_h__ #include "nsCOMPtr.h" #include "nsISupportsArray.h" #include "nsIDOMNode.h" #include "nsISupportsArray.h" #include "nsITextContent.h" #include "nsIEditor.h" class nsIDOMDocument; class nsIDOMNode; class nsHTMLEditor; class nsWSRunObject { public: typedef enum { kForward, kBackward } EWSDirection; // constructor / destructor nsWSRunObject(nsHTMLEditor *aEd); nsWSRunObject(nsHTMLEditor *aEd, nsIDOMNode *aNode, PRInt32 aOffset); ~nsWSRunObject(); // public methods static nsresult PrepareToJoinBlocks(nsHTMLEditor *aEd, nsIDOMNode *aLeftParent, nsIDOMNode *aRightParent); nsresult InsertBreak(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, nsIEditor::EDirection aSelect); nsresult InsertText(const nsAReadableString& aStringToInsert, nsCOMPtr *aInOutNode, PRInt32 *aInOutOffset, nsIDOMDocument *aDoc); nsresult DeleteWSBackward(); nsresult DeleteWSForward(); nsresult PrepareToDeleteRange(nsWSRunObject* aEndObject); nsresult PrepareToSplitAcrossBlocks(nsCOMPtr *aSplitNode, PRInt32 *aSplitOffset); nsresult PriorVisibleNode(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outVisNode, PRInt32 *outVisOffset, PRInt16 *outType); nsresult NextVisibleNode (nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outVisNode, PRInt32 *outVisOffset, PRInt16 *outType); enum {eNone = 0}; enum {eLeadingWS = 1}; enum {eTrailingWS = 1 << 1}; enum {eNormalWS = 1 << 2}; enum {eText = 1 << 3}; enum {eSpecial = 1 << 4}; enum {eBreak = 1 << 5}; enum {eOtherBlock = 1 << 6}; enum {eThisBlock = 1 << 7}; enum {eBlock = eOtherBlock | eThisBlock}; protected: struct WSFragment { nsCOMPtr mStartNode; nsCOMPtr mEndNode; PRInt16 mStartOffset; PRInt16 mEndOffset; PRInt16 mType, mLeftType, mRightType; WSFragment *mLeft, *mRight; WSFragment() : mStartNode(0),mEndNode(0),mStartOffset(0), mEndOffset(0),mType(0),mLeftType(0), mRightType(0),mLeft(0),mRight(0) {} }; struct WSPoint { nsCOMPtr mTextNode; PRInt16 mOffset; PRUnichar mChar; WSPoint() : mTextNode(0),mOffset(0),mChar(0) {} WSPoint(nsIDOMNode *aNode, PRInt32 aOffset, PRUnichar aChar) : mTextNode(do_QueryInterface(aNode)),mOffset(aOffset),mChar(aChar) {} WSPoint(nsITextContent *aTextNode, PRInt32 aOffset, PRUnichar aChar) : mTextNode(aTextNode),mOffset(aOffset),mChar(aChar) {} }; // protected methods nsresult GetWSNodes(); nsresult GetRuns(); void ClearRuns(); nsresult MakeSingleWSRun(PRInt16 aType); nsresult PrependNodeToList(nsIDOMNode *aNode); nsresult AppendNodeToList(nsIDOMNode *aNode); nsresult GetPreviousWSNode(nsIDOMNode *aStartNode, nsIDOMNode *aBlockParent, nsCOMPtr *aPriorNode); nsresult GetNextWSNode(nsIDOMNode *aStartNode, nsIDOMNode *aBlockParent, nsCOMPtr *aNextNode); nsresult GetPreviousWSNode(nsIDOMNode *aStartNode, PRInt16 aOffset, nsIDOMNode *aBlockParent, nsCOMPtr *aPriorNode); nsresult GetNextWSNode(nsIDOMNode *aStartNode, PRInt16 aOffset, nsIDOMNode *aBlockParent, nsCOMPtr *aNextNode); nsresult DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset, nsIDOMNode *aEndNode, PRInt32 aEndOffset); nsresult GetCharAfter(WSFragment *run, nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint); nsresult GetCharBefore(WSFragment *run, nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint); nsresult GetCharAfter(WSPoint &aPoint, WSPoint *outPoint); nsresult GetCharBefore(WSPoint &aPoint, WSPoint *outPoint); nsresult ConvertToNBSP(WSPoint aPoint); nsresult FindRun(nsIDOMNode *aNode, PRInt32 aOffset, WSFragment **outRun, PRBool after); PRUnichar GetCharAt(nsITextContent *aTextNode, PRInt32 aOffset); nsresult GetWSPointAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint); nsresult GetWSPointBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint); // member variables nsCOMPtr mNode; PRInt32 mOffset; nsCOMPtr mStartNode; PRInt32 mStartOffset; PRInt16 mStartReason; nsCOMPtr mEndNode; PRInt32 mEndOffset; PRInt16 mEndReason; nsCOMPtr mFirstNBSPNode; PRInt32 mFirstNBSPOffset; nsCOMPtr mLastNBSPNode; PRInt32 mLastNBSPOffset; nsCOMPtr mNodeArray; WSFragment *mRootRun; WSFragment *mStartRun; WSFragment *mEndRun; nsHTMLEditor *mHTMLEditor; // non-owning. }; #endif