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

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: Rebase on WebEditingCommandType & Yosin's review 2 Created 4 years, 8 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 e1d2f0fe18572803afa15c40bfe7af59a60e36ee..32cf130b55d1852dec8a93f32b5ec8b539db4006 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -172,6 +172,12 @@ bool InputMethodController::confirmComposition(const String& text, ConfirmCompos
clear();
+ // According to spec 'beforeinput' should not be sent along with CompositionEnd, so
+ // dispatch after CompositionEnd if there is any update.
+ // https://w3c.github.io/uievents/#h-events-composition-event-input-events
+ if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
+ return false;
+
insertTextForConfirmedComposition(text);
return true;
@@ -182,6 +188,10 @@ bool InputMethodController::confirmCompositionOrInsertText(const String& text, C
if (!hasComposition()) {
if (!text.length())
return false;
+
+ if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
+ return false;
+
editor().insertText(text, 0);
return true;
}
@@ -278,8 +288,12 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp
else
event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text);
}
- if (event)
+ if (event) {
+ // TODO(chongz): Support canceling IME composition.
+ if (event->type() == EventTypeNames::compositionupdate)
+ dispatchBeforeInputFromComposition(target, InputEvent::InputType::ReplaceContent, text);
target->dispatchEvent(event);
+ }
}
// If text is empty, then delete the old composition here. If text is non-empty, InsertTextCommand::input
@@ -453,6 +467,8 @@ void InputMethodController::extendSelectionAndDelete(int before, int after)
break;
++before;
} while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start()));
+ // TODO(chongz): According to spec |data| should be "forward" or "backward".
+ dispatchBeforeInputFromComposition(frame().document()->focusedElement(), InputEvent::InputType::DeleteComposedCharacter, "backward");
chongz 2016/04/13 00:34:28 Not sure when will this code path get called...?
yosin_UTC9 2016/04/13 06:13:09 Backspace emulation? Or, Thai keyboard? I remember
chongz 2016/04/13 23:53:08 Actually it will always go into here by pressing b
TypingCommand::deleteSelection(*frame().document());
}

Powered by Google App Engine
This is Rietveld 408576698