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

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

Issue 2074423004: [InputEvent] Dispatch 'input' event for ContentEditable and typing on Input element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dispatch scoped 'input' event Created 4 years, 6 months 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/Editor.cpp
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp
index 5cd82372fa772f46d460fcb7c7ec2bc0bf70a594..94e721a3f32b09668b00a622770dced56e740848 100644
--- a/third_party/WebKit/Source/core/editing/Editor.cpp
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp
@@ -96,6 +96,66 @@ using namespace HTMLNames;
using namespace WTF;
using namespace Unicode;
+namespace {
+
+void dispatchInputEvent(Element* target, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComposing isComposing)
+{
+ if (!RuntimeEnabledFeatures::inputEventEnabled())
+ return;
+ if (!target)
+ return;
+ // TODO(chongz): Pass appreciate |ranges| after it's defined on spec.
+ // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
+ InputEvent* inputEvent = InputEvent::createInput(inputType, data, isComposing, nullptr);
+ target->dispatchScopedEvent(inputEvent);
chongz 2016/06/22 05:16:52 I have to check |FrameSelection::isAvailable()| if
yosin_UTC9 2016/06/22 06:29:25 Not sure. Why should we need to check |FrameSelect
chongz 2016/06/23 00:32:06 It's about test "editing/pasteboard/paste-removing
+}
+
+void dispatchInputEventEditableContentChanged(Element* startRoot, Element* endRoot, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComposing isComposing)
+{
+ if (startRoot)
+ dispatchInputEvent(startRoot, inputType, data, isComposing);
+ if (endRoot && endRoot != startRoot)
+ dispatchInputEvent(endRoot, inputType, data, isComposing);
+}
+
+InputEvent::InputType inputTypeFromCommand(CompositeEditCommand* command)
tkent 2016/06/22 06:53:21 The argument type should be |const CompositeEditCo
chongz 2016/06/23 00:32:06 Done.
+{
+ if (command->isTypingCommand()) {
+ TypingCommand* typingCommand = static_cast<TypingCommand*>(command);
tkent 2016/06/22 06:53:21 Please avoid bare static_cast<>. TypingCommand sh
chongz 2016/06/23 00:32:06 Done.
+ // TODO(chongz): Separate command types into more detailed InputType.
+ switch (typingCommand->commandTypeOfOpenCommand()) {
+ case TypingCommand::DeleteSelection:
+ case TypingCommand::DeleteKey:
+ case TypingCommand::ForwardDeleteKey:
+ return InputEvent::InputType::DeleteContent;
+ case TypingCommand::InsertText:
+ case TypingCommand::InsertLineBreak:
+ case TypingCommand::InsertParagraphSeparator:
+ case TypingCommand::InsertParagraphSeparatorInQuotedContent:
+ return InputEvent::InputType::InsertText;
+ default:
+ return InputEvent::InputType::None;
+ }
+ }
+
+ switch (command->editingAction()) {
+ // TODO(chongz): Handle other edit actions.
+ case EditActionBold:
+ return InputEvent::InputType::Bold;
chongz 2016/06/23 00:32:06 Actually text styling commands are a little bit co
+ default:
+ return InputEvent::InputType::None;
+ }
+}
+
+InputEvent::EventIsComposing isComposingFromCommand(CompositeEditCommand* command)
tkent 2016/06/22 06:53:21 The argument type should be |const CompositeEditCo
chongz 2016/06/23 00:32:06 Done.
+{
+ if (command->isTypingCommand() && static_cast<TypingCommand*>(command)->compositionType() != TypingCommand::TextCompositionNone)
tkent 2016/06/22 06:53:21 We should use toTypingCommand(command).
chongz 2016/06/23 00:32:06 Done.
+ return InputEvent::EventIsComposing::IsComposing;
+ return InputEvent::EventIsComposing::NotComposing;
+}
+
+} // anonymous namespace
+
Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor)
: m_editor(editor)
{
@@ -702,6 +762,9 @@ void Editor::appliedEditing(CompositeEditCommand* cmd)
EditCommandComposition* composition = cmd->composition();
DCHECK(composition);
dispatchEditableContentChangedEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement());
+ // TODO(chongz): Filter empty InputType after spec is finalized.
+ // TODO(chongz): Fill in |data| field.
+ dispatchInputEventEditableContentChanged(composition->startingRootEditableElement(), composition->endingRootEditableElement(), inputTypeFromCommand(cmd), emptyString(), isComposingFromCommand(cmd));
VisibleSelection newSelection(cmd->endingSelection());
// Don't clear the typing style with this selection change. We do those things elsewhere if necessary.
@@ -730,6 +793,7 @@ void Editor::unappliedEditing(EditCommandComposition* cmd)
frame().document()->updateStyleAndLayout();
dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd->endingRootEditableElement());
+ dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Undo, emptyString(), InputEvent::EventIsComposing::NotComposing);
VisibleSelection newSelection(cmd->startingSelection());
newSelection.validatePositionsIfNeeded();
@@ -748,6 +812,7 @@ void Editor::reappliedEditing(EditCommandComposition* cmd)
frame().document()->updateStyleAndLayout();
dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd->endingRootEditableElement());
+ dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Redo, emptyString(), InputEvent::EventIsComposing::NotComposing);
VisibleSelection newSelection(cmd->endingSelection());
changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);

Powered by Google App Engine
This is Rietveld 408576698