Skip to content

Commit 7342525

Browse files
committed
refactor: Use TreeState::locate_node in adapters
1 parent 941a96d commit 7342525

5 files changed

Lines changed: 34 additions & 25 deletions

File tree

platforms/android/src/adapter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl Adapter {
419419
} else {
420420
self.node_id_map.get_accesskit_id(virtual_view_id)?
421421
};
422-
let (target_node, target_tree) = tree.locate_node(target)?;
422+
let (target_node, target_tree) = tree_state.locate_node(target)?;
423423
let mut events = Vec::new();
424424
let request = match action {
425425
ACTION_CLICK => ActionRequest {
@@ -532,8 +532,8 @@ impl Adapter {
532532
let id = self.node_id_map.get_accesskit_id(virtual_view_id)?;
533533
tree_state.node_by_id(id).unwrap()
534534
};
535-
let (node_id, tree_id) = tree.locate_node(node.id())?;
536-
let (focus_id, _) = tree.locate_node(tree_state.focus_id_in_tree())?;
535+
let (node_id, tree_id) = tree_state.locate_node(node.id())?;
536+
let (focus_id, _) = tree_state.locate_node(tree_state.focus_id_in_tree())?;
537537
// TalkBack expects the text selection change to take effect
538538
// immediately, so we optimistically update the node.
539539
// But don't be *too* optimistic.

platforms/atspi-common/src/node.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl PlatformNode {
746746
{
747747
let context = self.upgrade_context()?;
748748
let tree = context.read_tree();
749-
if let Some((target_node, target_tree)) = tree.locate_node(target) {
749+
if let Some((target_node, target_tree)) = tree.state().locate_node(target) {
750750
let request = f(tree.state(), &context, target_node, target_tree);
751751
drop(tree);
752752
context.do_action(request);
@@ -1072,7 +1072,8 @@ impl PlatformNode {
10721072
node.filtered_parent(&filter),
10731073
coord_type,
10741074
);
1075-
let (target_node, target_tree) = tree.locate_node(self.id).ok_or(Error::Defunct)?;
1075+
let (target_node, target_tree) =
1076+
tree.state().locate_node(self.id).ok_or(Error::Defunct)?;
10761077
context.do_action(ActionRequest {
10771078
action: Action::ScrollToPoint,
10781079
target_tree,
@@ -1153,7 +1154,7 @@ impl PlatformNode {
11531154
Ok(true)
11541155
} else if child.is_selectable() && child.is_clickable(&filter) {
11551156
let (target_node, target_tree) =
1156-
tree.locate_node(child.id()).ok_or(Error::Defunct)?;
1157+
tree.state().locate_node(child.id()).ok_or(Error::Defunct)?;
11571158
context.do_action(ActionRequest {
11581159
action: Action::Click,
11591160
target_tree,
@@ -1179,7 +1180,7 @@ impl PlatformNode {
11791180
{
11801181
if child.is_clickable(&filter) {
11811182
let (target_node, target_tree) =
1182-
tree.locate_node(child.id()).ok_or(Error::Defunct)?;
1183+
tree.state().locate_node(child.id()).ok_or(Error::Defunct)?;
11831184
context.do_action(ActionRequest {
11841185
action: Action::Click,
11851186
target_tree,
@@ -1222,7 +1223,7 @@ impl PlatformNode {
12221223
Ok(true)
12231224
} else if child.is_selectable() && child.is_clickable(&filter) {
12241225
let (target_node, target_tree) =
1225-
tree.locate_node(child.id()).ok_or(Error::Defunct)?;
1226+
tree.state().locate_node(child.id()).ok_or(Error::Defunct)?;
12261227
context.do_action(ActionRequest {
12271228
action: Action::Click,
12281229
target_tree,
@@ -1294,7 +1295,8 @@ impl PlatformNode {
12941295
pub fn set_caret_offset(&self, offset: i32) -> Result<bool> {
12951296
self.resolve_for_text_with_context(|node, tree, context| {
12961297
let offset = text_position_from_offset(&node, offset).ok_or(Error::IndexOutOfRange)?;
1297-
let (target_node, target_tree) = tree.locate_node(node.id()).ok_or(Error::Defunct)?;
1298+
let (target_node, target_tree) =
1299+
tree.state().locate_node(node.id()).ok_or(Error::Defunct)?;
12981300
context.do_action(ActionRequest {
12991301
action: Action::SetTextSelection,
13001302
target_tree,
@@ -1405,7 +1407,8 @@ impl PlatformNode {
14051407
let selection_end = node
14061408
.text_selection_focus()
14071409
.unwrap_or_else(|| node.document_range().start());
1408-
let (target_node, target_tree) = tree.locate_node(node.id()).ok_or(Error::Defunct)?;
1410+
let (target_node, target_tree) =
1411+
tree.state().locate_node(node.id()).ok_or(Error::Defunct)?;
14091412
context.do_action(ActionRequest {
14101413
action: Action::SetTextSelection,
14111414
target_tree,
@@ -1431,7 +1434,8 @@ impl PlatformNode {
14311434
self.resolve_for_text_with_context(|node, tree, context| {
14321435
let range = text_range_from_offsets(&node, start_offset, end_offset)
14331436
.ok_or(Error::IndexOutOfRange)?;
1434-
let (target_node, target_tree) = tree.locate_node(node.id()).ok_or(Error::Defunct)?;
1437+
let (target_node, target_tree) =
1438+
tree.state().locate_node(node.id()).ok_or(Error::Defunct)?;
14351439
context.do_action(ActionRequest {
14361440
action: Action::SetTextSelection,
14371441
target_tree,
@@ -1492,6 +1496,7 @@ impl PlatformNode {
14921496
range.start()
14931497
};
14941498
let (target_node, target_tree) = tree
1499+
.state()
14951500
.locate_node(position.inner_node().id())
14961501
.ok_or(Error::Defunct)?;
14971502
context.do_action(ActionRequest {
@@ -1526,7 +1531,7 @@ impl PlatformNode {
15261531
if let Some(rect) = text_range_bounds_from_offsets(&node, start_offset, end_offset) {
15271532
let point = Point::new(target_point.x - rect.x0, target_point.y - rect.y0);
15281533
let (target_node, target_tree) =
1529-
tree.locate_node(node.id()).ok_or(Error::Defunct)?;
1534+
tree.state().locate_node(node.id()).ok_or(Error::Defunct)?;
15301535
context.do_action(ActionRequest {
15311536
action: Action::ScrollToPoint,
15321537
target_tree,

platforms/macos/src/node.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ declare_class!(
556556
fn set_value(&self, value: &NSObject) {
557557
if let Some(string) = downcast_ref::<NSString>(value) {
558558
self.resolve_with_context(|node, tree, context| {
559-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
559+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
560560
context.do_action(ActionRequest {
561561
action: Action::SetValue,
562562
target_tree,
@@ -567,7 +567,7 @@ declare_class!(
567567
});
568568
} else if let Some(number) = downcast_ref::<NSNumber>(value) {
569569
self.resolve_with_context(|node, tree, context| {
570-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
570+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
571571
context.do_action(ActionRequest {
572572
action: Action::SetValue,
573573
target_tree,
@@ -640,7 +640,7 @@ declare_class!(
640640
self.resolve_with_context(|node, tree, context| {
641641
if focused {
642642
if node.is_focusable(&filter) {
643-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
643+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
644644
context.do_action(ActionRequest {
645645
action: Action::Focus,
646646
target_tree,
@@ -652,7 +652,7 @@ declare_class!(
652652
} else {
653653
let root = tree.state().root();
654654
if root.is_focusable(&filter) {
655-
if let Some((target_node, target_tree)) = tree.locate_node(root.id()) {
655+
if let Some((target_node, target_tree)) = tree.state().locate_node(root.id()) {
656656
context.do_action(ActionRequest {
657657
action: Action::Focus,
658658
target_tree,
@@ -670,7 +670,7 @@ declare_class!(
670670
self.resolve_with_context(|node, tree, context| {
671671
let clickable = node.is_clickable(&filter);
672672
if clickable {
673-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
673+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
674674
context.do_action(ActionRequest {
675675
action: Action::Click,
676676
target_tree,
@@ -689,7 +689,7 @@ declare_class!(
689689
self.resolve_with_context(|node, tree, context| {
690690
let supports_increment = node.supports_increment(&filter);
691691
if supports_increment {
692-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
692+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
693693
context.do_action(ActionRequest {
694694
action: Action::Increment,
695695
target_tree,
@@ -708,7 +708,7 @@ declare_class!(
708708
self.resolve_with_context(|node, tree, context| {
709709
let supports_decrement = node.supports_decrement(&filter);
710710
if supports_decrement {
711-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
711+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
712712
context.do_action(ActionRequest {
713713
action: Action::Decrement,
714714
target_tree,
@@ -1008,7 +1008,7 @@ declare_class!(
10081008
self.resolve_with_context(|node, tree, context| {
10091009
if node.supports_text_ranges() {
10101010
if let Some(range) = from_ns_range(node, range) {
1011-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
1011+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
10121012
context.do_action(ActionRequest {
10131013
action: Action::SetTextSelection,
10141014
target_tree,
@@ -1051,7 +1051,7 @@ declare_class!(
10511051
if node.is_selected() == Some(selected) {
10521052
return;
10531053
}
1054-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
1054+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
10551055
context.do_action(ActionRequest {
10561056
action: Action::Click,
10571057
target_tree,
@@ -1117,7 +1117,7 @@ declare_class!(
11171117
&& wrapper.is_item_like()
11181118
&& node.is_selectable();
11191119
if selectable {
1120-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
1120+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
11211121
context.do_action(ActionRequest {
11221122
action: Action::Click,
11231123
target_tree,
@@ -1192,7 +1192,7 @@ declare_class!(
11921192
fn perform_action(&self, action: &NSString) {
11931193
self.resolve_with_context(|node, tree, context| {
11941194
if action == ns_string!(SCROLL_TO_VISIBLE_ACTION) {
1195-
if let Some((target_node, target_tree)) = tree.locate_node(node.id()) {
1195+
if let Some((target_node, target_tree)) = tree.state().locate_node(node.id()) {
11961196
context.do_action(ActionRequest {
11971197
action: Action::ScrollIntoView,
11981198
target_tree,

platforms/windows/src/node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ impl PlatformNode {
828828
fn node_with_location<'a>(&self, tree: &'a Tree) -> Result<(Node<'a>, LocalNodeId, TreeId)> {
829829
let node = self.node(tree)?;
830830
let (local_id, tree_id) = tree
831+
.state()
831832
.locate_node(node.id())
832833
.ok_or_else(element_not_available)?;
833834
Ok((node, local_id, tree_id))

platforms/windows/src/text.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl ITextRangeProvider_Impl for PlatformRange_Impl {
598598

599599
fn Select(&self) -> Result<()> {
600600
self.do_action(|range, tree| {
601-
let (target_node, target_tree) = tree.locate_node(range.node().id()).unwrap();
601+
let (target_node, target_tree) = tree.state().locate_node(range.node().id()).unwrap();
602602
ActionRequest {
603603
action: Action::SetTextSelection,
604604
target_tree,
@@ -625,7 +625,10 @@ impl ITextRangeProvider_Impl for PlatformRange_Impl {
625625
} else {
626626
range.end()
627627
};
628-
let (target_node, target_tree) = tree.locate_node(position.inner_node().id()).unwrap();
628+
let (target_node, target_tree) = tree
629+
.state()
630+
.locate_node(position.inner_node().id())
631+
.unwrap();
629632
ActionRequest {
630633
action: Action::ScrollIntoView,
631634
target_tree,

0 commit comments

Comments
 (0)