Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2618583003: [InputEvent] Add 'beforeinput' logic in |will*()| and guarded by a flag (3/11) (Closed)
Patch Set: Change target to |startingRootEditableElement()| Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698