Bug 1776056 - Switch to the tab an animation is running and make sure the animation...
[gecko.git] / editor / libeditor / PlaceholderTransaction.h
blob35387d78beebe9122227d3fe97afa2f86bde3976
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef PlaceholderTransaction_h
7 #define PlaceholderTransaction_h
9 #include "EditAggregateTransaction.h"
10 #include "EditorForwards.h"
11 #include "SelectionState.h"
13 #include "mozilla/Maybe.h"
14 #include "mozilla/WeakPtr.h"
16 namespace mozilla {
18 /**
19 * An aggregate transaction that knows how to absorb all subsequent
20 * transactions with the same name. This transaction does not "Do" anything.
21 * But it absorbs other transactions via merge, and can undo/redo the
22 * transactions it has absorbed.
25 class PlaceholderTransaction final : public EditAggregateTransaction,
26 public SupportsWeakPtr {
27 protected:
28 PlaceholderTransaction(EditorBase& aEditorBase, nsStaticAtom& aName,
29 Maybe<SelectionState>&& aSelState);
31 public:
32 /**
33 * Creates a placeholder transaction. This never returns nullptr.
35 * @param aEditorBase The editor.
36 * @param aName The name of creating transaction.
37 * @param aSelState The selection state of aEditorBase.
39 static already_AddRefed<PlaceholderTransaction> Create(
40 EditorBase& aEditorBase, nsStaticAtom& aName,
41 Maybe<SelectionState>&& aSelState) {
42 // Make sure to move aSelState into a local variable to null out the
43 // original Maybe<SelectionState> variable.
44 Maybe<SelectionState> selState(std::move(aSelState));
45 RefPtr<PlaceholderTransaction> transaction =
46 new PlaceholderTransaction(aEditorBase, aName, std::move(selState));
47 return transaction.forget();
50 NS_DECL_ISUPPORTS_INHERITED
52 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
53 EditAggregateTransaction)
54 // ------------ EditAggregateTransaction -----------------------
56 NS_DECL_EDITTRANSACTIONBASE
57 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(PlaceholderTransaction)
59 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
60 NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
62 nsresult EndPlaceHolderBatch();
64 void ForwardEndBatchTo(PlaceholderTransaction& aForwardingTransaction) {
65 mForwardingTransaction = &aForwardingTransaction;
68 void Commit() { mCommitted = true; }
70 nsresult RememberEndingSelection();
72 protected:
73 virtual ~PlaceholderTransaction() = default;
75 // The editor for this transaction.
76 RefPtr<EditorBase> mEditorBase;
78 WeakPtr<PlaceholderTransaction> mForwardingTransaction;
80 // First IME txn in this placeholder - used for IME merging.
81 WeakPtr<CompositionTransaction> mCompositionTransaction;
83 // These next two members store the state of the selection in a safe way.
84 // Selection at the start of the transaction is stored, as is the selection
85 // at the end. This is so that UndoTransaction() and RedoTransaction() can
86 // restore the selection properly.
88 SelectionState mStartSel;
89 SelectionState mEndSel;
91 // Do we auto absorb any and all transaction?
92 bool mAbsorb;
93 // Do we stop auto absorbing any matching placeholder transactions?
94 bool mCommitted;
97 } // namespace mozilla
99 #endif // #ifndef PlaceholderTransaction_h