Skip to content

Commit 7228494

Browse files
authored
fix: Fix problems related to the root node (#231)
1 parent fdd88e0 commit 7228494

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

platforms/macos/src/adapter.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ impl Adapter {
101101
let state = tree.state();
102102
let root = state.root();
103103
let point = from_ns_point(&view, &root, point);
104-
if let Some(node) = root.node_at_point(point, &filter) {
105-
return Id::autorelease_return(self.context.get_or_create_platform_node(node.id()))
106-
as *mut _;
107-
}
108-
null_mut()
104+
let node = root.node_at_point(point, &filter).unwrap_or(root);
105+
Id::autorelease_return(self.context.get_or_create_platform_node(node.id())) as *mut _
109106
}
110107
}

platforms/macos/src/appkit/view.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,13 @@ extern_methods!(
4747

4848
#[sel(backingScaleFactor)]
4949
pub(crate) fn backing_scale_factor(&self) -> CGFloat;
50+
51+
// NSView actually implements the full NSAccessibility protocol,
52+
// but since we don't have complete metadata for that, it's easier
53+
// to just expose the needed methods here.
54+
#[sel(accessibilityFrame)]
55+
pub(crate) fn accessibility_frame(&self) -> NSRect;
56+
#[sel(accessibilityParent)]
57+
pub(crate) fn accessibility_parent(&self) -> *mut NSObject;
5058
}
5159
);

platforms/macos/src/node.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ declare_class!(
376376
context
377377
.view
378378
.load()
379-
.map_or_else(null_mut, |view| Id::autorelease_return(view) as *mut _)
379+
.map_or_else(null_mut, |view| view.accessibility_parent())
380380
}
381381
})
382382
.unwrap_or_else(null_mut)
@@ -403,8 +403,16 @@ declare_class!(
403403
}
404404
};
405405

406-
node.bounding_box()
407-
.map_or(NSRect::ZERO, |rect| to_ns_rect(&view, rect))
406+
node.bounding_box().map_or_else(
407+
|| {
408+
if node.is_root() {
409+
view.accessibility_frame()
410+
} else {
411+
NSRect::ZERO
412+
}
413+
},
414+
|rect| to_ns_rect(&view, rect),
415+
)
408416
})
409417
.unwrap_or(NSRect::ZERO)
410418
}

0 commit comments

Comments
 (0)