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

Unified Diff: third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp

Issue 1752933002: [InputEvent] Fire 'beforeinput' during typing, pressing hot keys and IME composition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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/commands/EditorCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
index 82083270ba88e8e87d95e13427ba8b1e7586305c..b71feb92c5b60592b4d1e5bfc5213c18b86823e2 100644
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
@@ -104,6 +104,33 @@ WebEditingCommandType WebEditingCommandTypeFromCommandName(const String& command
return WebEditingCommandType::Invalid;
}
+InputEvent::InputType InputTypeFromCommandType(WebEditingCommandType commandType)
+{
+ switch (commandType) {
+ case WebEditingCommandType::Delete:
+ case WebEditingCommandType::DeleteBackward:
+ case WebEditingCommandType::DeleteBackwardByDecomposingPreviousCharacter:
+ case WebEditingCommandType::DeleteForward:
+ case WebEditingCommandType::DeleteToBeginningOfLine:
+ case WebEditingCommandType::DeleteToBeginningOfParagraph:
+ case WebEditingCommandType::DeleteToEndOfLine:
+ case WebEditingCommandType::DeleteToEndOfParagraph:
+ case WebEditingCommandType::DeleteToMark:
+ case WebEditingCommandType::DeleteWordBackward:
+ case WebEditingCommandType::DeleteWordForward:
+ return InputEvent::InputType::DeleteContent;
+ case WebEditingCommandType::Redo:
+ return InputEvent::InputType::Redo;
+ case WebEditingCommandType::Undo:
+ return InputEvent::InputType::Undo;
+ case WebEditingCommandType::InsertBacktab:
+ case WebEditingCommandType::InsertText:
+ return InputEvent::InputType::InsertText;
+ default:
+ return InputEvent::InputType::None;
+ }
+}
+
} // anonymous namespace
class EditorInternalCommand {
@@ -1751,6 +1778,19 @@ bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) c
if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
return false;
}
+
+ if (m_source == CommandFromMenuOrKeyBinding) {
+ InputEvent::InputType inputType = InputTypeFromCommandType(m_command->commandType);
+ if (inputType != InputEvent::InputType::None) {
+ if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_frame->document()), inputType) != DispatchEventResult::NotCanceled)
+ return true;
+ }
+ }
+
+ // 'beforeinput' event handler may destroy |frame()|.
+ if (!m_frame || !frame().document())
+ return false;
+
frame().document()->updateLayoutIgnorePendingStylesheets();
DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Commands"));
commandHistogram.sample(static_cast<int>(m_command->commandType));

Powered by Google App Engine
This is Rietveld 408576698