Bug 251849 - AX: Remove unnecessary TextMarker methods from WebAccessibilityObjectWrapper
Summary: AX: Remove unnecessary TextMarker methods from WebAccessibilityObjectWrapper
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Andres Gonzalez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-02-07 07:47 PST by Andres Gonzalez
Modified: 2023-02-10 08:18 PST (History)
12 users (show)

See Also:


Attachments
Patch (5.43 KB, patch)
2023-02-07 07:55 PST, Andres Gonzalez
no flags Details | Formatted Diff | Diff
Patch (5.44 KB, patch)
2023-02-09 08:50 PST, Andres Gonzalez
no flags Details | Formatted Diff | Diff
Patch (5.44 KB, patch)
2023-02-09 08:52 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 2023-02-07 07:47:25 PST
Use the corresponding C functions instead.
Comment 1 Radar WebKit Bug Importer 2023-02-07 07:47:43 PST
<rdar://problem/105128584>
Comment 2 Andres Gonzalez 2023-02-07 07:55:09 PST
Created attachment 464885 [details]
Patch
Comment 3 Tyler Wilcock 2023-02-07 12:06:55 PST
Comment on attachment 464885 [details]
Patch

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

> COMMIT_MESSAGE:1
> +AX: Remove unnecessary TextMrker methods from WebAccessibilityObjectWrapper. 

Typo — TextMrker should be TextMarker
Comment 4 Darin Adler 2023-02-08 10:07:14 PST
Comment on attachment 464885 [details]
Patch

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

> COMMIT_MESSAGE:1
> +AX: Remove unnecessary TextMrker methods from WebAccessibilityObjectWrapper. 

Typo here in TextMarker.

> Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:535
> +        [change setObject:marker.bridgingAutorelease() forKey:NSAccessibilityTextChangeValueStartMarker];

Never need autorelease when passing a value to a method, only when returning. Wastefully puts an object into the autorelease pool. Instead this should use get() and bridge_cast. You can probably find an example by searching for bridge_cast.
Comment 5 Darin Adler 2023-02-08 10:07:30 PST
Set back to review? by accident.
Comment 6 Andres Gonzalez 2023-02-09 08:42:33 PST
(In reply to Darin Adler from comment #4)
> Comment on attachment 464885 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=464885&action=review
> 
> > COMMIT_MESSAGE:1
> > +AX: Remove unnecessary TextMrker methods from WebAccessibilityObjectWrapper. 
> 
> Typo here in TextMarker.
> 
> > Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:535
> > +        [change setObject:marker.bridgingAutorelease() forKey:NSAccessibilityTextChangeValueStartMarker];
> 
> Never need autorelease when passing a value to a method, only when
> returning. Wastefully puts an object into the autorelease pool. Instead this
> should use get() and bridge_cast. You can probably find an example by
> searching for bridge_cast.

Thanks Darin. Tried that but getting error: no matching function for call to 'bridge_cast'
        [change setObject:bridge_cast(marker.get()) forKey:NSAccessibilityTextChangeValueStartMarker];
                          ^~~~~~~~~~~

/OpenSource/WebKitBuild/Release/usr/local/include/wtf/cocoa/TypeCastsCocoa.h:59:113: note: candidate template ignored: could not match 'RetainPtr<T>' against 'WTF::RetainPtr<const __AXTextMarker>::PtrType' (aka 'const __AXTextMarker *')
template<typename T> inline RetainPtr<std::remove_pointer_t<typename CFTollFreeBridgingTraits<T>::BridgedType>> bridge_cast(RetainPtr<T>&& object)
                                                                                                                ^
/OpenSource/WebKitBuild/Release/usr/local/include/wtf/cocoa/TypeCastsCocoa.h:54:79: note: candidate template ignored: substitution failure [with T = const __AXTextMarker *]: implicit instantiation of undefined template 'WTF::CFTollFreeBridgingTraits<const __AXTextMarker *>'
template<typename T> inline typename CFTollFreeBridgingTraits<T>::BridgedType bridge_cast(T object)
                                     ~~~~~~~~~~~~~~~~~~~~~~~~                 ^
/Users/ag/s/web/OpenSource/WebKitBuild/Release/usr/local/include/wtf/cocoa/TypeCastsCocoa.h:49:113: note: candidate template ignored: could not match 'RetainPtr<T>' against 'WTF::RetainPtr<const __AXTextMarker>::PtrType' (aka 'const __AXTextMarker *')
template<typename T> inline RetainPtr<typename NSTollFreeBridgingTraits<std::remove_pointer_t<T>>::BridgedType> bridge_cast(RetainPtr<T>&& object)
                                                                                                                ^
/Users/ag/s/web/OpenSource/WebKitBuild/Release/usr/local/include/wtf/cocoa/TypeCastsCocoa.h:44:102: note: candidate template ignored: substitution failure [with T = const __AXTextMarker *]: implicit instantiation of undefined template 'WTF::NSTollFreeBridgingTraits<const __AXTextMarker>'
template<typename T> inline typename NSTollFreeBridgingTraits<std::remove_pointer_t<T>>::BridgedType bridge_cast(T object)
                                     ~~~~~~~~~~~~~~~~~~~~~~~~                                        ^

Maybe because AXTextMarkerRef is an opaque pointer?


Can get it to compile with:

        [change setObject:(__bridge id)(marker.get()) forKey:NSAccessibilityTextChangeValueStartMarker];

which perhaps is the right thing in this case.
Comment 7 Andres Gonzalez 2023-02-09 08:50:45 PST
Created attachment 464923 [details]
Patch
Comment 8 Andres Gonzalez 2023-02-09 08:52:48 PST
Created attachment 464924 [details]
Patch
Comment 9 Darin Adler 2023-02-09 09:52:41 PST
Comment on attachment 464924 [details]
Patch

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

> Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:535
> +        [change setObject:(__bridge id)marker.get() forKey:NSAccessibilityTextChangeValueStartMarker];

Great as is. To make code like this look more elegant and perhaps be more type safe we also have bridge_id_cast for cases where there is not an Objective-C equivalent. Or if there is an Objective-C toll free bridged version of AXTextMarkerRef, we could add it to the toll free bridging header and then use bridge_cast. But none of that is required, this is fine.
Comment 10 EWS 2023-02-09 11:49:27 PST
Committed 260075@main (cf1fe7b77825): <https://commits.webkit.org/260075@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 464924 [details].