Bug 215982

Summary: Remove comparePositions and make VisiblePosition improvements
Product: WebKit Reporter: Darin Adler <darin>
Component: HTML EditingAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, achristensen, apinheiro, cdumez, cfleizach, changseok, dino, dmazzoni, esprehn+autocc, ews-watchlist, fmalita, glenn, gyuyoung.kim, jcraig, jdiggs, kangil.han, kondapallykalyan, mifenton, mmaxfield, pdr, sabouhallawa, samuel_white, sam, schenney, sergio, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch sam: review+

Description Darin Adler 2020-08-29 20:46:25 PDT
Remove comparePositions and make VisiblePosition improvements
Comment 1 Darin Adler 2020-08-29 21:42:58 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-08-29 21:46:08 PDT
One thing not explicitly mentioned in the change log that makes this improvement possible is that all the Position operators now consistently work properly with shadow trees. Before, comparePositions would handle shadow trees correctly, but operators like < and > would not. Now they are all consistently correct in this respect so we can switch to the simpler idiom by using the operators directly. In the few cases where this is not possible, we still don't need a comparePositions function: we can call documentOrder or one of the documentOrder-related functions instead.
Comment 3 Darin Adler 2020-09-01 13:00:41 PDT
Created attachment 407705 [details]
Patch
Comment 4 Sam Weinig 2020-09-01 15:02:50 PDT
Comment on attachment 407705 [details]
Patch

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

> Source/WebCore/editing/ios/EditorIOS.mm:372
> +    VisibleSelection selection;
>      selection.setBase(visiblePos);
>      selection.setExtent(visiblePos);

Any reason not to use the VisibleSelection constructor that takes VisiblePositions here? e.g. VisibleSelection selection { visiblePos, visiblePos };? I guess the affinity of selection might be different?
Comment 5 Darin Adler 2020-09-01 15:10:05 PDT
Comment on attachment 407705 [details]
Patch

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

>> Source/WebCore/editing/ios/EditorIOS.mm:372
>>      selection.setExtent(visiblePos);
> 
> Any reason not to use the VisibleSelection constructor that takes VisiblePositions here? e.g. VisibleSelection selection { visiblePos, visiblePos };? I guess the affinity of selection might be different?

We almost certainly could and should do that.
Comment 6 Darin Adler 2020-09-01 15:11:25 PDT
Comment on attachment 407705 [details]
Patch

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

>>> Source/WebCore/editing/ios/EditorIOS.mm:372
>>>      selection.setExtent(visiblePos);
>> 
>> Any reason not to use the VisibleSelection constructor that takes VisiblePositions here? e.g. VisibleSelection selection { visiblePos, visiblePos };? I guess the affinity of selection might be different?
> 
> We almost certainly could and should do that.

Not only that, there’s one that takes a single VisiblePosition and uses it for both base and extent, and we should use that!
Comment 7 Darin Adler 2020-09-01 18:07:38 PDT
This is passing tests. The "failure" on iOS-wk2 is a progression, probably a test doing better after r266399 that needs an updated expectation for this platform.

Sam, looks like you read the patch but didn’t review yet. Should I upload a new version with the VisibleSelection improvement?
Comment 8 Sam Weinig 2020-09-02 09:37:18 PDT
(In reply to Darin Adler from comment #7)
> This is passing tests. The "failure" on iOS-wk2 is a progression, probably a
> test doing better after r266399 that needs an updated expectation for this
> platform.
> 
> Sam, looks like you read the patch but didn’t review yet. Should I upload a
> new version with the VisibleSelection improvement?

No, sorry, was just not on a computer last night. Finishing off the review now, no need to upload a new one.
Comment 9 Sam Weinig 2020-09-02 09:50:18 PDT
Comment on attachment 407705 [details]
Patch

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

> Source/WebCore/editing/TextAffinity.h:31
> +enum Affinity : bool { Upstream, Downstream };

I think these would read clearer at callsites as an enum class, but I could see arguments either way and this is a clear improvement.

> Source/WebCore/editing/VisibleUnits.cpp:1065
> +    if (auto box = visiblePosition.inlineBoxAndOffset().box) {

A thought for the future. Given how often callers of inlineBoxAndOffset() want just the box, is there a worthwhile optimization of having a version that doesn't return the offset? Can any computation be avoided?
Comment 10 Darin Adler 2020-09-02 14:02:05 PDT
Committed r266487: <https://trac.webkit.org/changeset/266487>
Comment 11 Radar WebKit Bug Importer 2020-09-02 14:03:29 PDT
<rdar://problem/68231268>