Changeset 207698 in webkit


Ignore:
Timestamp:
Oct 21, 2016 4:06:05 PM (8 years ago)
Author:
Wenson Hsieh
Message:

Support (insertFrom|deleteBy)Composition and (insert|delete)CompositionText inputTypes for InputEvents
https://bugs.webkit.org/show_bug.cgi?id=163460
<rdar://problem/28784142>

Reviewed by Darin Adler.

Source/WebCore:

Adds basic support for the composition inputTypes in the InputEvent spec. See w3.org/TR/input-events,
github.com/w3c/input-events/issues/41 and github.com/w3c/input-events/issues/42 for more details. While input
events are fired in the correct order with respect to each other, additional work will be required to ensure
that input events are fired in the correct order with respect to composition(start|update|end) events and
textInput events. This is held off until the expected ordering of events is officially defined in the spec.

Tests: fast/events/before-input-events-prevent-insert-composition.html

fast/events/before-input-events-prevent-recomposition.html
fast/events/input-events-ime-composition.html
fast/events/input-events-ime-recomposition.html

  • editing/CompositeEditCommand.cpp:

(WebCore::CompositeEditCommand::apply):

  • editing/CompositeEditCommand.h:

(WebCore::CompositeEditCommand::isBeforeInputEventCancelable):

Adds a new virtual method hook for subclasses to mark their beforeinput events as non-cancelable (see
TypingCommand::isBeforeInputEventCancelable). By default, beforeinput events are cancelable.

  • editing/EditAction.h:

Adds 4 new EditActions corresponding to the 4 composition-related inputTypes. These are:
EditActionTypingDeletePendingComposition => "deleteCompositionText"
EditActionTypingDeleteFinalComposition => "deleteByComposition"
EditActionTypingInsertPendingComposition => "insertCompositionText"
EditActionTypingInsertFinalComposition => "insertFromComposition"

  • editing/EditCommand.cpp:

(WebCore::inputTypeNameForEditingAction):

  • editing/Editor.cpp:

(WebCore::dispatchBeforeInputEvent):
(WebCore::dispatchBeforeInputEvents):
(WebCore::Editor::willApplyEditing):
(WebCore::Editor::insertTextWithoutSendingTextEvent):
(WebCore::Editor::setComposition):

In setComposition(text, mode), tweak the logic for committing a composition to always delete the selection
before inserting the final composition text. In setComposition(text, underlines, start, end), catch the case
where we're beginning to recompose an existing range in the DOM and delete the recomposed text first.

  • editing/TypingCommand.cpp:

(WebCore::editActionForTypingCommand):
(WebCore::TypingCommand::TypingCommand):
(WebCore::TypingCommand::deleteSelection):

Adds a TextCompositionType parameter so that call sites (see Editor::setComposition) can indicate what state the
edited composition is in. This allows us to differentiate between deletion of finalized composition text in
preparation of recomposing a range in the DOM, and deletion of composition text that has not yet been committed
in preparation for inserting a finalized composition into the DOM.

(WebCore::TypingCommand::deleteKeyPressed):
(WebCore::TypingCommand::forwardDeleteKeyPressed):
(WebCore::TypingCommand::insertText):
(WebCore::TypingCommand::insertLineBreak):
(WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent):
(WebCore::TypingCommand::insertParagraphSeparator):
(WebCore::TypingCommand::isBeforeInputEventCancelable):
(WebCore::TypingCommand::inputEventData):
(WebCore::TypingCommand::willAddTypingToOpenCommand):

  • editing/TypingCommand.h:

Source/WebKit/mac:

Handle new EditAction types for inserting/deleting pending/final compositions.

  • WebCoreSupport/WebEditorClient.mm:

(undoNameForEditAction):

Source/WebKit2:

Handle new EditAction types for inserting/deleting pending/final compositions.

  • UIProcess/WebEditCommandProxy.cpp:

(WebKit::WebEditCommandProxy::nameForEditAction):

LayoutTests:

Adds 4 new layout tests to verify that composition events are dispatched as expected when using IME, and that
input events of type "insertFromComposition" and "deleteByComposition" can be prevented.

