Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / DeleteRangeTransaction.h
blob4de8fd09e775cafd43b381e7cae75ca3a61decc9
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 DeleteRangeTransaction_h
7 #define DeleteRangeTransaction_h
9 #include "EditAggregateTransaction.h"
11 #include "EditorForwards.h"
13 #include "mozilla/RangeBoundary.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsID.h"
16 #include "nsIEditor.h"
17 #include "nsISupportsImpl.h"
18 #include "nsRange.h"
19 #include "nscore.h"
21 class nsINode;
23 namespace mozilla {
25 /**
26 * A transaction that deletes an entire range in the content tree
28 class DeleteRangeTransaction final : public EditAggregateTransaction {
29 protected:
30 DeleteRangeTransaction(EditorBase& aEditorBase,
31 const nsRange& aRangeToDelete);
33 public:
34 /**
35 * Creates a delete range transaction. This never returns nullptr.
37 * @param aEditorBase The object providing basic editing operations.
38 * @param aRangeToDelete The range to delete.
40 static already_AddRefed<DeleteRangeTransaction> Create(
41 EditorBase& aEditorBase, const nsRange& aRangeToDelete) {
42 RefPtr<DeleteRangeTransaction> transaction =
43 new DeleteRangeTransaction(aEditorBase, aRangeToDelete);
44 return transaction.forget();
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteRangeTransaction,
48 EditAggregateTransaction)
49 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
51 NS_DECL_EDITTRANSACTIONBASE
52 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteRangeTransaction)
54 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
56 protected:
57 /**
58 * CreateTxnsToDeleteBetween() creates a DeleteTextTransaction or some
59 * DeleteNodeTransactions to remove text or nodes between aStart and aEnd
60 * and appends the created transactions to the array.
62 * @param aStart Must be set and valid point.
63 * @param aEnd Must be set and valid point. Additionally, the
64 * container must be same as aStart's container.
65 * And of course, this must not be before aStart in
66 * the DOM tree order.
67 * @return Returns NS_OK in most cases.
68 * When the arguments are invalid, returns
69 * NS_ERROR_INVALID_ARG.
70 * When mEditorBase isn't available, returns
71 * NS_ERROR_NOT_AVAIALBLE.
72 * When created DeleteTextTransaction cannot do its
73 * transaction, returns NS_ERROR_FAILURE.
74 * Note that even if one of created DeleteNodeTransaction
75 * cannot do its transaction, this returns NS_OK.
77 nsresult CreateTxnsToDeleteBetween(const RawRangeBoundary& aStart,
78 const RawRangeBoundary& aEnd);
80 nsresult CreateTxnsToDeleteNodesBetween(nsRange* aRangeToDelete);
82 /**
83 * CreateTxnsToDeleteContent() creates a DeleteTextTransaction to delete
84 * text between start of aPoint.GetContainer() and aPoint or aPoint and end of
85 * aPoint.GetContainer() and appends the created transaction to the array.
87 * @param aPoint Must be set and valid point. If the container is not
88 * a data node, this method does nothing.
89 * @param aAction If nsIEditor::eNext, this method creates a transaction
90 * to delete text from aPoint to the end of the data node.
91 * Otherwise, this method creates a transaction to delete
92 * text from start of the data node to aPoint.
93 * @return Returns NS_OK in most cases.
94 * When the arguments are invalid, returns
95 * NS_ERROR_INVALID_ARG.
96 * When mEditorBase isn't available, returns
97 * NS_ERROR_NOT_AVAIALBLE.
98 * When created DeleteTextTransaction cannot do its
99 * transaction, returns NS_ERROR_FAILURE.
100 * Note that even if no character will be deleted,
101 * this returns NS_OK.
103 nsresult CreateTxnsToDeleteContent(const RawRangeBoundary& aPoint,
104 nsIEditor::EDirection aAction);
106 // The editor for this transaction.
107 RefPtr<EditorBase> mEditorBase;
109 // P1 in the range. This is only non-null until DoTransaction is called and
110 // we convert it into child transactions.
111 RefPtr<nsRange> mRangeToDelete;
114 } // namespace mozilla
116 #endif // #ifndef DeleteRangeTransaction_h