1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DeleteMultipleRangesTransaction.h"
#include "DeleteContentTransactionBase.h"
#include "DeleteRangeTransaction.h"
#include "EditorBase.h"
#include "EditorDOMPoint.h"
#include "EditTransactionBase.h"
#include "nsDebug.h"
namespace mozilla {
NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteMultipleRangesTransaction,
EditAggregateTransaction)
NS_IMPL_ADDREF_INHERITED(DeleteMultipleRangesTransaction,
EditAggregateTransaction)
NS_IMPL_RELEASE_INHERITED(DeleteMultipleRangesTransaction,
EditAggregateTransaction)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteMultipleRangesTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
NS_IMETHODIMP DeleteMultipleRangesTransaction::DoTransaction() {
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
"Start==============================",
this, __FUNCTION__,
nsAtomCString(mName ? mName.get() : nsGkAtoms::_empty).get()));
nsresult rv = EditAggregateTransaction::DoTransaction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditAggregateTransaction::DoTransaction() failed");
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
"End==============================",
this, __FUNCTION__,
nsAtomCString(mName ? mName.get() : nsGkAtoms::_empty).get()));
return rv;
}
NS_IMETHODIMP DeleteMultipleRangesTransaction::UndoTransaction() {
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
"Start==============================",
this, __FUNCTION__,
nsAtomCString(mName ? mName.get() : nsGkAtoms::_empty).get()));
nsresult rv = EditAggregateTransaction::UndoTransaction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditAggregateTransaction::UndoTransaction() failed");
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
"End==============================",
this, __FUNCTION__,
nsAtomCString(mName ? mName.get() : nsGkAtoms::_empty).get()));
return rv;
}
NS_IMETHODIMP DeleteMultipleRangesTransaction::RedoTransaction() {
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
"Start==============================",
this, __FUNCTION__,
nsAtomCString(mName ? mName.get() : nsGkAtoms::_empty).get()));
nsresult rv = EditAggregateTransaction::RedoTransaction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditAggregateTransaction::RedoTransaction() failed");
MOZ_LOG(GetLogModule(), LogLevel::Info,
("%p DeleteMultipleRangesTransaction::%s this={ mName=%s } "
"End==============================",
this, __FUNCTION__,
nsAtomCString(mName ? mName.get() : nsGkAtoms::_empty).get()));
return rv;
}
void DeleteMultipleRangesTransaction::AppendChild(
DeleteContentTransactionBase& aTransaction) {
mChildren.AppendElement(aTransaction);
}
void DeleteMultipleRangesTransaction::AppendChild(
DeleteRangeTransaction& aTransaction) {
mChildren.AppendElement(aTransaction);
}
EditorDOMPoint DeleteMultipleRangesTransaction::SuggestPointToPutCaret() const {
for (const OwningNonNull<EditTransactionBase>& transaction :
Reversed(mChildren)) {
if (const DeleteContentTransactionBase* deleteContentTransaction =
transaction->GetAsDeleteContentTransactionBase()) {
EditorDOMPoint pointToPutCaret =
deleteContentTransaction->SuggestPointToPutCaret();
if (pointToPutCaret.IsSet()) {
return pointToPutCaret;
}
continue;
}
if (const DeleteRangeTransaction* deleteRangeTransaction =
transaction->GetAsDeleteRangeTransaction()) {
EditorDOMPoint pointToPutCaret =
deleteRangeTransaction->SuggestPointToPutCaret();
if (pointToPutCaret.IsSet()) {
return pointToPutCaret;
}
continue;
}
MOZ_ASSERT_UNREACHABLE(
"Child transactions must be DeleteContentTransactionBase or "
"DeleteRangeTransaction");
}
return EditorDOMPoint();
}
} // namespace mozilla
|