mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 05:48:26 +00:00
Bug 1626570 - Improve handling of copying arrays in editor/. r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D73631
This commit is contained in:
parent
da5ea0875b
commit
5ab15e9640
@ -22,8 +22,8 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
|
||||
|
||||
NS_IMETHODIMP EditAggregateTransaction::DoTransaction() {
|
||||
// FYI: It's legal (but not very useful) to have an empty child list.
|
||||
AutoTArray<OwningNonNull<EditTransactionBase>, 10> children(mChildren);
|
||||
for (OwningNonNull<EditTransactionBase>& childTransaction : children) {
|
||||
for (const OwningNonNull<EditTransactionBase>& childTransaction :
|
||||
CopyableAutoTArray<OwningNonNull<EditTransactionBase>, 10>(mChildren)) {
|
||||
nsresult rv = MOZ_KnownLive(childTransaction)->DoTransaction();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditTransactionBase::DoTransaction() failed");
|
||||
@ -36,8 +36,9 @@ NS_IMETHODIMP EditAggregateTransaction::DoTransaction() {
|
||||
NS_IMETHODIMP EditAggregateTransaction::UndoTransaction() {
|
||||
// FYI: It's legal (but not very useful) to have an empty child list.
|
||||
// Undo goes through children backwards.
|
||||
AutoTArray<OwningNonNull<EditTransactionBase>, 10> children(mChildren);
|
||||
for (OwningNonNull<EditTransactionBase>& childTransaction :
|
||||
const CopyableAutoTArray<OwningNonNull<EditTransactionBase>, 10> children(
|
||||
mChildren);
|
||||
for (const OwningNonNull<EditTransactionBase>& childTransaction :
|
||||
Reversed(children)) {
|
||||
nsresult rv = MOZ_KnownLive(childTransaction)->UndoTransaction();
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -50,8 +51,9 @@ NS_IMETHODIMP EditAggregateTransaction::UndoTransaction() {
|
||||
|
||||
NS_IMETHODIMP EditAggregateTransaction::RedoTransaction() {
|
||||
// It's legal (but not very useful) to have an empty child list.
|
||||
AutoTArray<OwningNonNull<EditTransactionBase>, 10> children(mChildren);
|
||||
for (OwningNonNull<EditTransactionBase>& childTransaction : children) {
|
||||
const CopyableAutoTArray<OwningNonNull<EditTransactionBase>, 10> children(
|
||||
mChildren);
|
||||
for (const OwningNonNull<EditTransactionBase>& childTransaction : children) {
|
||||
nsresult rv = MOZ_KnownLive(childTransaction)->RedoTransaction();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditTransactionBase::RedoTransaction() failed");
|
||||
|
@ -1490,8 +1490,7 @@ already_AddRefed<Element> EditorBase::CreateNodeWithTransaction(
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored = listener->DidCreateNode(
|
||||
nsDependentAtomString(&aTagName), newElement, rv);
|
||||
NS_WARNING_ASSERTION(
|
||||
@ -1564,8 +1563,7 @@ nsresult EditorBase::InsertNodeWithTransaction(
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->DidInsertNode(&aContentToInsert, rv);
|
||||
NS_WARNING_ASSERTION(
|
||||
@ -1666,8 +1664,7 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) {
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored = listener->DidDeleteNode(&aContent, rv);
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rvIgnored),
|
||||
@ -1753,7 +1750,7 @@ void EditorBase::NotifyEditorObservers(
|
||||
|
||||
if (!mEditorObservers.IsEmpty()) {
|
||||
// Copy the observers since EditAction()s can modify mEditorObservers.
|
||||
AutoEditorObserverArray observers(mEditorObservers);
|
||||
AutoEditorObserverArray observers(mEditorObservers.Clone());
|
||||
for (auto& observer : observers) {
|
||||
DebugOnly<nsresult> rvIgnored = observer->EditAction();
|
||||
NS_WARNING_ASSERTION(
|
||||
@ -2544,8 +2541,7 @@ nsresult EditorBase::InsertTextIntoTextNodeWithTransaction(
|
||||
|
||||
// let listeners know what happened
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
// TODO: might need adaptation because of mutation event listeners called
|
||||
// during `DoTransactionInternal`.
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
@ -2612,7 +2608,8 @@ nsresult EditorBase::NotifyDocumentListeners(
|
||||
}
|
||||
// Needs to store all listeners before notifying ComposerCommandsUpdate
|
||||
// since notifying it might change mDocStateListeners.
|
||||
const AutoDocumentStateListenerArray listeners(mDocStateListeners);
|
||||
const AutoDocumentStateListenerArray listeners(
|
||||
mDocStateListeners.Clone());
|
||||
if (composerCommandsUpdate) {
|
||||
composerCommandsUpdate->OnBeforeHTMLEditorDestroyed();
|
||||
}
|
||||
@ -2653,7 +2650,8 @@ nsresult EditorBase::NotifyDocumentListeners(
|
||||
}
|
||||
// Needs to store all listeners before notifying ComposerCommandsUpdate
|
||||
// since notifying it might change mDocStateListeners.
|
||||
const AutoDocumentStateListenerArray listeners(mDocStateListeners);
|
||||
const AutoDocumentStateListenerArray listeners(
|
||||
mDocStateListeners.Clone());
|
||||
if (composerCommandsUpdate) {
|
||||
composerCommandsUpdate->OnHTMLEditorDirtyStateChanged(mDocDirtyState);
|
||||
}
|
||||
@ -2690,8 +2688,7 @@ nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString,
|
||||
|
||||
// Let listeners know what's up
|
||||
if (!mActionListeners.IsEmpty() && length) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->WillDeleteText(&aTextNode, 0, length);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
@ -2727,8 +2724,7 @@ nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString,
|
||||
|
||||
// Let listeners know what happened
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
if (length) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->DidDeleteText(&aTextNode, 0, length, NS_OK);
|
||||
@ -2779,8 +2775,7 @@ nsresult EditorBase::DeleteTextWithTransaction(Text& aTextNode,
|
||||
|
||||
// Let listeners know what's up
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->WillDeleteText(&aTextNode, aOffset, aLength);
|
||||
NS_WARNING_ASSERTION(
|
||||
@ -2800,8 +2795,7 @@ nsresult EditorBase::DeleteTextWithTransaction(Text& aTextNode,
|
||||
|
||||
// Let listeners know what happened
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->DidDeleteText(&aTextNode, aOffset, aLength, rv);
|
||||
NS_WARNING_ASSERTION(
|
||||
@ -4133,7 +4127,7 @@ nsresult EditorBase::DeleteSelectionWithTransaction(
|
||||
// Notify nsIEditActionListener::WillDelete[Selection|Text]
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
if (!deleteContent) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
AutoActionListenerArray listeners(mActionListeners.Clone());
|
||||
for (auto& listener : listeners) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->WillDeleteSelection(SelectionRefPtr());
|
||||
@ -4145,7 +4139,7 @@ nsresult EditorBase::DeleteSelectionWithTransaction(
|
||||
"must not destroy the editor");
|
||||
}
|
||||
} else if (deleteCharData) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
AutoActionListenerArray listeners(mActionListeners.Clone());
|
||||
for (auto& listener : listeners) {
|
||||
// XXX Why don't we notify listeners of actual length?
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
@ -4184,7 +4178,7 @@ nsresult EditorBase::DeleteSelectionWithTransaction(
|
||||
}
|
||||
|
||||
// Notify nsIEditActionListener::DidDelete[Selection|Text|Node]
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
AutoActionListenerArray listeners(mActionListeners.Clone());
|
||||
if (!deleteContent) {
|
||||
for (auto& listener : mActionListeners) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
|
@ -4084,8 +4084,7 @@ already_AddRefed<nsIContent> HTMLEditor::SplitNodeWithTransaction(
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored = listener->DidSplitNode(
|
||||
aStartOfRightNode.GetContainer(), newLeftContent);
|
||||
NS_WARNING_ASSERTION(
|
||||
@ -4458,8 +4457,7 @@ nsresult HTMLEditor::JoinNodesWithTransaction(nsINode& aLeftNode,
|
||||
}
|
||||
|
||||
if (!mActionListeners.IsEmpty()) {
|
||||
AutoActionListenerArray listeners(mActionListeners);
|
||||
for (auto& listener : listeners) {
|
||||
for (auto& listener : mActionListeners.Clone()) {
|
||||
DebugOnly<nsresult> rvIgnored =
|
||||
listener->DidJoinNodes(&aLeftNode, &aRightNode, parent, rv);
|
||||
NS_WARNING_ASSERTION(
|
||||
|
@ -77,8 +77,8 @@ nsresult SelectionState::RestoreSelection(Selection& aSelection) {
|
||||
aSelection.SetDirection(mDirection);
|
||||
|
||||
ErrorResult error;
|
||||
AutoTArray<RefPtr<RangeItem>, 10> rangeItems(mArray);
|
||||
for (RefPtr<RangeItem>& rangeItem : rangeItems) {
|
||||
const CopyableAutoTArray<RefPtr<RangeItem>, 10> rangeItems(mArray);
|
||||
for (const RefPtr<RangeItem>& rangeItem : rangeItems) {
|
||||
RefPtr<nsRange> range = rangeItem->GetRange();
|
||||
if (!range) {
|
||||
NS_WARNING("RangeItem::GetRange() failed");
|
||||
|
@ -98,7 +98,7 @@ class SelectionState final {
|
||||
bool IsEmpty() const;
|
||||
|
||||
private:
|
||||
AutoTArray<RefPtr<RangeItem>, 1> mArray;
|
||||
CopyableAutoTArray<RefPtr<RangeItem>, 1> mArray;
|
||||
nsDirection mDirection;
|
||||
|
||||
friend class RangeUpdater;
|
||||
|
Loading…
x
Reference in New Issue
Block a user