Bug 205842 - First character in each word-wrapped line has incorrect character rect when requested range spans multiple lines
Summary: First character in each word-wrapped line has incorrect character rect when r...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Text (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Daniel Bates
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-06 16:34 PST by Daniel Bates
Modified: 2020-01-07 13:27 PST (History)
13 users (show)

See Also:


Attachments
For Bots (13.90 KB, patch)
2020-01-06 16:36 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch and unit test (17.20 KB, patch)
2020-01-07 10:30 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Addendum - keep current behavior of Range::absoluteBoundingBox, but fix up request document context code path (2.26 KB, patch)
2020-01-07 10:52 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
To land (19.88 KB, patch)
2020-01-07 11:59 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
To land (19.88 KB, patch)
2020-01-07 13:25 PST, Daniel Bates
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2020-01-06 16:34:44 PST
Consider a page with the following markup:

[[
<style>@font-face { font-family: Ahem; src: url(Ahem.ttf); } body { margin: 0; } * { font: 25px/1 Ahem; -webkit-text-size-adjust: 100%; }</style>
<meta name='viewport' content='width=980, initial-scale=1.0'>
<textarea id='test' style='width: 26em; padding: 0 /* Overrides default user-agent stylesheet */;'>The quick brown fox jumps over the lazy dog.</textarea>
<script>
test.focus(); test.setSelectionRange(25, 25)
</script>
]]

(^^^ Assumes the Ahem font is available)

Then requesting the a document context for rects returns an incorrect character rect for the space/line break after "jumps".
Comment 1 Daniel Bates 2020-01-06 16:34:53 PST
<rdar://problem/56884325>
Comment 2 Daniel Bates 2020-01-06 16:36:20 PST
Created attachment 386911 [details]
For Bots
Comment 3 Daniel Bates 2020-01-07 10:30:17 PST
Created attachment 386989 [details]
Patch and unit test
Comment 4 Daniel Bates 2020-01-07 10:34:28 PST
Comment on attachment 386989 [details]
Patch and unit test

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

> Source/WebCore/dom/Range.cpp:1152
> +    absoluteTextRects(rects, useSelectionHeight, inFixed, { BoundingRectBehavior::IgnoreEmptyTextSelections });

I patched here because I was kinda thinking this is the behavior we want for all IPI and SPI: it makes us match NSLayoutManager behavior. But it's enough to fix just my particular bug by having <https://trac.webkit.org/browser/trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm?rev=254070#L4074> pass BoundingRectBehavior::IgnoreEmptyTextSelections. That is, Range::absoluteBoundingBox() could take an optional BoundingRectBehavior argument, default such that we do what we do now and just have WebPageIOS.mm's code pass BoundingRectBehavior::IgnoreEmptyTextSelections. Thoughts?
Comment 5 Daniel Bates 2020-01-07 10:52:11 PST
Created attachment 386996 [details]
Addendum - keep current behavior of Range::absoluteBoundingBox, but fix up request document context code path
Comment 6 Daniel Bates 2020-01-07 10:54:51 PST
(In reply to Daniel Bates from comment #5)
> Created attachment 386996 [details]
> Addendum - keep current behavior of Range::absoluteBoundingBox, but fix up
> request document context code path

I can merge ^^^ into the patch if it would help make it easier to review this change.
Comment 7 Daniel Bates 2020-01-07 11:59:45 PST
Created attachment 387011 [details]
To land
Comment 8 Daniel Bates 2020-01-07 12:00:25 PST
(In reply to Daniel Bates from comment #6)
> (In reply to Daniel Bates from comment #5)
> > Created attachment 386996 [details]
> > Addendum - keep current behavior of Range::absoluteBoundingBox, but fix up
> > request document context code path
> 
> I can merge ^^^ into the patch if it would help make it easier to review
> this change.

Merge this in to the updated patch!
Comment 9 Daniel Bates 2020-01-07 12:03:12 PST
Comment on attachment 387011 [details]
To land

Clearing flags on attachment: 387011

Committed r254144: <https://trac.webkit.org/changeset/254144>
Comment 10 Daniel Bates 2020-01-07 12:03:15 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Aakash Jain 2020-01-07 12:54:16 PST
This seems to have broken the iOS build. Tracked in https://bugs.webkit.org/show_bug.cgi?id=205883

Relevant error:
WebPageIOS.mm:4064:73: error: use of undeclared identifier 'BoundingRectBehavior'
Comment 12 Ryan Haddad 2020-01-07 13:10:23 PST
Reverted r254144 for reason:

Broke the iOS build.

Committed r254151: <https://trac.webkit.org/changeset/254151>
Comment 13 Daniel Bates 2020-01-07 13:25:38 PST
Created attachment 387024 [details]
To land
Comment 14 Daniel Bates 2020-01-07 13:27:00 PST
Comment on attachment 387024 [details]
To land

Clearing flags on attachment: 387024

Committed r254153: <https://trac.webkit.org/changeset/254153>
Comment 15 Daniel Bates 2020-01-07 13:27:02 PST
All reviewed patches have been landed.  Closing bug.