1 | // Copyright 2023 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::Role; |
7 | |
8 | use crate::node::{DetachedNode, Node, NodeState}; |
9 | |
10 | #[derive (Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
11 | pub enum FilterResult { |
12 | Include, |
13 | ExcludeNode, |
14 | ExcludeSubtree, |
15 | } |
16 | |
17 | fn common_filter_base(node: &NodeState) -> FilterResult { |
18 | if node.is_hidden() { |
19 | return FilterResult::ExcludeSubtree; |
20 | } |
21 | |
22 | let role: Role = node.role(); |
23 | if role == Role::GenericContainer || role == Role::InlineTextBox { |
24 | return FilterResult::ExcludeNode; |
25 | } |
26 | |
27 | FilterResult::Include |
28 | } |
29 | |
30 | pub fn common_filter(node: &Node) -> FilterResult { |
31 | if node.is_focused() { |
32 | return FilterResult::Include; |
33 | } |
34 | common_filter_base(node:node.state()) |
35 | } |
36 | |
37 | pub fn common_filter_detached(node: &DetachedNode) -> FilterResult { |
38 | if node.is_focused() { |
39 | return FilterResult::Include; |
40 | } |
41 | common_filter_base(node:node.state()) |
42 | } |
43 | |
44 | pub fn common_filter_with_root_exception(node: &Node) -> FilterResult { |
45 | if node.is_root() { |
46 | return FilterResult::Include; |
47 | } |
48 | common_filter(node) |
49 | } |
50 | |