Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / editor / libeditor / InsertTextTransaction.h
blob16eccd05aa792f72553feb8734f20306e47ce167
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 InsertTextTransaction_h
7 #define InsertTextTransaction_h
9 #include "mozilla/EditTransactionBase.h" // base class
11 #include "mozilla/EditorDOMPoint.h" // EditorDOMPointInText
12 #include "nsCycleCollectionParticipant.h" // various macros
13 #include "nsID.h" // NS_DECLARE_STATIC_IID_ACCESSOR
14 #include "nsISupportsImpl.h" // NS_DECL_ISUPPORTS_INHERITED
15 #include "nsString.h" // nsString members
16 #include "nscore.h" // NS_IMETHOD, nsAString
18 namespace mozilla {
20 class EditorBase;
22 namespace dom {
23 class Text;
24 } // namespace dom
26 /**
27 * A transaction that inserts text into a content node.
29 class InsertTextTransaction final : public EditTransactionBase {
30 protected:
31 InsertTextTransaction(EditorBase& aEditorBase,
32 const nsAString& aStringToInsert,
33 const EditorDOMPointInText& aPointToInsert);
35 public:
36 /**
37 * Creates new InsertTextTransaction instance. This never returns nullptr.
39 * @param aEditorBase The editor which manages the transaction.
40 * @param aPointToInsert The insertion point.
41 * @param aStringToInsert The new string to insert.
43 static already_AddRefed<InsertTextTransaction> Create(
44 EditorBase& aEditorBase, const nsAString& aStringToInsert,
45 const EditorDOMPointInText& aPointToInsert);
47 NS_DECL_ISUPPORTS_INHERITED
48 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertTextTransaction,
49 EditTransactionBase)
51 NS_DECL_EDITTRANSACTIONBASE
52 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(InsertTextTransaction)
54 NS_IMETHOD Merge(nsITransaction* aOtherTransaction, bool* aDidMerge) override;
56 /**
57 * Return the string data associated with this transaction.
59 void GetData(nsString& aResult);
61 private:
62 virtual ~InsertTextTransaction() = default;
64 // Return true if aOtherTransaction immediately follows this transaction.
65 bool IsSequentialInsert(InsertTextTransaction& aOtherTrasaction);
67 // The Text node to operate upon.
68 RefPtr<dom::Text> mTextNode;
70 // The offset into mTextNode where the insertion is to take place.
71 uint32_t mOffset;
73 // The text to insert into mTextNode at mOffset.
74 nsString mStringToInsert;
76 // The editor, which we'll need to get the selection.
77 RefPtr<EditorBase> mEditorBase;
80 } // namespace mozilla
82 #endif // #ifndef InsertTextTransaction_h