Bug 1769033 - Add OpenBSD sandboxing support r=gaston
[gecko.git] / editor / libeditor / DeleteTextTransaction.h
blob8db1d4ae5fa43d0073a1e341ae3214988cb84221
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 DeleteTextTransaction_h
7 #define DeleteTextTransaction_h
9 #include "EditTransactionBase.h"
11 #include "EditorForwards.h"
13 #include "mozilla/dom/Text.h"
14 #include "nsCOMPtr.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsID.h"
17 #include "nsString.h"
18 #include "nscore.h"
20 namespace mozilla {
22 /**
23 * A transaction that removes text from a content node.
25 class DeleteTextTransaction final : public EditTransactionBase {
26 protected:
27 DeleteTextTransaction(EditorBase& aEditorBase, dom::Text& aTextNode,
28 uint32_t aOffset, uint32_t aLengthToDelete);
30 public:
31 /**
32 * Creates a delete text transaction to remove given range. This returns
33 * nullptr if it cannot modify the text node.
35 * @param aEditorBase The provider of basic editing operations.
36 * @param aTextNode The content node to remove text from.
37 * @param aOffset The location in aElement to begin the deletion.
38 * @param aLenthToDelete The length to delete.
40 static already_AddRefed<DeleteTextTransaction> MaybeCreate(
41 EditorBase& aEditorBase, dom::Text& aTextNode, uint32_t aOffset,
42 uint32_t aLengthToDelete);
44 /**
45 * Creates a delete text transaction to remove a previous or next character.
46 * Those methods MAY return nullptr.
48 * @param aEditorBase The provider of basic editing operations.
49 * @param aTextNode The content node to remove text from.
50 * @param aOffset The location in aElement to begin the deletion.
52 static already_AddRefed<DeleteTextTransaction>
53 MaybeCreateForPreviousCharacter(EditorBase& aEditorBase, dom::Text& aTextNode,
54 uint32_t aOffset);
55 static already_AddRefed<DeleteTextTransaction> MaybeCreateForNextCharacter(
56 EditorBase& aEditorBase, dom::Text& aTextNode, uint32_t aOffset);
58 /**
59 * CanDoIt() returns true if there are enough members and can modify the
60 * text. Otherwise, false.
62 bool CanDoIt() const;
64 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction,
65 EditTransactionBase)
66 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
68 NS_DECL_EDITTRANSACTIONBASE
69 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteTextTransaction)
71 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
73 dom::Text* GetText() const { return mTextNode; }
74 uint32_t Offset() const { return mOffset; }
75 uint32_t LengthToDelete() const { return mLengthToDelete; }
77 friend std::ostream& operator<<(std::ostream& aStream,
78 const DeleteTextTransaction& aTransaction);
80 protected:
81 // The provider of basic editing operations.
82 RefPtr<EditorBase> mEditorBase;
84 // The CharacterData node to operate upon.
85 RefPtr<dom::Text> mTextNode;
87 // The offset into mTextNode where the deletion is to take place.
88 uint32_t mOffset;
90 // The length to delete.
91 uint32_t mLengthToDelete;
93 // The text that was deleted.
94 nsString mDeletedText;
97 } // namespace mozilla
99 #endif // #ifndef DeleteTextTransaction_h