| 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..fe3fdfdc55ab2179587618a04286b13fb1ddf6ad 100644
|
| --- a/third_party/WebKit/Source/core/editing/Editor.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/Editor.cpp
|
| @@ -96,6 +96,61 @@ 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);
|
| +}
|
| +
|
| +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(const CompositeEditCommand* command)
|
| +{
|
| + if (command->isTypingCommand()) {
|
| + const TypingCommand* typingCommand = toTypingCommand(command);
|
| + // 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;
|
| + }
|
| + }
|
| +
|
| + // TODO(chongz): Handle other edit actions.
|
| + return InputEvent::InputType::None;
|
| +}
|
| +
|
| +InputEvent::EventIsComposing isComposingFromCommand(const CompositeEditCommand* command)
|
| +{
|
| + if (command->isTypingCommand() && toTypingCommand(command)->compositionType() != TypingCommand::TextCompositionNone)
|
| + return InputEvent::EventIsComposing::IsComposing;
|
| + return InputEvent::EventIsComposing::NotComposing;
|
| +}
|
| +
|
| +} // anonymous namespace
|
| +
|
| Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor)
|
| : m_editor(editor)
|
| {
|
| @@ -702,6 +757,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 +788,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 +807,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);
|
|
|