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 4debf150004b75497f83efa480177e71d5c8a50a..64a858fbe89737ab322d632f0d78b2fe23abb31b 100644 |
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
@@ -106,29 +106,29 @@ void insertTextDuringCompositionWithEvents( |
if (!frame.document()) |
return; |
- Element* target = frame.document()->focusedElement(); |
- if (!target) |
- return; |
- |
- // TODO(chongz): Fire 'beforeinput' for the composed text being |
- // replaced/deleted. |
- |
- // Only the last confirmed text is cancelable. |
- InputEvent::EventCancelable beforeInputCancelable = |
- (compositionType == |
- TypingCommand::TextCompositionType::TextCompositionUpdate) |
- ? InputEvent::EventCancelable::NotCancelable |
- : InputEvent::EventCancelable::IsCancelable; |
- DispatchEventResult result = dispatchBeforeInputFromComposition( |
- target, InputEvent::InputType::InsertText, text, beforeInputCancelable); |
- |
- if (beforeInputCancelable == InputEvent::EventCancelable::IsCancelable && |
- result != DispatchEventResult::NotCanceled) |
- return; |
- |
- // 'beforeinput' event handler may destroy document. |
- if (!frame.document()) |
- return; |
+ // TODO(chongz): Remove the following code after we have ensured it's OK to |
+ // fire 'beforeinput' after 'compositionupdate'. |
+ // https://crbug.com/675820 |
+ if (compositionType == TypingCommand::TextCompositionUpdate || |
+ compositionType == TypingCommand::TextCompositionConfirm) { |
+ Element* target = frame.document()->focusedElement(); |
+ if (!target) |
+ return; |
+ // Only the last confirmed text is cancelable. |
+ const InputEvent::EventCancelable beforeInputCancelable = |
+ (compositionType == TypingCommand::TextCompositionUpdate) |
+ ? InputEvent::EventCancelable::NotCancelable |
+ : InputEvent::EventCancelable::IsCancelable; |
+ RangeVector* targetRanges = nullptr; |
+ if (frame.editor().canEditRichly()) |
+ targetRanges = new RangeVector(1, frame.selection().firstRange()); |
+ const bool isCanceled = !dispatchBeforeInputEvent( |
+ EditCommandSource::kMenuOrKeyBinding, &frame, target, |
+ InputEvent::InputType::InsertText, text, nullptr, beforeInputCancelable, |
+ InputEvent::IsComposing, targetRanges); |
+ if (isCanceled) |
+ return; |
+ } |
dispatchCompositionUpdateEvent(frame, text); |
// 'compositionupdate' event handler may destroy document. |
@@ -352,9 +352,6 @@ bool InputMethodController::replaceCompositionAndMoveCaret( |
} |
bool InputMethodController::insertText(const String& text) { |
- if (dispatchBeforeInputInsertText(document().focusedElement(), text) != |
- DispatchEventResult::NotCanceled) |
- return false; |
editor().insertText(text, 0); |
return true; |
} |
@@ -387,11 +384,6 @@ void InputMethodController::cancelComposition() { |
clear(); |
- // TODO(chongz): Figure out which InputType should we use here. |
- dispatchBeforeInputFromComposition( |
- document().focusedElement(), |
- InputEvent::InputType::DeleteComposedCharacterBackward, nullAtom, |
- InputEvent::EventCancelable::NotCancelable); |
dispatchCompositionUpdateEvent(frame(), emptyString()); |
insertTextDuringCompositionWithEvents( |
frame(), emptyString(), 0, |
@@ -776,10 +768,6 @@ void InputMethodController::extendSelectionAndDelete(int before, int after) { |
++before; |
} while (frame().selection().start() == frame().selection().end() && |
before <= static_cast<int>(selectionOffsets.start())); |
- // TODO(chongz): Find a way to distinguish Forward and Backward. |
- dispatchBeforeInputEditorCommand( |
- document().focusedElement(), InputEvent::InputType::DeleteContentBackward, |
- new RangeVector(1, m_frame->selection().firstRange())); |
TypingCommand::deleteSelection(document(), |
EditCommandSource::kMenuOrKeyBinding); |
} |