Bug 1345690 part.4 Rename JoinNodeTransaction::CheckValidity() to JoinNodeTransaction::CanDoIt() for consistency with other transaction classes r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 10 Mar 2017 13:46:27 +0900
changeset 347047 e6423ffe849ebb794e8b2a98fea46e7993413864
parent 347046 98894712d99f6c90d8e5d2eacf4a505bb9275664
child 347048 d8e49646361159d59c13aa54f62a85d86b0102d7
push id87952
push userkwierso@gmail.com
push dateSat, 11 Mar 2017 01:23:00 +0000
treeherdermozilla-inbound@3683cfb843eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1345690
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1345690 part.4 Rename JoinNodeTransaction::CheckValidity() to JoinNodeTransaction::CanDoIt() for consistency with other transaction classes r=m_kato MozReview-Commit-ID: 3a5QXiofEL2
editor/libeditor/EditorBase.cpp
editor/libeditor/JoinNodeTransaction.cpp
editor/libeditor/JoinNodeTransaction.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2737,22 +2737,24 @@ EditorBase::CreateTxnForSplitNode(nsICon
     new SplitNodeTransaction(*this, aNode, aOffset);
   return transaction.forget();
 }
 
 already_AddRefed<JoinNodeTransaction>
 EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
                                  nsINode& aRightNode)
 {
-  RefPtr<JoinNodeTransaction> transaction =
+  RefPtr<JoinNodeTransaction> joinNodeTransaction =
     new JoinNodeTransaction(*this, aLeftNode, aRightNode);
-
-  NS_ENSURE_SUCCESS(transaction->CheckValidity(), nullptr);
-
-  return transaction.forget();
+  // If it's not editable, the transaction shouldn't be recorded since it
+  // should never be undone/redone.
+  if (NS_WARN_IF(!joinNodeTransaction->CanDoIt())) {
+    return nullptr;
+  }
+  return joinNodeTransaction.forget();
 }
 
 struct SavedRange final
 {
   RefPtr<Selection> mSelection;
   nsCOMPtr<nsINode> mStartNode;
   nsCOMPtr<nsINode> mEndNode;
   int32_t mStartOffset;
--- a/editor/libeditor/JoinNodeTransaction.cpp
+++ b/editor/libeditor/JoinNodeTransaction.cpp
@@ -31,23 +31,25 @@ JoinNodeTransaction::JoinNodeTransaction
 NS_IMPL_CYCLE_COLLECTION_INHERITED(JoinNodeTransaction, EditTransactionBase,
                                    mLeftNode,
                                    mRightNode,
                                    mParent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JoinNodeTransaction)
 NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
 
-nsresult
-JoinNodeTransaction::CheckValidity()
+bool
+JoinNodeTransaction::CanDoIt() const
 {
-  if (!mEditorBase.IsModifiableNode(mLeftNode->GetParentNode())) {
-    return NS_ERROR_FAILURE;
+  if (NS_WARN_IF(!mLeftNode) ||
+      NS_WARN_IF(!mRightNode) ||
+      !mLeftNode->GetParentNode()) {
+    return false;
   }
-  return NS_OK;
+  return mEditorBase.IsModifiableNode(mLeftNode->GetParentNode());
 }
 
 // After DoTransaction() and RedoTransaction(), the left node is removed from
 // the content tree and right node remains.
 NS_IMETHODIMP
 JoinNodeTransaction::DoTransaction()
 {
   // Get the parent node
--- a/editor/libeditor/JoinNodeTransaction.h
+++ b/editor/libeditor/JoinNodeTransaction.h
@@ -31,19 +31,20 @@ public:
    * @param aEditorBase     The provider of core editing operations.
    * @param aLeftNode       The first of two nodes to join.
    * @param aRightNode      The second of two nodes to join.
    */
   JoinNodeTransaction(EditorBase& aEditorBase,
                       nsINode& aLeftNode, nsINode& aRightNode);
 
   /**
-   * Call this after constructing to ensure the inputs are correct.
+   * CanDoIt() returns true if there are enough members and can join or
+   * restore the nodes.  Otherwise, false.
    */
-  nsresult CheckValidity();
+  bool CanDoIt() const;
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction,
                                            EditTransactionBase)
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
 
   NS_DECL_EDITTRANSACTIONBASE
 
 protected: