Bug 235695

Summary: DocumentContext gives empty rects for blank lines.
Product: WebKit Reporter: Megan Gardner <megan_gardner>
Component: New BugsAssignee: Megan Gardner <megan_gardner>
Status: RESOLVED FIXED    
Severity: Normal CC: akeerthi, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Megan Gardner 2022-01-27 00:32:26 PST
DocumentContext gives empty rects for blank lines.
Comment 1 Megan Gardner 2022-01-27 00:38:50 PST
Created attachment 450110 [details]
Patch
Comment 2 Aditya Keerthi 2022-01-27 09:10:24 PST
Comment on attachment 450110 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=450110&action=review

> Source/WebCore/platform/graphics/GeometryUtilities.cpp:108
> +FloatRect unionRectIfNonZero(const Vector<FloatRect>& rects)

This looks the same as `unionRectIgnoringZeroRects`!

Maybe just add a new method for `const Vector<IntRect>&` and give it the same name as the existing method?
Comment 3 Wenson Hsieh 2022-01-27 09:22:25 PST
Comment on attachment 450110 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=450110&action=review

This should be API-testable (there are existing examples in DocumentEditingContext.mm)

>> Source/WebCore/platform/graphics/GeometryUtilities.cpp:108
>> +FloatRect unionRectIfNonZero(const Vector<FloatRect>& rects)
> 
> This looks the same as `unionRectIgnoringZeroRects`!
> 
> Maybe just add a new method for `const Vector<IntRect>&` and give it the same name as the existing method?

Indeed!

Could also consider consolidating both into a template function and letting type deduction do it's thing:

```
template <typename RectType>
RectType unionRectIgnoringZeroRects(const Vector<RectType>& rects)
{
    RectType result;
    for (auto& rect : rects)
        result.uniteIfNonZero(rect);
    return result;
}
```
Comment 4 Megan Gardner 2022-01-27 14:21:38 PST
Created attachment 450178 [details]
Patch
Comment 5 Tim Horton 2022-01-27 14:47:17 PST
Comment on attachment 450178 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=450178&action=review

> Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:489
> +    auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"text.getBoundingClientRect().toJSON()"]);
> +    documentRect.origin.x += (documentRect.size.width / 2) - (glyphWidth * 2);
> +    documentRect.origin.y += (documentRect.size.height / 2) - (glyphWidth * 2);
> +    documentRect.size.width = glyphWidth;
> +    documentRect.size.height = glyphWidth;

You never use documentRect so you can delete all of this
Comment 6 Megan Gardner 2022-01-27 15:19:15 PST
Created attachment 450188 [details]
Patch
Comment 7 Megan Gardner 2022-01-27 20:03:16 PST
Created attachment 450201 [details]
Patch for landing
Comment 8 EWS 2022-01-27 21:14:38 PST
Committed r288721 (246514@main): <https://commits.webkit.org/246514@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 450201 [details].
Comment 9 Radar WebKit Bug Importer 2022-01-27 21:15:37 PST
<rdar://problem/88169210>