2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-09 01:34:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef nsEditorUtils_h__
|
|
|
|
#define nsEditorUtils_h__
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsEditor.h"
|
1999-08-09 01:34:04 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIEditor.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "prtypes.h"
|
1999-12-07 08:30:19 +00:00
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
class nsIAtom;
|
|
|
|
class nsIContentIterator;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIDOMRange;
|
|
|
|
class nsISelection;
|
|
|
|
template <class E> class nsCOMArray;
|
2001-04-05 23:48:01 +00:00
|
|
|
|
2000-01-31 10:30:12 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching a collection of txns inside a
|
|
|
|
* placeholder txn.
|
|
|
|
*/
|
2008-07-01 18:23:21 +00:00
|
|
|
class NS_STACK_CLASS nsAutoPlaceHolderBatch
|
1999-09-29 20:08:15 +00:00
|
|
|
{
|
|
|
|
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!
|
|
|
|
*/
|
2008-07-01 18:23:21 +00:00
|
|
|
class NS_STACK_CLASS nsAutoSelectionReset
|
1999-08-09 01:34:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
2008-07-01 18:23:21 +00:00
|
|
|
class NS_STACK_CLASS nsAutoRules
|
1999-12-07 08:30:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-05-05 18:52:29 +00:00
|
|
|
nsAutoRules(nsEditor *ed, nsEditor::OperationID action,
|
|
|
|
nsIEditor::EDirection aDirection) :
|
2011-10-17 14:59:28 +00:00
|
|
|
mEd(ed), mDoNothing(false)
|
2000-08-14 02:39:37 +00:00
|
|
|
{
|
|
|
|
if (mEd && !mEd->mAction) // mAction will already be set if this is nested call
|
|
|
|
{
|
|
|
|
mEd->StartOperation(action, aDirection);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
else mDoNothing = true; // nested calls will end up here
|
2000-08-14 02:39:37 +00:00
|
|
|
}
|
|
|
|
~nsAutoRules()
|
|
|
|
{
|
|
|
|
if (mEd && !mDoNothing)
|
|
|
|
{
|
|
|
|
mEd->EndOperation();
|
|
|
|
}
|
|
|
|
}
|
1999-12-07 08:30:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool 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
|
|
|
|
*/
|
2008-07-01 18:23:21 +00:00
|
|
|
class NS_STACK_CLASS nsAutoTxnsConserveSelection
|
2000-01-04 03:09:41 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
nsAutoTxnsConserveSelection(nsEditor *ed) : mEd(ed), mOldState(true)
|
2000-01-04 03:09:41 +00:00
|
|
|
{
|
|
|
|
if (mEd)
|
|
|
|
{
|
|
|
|
mOldState = mEd->GetShouldTxnSetSelection();
|
2011-10-17 14:59:28 +00:00
|
|
|
mEd->SetShouldTxnSetSelection(false);
|
2000-01-04 03:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsAutoTxnsConserveSelection()
|
|
|
|
{
|
|
|
|
if (mEd)
|
|
|
|
{
|
|
|
|
mEd->SetShouldTxnSetSelection(mOldState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mOldState;
|
2000-01-04 03:09:41 +00:00
|
|
|
};
|
|
|
|
|
2001-05-11 13:59:11 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching reflow and paint requests.
|
|
|
|
*/
|
2008-07-01 18:23:21 +00:00
|
|
|
class NS_STACK_CLASS nsAutoUpdateViewBatch
|
2001-05-11 13:59:11 +00:00
|
|
|
{
|
|
|
|
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 nsBoolDomIterFunctor
|
|
|
|
{
|
|
|
|
public:
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool operator()(nsIDOMNode* aNode)=0;
|
2000-08-26 04:03:50 +00:00
|
|
|
};
|
|
|
|
|
2008-07-01 18:23:21 +00:00
|
|
|
class NS_STACK_CLASS nsDOMIterator
|
2000-08-26 04:03:50 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDOMIterator();
|
|
|
|
virtual ~nsDOMIterator();
|
|
|
|
|
|
|
|
nsresult Init(nsIDOMRange* aRange);
|
|
|
|
nsresult Init(nsIDOMNode* aNode);
|
|
|
|
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);
|
|
|
|
};
|
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:
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool operator()(nsIDOMNode* aNode) // used to build list of all nodes iterator covers
|
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
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-08-29 07:49:31 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* general dom point utility struct
|
|
|
|
*****************************************************************************/
|
2008-07-01 18:23:21 +00:00
|
|
|
struct NS_STACK_CLASS DOMPoint
|
2002-08-29 07:49:31 +00:00
|
|
|
{
|
|
|
|
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:
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 *aOffset = 0);
|
|
|
|
static bool IsLeafNode(nsIDOMNode *aNode);
|
2002-12-22 01:51:14 +00:00
|
|
|
};
|
|
|
|
|
2003-04-25 21:05:32 +00:00
|
|
|
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsISimpleEnumerator;
|
2012-07-13 06:33:42 +00:00
|
|
|
class nsITransferable;
|
2003-04-25 21:05:32 +00:00
|
|
|
|
|
|
|
class nsEditorHookUtils
|
|
|
|
{
|
|
|
|
public:
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aEvent,
|
2003-04-25 21:05:32 +00:00
|
|
|
nsITransferable *aTrans);
|
|
|
|
private:
|
|
|
|
static nsresult GetHookEnumeratorFromDocument(nsIDOMDocument *aDoc,
|
|
|
|
nsISimpleEnumerator **aEnumerator);
|
|
|
|
};
|
|
|
|
|
1999-08-09 01:34:04 +00:00
|
|
|
#endif // nsEditorUtils_h__
|