Changeset 259013 in webkit


Ignore:
Timestamp:
Mar 25, 2020 2:56:03 PM (4 years ago)
Author:
dbates@webkit.org
Message:

Element context character rects may be in wrong coordinate system
https://bugs.webkit.org/show_bug.cgi?id=209493
<rdar://problem/60840261>

Reviewed by Wenson Hsieh.

Source/WebKit:

Convert the character rects from content view coordinates to root view coordinates
as that is the coordinate system callers of -requestDocumentContext expect.

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::requestDocumentEditingContext):

Tools:

Add some tests.

  • TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:

(TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r259008 r259013  
     12020-03-25  Daniel Bates  <dabates@apple.com>
     2
     3        Element context character rects may be in wrong coordinate system
     4        https://bugs.webkit.org/show_bug.cgi?id=209493
     5        <rdar://problem/60840261>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Convert the character rects from content view coordinates to root view coordinates
     10        as that is the coordinate system callers of -requestDocumentContext expect.
     11
     12        * WebProcess/WebPage/ios/WebPageIOS.mm:
     13        (WebKit::WebPage::requestDocumentEditingContext):
     14
    1152020-03-25  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r258989 r259013  
    42534253        const int stride = 1;
    42544254        while (!iterator.atEnd()) {
    4255             if (!iterator.text().isEmpty())
    4256                 rects.append({ createLiveRange(iterator.range())->absoluteBoundingBox(Range::BoundingRectBehavior::IgnoreEmptyTextSelections), { offsetSoFar++, stride } });
     4255            if (!iterator.text().isEmpty()) {
     4256                auto currentRange = createLiveRange(iterator.range());
     4257                auto absoluteBoundingBox = currentRange->absoluteBoundingBox(Range::BoundingRectBehavior::IgnoreEmptyTextSelections);
     4258                rects.append({ currentRange->ownerDocument().view()->contentsToRootView(absoluteBoundingBox), { offsetSoFar++, stride } });
     4259            }
    42574260            iterator.advance(stride);
    42584261        }
  • trunk/Tools/ChangeLog

    r259012 r259013  
     12020-03-25  Daniel Bates  <dabates@apple.com>
     2
     3        Element context character rects may be in wrong coordinate system
     4        https://bugs.webkit.org/show_bug.cgi?id=209493
     5        <rdar://problem/60840261>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Add some tests.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
     12        (TEST):
     13
    1142020-03-25  Doug Kelly  <dougk@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm

    r258974 r259013  
    514514}
    515515
     516TEST(DocumentEditingContext, RequestRectsInTextAreaInsideIFrame)
     517{
     518    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     519    // Use "padding: 0" for the <textarea> as the default user-agent stylesheet can effect text wrapping.
     520    [webView synchronouslyLoadHTMLString:applyAhemStyle([NSString stringWithFormat:@"<iframe srcdoc=\"%@\" style='position: absolute; left: 1em; top: 1em; border: none'></iframe>", applyAhemStyle(@"<textarea id='test' style='padding: 0'>The quick brown fox jumps over the lazy dog.</textarea><script>let textarea = document.getElementById('test'); textarea.focus(); textarea.setSelectionRange(0, 0); /* Place caret at the beginning of the field. */</script>")])];
     521
     522    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
     523    EXPECT_NOT_NULL(context);
     524    EXPECT_NULL(context.contextBefore);
     525    EXPECT_NSSTRING_EQ("The", context.contextAfter);
     526    auto *textRects = [context textRects];
     527    EXPECT_EQ(3U, textRects.count);
     528
     529#if PLATFORM(MACCATALYST)
     530    const size_t yPos = 27;
     531    const size_t height = 26;
     532#else
     533    const size_t yPos = 28;
     534    const size_t height = 25;
     535#endif
     536
     537    if (textRects.count >= 3) {
     538        CGFloat x = 28;
     539        EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T
     540        EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h
     541        EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e
     542    }
     543}
     544
     545TEST(DocumentEditingContext, RequestRectsInTextAreaInsideScrolledIFrame)
     546{
     547    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     548    // Use "padding: 0" for the <textarea> as the default user-agent stylesheet can effect text wrapping.
     549    [webView synchronouslyLoadHTMLString:applyAhemStyle([NSString stringWithFormat:@"<iframe srcdoc=\"%@\" style='position: absolute; left: 1em; top: 1em; border: none' height='200'></iframe>", applyAhemStyle(@"<body style='height: 1000px'><div style='width: 200px; height: 200px'></div><textarea id='test' style='padding: 0'>The quick brown fox jumps over the lazy dog.</textarea><script>let textarea = document.getElementById('test'); textarea.focus(); textarea.setSelectionRange(0, 0); /* Place caret at the beginning of the field. */ window.scrollTo(0, 200); /* Scroll <textarea> to the top. */</script></body>")])];
     550
     551    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
     552    EXPECT_NOT_NULL(context);
     553    EXPECT_NULL(context.contextBefore);
     554    EXPECT_NSSTRING_EQ("The", context.contextAfter);
     555    auto *textRects = [context textRects];
     556    EXPECT_EQ(3U, textRects.count);
     557
     558#if PLATFORM(MACCATALYST)
     559    const size_t yPos = 27;
     560    const size_t height = 26;
     561#else
     562    const size_t yPos = 28;
     563    const size_t height = 25;
     564#endif
     565
     566    if (textRects.count >= 3) {
     567        CGFloat x = 28;
     568        EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T
     569        EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h
     570        EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e
     571    }
     572}
     573
    516574// MARK: Tests using word granularity
    517575
Note: See TracChangeset for help on using the changeset viewer.