Index: third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp |
diff --git a/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp b/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp |
index 8e56bf043bffd04250b746a2b13d18410291902b..16fc6d7d6fa062bb8532dd0d3a26c24872f29dcb 100644 |
--- a/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp |
+++ b/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp |
@@ -40,6 +40,7 @@ |
#include "core/editing/commands/InsertTextCommand.h" |
#include "core/editing/spellcheck/SpellChecker.h" |
#include "core/events/BeforeTextInsertedEvent.h" |
+#include "core/events/TextEvent.h" |
#include "core/frame/LocalFrame.h" |
#include "core/html/HTMLBRElement.h" |
#include "core/layout/LayoutObject.h" |
@@ -140,11 +141,8 @@ void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand |
typingCommand->setEndingSelection(currentSelection); |
} |
-static String dispatchBeforeTextInsertedEvent(const String& text, const VisibleSelection& selectionForInsertion, bool insertionIsForUpdatingComposition) |
+static String dispatchBeforeTextInsertedEvent(const String& text, const VisibleSelection& selectionForInsertion) |
{ |
- if (insertionIsForUpdatingComposition) |
- return text; |
- |
String newText = text; |
if (Node* startNode = selectionForInsertion.start().computeContainerNode()) { |
if (startNode->rootEditableElement()) { |
@@ -157,6 +155,19 @@ static String dispatchBeforeTextInsertedEvent(const String& text, const VisibleS |
return newText; |
} |
+static String dispatchTextInputEvent(LocalFrame* frame, const String& text, const VisibleSelection& selectionForInsertion) |
+{ |
+ String newText = text; |
+ Element* target = frame->document()->focusedElement(); |
+ if (target) { |
+ // Send TextInputEvent. The event handler will update text if necessary. |
+ TextEvent* event = TextEvent::create(frame->domWindow(), text, TextEventInputDrop); |
+ target->dispatchEvent(event); |
+ newText = event->data(); |
+ } |
+ return newText; |
+} |
+ |
void TypingCommand::insertText(Document& document, const String& text, Options options, TextCompositionType composition) |
{ |
LocalFrame* frame = document.frame(); |
@@ -176,7 +187,12 @@ void TypingCommand::insertText(Document& document, const String& text, const Vis |
VisibleSelection currentSelection = frame->selection().selection(); |
- String newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion, compositionType == TextCompositionUpdate); |
+ String newText = text; |
+ if (compositionType != TextCompositionUpdate) |
+ newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion); |
+ |
+ if (compositionType == TextCompositionConfirm) |
+ newText = dispatchTextInputEvent(frame, newText, selectionForInsertion); |
// Set the starting and ending selection appropriately if we are using a selection |
// that is different from the current selection. In the future, we should change EditCommand |