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

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/3) (Closed)
Patch Set: xiaocheng's review: Isolate |UndoStep| code; Move attribuates to private Created 4 years 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 4debf150004b75497f83efa480177e71d5c8a50a..23a6ce14bf8f95249f6fe5f9489c136cb3706728 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -84,11 +84,9 @@ bool needsIncrementalInsertion(const LocalFrame& frame, const String& newText) {
// Used to insert/replace text during composition update and confirm
// composition.
// Procedure:
-// 1. Fire 'beforeinput' event for (TODO(chongz): deleted composed text) and
-// inserted text
-// 2. Fire 'compositionupdate' event
-// 3. Fire TextEvent and modify DOM
-// TODO(chongz): 4. Fire 'input' event
+// 1. Fire 'compositionupdate' event
Xiaocheng 2016/12/21 02:56:39 Please revise the comments here.
chongz 2016/12/21 23:59:24 Reverted comments since there is no behavior chang
+// 2. Use TextEvent or TypingCommand to modify DOM, which will fire
+// 'beforeinput' and 'input'
void insertTextDuringCompositionWithEvents(
LocalFrame& frame,
const String& text,
@@ -106,33 +104,33 @@ 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(
chongz 2016/12/20 23:27:52 Kept, still fire 'beforeinput' before 'composition
- 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.
- if (!frame.document())
+ if (!frame.document() || frame.document()->frame() != &frame)
Xiaocheng 2016/12/21 02:56:38 This seems irrelevant to beforeinput. If it's a b
chongz 2016/12/21 23:59:24 Reverted, will put in another patch.
return;
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
@@ -158,7 +156,6 @@ void insertTextDuringCompositionWithEvents(
default:
NOTREACHED();
}
- // TODO(chongz): Fire 'input' event.
Xiaocheng 2016/12/21 02:56:39 Is it a drive-by removal of a stale TODO? If so,
chongz 2016/12/21 23:59:24 Yes, will isolate into another patch.
}
AtomicString getInputModeAttribute(Element* element) {
@@ -352,9 +349,6 @@ bool InputMethodController::replaceCompositionAndMoveCaret(
}
bool InputMethodController::insertText(const String& text) {
- if (dispatchBeforeInputInsertText(document().focusedElement(), text) !=
chongz 2016/12/20 23:27:52 Removed, inserting text was covered by |TypingComm
- DispatchEventResult::NotCanceled)
- return false;
editor().insertText(text, 0);
return true;
}
@@ -387,11 +381,6 @@ void InputMethodController::cancelComposition() {
clear();
- // TODO(chongz): Figure out which InputType should we use here.
- dispatchBeforeInputFromComposition(
chongz 2016/12/20 23:27:52 Removed. This is a dummy 'beforeinput' with no act
- document().focusedElement(),
- InputEvent::InputType::DeleteComposedCharacterBackward, nullAtom,
- InputEvent::EventCancelable::NotCancelable);
dispatchCompositionUpdateEvent(frame(), emptyString());
insertTextDuringCompositionWithEvents(
frame(), emptyString(), 0,
@@ -776,10 +765,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(
chongz 2016/12/20 23:27:52 Removed, deleting text was covered by |TypingComma
- document().focusedElement(), InputEvent::InputType::DeleteContentBackward,
- new RangeVector(1, m_frame->selection().firstRange()));
TypingCommand::deleteSelection(document(),
EditCommandSource::kMenuOrKeyBinding);
}

Powered by Google App Engine
This is Rietveld 408576698