| Index: third_party/WebKit/Source/core/editing/EditingUtilities.cpp
|
| diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
|
| index b2e9585120c4d712818d6efd21dd2340888b1568..97baca85b3bf6c1f4ad03bcc8d3388902247f7d4 100644
|
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
|
| @@ -2159,4 +2159,47 @@ InputEvent::EventIsComposing isComposingFromCommand(
|
| return InputEvent::NotComposing;
|
| }
|
|
|
| +bool dispatchBeforeInputEvent(EditCommandSource source,
|
| + LocalFrame* frame,
|
| + Node* target,
|
| + InputEvent::InputType inputType,
|
| + const String& data,
|
| + DataTransfer* dataTransfer,
|
| + InputEvent::EventCancelable isCancelable,
|
| + InputEvent::EventIsComposing isComposing,
|
| + const RangeVector* ranges) {
|
| + // Don't fire 'beforeinput', return true to continue.
|
| + if (source != EditCommandSource::kMenuOrKeyBinding ||
|
| + inputType == InputEvent::InputType::None)
|
| + return true;
|
| + if (!RuntimeEnabledFeatures::inputEventEnabled())
|
| + return true;
|
| + if (!frame || !target || !target->isConnected())
|
| + return true;
|
| +
|
| + if (!hasRichlyEditableStyle(*target)) {
|
| + // Plain-text only elements (<input>, <textarea>, etc.) don't support
|
| + // DataTransfer or Range.
|
| + dataTransfer = nullptr;
|
| + ranges = nullptr;
|
| + }
|
| +
|
| + InputEvent* beforeInputEvent;
|
| +
|
| + if (dataTransfer) {
|
| + beforeInputEvent = InputEvent::createBeforeInput(
|
| + inputType, dataTransfer, isCancelable, isComposing, ranges);
|
| + } else {
|
| + beforeInputEvent = InputEvent::createBeforeInput(
|
| + inputType, data, isCancelable, isComposing, ranges);
|
| + }
|
| +
|
| + DispatchEventResult result = target->dispatchEvent(beforeInputEvent);
|
| + // 'beforeinput' event handler may destroy target frame.
|
| + if (!frame->document() || frame->document()->frame() != frame ||
|
| + !target->isConnected())
|
| + return false;
|
| + return result == DispatchEventResult::NotCanceled;
|
| +}
|
| +
|
| } // namespace blink
|
|
|