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