Bug 1656432 - part 1: Create nsIEditActionListener::WillDeleteRanges() r=m_kato

Currently, `nsIEditActionListener::WillDeleteSelection()` notifies
`FinderHighliter` of deleting selection ranges.  But it's referred only
the ranges, not selection object itself and editor shouldn't modify
`Selection` as far as possible for reducing the runtime cost.

Therefore, it should be replaced with this new API.  Then,
`EditorBase::WillDeleteSelectionWithTransaction()` can be rewritten as
`EditorBase::WillDeleteRangesWithTransaction()` later.

Differential Revision: https://phabricator.services.mozilla.com/D85681
This commit is contained in:
Masayuki Nakano 2020-08-04 14:59:03 +00:00
parent 19224fdc71
commit d68f059017
3 changed files with 29 additions and 0 deletions

View File

@ -4033,6 +4033,22 @@ nsresult EditorBase::DeleteSelectionWithTransaction(
MOZ_DIAGNOSTIC_ASSERT(!Destroyed(),
"nsIEditActionListener::WillDeleteSelection() "
"must not destroy the editor");
// FYI: Currently, there should be only one listener at most.
// Therefore, retrieving the lastest ranges everytime before
// calling `WillDeleteRanges()` must be fine.
AutoTArray<RefPtr<nsRange>, 8> ranges;
for (uint32_t i = 0; i < SelectionRefPtr()->RangeCount(); i++) {
ranges.AppendElement(SelectionRefPtr()->GetRangeAt(i)->CloneRange());
}
if (!ranges.IsEmpty()) {
DebugOnly<nsresult> rvIgnored = listener->WillDeleteRanges(ranges);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"nsIEditActionListener::WillDeleteRanges() failed, but ignored");
MOZ_DIAGNOSTIC_ASSERT(!Destroyed(),
"nsIEditActionListener::WillDeleteRanges() "
"must not destroy the editor");
}
}
} else if (deleteCharData) {
AutoActionListenerArray listeners(mActionListeners.Clone());

View File

@ -8,6 +8,7 @@
webidl CharacterData;
webidl Node;
webidl Range;
webidl Selection;
/*
@ -76,4 +77,10 @@ interface nsIEditActionListener : nsISupports
* @param aSelection The selection to be deleted
*/
void WillDeleteSelection(in Selection aSelection);
/**
* Called before the editor deletes the ranges.
* @param aRangesToDelete The ranges to be deleted.
*/
void WillDeleteRanges(in Array<Range> aRangesToDelete);
};

View File

@ -2913,4 +2913,10 @@ TextServicesDocument::WillDeleteSelection(Selection* aSelection) {
return NS_OK;
}
NS_IMETHODIMP
TextServicesDocument::WillDeleteRanges(
const nsTArray<RefPtr<nsRange>>& aRangesToDelete) {
return NS_OK;
}
} // namespace mozilla