@@ -14,16 +14,25 @@ pub enum FilterResult {
1414 ExcludeSubtree ,
1515}
1616
17- fn filter_for_sibling_clip_check ( node : & Node ) -> FilterResult {
17+ fn common_filter_base ( node : & Node ) -> Option < FilterResult > {
1818 if node. is_focused ( ) {
19- return FilterResult :: Include ;
19+ return Some ( FilterResult :: Include ) ;
2020 }
2121
2222 if node. is_hidden ( ) {
23- return FilterResult :: ExcludeSubtree ;
23+ return Some ( FilterResult :: ExcludeSubtree ) ;
2424 }
2525
26- FilterResult :: Include
26+ let role = node. role ( ) ;
27+ if role == Role :: GenericContainer || role == Role :: TextRun {
28+ return Some ( FilterResult :: ExcludeNode ) ;
29+ }
30+
31+ None
32+ }
33+
34+ fn common_filter_without_parent_checks ( node : & Node ) -> FilterResult {
35+ common_filter_base ( node) . unwrap_or ( FilterResult :: Include )
2736}
2837
2938fn is_first_sibling_in_parent_bbox < ' a > (
@@ -38,33 +47,26 @@ fn is_first_sibling_in_parent_bbox<'a>(
3847}
3948
4049pub fn common_filter ( node : & Node ) -> FilterResult {
41- if node. is_focused ( ) {
42- return FilterResult :: Include ;
43- }
44-
45- if node. is_hidden ( ) {
46- return FilterResult :: ExcludeSubtree ;
47- }
48-
49- let role = node. role ( ) ;
50- if role == Role :: GenericContainer || role == Role :: TextRun {
51- return FilterResult :: ExcludeNode ;
50+ if let Some ( result) = common_filter_base ( node) {
51+ return result;
5252 }
5353
5454 if let Some ( parent) = node. parent ( ) {
5555 if common_filter ( & parent) == FilterResult :: ExcludeSubtree {
5656 return FilterResult :: ExcludeSubtree ;
5757 }
58+ }
5859
60+ if let Some ( parent) = node. filtered_parent ( & common_filter_without_parent_checks) {
5961 if parent. clips_children ( ) {
6062 if let Some ( bbox) = node. bounding_box ( ) {
6163 if let Some ( parent_bbox) = parent. bounding_box ( ) {
6264 if bbox. intersect ( parent_bbox) . is_empty ( )
6365 && !( is_first_sibling_in_parent_bbox (
64- node. following_filtered_siblings ( & filter_for_sibling_clip_check ) ,
66+ node. following_filtered_siblings ( & common_filter_without_parent_checks ) ,
6567 parent_bbox,
6668 ) || is_first_sibling_in_parent_bbox (
67- node. preceding_filtered_siblings ( & filter_for_sibling_clip_check ) ,
69+ node. preceding_filtered_siblings ( & common_filter_without_parent_checks ) ,
6870 parent_bbox,
6971 ) )
7072 {
0 commit comments