@@ -915,6 +915,7 @@ struct Properties {
915
915
pub struct Node {
916
916
role : Role ,
917
917
actions : u32 ,
918
+ child_actions : u32 ,
918
919
flags : u32 ,
919
920
properties : Properties ,
920
921
}
@@ -1600,6 +1601,31 @@ impl Node {
1600
1601
pub fn clear_actions ( & mut self ) {
1601
1602
self . actions = 0 ;
1602
1603
}
1604
+
1605
+ /// Return whether the specified action is in the set supported on this node's
1606
+ /// direct children in the filtered tree.
1607
+ #[ inline]
1608
+ pub fn child_supports_action ( & self , action : Action ) -> bool {
1609
+ ( self . child_actions & action. mask ( ) ) != 0
1610
+ }
1611
+ /// Add the specified action to the set supported on this node's direct
1612
+ /// children in the filtered tree.
1613
+ #[ inline]
1614
+ pub fn add_child_action ( & mut self , action : Action ) {
1615
+ self . child_actions |= action. mask ( ) ;
1616
+ }
1617
+ /// Remove the specified action from the set supported on this node's direct
1618
+ /// children in the filtered tree.
1619
+ #[ inline]
1620
+ pub fn remove_child_action ( & mut self , action : Action ) {
1621
+ self . child_actions &= !( action. mask ( ) ) ;
1622
+ }
1623
+ /// Clear the set of actions supported on this node's direct children in the
1624
+ /// filtered tree.
1625
+ #[ inline]
1626
+ pub fn clear_child_actions ( & mut self ) {
1627
+ self . child_actions = 0 ;
1628
+ }
1603
1629
}
1604
1630
1605
1631
flag_methods ! {
@@ -2141,6 +2167,11 @@ impl fmt::Debug for Node {
2141
2167
fmt. field ( "actions" , & supported_actions) ;
2142
2168
}
2143
2169
2170
+ let child_supported_actions = action_mask_to_action_vec ( self . child_actions ) ;
2171
+ if !child_supported_actions. is_empty ( ) {
2172
+ fmt. field ( "child_actions" , & child_supported_actions) ;
2173
+ }
2174
+
2144
2175
self . debug_flag_properties ( & mut fmt) ;
2145
2176
self . debug_node_id_vec_properties ( & mut fmt) ;
2146
2177
self . debug_node_id_properties ( & mut fmt) ;
@@ -2820,31 +2851,38 @@ mod tests {
2820
2851
assert_eq ! ( node. role( ) , Role :: CheckBox ) ;
2821
2852
}
2822
2853
2854
+ macro_rules! assert_absent_action {
2855
+ ( $node: ident, $action: ident) => {
2856
+ assert!( !$node. supports_action( Action :: $action) ) ;
2857
+ assert!( !$node. child_supports_action( Action :: $action) ) ;
2858
+ } ;
2859
+ }
2860
+
2823
2861
#[ test]
2824
2862
fn new_node_should_not_support_anyaction ( ) {
2825
2863
let node = Node :: new ( Role :: Unknown ) ;
2826
- assert ! ( ! node. supports_action ( Action :: Click ) ) ;
2827
- assert ! ( ! node. supports_action ( Action :: Focus ) ) ;
2828
- assert ! ( ! node. supports_action ( Action :: Blur ) ) ;
2829
- assert ! ( ! node. supports_action ( Action :: Collapse ) ) ;
2830
- assert ! ( ! node. supports_action ( Action :: Expand ) ) ;
2831
- assert ! ( ! node. supports_action ( Action :: CustomAction ) ) ;
2832
- assert ! ( ! node. supports_action ( Action :: Decrement ) ) ;
2833
- assert ! ( ! node. supports_action ( Action :: Increment ) ) ;
2834
- assert ! ( ! node. supports_action ( Action :: HideTooltip ) ) ;
2835
- assert ! ( ! node. supports_action ( Action :: ShowTooltip ) ) ;
2836
- assert ! ( ! node. supports_action ( Action :: ReplaceSelectedText ) ) ;
2837
- assert ! ( ! node. supports_action ( Action :: ScrollDown ) ) ;
2838
- assert ! ( ! node. supports_action ( Action :: ScrollLeft ) ) ;
2839
- assert ! ( ! node. supports_action ( Action :: ScrollRight ) ) ;
2840
- assert ! ( ! node. supports_action ( Action :: ScrollUp ) ) ;
2841
- assert ! ( ! node. supports_action ( Action :: ScrollIntoView ) ) ;
2842
- assert ! ( ! node. supports_action ( Action :: ScrollToPoint ) ) ;
2843
- assert ! ( ! node. supports_action ( Action :: SetScrollOffset ) ) ;
2844
- assert ! ( ! node. supports_action ( Action :: SetTextSelection ) ) ;
2845
- assert ! ( ! node. supports_action ( Action :: SetSequentialFocusNavigationStartingPoint ) ) ;
2846
- assert ! ( ! node. supports_action ( Action :: SetValue ) ) ;
2847
- assert ! ( ! node. supports_action ( Action :: ShowContextMenu ) ) ;
2864
+ assert_absent_action ! ( node, Click ) ;
2865
+ assert_absent_action ! ( node, Focus ) ;
2866
+ assert_absent_action ! ( node, Blur ) ;
2867
+ assert_absent_action ! ( node, Collapse ) ;
2868
+ assert_absent_action ! ( node, Expand ) ;
2869
+ assert_absent_action ! ( node, CustomAction ) ;
2870
+ assert_absent_action ! ( node, Decrement ) ;
2871
+ assert_absent_action ! ( node, Increment ) ;
2872
+ assert_absent_action ! ( node, HideTooltip ) ;
2873
+ assert_absent_action ! ( node, ShowTooltip ) ;
2874
+ assert_absent_action ! ( node, ReplaceSelectedText ) ;
2875
+ assert_absent_action ! ( node, ScrollDown ) ;
2876
+ assert_absent_action ! ( node, ScrollLeft ) ;
2877
+ assert_absent_action ! ( node, ScrollRight ) ;
2878
+ assert_absent_action ! ( node, ScrollUp ) ;
2879
+ assert_absent_action ! ( node, ScrollIntoView ) ;
2880
+ assert_absent_action ! ( node, ScrollToPoint ) ;
2881
+ assert_absent_action ! ( node, SetScrollOffset ) ;
2882
+ assert_absent_action ! ( node, SetTextSelection ) ;
2883
+ assert_absent_action ! ( node, SetSequentialFocusNavigationStartingPoint ) ;
2884
+ assert_absent_action ! ( node, SetValue ) ;
2885
+ assert_absent_action ! ( node, ShowContextMenu ) ;
2848
2886
}
2849
2887
2850
2888
#[ test]
@@ -2856,6 +2894,15 @@ mod tests {
2856
2894
assert ! ( node. supports_action( Action :: Blur ) ) ;
2857
2895
}
2858
2896
2897
+ #[ test]
2898
+ fn node_add_child_action_should_add_the_action ( ) {
2899
+ let mut node = Node :: new ( Role :: Unknown ) ;
2900
+ node. add_child_action ( Action :: Focus ) ;
2901
+ assert ! ( node. child_supports_action( Action :: Focus ) ) ;
2902
+ node. add_child_action ( Action :: Blur ) ;
2903
+ assert ! ( node. child_supports_action( Action :: Blur ) ) ;
2904
+ }
2905
+
2859
2906
#[ test]
2860
2907
fn node_add_action_should_do_nothing_if_the_action_is_already_supported ( ) {
2861
2908
let mut node = Node :: new ( Role :: Unknown ) ;
@@ -2864,6 +2911,14 @@ mod tests {
2864
2911
assert ! ( node. supports_action( Action :: Focus ) ) ;
2865
2912
}
2866
2913
2914
+ #[ test]
2915
+ fn node_add_child_action_should_do_nothing_if_the_action_is_already_supported ( ) {
2916
+ let mut node = Node :: new ( Role :: Unknown ) ;
2917
+ node. add_child_action ( Action :: Focus ) ;
2918
+ node. add_child_action ( Action :: Focus ) ;
2919
+ assert ! ( node. child_supports_action( Action :: Focus ) ) ;
2920
+ }
2921
+
2867
2922
#[ test]
2868
2923
fn node_remove_action_should_remove_the_action ( ) {
2869
2924
let mut node = Node :: new ( Role :: Unknown ) ;
@@ -2872,6 +2927,14 @@ mod tests {
2872
2927
assert ! ( !node. supports_action( Action :: Blur ) ) ;
2873
2928
}
2874
2929
2930
+ #[ test]
2931
+ fn node_remove_child_action_should_remove_the_action ( ) {
2932
+ let mut node = Node :: new ( Role :: Unknown ) ;
2933
+ node. add_child_action ( Action :: Blur ) ;
2934
+ node. remove_child_action ( Action :: Blur ) ;
2935
+ assert ! ( !node. child_supports_action( Action :: Blur ) ) ;
2936
+ }
2937
+
2875
2938
#[ test]
2876
2939
fn node_clear_actions_should_remove_all_actions ( ) {
2877
2940
let mut node = Node :: new ( Role :: Unknown ) ;
@@ -2882,11 +2945,22 @@ mod tests {
2882
2945
assert ! ( !node. supports_action( Action :: Blur ) ) ;
2883
2946
}
2884
2947
2948
+ #[ test]
2949
+ fn node_clear_child_actions_should_remove_all_actions ( ) {
2950
+ let mut node = Node :: new ( Role :: Unknown ) ;
2951
+ node. add_child_action ( Action :: Focus ) ;
2952
+ node. add_child_action ( Action :: Blur ) ;
2953
+ node. clear_child_actions ( ) ;
2954
+ assert ! ( !node. child_supports_action( Action :: Focus ) ) ;
2955
+ assert ! ( !node. child_supports_action( Action :: Blur ) ) ;
2956
+ }
2957
+
2885
2958
#[ test]
2886
2959
fn node_should_have_debug_repr ( ) {
2887
2960
let mut node = Node :: new ( Role :: Unknown ) ;
2888
2961
node. add_action ( Action :: Click ) ;
2889
2962
node. add_action ( Action :: Focus ) ;
2963
+ node. add_child_action ( Action :: ScrollIntoView ) ;
2890
2964
node. set_hidden ( ) ;
2891
2965
node. set_multiselectable ( ) ;
2892
2966
node. set_children ( [ NodeId ( 0 ) , NodeId ( 1 ) ] ) ;
@@ -2898,7 +2972,7 @@ mod tests {
2898
2972
2899
2973
assert_eq ! (
2900
2974
& format!( "{node:?}" ) ,
2901
- r#"Node { role: Unknown, actions: [Click, Focus], is_hidden: true, is_multiselectable: true, children: [#0, #1], active_descendant: #2, custom_actions: [CustomAction { id: 0, description: "test action" }] }"#
2975
+ r#"Node { role: Unknown, actions: [Click, Focus], child_actions: [ScrollIntoView], is_hidden: true, is_multiselectable: true, children: [#0, #1], active_descendant: #2, custom_actions: [CustomAction { id: 0, description: "test action" }] }"#
2902
2976
) ;
2903
2977
}
2904
2978
0 commit comments