Bug 1540037 - part 42: Move TextEditor::DeleteSelectionByDragAsAction() into EditorBase r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D116569
This commit is contained in:
Masayuki Nakano
2021-06-04 05:23:05 +00:00
parent 7573c7e839
commit fd1688b098
4 changed files with 48 additions and 48 deletions

View File

@@ -271,7 +271,7 @@ nsresult TextEditor::OnDrop(DragEvent* aDropEvent) {
}
// Don't cancel "insertFromDrop" even if "deleteByDrag" is canceled.
if (rv != NS_ERROR_EDITOR_ACTION_CANCELED && NS_FAILED(rv)) {
NS_WARNING("TextEditor::DeleteSelectionByDragAsAction() failed");
NS_WARNING("EditorBase::DeleteSelectionByDragAsAction() failed");
editActionData.Abort();
return EditorBase::ToGenericNSResult(rv);
}
@@ -435,46 +435,6 @@ nsresult TextEditor::OnDrop(DragEvent* aDropEvent) {
return rv;
}
nsresult TextEditor::DeleteSelectionByDragAsAction(bool aDispatchInputEvent) {
// TODO: Move this method to `EditorBase`.
AutoRestore<bool> saveDispatchInputEvent(mDispatchInputEvent);
mDispatchInputEvent = aDispatchInputEvent;
// Even if we're handling "deleteByDrag" in same editor as "insertFromDrop",
// we need to recreate edit action data here because
// `AutoEditActionDataSetter` needs to manage event state separately.
bool requestedByAnotherEditor = GetEditAction() != EditAction::eDrop;
AutoEditActionDataSetter editActionData(*this, EditAction::eDeleteByDrag);
MOZ_ASSERT(!SelectionRef().IsCollapsed());
nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent();
if (NS_FAILED(rv)) {
NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED,
"CanHandleAndMaybeDispatchBeforeInputEvent() failed");
return rv;
}
// But keep using placeholder transaction for "insertFromDrop" if there is.
Maybe<AutoPlaceholderBatch> treatAsOneTransaction;
if (requestedByAnotherEditor) {
treatAsOneTransaction.emplace(*this, ScrollSelectionIntoView::Yes);
}
rv = DeleteSelectionAsSubAction(nsIEditor::eNone, IsTextEditor()
? nsIEditor::eNoStrip
: nsIEditor::eStrip);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteSelectionAsSubAction(eNone) failed");
return rv;
}
if (!mDispatchInputEvent) {
return NS_OK;
}
if (treatAsOneTransaction.isNothing()) {
DispatchInputEvent();
}
return NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : NS_OK;
}
nsresult TextEditor::PasteAsAction(int32_t aClipboardType,
bool aDispatchPasteEvent,
nsIPrincipal* aPrincipal) {