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 "mozilla/Maybe.h"
11 #include "mozilla/SelectionState.h"
12 #include "mozilla/WeakPtr.h"
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
{
28 PlaceholderTransaction(EditorBase
& aEditorBase
, nsStaticAtom
& aName
,
29 Maybe
<SelectionState
>&& aSelState
);
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 bool StartSelectionEquals(SelectionState
& aSelectionState
);
64 nsresult
EndPlaceHolderBatch();
66 void ForwardEndBatchTo(PlaceholderTransaction
& aForwardingTransaction
) {
67 mForwardingTransaction
= &aForwardingTransaction
;
70 void Commit() { mCommitted
= true; }
72 nsresult
RememberEndingSelection();
75 virtual ~PlaceholderTransaction() = default;
77 // The editor for this transaction.
78 RefPtr
<EditorBase
> mEditorBase
;
80 WeakPtr
<PlaceholderTransaction
> mForwardingTransaction
;
82 // First IME txn in this placeholder - used for IME merging.
83 WeakPtr
<CompositionTransaction
> mCompositionTransaction
;
85 // These next two members store the state of the selection in a safe way.
86 // Selection at the start of the transaction is stored, as is the selection
87 // at the end. This is so that UndoTransaction() and RedoTransaction() can
88 // restore the selection properly.
90 SelectionState mStartSel
;
91 SelectionState mEndSel
;
93 // Do we auto absorb any and all transaction?
95 // Do we stop auto absorbing any matching placeholder transactions?
99 } // namespace mozilla
101 #endif // #ifndef PlaceholderTransaction_h