1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/base/PlaceholderTxn.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef AggregatePlaceholderTxn_h__ 1.10 +#define AggregatePlaceholderTxn_h__ 1.11 + 1.12 +#include "EditAggregateTxn.h" 1.13 +#include "nsEditorUtils.h" 1.14 +#include "nsIAbsorbingTransaction.h" 1.15 +#include "nsIDOMNode.h" 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsWeakPtr.h" 1.18 +#include "nsWeakReference.h" 1.19 +#include "nsAutoPtr.h" 1.20 + 1.21 +class nsHTMLEditor; 1.22 +class IMETextTxn; 1.23 + 1.24 +/** 1.25 + * An aggregate transaction that knows how to absorb all subsequent 1.26 + * transactions with the same name. This transaction does not "Do" anything. 1.27 + * But it absorbs other transactions via merge, and can undo/redo the 1.28 + * transactions it has absorbed. 1.29 + */ 1.30 + 1.31 +class PlaceholderTxn : public EditAggregateTxn, 1.32 + public nsIAbsorbingTransaction, 1.33 + public nsSupportsWeakReference 1.34 +{ 1.35 +public: 1.36 + NS_DECL_ISUPPORTS_INHERITED 1.37 + 1.38 + PlaceholderTxn(); 1.39 + 1.40 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTxn, EditAggregateTxn) 1.41 +// ------------ EditAggregateTxn ----------------------- 1.42 + 1.43 + NS_DECL_EDITTXN 1.44 + 1.45 + NS_IMETHOD RedoTransaction(); 1.46 + NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge); 1.47 + 1.48 +// ------------ nsIAbsorbingTransaction ----------------------- 1.49 + 1.50 + NS_IMETHOD Init(nsIAtom* aName, nsSelectionState* aSelState, 1.51 + nsEditor* aEditor); 1.52 + 1.53 + NS_IMETHOD GetTxnName(nsIAtom **aName); 1.54 + 1.55 + NS_IMETHOD StartSelectionEquals(nsSelectionState *aSelState, bool *aResult); 1.56 + 1.57 + NS_IMETHOD EndPlaceHolderBatch(); 1.58 + 1.59 + NS_IMETHOD ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress); 1.60 + 1.61 + NS_IMETHOD Commit(); 1.62 + 1.63 + NS_IMETHOD RememberEndingSelection(); 1.64 + 1.65 +protected: 1.66 + 1.67 + /** the presentation shell, which we'll need to get the selection */ 1.68 + bool mAbsorb; // do we auto absorb any and all transaction? 1.69 + nsWeakPtr mForwarding; 1.70 + IMETextTxn *mIMETextTxn; // first IME txn in this placeholder - used for IME merging 1.71 + // non-owning for now - can't nsCOMPtr it due to broken transaction interfaces 1.72 + bool mCommitted; // do we stop auto absorbing any matching placeholder txns? 1.73 + // these next two members store the state of the selection in a safe way. 1.74 + // selection at the start of the txn is stored, as is the selection at the end. 1.75 + // This is so that UndoTransaction() and RedoTransaction() can restore the 1.76 + // selection properly. 1.77 + nsAutoPtr<nsSelectionState> mStartSel; // use a pointer because this is constructed before we exist 1.78 + nsSelectionState mEndSel; 1.79 + nsEditor* mEditor; /** the editor for this transaction */ 1.80 +}; 1.81 + 1.82 + 1.83 +#endif