Line data Source code
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 CompositionTransaction_h
7 : #define CompositionTransaction_h
8 :
9 : #include "mozilla/EditTransactionBase.h" // base class
10 : #include "nsCycleCollectionParticipant.h" // various macros
11 : #include "nsString.h" // mStringToInsert
12 :
13 : #define NS_IMETEXTTXN_IID \
14 : { 0xb391355d, 0x346c, 0x43d1, \
15 : { 0x85, 0xed, 0x9e, 0x65, 0xbe, 0xe7, 0x7e, 0x48 } }
16 :
17 : namespace mozilla {
18 :
19 : class EditorBase;
20 : class RangeUpdater;
21 : class TextRangeArray;
22 :
23 : namespace dom {
24 : class Text;
25 : } // namespace dom
26 :
27 : /**
28 : * CompositionTransaction stores all edit for a composition, i.e.,
29 : * from compositionstart event to compositionend event. E.g., inserting a
30 : * composition string, modifying the composition string or its IME selection
31 : * ranges and commit or cancel the composition.
32 : */
33 : class CompositionTransaction final : public EditTransactionBase
34 : {
35 : public:
36 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMETEXTTXN_IID)
37 :
38 : /**
39 : * @param aTextNode The start node of text content.
40 : * @param aOffset The location in aTextNode to do the insertion.
41 : * @param aReplaceLength The length of text to replace. 0 means not
42 : * replacing existing text.
43 : * @param aTextRangeArray Clauses and/or caret information. This may be
44 : * null.
45 : * @param aString The new text to insert.
46 : * @param aEditorBase Used to get and set the selection.
47 : * @param aRangeUpdater The range updater
48 : */
49 : CompositionTransaction(dom::Text& aTextNode,
50 : uint32_t aOffset, uint32_t aReplaceLength,
51 : TextRangeArray* aTextRangeArray,
52 : const nsAString& aString,
53 : EditorBase& aEditorBase,
54 : RangeUpdater* aRangeUpdater);
55 :
56 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CompositionTransaction,
57 : EditTransactionBase)
58 :
59 : NS_DECL_ISUPPORTS_INHERITED
60 :
61 : NS_DECL_EDITTRANSACTIONBASE
62 :
63 : NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
64 :
65 : void MarkFixed();
66 :
67 : static nsresult SetIMESelection(EditorBase& aEditorBase,
68 : dom::Text* aTextNode,
69 : uint32_t aOffsetInNode,
70 : uint32_t aLengthOfCompositionString,
71 : const TextRangeArray* aRanges);
72 :
73 : private:
74 : ~CompositionTransaction();
75 :
76 : nsresult SetSelectionForRanges();
77 :
78 : // The text element to operate upon.
79 : RefPtr<dom::Text> mTextNode;
80 :
81 : // The offsets into mTextNode where the insertion should be placed.
82 : uint32_t mOffset;
83 :
84 : uint32_t mReplaceLength;
85 :
86 : // The range list.
87 : RefPtr<TextRangeArray> mRanges;
88 :
89 : // The text to insert into mTextNode at mOffset.
90 : nsString mStringToInsert;
91 :
92 : // The editor, which is used to get the selection controller.
93 : RefPtr<EditorBase> mEditorBase;
94 :
95 : RangeUpdater* mRangeUpdater;
96 :
97 : bool mFixed;
98 : };
99 :
100 : NS_DEFINE_STATIC_IID_ACCESSOR(CompositionTransaction, NS_IMETEXTTXN_IID)
101 :
102 : } // namespace mozilla
103 :
104 : #endif // #ifndef CompositionTransaction_h
|