Line data Source code
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/. */
5 :
6 : #ifndef PlaceholderTransaction_h
7 : #define PlaceholderTransaction_h
8 :
9 : #include "EditAggregateTransaction.h"
10 : #include "mozilla/EditorUtils.h"
11 : #include "mozilla/UniquePtr.h"
12 : #include "mozilla/WeakPtr.h"
13 : #include "nsIAbsorbingTransaction.h"
14 : #include "nsIDOMNode.h"
15 : #include "nsCOMPtr.h"
16 : #include "nsWeakPtr.h"
17 : #include "nsWeakReference.h"
18 :
19 : namespace mozilla {
20 :
21 : class CompositionTransaction;
22 :
23 : /**
24 : * An aggregate transaction that knows how to absorb all subsequent
25 : * transactions with the same name. This transaction does not "Do" anything.
26 : * But it absorbs other transactions via merge, and can undo/redo the
27 : * transactions it has absorbed.
28 : */
29 :
30 : class PlaceholderTransaction final
31 : : public EditAggregateTransaction
32 : , public nsIAbsorbingTransaction
33 : , public SupportsWeakPtr<PlaceholderTransaction>
34 : {
35 : public:
36 7 : MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PlaceholderTransaction)
37 :
38 : NS_DECL_ISUPPORTS_INHERITED
39 :
40 : PlaceholderTransaction(EditorBase& aEditorBase, nsIAtom* aName,
41 : UniquePtr<SelectionState> aSelState);
42 :
43 4 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
44 : EditAggregateTransaction)
45 : // ------------ EditAggregateTransaction -----------------------
46 :
47 : NS_DECL_EDITTRANSACTIONBASE
48 :
49 : NS_IMETHOD RedoTransaction() override;
50 : NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
51 :
52 : // ------------ nsIAbsorbingTransaction -----------------------
53 :
54 : NS_IMETHOD GetTxnName(nsIAtom** aName) override;
55 :
56 : NS_IMETHOD StartSelectionEquals(SelectionState* aSelState,
57 : bool* aResult) override;
58 :
59 : NS_IMETHOD EndPlaceHolderBatch() override;
60 :
61 : NS_IMETHOD ForwardEndBatchTo(
62 : nsIAbsorbingTransaction* aForwardingAddress) override;
63 :
64 : NS_IMETHOD Commit() override;
65 :
66 0 : NS_IMETHOD_(PlaceholderTransaction*) AsPlaceholderTransaction() override
67 : {
68 0 : return this;
69 : }
70 :
71 : nsresult RememberEndingSelection();
72 :
73 : protected:
74 : virtual ~PlaceholderTransaction();
75 :
76 : // Do we auto absorb any and all transaction?
77 : bool mAbsorb;
78 : nsWeakPtr mForwarding;
79 : // First IME txn in this placeholder - used for IME merging.
80 : mozilla::CompositionTransaction* mCompositionTransaction;
81 : // Do we stop auto absorbing any matching placeholder transactions?
82 : bool mCommitted;
83 :
84 : // These next two members store the state of the selection in a safe way.
85 : // Selection at the start of the transaction is stored, as is the selection
86 : // at the end. This is so that UndoTransaction() and RedoTransaction() can
87 : // restore the selection properly.
88 :
89 : // Use a pointer because this is constructed before we exist.
90 : UniquePtr<SelectionState> mStartSel;
91 : SelectionState mEndSel;
92 :
93 : // The editor for this transaction.
94 : RefPtr<EditorBase> mEditorBase;
95 : };
96 :
97 : } // namespace mozilla
98 :
99 : #endif // #ifndef PlaceholderTransaction_h
|