From 46d18deed53c74afe5306c18249e8905e58b9408 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 2 Jul 2021 08:23:45 +0000 Subject: [PATCH] Bug 1718815 - part 3: Move `EditorBase::AutoTransactionBatch` to `HTMLEditor` r=m_kato I guess that this class is replaced with `AutoPlaceholderBatch`, and both of them are followed by its instances. However, I don't want to change the behavior in this bug. Therefore, this patch just moves it into `HTMLEditor`. Depends on D119002 Differential Revision: https://phabricator.services.mozilla.com/D119003 --- editor/libeditor/EditorBase.h | 30 ++++-------------------------- editor/libeditor/HTMLEditor.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index 69a6428f53bb..6d088caed048 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -60,7 +60,6 @@ namespace mozilla { class AlignStateAtSelection; class AutoRangeArray; class AutoTopLevelEditSubActionNotifier; -class AutoTransactionBatch; class AutoTransactionsConserveSelection; class AutoUpdateViewBatch; class ChangeAttributeTransaction; @@ -2147,9 +2146,10 @@ class EditorBase : public nsIEditor, MOZ_CAN_RUN_SCRIPT void EndUpdateViewBatch(); /** - * Used by AutoTransactionBatch. After calling BeginTransactionInternal(), - * all transactions will be treated as an atomic transaction. I.e., - * two or more transactions are undid once. + * Used by HTMLEditor::AutoTransactionBatch, nsIEditor::BeginTransaction + * and nsIEditor::EndTransation. After calling BeginTransactionInternal(), + * all transactions will be treated as an atomic transaction. I.e., two or + * more transactions are undid once. * XXX What's the difference with PlaceholderTransaction? Should we always * use it instead? */ @@ -2606,28 +2606,6 @@ class EditorBase : public nsIEditor, nsresult SetTextDirectionTo(TextDirection aTextDirection); protected: // helper classes which may be used by friends - /** - * Stack based helper class for calling EditorBase::EndTransactionInternal(). - * NOTE: This does not suppress multiple input events. In most cases, - * only one "input" event should be fired for an edit action rather - * than per edit sub-action. In such case, you should use - * AutoPlaceholderBatch instead. - */ - class MOZ_RAII AutoTransactionBatch final { - public: - MOZ_CAN_RUN_SCRIPT explicit AutoTransactionBatch(EditorBase& aEditorBase) - : mEditorBase(aEditorBase) { - MOZ_KnownLive(mEditorBase).BeginTransactionInternal(); - } - - MOZ_CAN_RUN_SCRIPT ~AutoTransactionBatch() { - MOZ_KnownLive(mEditorBase).EndTransactionInternal(); - } - - protected: - EditorBase& mEditorBase; - }; - /** * Stack based helper class for batching a collection of transactions inside * a placeholder transaction. Different from AutoTransactionBatch, this diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index 07edf637dee7..9cd8a4599686 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -4407,6 +4407,29 @@ class HTMLEditor final : public EditorBase, MOZ_KNOWN_LIVE HTMLEditor* mHTMLEditor = nullptr; }; + /** + * Stack based helper class for calling EditorBase::EndTransactionInternal(). + * NOTE: This does not suppress multiple input events. In most cases, + * only one "input" event should be fired for an edit action rather + * than per edit sub-action. In such case, you should use + * EditorBase::AutoPlaceholderBatch instead. + */ + class MOZ_RAII AutoTransactionBatch final { + public: + MOZ_CAN_RUN_SCRIPT explicit AutoTransactionBatch(HTMLEditor& aHTMLEditor) + : mHTMLEditor(aHTMLEditor) { + MOZ_KnownLive(mHTMLEditor).BeginTransactionInternal(); + } + + MOZ_CAN_RUN_SCRIPT ~AutoTransactionBatch() { + MOZ_KnownLive(mHTMLEditor).EndTransactionInternal(); + } + + protected: + // The lifetime must be guaranteed by the creator of this instance. + MOZ_KNOWN_LIVE HTMLEditor& mHTMLEditor; + }; + RefPtr mTypeInState; RefPtr mComposerCommandsUpdater;