Bug 1260651 part.20 Rename DeleteNodeTxn to mozilla::DeleteNodeTransaction (and their files too) r=mccr8 draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 07 Jul 2016 15:08:33 +0900
changeset 385710 dec9268b3f53564814c3487acb35c43c0974712f
parent 385709 965d150e9ddb7018b10e6feaf247dc9feef24fd6
child 385711 8b3a038948ccd75a07c67c1edbc35a9f605ef868
push id22582
push usermasayuki@d-toybox.com
push dateSat, 09 Jul 2016 03:13:39 +0000
reviewersmccr8
bugs1260651
milestone50.0a1
Bug 1260651 part.20 Rename DeleteNodeTxn to mozilla::DeleteNodeTransaction (and their files too) r=mccr8 MozReview-Commit-ID: ID8DUm0LoD5
editor/libeditor/DeleteNodeTransaction.cpp
editor/libeditor/DeleteNodeTransaction.h
editor/libeditor/DeleteNodeTxn.cpp
editor/libeditor/DeleteNodeTxn.h
editor/libeditor/DeleteRangeTxn.cpp
editor/libeditor/moz.build
editor/libeditor/nsEditor.cpp
editor/libeditor/nsEditor.h
rename from editor/libeditor/DeleteNodeTxn.cpp
rename to editor/libeditor/DeleteNodeTransaction.cpp
--- a/editor/libeditor/DeleteNodeTxn.cpp
+++ b/editor/libeditor/DeleteNodeTransaction.cpp
@@ -1,61 +1,62 @@
 /* -*- 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 "DeleteNodeTxn.h"
+#include "DeleteNodeTransaction.h"
 #include "nsDebug.h"
 #include "nsEditor.h"
 #include "nsError.h"
 #include "nsSelectionState.h" // nsRangeUpdater
 #include "nsAString.h"
 
-using namespace mozilla;
+namespace mozilla {
 
-DeleteNodeTxn::DeleteNodeTxn()
-  : EditTxn(), mNode(), mParent(), mRefNode(), mRangeUpdater(nullptr)
+DeleteNodeTransaction::DeleteNodeTransaction()
+  : mEditor(nullptr)
+  , mRangeUpdater(nullptr)
 {
 }
 
-DeleteNodeTxn::~DeleteNodeTxn()
+DeleteNodeTransaction::~DeleteNodeTransaction()
 {
 }
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteNodeTxn, EditTxn,
+NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteNodeTransaction, EditTxn,
                                    mNode,
                                    mParent,
                                    mRefNode)
 
-NS_IMPL_ADDREF_INHERITED(DeleteNodeTxn, EditTxn)
-NS_IMPL_RELEASE_INHERITED(DeleteNodeTxn, EditTxn)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteNodeTxn)
+NS_IMPL_ADDREF_INHERITED(DeleteNodeTransaction, EditTxn)
+NS_IMPL_RELEASE_INHERITED(DeleteNodeTransaction, EditTxn)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteNodeTransaction)
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 nsresult
-DeleteNodeTxn::Init(nsEditor* aEditor, nsINode* aNode,
-                    nsRangeUpdater* aRangeUpdater)
+DeleteNodeTransaction::Init(nsEditor* aEditor,
+                            nsINode* aNode,
+                            nsRangeUpdater* 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),
                  NS_ERROR_FAILURE);
 
   mRangeUpdater = aRangeUpdater;
   return NS_OK;
 }
 
-
 NS_IMETHODIMP
-DeleteNodeTxn::DoTransaction()
+DeleteNodeTransaction::DoTransaction()
 {
   NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
 
   if (!mParent) {
     // this is a no-op, there's no parent to delete mNode from
     return NS_OK;
   }
 
@@ -71,33 +72,33 @@ DeleteNodeTxn::DoTransaction()
   }
 
   ErrorResult error;
   mParent->RemoveChild(*mNode, error);
   return error.StealNSResult();
 }
 
 NS_IMETHODIMP
-DeleteNodeTxn::UndoTransaction()
+DeleteNodeTransaction::UndoTransaction()
 {
   if (!mParent) {
     // this is a legal state, the txn is a no-op
     return NS_OK;
   }
   if (!mNode) {
     return NS_ERROR_NULL_POINTER;
   }
 
   ErrorResult error;
   mParent->InsertBefore(*mNode, mRefNode, error);
   return error.StealNSResult();
 }
 
 NS_IMETHODIMP
-DeleteNodeTxn::RedoTransaction()
+DeleteNodeTransaction::RedoTransaction()
 {
   if (!mParent) {
     // this is a legal state, the txn is a no-op
     return NS_OK;
   }
   if (!mNode) {
     return NS_ERROR_NULL_POINTER;
   }
@@ -107,13 +108,15 @@ DeleteNodeTxn::RedoTransaction()
   }
 
   ErrorResult error;
   mParent->RemoveChild(*mNode, error);
   return error.StealNSResult();
 }
 
 NS_IMETHODIMP
-DeleteNodeTxn::GetTxnDescription(nsAString& aString)
+DeleteNodeTransaction::GetTxnDescription(nsAString& aString)
 {
-  aString.AssignLiteral("DeleteNodeTxn");
+  aString.AssignLiteral("DeleteNodeTransaction");
   return NS_OK;
 }
+
+} // namespace mozilla
rename from editor/libeditor/DeleteNodeTxn.h
rename to editor/libeditor/DeleteNodeTransaction.h
--- a/editor/libeditor/DeleteNodeTxn.h
+++ b/editor/libeditor/DeleteNodeTransaction.h
@@ -1,60 +1,65 @@
 /* -*- 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 DeleteNodeTxn_h__
-#define DeleteNodeTxn_h__
+#ifndef DeleteNodeTransaction_h
+#define DeleteNodeTransaction_h
 
 #include "EditTxn.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIContent.h"
 #include "nsINode.h"
 #include "nsISupportsImpl.h"
 #include "nscore.h"
 
 class nsEditor;
 class nsRangeUpdater;
 
+namespace mozilla {
+
 /**
  * A transaction that deletes a single element
  */
