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()); |
} |