Skip to content

Commit e0053a5

Browse files
authored
refactor!: Rename name to label and use value for label content (#475)
1 parent 7d8910e commit e0053a5

File tree

14 files changed

+102
-102
lines changed

14 files changed

+102
-102
lines changed

common/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ enum PropertyId {
784784
PopupFor,
785785

786786
// String
787-
Name,
787+
Label,
788788
Description,
789789
Value,
790790
AccessKey,
@@ -1537,7 +1537,11 @@ node_id_property_methods! {
15371537
}
15381538

15391539
string_property_methods! {
1540-
(Name, name, set_name, clear_name),
1540+
/// The label of a control that can have a label. If the label is specified
1541+
/// via the [`Node::labelled_by`] relation, this doesn't need to be set.
1542+
/// Note that the text content of a node with the [`Role::Label`] role
1543+
/// should be provided via [`Node::value`], not this property.
1544+
(Label, label, set_label, clear_label),
15411545
(Description, description, set_description, clear_description),
15421546
(Value, value, set_value, clear_value),
15431547
/// A single character, usually part of this node's name, that can be pressed,
@@ -1982,7 +1986,7 @@ impl<'de> Visitor<'de> for PropertiesVisitor {
19821986
PopupFor
19831987
},
19841988
String {
1985-
Name,
1989+
Label,
19861990
Description,
19871991
Value,
19881992
AccessKey,
@@ -2129,7 +2133,7 @@ impl JsonSchema for Properties {
21292133
PopupFor
21302134
},
21312135
Box<str> {
2132-
Name,
2136+
Label,
21332137
Description,
21342138
Value,
21352139
AccessKey,

consumer/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod tests {
6262
};
6363
let label_0_0_ignored = {
6464
let mut node = Node::new(Role::Label);
65-
node.set_name("label_0_0_ignored");
65+
node.set_value("label_0_0_ignored");
6666
node
6767
};
6868
let paragraph_1_ignored = {
@@ -83,7 +83,7 @@ mod tests {
8383
};
8484
let button_1_0_hidden = {
8585
let mut node = Node::new(Role::Button);
86-
node.set_name("button_1_0_hidden");
86+
node.set_label("button_1_0_hidden");
8787
node.set_hidden();
8888
node.set_children(vec![CONTAINER_1_0_0_HIDDEN_ID]);
8989
node
@@ -101,12 +101,12 @@ mod tests {
101101
x1: 90.0,
102102
y1: 30.0,
103103
});
104-
node.set_name("label_1_1");
104+
node.set_value("label_1_1");
105105
node
106106
};
107107
let button_1_2_hidden = {
108108
let mut node = Node::new(Role::Button);
109-
node.set_name("button_1_2_hidden");
109+
node.set_label("button_1_2_hidden");
110110
node.set_hidden();
111111
node.set_children(vec![CONTAINER_1_2_0_HIDDEN_ID]);
112112
node
@@ -123,7 +123,7 @@ mod tests {
123123
};
124124
let label_2_0 = {
125125
let mut node = Node::new(Role::Label);
126-
node.set_name("label_2_0");
126+
node.set_label("label_2_0");
127127
node
128128
};
129129
let paragraph_3_ignored = {
@@ -145,12 +145,12 @@ mod tests {
145145
};
146146
let label_3_1_0 = {
147147
let mut node = Node::new(Role::Label);
148-
node.set_name("label_3_1_0");
148+
node.set_value("label_3_1_0");
149149
node
150150
};
151151
let button_3_2 = {
152152
let mut node = Node::new(Role::Button);
153-
node.set_name("button_3_2");
153+
node.set_label("button_3_2");
154154
node
155155
};
156156
let empty_container_3_3_ignored = Node::new(Role::GenericContainer);

consumer/src/node.rs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,25 @@ impl<'a> Node<'a> {
492492
}
493493
}
494494

495-
pub fn name(&self) -> Option<String> {
496-
if let Some(name) = &self.data().name() {
497-
Some(name.to_string())
495+
pub fn label_comes_from_value(&self) -> bool {
496+
self.role() == Role::Label
497+
}
498+
499+
pub fn label(&self) -> Option<String> {
500+
if let Some(label) = &self.data().label() {
501+
Some(label.to_string())
498502
} else {
499-
let names = self
503+
let labels = self
500504
.labelled_by()
501-
.filter_map(|node| node.name())
505+
.filter_map(|node| {
506+
if node.label_comes_from_value() {
507+
node.value()
508+
} else {
509+
node.label()
510+
}
511+
})
502512
.collect::<Vec<String>>();
503-
(!names.is_empty()).then(move || names.join(" "))
513+
(!labels.is_empty()).then(move || labels.join(" "))
504514
}
505515
}
506516

@@ -916,7 +926,7 @@ mod tests {
916926
}
917927

918928
#[test]
919-
fn no_name_or_labelled_by() {
929+
fn no_label_or_labelled_by() {
920930
let update = TreeUpdate {
921931
nodes: vec![
922932
(NodeId(0), {
@@ -930,11 +940,11 @@ mod tests {
930940
focus: NodeId(0),
931941
};
932942
let tree = crate::Tree::new(update, false);
933-
assert_eq!(None, tree.state().node_by_id(NodeId(1)).unwrap().name());
943+
assert_eq!(None, tree.state().node_by_id(NodeId(1)).unwrap().label());
934944
}
935945

936946
#[test]
937-
fn name_from_labelled_by() {
947+
fn label_from_labelled_by() {
938948
// The following mock UI probably isn't very localization-friendly,
939949
// but it's good for this test.
940950
const LABEL_1: &str = "Check email every";
@@ -954,7 +964,7 @@ mod tests {
954964
}),
955965
(NodeId(2), {
956966
let mut node = Node::new(Role::Label);
957-
node.set_name(LABEL_1);
967+
node.set_value(LABEL_1);
958968
node
959969
}),
960970
(NodeId(3), {
@@ -964,7 +974,7 @@ mod tests {
964974
}),
965975
(NodeId(4), {
966976
let mut node = Node::new(Role::Label);
967-
node.set_name(LABEL_2);
977+
node.set_value(LABEL_2);
968978
node
969979
}),
970980
],
@@ -974,16 +984,16 @@ mod tests {
974984
let tree = crate::Tree::new(update, false);
975985
assert_eq!(
976986
Some([LABEL_1, LABEL_2].join(" ")),
977-
tree.state().node_by_id(NodeId(1)).unwrap().name()
987+
tree.state().node_by_id(NodeId(1)).unwrap().label()
978988
);
979989
assert_eq!(
980990
Some(LABEL_2.into()),
981-
tree.state().node_by_id(NodeId(3)).unwrap().name()
991+
tree.state().node_by_id(NodeId(3)).unwrap().label()
982992
);
983993
}
984994

985995
#[test]
986-
fn name_from_descendant_label() {
996+
fn label_from_descendant_label() {
987997
const ROOT_ID: NodeId = NodeId(0);
988998
const DEFAULT_BUTTON_ID: NodeId = NodeId(1);
989999
const DEFAULT_BUTTON_LABEL_ID: NodeId = NodeId(2);
@@ -1034,7 +1044,7 @@ mod tests {
10341044
}),
10351045
(DEFAULT_BUTTON_LABEL_ID, {
10361046
let mut node = Node::new(Role::Image);
1037-
node.set_name(DEFAULT_BUTTON_LABEL);
1047+
node.set_label(DEFAULT_BUTTON_LABEL);
10381048
node
10391049
}),
10401050
(LINK_ID, {
@@ -1049,7 +1059,7 @@ mod tests {
10491059
}),
10501060
(LINK_LABEL_ID, {
10511061
let mut node = Node::new(Role::Label);
1052-
node.set_name(LINK_LABEL);
1062+
node.set_value(LINK_LABEL);
10531063
node
10541064
}),
10551065
(CHECKBOX_ID, {
@@ -1059,7 +1069,7 @@ mod tests {
10591069
}),
10601070
(CHECKBOX_LABEL_ID, {
10611071
let mut node = Node::new(Role::Label);
1062-
node.set_name(CHECKBOX_LABEL);
1072+
node.set_value(CHECKBOX_LABEL);
10631073
node
10641074
}),
10651075
(RADIO_BUTTON_ID, {
@@ -1069,7 +1079,7 @@ mod tests {
10691079
}),
10701080
(RADIO_BUTTON_LABEL_ID, {
10711081
let mut node = Node::new(Role::Label);
1072-
node.set_name(RADIO_BUTTON_LABEL);
1082+
node.set_value(RADIO_BUTTON_LABEL);
10731083
node
10741084
}),
10751085
(MENU_BUTTON_ID, {
@@ -1079,7 +1089,7 @@ mod tests {
10791089
}),
10801090
(MENU_BUTTON_LABEL_ID, {
10811091
let mut node = Node::new(Role::Label);
1082-
node.set_name(MENU_BUTTON_LABEL);
1092+
node.set_value(MENU_BUTTON_LABEL);
10831093
node
10841094
}),
10851095
(MENU_ID, {
@@ -1094,7 +1104,7 @@ mod tests {
10941104
}),
10951105
(MENU_ITEM_LABEL_ID, {
10961106
let mut node = Node::new(Role::Label);
1097-
node.set_name(MENU_ITEM_LABEL);
1107+
node.set_value(MENU_ITEM_LABEL);
10981108
node
10991109
}),
11001110
(MENU_ITEM_CHECKBOX_ID, {
@@ -1104,7 +1114,7 @@ mod tests {
11041114
}),
11051115
(MENU_ITEM_CHECKBOX_LABEL_ID, {
11061116
let mut node = Node::new(Role::Label);
1107-
node.set_name(MENU_ITEM_CHECKBOX_LABEL);
1117+
node.set_value(MENU_ITEM_CHECKBOX_LABEL);
11081118
node
11091119
}),
11101120
(MENU_ITEM_RADIO_ID, {
@@ -1114,7 +1124,7 @@ mod tests {
11141124
}),
11151125
(MENU_ITEM_RADIO_LABEL_ID, {
11161126
let mut node = Node::new(Role::Label);
1117-
node.set_name(MENU_ITEM_RADIO_LABEL);
1127+
node.set_value(MENU_ITEM_RADIO_LABEL);
11181128
node
11191129
}),
11201130
],
@@ -1124,38 +1134,38 @@ mod tests {
11241134
let tree = crate::Tree::new(update, false);
11251135
assert_eq!(
11261136
Some(DEFAULT_BUTTON_LABEL.into()),
1127-
tree.state().node_by_id(DEFAULT_BUTTON_ID).unwrap().name()
1137+
tree.state().node_by_id(DEFAULT_BUTTON_ID).unwrap().label()
11281138
);
11291139
assert_eq!(
11301140
Some(LINK_LABEL.into()),
1131-
tree.state().node_by_id(LINK_ID).unwrap().name()
1141+
tree.state().node_by_id(LINK_ID).unwrap().label()
11321142
);
11331143
assert_eq!(
11341144
Some(CHECKBOX_LABEL.into()),
1135-
tree.state().node_by_id(CHECKBOX_ID).unwrap().name()
1145+
tree.state().node_by_id(CHECKBOX_ID).unwrap().label()
11361146
);
11371147
assert_eq!(
11381148
Some(RADIO_BUTTON_LABEL.into()),
1139-
tree.state().node_by_id(RADIO_BUTTON_ID).unwrap().name()
1149+
tree.state().node_by_id(RADIO_BUTTON_ID).unwrap().label()
11401150
);
11411151
assert_eq!(
11421152
Some(MENU_BUTTON_LABEL.into()),
1143-
tree.state().node_by_id(MENU_BUTTON_ID).unwrap().name()
1153+
tree.state().node_by_id(MENU_BUTTON_ID).unwrap().label()
11441154
);
11451155
assert_eq!(
11461156
Some(MENU_ITEM_LABEL.into()),
1147-
tree.state().node_by_id(MENU_ITEM_ID).unwrap().name()
1157+
tree.state().node_by_id(MENU_ITEM_ID).unwrap().label()
11481158
);
11491159
assert_eq!(
11501160
Some(MENU_ITEM_CHECKBOX_LABEL.into()),
11511161
tree.state()
11521162
.node_by_id(MENU_ITEM_CHECKBOX_ID)
11531163
.unwrap()
1154-
.name()
1164+
.label()
11551165
);
11561166
assert_eq!(
11571167
Some(MENU_ITEM_RADIO_LABEL.into()),
1158-
tree.state().node_by_id(MENU_ITEM_RADIO_ID).unwrap().name()
1168+
tree.state().node_by_id(MENU_ITEM_RADIO_ID).unwrap().label()
11591169
);
11601170
}
11611171
}

consumer/src/tree.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ mod tests {
647647
}),
648648
(NodeId(1), {
649649
let mut node = child_node.clone();
650-
node.set_name("foo");
650+
node.set_label("foo");
651651
node
652652
}),
653653
],
@@ -657,12 +657,12 @@ mod tests {
657657
let mut tree = super::Tree::new(first_update, false);
658658
assert_eq!(
659659
Some("foo".into()),
660-
tree.state().node_by_id(NodeId(1)).unwrap().name()
660+
tree.state().node_by_id(NodeId(1)).unwrap().label()
661661
);
662662
let second_update = TreeUpdate {
663663
nodes: vec![(NodeId(1), {
664664
let mut node = child_node;
665-
node.set_name("bar");
665+
node.set_label("bar");
666666
node
667667
})],
668668
tree: None,
@@ -680,8 +680,8 @@ mod tests {
680680
}
681681
fn node_updated(&mut self, old_node: &crate::Node, new_node: &crate::Node) {
682682
if new_node.id() == NodeId(1)
683-
&& old_node.name() == Some("foo".into())
684-
&& new_node.name() == Some("bar".into())
683+
&& old_node.label() == Some("foo".into())
684+
&& new_node.label() == Some("bar".into())
685685
{
686686
self.got_updated_child_node = true;
687687
return;
@@ -706,7 +706,7 @@ mod tests {
706706
assert!(handler.got_updated_child_node);
707707
assert_eq!(
708708
Some("bar".into()),
709-
tree.state().node_by_id(NodeId(1)).unwrap().name()
709+
tree.state().node_by_id(NodeId(1)).unwrap().label()
710710
);
711711
}
712712

@@ -725,7 +725,7 @@ mod tests {
725725
}),
726726
(NodeId(1), {
727727
let mut node = Node::new(Role::Button);
728-
node.set_name("foo");
728+
node.set_label("foo");
729729
node
730730
}),
731731
],

platforms/atspi-common/src/node.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ pub(crate) struct NodeWrapper<'a>(pub(crate) &'a Node<'a>);
3636

3737
impl<'a> NodeWrapper<'a> {
3838
pub(crate) fn name(&self) -> Option<String> {
39-
self.0.name()
39+
if self.0.label_comes_from_value() {
40+
self.0.value()
41+
} else {
42+
self.0.label()
43+
}
4044
}
4145

4246
pub(crate) fn description(&self) -> Option<String> {

0 commit comments

Comments
 (0)