Bug 1260651 part.22 Rename mozilla::dom::DeleteTextTxn to mozilla::DeleteTextTransaction (and their files too) r=mccr8
MozReview-Commit-ID: 6WNiA7N3a9Y
--- a/editor/libeditor/DeleteRangeTransaction.cpp
+++ b/editor/libeditor/DeleteRangeTransaction.cpp
@@ -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/. */
#include "DeleteRangeTransaction.h"
#include "DeleteNodeTransaction.h"
-#include "DeleteTextTxn.h"
+#include "DeleteTextTransaction.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/mozalloc.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsIContent.h"
@@ -142,24 +142,24 @@ DeleteRangeTransaction::CreateTxnsToDele
numToDel = 1;
} else {
numToDel = aEndOffset - aStartOffset;
}
RefPtr<nsGenericDOMDataNode> charDataNode =
static_cast<nsGenericDOMDataNode*>(aNode);
- RefPtr<DeleteTextTxn> txn =
- new DeleteTextTxn(*mEditor, *charDataNode, aStartOffset, numToDel,
- mRangeUpdater);
+ RefPtr<DeleteTextTransaction> transaction =
+ new DeleteTextTransaction(*mEditor, *charDataNode, aStartOffset, numToDel,
+ mRangeUpdater);
- nsresult res = txn->Init();
+ nsresult res = transaction->Init();
NS_ENSURE_SUCCESS(res, res);
- AppendChild(txn);
+ AppendChild(transaction);
return NS_OK;
}
nsCOMPtr<nsIContent> child = aNode->GetChildAt(aStartOffset);
NS_ENSURE_STATE(child);
nsresult res = NS_OK;
for (int32_t i = aStartOffset; i < aEndOffset; ++i) {
@@ -191,23 +191,24 @@ DeleteRangeTransaction::CreateTxnsToDele
} else {
start = 0;
numToDelete = aOffset;
}
if (numToDelete) {
RefPtr<nsGenericDOMDataNode> dataNode =
static_cast<nsGenericDOMDataNode*>(aNode);
- RefPtr<DeleteTextTxn> txn = new DeleteTextTxn(*mEditor, *dataNode,
- start, numToDelete, mRangeUpdater);
+ RefPtr<DeleteTextTransaction> transaction =
+ new DeleteTextTransaction(*mEditor, *dataNode, start, numToDelete,
+ mRangeUpdater);
- nsresult res = txn->Init();
+ nsresult res = transaction->Init();
NS_ENSURE_SUCCESS(res, res);
- AppendChild(txn);
+ AppendChild(transaction);
}
}
return NS_OK;
}
nsresult
DeleteRangeTransaction::CreateTxnsToDeleteNodesBetween()
rename from editor/libeditor/DeleteTextTxn.cpp
rename to editor/libeditor/DeleteTextTransaction.cpp
--- a/editor/libeditor/DeleteTextTxn.cpp
+++ b/editor/libeditor/DeleteTextTransaction.cpp
@@ -1,61 +1,63 @@
/* -*- 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 "DeleteTextTxn.h"
+#include "DeleteTextTransaction.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/Selection.h"
#include "nsDebug.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsIEditor.h"
#include "nsISupportsImpl.h"
#include "nsSelectionState.h"
#include "nsAString.h"
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
-DeleteTextTxn::DeleteTextTxn(nsEditor& aEditor,
- nsGenericDOMDataNode& aCharData, uint32_t aOffset,
- uint32_t aNumCharsToDelete,
- nsRangeUpdater* aRangeUpdater)
- : EditTxn()
- , mEditor(aEditor)
+DeleteTextTransaction::DeleteTextTransaction(
+ nsEditor& aEditor,
+ nsGenericDOMDataNode& aCharData,
+ uint32_t aOffset,
+ uint32_t aNumCharsToDelete,
+ nsRangeUpdater* 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");
}
-NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteTextTxn, EditTxn,
+NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteTextTransaction, EditTxn,
mCharData)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteTextTxn)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteTextTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
nsresult
-DeleteTextTxn::Init()
+DeleteTextTransaction::Init()
{
// Do nothing if the node is read-only
if (!mEditor.IsModifiableNode(mCharData)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
-DeleteTextTxn::DoTransaction()
+DeleteTextTransaction::DoTransaction()
{
MOZ_ASSERT(mCharData);
// Get the text that we're about to delete
nsresult res = mCharData->SubstringData(mOffset, mNumCharsToDelete,
mDeletedText);
MOZ_ASSERT(NS_SUCCEEDED(res));
res = mCharData->DeleteData(mOffset, mNumCharsToDelete);
@@ -76,22 +78,24 @@ DeleteTextTxn::DoTransaction()
}
// Else do nothing - DOM Range gravity will adjust selection
return NS_OK;
}
//XXX: We may want to store the selection state and restore it properly. Was
// it an insertion point or an extended selection?
NS_IMETHODIMP
-DeleteTextTxn::UndoTransaction()
+DeleteTextTransaction::UndoTransaction()
{
MOZ_ASSERT(mCharData);
return mCharData->InsertData(mOffset, mDeletedText);
}
NS_IMETHODIMP
-DeleteTextTxn::GetTxnDescription(nsAString& aString)
+DeleteTextTransaction::GetTxnDescription(nsAString& aString)
{
- aString.AssignLiteral("DeleteTextTxn: ");
+ aString.AssignLiteral("DeleteTextTransaction: ");
aString += mDeletedText;
return NS_OK;
}
+
+} // namespace mozilla
rename from editor/libeditor/DeleteTextTxn.h
rename to editor/libeditor/DeleteTextTransaction.h
--- a/editor/libeditor/DeleteTextTxn.h
+++ b/editor/libeditor/DeleteTextTransaction.h
@@ -1,76 +1,75 @@
/* -*- 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 DeleteTextTxn_h__
-#define DeleteTextTxn_h__
+#ifndef DeleteTextTransaction_h
+#define DeleteTextTransaction_h
#include "EditTxn.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsGenericDOMDataNode.h"
#include "nsID.h"
#include "nsString.h"
#include "nscore.h"
class nsEditor;
class nsRangeUpdater;
namespace mozilla {
-namespace dom {
/**
* A transaction that removes text from a content node.
*/
-class DeleteTextTxn : public EditTxn
+class DeleteTextTransaction final : public EditTxn
{
public:
- /** initialize the transaction.
- * @param aEditor the provider of basic editing operations
- * @param aElement the content node to remove text from
- * @param aOffset the location in aElement to begin the deletion
- * @param aNumCharsToDelete the number of characters to delete. Not the number of bytes!
- */
- DeleteTextTxn(nsEditor& aEditor,
- nsGenericDOMDataNode& aCharData,
- uint32_t aOffset,
- uint32_t aNumCharsToDelete,
- nsRangeUpdater* aRangeUpdater);
+ /**
+ * Initialize the transaction.
+ * @param aEditor The provider of basic editing operations.
+ * @param aElement The content node to remove text from.
+ * @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);
nsresult Init();
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTxn, EditTxn)
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction, EditTxn)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
NS_DECL_EDITTXN
uint32_t GetOffset() { return mOffset; }
uint32_t GetNumCharsToDelete() { return mNumCharsToDelete; }
protected:
-
- /** the provider of basic editing operations */
+ // The provider of basic editing operations.
nsEditor& mEditor;
- /** the CharacterData node to operate upon */
+ // The CharacterData node to operate upon.
RefPtr<nsGenericDOMDataNode> mCharData;
- /** the offset into mCharData where the deletion is to take place */
+ // The offset into mCharData where the deletion is to take place.
uint32_t mOffset;
- /** the number of characters to delete */
+ // The number of characters to delete.
uint32_t mNumCharsToDelete;
- /** the text that was deleted */
+ // The text that was deleted.
nsString mDeletedText;
- /** range updater object */
+ // Range updater object.
nsRangeUpdater* mRangeUpdater;
};
-} // namespace dom
} // namespace mozilla
-#endif
+#endif // #ifndef DeleteTextTransaction_h
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -14,17 +14,17 @@ MOCHITEST_CHROME_MANIFESTS += ['tests/ch
BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
UNIFIED_SOURCES += [
'ChangeAttributeTransaction.cpp',
'ChangeStyleTransaction.cpp',
'CreateElementTransaction.cpp',
'DeleteNodeTransaction.cpp',
'DeleteRangeTransaction.cpp',
- 'DeleteTextTxn.cpp',
+ 'DeleteTextTransaction.cpp',
'EditAggregateTxn.cpp',
'EditorUtils.cpp',
'EditTxn.cpp',
'HTMLEditUtils.cpp',
'IMETextTxn.cpp',
'InsertNodeTxn.cpp',
'InsertTextTxn.cpp',
'JoinNodeTxn.cpp',
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -9,17 +9,17 @@
#include <stdio.h> // for nullptr, stdout
#include <string.h> // for strcmp
#include "ChangeAttributeTransaction.h" // for ChangeAttributeTransaction
#include "CreateElementTransaction.h" // for CreateElementTransaction
#include "DeleteNodeTransaction.h" // for DeleteNodeTransaction
#include "DeleteRangeTransaction.h" // for DeleteRangeTransaction
-#include "DeleteTextTxn.h" // for DeleteTextTxn
+#include "DeleteTextTransaction.h" // for DeleteTextTransaction
#include "EditAggregateTxn.h" // for EditAggregateTxn
#include "EditorUtils.h" // for AutoRules, etc
#include "EditTxn.h" // for EditTxn
#include "IMETextTxn.h" // for IMETextTxn
#include "InsertNodeTxn.h" // for InsertNodeTxn
#include "InsertTextTxn.h" // for InsertTextTxn
#include "JoinNodeTxn.h" // for JoinNodeTxn
#include "PlaceholderTxn.h" // for PlaceholderTxn
@@ -2587,54 +2587,53 @@ nsEditor::CreateTxnForInsertText(const n
return txn.forget();
}
nsresult
nsEditor::DeleteText(nsGenericDOMDataNode& aCharData, uint32_t aOffset,
uint32_t aLength)
{
- RefPtr<DeleteTextTxn> txn =
+ RefPtr<DeleteTextTransaction> transaction =
CreateTxnForDeleteText(aCharData, aOffset, aLength);
- NS_ENSURE_STATE(txn);
+ NS_ENSURE_STATE(transaction);
AutoRules beginRulesSniffing(this, EditAction::deleteText,
nsIEditor::ePrevious);
// Let listeners know what's up
for (auto& listener : mActionListeners) {
listener->WillDeleteText(
static_cast<nsIDOMCharacterData*>(GetAsDOMNode(&aCharData)), aOffset,
aLength);
}
- nsresult res = DoTransaction(txn);
+ nsresult rv = DoTransaction(transaction);
// Let listeners know what happened
for (auto& listener : mActionListeners) {
listener->DidDeleteText(
static_cast<nsIDOMCharacterData*>(GetAsDOMNode(&aCharData)), aOffset,
- aLength, res);
- }
-
- return res;
-}
-
-
-already_AddRefed<DeleteTextTxn>
+ aLength, rv);
+ }
+
+ return rv;
+}
+
+already_AddRefed<DeleteTextTransaction>
nsEditor::CreateTxnForDeleteText(nsGenericDOMDataNode& aCharData,
uint32_t aOffset, uint32_t aLength)
{
- RefPtr<DeleteTextTxn> txn =
- new DeleteTextTxn(*this, aCharData, aOffset, aLength, &mRangeUpdater);
-
- nsresult res = txn->Init();
- NS_ENSURE_SUCCESS(res, nullptr);
-
- return txn.forget();
+ RefPtr<DeleteTextTransaction> transaction =
+ new DeleteTextTransaction(*this, aCharData, aOffset, aLength,
+ &mRangeUpdater);
+ nsresult rv = transaction->Init();
+ NS_ENSURE_SUCCESS(rv, nullptr);
+
+ return transaction.forget();
}
already_AddRefed<SplitNodeTxn>
nsEditor::CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset)
{
RefPtr<SplitNodeTxn> txn = new SplitNodeTxn(*this, aNode, aOffset);
return txn.forget();
}
@@ -4314,17 +4313,17 @@ nsEditor::CreateTxnForDeleteSelection(ED
}
}
aggTxn.forget(aTxn);
return NS_OK;
}
-already_AddRefed<DeleteTextTxn>
+already_AddRefed<DeleteTextTransaction>
nsEditor::CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData,
uint32_t aOffset, EDirection aDirection)
{
NS_ASSERTION(aDirection == eNext || aDirection == ePrevious,
"Invalid direction");
nsAutoString data;
aData.GetData(data);
NS_ASSERTION(data.Length(), "Trying to delete from a zero-length node");
@@ -4394,23 +4393,23 @@ nsEditor::CreateTxnForDeleteInsertionPoi
// there is a priorNode, so delete its last child (if chardata, delete the
// last char). if it has no children, delete it
if (priorNode->IsNodeOfType(nsINode::eDATA_NODE)) {
RefPtr<nsGenericDOMDataNode> priorNodeAsCharData =
static_cast<nsGenericDOMDataNode*>(priorNode.get());
uint32_t length = priorNode->Length();
// Bail out for empty chardata XXX: Do we want to do something else?
NS_ENSURE_STATE(length);
- RefPtr<DeleteTextTxn> txn =
+ RefPtr<DeleteTextTransaction> transaction =
CreateTxnForDeleteCharacter(*priorNodeAsCharData, length, ePrevious);
- NS_ENSURE_STATE(txn);
-
- *aOffset = txn->GetOffset();
- *aLength = txn->GetNumCharsToDelete();
- aTxn->AppendChild(txn);
+ NS_ENSURE_STATE(transaction);
+
+ *aOffset = transaction->GetOffset();
+ *aLength = transaction->GetNumCharsToDelete();
+ aTxn->AppendChild(transaction);
} else {
// priorNode is not chardata, so tell its parent to delete it
RefPtr<DeleteNodeTransaction> transaction;
res = CreateTxnForDeleteNode(priorNode, getter_AddRefs(transaction));
NS_ENSURE_SUCCESS(res, res);
aTxn->AppendChild(transaction);
}
@@ -4429,23 +4428,23 @@ nsEditor::CreateTxnForDeleteInsertionPoi
// there is a nextNode, so delete its first child (if chardata, delete the
// first char). if it has no children, delete it
if (nextNode->IsNodeOfType(nsINode::eDATA_NODE)) {
RefPtr<nsGenericDOMDataNode> nextNodeAsCharData =
static_cast<nsGenericDOMDataNode*>(nextNode.get());
uint32_t length = nextNode->Length();
// Bail out for empty chardata XXX: Do we want to do something else?
NS_ENSURE_STATE(length);
- RefPtr<DeleteTextTxn> txn =
+ RefPtr<DeleteTextTransaction> transaction =
CreateTxnForDeleteCharacter(*nextNodeAsCharData, 0, eNext);
- NS_ENSURE_STATE(txn);
-
- *aOffset = txn->GetOffset();
- *aLength = txn->GetNumCharsToDelete();
- aTxn->AppendChild(txn);
+ NS_ENSURE_STATE(transaction);
+
+ *aOffset = transaction->GetOffset();
+ *aLength = transaction->GetNumCharsToDelete();
+ aTxn->AppendChild(transaction);
} else {
// nextNode is not chardata, so tell its parent to delete it
RefPtr<DeleteNodeTransaction> transaction;
res = CreateTxnForDeleteNode(nextNode, getter_AddRefs(transaction));
NS_ENSURE_SUCCESS(res, res);
aTxn->AppendChild(transaction);
}
@@ -4453,24 +4452,24 @@ nsEditor::CreateTxnForDeleteInsertionPoi
return NS_OK;
}
if (node->IsNodeOfType(nsINode::eDATA_NODE)) {
RefPtr<nsGenericDOMDataNode> nodeAsCharData =
static_cast<nsGenericDOMDataNode*>(node.get());
// we have chardata, so delete a char at the proper offset
- RefPtr<DeleteTextTxn> txn = CreateTxnForDeleteCharacter(*nodeAsCharData,
- offset, aAction);
- NS_ENSURE_STATE(txn);
-
- aTxn->AppendChild(txn);
+ RefPtr<DeleteTextTransaction> transaction =
+ CreateTxnForDeleteCharacter(*nodeAsCharData, offset, aAction);
+ NS_ENSURE_STATE(transaction);
+
+ aTxn->AppendChild(transaction);
NS_ADDREF(*aNode = node);
- *aOffset = txn->GetOffset();
- *aLength = txn->GetNumCharsToDelete();
+ *aOffset = transaction->GetOffset();
+ *aLength = transaction->GetNumCharsToDelete();
} else {
// we're either deleting a node or chardata, need to dig into the next/prev
// node to find out
nsCOMPtr<nsINode> selectedNode;
if (aAction == ePrevious) {
selectedNode = GetPriorNode(node, offset, true);
} else if (aAction == eNext) {
selectedNode = GetNextNode(node, offset, true);
@@ -4491,24 +4490,24 @@ nsEditor::CreateTxnForDeleteInsertionPoi
if (selectedNode->IsNodeOfType(nsINode::eDATA_NODE)) {
RefPtr<nsGenericDOMDataNode> selectedNodeAsCharData =
static_cast<nsGenericDOMDataNode*>(selectedNode.get());
// we are deleting from a chardata node, so do a character deletion
uint32_t position = 0;
if (aAction == ePrevious) {
position = selectedNode->Length();
}
- RefPtr<DeleteTextTxn> delTextTxn =
+ RefPtr<DeleteTextTransaction> deleteTextTransaction =
CreateTxnForDeleteCharacter(*selectedNodeAsCharData, position,
aAction);
- NS_ENSURE_TRUE(delTextTxn, NS_ERROR_NULL_POINTER);
-
- aTxn->AppendChild(delTextTxn);
- *aOffset = delTextTxn->GetOffset();
- *aLength = delTextTxn->GetNumCharsToDelete();
+ NS_ENSURE_TRUE(deleteTextTransaction, NS_ERROR_NULL_POINTER);
+
+ aTxn->AppendChild(deleteTextTransaction);
+ *aOffset = deleteTextTransaction->GetOffset();
+ *aLength = deleteTextTransaction->GetNumCharsToDelete();
} else {
RefPtr<DeleteNodeTransaction> deleteNodeTransaction;
res = CreateTxnForDeleteNode(selectedNode,
getter_AddRefs(deleteNodeTransaction));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(deleteNodeTransaction, NS_ERROR_NULL_POINTER);
aTxn->AppendChild(deleteNodeTransaction);
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -54,23 +54,23 @@ class nsTransactionManager;
namespace mozilla {
class AutoRules;
class AutoSelectionRestorer;
class AutoTransactionsConserveSelection;
class ChangeAttributeTransaction;
class CreateElementTransaction;
class DeleteNodeTransaction;
+class DeleteTextTransaction;
class ErrorResult;
class TextComposition;
struct EditorDOMPoint;
namespace dom {
class DataTransfer;
-class DeleteTextTxn;
class Element;
class EventTarget;
class IMETextTxn;
class InsertTextTxn;
class InsertNodeTxn;
class JoinNodeTxn;
class Selection;
class SplitNodeTxn;
@@ -322,21 +322,21 @@ protected:
NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::StyleSheetHandle aSheet,
RemoveStyleSheetTxn* *aTxn);
nsresult DeleteText(nsGenericDOMDataNode& aElement,
uint32_t aOffset, uint32_t aLength);
// NS_IMETHOD DeleteRange(nsIDOMRange *aRange);
- already_AddRefed<mozilla::dom::DeleteTextTxn>
+ already_AddRefed<mozilla::DeleteTextTransaction>
CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
uint32_t aOffset, uint32_t aLength);
- already_AddRefed<mozilla::dom::DeleteTextTxn>
+ already_AddRefed<mozilla::DeleteTextTransaction>
CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
EDirection aDirection);
already_AddRefed<mozilla::dom::SplitNodeTxn>
CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset);
already_AddRefed<mozilla::dom::JoinNodeTxn>
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);