Changeset 208143 in webkit


Ignore:
Timestamp:
Oct 31, 2016, 8:12:00 AM (9 years ago)
Author:
Wenson Hsieh
Message:

Holding down a key to choose an accented character should fire "insertReplacementText" input events
https://bugs.webkit.org/show_bug.cgi?id=164209
<rdar://problem/29019305>

Reviewed by Darin Adler.

Source/WebCore:

For TypingCommands that correspond to "insertReplacementText" inputTypes, vend dataTransfers for resulting
beforeinput and input events if the edited area is not an input field or textarea. To do this, convert the plain
text representation of the content to be inserted to HTML text using a helper function,
MarkupAccumulator::appendCharactersReplacingEntities, that is used when creating markup for Text nodes.

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

fast/events/input-event-insert-replacement.html

  • editing/TypingCommand.cpp:

(WebCore::TypingCommand::inputEventData):
(WebCore::TypingCommand::inputEventDataTransfer):

  • editing/TypingCommand.h:

Source/WebKit2:

When replacing text, call Editor::insertText with the correct TextEventInputType so that WebCore will know to
use EditActionInsertReplacement when creating and applying the corresponding TypingCommand. Additional minor
changes in order to support testing replacement text insertion.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _insertText:replacementRange:]):

  • UIProcess/API/Cocoa/WKWebViewPrivate.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::insertTextAsync):

Tools:

Adds test support for inserting replacement text on Mac. This is equivalent to holding down a vowel key (e.g.
'a') to bring up the menu containing accented version of the character, then selecting an accented character to
insert in place of the typed character. This is exposed via UIScriptController.insertText, which takes a string
and an insertion range.

  • DumpRenderTree/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::insertText):

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:

Note that there is no callback argument to insertText, since UIScriptController::insertText is synchronous in
the UI process. The tests end when corresponding input events fired as a result of insertText have been received
in the web process. Please see the new layout tests for more detail.

  • TestRunnerShared/UIScriptContext/UIScriptController.cpp:

(WTR::UIScriptController::insertText):

  • TestRunnerShared/UIScriptContext/UIScriptController.h:
  • WebKitTestRunner/mac/UIScriptControllerMac.mm:

(WTR::nsStringFromJSString):
(WTR::UIScriptController::insertText):

LayoutTests:

Adds 2 new layout tests to verify that inserting replacement text fires input events of inputType
"insertReplacementText" instead of the generic "insertText", and that calling preventDefault() on the
beforeinput event prevents text from being inserted. Also checks that inserting replacement text in
contenteditable areas causes the dataTransfer attribute to be populated, and that the data attribute is null.

  • fast/events/before-input-prevent-insert-replacement-expected.txt: Added.
  • fast/events/before-input-prevent-insert-replacement.html: Added.
  • fast/events/input-event-insert-replacement-expected.txt: Added.
  • fast/events/input-event-insert-replacement.html: Added.
  • platform/ios-simulator/TestExpectations:
  • platform/mac-wk1/TestExpectations:
