Bug 219491 - Prelininary refactoring of TextMarker and TextMarkerRange.
Summary: Prelininary refactoring of TextMarker and TextMarkerRange.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andres Gonzalez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-12-03 08:07 PST by Andres Gonzalez
Modified: 2020-12-07 08:23 PST (History)
10 users (show)

See Also:


Attachments
Patch (31.96 KB, patch)
2020-12-03 08:35 PST, Andres Gonzalez
no flags Details | Formatted Diff | Diff
Patch (62.08 KB, patch)
2020-12-04 10:52 PST, Andres Gonzalez
no flags Details | Formatted Diff | Diff
Patch (62.31 KB, patch)
2020-12-05 10:59 PST, Andres Gonzalez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andres Gonzalez 2020-12-03 08:07:36 PST
Prelininary refactoring of TextMarker and TextMarkerRange.
Comment 1 Andres Gonzalez 2020-12-03 08:35:44 PST
Created attachment 415303 [details]
Patch
Comment 2 chris fleizach 2020-12-03 10:37:49 PST
Comment on attachment 415303 [details]
Patch

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

> Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:613
> +static id AXTextMarkerRangeStart(id textMarkerRange)

should these methods return the actual types rather than id (since we're refactoring anyway)

> Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:627
> +static bool getBytesFromAXTextMarker(CFTypeRef textMarker, void* bytes, size_t length)

I think we can use a 
TextMarkerData*

instead of a void* and then avoid the size parameter
Comment 3 Andres Gonzalez 2020-12-04 10:52:42 PST
Created attachment 415430 [details]
Patch
Comment 4 Andres Gonzalez 2020-12-04 10:56:21 PST
(In reply to chris fleizach from comment #2)
> Comment on attachment 415303 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=415303&action=review
> 
> > Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:613
> > +static id AXTextMarkerRangeStart(id textMarkerRange)
> 
> should these methods return the actual types rather than id (since we're
> refactoring anyway)

Done. More work than I anticipated, but done and tested now.
> 
> > Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:627
> > +static bool getBytesFromAXTextMarker(CFTypeRef textMarker, void* bytes, size_t length)
> 
> I think we can use a 
> TextMarkerData*
> 
> instead of a void* and then avoid the size parameter

Done, good catch.
Comment 5 Andres Gonzalez 2020-12-05 10:59:50 PST
Created attachment 415491 [details]
Patch
Comment 6 EWS 2020-12-05 13:25:57 PST
Committed r270476: <https://trac.webkit.org/changeset/270476>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 415491 [details].
Comment 7 Radar WebKit Bug Importer 2020-12-05 13:26:17 PST
<rdar://problem/72012226>
Comment 8 Simon Fraser (smfr) 2020-12-05 20:06:31 PST
Comment on attachment 415491 [details]
Patch

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

> Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:637
> +    memcpy(&data, AXTextMarkerGetBytePtr(textMarker), sizeof(data));

How do we know that the binary layout of the result of AXTextMarkerGetBytePtr matches TextMarkerData?

> Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:704
> +AXTextMarkerRef textMarkerForCharacterOffset(AXObjectCache* cache, const CharacterOffset& characterOffset)

Should functions like this return RetainPtr<AXTextMarkerRef>?
Comment 9 Andres Gonzalez 2020-12-07 08:23:11 PST
(In reply to Simon Fraser (smfr) from comment #8)
> Comment on attachment 415491 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=415491&action=review
> 
> > Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:637
> > +    memcpy(&data, AXTextMarkerGetBytePtr(textMarker), sizeof(data));
> 
> How do we know that the binary layout of the result of
> AXTextMarkerGetBytePtr matches TextMarkerData?

Please, see https://bugs.webkit.org/show_bug.cgi?id=219601. Added a size check. We should eventually make the definition of TextMarkerData common to both the system APIs and Webkit, but in the meantime this check has served us well for a few years already.
> 
> > Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:704
> > +AXTextMarkerRef textMarkerForCharacterOffset(AXObjectCache* cache, const CharacterOffset& characterOffset)
> 
> Should functions like this return RetainPtr<AXTextMarkerRef>?

The idea is to add a class AXTextMarker that wraps and retains the system AXTextMarkerRef. This class will expose the conversions to the WebCore types, VisiblePosition, CharacterOffset, etc. For now, I don't see any downside in keeping the return values to be the raw AXTextMarkerRefs as before.