2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 05:34:04 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef nsEditorUtils_h__
|
|
|
|
#define nsEditorUtils_h__
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsEditor.h"
|
1999-08-09 05:34:04 +04:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIEditor.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nscore.h"
|
1999-12-07 11:30:19 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIAtom;
|
|
|
|
class nsIContentIterator;
|
|
|
|
class nsIDOMDocument;
|
2014-11-02 15:04:13 +03:00
|
|
|
class nsRange;
|
2014-11-02 15:04:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-04-24 14:27:35 +03:00
|
|
|
template <class T> class OwningNonNull;
|
2014-11-02 15:04:13 +03:00
|
|
|
class Selection;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2001-04-06 03:48:01 +04:00
|
|
|
|
2000-01-31 13:30:12 +03:00
|
|
|
/***************************************************************************
|
2015-05-28 18:58:42 +03:00
|
|
|
* stack based helper class for batching a collection of txns inside a
|
2000-01-31 13:30:12 +03:00
|
|
|
* placeholder txn.
|
|
|
|
*/
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoPlaceHolderBatch
|
1999-09-30 00:08:15 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIEditor> mEd;
|
|
|
|
public:
|
2015-05-28 18:58:42 +03:00
|
|
|
nsAutoPlaceHolderBatch( nsIEditor *aEd, nsIAtom *atom) : mEd(do_QueryInterface(aEd))
|
1999-09-30 00:08:15 +04:00
|
|
|
{ if (mEd) mEd->BeginPlaceHolderTransaction(atom); }
|
|
|
|
~nsAutoPlaceHolderBatch() { if (mEd) mEd->EndPlaceHolderTransaction(); }
|
|
|
|
};
|
|
|
|
|
2000-01-31 13:30:12 +03:00
|
|
|
/***************************************************************************
|
2015-05-28 18:58:42 +03:00
|
|
|
* stack based helper class for batching a collection of txns.
|
2000-01-31 13:30:12 +03:00
|
|
|
* Note: I changed this to use placeholder batching so that we get
|
|
|
|
* proper selection save/restore across undo/redo.
|
|
|
|
*/
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoEditBatch : public nsAutoPlaceHolderBatch
|
2000-01-31 13:30:12 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:33:43 +04:00
|
|
|
explicit nsAutoEditBatch( nsIEditor *aEd) : nsAutoPlaceHolderBatch(aEd,nullptr) {}
|
2000-01-31 13:30:12 +03:00
|
|
|
~nsAutoEditBatch() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for saving/restoring selection. Note that this
|
|
|
|
* assumes that the nodes involved are still around afterwards!
|
|
|
|
*/
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoSelectionReset
|
1999-08-09 05:34:04 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
/** ref-counted reference to the selection that we are supposed to restore */
|
2014-04-10 20:09:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::Selection> 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 */
|
2014-04-10 20:09:40 +04:00
|
|
|
nsAutoSelectionReset(mozilla::dom::Selection* aSel, nsEditor* aEd);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
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
|
|
|
|
*/
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoRules
|
1999-12-07 11:30:19 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2012-08-12 22:28:26 +04:00
|
|
|
nsAutoRules(nsEditor *ed, EditAction action,
|
2012-05-05 22:52:29 +04:00
|
|
|
nsIEditor::EDirection aDirection) :
|
2011-10-17 18:59:28 +04:00
|
|
|
mEd(ed), mDoNothing(false)
|
2015-05-28 18:58:42 +03:00
|
|
|
{
|
2000-08-14 06:39:37 +04:00
|
|
|
if (mEd && !mEd->mAction) // mAction will already be set if this is nested call
|
|
|
|
{
|
|
|
|
mEd->StartOperation(action, aDirection);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
else mDoNothing = true; // nested calls will end up here
|
2000-08-14 06:39:37 +04:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
~nsAutoRules()
|
2000-08-14 06:39:37 +04:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
if (mEd && !mDoNothing)
|
2000-08-14 06:39:37 +04:00
|
|
|
{
|
|
|
|
mEd->EndOperation();
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
1999-12-07 11:30:19 +03:00
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool 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
|
|
|
|
*/
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoTxnsConserveSelection
|
2000-01-04 06:09:41 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2014-09-01 07:33:43 +04:00
|
|
|
explicit nsAutoTxnsConserveSelection(nsEditor *ed) : mEd(ed), mOldState(true)
|
2000-01-04 06:09:41 +03:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
if (mEd)
|
2000-01-04 06:09:41 +03:00
|
|
|
{
|
|
|
|
mOldState = mEd->GetShouldTxnSetSelection();
|
2011-10-17 18:59:28 +04:00
|
|
|
mEd->SetShouldTxnSetSelection(false);
|
2000-01-04 06:09:41 +03:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
|
|
|
~nsAutoTxnsConserveSelection()
|
2000-01-04 06:09:41 +03:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
if (mEd)
|
2000-01-04 06:09:41 +03:00
|
|
|
{
|
|
|
|
mEd->SetShouldTxnSetSelection(mOldState);
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2000-01-04 06:09:41 +03:00
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOldState;
|
2000-01-04 06:09:41 +03:00
|
|
|
};
|
|
|
|
|
2001-05-11 17:59:11 +04:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching reflow and paint requests.
|
|
|
|
*/
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoUpdateViewBatch
|
2001-05-11 17:59:11 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2014-09-01 07:33:43 +04:00
|
|
|
explicit nsAutoUpdateViewBatch(nsEditor *ed) : mEd(ed)
|
2001-05-11 17:59:11 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mEd, "null mEd pointer!");
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
if (mEd)
|
2001-05-11 17:59:11 +04:00
|
|
|
mEd->BeginUpdateViewBatch();
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
|
|
|
~nsAutoUpdateViewBatch()
|
2001-05-11 17:59:11 +04:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
if (mEd)
|
2001-05-11 17:59:11 +04:00
|
|
|
mEd->EndUpdateViewBatch();
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2001-05-11 17:59:11 +04:00
|
|
|
protected:
|
|
|
|
nsEditor *mEd;
|
|
|
|
};
|
|
|
|
|
2000-08-26 08:03:50 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* some helper classes for iterating the dom tree
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
class nsBoolDomIterFunctor
|
2000-08-26 08:03:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-04-24 14:27:36 +03:00
|
|
|
virtual bool operator()(nsINode* aNode) const = 0;
|
2000-08-26 08:03:50 +04:00
|
|
|
};
|
|
|
|
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsDOMIterator
|
2000-08-26 08:03:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-05-22 16:58:30 +03:00
|
|
|
nsDOMIterator();
|
|
|
|
|
2015-04-24 14:27:35 +03:00
|
|
|
explicit nsDOMIterator(nsINode& aNode);
|
2000-08-26 08:03:50 +04:00
|
|
|
virtual ~nsDOMIterator();
|
2015-04-24 14:27:34 +03:00
|
|
|
|
2015-05-22 16:58:30 +03:00
|
|
|
nsresult Init(nsRange& aRange);
|
|
|
|
|
2015-04-24 14:27:35 +03:00
|
|
|
void AppendList(const nsBoolDomIterFunctor& functor,
|
|
|
|
nsTArray<mozilla::dom::OwningNonNull<nsINode>>& arrayOfNodes) const;
|
2000-08-26 08:03:50 +04:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIContentIterator> mIter;
|
|
|
|
};
|
|
|
|
|
2013-04-12 07:20:27 +04:00
|
|
|
class MOZ_STACK_CLASS nsDOMSubtreeIterator : public nsDOMIterator
|
2000-08-26 08:03:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-05-22 16:58:30 +03:00
|
|
|
nsDOMSubtreeIterator();
|
2000-08-26 08:03:50 +04:00
|
|
|
virtual ~nsDOMSubtreeIterator();
|
2015-05-22 16:58:30 +03:00
|
|
|
|
|
|
|
nsresult Init(nsRange& aRange);
|
2000-08-26 08:03:50 +04:00
|
|
|
};
|
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:
|
2015-04-24 14:27:34 +03:00
|
|
|
// Used to build list of all nodes iterator covers
|
2015-04-24 14:27:36 +03:00
|
|
|
virtual bool operator()(nsINode* aNode) const
|
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
|
|
|
{
|
2011-10-17 18:59:28 +04: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 14:57:30 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-08-29 11:49:31 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* general dom point utility struct
|
|
|
|
*****************************************************************************/
|
2013-04-12 07:20:27 +04:00
|
|
|
struct MOZ_STACK_CLASS DOMPoint
|
2002-08-29 11:49:31 +04:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
nsCOMPtr<nsINode> node;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t offset;
|
2014-11-02 15:04:13 +03:00
|
|
|
|
|
|
|
DOMPoint() : node(nullptr), offset(-1) {}
|
2014-04-28 19:34:05 +04:00
|
|
|
DOMPoint(nsINode* aNode, int32_t aOffset)
|
|
|
|
: node(aNode)
|
|
|
|
, offset(aOffset)
|
|
|
|
{}
|
|
|
|
DOMPoint(nsIDOMNode* aNode, int32_t aOffset)
|
|
|
|
: node(do_QueryInterface(aNode))
|
|
|
|
, offset(aOffset)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void SetPoint(nsINode* aNode, int32_t aOffset)
|
2002-08-29 11:49:31 +04:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
node = aNode;
|
|
|
|
offset = aOffset;
|
2002-08-29 11:49:31 +04:00
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
void SetPoint(nsIDOMNode* aNode, int32_t aOffset)
|
2002-08-29 11:49:31 +04:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
node = do_QueryInterface(aNode);
|
|
|
|
offset = aOffset;
|
2002-08-29 11:49:31 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-12-22 04:51:14 +03:00
|
|
|
class nsEditorUtils
|
|
|
|
{
|
|
|
|
public:
|
2014-04-28 19:34:05 +04:00
|
|
|
static bool IsDescendantOf(nsINode* aNode, nsINode* aParent, int32_t* aOffset = 0);
|
2012-08-22 19:56:38 +04:00
|
|
|
static bool IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t *aOffset = 0);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsLeafNode(nsIDOMNode *aNode);
|
2002-12-22 04:51:14 +03:00
|
|
|
};
|
|
|
|
|
2003-04-26 01:05:32 +04:00
|
|
|
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsISimpleEnumerator;
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsITransferable;
|
2003-04-26 01:05:32 +04:00
|
|
|
|
|
|
|
class nsEditorHookUtils
|
|
|
|
{
|
|
|
|
public:
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aEvent,
|
2003-04-26 01:05:32 +04:00
|
|
|
nsITransferable *aTrans);
|
|
|
|
private:
|
|
|
|
static nsresult GetHookEnumeratorFromDocument(nsIDOMDocument *aDoc,
|
|
|
|
nsISimpleEnumerator **aEnumerator);
|
|
|
|
};
|
|
|
|
|
1999-08-09 05:34:04 +04:00
|
|
|
#endif // nsEditorUtils_h__
|