accesskit_unix/atspi/interfaces/
hyperlink.rs

1// Copyright 2026 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
6use accesskit_atspi_common::PlatformNode;
7use zbus::{fdo, interface, names::OwnedUniqueName};
8
9use crate::atspi::{ObjectId, OwnedObjectAddress};
10
11pub(crate) struct HyperlinkInterface {
12    bus_name: OwnedUniqueName,
13    node: PlatformNode,
14}
15
16impl HyperlinkInterface {
17    pub fn new(bus_name: OwnedUniqueName, node: PlatformNode) -> Self {
18        Self { bus_name, node }
19    }
20
21    fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
22        |error| crate::util::map_error_from_node(&self.node, error)
23    }
24}
25
26#[interface(name = "org.a11y.atspi.Hyperlink")]
27impl HyperlinkInterface {
28    #[zbus(property)]
29    fn n_anchors(&self) -> fdo::Result<i32> {
30        self.node.n_anchors().map_err(self.map_error())
31    }
32
33    #[zbus(property)]
34    fn start_index(&self) -> fdo::Result<i32> {
35        self.node.hyperlink_start_index().map_err(self.map_error())
36    }
37
38    #[zbus(property)]
39    fn end_index(&self) -> fdo::Result<i32> {
40        self.node.hyperlink_end_index().map_err(self.map_error())
41    }
42
43    fn get_object(&self, index: i32) -> fdo::Result<(OwnedObjectAddress,)> {
44        let object = self
45            .node
46            .hyperlink_object(index)
47            .map_err(self.map_error())?
48            .map(|node| ObjectId::Node {
49                adapter: self.node.adapter_id(),
50                node,
51            });
52        Ok(super::optional_object_address(&self.bus_name, object))
53    }
54
55    #[zbus(name = "GetURI")]
56    fn get_uri(&self, index: i32) -> fdo::Result<String> {
57        self.node.uri(index).map_err(self.map_error())
58    }
59
60    fn is_valid(&self) -> fdo::Result<bool> {
61        self.node.hyperlink_is_valid().map_err(self.map_error())
62    }
63}