2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:21:17 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-09 01:34:04 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1999-08-09 01:34:04 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +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-08-09 01:34:04 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:53:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:21:17 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:53:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:21:17 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:53:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:21:17 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-09 01:34:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef nsEditorUtils_h__
|
|
|
|
#define nsEditorUtils_h__
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
1999-08-09 01:34:04 +00:00
|
|
|
#include "nsIEditor.h"
|
1999-09-29 20:08:15 +00:00
|
|
|
#include "nsIAtom.h"
|
2000-01-31 10:30:12 +00:00
|
|
|
#include "nsVoidArray.h"
|
1999-12-07 08:30:19 +00:00
|
|
|
#include "nsEditor.h"
|
2000-08-26 04:03:50 +00:00
|
|
|
#include "nsIContentIterator.h"
|
2002-11-12 19:40:11 +00:00
|
|
|
#include "nsCOMArray.h"
|
1999-12-07 08:30:19 +00:00
|
|
|
|
2001-04-05 23:48:01 +00:00
|
|
|
class nsPlaintextEditor;
|
|
|
|
|
2000-01-31 10:30:12 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching a collection of txns inside a
|
|
|
|
* placeholder txn.
|
|
|
|
*/
|
1999-09-29 20:08:15 +00:00
|
|
|
class nsAutoPlaceHolderBatch
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIEditor> mEd;
|
|
|
|
public:
|
|
|
|
nsAutoPlaceHolderBatch( nsIEditor *aEd, nsIAtom *atom) : mEd(do_QueryInterface(aEd))
|
|
|
|
{ if (mEd) mEd->BeginPlaceHolderTransaction(atom); }
|
|
|
|
~nsAutoPlaceHolderBatch() { if (mEd) mEd->EndPlaceHolderTransaction(); }
|
|
|
|
};
|
|
|
|
|
2000-01-31 10:30:12 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching a collection of txns.
|
|
|
|
* Note: I changed this to use placeholder batching so that we get
|
|
|
|
* proper selection save/restore across undo/redo.
|
|
|
|
*/
|
|
|
|
class nsAutoEditBatch : public nsAutoPlaceHolderBatch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAutoEditBatch( nsIEditor *aEd) : nsAutoPlaceHolderBatch(aEd,nsnull) {}
|
|
|
|
~nsAutoEditBatch() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for saving/restoring selection. Note that this
|
|
|
|
* assumes that the nodes involved are still around afterwards!
|
|
|
|
*/
|
1999-08-09 01:34:04 +00:00
|
|
|
class nsAutoSelectionReset
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
/** ref-counted reference to the selection that we are supposed to restore */
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelection> mSel;
|
2000-03-24 00:26:47 +00:00
|
|
|
nsEditor *mEd; // non-owning ref to nsEditor
|
1999-08-09 01:34:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** constructor responsible for remembering all state needed to restore aSel */
|
2000-09-14 11:45:01 +00:00
|
|
|
nsAutoSelectionReset(nsISelection *aSel, nsEditor *aEd);
|
1999-08-09 01:34:04 +00:00
|
|
|
|
|
|
|
/** destructor restores mSel to its former state */
|
|
|
|
~nsAutoSelectionReset();
|
2000-08-26 04:03:50 +00:00
|
|
|
|
|
|
|
/** Abort: cancel selection saver */
|
|
|
|
void Abort();
|
1999-08-09 01:34:04 +00:00
|
|
|
};
|
|
|
|
|
1999-12-07 08:30:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for StartOperation()/EndOperation() sandwich
|
|
|
|
*/
|
|
|
|
class nsAutoRules
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2000-03-24 00:26:47 +00:00
|
|
|
nsAutoRules(nsEditor *ed, PRInt32 action, nsIEditor::EDirection aDirection) :
|
2000-08-14 02:39:37 +00:00
|
|
|
mEd(ed), mDoNothing(PR_FALSE)
|
|
|
|
{
|
|
|
|
if (mEd && !mEd->mAction) // mAction will already be set if this is nested call
|
|
|
|
{
|
|
|
|
mEd->StartOperation(action, aDirection);
|
|
|
|
}
|
|
|
|
else mDoNothing = PR_TRUE; // nested calls will end up here
|
|
|
|
}
|
|
|
|
~nsAutoRules()
|
|
|
|
{
|
|
|
|
if (mEd && !mDoNothing)
|
|
|
|
{
|
|
|
|
mEd->EndOperation();
|
|
|
|
}
|
|
|
|
}
|
1999-12-07 08:30:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
2000-08-14 02:39:37 +00:00
|
|
|
PRBool mDoNothing;
|
1999-12-07 08:30:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-01-04 03:09:41 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for turning off active selection adjustment
|
|
|
|
* by low level transactions
|
|
|
|
*/
|
|
|
|
class nsAutoTxnsConserveSelection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsAutoTxnsConserveSelection(nsEditor *ed) : mEd(ed), mOldState(PR_TRUE)
|
|
|
|
{
|
|
|
|
if (mEd)
|
|
|
|
{
|
|
|
|
mOldState = mEd->GetShouldTxnSetSelection();
|
|
|
|
mEd->SetShouldTxnSetSelection(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsAutoTxnsConserveSelection()
|
|
|
|
{
|
|
|
|
if (mEd)
|
|
|
|
{
|
|
|
|
mEd->SetShouldTxnSetSelection(mOldState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
|
|
|
PRBool mOldState;
|
|
|
|
};
|
|
|
|
|
2001-05-11 13:59:11 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching reflow and paint requests.
|
|
|
|
*/
|
|
|
|
class nsAutoUpdateViewBatch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsAutoUpdateViewBatch(nsEditor *ed) : mEd(ed)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mEd, "null mEd pointer!");
|
|
|
|
|
|
|
|
if (mEd)
|
|
|
|
mEd->BeginUpdateViewBatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsAutoUpdateViewBatch()
|
|
|
|
{
|
|
|
|
if (mEd)
|
|
|
|
mEd->EndUpdateViewBatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
|
|
|
};
|
|
|
|
|
2000-08-26 04:03:50 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* some helper classes for iterating the dom tree
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class nsDomIterFunctor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void* operator()(nsIDOMNode* aNode)=0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsBoolDomIterFunctor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual PRBool operator()(nsIDOMNode* aNode)=0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDOMIterator();
|
|
|
|
virtual ~nsDOMIterator();
|
|
|
|
|
|
|
|
nsresult Init(nsIDOMRange* aRange);
|
|
|
|
nsresult Init(nsIDOMNode* aNode);
|
|
|
|
void ForEach(nsDomIterFunctor& functor) const;
|
|
|
|
nsresult AppendList(nsBoolDomIterFunctor& functor,
|
2002-11-12 19:40:11 +00:00
|
|
|
nsCOMArray<nsIDOMNode>& arrayOfNodes) const;
|
2000-08-26 04:03:50 +00:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIContentIterator> mIter;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMSubtreeIterator : public nsDOMIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDOMSubtreeIterator();
|
|
|
|
virtual ~nsDOMSubtreeIterator();
|
|
|
|
|
|
|
|
nsresult Init(nsIDOMRange* aRange);
|
|
|
|
nsresult Init(nsIDOMNode* aNode);
|
|
|
|
};
|
2000-01-04 03:09:41 +00:00
|
|
|
|
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
|
|
|
class nsTrivialFunctor : public nsBoolDomIterFunctor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual PRBool operator()(nsIDOMNode* aNode) // used to build list of all nodes iterator covers
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-08-29 07:49:31 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* general dom point utility struct
|
|
|
|
*****************************************************************************/
|
|
|
|
struct DOMPoint
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
PRInt32 offset;
|
|
|
|
|
|
|
|
DOMPoint() : node(0),offset(0) {}
|
|
|
|
DOMPoint(nsIDOMNode *aNode, PRInt32 aOffset) :
|
|
|
|
node(aNode),offset(aOffset) {}
|
|
|
|
void SetPoint(nsIDOMNode *aNode, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
node = aNode; offset = aOffset;
|
|
|
|
}
|
|
|
|
void GetPoint(nsCOMPtr<nsIDOMNode> &aNode, PRInt32 &aOffset)
|
|
|
|
{
|
|
|
|
aNode = node; aOffset = offset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-12-22 01:51:14 +00:00
|
|
|
class nsEditorUtils
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static PRBool IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 *aOffset = 0);
|
|
|
|
static PRBool IsLeafNode(nsIDOMNode *aNode);
|
|
|
|
};
|
|
|
|
|
2003-04-25 21:05:32 +00:00
|
|
|
|
|
|
|
class nsIDragSession;
|
|
|
|
class nsITransferable;
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsISimpleEnumerator;
|
|
|
|
|
|
|
|
class nsEditorHookUtils
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static PRBool DoAllowDragHook(nsIDOMDocument *aDoc, nsIDOMEvent *aEvent);
|
2003-05-09 18:30:02 +00:00
|
|
|
static PRBool DoDragHook(nsIDOMDocument *aDoc, nsIDOMEvent *aEvent,
|
|
|
|
nsITransferable *aTrans);
|
2003-04-25 21:05:32 +00:00
|
|
|
static PRBool DoAllowDropHook(nsIDOMDocument *aDoc, nsIDOMEvent *aEvent,
|
|
|
|
nsIDragSession *aSession);
|
|
|
|
static PRBool DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aEvent,
|
|
|
|
nsITransferable *aTrans);
|
|
|
|
private:
|
|
|
|
static nsresult GetHookEnumeratorFromDocument(nsIDOMDocument *aDoc,
|
|
|
|
nsISimpleEnumerator **aEnumerator);
|
|
|
|
};
|
|
|
|
|
1999-08-09 01:34:04 +00:00
|
|
|
#endif // nsEditorUtils_h__
|