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 "DeleteContentTransactionBase.h"
11 #include "EditorForwards.h"
13 #include "mozilla/dom/Text.h"
16 #include "nsCycleCollectionParticipant.h"
24 * A transaction that removes text from a content node.
26 class DeleteTextTransaction final
: public DeleteContentTransactionBase
{
28 DeleteTextTransaction(EditorBase
& aEditorBase
, dom::Text
& aTextNode
,
29 uint32_t aOffset
, uint32_t aLengthToDelete
);
33 * Creates a delete text transaction to remove given range. This returns
34 * nullptr if it cannot modify the text node.
36 * @param aEditorBase The provider of basic editing operations.
37 * @param aTextNode The content node to remove text from.
38 * @param aOffset The location in aElement to begin the deletion.
39 * @param aLenthToDelete The length to delete.
41 static already_AddRefed
<DeleteTextTransaction
> MaybeCreate(
42 EditorBase
& aEditorBase
, dom::Text
& aTextNode
, uint32_t aOffset
,
43 uint32_t aLengthToDelete
);
46 * Creates a delete text transaction to remove a previous or next character.
47 * Those methods MAY return nullptr.
49 * @param aEditorBase The provider of basic editing operations.
50 * @param aTextNode The content node to remove text from.
51 * @param aOffset The location in aElement to begin the deletion.
53 static already_AddRefed
<DeleteTextTransaction
>
54 MaybeCreateForPreviousCharacter(EditorBase
& aEditorBase
, dom::Text
& aTextNode
,
56 static already_AddRefed
<DeleteTextTransaction
> MaybeCreateForNextCharacter(
57 EditorBase
& aEditorBase
, dom::Text
& aTextNode
, uint32_t aOffset
);
60 * CanDoIt() returns true if there are enough members and can modify the
61 * text. Otherwise, false.
65 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction
,
66 DeleteContentTransactionBase
)
67 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) override
;
69 NS_DECL_EDITTRANSACTIONBASE
70 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteTextTransaction
)
72 MOZ_CAN_RUN_SCRIPT NS_IMETHOD
RedoTransaction() final
;
74 EditorDOMPoint
SuggestPointToPutCaret() const final
;
76 dom::Text
* GetText() const { return mTextNode
; }
77 uint32_t Offset() const { return mOffset
; }
78 uint32_t LengthToDelete() const { return mLengthToDelete
; }
80 friend std::ostream
& operator<<(std::ostream
& aStream
,
81 const DeleteTextTransaction
& aTransaction
);
84 // The CharacterData node to operate upon.
85 RefPtr
<dom::Text
> mTextNode
;
87 // The offset into mTextNode where the deletion is to take place.
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