Support InputEvent.inputType for the new InputEvent spec
https://bugs.webkit.org/show_bug.cgi?id=163025
<rdar://problem/28658092>

Reviewed by Darin Adler.

Source/WebCore:

Adds support for the inputType attribute of InputEvent. To do this, we introduce a helper to
map EditActions to inputType names, and also split out ambiguous EditActions (such as
EditActionTyping) into more specific subtypes (such as EditActionTypingDeleteBackward,
EditActionTypingInsertParagraph, etc.), each of which corresponds to an inputType.

In places where we create CompositeEditCommands, we now pass in these specific EditActions
where appropriate, and when dispatching `beforeinput` and `input` events, we ask the
CompositeEditCommand for its input type name, which it derives from its editingAction.

Tests: fast/events/before-input-prevent-biu.html
       fast/events/before-input-prevent-cut.html
       fast/events/before-input-prevent-paste.html
       fast/events/before-input-prevent-typing.html
       fast/events/before-input-prevent-undo.html

* dom/InputEvent.h:
* dom/Node.cpp:
(WebCore::Node::dispatchInputEvent):
* dom/Node.h:
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::apply):
(WebCore::CompositeEditCommand::inputEventTypeName):

Allows a CompositeEditCommand to specify the inputType its corresponding `beforeinput` and `input` events
should have.

* editing/CompositeEditCommand.h:
(WebCore::CompositeEditCommand::shouldStopCaretBlinking): Deleted.
* editing/EditAction.h:
* editing/EditCommand.cpp:
(WebCore::inputTypeNameForEditingAction):
* editing/EditCommand.h:
* editing/Editor.cpp:
(WebCore::Editor::willApplyEditing):
(WebCore::Editor::appliedEditing):
(WebCore::Editor::willUnapplyEditing):
(WebCore::Editor::unappliedEditing):
(WebCore::Editor::willReapplyEditing):
(WebCore::Editor::reappliedEditing):
(WebCore::Editor::computeAndSetTypingStyle):
* editing/InsertListCommand.cpp:
(WebCore::InsertListCommand::editingAction):
* editing/InsertListCommand.h:
(WebCore::InsertListCommand::preservesTypingStyle): Deleted.
(WebCore::InsertListCommand::editingAction): Deleted.
* editing/ReplaceRangeWithTextCommand.cpp:
(WebCore::ReplaceRangeWithTextCommand::ReplaceRangeWithTextCommand):
* editing/SpellingCorrectionCommand.cpp:
(WebCore::SpellingCorrectionCommand::SpellingCorrectionCommand):
* editing/TypingCommand.cpp:
(WebCore::editActionForTypingCommand):
(WebCore::TypingCommand::TypingCommand):
(WebCore::TypingCommand::inputEventTypeName):

The editingAction() of a TypingCommand is the first editing action the TypingCommand was initialized using.
Since subsequent typing commands update the last open typing command, we override inputEventTypeName here to
use the last updated editing action rather than the default (initial) editing action.

(WebCore::TypingCommand::willAddTypingToOpenCommand):
(WebCore::TypingCommand::insertTextRunWithoutNewlines):
(WebCore::TypingCommand::insertParagraphSeparator):
* editing/TypingCommand.h:

Source/WebKit/mac:

Accounts for some changes to the EditAction enum in nameForEditAction. See WebCore ChangeLog
entry for more details.

* WebCoreSupport/WebEditorClient.mm:
(undoNameForEditAction):

Source/WebKit/win:

* WebCoreSupport/WebEditorClient.cpp:
(undoNameForEditAction):

Source/WebKit2:

Accounts for some changes to the EditAction enum in nameForEditAction. Some former edit
actions, such as EditActionTyping, have been split out into its more specific subtypes,
so we preserve shipping behavior by treating all of the new subtypes the same way as the
original type.

* UIProcess/WebEditCommandProxy.cpp:
(WebKit::WebEditCommandProxy::nameForEditAction):

LayoutTests:

Adds new layout tests to check that various actions, such as cutting, pasting and undoing can
be prevented via the InputEvent fired in a `beforechange` handler.

