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 #include "DeleteMultipleRangesTransaction.h"
8 #include "DeleteContentTransactionBase.h"
9 #include "DeleteRangeTransaction.h"
10 #include "EditorBase.h"
11 #include "EditorDOMPoint.h"
12 #include "EditTransactionBase.h"
18 NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteMultipleRangesTransaction
,
19 EditAggregateTransaction
)
21 NS_IMPL_ADDREF_INHERITED(DeleteMultipleRangesTransaction
,
22 EditAggregateTransaction
)
23 NS_IMPL_RELEASE_INHERITED(DeleteMultipleRangesTransaction
,
24 EditAggregateTransaction
)
25 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteMultipleRangesTransaction
)
26 NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction
)
28 NS_IMETHODIMP
DeleteMultipleRangesTransaction::DoTransaction() {
29 MOZ_LOG(GetLogModule(), LogLevel::Info
,
30 ("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
31 "Start==============================",
33 nsAtomCString(mName
? mName
.get() : nsGkAtoms::_empty
).get()));
34 nsresult rv
= EditAggregateTransaction::DoTransaction();
35 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv
),
36 "EditAggregateTransaction::DoTransaction() failed");
38 MOZ_LOG(GetLogModule(), LogLevel::Info
,
39 ("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
40 "End==============================",
42 nsAtomCString(mName
? mName
.get() : nsGkAtoms::_empty
).get()));
46 NS_IMETHODIMP
DeleteMultipleRangesTransaction::UndoTransaction() {
47 MOZ_LOG(GetLogModule(), LogLevel::Info
,
48 ("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
49 "Start==============================",
51 nsAtomCString(mName
? mName
.get() : nsGkAtoms::_empty
).get()));
53 nsresult rv
= EditAggregateTransaction::UndoTransaction();
54 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv
),
55 "EditAggregateTransaction::UndoTransaction() failed");
57 MOZ_LOG(GetLogModule(), LogLevel::Info
,
58 ("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
59 "End==============================",
61 nsAtomCString(mName
? mName
.get() : nsGkAtoms::_empty
).get()));
65 NS_IMETHODIMP
DeleteMultipleRangesTransaction::RedoTransaction() {
66 MOZ_LOG(GetLogModule(), LogLevel::Info
,
67 ("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
68 "Start==============================",
70 nsAtomCString(mName
? mName
.get() : nsGkAtoms::_empty
).get()));
72 nsresult rv
= EditAggregateTransaction::RedoTransaction();
73 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv
),
74 "EditAggregateTransaction::RedoTransaction() failed");
76 MOZ_LOG(GetLogModule(), LogLevel::Info
,
77 ("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
78 "End==============================",
80 nsAtomCString(mName
? mName
.get() : nsGkAtoms::_empty
).get()));
84 void DeleteMultipleRangesTransaction::AppendChild(
85 DeleteContentTransactionBase
& aTransaction
) {
86 mChildren
.AppendElement(aTransaction
);
89 void DeleteMultipleRangesTransaction::AppendChild(
90 DeleteRangeTransaction
& aTransaction
) {
91 mChildren
.AppendElement(aTransaction
);
94 EditorDOMPoint
DeleteMultipleRangesTransaction::SuggestPointToPutCaret() const {
95 for (const OwningNonNull
<EditTransactionBase
>& transaction
:
96 Reversed(mChildren
)) {
97 if (const DeleteContentTransactionBase
* deleteContentTransaction
=
98 transaction
->GetAsDeleteContentTransactionBase()) {
99 EditorDOMPoint pointToPutCaret
=
100 deleteContentTransaction
->SuggestPointToPutCaret();
101 if (pointToPutCaret
.IsSet()) {
102 return pointToPutCaret
;
106 if (const DeleteRangeTransaction
* deleteRangeTransaction
=
107 transaction
->GetAsDeleteRangeTransaction()) {
108 EditorDOMPoint pointToPutCaret
=
109 deleteRangeTransaction
->SuggestPointToPutCaret();
110 if (pointToPutCaret
.IsSet()) {
111 return pointToPutCaret
;
115 MOZ_ASSERT_UNREACHABLE(
116 "Child transactions must be DeleteContentTransactionBase or "
117 "DeleteRangeTransaction");
119 return EditorDOMPoint();
122 } // namespace mozilla