-class DeleteNodeTxn : public EditTxn
+class DeleteNodeTransaction final : public EditTxn
 {
 public:
-  /** initialize the transaction.
-    * @param aElement the node to delete
-    */
+  /**
+   * Initialize the transaction.
+   * @param aElement        The node to delete.
+   */
   nsresult Init(nsEditor* aEditor, nsINode* aNode,
                 nsRangeUpdater* aRangeUpdater);
 
-  DeleteNodeTxn();
+  DeleteNodeTransaction();
 
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTxn, EditTxn)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction, EditTxn)
 
   NS_DECL_EDITTXN
 
   NS_IMETHOD RedoTransaction() override;
 
 protected:
-  virtual ~DeleteNodeTxn();
+  virtual ~DeleteNodeTransaction();
 
-  /** the element to delete */
+  // The element to delete.
   nsCOMPtr<nsINode> mNode;
 
-  /** parent of node to delete */
+  // Parent of node to delete.
   nsCOMPtr<nsINode> mParent;
 
-  /** next sibling to remember for undo/redo purposes */
+  // Next sibling to remember for undo/redo purposes.
   nsCOMPtr<nsIContent> mRefNode;
 
-  /** the editor for this transaction */
+  // The editor for this transaction.
   nsEditor* mEditor;
 
-  /** range updater object */
+  // Range updater object.
   nsRangeUpdater* mRangeUpdater;
 };
 
-#endif
+} // namespace mozilla
+
+#endif // #ifndef DeleteNodeTransaction_h
--- a/editor/libeditor/DeleteRangeTxn.cpp
+++ b/editor/libeditor/DeleteRangeTxn.cpp
@@ -1,16 +1,16 @@
 /* -*- 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 "DeleteRangeTxn.h"
 
-#include "DeleteNodeTxn.h"
+#include "DeleteNodeTransaction.h"
 #include "DeleteTextTxn.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"
@@ -159,20 +159,20 @@ DeleteRangeTxn::CreateTxnsToDeleteBetwee
     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) {
-    RefPtr<DeleteNodeTxn> txn = new DeleteNodeTxn();
-    res = txn->Init(mEditor, child, mRangeUpdater);
+    RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
+    res = transaction->Init(mEditor, child, mRangeUpdater);
     if (NS_SUCCEEDED(res)) {
-      AppendChild(txn);
+      AppendChild(transaction);
     }
 
     child = child->GetNextSibling();
   }
 
   NS_ENSURE_SUCCESS(res, res);
   return NS_OK;
 }
@@ -217,18 +217,17 @@ DeleteRangeTxn::CreateTxnsToDeleteNodesB
 
   nsresult res = iter->Init(mRange);
   NS_ENSURE_SUCCESS(res, res);
 
   while (!iter->IsDone()) {
     nsCOMPtr<nsINode> node = iter->GetCurrentNode();
     NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
-    RefPtr<DeleteNodeTxn> txn = new DeleteNodeTxn();
-
-    res = txn->Init(mEditor, node, mRangeUpdater);
+    RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
+    res = transaction->Init(mEditor, node, mRangeUpdater);
     NS_ENSURE_SUCCESS(res, res);
-    AppendChild(txn);
+    AppendChild(transaction);
 
     iter->Next();
   }
   return NS_OK;
 }
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -12,17 +12,17 @@ MOCHITEST_MANIFESTS += [
 MOCHITEST_CHROME_MANIFESTS += ['tests/chrome.ini']
 
 BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
 
 UNIFIED_SOURCES += [
     'ChangeAttributeTransaction.cpp',
     'ChangeStyleTransaction.cpp',
     'CreateElementTransaction.cpp',
-    'DeleteNodeTxn.cpp',
+    'DeleteNodeTransaction.cpp',
     'DeleteRangeTxn.cpp',
     'DeleteTextTxn.cpp',
     'EditAggregateTxn.cpp',
     'EditorUtils.cpp',
     'EditTxn.cpp',
     'HTMLEditUtils.cpp',
     'IMETextTxn.cpp',
     'InsertNodeTxn.cpp',
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -7,17 +7,17 @@
 
 #include "mozilla/DebugOnly.h"          // for DebugOnly
 
 #include <stdio.h>                      // for nullptr, stdout
 #include <string.h>                     // for strcmp
 
 #include "ChangeAttributeTransaction.h" // for ChangeAttributeTransaction
 #include "CreateElementTransaction.h"   // for CreateElementTransaction
-#include "DeleteNodeTxn.h"              // for DeleteNodeTxn
+#include "DeleteNodeTransaction.h"      // for DeleteNodeTransaction
 #include "DeleteRangeTxn.h"             // for DeleteRangeTxn
 #include "DeleteTextTxn.h"              // for DeleteTextTxn
 #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
@@ -1515,27 +1515,27 @@ nsEditor::DeleteNode(nsINode* aNode)
   AutoRules beginRulesSniffing(this, EditAction::createNode,
                                nsIEditor::ePrevious);
 
   // save node location for selection updating code.
   for (auto& listener : mActionListeners) {
     listener->WillDeleteNode(aNode->AsDOMNode());
   }
 
-  RefPtr<DeleteNodeTxn> txn;
-  nsresult res = CreateTxnForDeleteNode(aNode, getter_AddRefs(txn));
-  if (NS_SUCCEEDED(res))  {
-    res = DoTransaction(txn);
+  RefPtr<DeleteNodeTransaction> transaction;
+  nsresult rv = CreateTxnForDeleteNode(aNode, getter_AddRefs(transaction));
+  if (NS_SUCCEEDED(rv))  {
+    rv = DoTransaction(transaction);
   }
 
   for (auto& listener : mActionListeners) {
-    listener->DidDeleteNode(aNode->AsDOMNode(), res);
-  }
-
-  NS_ENSURE_SUCCESS(res, res);
+    listener->DidDeleteNode(aNode->AsDOMNode(), rv);
+  }
+
+  NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // ReplaceContainer: replace inNode with a new node (outNode) which is contructed
 //                   to be of type aNodeType.  Put inNodes children into outNode.
 //                   Callers responsibility to make sure inNode's children can
 //                   go in outNode.
@@ -4210,26 +4210,27 @@ nsEditor::CreateTxnForInsertNode(nsICont
                                  int32_t aPosition)
 {
   RefPtr<InsertNodeTxn> txn = new InsertNodeTxn(aNode, aParent, aPosition,
                                                   *this);
   return txn.forget();
 }
 
 nsresult
-nsEditor::CreateTxnForDeleteNode(nsINode* aNode, DeleteNodeTxn** aTxn)
+nsEditor::CreateTxnForDeleteNode(nsINode* aNode,
+                                 DeleteNodeTransaction** aTransaction)
 {
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
-  RefPtr<DeleteNodeTxn> txn = new DeleteNodeTxn();
-
-  nsresult res = txn->Init(this, aNode, &mRangeUpdater);
-  NS_ENSURE_SUCCESS(res, res);
-
-  txn.forget(aTxn);
+  RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
+
+  nsresult rv = transaction->Init(this, aNode, &mRangeUpdater);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  transaction.forget(aTransaction);
   return NS_OK;
 }
 
 already_AddRefed<IMETextTxn>
 nsEditor::CreateTxnForIMEText(const nsAString& aStringToInsert)
 {
   MOZ_ASSERT(mIMETextNode);
   // During handling IME composition, mComposition must have been initialized.
@@ -4402,21 +4403,21 @@ nsEditor::CreateTxnForDeleteInsertionPoi
         CreateTxnForDeleteCharacter(*priorNodeAsCharData, length, ePrevious);
       NS_ENSURE_STATE(txn);
 
       *aOffset = txn->GetOffset();
       *aLength = txn->GetNumCharsToDelete();
       aTxn->AppendChild(txn);
     } else {
       // priorNode is not chardata, so tell its parent to delete it
-      RefPtr<DeleteNodeTxn> txn;
-      res = CreateTxnForDeleteNode(priorNode, getter_AddRefs(txn));
+      RefPtr<DeleteNodeTransaction> transaction;
+      res = CreateTxnForDeleteNode(priorNode, getter_AddRefs(transaction));
       NS_ENSURE_SUCCESS(res, res);
 
-      aTxn->AppendChild(txn);
+      aTxn->AppendChild(transaction);
     }
 
     NS_ADDREF(*aNode = priorNode);
 
     return NS_OK;
   }
 
   if (aAction == eNext && isLast) {
@@ -4437,20 +4438,20 @@ nsEditor::CreateTxnForDeleteInsertionPoi
         CreateTxnForDeleteCharacter(*nextNodeAsCharData, 0, eNext);
       NS_ENSURE_STATE(txn);
 
       *aOffset = txn->GetOffset();
       *aLength = txn->GetNumCharsToDelete();
       aTxn->AppendChild(txn);
     } else {
       // nextNode is not chardata, so tell its parent to delete it
-      RefPtr<DeleteNodeTxn> txn;
-      res = CreateTxnForDeleteNode(nextNode, getter_AddRefs(txn));
+      RefPtr<DeleteNodeTransaction> transaction;
+      res = CreateTxnForDeleteNode(nextNode, getter_AddRefs(transaction));
       NS_ENSURE_SUCCESS(res, res);
-      aTxn->AppendChild(txn);
+      aTxn->AppendChild(transaction);
     }
 
     NS_ADDREF(*aNode = nextNode);
 
     return NS_OK;
   }
 
   if (node->IsNodeOfType(nsINode::eDATA_NODE)) {
@@ -4499,22 +4500,23 @@ nsEditor::CreateTxnForDeleteInsertionPoi
         CreateTxnForDeleteCharacter(*selectedNodeAsCharData, position,
                                     aAction);
       NS_ENSURE_TRUE(delTextTxn, NS_ERROR_NULL_POINTER);
 
       aTxn->AppendChild(delTextTxn);
       *aOffset = delTextTxn->GetOffset();
       *aLength = delTextTxn->GetNumCharsToDelete();
     } else {
-      RefPtr<DeleteNodeTxn> delElementTxn;
-      res = CreateTxnForDeleteNode(selectedNode, getter_AddRefs(delElementTxn));
+      RefPtr<DeleteNodeTransaction> deleteNodeTransaction;
+      res = CreateTxnForDeleteNode(selectedNode,
+                                   getter_AddRefs(deleteNodeTransaction));
       NS_ENSURE_SUCCESS(res, res);
-      NS_ENSURE_TRUE(delElementTxn, NS_ERROR_NULL_POINTER);
-
-      aTxn->AppendChild(delElementTxn);
+      NS_ENSURE_TRUE(deleteNodeTransaction, NS_ERROR_NULL_POINTER);
+
+      aTxn->AppendChild(deleteNodeTransaction);
     }
 
     NS_ADDREF(*aNode = selectedNode);
   }
 
   return NS_OK;
 }
 
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -23,17 +23,16 @@
 #include "nsIWeakReferenceUtils.h"      // for nsWeakPtr
 #include "nsLiteralString.h"            // for NS_LITERAL_STRING
 #include "nsSelectionState.h"           // for nsRangeUpdater, etc
 #include "nsString.h"                   // for nsCString
 #include "nsWeakReference.h"            // for nsSupportsWeakReference
 #include "nscore.h"                     // for nsresult, nsAString, etc
 
 class AddStyleSheetTxn;
-class DeleteNodeTxn;
 class EditAggregateTxn;
 class RemoveStyleSheetTxn;
 class nsIAtom;
 class nsIContent;
 class nsIDOMDocument;
 class nsIDOMEvent;
 class nsIDOMEventListener;
 class nsIDOMEventTarget;
@@ -54,16 +53,17 @@ class nsString;
 class nsTransactionManager;
 
 namespace mozilla {
 class AutoRules;
 class AutoSelectionRestorer;
 class AutoTransactionsConserveSelection;
 class ChangeAttributeTransaction;
 class CreateElementTransaction;
+class DeleteNodeTransaction;
 class ErrorResult;
 class TextComposition;
 struct EditorDOMPoint;
 
 namespace dom {
 class DataTransfer;
 class DeleteTextTxn;
 class Element;
@@ -278,18 +278,19 @@ protected:
 
   /** create a transaction for inserting aNode as a child of aParent.
     */
   already_AddRefed<mozilla::dom::InsertNodeTxn>
   CreateTxnForInsertNode(nsIContent& aNode, nsINode& aParent, int32_t aOffset);
 
   /** create a transaction for removing aNode from its parent.
     */
-  nsresult CreateTxnForDeleteNode(nsINode* aNode, DeleteNodeTxn** aTxn);
-
+  nsresult CreateTxnForDeleteNode(
+             nsINode* aNode,
+             mozilla::DeleteNodeTransaction** aTransaction);
 
   nsresult CreateTxnForDeleteSelection(EDirection aAction,
                                        EditAggregateTxn** aTxn,
                                        nsINode** aNode,
                                        int32_t* aOffset,
                                        int32_t* aLength);
 
   nsresult CreateTxnForDeleteInsertionPoint(nsRange* aRange,