1 | // Copyright 2022 The AccessKit Authors. All rights reserved. |
2 | // Licensed under the Apache License, Version 2.0 (found in |
3 | // the LICENSE-APACHE file) or the MIT license (found in |
4 | // the LICENSE-MIT file), at your option. |
5 | |
6 | use accesskit_atspi_common::{PlatformNode, Rect}; |
7 | use atspi::{CoordType, Layer}; |
8 | use zbus::{fdo, names::OwnedUniqueName}; |
9 | |
10 | use crate::atspi::{ObjectId, OwnedObjectAddress}; |
11 | |
12 | pub(crate) struct ComponentInterface { |
13 | bus_name: OwnedUniqueName, |
14 | node: PlatformNode, |
15 | } |
16 | |
17 | impl ComponentInterface { |
18 | pub fn new(bus_name: OwnedUniqueName, node: PlatformNode) -> Self { |
19 | Self { bus_name, node } |
20 | } |
21 | |
22 | fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error { |
23 | |error: Error| crate::util::map_error_from_node(&self.node, error) |
24 | } |
25 | } |
26 | |
27 | #[dbus_interface (name = "org.a11y.atspi.Component" )] |
28 | impl ComponentInterface { |
29 | fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> fdo::Result<bool> { |
30 | self.node |
31 | .contains(x, y, coord_type) |
32 | .map_err(self.map_error()) |
33 | } |
34 | |
35 | fn get_accessible_at_point( |
36 | &self, |
37 | x: i32, |
38 | y: i32, |
39 | coord_type: CoordType, |
40 | ) -> fdo::Result<(OwnedObjectAddress,)> { |
41 | let accessible = self |
42 | .node |
43 | .accessible_at_point(x, y, coord_type) |
44 | .map_err(self.map_error())? |
45 | .map(|node| ObjectId::Node { |
46 | adapter: self.node.adapter_id(), |
47 | node, |
48 | }); |
49 | Ok(super::optional_object_address(&self.bus_name, accessible)) |
50 | } |
51 | |
52 | fn get_extents(&self, coord_type: CoordType) -> fdo::Result<(Rect,)> { |
53 | self.node |
54 | .extents(coord_type) |
55 | .map(|rect| (rect,)) |
56 | .map_err(self.map_error()) |
57 | } |
58 | |
59 | fn get_layer(&self) -> fdo::Result<Layer> { |
60 | self.node.layer().map_err(self.map_error()) |
61 | } |
62 | |
63 | fn grab_focus(&self) -> fdo::Result<bool> { |
64 | self.node.grab_focus().map_err(self.map_error()) |
65 | } |
66 | |
67 | fn scroll_to_point(&self, coord_type: CoordType, x: i32, y: i32) -> fdo::Result<bool> { |
68 | self.node |
69 | .scroll_to_point(coord_type, x, y) |
70 | .map_err(self.map_error()) |
71 | } |
72 | } |
73 | |