michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef InsertTextTxn_h__ michael@0: #define InsertTextTxn_h__ michael@0: michael@0: #include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN michael@0: #include "nsCOMPtr.h" // for nsCOMPtr michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsID.h" // for nsIID michael@0: #include "nsIDOMCharacterData.h" // for nsIDOMCharacterData michael@0: #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED michael@0: #include "nsString.h" // for nsString michael@0: #include "nscore.h" // for NS_IMETHOD, nsAString michael@0: michael@0: class nsIEditor; michael@0: class nsITransaction; michael@0: michael@0: michael@0: #define INSERT_TEXT_TXN_CID \ michael@0: {/* 93276f00-ab2c-11d2-8f4b-006008159b0c*/ \ michael@0: 0x93276f00, 0xab2c, 0x11d2, \ michael@0: {0x8f, 0xb4, 0x0, 0x60, 0x8, 0x15, 0x9b, 0xc} } michael@0: michael@0: /** michael@0: * A transaction that inserts text into a content node. michael@0: */ michael@0: class InsertTextTxn : public EditTxn michael@0: { michael@0: public: michael@0: michael@0: static const nsIID& GetCID() { static const nsIID iid = INSERT_TEXT_TXN_CID; return iid; } michael@0: michael@0: /** initialize the transaction michael@0: * @param aElement the text content node michael@0: * @param aOffset the location in aElement to do the insertion michael@0: * @param aString the new text to insert michael@0: * @param aPresShell used to get and set the selection michael@0: */ michael@0: NS_IMETHOD Init(nsIDOMCharacterData *aElement, michael@0: uint32_t aOffset, michael@0: const nsAString& aString, michael@0: nsIEditor *aEditor); michael@0: michael@0: InsertTextTxn(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertTextTxn, EditTxn) michael@0: michael@0: NS_DECL_EDITTXN michael@0: michael@0: NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge); michael@0: michael@0: /** return the string data associated with this transaction */ michael@0: NS_IMETHOD GetData(nsString& aResult); michael@0: michael@0: protected: michael@0: michael@0: /** return true if aOtherTxn immediately follows this txn */ michael@0: virtual bool IsSequentialInsert(InsertTextTxn *aOtherTxn); michael@0: michael@0: /** the text element to operate upon */ michael@0: nsCOMPtr mElement; michael@0: michael@0: /** the offset into mElement where the insertion is to take place */ michael@0: uint32_t mOffset; michael@0: michael@0: /** the text to insert into mElement at mOffset */ michael@0: nsString mStringToInsert; michael@0: michael@0: /** the editor, which we'll need to get the selection */ michael@0: nsIEditor *mEditor; michael@0: }; michael@0: michael@0: #endif