@@ -23,8 +23,8 @@ use objc2::{
2323} ;
2424use objc2_app_kit:: * ;
2525use objc2_foundation:: {
26- ns_string, NSArray , NSCopying , NSInteger , NSNumber , NSObject , NSPoint , NSRange , NSRect ,
27- NSString ,
26+ ns_string, NSArray , NSCopying , NSInteger , NSNumber , NSObject , NSObjectProtocol , NSPoint ,
27+ NSRange , NSRect , NSString ,
2828} ;
2929use std:: rc:: { Rc , Weak } ;
3030
@@ -357,6 +357,13 @@ impl NodeWrapper<'_> {
357357 }
358358}
359359
360+ // derived from objc2 0.6 `AnyObject::downcast_ref`
361+ // TODO: can be removed after updating objc2 to 0.6 which has `AnyObject::downcast_ref`
362+ fn downcast_ref < T : ClassType > ( obj : & NSObject ) -> Option < & T > {
363+ obj. is_kind_of :: < T > ( )
364+ . then ( || unsafe { & * ( obj as * const NSObject ) . cast :: < T > ( ) } )
365+ }
366+
360367pub ( crate ) struct PlatformNodeIvars {
361368 context : Weak < Context > ,
362369 node_id : NodeId ,
@@ -548,9 +555,24 @@ declare_class!(
548555 }
549556
550557 #[ method( setAccessibilityValue: ) ]
551- fn set_value( & self , _value: & NSObject ) {
552- // This isn't yet implemented. See the comment on this selector
553- // in `is_selector_allowed`.
558+ fn set_value( & self , value: & NSObject ) {
559+ if let Some ( string) = downcast_ref:: <NSString >( value) {
560+ self . resolve_with_context( |node, context| {
561+ context. do_action( ActionRequest {
562+ action: Action :: SetValue ,
563+ target: node. id( ) ,
564+ data: Some ( ActionData :: Value ( string. to_string( ) . into( ) ) ) ,
565+ } ) ;
566+ } ) ;
567+ } else if let Some ( number) = downcast_ref:: <NSNumber >( value) {
568+ self . resolve_with_context( |node, context| {
569+ context. do_action( ActionRequest {
570+ action: Action :: SetValue ,
571+ target: node. id( ) ,
572+ data: Some ( ActionData :: NumericValue ( number. doubleValue( ) ) ) ,
573+ } ) ;
574+ } ) ;
575+ }
554576 }
555577
556578 #[ method_id( accessibilityMinValue) ]
@@ -1024,11 +1046,7 @@ declare_class!(
10241046 return node. supports_text_ranges( ) ;
10251047 }
10261048 if selector == sel!( setAccessibilityValue: ) {
1027- // Our implementation of this currently does nothing,
1028- // and it's not clear if VoiceOver ever actually uses it,
1029- // but it must be allowed for editable text in order to get
1030- // the expected VoiceOver behavior.
1031- return node. supports_text_ranges( ) && !node. is_read_only( ) ;
1049+ return ( node. supports_text_ranges( ) && !node. is_read_only( ) ) || node. supports_action( Action :: SetValue , & filter) ;
10321050 }
10331051 if selector == sel!( isAccessibilitySelected) {
10341052 let wrapper = NodeWrapper ( node) ;
0 commit comments