Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix our Collection story #196

Merged
merged 30 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
693fbec
Prepare collection proxy
luukvanderduim Jun 22, 2024
fb8276a
Update type validation table
luukvanderduim Jun 22, 2024
a664693
Implement `Default` and `FromIterator` on `InterfaceSet`
luukvanderduim Jun 22, 2024
7e6368e
Introduce `object_match` module
luukvanderduim Jun 22, 2024
fe8d1dc
Fix Clippy lint on doc
luukvanderduim Jun 23, 2024
3aa32c3
Fix docs on `SortOrder`
luukvanderduim Jun 23, 2024
86708f8
Add module level docs to CollectionProxy
luukvanderduim Jun 23, 2024
6386203
Document `get_active_descendant`
luukvanderduim Jun 23, 2024
39819ed
Document `get_matches`
luukvanderduim Jun 23, 2024
3c65410
Document `get_matches_from`
luukvanderduim Jun 23, 2024
5475332
Document `get_matches_to`
luukvanderduim Jun 23, 2024
7f5dcd7
Move `SortOrder` to object_match module
luukvanderduim Jun 23, 2024
511637c
Fix imports
luukvanderduim Jun 23, 2024
6edc916
Docs: Remove max object number
luukvanderduim Jun 23, 2024
779a6c9
Provide links to methods in module level docs
luukvanderduim Jun 23, 2024
d6e2f03
Rename 'phantom' field to '_marker'
luukvanderduim Jun 24, 2024
728e724
`MatchType` now defaults to `All`
luukvanderduim Jun 24, 2024
e79d185
We know of only one implementation
luukvanderduim Jun 24, 2024
eb6b351
Implement IntoIterator for InterfaceSet and &InterfaceSet
luukvanderduim Jun 24, 2024
9eea366
Accept implementations of IntoIterator in `interfaces` method
luukvanderduim Jun 24, 2024
f723bfe
Update imports, add `Borrow`
luukvanderduim Jun 24, 2024
6e5fbde
Clippy requests us to be more concise.
luukvanderduim Jun 25, 2024
1aaf7e0
Add `IntoIterator` for `StateSet`
luukvanderduim Jun 25, 2024
3e1ba08
Add FromIterator that allows to collect from iterators that yield &In…
luukvanderduim Jun 25, 2024
87117b8
impl `FromIterator` and `IntoIterator` for `StateSet`
luukvanderduim Jun 25, 2024
d5f1bc0
Tests for `FromIterator` and `IntoIterator` for StateSet
luukvanderduim Jun 25, 2024
3d2739d
Add `State` to imports
luukvanderduim Jun 25, 2024
94192a6
Fixup docs on `Collection::{get_matches_to, get_matches_from}`
luukvanderduim Jun 25, 2024
d478e27
Comment on magic numbers while slicing into the signature
luukvanderduim Jun 25, 2024
1eee245
Reinstate ` get_active_descendant`
luukvanderduim Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion atspi-common/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,36 @@
self.0.insert(other);
}

pub fn iter(self) -> impl Iterator<Item = Interface> {
#[must_use]
pub fn iter(&self) -> enumflags2::Iter<Interface> {
self.0.iter()
}
}

impl IntoIterator for InterfaceSet {
type IntoIter = enumflags2::Iter<Interface>;
type Item = Interface;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl IntoIterator for &InterfaceSet {
type IntoIter = enumflags2::Iter<Interface>;
type Item = Interface;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl Default for InterfaceSet {
luukvanderduim marked this conversation as resolved.
Show resolved Hide resolved
fn default() -> Self {
Self::empty()
}
}

impl<'de> de::Deserialize<'de> for InterfaceSet {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -161,6 +186,18 @@
}
}

impl FromIterator<Interface> for InterfaceSet {
fn from_iter<T: IntoIterator<Item = Interface>>(iter: T) -> Self {
Self(BitFlags::from_iter(iter))
}
}

luukvanderduim marked this conversation as resolved.
Show resolved Hide resolved
impl<'a> FromIterator<&'a Interface> for InterfaceSet {
fn from_iter<I: IntoIterator<Item = &'a Interface>>(iter: I) -> Self {
InterfaceSet(iter.into_iter().copied().collect())
}

Check warning on line 198 in atspi-common/src/interface.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/interface.rs#L196-L198

Added lines #L196 - L198 were not covered by tests
}