Also rebaselines an existing WK1 editing test (text-input-controller.html) to account for how we now delete the
existing composition text before inserting the finalized composition text in Editor::setComposition. This means
that there are a few more delegate calls than there were before (as seen in the expected output), although the
resulting behavior is still the same.

  • editing/mac/input/text-input-controller-expected.txt:
  • fast/events/before-input-events-prevent-insert-composition.html: Added.
  • fast/events/before-input-events-prevent-recomposition.html: Added.
  • fast/events/input-events-ime-composition.html: Added.
  • fast/events/input-events-ime-recomposition.html: Added.
  • platform/ios-simulator/TestExpectations:
Location:
trunk
Files:
8 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r207692 r207698  
     12016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support (insertFrom|deleteBy)Composition and (insert|delete)CompositionText inputTypes for InputEvents
     4        https://bugs.webkit.org/show_bug.cgi?id=163460
     5        <rdar://problem/28784142>
     6
     7        Reviewed by Darin Adler.
     8
     9        Adds 4 new layout tests to verify that composition events are dispatched as expected when using IME, and that
     10        input events of type "insertFromComposition" and "deleteByComposition" can be prevented.
     11
     12        Also rebaselines an existing WK1 editing test (text-input-controller.html) to account for how we now delete the
     13        existing composition text before inserting the finalized composition text in Editor::setComposition. This means
     14        that there are a few more delegate calls than there were before (as seen in the expected output), although the
     15        resulting behavior is still the same.
     16
     17        * editing/mac/input/text-input-controller-expected.txt:
     18        * fast/events/before-input-events-prevent-insert-composition.html: Added.
     19        * fast/events/before-input-events-prevent-recomposition.html: Added.
     20        * fast/events/input-events-ime-composition.html: Added.
     21        * fast/events/input-events-ime-recomposition.html: Added.
     22        * platform/ios-simulator/TestExpectations:
     23
    1242016-10-20  Dean Jackson  <dino@apple.com>
    225
  • trunk/LayoutTests/editing/mac/input/text-input-controller-expected.txt

    r187932 r207698  
    2323EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    2424EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
    25 EDITING DELEGATE: shouldInsertText:Success replacingDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document givenAction:WebViewInsertActionTyped
    2625EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    27 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     26EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     27EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
     28EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     29EDITING DELEGATE: shouldInsertText:Success replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionTyped
     30EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document toDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    2831EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    2932EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
  • trunk/LayoutTests/platform/ios-simulator/TestExpectations

    r207670 r207698  
    12101210fast/events/input-events-typing-data.html [ Failure ]
    12111211fast/events/input-events-forecolor-data.html [ Failure ]
     1212fast/events/input-events-ime-recomposition.html [ Failure ]
     1213fast/events/input-events-ime-composition.html [ Failure ]
    12121214fast/events/before-input-events-prevent-default.html [ Failure ]
    12131215fast/events/before-input-events-prevent-default-in-textfield.html [ Failure ]
     
    12211223fast/events/before-input-replace-text-target-ranges.html [ Failure ]
    12221224fast/events/before-input-delete-empty-list-target-ranges.html [ Failure ]
     1225fast/events/before-input-events-prevent-recomposition.html [ Failure ]
     1226fast/events/before-input-events-prevent-insert-composition.html [ Failure ]
    12231227fast/events/key-events-in-input-button.html [ Failure ]
    12241228fast/events/keydown-1.html [ Failure ]
  • trunk/Source/WebCore/ChangeLog

    r207695 r207698  
     12016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support (insertFrom|deleteBy)Composition and (insert|delete)CompositionText inputTypes for InputEvents
     4        https://bugs.webkit.org/show_bug.cgi?id=163460
     5        <rdar://problem/28784142>
     6
     7        Reviewed by Darin Adler.
     8
     9        Adds basic support for the composition inputTypes in the InputEvent spec. See w3.org/TR/input-events,
     10        github.com/w3c/input-events/issues/41 and github.com/w3c/input-events/issues/42 for more details. While input
     11        events are fired in the correct order with respect to each other, additional work will be required to ensure
     12        that input events are fired in the correct order with respect to composition(start|update|end) events and
     13        textInput events. This is held off until the expected ordering of events is officially defined in the spec.
     14
     15        Tests: fast/events/before-input-events-prevent-insert-composition.html
     16               fast/events/before-input-events-prevent-recomposition.html
     17               fast/events/input-events-ime-composition.html
     18               fast/events/input-events-ime-recomposition.html
     19
     20        * editing/CompositeEditCommand.cpp:
     21        (WebCore::CompositeEditCommand::apply):
     22        * editing/CompositeEditCommand.h:
     23        (WebCore::CompositeEditCommand::isBeforeInputEventCancelable):
     24
     25        Adds a new virtual method hook for subclasses to mark their `beforeinput` events as non-cancelable (see
     26        TypingCommand::isBeforeInputEventCancelable). By default, `beforeinput` events are cancelable.
     27
     28        * editing/EditAction.h:
     29
     30        Adds 4 new EditActions corresponding to the 4 composition-related inputTypes. These are:
     31        EditActionTypingDeletePendingComposition    => "deleteCompositionText"
     32        EditActionTypingDeleteFinalComposition      => "deleteByComposition"
     33        EditActionTypingInsertPendingComposition    => "insertCompositionText"
     34        EditActionTypingInsertFinalComposition      => "insertFromComposition"
     35
     36        * editing/EditCommand.cpp:
     37        (WebCore::inputTypeNameForEditingAction):
     38        * editing/Editor.cpp:
     39        (WebCore::dispatchBeforeInputEvent):
     40        (WebCore::dispatchBeforeInputEvents):
     41        (WebCore::Editor::willApplyEditing):
     42        (WebCore::Editor::insertTextWithoutSendingTextEvent):
     43        (WebCore::Editor::setComposition):
     44
     45        In setComposition(text, mode), tweak the logic for committing a composition to always delete the selection
     46        before inserting the final composition text. In setComposition(text, underlines, start, end), catch the case
     47        where we're beginning to recompose an existing range in the DOM and delete the recomposed text first.
     48
     49        * editing/TypingCommand.cpp:
     50        (WebCore::editActionForTypingCommand):
     51        (WebCore::TypingCommand::TypingCommand):
     52        (WebCore::TypingCommand::deleteSelection):
     53
     54        Adds a TextCompositionType parameter so that call sites (see Editor::setComposition) can indicate what state the
     55        edited composition is in. This allows us to differentiate between deletion of finalized composition text in
     56        preparation of recomposing a range in the DOM, and deletion of composition text that has not yet been committed
     57        in preparation for inserting a finalized composition into the DOM.
     58
     59        (WebCore::TypingCommand::deleteKeyPressed):
     60        (WebCore::TypingCommand::forwardDeleteKeyPressed):
     61        (WebCore::TypingCommand::insertText):
     62        (WebCore::TypingCommand::insertLineBreak):
     63        (WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent):
     64        (WebCore::TypingCommand::insertParagraphSeparator):
     65        (WebCore::TypingCommand::isBeforeInputEventCancelable):
     66        (WebCore::TypingCommand::inputEventData):
     67        (WebCore::TypingCommand::willAddTypingToOpenCommand):
     68        * editing/TypingCommand.h:
     69
    1702016-10-21  Dave Hyatt  <hyatt@apple.com>
    271
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r207670 r207698  
    335335        case EditActionTypingDeleteLineBackward:
    336336        case EditActionTypingDeleteLineForward:
     337        case EditActionTypingDeletePendingComposition:
     338        case EditActionTypingDeleteFinalComposition:
    337339        case EditActionTypingInsertText:
    338340        case EditActionTypingInsertLineBreak:
    339341        case EditActionTypingInsertParagraph:
     342        case EditActionTypingInsertPendingComposition:
     343        case EditActionTypingInsertFinalComposition:
    340344        case EditActionPaste:
    341345        case EditActionDrag:
  • trunk/Source/WebCore/editing/CompositeEditCommand.h

    r207670 r207698  
    117117    virtual String inputEventTypeName() const;
    118118    virtual String inputEventData() const { return { }; }
     119    virtual bool isBeforeInputEventCancelable() const { return true; }
    119120    Vector<RefPtr<StaticRange>> targetRangesForBindings() const;
    120121
  • trunk/Source/WebCore/editing/EditAction.h

    r206979 r207698  
    7272        EditActionTypingDeleteLineBackward,
    7373        EditActionTypingDeleteLineForward,
     74        EditActionTypingDeletePendingComposition,
     75        EditActionTypingDeleteFinalComposition,
    7476        EditActionTypingInsertText,
    7577        EditActionTypingInsertLineBreak,
    7678        EditActionTypingInsertParagraph,
     79        EditActionTypingInsertPendingComposition,
     80        EditActionTypingInsertFinalComposition,
    7781        EditActionCreateLink,
    7882        EditActionUnlink,
  • trunk/Source/WebCore/editing/EditCommand.cpp

    r207670 r207698  
    8484    case EditActionTypingDeleteLineForward:
    8585        return ASCIILiteral("deleteHardLineForward");
     86    case EditActionTypingDeletePendingComposition:
     87        return ASCIILiteral("deleteCompositionText");
     88    case EditActionTypingDeleteFinalComposition:
     89        return ASCIILiteral("deleteByComposition");
    8690    case EditActionInsert:
    8791    case EditActionTypingInsertText:
     
    97101    case EditActionInsertUnorderedList:
    98102        return ASCIILiteral("insertUnorderedList");
     103    case EditActionTypingInsertPendingComposition:
     104        return ASCIILiteral("insertCompositionText");
     105    case EditActionTypingInsertFinalComposition:
     106        return ASCIILiteral("insertFromComposition");
    99107    case EditActionIndent:
    100108        return ASCIILiteral("formatIndent");
  • trunk/Source/WebCore/editing/Editor.cpp

    r207670 r207698  
    112112namespace WebCore {
    113113
    114 static bool dispatchBeforeInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })
     114static bool dispatchBeforeInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { }, bool cancelable = true)
    115115{
    116116    auto* settings = element.document().settings();
     
    118118        return true;
    119119
    120     return element.dispatchEvent(InputEvent::create(eventNames().beforeinputEvent, inputType, true, true, element.document().defaultView(), data, targetRanges, 0));
     120    return element.dispatchEvent(InputEvent::create(eventNames().beforeinputEvent, inputType, true, cancelable, element.document().defaultView(), data, targetRanges, 0));
    121121}
    122122
     
    125125    auto* settings = element.document().settings();
    126126    if (settings && settings->inputEventsEnabled())
    127         element.dispatchScopedEvent(InputEvent::create(eventNames().inputEvent, inputType, true, false, element.document().defaultView(), data, targetRanges, 0));
     127        element.dispatchEvent(InputEvent::create(eventNames().inputEvent, inputType, true, false, element.document().defaultView(), data, targetRanges, 0));
    128128    else
    129129        element.dispatchInputEvent();
     
    10641064}
    10651065
    1066 static bool dispatchBeforeInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })
     1066static bool dispatchBeforeInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { }, bool cancelable = true)
    10671067{
    10681068    bool continueWithDefaultBehavior = true;
    10691069    if (startRoot)
    1070         continueWithDefaultBehavior &= dispatchBeforeInputEvent(*startRoot, inputTypeName, data, targetRanges);
     1070        continueWithDefaultBehavior &= dispatchBeforeInputEvent(*startRoot, inputTypeName, data, targetRanges, cancelable);
    10711071    if (endRoot && endRoot != startRoot)
    1072         continueWithDefaultBehavior &= dispatchBeforeInputEvent(*endRoot, inputTypeName, data, targetRanges);
     1072        continueWithDefaultBehavior &= dispatchBeforeInputEvent(*endRoot, inputTypeName, data, targetRanges, cancelable);
    10731073    return continueWithDefaultBehavior;
    10741074}
     
    10881088        return true;
    10891089
    1090     return dispatchBeforeInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), targetRanges);
     1090    return dispatchBeforeInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), targetRanges, command.isBeforeInputEventCancelable());
    10911091}
    10921092
     
    12621262                if (autocorrectionWasApplied)
    12631263                    options |= TypingCommand::RetainAutocorrectionIndicator;
    1264                 TypingCommand::insertText(document, text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionConfirm : TypingCommand::TextCompositionNone);
     1264                TypingCommand::insertText(document, text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionFinal : TypingCommand::TextCompositionNone);
    12651265            }
    12661266
     
    18331833    }
    18341834
    1835     // If text is empty, then delete the old composition here.  If text is non-empty, InsertTextCommand::input
    1836     // will delete the old composition with an optimized replace operation.
    1837     if (text.isEmpty() && mode != CancelComposition)
    1838         TypingCommand::deleteSelection(document(), 0);
     1835    // Always delete the current composition before inserting the finalized composition text if we're confirming our composition.
     1836    // Our default behavior (if the beforeinput event is not prevented) is to insert the finalized composition text back in.
     1837    // We pass TypingCommand::TextCompositionPending here to indicate that we are deleting the pending composition.
     1838    if (mode != CancelComposition)
     1839        TypingCommand::deleteSelection(document(), 0, TypingCommand::TextCompositionPending);
    18391840
    18401841    m_compositionNode = nullptr;
     
    18671868        setIgnoreCompositionSelectionChange(false);
    18681869        return;
     1870    }
     1871
     1872    String originalText = selectedText();
     1873    bool isStartingToRecomposeExistingRange = !text.isEmpty() && selectionStart < selectionEnd && !hasComposition();
     1874    if (isStartingToRecomposeExistingRange) {
     1875        // We pass TypingCommand::TextCompositionFinal here to indicate that we are removing composition text that has been finalized.
     1876        TypingCommand::deleteSelection(document(), 0, TypingCommand::TextCompositionFinal);
     1877        const VisibleSelection& currentSelection = m_frame.selection().selection();
     1878        if (currentSelection.isRange()) {
     1879            // If deletion was prevented, then we need to collapse the selection to the end so that the original text will not be recomposed.
     1880            m_frame.selection().setSelection({ currentSelection.end(), currentSelection.end() });
     1881        }
    18691882    }
    18701883
     
    18951908            // function doesn't create a composition node when the text is empty.
    18961909            if (!text.isEmpty()) {
    1897                 target->dispatchEvent(CompositionEvent::create(eventNames().compositionstartEvent, document().domWindow(), selectedText()));
     1910                target->dispatchEvent(CompositionEvent::create(eventNames().compositionstartEvent, document().domWindow(), originalText));
    18981911                event = CompositionEvent::create(eventNames().compositionupdateEvent, document().domWindow(), text);
    18991912            }
     
    19111924    // will delete the old composition with an optimized replace operation.
    19121925    if (text.isEmpty())
    1913         TypingCommand::deleteSelection(document(), TypingCommand::PreventSpellChecking);
     1926        TypingCommand::deleteSelection(document(), TypingCommand::PreventSpellChecking, TypingCommand::TextCompositionPending);
    19141927
    19151928    m_compositionNode = nullptr;
     
    19171930
    19181931    if (!text.isEmpty()) {
    1919         TypingCommand::insertText(document(), text, TypingCommand::SelectInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextCompositionUpdate);
     1932        TypingCommand::insertText(document(), text, TypingCommand::SelectInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextCompositionPending);
    19201933
    19211934        // Find out what node has the composition now.
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r207670 r207698  
    7878};
    7979
    80 static inline EditAction editActionForTypingCommand(TypingCommand::ETypingCommand command, TextGranularity granularity)
    81 {
     80static inline EditAction editActionForTypingCommand(TypingCommand::ETypingCommand command, TextGranularity granularity, TypingCommand::TextCompositionType compositionType)
     81{
     82    if (compositionType == TypingCommand::TextCompositionPending) {
     83        if (command == TypingCommand::InsertText)
     84            return EditActionTypingInsertPendingComposition;
     85        if (command == TypingCommand::DeleteSelection)
     86            return EditActionTypingDeletePendingComposition;
     87        ASSERT_NOT_REACHED();
     88    }
     89
     90    if (compositionType == TypingCommand::TextCompositionFinal) {
     91        if (command == TypingCommand::InsertText)
     92            return EditActionTypingInsertFinalComposition;
     93        if (command == TypingCommand::DeleteSelection)
     94            return EditActionTypingDeleteFinalComposition;
     95        ASSERT_NOT_REACHED();
     96    }
     97
    8298    switch (command) {
    8399    case TypingCommand::DeleteSelection:
     
    125141
    126142TypingCommand::TypingCommand(Document& document, ETypingCommand commandType, const String &textToInsert, Options options, TextGranularity granularity, TextCompositionType compositionType)
    127     : TextInsertionBaseCommand(document, editActionForTypingCommand(commandType, granularity))
     143    : TextInsertionBaseCommand(document, editActionForTypingCommand(commandType, granularity, compositionType))
    128144    , m_commandType(commandType)
    129145    , m_textToInsert(textToInsert)
     
    143159}
    144160
    145 void TypingCommand::deleteSelection(Document& document, Options options)
     161void TypingCommand::deleteSelection(Document& document, Options options, TextCompositionType compositionType)
    146162{
    147163    Frame* frame = document.frame();
     
    152168
    153169    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
     170        lastTypingCommand->setCompositionType(compositionType);
    154171        lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
    155172        lastTypingCommand->deleteSelection(options & SmartDelete);
     
    157174    }
    158175
    159     TypingCommand::create(document, DeleteSelection, emptyString(), options)->apply();
     176    TypingCommand::create(document, DeleteSelection, emptyString(), options, compositionType)->apply();
    160177}
    161178
     
    165182        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
    166183            updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document.frame());
     184            lastTypingCommand->setCompositionType(TextCompositionNone);
    167185            lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
    168186            lastTypingCommand->deleteKeyPressed(granularity, options & AddsToKillRing);
     
    181199        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
    182200            updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), frame);
     201            lastTypingCommand->setCompositionType(TextCompositionNone);
    183202            lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
    184203            lastTypingCommand->forwardDeleteKeyPressed(granularity, options & AddsToKillRing);
     
    222241    VisibleSelection currentSelection = frame->selection().selection();
    223242
    224     String newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion, compositionType == TextCompositionUpdate);
     243    String newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion, compositionType == TextCompositionPending);
    225244   
    226245    // Set the starting and ending selection appropriately if we are using a selection
     
    247266{
    248267    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
     268        lastTypingCommand->setCompositionType(TextCompositionNone);
    249269        lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
    250270        lastTypingCommand->insertLineBreakAndNotifyAccessibility();
     
    258278{
    259279    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
     280        lastTypingCommand->setCompositionType(TextCompositionNone);
    260281        lastTypingCommand->insertParagraphSeparatorInQuotedContentAndNotifyAccessibility();
    261282        return;
     
    268289{
    269290    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
     291        lastTypingCommand->setCompositionType(TextCompositionNone);
    270292        lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
    271293        lastTypingCommand->insertParagraphSeparatorAndNotifyAccessibility();
     
    368390}
    369391
     392bool TypingCommand::isBeforeInputEventCancelable() const
     393{
     394    return m_currentTypingEditAction != EditActionTypingInsertPendingComposition && m_currentTypingEditAction != EditActionTypingDeletePendingComposition;
     395}
     396
    370397String TypingCommand::inputEventData() const
    371398{
    372     if (m_currentTypingEditAction == EditActionTypingInsertText)
     399    switch (m_currentTypingEditAction) {
     400    case EditActionTypingInsertText:
     401    case EditActionTypingInsertPendingComposition:
     402    case EditActionTypingInsertFinalComposition:
    373403        return m_currentTextToInsert;
    374 
    375     return CompositeEditCommand::inputEventData();
     404    default:
     405        return CompositeEditCommand::inputEventData();
     406    }
    376407}
    377408
     
    439470{
    440471    m_currentTextToInsert = text;
    441     m_currentTypingEditAction = editActionForTypingCommand(commandType, granularity);
     472    m_currentTypingEditAction = editActionForTypingCommand(commandType, granularity, m_compositionType);
    442473
    443474    if (!shouldDeferWillApplyCommandUntilAddingTypingCommand())
  • trunk/Source/WebCore/editing/TypingCommand.h

    r207670 r207698  
    4545    enum TextCompositionType {
    4646        TextCompositionNone,
    47         TextCompositionUpdate,
    48         TextCompositionConfirm
     47        TextCompositionPending,
     48        TextCompositionFinal,
    4949    };
    5050
     
    5858    typedef unsigned Options;
    5959
    60     static void deleteSelection(Document&, Options = 0);
     60    static void deleteSelection(Document&, Options = 0, TextCompositionType = TextCompositionNone);
    6161    static void deleteKeyPressed(Document&, Options = 0, TextGranularity = CharacterGranularity);
    6262    static void forwardDeleteKeyPressed(Document&, Options = 0, TextGranularity = CharacterGranularity);
     
    8686
    8787private:
    88     static Ref<TypingCommand> create(Document& document, ETypingCommand command, const String& text = emptyString(), Options options = 0, TextGranularity granularity = CharacterGranularity)
     88    static Ref<TypingCommand> create(Document& document, ETypingCommand command, const String& text = emptyString(), Options options = 0, TextGranularity granularity = CharacterGranularity, TextCompositionType compositionType = TextCompositionNone)
    8989    {
    90         return adoptRef(*new TypingCommand(document, command, text, options, granularity, TextCompositionNone));
     90        return adoptRef(*new TypingCommand(document, command, text, options, granularity, compositionType));
    9191    }
    9292
     
    119119    String inputEventTypeName() const final;
    120120    String inputEventData() const final;
     121    bool isBeforeInputEventCancelable() const final;
    121122
    122123    static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Frame*);
  • trunk/Source/WebKit/mac/ChangeLog

    r207689 r207698  
     12016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support (insertFrom|deleteBy)Composition and (insert|delete)CompositionText inputTypes for InputEvents
     4        https://bugs.webkit.org/show_bug.cgi?id=163460
     5        <rdar://problem/28784142>
     6
     7        Reviewed by Darin Adler.
     8
     9        Handle new EditAction types for inserting/deleting pending/final compositions.
     10
     11        * WebCoreSupport/WebEditorClient.mm:
     12        (undoNameForEditAction):
     13
    1142016-10-21  Jeremy Jones  <jeremyj@apple.com>
    215
  • trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm

    r206979 r207698  
    601601        case EditActionTypingDeleteLineBackward:
    602602        case EditActionTypingDeleteLineForward:
     603        case EditActionTypingDeletePendingComposition:
     604        case EditActionTypingDeleteFinalComposition:
    603605        case EditActionTypingInsertText:
    604606        case EditActionTypingInsertLineBreak:
    605607        case EditActionTypingInsertParagraph:
     608        case EditActionTypingInsertPendingComposition:
     609        case EditActionTypingInsertFinalComposition:
    606610            return UI_STRING_KEY_INTERNAL("Typing", "Typing (Undo action name)", "Undo action name");
    607611        case EditActionCreateLink: return UI_STRING_KEY_INTERNAL("Create Link", "Create Link (Undo action name)", "Undo action name");
  • trunk/Source/WebKit2/ChangeLog

    r207689 r207698  
     12016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support (insertFrom|deleteBy)Composition and (insert|delete)CompositionText inputTypes for InputEvents
     4        https://bugs.webkit.org/show_bug.cgi?id=163460
     5        <rdar://problem/28784142>
     6
     7        Reviewed by Darin Adler.
     8
     9        Handle new EditAction types for inserting/deleting pending/final compositions.
     10
     11        * UIProcess/WebEditCommandProxy.cpp:
     12        (WebKit::WebEditCommandProxy::nameForEditAction):
     13
    1142016-10-21  Jeremy Jones  <jeremyj@apple.com>
    215
  • trunk/Source/WebKit2/UIProcess/WebEditCommandProxy.cpp

    r206979 r207698  
    152152    case EditActionTypingDeleteLineBackward:
    153153    case EditActionTypingDeleteLineForward:
     154    case EditActionTypingDeletePendingComposition:
     155    case EditActionTypingDeleteFinalComposition:
    154156    case EditActionTypingInsertText:
    155157    case EditActionTypingInsertLineBreak:
    156158    case EditActionTypingInsertParagraph:
     159    case EditActionTypingInsertPendingComposition:
     160    case EditActionTypingInsertFinalComposition:
    157161        return WEB_UI_STRING_KEY("Typing", "Typing (Undo action name)", "Undo action name");
    158162    case EditActionCreateLink:
Note: See TracChangeset for help on using the changeset viewer.