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

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

Issue 1752933002: [InputEvent] Fire 'beforeinput' during typing, pressing hot keys and IME composition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/InputMethodController.cpp
diff --git a/third_party/WebKit/Source/core/editing/InputMethodController.cpp b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
index 7aeb0d1f45878ec10d499195a6e38f8e40180923..59ef222a21947ce1e9f86bbfdce6aa95e0dc1228 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -34,6 +34,7 @@
#include "core/editing/commands/TypingCommand.h"
#include "core/editing/markers/DocumentMarkerController.h"
#include "core/events/CompositionEvent.h"
+#include "core/events/InputEvent.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLTextAreaElement.h"
#include "core/input/EventHandler.h"
@@ -156,6 +157,16 @@ bool InputMethodController::confirmComposition(const String& text)
if (frame().selection().isNone())
return false;
+ if (RuntimeEnabledFeatures::inputEventEnabled()) {
dtapuska 2016/03/01 21:49:51 This seems to be a repeated pattern in this class.
+ if (Element* target = frame().document()->focusedElement()) {
+ // Dispatch 'beforeinput' before CompositionEvent
+ RefPtrWillBeRawPtr<InputEvent> beforeInputEvent = InputEvent::createBeforeInput("insertText", text);
chongz 2016/03/01 20:41:10 https://developer.mozilla.org/en-US/docs/Web/API/D
+ DispatchEventResult dispatchResult = target->dispatchEvent(beforeInputEvent);
+ if (dispatchResult != DispatchEventResult::NotCanceled)
+ return false;
+ }
+ }
+
dispatchCompositionEndEvent(frame(), text);
if (!frame().document())
@@ -179,6 +190,16 @@ bool InputMethodController::confirmCompositionOrInsertText(const String& text, C
if (!hasComposition()) {
if (!text.length())
return false;
+
+ if (RuntimeEnabledFeatures::inputEventEnabled()) {
+ if (Element* target = frame().document()->focusedElement()) {
+ // Dispatch 'beforeinput' before insertText
+ RefPtrWillBeRawPtr<InputEvent> beforeInputEvent = InputEvent::createBeforeInput("insertText", text);
+ DispatchEventResult dispatchResult = target->dispatchEvent(beforeInputEvent);
+ if (dispatchResult != DispatchEventResult::NotCanceled)
+ return false;
+ }
+ }
editor().insertText(text, 0);
return true;
}
@@ -246,6 +267,14 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp
return;
if (Element* target = frame().document()->focusedElement()) {
+ if (RuntimeEnabledFeatures::inputEventEnabled()) {
+ // Dispatch 'beforeinput' before CompositionEvent
+ RefPtrWillBeRawPtr<InputEvent> beforeInputEvent = InputEvent::createBeforeInput("replaceContent", text);
chongz 2016/03/01 20:41:10 'replaceContent' is mentioned here http://w3c.gith
dtapuska 2016/03/01 21:49:51 Let us leave it with replace text for now and see
+ DispatchEventResult dispatchResult = target->dispatchEvent(beforeInputEvent);
+ if (dispatchResult != DispatchEventResult::NotCanceled)
+ return;
+ }
+
// Dispatch an appropriate composition event to the focused node.
// We check the composition status and choose an appropriate composition event since this
// function is used for three purposes:

Powered by Google App Engine
This is Rietveld 408576698