impl From<Interface> for InterfaceSet {
fn from(value: Interface) -> Self {
Self(value.into())
Expand Down Expand Up @@ -249,4 +286,25 @@
let (decoded, _) = encoded.deserialize::<InterfaceSet>().unwrap();
assert!(object == decoded);
}

// The order of appearance of the interfaces is equal to the order in the enum.
#[test]
fn iterator_on_interface_set() {
let set =
InterfaceSet::new(Interface::Accessible | Interface::Action | Interface::Component);
let mut iter = set.into_iter();
assert_eq!(iter.next(), Some(Interface::Accessible));
assert_eq!(iter.next(), Some(Interface::Action));
assert_eq!(iter.next(), Some(Interface::Component));
assert_eq!(iter.next(), None);
}

#[test]
fn iterator_on_interface_set_ref() {
let set = InterfaceSet::new(Interface::Text | Interface::Collection | Interface::Component);
let mut iter = (&set).into_iter();
assert_eq!(iter.next(), Some(Interface::Collection));
assert_eq!(iter.next(), Some(Interface::Component));
assert_eq!(iter.next(), Some(Interface::Text));
}
}
80 changes: 2 additions & 78 deletions atspi-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ extern crate static_assertions;
#[macro_use]
pub(crate) mod macros;

pub mod object_match;
pub use object_match::{MatchType, ObjectMatchRule, SortOrder, TreeTraversalType};
pub mod object_ref;
pub use object_ref::ObjectRef;
pub mod interface;
Expand All @@ -36,74 +38,8 @@ use zvariant::Type;

pub type Result<T> = std::result::Result<T, AtspiError>;

pub type MatchArgs<'a> = (
&'a [i32],
MatchType,
std::collections::HashMap<&'a str, &'a str>,
MatchType,
&'a [i32],
MatchType,
&'a [&'a str],
MatchType,
bool,
);

pub type TextSelection = (ObjectRef, i32, ObjectRef, i32, bool);

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(u32)]
/// Enumeration used by interface `CollectionProxy` to specify the way [`ObjectRef`]
/// objects should be sorted.
///
/// [`ObjectRef`]: crate::object_ref::ObjectRef
pub enum SortOrder {
/// Invalid sort order
Invalid,
/// Canonical sort order
Canonical,
/// Flow sort order
Flow,
/// Tab sort order
Tab,
/// Reverse canonical sort order
ReverseCanonical,
/// Reverse flow sort order
ReverseFlow,
/// Reverse tab sort order
ReverseTab,
}

/// Method of traversing a tree in the `CollectionProxy`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(u32)]
pub enum TreeTraversalType {
/// Restrict children tree traversal
RestrictChildren,
/// Restrict sibling tree traversal
RestrictSibling,
/// In-order tree traversal.
Inorder,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(i32)]
/// Enumeration used by [`MatchArgs`] to specify how to interpret [`ObjectRef`] objects.
///
/// [`ObjectRef`]: crate::object_ref::ObjectRef
pub enum MatchType {
/// Invalid match type
Invalid,
/// true if all of the criteria are met.
All,
/// true if any of the criteria are met.
Any,
/// true if none of the criteria are met.
NA,
/// Same as [`Self::All`] if the criteria is non-empty;
/// for empty criteria this rule requires returned value to also have empty set.
Empty,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(u32)]
/// The coordinate type encodes the frame of reference.
Expand Down Expand Up @@ -293,16 +229,4 @@ mod tests {
let match_type_signature = rule_signature.slice(3..4);
assert_eq!(MatchType::signature(), match_type_signature);
}

#[test]
fn validate_tree_traversal_type_signature() {
let signature = method_args_signature!(member: "GetMatchesTo", interface: "org.a11y.atspi.Collection", argument: "tree");
assert_eq!(TreeTraversalType::signature(), signature);
}

#[test]
fn validate_sort_order_signature() {
let signature = method_args_signature!(member: "GetMatches", interface: "org.a11y.atspi.Collection", argument: "sortby");
assert_eq!(SortOrder::signature(), signature);
}
}
Loading
Loading