From b05c5bbdecbcbda2747a86ec8b0b92d3401b6f21 Mon Sep 17 00:00:00 2001 From: Matt Campbell Date: Tue, 29 Oct 2024 14:15:57 -0500 Subject: [PATCH] Address review feedback --- consumer/src/node.rs | 14 ++++++++++++-- platforms/atspi-common/src/node.rs | 2 +- platforms/windows/src/node.rs | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/consumer/src/node.rs b/consumer/src/node.rs index 06d6dffa..ae6233a3 100644 --- a/consumer/src/node.rs +++ b/consumer/src/node.rs @@ -492,13 +492,23 @@ impl<'a> Node<'a> { } } + pub fn label_comes_from_value(&self) -> bool { + self.role() == Role::Label + } + pub fn label(&self) -> Option { if let Some(label) = &self.data().label() { Some(label.to_string()) } else { let labels = self .labelled_by() - .filter_map(|node| node.value()) + .filter_map(|node| { + if node.label_comes_from_value() { + node.value() + } else { + node.label() + } + }) .collect::>(); (!labels.is_empty()).then(move || labels.join(" ")) } @@ -1034,7 +1044,7 @@ mod tests { }), (DEFAULT_BUTTON_LABEL_ID, { let mut builder = NodeBuilder::new(Role::Image); - builder.set_value(DEFAULT_BUTTON_LABEL); + builder.set_label(DEFAULT_BUTTON_LABEL); builder.build() }), (LINK_ID, { diff --git a/platforms/atspi-common/src/node.rs b/platforms/atspi-common/src/node.rs index 6e43c986..31518708 100644 --- a/platforms/atspi-common/src/node.rs +++ b/platforms/atspi-common/src/node.rs @@ -36,7 +36,7 @@ pub(crate) struct NodeWrapper<'a>(pub(crate) &'a Node<'a>); impl<'a> NodeWrapper<'a> { pub(crate) fn name(&self) -> Option { - if matches!(self.0.role(), Role::Label | Role::Image) { + if self.0.label_comes_from_value() { self.0.value() } else { self.0.label() diff --git a/platforms/windows/src/node.rs b/platforms/windows/src/node.rs index 2cde1dbb..7a44e7c1 100644 --- a/platforms/windows/src/node.rs +++ b/platforms/windows/src/node.rs @@ -259,7 +259,7 @@ impl<'a> NodeWrapper<'a> { } pub(crate) fn name(&self) -> Option { - if matches!(self.0.role(), Role::Label | Role::Image) { + if self.0.label_comes_from_value() { self.0.value() } else { self.0.label() @@ -332,7 +332,7 @@ impl<'a> NodeWrapper<'a> { } fn is_value_pattern_supported(&self) -> bool { - self.0.has_value() && !matches!(self.0.role(), Role::Label | Role::Image) + self.0.has_value() && !self.0.label_comes_from_value() } fn is_range_value_pattern_supported(&self) -> bool {