editor/libeditor/base/InsertTextTxn.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:e11740c73cba
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 InsertTextTxn_h__
7 #define InsertTextTxn_h__
8
9 #include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN
10 #include "nsCOMPtr.h" // for nsCOMPtr
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsID.h" // for nsIID
13 #include "nsIDOMCharacterData.h" // for nsIDOMCharacterData
14 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
15 #include "nsString.h" // for nsString
16 #include "nscore.h" // for NS_IMETHOD, nsAString
17
18 class nsIEditor;
19 class nsITransaction;
20
21
22 #define INSERT_TEXT_TXN_CID \
23 {/* 93276f00-ab2c-11d2-8f4b-006008159b0c*/ \
24 0x93276f00, 0xab2c, 0x11d2, \
25 {0x8f, 0xb4, 0x0, 0x60, 0x8, 0x15, 0x9b, 0xc} }
26
27 /**
28 * A transaction that inserts text into a content node.
29 */
30 class InsertTextTxn : public EditTxn
31 {
32 public:
33
34 static const nsIID& GetCID() { static const nsIID iid = INSERT_TEXT_TXN_CID; return iid; }
35
36 /** initialize the transaction
37 * @param aElement the text content node
38 * @param aOffset the location in aElement to do the insertion
39 * @param aString the new text to insert
40 * @param aPresShell used to get and set the selection
41 */
42 NS_IMETHOD Init(nsIDOMCharacterData *aElement,
43 uint32_t aOffset,
44 const nsAString& aString,
45 nsIEditor *aEditor);
46
47 InsertTextTxn();
48
49 NS_DECL_ISUPPORTS_INHERITED
50 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertTextTxn, EditTxn)
51
52 NS_DECL_EDITTXN
53
54 NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge);
55
56 /** return the string data associated with this transaction */
57 NS_IMETHOD GetData(nsString& aResult);
58
59 protected:
60
61 /** return true if aOtherTxn immediately follows this txn */
62 virtual bool IsSequentialInsert(InsertTextTxn *aOtherTxn);
63
64 /** the text element to operate upon */
65 nsCOMPtr<nsIDOMCharacterData> mElement;
66
67 /** the offset into mElement where the insertion is to take place */
68 uint32_t mOffset;
69
70 /** the text to insert into mElement at mOffset */
71 nsString mStringToInsert;
72
73 /** the editor, which we'll need to get the selection */
74 nsIEditor *mEditor;
75 };
76
77 #endif

mercurial