Chromium Code Reviews| 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 a9c9fd3ade529c8a4ebbebcdc1eb128ba0ad4b1b..10cba0a65a7ab897b676dbc5f6acf73403a960e4 100644 |
| --- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
| +++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
| @@ -104,6 +104,43 @@ 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::InsertHTML: |
| + case WebEditingCommandType::InsertHorizontalRule: |
| + case WebEditingCommandType::InsertImage: |
| + case WebEditingCommandType::InsertLineBreak: |
| + case WebEditingCommandType::InsertNewline: |
| + case WebEditingCommandType::InsertNewlineInQuotedContent: |
| + case WebEditingCommandType::InsertOrderedList: |
| + case WebEditingCommandType::InsertParagraph: |
| + case WebEditingCommandType::InsertTab: |
| + case WebEditingCommandType::InsertText: |
| + case WebEditingCommandType::InsertUnorderedList: |
| + return InputEvent::InputType::InsertText; |
|
ojan
2016/04/16 00:11:45
I think InsertText and InsertHTML should be two se
chongz
2016/04/18 22:54:47
The spec (http://w3c.github.io/editing/input-event
chongz
2016/04/19 21:17:01
Actually according to https://github.com/w3c/editi
|
| + default: |
| + return InputEvent::InputType::None; |
| + } |
| +} |
| + |
| } // anonymous namespace |
| class EditorInternalCommand { |
| @@ -1751,6 +1788,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)); |