| 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::{Action, PlatformNode}; |
| 7 | use zbus::{fdo, interface }; |
| 8 | |
| 9 | pub(crate) struct ActionInterface(PlatformNode); |
| 10 | |
| 11 | impl ActionInterface { |
| 12 | pub fn new(node: PlatformNode) -> Self { |
| 13 | Self(node) |
| 14 | } |
| 15 | |
| 16 | fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error { |
| 17 | |error: Error| crate::util::map_error_from_node(&self.0, error) |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | #[interface (name = "org.a11y.atspi.Action" )] |
| 22 | impl ActionInterface { |
| 23 | #[zbus(property)] |
| 24 | fn n_actions(&self) -> fdo::Result<i32> { |
| 25 | self.0.n_actions().map_err(self.map_error()) |
| 26 | } |
| 27 | |
| 28 | fn get_description(&self, _index: i32) -> &str { |
| 29 | "" |
| 30 | } |
| 31 | |
| 32 | fn get_name(&self, index: i32) -> fdo::Result<String> { |
| 33 | self.0.action_name(index).map_err(self.map_error()) |
| 34 | } |
| 35 | |
| 36 | fn get_localized_name(&self, index: i32) -> fdo::Result<String> { |
| 37 | self.0.action_name(index).map_err(self.map_error()) |
| 38 | } |
| 39 | |
| 40 | fn get_key_binding(&self, _index: i32) -> &str { |
| 41 | "" |
| 42 | } |
| 43 | |
| 44 | fn get_actions(&self) -> fdo::Result<Vec<Action>> { |
| 45 | self.0.actions().map_err(self.map_error()) |
| 46 | } |
| 47 | |
| 48 | fn do_action(&self, index: i32) -> fdo::Result<bool> { |
| 49 | self.0.do_action(index).map_err(self.map_error()) |
| 50 | } |
| 51 | } |
| 52 | |