1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/base/InsertTextTxn.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 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 InsertTextTxn_h__ 1.10 +#define InsertTextTxn_h__ 1.11 + 1.12 +#include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN 1.13 +#include "nsCOMPtr.h" // for nsCOMPtr 1.14 +#include "nsCycleCollectionParticipant.h" 1.15 +#include "nsID.h" // for nsIID 1.16 +#include "nsIDOMCharacterData.h" // for nsIDOMCharacterData 1.17 +#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED 1.18 +#include "nsString.h" // for nsString 1.19 +#include "nscore.h" // for NS_IMETHOD, nsAString 1.20 + 1.21 +class nsIEditor; 1.22 +class nsITransaction; 1.23 + 1.24 + 1.25 +#define INSERT_TEXT_TXN_CID \ 1.26 +{/* 93276f00-ab2c-11d2-8f4b-006008159b0c*/ \ 1.27 +0x93276f00, 0xab2c, 0x11d2, \ 1.28 +{0x8f, 0xb4, 0x0, 0x60, 0x8, 0x15, 0x9b, 0xc} } 1.29 + 1.30 +/** 1.31 + * A transaction that inserts text into a content node. 1.32 + */ 1.33 +class InsertTextTxn : public EditTxn 1.34 +{ 1.35 +public: 1.36 + 1.37 + static const nsIID& GetCID() { static const nsIID iid = INSERT_TEXT_TXN_CID; return iid; } 1.38 + 1.39 + /** initialize the transaction 1.40 + * @param aElement the text content node 1.41 + * @param aOffset the location in aElement to do the insertion 1.42 + * @param aString the new text to insert 1.43 + * @param aPresShell used to get and set the selection 1.44 + */ 1.45 + NS_IMETHOD Init(nsIDOMCharacterData *aElement, 1.46 + uint32_t aOffset, 1.47 + const nsAString& aString, 1.48 + nsIEditor *aEditor); 1.49 + 1.50 + InsertTextTxn(); 1.51 + 1.52 + NS_DECL_ISUPPORTS_INHERITED 1.53 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertTextTxn, EditTxn) 1.54 + 1.55 + NS_DECL_EDITTXN 1.56 + 1.57 + NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge); 1.58 + 1.59 + /** return the string data associated with this transaction */ 1.60 + NS_IMETHOD GetData(nsString& aResult); 1.61 + 1.62 +protected: 1.63 + 1.64 + /** return true if aOtherTxn immediately follows this txn */ 1.65 + virtual bool IsSequentialInsert(InsertTextTxn *aOtherTxn); 1.66 + 1.67 + /** the text element to operate upon */ 1.68 + nsCOMPtr<nsIDOMCharacterData> mElement; 1.69 + 1.70 + /** the offset into mElement where the insertion is to take place */ 1.71 + uint32_t mOffset; 1.72 + 1.73 + /** the text to insert into mElement at mOffset */ 1.74 + nsString mStringToInsert; 1.75 + 1.76 + /** the editor, which we'll need to get the selection */ 1.77 + nsIEditor *mEditor; 1.78 +}; 1.79 + 1.80 +#endif