Bug 1500862 - part 2: Create AutoTransactionBatchExternal class which calls XPCOM methods instead of non-virtual internal methods r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 24 Oct 2018 05:18:40 +0000
changeset 501963 d2112ced49ef79ddf69c041a8b01589869c39343
parent 501962 7bda40ae7f004f43c3afbfb66f7a3b5a2ea2eaa9
child 501964 b7fdf387fa7b2ecd8f046524f72ed1abc76a02fc
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1500862
milestone65.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 1500862 - part 2: Create AutoTransactionBatchExternal class which calls XPCOM methods instead of non-virtual internal methods r=m_kato Unfortunately, TextServicesDocument::InsertText() is too complicated to do it with both editor class and TextServicesDocument separately. Therefore, this patch adds AutoTransactionBatchExternal class which is almost same as AutoTransactionBatch but uses XPCOM methods to begin/end transaction. This change helps editor to manage whether it starts to handle new edit action or not when BeginTransaction() is called explicitly. Differential Revision: https://phabricator.services.mozilla.com/D9478
editor/libeditor/EditorUtils.h
editor/spellchecker/TextServicesDocument.cpp
--- a/editor/libeditor/EditorUtils.h
+++ b/editor/libeditor/EditorUtils.h
@@ -448,16 +448,44 @@ private:
 
   nsresult mRv;
 
   SplitRangeOffFromNodeResult() = delete;
 };
 
 /***************************************************************************
  * stack based helper class for calling EditorBase::EndTransaction() after
+ * EditorBase::BeginTransaction().  This shouldn't be used in editor classes
+ * or helper classes while an edit action is being handled.  Use
+ * AutoTransactionBatch in such cases since it uses non-virtual internal
+ * methods.
+ ***************************************************************************/
+class MOZ_RAII AutoTransactionBatchExternal final
+{
+private:
+  OwningNonNull<EditorBase> mEditorBase;
+  MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
+
+public:
+  explicit AutoTransactionBatchExternal(EditorBase& aEditorBase
+                                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
+    : mEditorBase(aEditorBase)
+  {
+    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
+    mEditorBase->BeginTransaction();
+  }
+
+  ~AutoTransactionBatchExternal()
+  {
+    mEditorBase->EndTransaction();
+  }
+};
+
+/***************************************************************************
+ * stack based helper class for calling EditorBase::EndTransaction() after
  * EditorBase::BeginTransaction().
  ***************************************************************************/
 class MOZ_RAII AutoTransactionBatch final
 {
 private:
   OwningNonNull<EditorBase> mEditorBase;
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 
--- a/editor/spellchecker/TextServicesDocument.cpp
+++ b/editor/spellchecker/TextServicesDocument.cpp
@@ -1143,22 +1143,19 @@ TextServicesDocument::InsertText(const n
     // Collapse to the start of the current selection
     // for the insert!
 
     nsresult rv = SetSelection(mSelStartOffset, 0);
 
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  // AutoTransactionBatch grabs mTextEditor, so, we don't need to grab the
-  // instance with local variable here.
-  // XXX Well, do we really need to create AutoTransactionBatch here?
-  //     Looks like that after InsertTextAsAction(), this does nothing
-  //     from a point of view of editor.
-  AutoTransactionBatch bundleAllTransactions(*mTextEditor);
+  // AutoTransactionBatchExternal grabs mTextEditor, so, we don't need to grab
+  // the instance with local variable here.
+  AutoTransactionBatchExternal treatAsOneTransaction(*mTextEditor);
 
   nsresult rv = mTextEditor->InsertTextAsAction(*aText);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   int32_t strLength = aText->Length();