--- a/editor/libeditor/DeleteNodeTransaction.cpp
+++ b/editor/libeditor/DeleteNodeTransaction.cpp
@@ -1,15 +1,15 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "DeleteNodeTransaction.h"
-#include "SelectionState.h" // nsRangeUpdater
+#include "SelectionState.h" // RangeUpdater
#include "nsDebug.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsAString.h"
namespace mozilla {
DeleteNodeTransaction::DeleteNodeTransaction()
@@ -30,17 +30,17 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Delet
NS_IMPL_ADDREF_INHERITED(DeleteNodeTransaction, EditTransactionBase)
NS_IMPL_RELEASE_INHERITED(DeleteNodeTransaction, EditTransactionBase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteNodeTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
nsresult
DeleteNodeTransaction::Init(nsEditor* aEditor,
nsINode* aNode,
- nsRangeUpdater* aRangeUpdater)
+ RangeUpdater* aRangeUpdater)
{
NS_ENSURE_TRUE(aEditor && aNode, NS_ERROR_NULL_POINTER);
mEditor = aEditor;
mNode = aNode;
mParent = aNode->GetParentNode();
// do nothing if the node has a parent and it's read-only
NS_ENSURE_TRUE(!mParent || mEditor->IsModifiableNode(mParent),
--- a/editor/libeditor/DeleteNodeTransaction.h
+++ b/editor/libeditor/DeleteNodeTransaction.h
@@ -10,32 +10,33 @@
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContent.h"
#include "nsINode.h"
#include "nsISupportsImpl.h"
#include "nscore.h"
class nsEditor;
-class nsRangeUpdater;
namespace mozilla {
+class RangeUpdater;
+
/**
* A transaction that deletes a single element
*/
class DeleteNodeTransaction final : public EditTransactionBase
{
public:
/**
* Initialize the transaction.
* @param aElement The node to delete.
*/
nsresult Init(nsEditor* aEditor, nsINode* aNode,
- nsRangeUpdater* aRangeUpdater);
+ RangeUpdater* aRangeUpdater);
DeleteNodeTransaction();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction,
EditTransactionBase)
NS_DECL_EDITTRANSACTIONBASE
@@ -53,14 +54,14 @@ protected:
// Next sibling to remember for undo/redo purposes.
nsCOMPtr<nsIContent> mRefNode;
// The editor for this transaction.
nsEditor* mEditor;
// Range updater object.
- nsRangeUpdater* mRangeUpdater;
+ RangeUpdater* mRangeUpdater;
};
} // namespace mozilla
#endif // #ifndef DeleteNodeTransaction_h
--- a/editor/libeditor/DeleteRangeTransaction.cpp
+++ b/editor/libeditor/DeleteRangeTransaction.cpp
@@ -36,17 +36,17 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Delet
mRange)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteRangeTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
nsresult
DeleteRangeTransaction::Init(nsEditor* aEditor,
nsRange* aRange,
- nsRangeUpdater* aRangeUpdater)
+ RangeUpdater* aRangeUpdater)
{
MOZ_ASSERT(aEditor && aRange);
mEditor = aEditor;
mRange = aRange->CloneRange();
mRangeUpdater = aRangeUpdater;
NS_ENSURE_TRUE(mEditor->IsModifiableNode(mRange->GetStartParent()),
--- a/editor/libeditor/DeleteRangeTransaction.h
+++ b/editor/libeditor/DeleteRangeTransaction.h
@@ -11,34 +11,35 @@
#include "nsID.h"
#include "nsIEditor.h"
#include "nsISupportsImpl.h"
#include "nsRange.h"
#include "nscore.h"
class nsEditor;
class nsINode;
-class nsRangeUpdater;
namespace mozilla {
+class RangeUpdater;
+
/**
* A transaction that deletes an entire range in the content tree
*/
class DeleteRangeTransaction final : public EditAggregateTransaction
{
public:
/**
* Initialize the transaction.
* @param aEditor The object providing basic editing operations.
* @param aRange The range to delete.
*/
nsresult Init(nsEditor* aEditor,
nsRange* aRange,
- nsRangeUpdater* aRangeUpdater);
+ RangeUpdater* aRangeUpdater);
DeleteRangeTransaction();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteRangeTransaction,
EditAggregateTransaction)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
NS_DECL_EDITTRANSACTIONBASE
@@ -64,14 +65,14 @@ protected:
// P1 in the range.
RefPtr<nsRange> mRange;
// The editor for this transaction.
nsEditor* mEditor;
// Range updater object.
- nsRangeUpdater* mRangeUpdater;
+ RangeUpdater* mRangeUpdater;
};
} // namespace mozilla
#endif // #ifndef DeleteRangeTransaction_h
--- a/editor/libeditor/DeleteTextTransaction.cpp
+++ b/editor/libeditor/DeleteTextTransaction.cpp
@@ -18,17 +18,17 @@ namespace mozilla {
using namespace dom;
DeleteTextTransaction::DeleteTextTransaction(
nsEditor& aEditor,
nsGenericDOMDataNode& aCharData,
uint32_t aOffset,
uint32_t aNumCharsToDelete,
- nsRangeUpdater* aRangeUpdater)
+ RangeUpdater* aRangeUpdater)
: mEditor(aEditor)
, mCharData(&aCharData)
, mOffset(aOffset)
, mNumCharsToDelete(aNumCharsToDelete)
, mRangeUpdater(aRangeUpdater)
{
NS_ASSERTION(mCharData->Length() >= aOffset + aNumCharsToDelete,
"Trying to delete more characters than in node");
--- a/editor/libeditor/DeleteTextTransaction.h
+++ b/editor/libeditor/DeleteTextTransaction.h
@@ -10,20 +10,21 @@
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsGenericDOMDataNode.h"
#include "nsID.h"
#include "nsString.h"
#include "nscore.h"
class nsEditor;
-class nsRangeUpdater;
namespace mozilla {
+class RangeUpdater;
+
/**
* A transaction that removes text from a content node.
*/
class DeleteTextTransaction final : public EditTransactionBase
{
public:
/**
* Initialize the transaction.
@@ -32,17 +33,17 @@ public:
* @param aOffset The location in aElement to begin the deletion.
* @param aNumCharsToDelete The number of characters to delete. Not the
* number of bytes!
*/
DeleteTextTransaction(nsEditor& aEditor,
nsGenericDOMDataNode& aCharData,
uint32_t aOffset,
uint32_t aNumCharsToDelete,
- nsRangeUpdater* aRangeUpdater);
+ RangeUpdater* aRangeUpdater);
nsresult Init();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction,
EditTransactionBase)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
NS_DECL_EDITTRANSACTIONBASE
@@ -63,14 +64,14 @@ protected:
// The number of characters to delete.
uint32_t mNumCharsToDelete;
// The text that was deleted.
nsString mDeletedText;
// Range updater object.
- nsRangeUpdater* mRangeUpdater;
+ RangeUpdater* mRangeUpdater;
};
} // namespace mozilla
#endif // #ifndef DeleteTextTransaction_h
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -132,83 +132,84 @@ SelectionState::MakeEmpty()
}
bool
SelectionState::IsEmpty()
{
return mArray.IsEmpty();
}
-} // namespace mozilla
-
-using namespace mozilla;
-using namespace mozilla::dom;
+/******************************************************************************
+ * mozilla::RangeUpdater
+ *
+ * Class for updating nsRanges in response to editor actions.
+ ******************************************************************************/
-/***************************************************************************
- * nsRangeUpdater: class for updating nsRanges in response to editor actions.
- */
+RangeUpdater::RangeUpdater()
+ : mLock(false)
+{
+}
-nsRangeUpdater::nsRangeUpdater() : mArray(), mLock(false) {}
-
-nsRangeUpdater::~nsRangeUpdater()
+RangeUpdater::~RangeUpdater()
{
// nothing to do, we don't own the items in our array.
}
void
-nsRangeUpdater::RegisterRangeItem(RangeItem* aRangeItem)
+RangeUpdater::RegisterRangeItem(RangeItem* aRangeItem)
{
if (!aRangeItem) return;
if (mArray.Contains(aRangeItem))
{
NS_ERROR("tried to register an already registered range");
return; // don't register it again. It would get doubly adjusted.
}
mArray.AppendElement(aRangeItem);
}
void
-nsRangeUpdater::DropRangeItem(RangeItem* aRangeItem)
+RangeUpdater::DropRangeItem(RangeItem* aRangeItem)
{
if (!aRangeItem) return;
mArray.RemoveElement(aRangeItem);
}
nsresult
-nsRangeUpdater::RegisterSelectionState(SelectionState& aSelState)
+RangeUpdater::RegisterSelectionState(SelectionState& aSelState)
{
uint32_t i, theCount = aSelState.mArray.Length();
if (theCount < 1) return NS_ERROR_FAILURE;
for (i=0; i<theCount; i++)
{
RegisterRangeItem(aSelState.mArray[i]);
}
return NS_OK;
}
nsresult
-nsRangeUpdater::DropSelectionState(SelectionState& aSelState)
+RangeUpdater::DropSelectionState(SelectionState& aSelState)
{
uint32_t i, theCount = aSelState.mArray.Length();
if (theCount < 1) return NS_ERROR_FAILURE;
for (i=0; i<theCount; i++)
{
DropRangeItem(aSelState.mArray[i]);
}
return NS_OK;
}
// gravity methods:
nsresult
-nsRangeUpdater::SelAdjCreateNode(nsINode* aParent, int32_t aPosition)
+RangeUpdater::SelAdjCreateNode(nsINode* aParent,
+ int32_t aPosition)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
return NS_OK;
}
NS_ENSURE_TRUE(aParent, NS_ERROR_NULL_POINTER);
uint32_t count = mArray.Length();
if (!count) {
@@ -225,36 +226,39 @@ nsRangeUpdater::SelAdjCreateNode(nsINode
if (item->endNode == aParent && item->endOffset > aPosition) {
item->endOffset++;
}
}
return NS_OK;
}
nsresult
-nsRangeUpdater::SelAdjCreateNode(nsIDOMNode* aParent, int32_t aPosition)
+RangeUpdater::SelAdjCreateNode(nsIDOMNode* aParent,
+ int32_t aPosition)
{
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
return SelAdjCreateNode(parent, aPosition);
}
nsresult
-nsRangeUpdater::SelAdjInsertNode(nsINode* aParent, int32_t aPosition)
+RangeUpdater::SelAdjInsertNode(nsINode* aParent,
+ int32_t aPosition)
{
return SelAdjCreateNode(aParent, aPosition);
}
nsresult
-nsRangeUpdater::SelAdjInsertNode(nsIDOMNode *aParent, int32_t aPosition)
+RangeUpdater::SelAdjInsertNode(nsIDOMNode* aParent,
+ int32_t aPosition)
{
return SelAdjCreateNode(aParent, aPosition);
}
void
-nsRangeUpdater::SelAdjDeleteNode(nsINode* aNode)
+RangeUpdater::SelAdjDeleteNode(nsINode* aNode)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
return;
}
MOZ_ASSERT(aNode);
uint32_t count = mArray.Length();
if (!count) {
@@ -300,27 +304,27 @@ nsRangeUpdater::SelAdjDeleteNode(nsINode
{
item->endNode = parent;
item->endOffset = offset;
}
}
}
void
-nsRangeUpdater::SelAdjDeleteNode(nsIDOMNode *aNode)
+RangeUpdater::SelAdjDeleteNode(nsIDOMNode* aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node, );
return SelAdjDeleteNode(node);
}
-
nsresult
-nsRangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode, int32_t aOffset,
- nsIContent* aNewLeftNode)
+RangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode,
+ int32_t aOffset,
+ nsIContent* aNewLeftNode)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
return NS_OK;
}
NS_ENSURE_TRUE(aNewLeftNode, NS_ERROR_NULL_POINTER);
uint32_t count = mArray.Length();
if (!count) {
@@ -353,21 +357,21 @@ nsRangeUpdater::SelAdjSplitNode(nsIConte
item->endNode = aNewLeftNode;
}
}
}
return NS_OK;
}
nsresult
-nsRangeUpdater::SelAdjJoinNodes(nsINode& aLeftNode,
- nsINode& aRightNode,
- nsINode& aParent,
- int32_t aOffset,
- int32_t aOldLeftNodeLength)
+RangeUpdater::SelAdjJoinNodes(nsINode& aLeftNode,
+ nsINode& aRightNode,
+ nsINode& aParent,
+ int32_t aOffset,
+ int32_t aOldLeftNodeLength)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
return NS_OK;
}
uint32_t count = mArray.Length();
if (!count) {
return NS_OK;
@@ -410,20 +414,20 @@ nsRangeUpdater::SelAdjJoinNodes(nsINode&
// adjust end point in aLeftNode
item->endNode = &aRightNode;
}
}
return NS_OK;
}
-
void
-nsRangeUpdater::SelAdjInsertText(Text& aTextNode, int32_t aOffset,
- const nsAString& aString)
+RangeUpdater::SelAdjInsertText(Text& aTextNode,
+ int32_t aOffset,
+ const nsAString& aString)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
return;
}
uint32_t count = mArray.Length();
if (!count) {
@@ -441,18 +445,19 @@ nsRangeUpdater::SelAdjInsertText(Text& a
if (item->endNode == &aTextNode && item->endOffset > aOffset) {
item->endOffset += len;
}
}
return;
}
nsresult
-nsRangeUpdater::SelAdjDeleteText(nsIContent* aTextNode, int32_t aOffset,
- int32_t aLength)
+RangeUpdater::SelAdjDeleteText(nsIContent* aTextNode,
+ int32_t aOffset,
+ int32_t aLength)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
return NS_OK;
}
uint32_t count = mArray.Length();
if (!count) {
@@ -476,35 +481,35 @@ nsRangeUpdater::SelAdjDeleteText(nsICont
item->endOffset = 0;
}
}
}
return NS_OK;
}
nsresult
-nsRangeUpdater::SelAdjDeleteText(nsIDOMCharacterData* aTextNode,
- int32_t aOffset, int32_t aLength)
+RangeUpdater::SelAdjDeleteText(nsIDOMCharacterData* aTextNode,
+ int32_t aOffset,
+ int32_t aLength)
{
nsCOMPtr<nsIContent> textNode = do_QueryInterface(aTextNode);
return SelAdjDeleteText(textNode, aOffset, aLength);
}
-
nsresult
-nsRangeUpdater::WillReplaceContainer()
+RangeUpdater::WillReplaceContainer()
{
if (mLock) return NS_ERROR_UNEXPECTED;
mLock = true;
return NS_OK;
}
-
nsresult
-nsRangeUpdater::DidReplaceContainer(Element* aOriginalNode, Element* aNewNode)
+RangeUpdater::DidReplaceContainer(Element* aOriginalNode,
+ Element* aNewNode)
{
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
mLock = false;
NS_ENSURE_TRUE(aOriginalNode && aNewNode, NS_ERROR_NULL_POINTER);
uint32_t count = mArray.Length();
if (!count) {
return NS_OK;
@@ -519,29 +524,29 @@ nsRangeUpdater::DidReplaceContainer(Elem
}
if (item->endNode == aOriginalNode) {
item->endNode = aNewNode;
}
}
return NS_OK;
}
-
nsresult
-nsRangeUpdater::WillRemoveContainer()
+RangeUpdater::WillRemoveContainer()
{
if (mLock) return NS_ERROR_UNEXPECTED;
mLock = true;
return NS_OK;
}
-
nsresult
-nsRangeUpdater::DidRemoveContainer(nsINode* aNode, nsINode* aParent,
- int32_t aOffset, uint32_t aNodeOrigLen)
+RangeUpdater::DidRemoveContainer(nsINode* aNode,
+ nsINode* aParent,
+ int32_t aOffset,
+ uint32_t aNodeOrigLen)
{
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
mLock = false;
NS_ENSURE_TRUE(aNode && aParent, NS_ERROR_NULL_POINTER);
uint32_t count = mArray.Length();
if (!count) {
return NS_OK;
@@ -564,52 +569,50 @@ nsRangeUpdater::DidRemoveContainer(nsINo
} else if (item->endNode == aParent && item->endOffset > aOffset) {
item->endOffset += (int32_t)aNodeOrigLen - 1;
}
}
return NS_OK;
}
nsresult
-nsRangeUpdater::DidRemoveContainer(nsIDOMNode* aNode, nsIDOMNode* aParent,
- int32_t aOffset, uint32_t aNodeOrigLen)
+RangeUpdater::DidRemoveContainer(nsIDOMNode* aNode,
+ nsIDOMNode* aParent,
+ int32_t aOffset,
+ uint32_t aNodeOrigLen)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
return DidRemoveContainer(node, parent, aOffset, aNodeOrigLen);
}
-
nsresult
-nsRangeUpdater::WillInsertContainer()
+RangeUpdater::WillInsertContainer()
{
if (mLock) return NS_ERROR_UNEXPECTED;
mLock = true;
return NS_OK;
}
-
nsresult
-nsRangeUpdater::DidInsertContainer()
+RangeUpdater::DidInsertContainer()
{
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
mLock = false;
return NS_OK;
}
-
void
-nsRangeUpdater::WillMoveNode()
+RangeUpdater::WillMoveNode()
{
mLock = true;
}
-
void
-nsRangeUpdater::DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
+RangeUpdater::DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
nsINode* aNewParent, int32_t aNewOffset)
{
MOZ_ASSERT(aOldParent);
MOZ_ASSERT(aNewParent);
NS_ENSURE_TRUE_VOID(mLock);
mLock = false;
for (uint32_t i = 0, count = mArray.Length(); i < count; ++i) {
@@ -629,18 +632,16 @@ nsRangeUpdater::DidMoveNode(nsINode* aOl
item->startOffset++;
}
if (item->endNode == aNewParent && item->endOffset > aNewOffset) {
item->endOffset++;
}
}
}
-namespace mozilla {
-
/******************************************************************************
* mozilla::RangeItem
*
* Helper struct for SelectionState. This stores range endpoints.
******************************************************************************/
RangeItem::RangeItem()
{
--- a/editor/libeditor/SelectionState.h
+++ b/editor/libeditor/SelectionState.h
@@ -10,18 +10,18 @@
#include "nsIDOMNode.h"
#include "nsINode.h"
#include "nsTArray.h"
#include "nscore.h"
class nsCycleCollectionTraversalCallback;
class nsIDOMCharacterData;
class nsRange;
-class nsRangeUpdater;
namespace mozilla {
+class RangeUpdater;
namespace dom {
class Selection;
class Text;
} // namespace dom
/**
* A helper struct for saving/setting ranges.
*/
@@ -64,17 +64,17 @@ public:
nsresult RestoreSelection(dom::Selection* aSel);
bool IsCollapsed();
bool IsEqual(SelectionState *aSelState);
void MakeEmpty();
bool IsEmpty();
private:
nsTArray<RefPtr<RangeItem>> mArray;
- friend class nsRangeUpdater;
+ friend class RangeUpdater;
friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
SelectionState&,
const char*,
uint32_t);
friend void ImplCycleCollectionUnlink(SelectionState&);
};
inline void
@@ -87,124 +87,127 @@ ImplCycleCollectionTraverse(nsCycleColle
}
inline void
ImplCycleCollectionUnlink(SelectionState& aField)
{
ImplCycleCollectionUnlink(aField.mArray);
}
-} // namespace mozilla
-
-class nsRangeUpdater
+class RangeUpdater final
{
- public:
+public:
+ RangeUpdater();
+ ~RangeUpdater();
- nsRangeUpdater();
- ~nsRangeUpdater();
-
- void RegisterRangeItem(mozilla::RangeItem* aRangeItem);
- void DropRangeItem(mozilla::RangeItem* aRangeItem);
- nsresult RegisterSelectionState(mozilla::SelectionState& aSelState);
- nsresult DropSelectionState(mozilla::SelectionState& aSelState);
+ void RegisterRangeItem(RangeItem* aRangeItem);
+ void DropRangeItem(RangeItem* aRangeItem);
+ nsresult RegisterSelectionState(SelectionState& aSelState);
+ nsresult DropSelectionState(SelectionState& aSelState);
- // editor selection gravity routines. Note that we can't always depend on
- // DOM Range gravity to do what we want to the "real" selection. For instance,
- // if you move a node, that corresponds to deleting it and reinserting it.
- // DOM Range gravity will promote the selection out of the node on deletion,
- // which is not what you want if you know you are reinserting it.
- nsresult SelAdjCreateNode(nsINode* aParent, int32_t aPosition);
- nsresult SelAdjCreateNode(nsIDOMNode *aParent, int32_t aPosition);
- nsresult SelAdjInsertNode(nsINode* aParent, int32_t aPosition);
- nsresult SelAdjInsertNode(nsIDOMNode *aParent, int32_t aPosition);
- void SelAdjDeleteNode(nsINode* aNode);
- void SelAdjDeleteNode(nsIDOMNode *aNode);
- nsresult SelAdjSplitNode(nsIContent& aOldRightNode, int32_t aOffset,
- nsIContent* aNewLeftNode);
- nsresult SelAdjJoinNodes(nsINode& aLeftNode,
- nsINode& aRightNode,
- nsINode& aParent,
- int32_t aOffset,
- int32_t aOldLeftNodeLength);
- void SelAdjInsertText(mozilla::dom::Text& aTextNode, int32_t aOffset,
- const nsAString &aString);
- nsresult SelAdjDeleteText(nsIContent* aTextNode, int32_t aOffset,
- int32_t aLength);
- nsresult SelAdjDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength);
- // the following gravity routines need will/did sandwiches, because the other gravity
- // routines will be called inside of these sandwiches, but should be ignored.
- nsresult WillReplaceContainer();
- nsresult DidReplaceContainer(mozilla::dom::Element* aOriginalNode,
- mozilla::dom::Element* aNewNode);
- nsresult WillRemoveContainer();
- nsresult DidRemoveContainer(nsINode* aNode, nsINode* aParent,
- int32_t aOffset, uint32_t aNodeOrigLen);
- nsresult DidRemoveContainer(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aOffset, uint32_t aNodeOrigLen);
- nsresult WillInsertContainer();
- nsresult DidInsertContainer();
- void WillMoveNode();
- void DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
- nsINode* aNewParent, int32_t aNewOffset);
- private:
- friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
- nsRangeUpdater&,
- const char*,
- uint32_t);
- friend void ImplCycleCollectionUnlink(nsRangeUpdater& aField);
+ // editor selection gravity routines. Note that we can't always depend on
+ // DOM Range gravity to do what we want to the "real" selection. For instance,
+ // if you move a node, that corresponds to deleting it and reinserting it.
+ // DOM Range gravity will promote the selection out of the node on deletion,
+ // which is not what you want if you know you are reinserting it.
+ nsresult SelAdjCreateNode(nsINode* aParent, int32_t aPosition);
+ nsresult SelAdjCreateNode(nsIDOMNode* aParent, int32_t aPosition);
+ nsresult SelAdjInsertNode(nsINode* aParent, int32_t aPosition);
+ nsresult SelAdjInsertNode(nsIDOMNode* aParent, int32_t aPosition);
+ void SelAdjDeleteNode(nsINode* aNode);
+ void SelAdjDeleteNode(nsIDOMNode* aNode);
+ nsresult SelAdjSplitNode(nsIContent& aOldRightNode, int32_t aOffset,
+ nsIContent* aNewLeftNode);
+ nsresult SelAdjJoinNodes(nsINode& aLeftNode,
+ nsINode& aRightNode,
+ nsINode& aParent,
+ int32_t aOffset,
+ int32_t aOldLeftNodeLength);
+ void SelAdjInsertText(dom::Text& aTextNode, int32_t aOffset,
+ const nsAString &aString);
+ nsresult SelAdjDeleteText(nsIContent* aTextNode, int32_t aOffset,
+ int32_t aLength);
+ nsresult SelAdjDeleteText(nsIDOMCharacterData* aTextNode,
+ int32_t aOffset, int32_t aLength);
+ // the following gravity routines need will/did sandwiches, because the other
+ // gravity routines will be called inside of these sandwiches, but should be
+ // ignored.
+ nsresult WillReplaceContainer();
+ nsresult DidReplaceContainer(dom::Element* aOriginalNode,
+ dom::Element* aNewNode);
+ nsresult WillRemoveContainer();
+ nsresult DidRemoveContainer(nsINode* aNode, nsINode* aParent,
+ int32_t aOffset, uint32_t aNodeOrigLen);
+ nsresult DidRemoveContainer(nsIDOMNode* aNode, nsIDOMNode* aParent,
+ int32_t aOffset, uint32_t aNodeOrigLen);
+ nsresult WillInsertContainer();
+ nsresult DidInsertContainer();
+ void WillMoveNode();
+ void DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
+ nsINode* aNewParent, int32_t aNewOffset);
- nsTArray<RefPtr<mozilla::RangeItem>> mArray;
- bool mLock;
+private:
+ friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
+ RangeUpdater&,
+ const char*,
+ uint32_t);
+ friend void ImplCycleCollectionUnlink(RangeUpdater& aField);
+
+ nsTArray<RefPtr<RangeItem>> mArray;
+ bool mLock;
};
inline void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
- nsRangeUpdater& aField,
+ RangeUpdater& aField,
const char* aName,
uint32_t aFlags = 0)
{
ImplCycleCollectionTraverse(aCallback, aField.mArray, aName, aFlags);
}
inline void
-ImplCycleCollectionUnlink(nsRangeUpdater& aField)
+ImplCycleCollectionUnlink(RangeUpdater& aField)
{
ImplCycleCollectionUnlink(aField.mArray);
}
+} // namespace mozilla
+
/***************************************************************************
* helper class for using SelectionState. stack based class for doing
* preservation of dom points across editor actions
*/
class MOZ_STACK_CLASS nsAutoTrackDOMPoint
{
private:
- nsRangeUpdater &mRU;
+ mozilla::RangeUpdater& mRU;
// Allow tracking either nsIDOMNode or nsINode until nsIDOMNode is gone
nsCOMPtr<nsINode>* mNode;
nsCOMPtr<nsIDOMNode>* mDOMNode;
int32_t* mOffset;
RefPtr<mozilla::RangeItem> mRangeItem;
public:
- nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater,
+ nsAutoTrackDOMPoint(mozilla::RangeUpdater& aRangeUpdater,
nsCOMPtr<nsINode>* aNode, int32_t* aOffset)
: mRU(aRangeUpdater)
, mNode(aNode)
, mDOMNode(nullptr)
, mOffset(aOffset)
{
mRangeItem = new mozilla::RangeItem();
mRangeItem->startNode = *mNode;
mRangeItem->endNode = *mNode;
mRangeItem->startOffset = *mOffset;
mRangeItem->endOffset = *mOffset;
mRU.RegisterRangeItem(mRangeItem);
}
- nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater,
+ nsAutoTrackDOMPoint(mozilla::RangeUpdater& aRangeUpdater,
nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset)
: mRU(aRangeUpdater)
, mNode(nullptr)
, mDOMNode(aNode)
, mOffset(aOffset)
{
mRangeItem = new mozilla::RangeItem();
mRangeItem->startNode = do_QueryInterface(*mDOMNode);
@@ -233,22 +236,22 @@ class MOZ_STACK_CLASS nsAutoTrackDOMPoin
* Will/DidReplaceContainer()
*/
namespace mozilla {
namespace dom {
class MOZ_STACK_CLASS AutoReplaceContainerSelNotify
{
private:
- nsRangeUpdater &mRU;
+ RangeUpdater& mRU;
Element* mOriginalElement;
Element* mNewElement;
public:
- AutoReplaceContainerSelNotify(nsRangeUpdater& aRangeUpdater,
+ AutoReplaceContainerSelNotify(RangeUpdater& aRangeUpdater,
Element* aOriginalElement,
Element* aNewElement)
: mRU(aRangeUpdater)
, mOriginalElement(aOriginalElement)
, mNewElement(aNewElement)
{
mRU.WillReplaceContainer();
}
@@ -266,24 +269,24 @@ class MOZ_STACK_CLASS AutoReplaceContain
/***************************************************************************
* another helper class for SelectionState. stack based class for doing
* Will/DidRemoveContainer()
*/
class MOZ_STACK_CLASS nsAutoRemoveContainerSelNotify
{
private:
- nsRangeUpdater &mRU;
+ mozilla::RangeUpdater& mRU;
nsIDOMNode *mNode;
nsIDOMNode *mParent;
int32_t mOffset;
uint32_t mNodeOrigLen;
public:
- nsAutoRemoveContainerSelNotify(nsRangeUpdater& aRangeUpdater,
+ nsAutoRemoveContainerSelNotify(mozilla::RangeUpdater& aRangeUpdater,
nsINode* aNode,
nsINode* aParent,
int32_t aOffset,
uint32_t aNodeOrigLen)
: mRU(aRangeUpdater)
, mNode(aNode->AsDOMNode())
, mParent(aParent->AsDOMNode())
, mOffset(aOffset)
@@ -301,20 +304,21 @@ class MOZ_STACK_CLASS nsAutoRemoveContai
/***************************************************************************
* another helper class for SelectionState. stack based class for doing
* Will/DidInsertContainer()
*/
class MOZ_STACK_CLASS nsAutoInsertContainerSelNotify
{
private:
- nsRangeUpdater &mRU;
+ mozilla::RangeUpdater& mRU;
public:
- explicit nsAutoInsertContainerSelNotify(nsRangeUpdater &aRangeUpdater) :
+ explicit nsAutoInsertContainerSelNotify(
+ mozilla::RangeUpdater& aRangeUpdater) :
mRU(aRangeUpdater)
{
mRU.WillInsertContainer();
}
~nsAutoInsertContainerSelNotify()
{
mRU.DidInsertContainer();
@@ -325,24 +329,24 @@ class MOZ_STACK_CLASS nsAutoInsertContai
/***************************************************************************
* another helper class for SelectionState. stack based class for doing
* Will/DidMoveNode()
*/
class MOZ_STACK_CLASS nsAutoMoveNodeSelNotify
{
private:
- nsRangeUpdater &mRU;
+ mozilla::RangeUpdater& mRU;
nsINode* mOldParent;
nsINode* mNewParent;
int32_t mOldOffset;
int32_t mNewOffset;
public:
- nsAutoMoveNodeSelNotify(nsRangeUpdater &aRangeUpdater,
+ nsAutoMoveNodeSelNotify(mozilla::RangeUpdater& aRangeUpdater,
nsINode* aOldParent,
int32_t aOldOffset,
nsINode* aNewParent,
int32_t aNewOffset)
: mRU(aRangeUpdater)
, mOldParent(aOldParent)
, mNewParent(aNewParent)
, mOldOffset(aOldOffset)
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -1,17 +1,17 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef __editor_h__
#define __editor_h__
-#include "SelectionState.h" // for nsRangeUpdater, etc
+#include "SelectionState.h" // for RangeUpdater, etc
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
#include "mozilla/OwningNonNull.h" // for OwningNonNull
#include "mozilla/StyleSheetHandle.h" // for StyleSheetHandle
#include "mozilla/dom/Text.h"
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsGkAtoms.h"
#include "nsIEditor.h" // for nsIEditor::EDirection, etc
@@ -862,17 +862,18 @@ protected:
nsTArray<OwningNonNull<nsIEditActionListener>> mActionListeners;
// Just notify once per high level change
nsTArray<OwningNonNull<nsIEditorObserver>> mEditorObservers;
// Listen to overall doc state (dirty or not, just created, etc)
nsTArray<OwningNonNull<nsIDocumentStateListener>> mDocStateListeners;
// Cached selection for AutoSelectionRestorer.
mozilla::SelectionState mSavedSel;
- nsRangeUpdater mRangeUpdater; // utility class object for maintaining preserved ranges
+ // Utility class object for maintaining preserved ranges.
+ mozilla::RangeUpdater mRangeUpdater;
uint32_t mModCount; // number of modifications (for undo/redo stack)
uint32_t mFlags; // behavior flags. See nsIPlaintextEditor.idl for the flags we use.
int32_t mUpdateCount;
int32_t mPlaceHolderBatch; // nesting count for batching
EditAction mAction; // the current editor action
@@ -892,13 +893,13 @@ protected:
bool mDispatchInputEvent;
bool mIsInEditAction; // true while the instance is handling an edit action
bool mHidingCaret; // whether caret is hidden forcibly.
friend bool NSCanUnload(nsISupports* serviceMgr);
friend class mozilla::AutoRules;
friend class mozilla::AutoSelectionRestorer;
friend class mozilla::AutoTransactionsConserveSelection;
- friend class nsRangeUpdater;
+ friend class mozilla::RangeUpdater;
};
#endif