Location:
trunk
Files:
4 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r208138 r208143  
     12016-10-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Holding down a key to choose an accented character should fire "insertReplacementText" input events
     4        https://bugs.webkit.org/show_bug.cgi?id=164209
     5        <rdar://problem/29019305>
     6
     7        Reviewed by Darin Adler.
     8
     9        Adds 2 new layout tests to verify that inserting replacement text fires input events of inputType
     10        "insertReplacementText" instead of the generic "insertText", and that calling preventDefault() on the
     11        beforeinput event prevents text from being inserted. Also checks that inserting replacement text in
     12        contenteditable areas causes the dataTransfer attribute to be populated, and that the data attribute is null.
     13
     14        * fast/events/before-input-prevent-insert-replacement-expected.txt: Added.
     15        * fast/events/before-input-prevent-insert-replacement.html: Added.
     16        * fast/events/input-event-insert-replacement-expected.txt: Added.
     17        * fast/events/input-event-insert-replacement.html: Added.
     18        * platform/ios-simulator/TestExpectations:
     19        * platform/mac-wk1/TestExpectations:
     20
    1212016-10-30  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    222
  • trunk/LayoutTests/platform/ios-simulator/TestExpectations

    r208105 r208143  
    12031203fast/events/ime-composition-events-001.html [ Failure ]
    12041204fast/events/inputText-never-fired-on-keydown-cancel.html [ Failure ]
     1205fast/events/input-event-insert-replacement.html [ Failure ]
    12051206fast/events/input-events-drag-and-drop.html [ Failure ]
    12061207fast/events/input-events-insert-by-drop.html [ Failure ]
     
    12131214fast/events/input-events-paste-rich-datatransfer.html [ Failure ]
    12141215fast/events/input-events-spell-checking-datatransfer.html [ Failure ]
     1216fast/events/before-input-prevent-insert-replacement.html [ Failure ]
    12151217fast/events/before-input-events-prevent-default.html [ Failure ]
    12161218fast/events/before-input-events-prevent-default-in-textfield.html [ Failure ]
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r207635 r208143  
    8484# WK1 and WK2 mousemove events are subtly different in ways that break this test on WK1.
    8585fast/events/ghostly-mousemoves-in-subframe.html [ Skip ]
     86
     87# Test support for inserting special characters is not yet implemented on WK1.
     88fast/events/before-input-prevent-insert-replacement.html [ Skip ]
     89fast/events/input-event-insert-replacement.html [ Skip ]
    8690
    8791# Media Stream API testing is not supported for WK1 yet.
  • trunk/Source/WebCore/ChangeLog

    r208142 r208143  
     12016-10-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Holding down a key to choose an accented character should fire "insertReplacementText" input events
     4        https://bugs.webkit.org/show_bug.cgi?id=164209
     5        <rdar://problem/29019305>
     6
     7        Reviewed by Darin Adler.
     8
     9        For TypingCommands that correspond to "insertReplacementText" inputTypes, vend dataTransfers for resulting
     10        beforeinput and input events if the edited area is not an input field or textarea. To do this, convert the plain
     11        text representation of the content to be inserted to HTML text using a helper function,
     12        MarkupAccumulator::appendCharactersReplacingEntities, that is used when creating markup for Text nodes.
     13
     14        Tests: fast/events/before-input-prevent-insert-replacement.html
     15               fast/events/input-event-insert-replacement.html
     16
     17        * editing/TypingCommand.cpp:
     18        (WebCore::TypingCommand::inputEventData):
     19        (WebCore::TypingCommand::inputEventDataTransfer):
     20        * editing/TypingCommand.h:
     21
    1222016-10-30  Dave Hyatt  <hyatt@apple.com>
    223
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r208090 r208143  
    2929#include "AXObjectCache.h"
    3030#include "BreakBlockquoteCommand.h"
     31#include "DataTransfer.h"
    3132#include "DeleteSelectionCommand.h"
    3233#include "Document.h"
     
    4041#include "InsertTextCommand.h"
    4142#include "Logging.h"
     43#include "MarkupAccumulator.h"
    4244#include "MathMLElement.h"
    4345#include "RenderElement.h"
     
    407409    switch (m_currentTypingEditAction) {
    408410    case EditActionTypingInsertText:
    409     case EditActionInsertReplacement:
    410411    case EditActionTypingInsertPendingComposition:
    411412    case EditActionTypingInsertFinalComposition:
    412413        return m_currentTextToInsert;
     414    case EditActionInsertReplacement:
     415        return isEditingTextAreaOrTextInput() ? m_currentTextToInsert : String();
    413416    default:
    414417        return CompositeEditCommand::inputEventData();
    415418    }
     419}
     420
     421RefPtr<DataTransfer> TypingCommand::inputEventDataTransfer() const
     422{
     423    if (m_currentTypingEditAction != EditActionInsertReplacement || isEditingTextAreaOrTextInput())
     424        return nullptr;
     425
     426    StringBuilder htmlText;
     427    MarkupAccumulator::appendCharactersReplacingEntities(htmlText, m_currentTextToInsert, 0, m_currentTextToInsert.length(), EntityMaskInHTMLPCDATA);
     428    return DataTransfer::createForInputEvent(m_currentTextToInsert, htmlText.toString());
    416429}
    417430
  • trunk/Source/WebCore/editing/TypingCommand.h

    r208090 r208143  
    121121    String inputEventTypeName() const final;
    122122    String inputEventData() const final;
     123    RefPtr<DataTransfer> inputEventDataTransfer() const final;
    123124    bool isBeforeInputEventCancelable() const final;
    124125
  • trunk/Source/WebKit2/ChangeLog

    r208135 r208143  
     12016-10-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Holding down a key to choose an accented character should fire "insertReplacementText" input events
     4        https://bugs.webkit.org/show_bug.cgi?id=164209
     5        <rdar://problem/29019305>
     6
     7        Reviewed by Darin Adler.
     8
     9        When replacing text, call Editor::insertText with the correct TextEventInputType so that WebCore will know to
     10        use EditActionInsertReplacement when creating and applying the corresponding TypingCommand. Additional minor
     11        changes in order to support testing replacement text insertion.
     12
     13        * UIProcess/API/Cocoa/WKWebView.mm:
     14        (-[WKWebView _insertText:replacementRange:]):
     15        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     16        * WebProcess/WebPage/WebPage.cpp:
     17        (WebKit::WebPage::insertTextAsync):
     18
    1192016-10-30  Darin Adler  <darin@apple.com>
    220
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r207822 r208143  
    46514651    // Overridden by subclasses.
    46524652}
     4653
     4654- (void)_insertText:(id)string replacementRange:(NSRange)replacementRange
     4655{
     4656    [self insertText:string replacementRange:replacementRange];
     4657}
    46534658#endif // PLATFORM(MAC)
    46544659
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r208024 r208143  
    291291- (void)_requestActiveNowPlayingSessionInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    292292- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession title:(NSString *)title duration:(double)duration elapsedTime:(double)elapsedTime WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     293
     294- (void)_insertText:(id)string replacementRange:(NSRange)replacementRange WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    293295#endif
    294296
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r208096 r208143  
    46264626    Frame& frame = m_page->focusController().focusedOrMainFrame();
    46274627
     4628    bool replacesText = false;
    46284629    if (replacementEditingRange.location != notFound) {
    46294630        RefPtr<Range> replacementRange = rangeFromEditingRange(frame, replacementEditingRange, static_cast<EditingRangeIsRelativeTo>(editingRangeIsRelativeTo));
     
    46314632            TemporaryChange<bool> isSelectingTextWhileInsertingAsynchronously(m_isSelectingTextWhileInsertingAsynchronously, suppressSelectionUpdate);
    46324633            frame.selection().setSelection(VisibleSelection(*replacementRange, SEL_DEFAULT_AFFINITY));
     4634            replacesText = true;
    46334635        }
    46344636    }
     
    46404642        // An insertText: might be handled by other responders in the chain if we don't handle it.
    46414643        // One example is space bar that results in scrolling down the page.
    4642         frame.editor().insertText(text, nullptr);
     4644        frame.editor().insertText(text, nullptr, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard);
    46434645    } else
    46444646        frame.editor().confirmComposition(text);
  • trunk/Tools/ChangeLog

    r208134 r208143  
     12016-10-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Holding down a key to choose an accented character should fire "insertReplacementText" input events
     4        https://bugs.webkit.org/show_bug.cgi?id=164209
     5        <rdar://problem/29019305>
     6
     7        Reviewed by Darin Adler.
     8
     9        Adds test support for inserting replacement text on Mac. This is equivalent to holding down a vowel key (e.g.
     10        'a') to bring up the menu containing accented version of the character, then selecting an accented character to
     11        insert in place of the typed character. This is exposed via UIScriptController.insertText, which takes a string
     12        and an insertion range.
     13
     14        * DumpRenderTree/mac/UIScriptControllerMac.mm:
     15        (WTR::UIScriptController::insertText):
     16        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     17
     18        Note that there is no callback argument to insertText, since UIScriptController::insertText is synchronous in
     19        the UI process. The tests end when corresponding input events fired as a result of insertText have been received
     20        in the web process. Please see the new layout tests for more detail.
     21
     22        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     23        (WTR::UIScriptController::insertText):
     24        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     25        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
     26        (WTR::nsStringFromJSString):
     27        (WTR::UIScriptController::insertText):
     28
    1292016-10-30  Sam Weinig  <sam@webkit.org>
    230
  • trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm

    r204877 r208143  
    4444}
    4545
     46void UIScriptController::insertText(JSStringRef, int, int)
     47{
     48}
     49
    4650}
    4751
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r208090 r208143  
    157157    readonly attribute object selectionRangeViewRects; // An array of objects with 'left', 'top', 'width', and 'height' properties.
    158158
     159    void insertText(DOMString text, long location, long length);
     160
    159161    void uiScriptComplete(DOMString result);
    160162};
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r208090 r208143  
    318318#endif
    319319
     320#if !PLATFORM(MAC)
     321
     322void UIScriptController::insertText(JSStringRef, int, int)
     323{
     324}
     325
     326#endif
     327
    320328void UIScriptController::uiScriptComplete(JSStringRef result)
    321329{
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r208090 r208143  
    118118    JSObjectRef selectionRangeViewRects() const;
    119119
     120    void insertText(JSStringRef, int location, int length);
     121
    120122    void uiScriptComplete(JSStringRef result);
    121123
  • trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

    r194721 r208143  
    2727#import "UIScriptController.h"
    2828
     29#import "PlatformWebView.h"
     30#import "TestController.h"
     31#import "TestRunnerWKWebView.h"
    2932#import "UIScriptContext.h"
     33#import <JavaScriptCore/JSStringRefCF.h>
     34#import <WebKit/WKWebViewPrivate.h>
    3035
    3136namespace WTR {
     37
     38NSString *nsString(JSStringRef string)
     39{
     40    return (NSString *)adoptCF(JSStringCopyCFString(kCFAllocatorDefault, string)).autorelease();
     41}
    3242
    3343void UIScriptController::doAsyncTask(JSValueRef callback)
     
    4252}
    4353
     54void UIScriptController::insertText(JSStringRef text, int location, int length)
     55{
     56#if WK_API_ENABLED
     57    if (location == -1)
     58        location = NSNotFound;
     59
     60    auto* webView = TestController::singleton().mainWebView()->platformView();
     61    [webView _insertText:nsString(text) replacementRange:NSMakeRange(location, length)];
     62#else
     63    UNUSED_PARAM(text);
     64    UNUSED_PARAM(location);
     65    UNUSED_PARAM(length);
     66#endif
    4467}
     68
     69}
Note: See TracChangeset for help on using the changeset viewer.