Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / editor / libeditor / CompositionTransaction.h
bloba3b7950346085a74a491ad3f6bc3c44c839776dc
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/. */
6 #ifndef CompositionTransaction_h
7 #define CompositionTransaction_h
9 #include "mozilla/EditTransactionBase.h" // base class
11 #include "mozilla/EditorDOMPoint.h" // EditorDOMPointInText
12 #include "mozilla/WeakPtr.h"
13 #include "nsCycleCollectionParticipant.h" // various macros
14 #include "nsString.h" // mStringToInsert
16 namespace mozilla {
18 class EditorBase;
19 class TextComposition;
20 class TextRangeArray;
22 namespace dom {
23 class Text;
24 } // namespace dom
26 /**
27 * CompositionTransaction stores all edit for a composition, i.e.,
28 * from compositionstart event to compositionend event. E.g., inserting a
29 * composition string, modifying the composition string or its IME selection
30 * ranges and commit or cancel the composition.
32 class CompositionTransaction final : public EditTransactionBase,
33 public SupportsWeakPtr {
34 protected:
35 CompositionTransaction(EditorBase& aEditorBase,
36 const nsAString& aStringToInsert,
37 const EditorDOMPointInText& aPointToInsert);
39 public:
40 /**
41 * Creates a composition transaction. aEditorBase must not return from
42 * GetComposition() while calling this method. Note that this method will
43 * update text node information of aEditorBase.mComposition.
45 * @param aEditorBase The editor which has composition.
46 * @param aStringToInsert The new composition string to insert. This may
47 * be different from actual composition string.
48 * E.g., password editor can hide the character
49 * with a different character.
50 * @param aPointToInsert The insertion point.
52 static already_AddRefed<CompositionTransaction> Create(
53 EditorBase& aEditorBase, const nsAString& aStringToInsert,
54 const EditorDOMPointInText& aPointToInsert);
56 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CompositionTransaction,
57 EditTransactionBase)
59 NS_DECL_ISUPPORTS_INHERITED
61 NS_DECL_EDITTRANSACTIONBASE
62 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(CompositionTransaction)
64 NS_IMETHOD Merge(nsITransaction* aOtherTransaction, bool* aDidMerge) override;
66 void MarkFixed();
68 MOZ_CAN_RUN_SCRIPT static nsresult SetIMESelection(
69 EditorBase& aEditorBase, dom::Text* aTextNode, uint32_t aOffsetInNode,
70 uint32_t aLengthOfCompositionString, const TextRangeArray* aRanges);
72 private:
73 virtual ~CompositionTransaction() = default;
75 MOZ_CAN_RUN_SCRIPT nsresult SetSelectionForRanges();
77 // The text element to operate upon.
78 RefPtr<dom::Text> mTextNode;
80 // The offsets into mTextNode where the insertion should be placed.
81 uint32_t mOffset;
83 uint32_t mReplaceLength;
85 // The range list.
86 RefPtr<TextRangeArray> mRanges;
88 // The text to insert into mTextNode at mOffset.
89 nsString mStringToInsert;
91 // The editor, which is used to get the selection controller.
92 RefPtr<EditorBase> mEditorBase;
94 bool mFixed;
97 } // namespace mozilla
99 #endif // #ifndef CompositionTransaction_h