accesskit_unix/atspi/interfaces/
component.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use accesskit_atspi_common::{PlatformNode, Rect};
use atspi::{CoordType, Layer};
use zbus::{fdo, names::OwnedUniqueName};

use crate::atspi::{ObjectId, OwnedObjectAddress};

pub(crate) struct ComponentInterface {
    bus_name: OwnedUniqueName,
    node: PlatformNode,
}

impl ComponentInterface {
    pub fn new(bus_name: OwnedUniqueName, node: PlatformNode) -> Self {
        Self { bus_name, node }
    }

    fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
        |error| crate::util::map_error_from_node(&self.node, error)
    }
}

#[dbus_interface(name = "org.a11y.atspi.Component")]
impl ComponentInterface {
    fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> fdo::Result<bool> {
        self.node
            .contains(x, y, coord_type)
            .map_err(self.map_error())
    }

    fn get_accessible_at_point(
        &self,
        x: i32,
        y: i32,
        coord_type: CoordType,
    ) -> fdo::Result<(OwnedObjectAddress,)> {
        let accessible = self
            .node
            .accessible_at_point(x, y, coord_type)
            .map_err(self.map_error())?
            .map(|node| ObjectId::Node {
                adapter: self.node.adapter_id(),
                node,
            });
        Ok(super::optional_object_address(&self.bus_name, accessible))
    }

    fn get_extents(&self, coord_type: CoordType) -> fdo::Result<(Rect,)> {
        self.node
            .extents(coord_type)
            .map(|rect| (rect,))
            .map_err(self.map_error())
    }

    fn get_layer(&self) -> fdo::Result<Layer> {
        self.node.layer().map_err(self.map_error())
    }

    fn grab_focus(&self) -> fdo::Result<bool> {
        self.node.grab_focus().map_err(self.map_error())
    }

    fn scroll_to_point(&self, coord_type: CoordType, x: i32, y: i32) -> fdo::Result<bool> {
        self.node
            .scroll_to_point(coord_type, x, y)
            .map_err(self.map_error())
    }
}