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 d1f22bb0aecdf46ab38fd30d4ba95daf5338738e..0f3651d9d40840e74ccab9aa990e1a9f7236d973 100644 |
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
@@ -82,6 +82,19 @@ inline Editor& InputMethodController::editor() const |
return frame().editor(); |
} |
+static void dispatchCompositionEvent(LocalFrame& frame, const AtomicString& type, const String& text) |
aelias_OOO_until_Jul13
2016/01/16 01:48:50
nit: Could you position this method where the prev
|
+{ |
+ // We should send this event before sending a TextEvent as written in |
+ // Section 6.2.2 and 6.2.3 of the DOM Event specification. |
+ Element* target = frame.document()->focusedElement(); |
+ if (!target) |
+ return; |
+ |
+ RefPtrWillBeRawPtr<CompositionEvent> event = |
+ CompositionEvent::create(EventTypeNames::compositionend, frame.domWindow(), text); |
aelias_OOO_until_Jul13
2016/01/16 01:48:50
Looks like you intended to use "type" here, instea
|
+ target->dispatchEvent(event); |
+} |
+ |
void InputMethodController::clear() |
{ |
m_hasComposition = false; |
@@ -122,23 +135,17 @@ bool InputMethodController::confirmComposition() |
return confirmComposition(composingText()); |
} |
-static void dispatchCompositionEndEvent(LocalFrame& frame, const String& text) |
-{ |
- // We should send this event before sending a TextEvent as written in |
- // Section 6.2.2 and 6.2.3 of the DOM Event specification. |
- Element* target = frame.document()->focusedElement(); |
- if (!target) |
- return; |
- |
- RefPtrWillBeRawPtr<CompositionEvent> event = |
- CompositionEvent::create(EventTypeNames::compositionend, frame.domWindow(), text); |
- target->dispatchEvent(event); |
-} |
- |
bool InputMethodController::confirmComposition(const String& text) |
{ |
+#if OS(ANDROID) |
aelias_OOO_until_Jul13
2016/01/16 01:48:50
Let's avoid introducing any OS(ANDROID) in Blink.
|
+ // On Android, we want to trigger compositionstart/end even for |
+ // confirmComposition since it does not accompany actual keycodes. |
+ if (!hasComposition() && text.isEmpty()) |
+ return false; |
+#else |
if (!hasComposition()) |
return false; |
+#endif |
Editor::RevealSelectionScope revealSelectionScope(&editor()); |
@@ -156,7 +163,9 @@ bool InputMethodController::confirmComposition(const String& text) |
if (frame().selection().isNone()) |
return false; |
- dispatchCompositionEndEvent(frame(), text); |
+ if (!hasComposition()) |
+ dispatchCompositionEvent(frame(), EventTypeNames::compositionstart, frame().selectedText()); |
+ dispatchCompositionEvent(frame(), EventTypeNames::compositionend, text); |
if (!frame().document()) |
return false; |
@@ -179,8 +188,10 @@ bool InputMethodController::confirmCompositionOrInsertText(const String& text, C |
if (!hasComposition()) { |
if (!text.length()) |
return false; |
+#if !OS(ANDROID) |
editor().insertText(text, 0); |
aelias_OOO_until_Jul13
2016/01/16 01:48:50
Hmm, wouldn't it work just as well to add the comp
|
return true; |
+#endif |
} |
if (text.length()) { |
@@ -205,7 +216,7 @@ void InputMethodController::cancelComposition() |
if (frame().selection().isNone()) |
return; |
- dispatchCompositionEndEvent(frame(), emptyString()); |
+ dispatchCompositionEvent(frame(), EventTypeNames::compositionend, emptyString()); |
clear(); |
insertTextForConfirmedComposition(emptyString()); |