1999-08-09 05:34:04 +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-08-09 05:34:04 +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-08-09 05:34:04 +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-08-09 05:34:04 +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-08-09 05:34:04 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef nsEditorUtils_h__
|
|
|
|
#define nsEditorUtils_h__
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelection.h"
|
1999-08-09 05:34:04 +04:00
|
|
|
#include "nsIEditor.h"
|
1999-09-30 00:08:15 +04:00
|
|
|
#include "nsIAtom.h"
|
2000-01-31 13:30:12 +03:00
|
|
|
#include "nsVoidArray.h"
|
1999-12-07 11:30:19 +03:00
|
|
|
#include "nsEditor.h"
|
2000-08-26 08:03:50 +04:00
|
|
|
#include "nsIContentIterator.h"
|
1999-12-07 11:30:19 +03:00
|
|
|
|
2000-01-31 13:30:12 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching a collection of txns inside a
|
|
|
|
* placeholder txn.
|
|
|
|
*/
|
1999-09-30 00:08:15 +04: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(); }
|
|
|
|
};
|
|
|
|
|
1999-09-20 05:31:44 +04:00
|
|
|
|
2000-01-31 13:30:12 +03: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 05:34:04 +04:00
|
|
|
class nsAutoSelectionReset
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
/** ref-counted reference to the selection that we are supposed to restore */
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelection> mSel;
|
2000-03-24 03:26:47 +03:00
|
|
|
nsEditor *mEd; // non-owning ref to nsEditor
|
1999-08-09 05:34:04 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** constructor responsible for remembering all state needed to restore aSel */
|
2000-09-14 15:45:01 +04:00
|
|
|
nsAutoSelectionReset(nsISelection *aSel, nsEditor *aEd);
|
1999-08-09 05:34:04 +04:00
|
|
|
|
|
|
|
/** destructor restores mSel to its former state */
|
|
|
|
~nsAutoSelectionReset();
|
2000-08-26 08:03:50 +04:00
|
|
|
|
|
|
|
/** Abort: cancel selection saver */
|
|
|
|
void Abort();
|
1999-08-09 05:34:04 +04:00
|
|
|
};
|
|
|
|
|
1999-12-07 11:30:19 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for StartOperation()/EndOperation() sandwich
|
|
|
|
*/
|
|
|
|
class nsAutoRules
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2000-03-24 03:26:47 +03:00
|
|
|
nsAutoRules(nsEditor *ed, PRInt32 action, nsIEditor::EDirection aDirection) :
|
2000-08-14 06:39:37 +04: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 11:30:19 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
2000-08-14 06:39:37 +04:00
|
|
|
PRBool mDoNothing;
|
1999-12-07 11:30:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-01-04 06:09:41 +03: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;
|
|
|
|
};
|
|
|
|
|
2000-08-26 08:03:50 +04: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 MakeList(nsBoolDomIterFunctor& functor,
|
|
|
|
nsCOMPtr<nsISupportsArray> *outArrayOfNodes) const;
|
|
|
|
nsresult AppendList(nsBoolDomIterFunctor& functor,
|
|
|
|
nsCOMPtr<nsISupportsArray> arrayOfNodes) const;
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIContentIterator> mIter;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMSubtreeIterator : public nsDOMIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDOMSubtreeIterator();
|
|
|
|
virtual ~nsDOMSubtreeIterator();
|
|
|
|
|
|
|
|
nsresult Init(nsIDOMRange* aRange);
|
|
|
|
nsresult Init(nsIDOMNode* aNode);
|
|
|
|
};
|
2000-01-04 06:09:41 +03: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 14:57:30 +04:00
|
|
|
class nsTrivialFunctor : public nsBoolDomIterFunctor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual PRBool operator()(nsIDOMNode* aNode) // used to build list of all nodes iterator covers
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-08-09 05:34:04 +04:00
|
|
|
#endif // nsEditorUtils_h__
|