Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 sw=2 et tw=78: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_SetTextTransaction_h
8 : #define mozilla_SetTextTransaction_h
9 :
10 : #include "mozilla/EditTransactionBase.h" // base class
11 : #include "nsCycleCollectionParticipant.h" // various macros
12 : #include "nsID.h" // NS_DECLARE_STATIC_IID_ACCESSOR
13 : #include "nsISupportsImpl.h" // NS_DECL_ISUPPORTS_INHERITED
14 : #include "nsString.h" // nsString members
15 : #include "nscore.h" // NS_IMETHOD, nsAString
16 :
17 : class nsITransaction;
18 :
19 : #define NS_SETTEXTTXN_IID \
20 : { 0x568bac0b, 0xa42a, 0x4150, \
21 : { 0xbd, 0x90, 0x34, 0xd0, 0x2f, 0x32, 0x74, 0x2e } }
22 :
23 : namespace mozilla {
24 :
25 : class EditorBase;
26 : class RangeUpdater;
27 :
28 : namespace dom {
29 : class Text;
30 : } // namespace dom
31 :
32 : /**
33 : * A transaction that inserts text into a content node.
34 : */
35 : class SetTextTransaction final : public EditTransactionBase
36 : {
37 : public:
38 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_SETTEXTTXN_IID)
39 :
40 : /**
41 : * @param aTextNode The text content node.
42 : * @param aString The new text to insert.
43 : * @param aEditorBase Used to get and set the selection.
44 : * @param aRangeUpdater The range updater
45 : */
46 : SetTextTransaction(dom::Text& aTextNode,
47 : const nsAString& aString, EditorBase& aEditorBase,
48 : RangeUpdater* aRangeUpdater);
49 :
50 : NS_DECL_ISUPPORTS_INHERITED
51 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SetTextTransaction,
52 : EditTransactionBase)
53 :
54 : NS_DECL_EDITTRANSACTIONBASE
55 :
56 : NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
57 :
58 : private:
59 : virtual ~SetTextTransaction();
60 :
61 : // The Text node to operate upon.
62 : RefPtr<dom::Text> mTextNode;
63 :
64 : // The text to insert into mTextNode at mOffset.
65 : nsString mStringToSet;
66 :
67 : // The previous text for undo
68 : nsString mPreviousData;
69 :
70 : // The editor, which we'll need to get the selection.
71 : RefPtr<EditorBase> mEditorBase;
72 :
73 : RangeUpdater* mRangeUpdater;
74 : };
75 :
76 : NS_DEFINE_STATIC_IID_ACCESSOR(SetTextTransaction, NS_SETTEXTTXN_IID)
77 :
78 : } // namespace mozilla
79 :
80 : #endif // #ifndef mozilla_SetTextTransaction_h
|