* fast/events/before-input-prevent-biu-expected.txt: Added.
* fast/events/before-input-prevent-biu.html: Added.
* fast/events/before-input-prevent-cut-expected.txt: Added.
* fast/events/before-input-prevent-cut.html: Added.
* fast/events/before-input-prevent-paste-expected.txt: Added.
* fast/events/before-input-prevent-paste.html: Added.
* fast/events/before-input-prevent-typing-expected.txt: Added.
* fast/events/before-input-prevent-typing.html: Added.
* fast/events/before-input-prevent-undo-expected.txt: Added.
* fast/events/before-input-prevent-undo.html: Added.
* platform/ios-simulator/TestExpectations:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@206979 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TypingCommand.cpp b/Source/WebCore/editing/TypingCommand.cpp
index 1412711..e35f6d3 100644
--- a/Source/WebCore/editing/TypingCommand.cpp
+++ b/Source/WebCore/editing/TypingCommand.cpp
@@ -76,8 +76,38 @@
     const String& m_text;
 };
 
+static inline EditAction editActionForTypingCommand(TypingCommand::ETypingCommand command, TextGranularity granularity)
+{
+    switch (command) {
+    case TypingCommand::DeleteSelection:
+        return EditActionTypingDeleteSelection;
+    case TypingCommand::DeleteKey: {
+        if (granularity == WordGranularity)
+            return EditActionTypingDeleteWordBackward;
+        if (granularity == LineBoundary)
+            return EditActionTypingDeleteLineBackward;
+        return EditActionTypingDeleteBackward;
+    }
+    case TypingCommand::ForwardDeleteKey:
+        if (granularity == WordGranularity)
+            return EditActionTypingDeleteWordForward;
+        if (granularity == LineBoundary)
+            return EditActionTypingDeleteLineForward;
+        return EditActionTypingDeleteForward;
+    case TypingCommand::InsertText:
+        return EditActionTypingInsertText;
+    case TypingCommand::InsertLineBreak:
+        return EditActionTypingInsertLineBreak;
+    case TypingCommand::InsertParagraphSeparator:
+    case TypingCommand::InsertParagraphSeparatorInQuotedContent:
+        return EditActionTypingInsertParagraph;
+    default:
+        return EditActionUnspecified;
+    }
+}
+
 TypingCommand::TypingCommand(Document& document, ETypingCommand commandType, const String &textToInsert, Options options, TextGranularity granularity, TextCompositionType compositionType)
-    : TextInsertionBaseCommand(document, EditActionTyping)
+    : TextInsertionBaseCommand(document, editActionForTypingCommand(commandType, granularity))
     , m_commandType(commandType)
     , m_textToInsert(textToInsert)
     , m_openForMoreTyping(true)
@@ -90,6 +120,7 @@
     , m_shouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator)
     , m_shouldPreventSpellChecking(options & PreventSpellChecking)
 {
+    m_currentTypingEditAction = editingAction();
     updatePreservesTypingStyle(m_commandType);
 }
 
@@ -308,6 +339,11 @@
     ASSERT_NOT_REACHED();
 }
 
+String TypingCommand::inputEventTypeName() const
+{
+    return inputTypeNameForEditingAction(m_currentTypingEditAction);
+}
+
 void TypingCommand::didApplyCommand()
 {
     // TypingCommands handle applied editing separately (see TypingCommand::typingAddedToOpenCommand).
@@ -368,13 +404,14 @@
     }
 }
 
-bool TypingCommand::willAddTypingToOpenCommand(ETypingCommand, TextGranularity)
+bool TypingCommand::willAddTypingToOpenCommand(ETypingCommand commandType, TextGranularity granularity)
 {
     if (m_isHandlingInitialTypingCommand)
         return true;
 
     // FIXME: Use the newly added typing command and granularity to ensure that an InputEvent with the
     // correct inputType is dispatched.
+    m_currentTypingEditAction = editActionForTypingCommand(commandType, granularity);
     return frame().editor().willApplyEditing(*this);
 }
 
@@ -423,7 +460,7 @@
         return;
 
     RefPtr<InsertTextCommand> command = InsertTextCommand::create(document(), text, selectInsertedText,
-        m_compositionType == TextCompositionNone ? InsertTextCommand::RebalanceLeadingAndTrailingWhitespaces : InsertTextCommand::RebalanceAllWhitespaces, EditActionTyping);
+        m_compositionType == TextCompositionNone ? InsertTextCommand::RebalanceLeadingAndTrailingWhitespaces : InsertTextCommand::RebalanceAllWhitespaces, EditActionTypingInsertText);
 
     applyCommandToComposite(command, endingSelection());
 
@@ -458,7 +495,7 @@
     if (!willAddTypingToOpenCommand(InsertParagraphSeparator, ParagraphGranularity))
         return;
 
-    applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(), false, false, EditActionTyping));
+    applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(), false, false, EditActionTypingInsertParagraph));
     typingAddedToOpenCommand(InsertParagraphSeparator);
 }