Bug 1480055 - part 3: Create non-virtual method to set EditorBase::mAllowsTransactionsToChangeSelection r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 01 Aug 2018 21:11:44 +0900
changeset 825748 4849353b3dc0da9184401d5a45f18206459ab2bc
parent 825747 2c1cbb7b73c7af4892fbb3b8967a648a8b6d02d3
child 825749 07e32f07504be1dc311b114b460a970e756cf980
push id118159
push usermasayuki@d-toybox.com
push dateThu, 02 Aug 2018 07:24:41 +0000
reviewersm_kato
bugs1480055
milestone63.0a1
Bug 1480055 - part 3: Create non-virtual method to set EditorBase::mAllowsTransactionsToChangeSelection r?m_kato There is no non-virtual method to modify EditorBase::mAllowsTransactionsToChangeSelection. Therefore, AutoTransactionsConserveSelection calls virtual method, nsIEditor::SetShouldTxnSetSelection() twice (from both constructor and destructor). So, we should save this unnecessary cost. MozReview-Commit-ID: B7TYGnGtuLB
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/EditorUtils.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -980,17 +980,17 @@ EditorBase::EndPlaceholderTransaction()
     }
   }
   mPlaceholderBatch--;
 }
 
 NS_IMETHODIMP
 EditorBase::SetShouldTxnSetSelection(bool aShould)
 {
-  mAllowsTransactionsToChangeSelection = aShould;
+  MakeThisAllowTransactionsToChangeSelection(aShould);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::GetDocumentIsEmpty(bool* aDocumentIsEmpty)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1551,16 +1551,26 @@ protected: // May be called by friends.
    * transactions to change Selection.  Otherwise, transactions shouldn't
    * change Selection.
    */
   inline bool AllowsTransactionsToChangeSelection() const
   {
     return mAllowsTransactionsToChangeSelection;
   }
 
+  /**
+   * MakeThisAllowTransactionsToChangeSelection() with true makes this editor
+   * allow transactions to change Selection.  Otherwise, i.e., with false,
+   * makes this editor not allow transactions to change Selection.
+   */
+  inline void MakeThisAllowTransactionsToChangeSelection(bool aAllow)
+  {
+    mAllowsTransactionsToChangeSelection = aAllow;
+  }
+
   nsresult HandleInlineSpellCheck(EditSubAction aEditSubAction,
                                   Selection& aSelection,
                                   nsINode* previousSelectedNode,
                                   uint32_t previousSelectedOffset,
                                   nsINode* aStartContainer,
                                   uint32_t aStartOffset,
                                   nsINode* aEndContainer,
                                   uint32_t aEndOffset);
--- a/editor/libeditor/EditorUtils.h
+++ b/editor/libeditor/EditorUtils.h
@@ -576,24 +576,24 @@ public:
                                              MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
     : mEditorBase(aEditorBase)
     , mAllowedTransactionsToChangeSelection(true)
   {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     if (mEditorBase) {
       mAllowedTransactionsToChangeSelection =
         mEditorBase->AllowsTransactionsToChangeSelection();
-      mEditorBase->SetShouldTxnSetSelection(false);
+      mEditorBase->MakeThisAllowTransactionsToChangeSelection(false);
     }
   }
 
   ~AutoTransactionsConserveSelection()
   {
     if (mEditorBase) {
-      mEditorBase->SetShouldTxnSetSelection(
+      mEditorBase->MakeThisAllowTransactionsToChangeSelection(
                      mAllowedTransactionsToChangeSelection);
     }
   }
 
 protected:
   EditorBase* mEditorBase;
   bool mAllowedTransactionsToChangeSelection;
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER