Bug 1964011 - part 1: Make EditorBase log dispatching events r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D248368
This commit is contained in:
committed by
masayuki@d-toybox.com
parent
3784234e60
commit
90e1f5ae9a
@@ -53,6 +53,7 @@
|
||||
#include "mozilla/InputEventOptions.h" // for InputEventOptions
|
||||
#include "mozilla/IntegerRange.h" // for IntegerRange
|
||||
#include "mozilla/InternalMutationEvent.h" // for NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED
|
||||
#include "mozilla/Logging.h" //for MOZ_LOG
|
||||
#include "mozilla/mozalloc.h" // for operator new, etc.
|
||||
#include "mozilla/mozInlineSpellChecker.h" // for mozInlineSpellChecker
|
||||
#include "mozilla/mozSpellChecker.h" // for mozSpellChecker
|
||||
@@ -70,6 +71,7 @@
|
||||
#include "mozilla/TextInputListener.h" // for TextInputListener
|
||||
#include "mozilla/TextServicesDocument.h" // for TextServicesDocument
|
||||
#include "mozilla/TextEvents.h"
|
||||
#include "mozilla/ToString.h"
|
||||
#include "mozilla/TransactionManager.h" // for TransactionManager
|
||||
#include "mozilla/dom/AbstractRange.h" // for AbstractRange
|
||||
#include "mozilla/dom/Attr.h" // for Attr
|
||||
@@ -147,6 +149,8 @@ using LeafNodeType = HTMLEditUtils::LeafNodeType;
|
||||
using LeafNodeTypes = HTMLEditUtils::LeafNodeTypes;
|
||||
using WalkTreeOption = HTMLEditUtils::WalkTreeOption;
|
||||
|
||||
static LazyLogModule gEventLog("EditorEvent");
|
||||
|
||||
/*****************************************************************************
|
||||
* mozilla::EditorBase
|
||||
*****************************************************************************/
|
||||
@@ -1647,10 +1651,32 @@ EditorBase::DispatchClipboardEventAndUpdateClipboard(
|
||||
return do_AddRef(&SelectionRef());
|
||||
}();
|
||||
|
||||
const auto GetDOMEventName = [&]() -> const char* {
|
||||
switch (aEventMessage) {
|
||||
case eCopy:
|
||||
return "copy";
|
||||
case eCut:
|
||||
return "cut";
|
||||
case ePaste:
|
||||
case ePasteNoFormatting:
|
||||
return "paste";
|
||||
default:
|
||||
return ToChar(aEventMessage);
|
||||
}
|
||||
};
|
||||
|
||||
MOZ_LOG(
|
||||
gEventLog, LogLevel::Info,
|
||||
("%p %s: Dispatching \"%s\" event...", this,
|
||||
mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", GetDOMEventName()));
|
||||
bool actionTaken = false;
|
||||
const bool doDefault = nsCopySupport::FireClipboardEvent(
|
||||
aEventMessage, aClipboardType, presShell, sel, aDataTransfer,
|
||||
&actionTaken);
|
||||
MOZ_LOG(gEventLog, LogLevel::Info,
|
||||
("%p %s: Dispatched \"%s\" event, defaultPrevented=%s", this,
|
||||
mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", GetDOMEventName(),
|
||||
doDefault ? "false" : "true"));
|
||||
NotifyOfDispatchingClipboardEvent();
|
||||
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
@@ -2770,6 +2796,14 @@ void EditorBase::NotifyEditorObservers(
|
||||
|
||||
if (!mDispatchInputEvent || IsEditActionAborted() ||
|
||||
IsEditActionCanceled()) {
|
||||
MOZ_LOG(
|
||||
gEventLog, LogLevel::Warning,
|
||||
("%p %s: Not dispatching \"input\" event (mDispatchInputEvent=%s, "
|
||||
"IsEditActionAborted()=%s, IsEditActionCanceled()=%s",
|
||||
this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor",
|
||||
mDispatchInputEvent ? "true" : "false",
|
||||
IsEditActionAborted() ? "true" : "false",
|
||||
IsEditActionCanceled() ? "true" : "false"));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2837,16 +2871,27 @@ void EditorBase::DispatchInputEvent() {
|
||||
|
||||
RefPtr<Element> targetElement = GetInputEventTargetElement();
|
||||
if (NS_WARN_IF(!targetElement)) {
|
||||
MOZ_LOG(gEventLog, LogLevel::Error,
|
||||
("%p %s: Failed dispatching \"input\" event due to no target", this,
|
||||
mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor"));
|
||||
return;
|
||||
}
|
||||
RefPtr<DataTransfer> dataTransfer = GetInputEventDataTransfer();
|
||||
mEditActionData->WillDispatchInputEvent();
|
||||
MOZ_LOG(gEventLog, LogLevel::Info,
|
||||
("%p %s: Dispatching \"input\" event: { inputType=\"%s\" }...", this,
|
||||
mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor",
|
||||
ToString(ToInputType(GetEditAction())).c_str()));
|
||||
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(
|
||||
targetElement, eEditorInput, ToInputType(GetEditAction()), this,
|
||||
dataTransfer ? InputEventOptions(dataTransfer,
|
||||
InputEventOptions::NeverCancelable::No)
|
||||
: InputEventOptions(GetInputEventData(),
|
||||
InputEventOptions::NeverCancelable::No));
|
||||
MOZ_LOG(gEventLog, LogLevel::Debug,
|
||||
("%p %s: Dispatched \"input\" event: { inputType=\"%s\" }", this,
|
||||
mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor",
|
||||
ToString(ToInputType(GetEditAction())).c_str()));
|
||||
mEditActionData->DidDispatchInputEvent();
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rvIgnored),
|
||||
@@ -6830,6 +6875,10 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
|
||||
// action since web apps cannot override it with `beforeinput` event
|
||||
// listener, but for backward compatibility, we should return a special
|
||||
// success code instead of error.
|
||||
MOZ_LOG(gEventLog, LogLevel::Error,
|
||||
("%p %s: Failed dispatching \"beforeinput\" event due to no target",
|
||||
&mEditorBase,
|
||||
mEditorBase.mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor"));
|
||||
return NS_OK;
|
||||
}
|
||||
OwningNonNull<EditorBase> editorBase = mEditorBase;
|
||||
@@ -6909,6 +6958,11 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
|
||||
? InputEventOptions::NeverCancelable::Yes
|
||||
: InputEventOptions::NeverCancelable::No;
|
||||
WillDispatchInputEvent();
|
||||
MOZ_LOG(gEventLog, LogLevel::Info,
|
||||
("%p %s: Dispatching \"beforeinput\" event: { inputType=\"%s\" }...",
|
||||
editorBase.get(),
|
||||
editorBase->mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor",
|
||||
ToString(ToInputType(GetEditAction())).c_str()));
|
||||
nsresult rv = nsContentUtils::DispatchInputEvent(
|
||||
targetElement, eEditorBeforeInput, inputType, editorBase,
|
||||
mDataTransfer
|
||||
@@ -6916,6 +6970,13 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
|
||||
neverCancelable)
|
||||
: InputEventOptions(mData, std::move(mTargetRanges), neverCancelable),
|
||||
&status);
|
||||
MOZ_LOG(gEventLog, LogLevel::Info,
|
||||
("%p %s: Dispatched \"beforeinput\" event: { inputType=\"%s\" }, "
|
||||
"defaultPrevented=%s",
|
||||
editorBase.get(),
|
||||
editorBase->mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor",
|
||||
ToString(ToInputType(GetEditAction())).c_str(),
|
||||
status == nsEventStatus_eConsumeNoDefault ? "true" : "false"));
|
||||
DidDispatchInputEvent();
|
||||
if (NS_WARN_IF(mEditorBase.Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
|
||||
Reference in New Issue
Block a user