(
snapshot: &Value,
selector: &ElementSelector,
)
| 50 | } |
| 51 | |
| 52 | fn find_element_tap_target( |
| 53 | snapshot: &Value, |
| 54 | selector: &ElementSelector, |
| 55 | ) -> Option<ElementTapTarget> { |
| 56 | let roots = snapshot.get("roots")?.as_array()?; |
| 57 | let mut matches = Vec::new(); |
| 58 | for root in roots { |
| 59 | let (root_width, root_height) = element_size(root)?; |
| 60 | collect_matching_elements(root, selector, root_width, root_height, &mut matches); |
| 61 | } |
| 62 | let target = if let Some(index) = selector.index { |
| 63 | matches.into_iter().nth(index) |
| 64 | } else { |
| 65 | matches |
| 66 | .into_iter() |
| 67 | .max_by_key(|target| is_actionable_element(target.node) as u8) |
| 68 | }; |
| 69 | target.and_then(|target| { |
| 70 | element_center(target.node).map(|(x, y)| ElementTapTarget { |
| 71 | x, |
| 72 | y, |
| 73 | root_width: target.root_width, |
| 74 | root_height: target.root_height, |
| 75 | }) |
| 76 | }) |
| 77 | } |
| 78 | |
| 79 | struct MatchedElement<'a> { |
| 80 | node: &'a Value, |
no test coverage detected