Changeset 261903 in webkit


Ignore:
Timestamp:
May 19, 2020 8:13:49 PM (4 years ago)
Author:
Darin Adler
Message:

REGRESSION (r259930): Dictation marker at start of text is removed when added trailing whitespace is collapsed
https://bugs.webkit.org/show_bug.cgi?id=212093

Reviewed by Daniel Bates.

Source/WebCore:

  • dom/DocumentMarkerController.cpp:

(WebCore::DocumentMarkerController::shiftMarkers): Use int to do the math before clamping to
unsigned. This protects against underflow.

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm:

(TestWebKitAPI::TEST): Expect success rather than failure.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r261901 r261903  
     12020-05-19  Darin Adler  <darin@apple.com>
     2
     3        REGRESSION (r259930): Dictation marker at start of text is removed when added trailing whitespace is collapsed
     4        https://bugs.webkit.org/show_bug.cgi?id=212093
     5
     6        Reviewed by Daniel Bates.
     7
     8        * dom/DocumentMarkerController.cpp:
     9        (WebCore::DocumentMarkerController::shiftMarkers): Use int to do the math before clamping to
     10        unsigned. This protects against underflow.
     11
    1122020-05-19  Sam Weinig  <weinig@apple.com>
    213
  • trunk/Source/WebCore/dom/DocumentMarkerController.cpp

    r259930 r261903  
    596596#if PLATFORM(IOS_FAMILY)
    597597        // FIXME: No obvious reason this should be iOS-specific. Remove the #if at some point.
    598         int targetStartOffset = marker.startOffset() + delta;
    599         int targetEndOffset = marker.endOffset() + delta;
    600         if (static_cast<unsigned>(targetStartOffset) >= node.length() || targetEndOffset <= 0) {
     598        auto targetStartOffset = clampTo<unsigned>(static_cast<int>(marker.startOffset()) + delta);
     599        auto targetEndOffset = clampTo<unsigned>(static_cast<int>(marker.endOffset()) + delta);
     600        if (targetStartOffset >= node.length() || targetEndOffset <= 0) {
    601601            list->remove(i);
    602602            continue;
     
    612612        // FIXME: No obvious reason this should be iOS-specific. Remove the #if at some point.
    613613        else if (marker.endOffset() > startOffset) {
    614             if (marker.endOffset() + delta <= marker.startOffset()) {
     614            if (targetEndOffset <= marker.startOffset()) {
    615615                list->remove(i);
    616616                continue;
    617617            }
    618             marker.setEndOffset(std::min<unsigned>(targetEndOffset, node.length()));
     618            marker.setEndOffset(std::min(targetEndOffset, node.length()));
    619619            didShiftMarker = true;
    620620        }
  • trunk/Tools/ChangeLog

    r261898 r261903  
     12020-05-19  Darin Adler  <darin@apple.com>
     2
     3        REGRESSION (r259930): Dictation marker at start of text is removed when added trailing whitespace is collapsed
     4        https://bugs.webkit.org/show_bug.cgi?id=212093
     5
     6        Reviewed by Daniel Bates.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm:
     9        (TestWebKitAPI::TEST): Expect success rather than failure.
     10
    1112020-05-19  Alex Christensen  <achristensen@webkit.org>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm

    r261897 r261903  
    154154}
    155155
    156 TEST(InsertTextAlternatives, InsertTrailingSpaceWhitespaceRebalance_ExpectedFailure)
    157 {
    158     auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    159     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration]);
    160     auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
    161     [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }];
    162     [webView _setInputDelegate:inputDelegate.get()];
    163 
    164     [webView synchronouslyLoadHTMLString:@"<body contenteditable='true'></body>"];
    165     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
    166     [[webView textInputContentView] insertText:@"hello" alternatives:@[@"yellow"] style:UITextAlternativeStyleNone];
    167     [[webView textInputContentView] insertText:@" "];
    168     [webView waitForNextPresentationUpdate];
    169 
    170     // FIXME: Change this to EXPECT_TRUE() once <https://webkit.org/b/212093> is fixed.
    171     EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(0, 5)"] boolValue]); // hello
     156TEST(InsertTextAlternatives, InsertTrailingSpaceWhitespaceRebalance)
     157{
     158    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     159    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration]);
     160    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
     161    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }];
     162    [webView _setInputDelegate:inputDelegate.get()];
     163
     164    [webView synchronouslyLoadHTMLString:@"<body contenteditable='true'></body>"];
     165    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
     166    [[webView textInputContentView] insertText:@"hello" alternatives:@[@"yellow"] style:UITextAlternativeStyleNone];
     167    [[webView textInputContentView] insertText:@" "];
     168    [webView waitForNextPresentationUpdate];
     169
     170    EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(0, 5)"] boolValue]); // hello
    172171}
    173172
Note: See TracChangeset for help on using the changeset viewer.