зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1546888 - Make editor public methods which may be canceled by clipboard event listener return NS_SUCCESS_DOM_NO_OPERATION when it's canceled r=m_kato
This patch makes editors return new error code internally when clipboard event is dispatched and canceled by script. This is for making each caller stop handling the edit action. However, it's not actual failure. Therefore, making public methods return `NS_SUCCESS_DOM_NO_OPERATION` instead via `EditorBase::ToGenericNSResult()`. Differential Revision: https://phabricator.services.mozilla.com/D28935 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
bf5404331b
Коммит
006066d2ee
|
@ -1820,6 +1820,13 @@ class EditorBase : public nsIEditor,
|
|||
// this case.
|
||||
case NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE:
|
||||
return NS_OK;
|
||||
// If the editing action is canceled by event listeners, editor needs
|
||||
// to stop handling it. However, editor shouldn't return error for
|
||||
// the callers but they should be able to distinguish whether it's
|
||||
// canceled or not. Although it's DOM specific code, let's return
|
||||
// DOM_SUCCESS_DOM_NO_OPERATION here.
|
||||
case NS_ERROR_EDITOR_ACTION_CANCELED:
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
default:
|
||||
return aRv;
|
||||
}
|
||||
|
|
|
@ -1454,7 +1454,7 @@ nsresult HTMLEditor::PasteInternal(int32_t aClipboardType,
|
|||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
if (aDispatchPasteEvent && !FireClipboardEvent(ePaste, aClipboardType)) {
|
||||
return NS_OK;
|
||||
return NS_ERROR_EDITOR_ACTION_CANCELED;
|
||||
}
|
||||
|
||||
// Get Clipboard Service
|
||||
|
@ -1546,7 +1546,7 @@ nsresult HTMLEditor::PasteTransferable(nsITransferable* aTransferable) {
|
|||
// aTransferable and we don't currently implement a way to put that in the
|
||||
// data transfer yet.
|
||||
if (!FireClipboardEvent(ePaste, nsIClipboard::kGlobalClipboard)) {
|
||||
return NS_OK;
|
||||
return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED);
|
||||
}
|
||||
|
||||
nsAutoString contextStr, infoStr;
|
||||
|
@ -1571,7 +1571,7 @@ HTMLEditor::PasteNoFormatting(int32_t aSelectionType) {
|
|||
SettingDataTransfer::eWithoutFormat, aSelectionType);
|
||||
|
||||
if (!FireClipboardEvent(ePasteNoFormatting, aSelectionType)) {
|
||||
return NS_OK;
|
||||
return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED);
|
||||
}
|
||||
|
||||
CommitComposition();
|
||||
|
|
|
@ -1788,7 +1788,8 @@ TextEditor::Cut() {
|
|||
*nsGkAtoms::DeleteTxnName);
|
||||
DeleteSelectionAsSubAction(eNone, eStrip);
|
||||
}
|
||||
return actionTaken ? NS_OK : NS_ERROR_FAILURE;
|
||||
return EditorBase::ToGenericNSResult(
|
||||
actionTaken ? NS_OK : NS_ERROR_EDITOR_ACTION_CANCELED);
|
||||
}
|
||||
|
||||
bool TextEditor::CanCut() const {
|
||||
|
@ -1816,7 +1817,8 @@ TextEditor::Copy() {
|
|||
bool actionTaken = false;
|
||||
FireClipboardEvent(eCopy, nsIClipboard::kGlobalClipboard, &actionTaken);
|
||||
|
||||
return actionTaken ? NS_OK : NS_ERROR_FAILURE;
|
||||
return EditorBase::ToGenericNSResult(
|
||||
actionTaken ? NS_OK : NS_ERROR_EDITOR_ACTION_CANCELED);
|
||||
}
|
||||
|
||||
bool TextEditor::CanCopy() const {
|
||||
|
|
|
@ -378,7 +378,7 @@ nsresult TextEditor::PasteAsAction(int32_t aClipboardType,
|
|||
}
|
||||
|
||||
if (aDispatchPasteEvent && !FireClipboardEvent(ePaste, aClipboardType)) {
|
||||
return NS_OK;
|
||||
return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED);
|
||||
}
|
||||
|
||||
// Get Clipboard Service
|
||||
|
@ -425,7 +425,7 @@ TextEditor::PasteTransferable(nsITransferable* aTransferable) {
|
|||
// aTransferable and we don't currently implement a way to put that in the
|
||||
// data transfer yet.
|
||||
if (!FireClipboardEvent(ePaste, -1)) {
|
||||
return NS_OK;
|
||||
return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED);
|
||||
}
|
||||
|
||||
if (!IsModifiable()) {
|
||||
|
|
|
@ -679,12 +679,18 @@ with modules["IMGLIB"]:
|
|||
with modules["EDITOR"]:
|
||||
errors["NS_ERROR_EDITOR_DESTROYED"] = FAILURE(1)
|
||||
|
||||
# A error code that indicates that the DOM tree has been modified by
|
||||
# An error code that indicates that the DOM tree has been modified by
|
||||
# web app or add-on while the editor modifying the tree. However,
|
||||
# this shouldn't be exposed to the web because the result should've
|
||||
# been expected by the web app.
|
||||
errors["NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE"] = FAILURE(2)
|
||||
|
||||
# An error code that indicates that the edit action canceled by
|
||||
# clipboard event listener or beforeinput event listener. Note that
|
||||
# don't make this as a success code since it's not check with NS_FAILED()
|
||||
# and may keep handling the operation unexpectedly.
|
||||
errors["NS_ERROR_EDITOR_ACTION_CANCELED"] = FAILURE(3)
|
||||
|
||||
errors["NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND"] = SUCCESS(1)
|
||||
errors["NS_SUCCESS_EDITOR_FOUND_TARGET"] = SUCCESS(2)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче