Skip to content

Commit 29fa341

Browse files
authored
refactor!: Rename Role::InlineTextBox to TextRun (#473)
1 parent ef3b003 commit 29fa341

File tree

9 files changed

+49
-59
lines changed

9 files changed

+49
-59
lines changed

common/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub use geometry::{Affine, Point, Rect, Size, Vec2};
5555
pub enum Role {
5656
#[default]
5757
Unknown,
58-
InlineTextBox,
58+
TextRun,
5959
Cell,
6060
Label,
6161
Image,
@@ -665,7 +665,7 @@ pub struct CustomAction {
665665
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
666666
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
667667
pub struct TextPosition {
668-
/// The node's role must be [`Role::InlineTextBox`].
668+
/// The node's role must be [`Role::TextRun`].
669669
pub node: NodeId,
670670
/// The index of an item in [`Node::character_lengths`], or the length
671671
/// of that slice if the position is at the end of the line.
@@ -1438,7 +1438,7 @@ flag_methods! {
14381438
/// is in touch exploration mode, e.g. a virtual keyboard normally
14391439
/// behaves this way.
14401440
(TouchTransparent, is_touch_transparent, set_touch_transparent, clear_touch_transparent),
1441-
/// Use for a textbox that allows focus/selection but not input.
1441+
/// Use for a text widget that allows focus/selection but not input.
14421442
(ReadOnly, is_read_only, set_read_only, clear_read_only),
14431443
/// Use for a control or group of controls that disallows input.
14441444
(Disabled, is_disabled, set_disabled, clear_disabled),
@@ -1629,7 +1629,7 @@ text_decoration_property_methods! {
16291629
}
16301630

16311631
length_slice_property_methods! {
1632-
/// For inline text. The length (non-inclusive) of each character
1632+
/// For text runs, the length (non-inclusive) of each character
16331633
/// in UTF-8 code units (bytes). The sum of these lengths must equal
16341634
/// the length of [`value`], also in bytes.
16351635
///
@@ -1639,7 +1639,7 @@ length_slice_property_methods! {
16391639
/// the lengths of the characters from the text itself; this information
16401640
/// must be provided by the text editing implementation.
16411641
///
1642-
/// If this node is the last text box in a line that ends with a hard
1642+
/// If this node is the last text run in a line that ends with a hard
16431643
/// line break, that line break should be included at the end of this
16441644
/// node's value as either a CRLF or LF; in both cases, the line break
16451645
/// should be counted as a single character for the sake of this slice.
@@ -1649,7 +1649,7 @@ length_slice_property_methods! {
16491649
/// [`value`]: Node::value
16501650
(CharacterLengths, character_lengths, set_character_lengths, clear_character_lengths),
16511651

1652-
/// For inline text. The length of each word in characters, as defined
1652+
/// For text runs, the length of each word in characters, as defined
16531653
/// in [`character_lengths`]. The sum of these lengths must equal
16541654
/// the length of [`character_lengths`].
16551655
///
@@ -1675,7 +1675,7 @@ length_slice_property_methods! {
16751675
}
16761676

16771677
coord_slice_property_methods! {
1678-
/// For inline text. This is the position of each character within
1678+
/// For text runs, this is the position of each character within
16791679
/// the node's bounding box, in the direction given by
16801680
/// [`text_direction`], in the coordinate space of this node.
16811681
///
@@ -1693,7 +1693,7 @@ coord_slice_property_methods! {
16931693
/// [`character_lengths`]: Node::character_lengths
16941694
(CharacterPositions, character_positions, set_character_positions, clear_character_positions),
16951695

1696-
/// For inline text. This is the advance width of each character,
1696+
/// For text runs, this is the advance width of each character,
16971697
/// in the direction given by [`text_direction`], in the coordinate
16981698
/// space of this node.
16991699
///

consumer/src/filters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn common_filter(node: &Node) -> FilterResult {
3030
}
3131

3232
let role = node.role();
33-
if role == Role::GenericContainer || role == Role::InlineTextBox {
33+
if role == Role::GenericContainer || role == Role::TextRun {
3434
return FilterResult::ExcludeNode;
3535
}
3636

consumer/src/text.rs

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) struct InnerPosition<'a> {
1919
impl<'a> InnerPosition<'a> {
2020
fn upgrade(tree_state: &'a TreeState, weak: WeakPosition) -> Option<Self> {
2121
let node = tree_state.node_by_id(weak.node)?;
22-
if node.role() != Role::InlineTextBox {
22+
if node.role() != Role::TextRun {
2323
return None;
2424
}
2525
let character_index = weak.character_index;
@@ -34,7 +34,7 @@ impl<'a> InnerPosition<'a> {
3434

3535
fn clamped_upgrade(tree_state: &'a TreeState, weak: WeakPosition) -> Option<Self> {
3636
let node = tree_state.node_by_id(weak.node)?;
37-
if node.role() != Role::InlineTextBox {
37+
if node.role() != Role::TextRun {
3838
return None;
3939
}
4040
let character_index = weak
@@ -57,47 +57,37 @@ impl<'a> InnerPosition<'a> {
5757
false
5858
}
5959

60-
fn is_box_start(&self) -> bool {
60+
fn is_run_start(&self) -> bool {
6161
self.character_index == 0
6262
}
6363

6464
fn is_line_start(&self) -> bool {
65-
self.is_box_start() && self.node.data().previous_on_line().is_none()
65+
self.is_run_start() && self.node.data().previous_on_line().is_none()
6666
}
6767

68-
fn is_box_end(&self) -> bool {
68+
fn is_run_end(&self) -> bool {
6969
self.character_index == self.node.data().character_lengths().len()
7070
}
7171

7272
fn is_line_end(&self) -> bool {
73-
self.is_box_end() && self.node.data().next_on_line().is_none()
73+
self.is_run_end() && self.node.data().next_on_line().is_none()
7474
}
7575

7676
fn is_paragraph_end(&self) -> bool {
7777
self.is_line_end() && self.node.data().value().unwrap().ends_with('\n')
7878
}
7979

8080
fn is_document_start(&self, root_node: &Node) -> bool {
81-
self.is_box_start()
82-
&& self
83-
.node
84-
.preceding_inline_text_boxes(root_node)
85-
.next()
86-
.is_none()
81+
self.is_run_start() && self.node.preceding_text_runs(root_node).next().is_none()
8782
}
8883

8984
fn is_document_end(&self, root_node: &Node) -> bool {
90-
self.is_box_end()
91-
&& self
92-
.node
93-
.following_inline_text_boxes(root_node)
94-
.next()
95-
.is_none()
85+
self.is_run_end() && self.node.following_text_runs(root_node).next().is_none()
9686
}
9787

9888
fn biased_to_start(&self, root_node: &Node) -> Self {
99-
if self.is_box_end() {
100-
if let Some(node) = self.node.following_inline_text_boxes(root_node).next() {
89+
if self.is_run_end() {
90+
if let Some(node) = self.node.following_text_runs(root_node).next() {
10191
return Self {
10292
node,
10393
character_index: 0,
@@ -108,8 +98,8 @@ impl<'a> InnerPosition<'a> {
10898
}
10999

110100
fn biased_to_end(&self, root_node: &Node) -> Self {
111-
if self.is_box_start() {
112-
if let Some(node) = self.node.preceding_inline_text_boxes(root_node).next() {
101+
if self.is_run_start() {
102+
if let Some(node) = self.node.preceding_text_runs(root_node).next() {
113103
return Self {
114104
node,
115105
character_index: node.data().character_lengths().len(),
@@ -250,7 +240,7 @@ impl<'a> Position<'a> {
250240

251241
pub fn to_global_usv_index(&self) -> usize {
252242
let mut total_length = 0usize;
253-
for node in self.root_node.inline_text_boxes() {
243+
for node in self.root_node.text_runs() {
254244
let node_text = node.data().value().unwrap();
255245
if node.id() == self.inner.node.id() {
256246
let character_lengths = node.data().character_lengths();
@@ -268,7 +258,7 @@ impl<'a> Position<'a> {
268258

269259
pub fn to_global_utf16_index(&self) -> usize {
270260
let mut total_length = 0usize;
271-
for node in self.root_node.inline_text_boxes() {
261+
for node in self.root_node.text_runs() {
272262
let node_text = node.data().value().unwrap();
273263
if node.id() == self.inner.node.id() {
274264
let character_lengths = node.data().character_lengths();
@@ -545,7 +535,7 @@ impl<'a> Range<'a> {
545535
if start.node.id() == end.node.id() {
546536
return None;
547537
}
548-
for node in start.node.following_inline_text_boxes(&self.node) {
538+
for node in start.node.following_text_runs(&self.node) {
549539
if let Some(result) = f(&node) {
550540
return Some(result);
551541
}
@@ -796,7 +786,7 @@ impl WeakRange {
796786
}
797787

798788
fn text_node_filter(root_id: NodeId, node: &Node) -> FilterResult {
799-
if node.id() == root_id || node.role() == Role::InlineTextBox {
789+
if node.id() == root_id || node.role() == Role::TextRun {
800790
FilterResult::Include
801791
} else {
802792
FilterResult::ExcludeNode
@@ -844,22 +834,22 @@ fn character_index_at_point(node: &Node, point: Point) -> usize {
844834
}
845835

846836
impl<'a> Node<'a> {
847-
fn inline_text_boxes(
837+
fn text_runs(
848838
&self,
849839
) -> impl DoubleEndedIterator<Item = Node<'a>> + FusedIterator<Item = Node<'a>> + 'a {
850840
let id = self.id();
851841
self.filtered_children(move |node| text_node_filter(id, node))
852842
}
853843

854-
fn following_inline_text_boxes(
844+
fn following_text_runs(
855845
&self,
856846
root_node: &Node,
857847
) -> impl DoubleEndedIterator<Item = Node<'a>> + FusedIterator<Item = Node<'a>> + 'a {
858848
let id = root_node.id();
859849
self.following_filtered_siblings(move |node| text_node_filter(id, node))
860850
}
861851

862-
fn preceding_inline_text_boxes(
852+
fn preceding_text_runs(
863853
&self,
864854
root_node: &Node,
865855
) -> impl DoubleEndedIterator<Item = Node<'a>> + FusedIterator<Item = Node<'a>> + 'a {
@@ -870,19 +860,19 @@ impl<'a> Node<'a> {
870860
pub fn supports_text_ranges(&self) -> bool {
871861
(self.is_text_input()
872862
|| matches!(self.role(), Role::Label | Role::Document | Role::Terminal))
873-
&& self.inline_text_boxes().next().is_some()
863+
&& self.text_runs().next().is_some()
874864
}
875865

876866
fn document_start(&self) -> InnerPosition<'a> {
877-
let node = self.inline_text_boxes().next().unwrap();
867+
let node = self.text_runs().next().unwrap();
878868
InnerPosition {
879869
node,
880870
character_index: 0,
881871
}
882872
}
883873

884874
fn document_end(&self) -> InnerPosition<'a> {
885-
let node = self.inline_text_boxes().next_back().unwrap();
875+
let node = self.text_runs().next_back().unwrap();
886876
InnerPosition {
887877
node,
888878
character_index: node.data().character_lengths().len(),
@@ -922,7 +912,7 @@ impl<'a> Node<'a> {
922912
pub fn text_position_at_point(&self, point: Point) -> Position {
923913
let id = self.id();
924914
if let Some((node, point)) = self.hit_test(point, &move |node| text_node_filter(id, node)) {
925-
if node.role() == Role::InlineTextBox {
915+
if node.role() == Role::TextRun {
926916
let pos = InnerPosition {
927917
node,
928918
character_index: character_index_at_point(&node, point),
@@ -935,9 +925,9 @@ impl<'a> Node<'a> {
935925
}
936926

937927
// The following tests can assume that the point is not within
938-
// any inline text box.
928+
// any text run.
939929

940-
if let Some(node) = self.inline_text_boxes().next() {
930+
if let Some(node) = self.text_runs().next() {
941931
if let Some(rect) = node.bounding_box_in_coordinate_space(self) {
942932
let origin = rect.origin();
943933
if point.x < origin.x || point.y < origin.y {
@@ -949,7 +939,7 @@ impl<'a> Node<'a> {
949939
}
950940
}
951941

952-
for node in self.inline_text_boxes().rev() {
942+
for node in self.text_runs().rev() {
953943
if let Some(rect) = node.bounding_box_in_coordinate_space(self) {
954944
if let Some(direction) = node.data().text_direction() {
955945
let is_past_end = match direction {
@@ -1013,7 +1003,7 @@ impl<'a> Node<'a> {
10131003

10141004
pub fn text_position_from_global_usv_index(&self, index: usize) -> Option<Position> {
10151005
let mut total_length = 0usize;
1016-
for node in self.inline_text_boxes() {
1006+
for node in self.text_runs() {
10171007
let node_text = node.data().value().unwrap();
10181008
let node_text_length = node_text.chars().count();
10191009
let new_total_length = total_length + node_text_length;
@@ -1055,7 +1045,7 @@ impl<'a> Node<'a> {
10551045

10561046
pub fn text_position_from_global_utf16_index(&self, index: usize) -> Option<Position> {
10571047
let mut total_length = 0usize;
1058-
for node in self.inline_text_boxes() {
1048+
for node in self.text_runs() {
10591049
let node_text = node.data().value().unwrap();
10601050
let node_text_length = node_text.chars().map(char::len_utf16).sum::<usize>();
10611051
let new_total_length = total_length + node_text_length;
@@ -1135,7 +1125,7 @@ mod tests {
11351125
builder.build()
11361126
}),
11371127
(NodeId(2), {
1138-
let mut builder = NodeBuilder::new(Role::InlineTextBox);
1128+
let mut builder = NodeBuilder::new(Role::TextRun);
11391129
builder.set_bounds(Rect {
11401130
x0: 12.0,
11411131
y0: 33.666664123535156,
@@ -1170,7 +1160,7 @@ mod tests {
11701160
builder.build()
11711161
}),
11721162
(NodeId(3), {
1173-
let mut builder = NodeBuilder::new(Role::InlineTextBox);
1163+
let mut builder = NodeBuilder::new(Role::TextRun);
11741164
builder.set_bounds(Rect {
11751165
x0: 12.0,
11761166
y0: 48.33333206176758,
@@ -1195,7 +1185,7 @@ mod tests {
11951185
builder.build()
11961186
}),
11971187
(NodeId(4), {
1198-
let mut builder = NodeBuilder::new(Role::InlineTextBox);
1188+
let mut builder = NodeBuilder::new(Role::TextRun);
11991189
builder.set_bounds(Rect {
12001190
x0: 12.0,
12011191
y0: 63.0,
@@ -1221,7 +1211,7 @@ mod tests {
12211211
builder.build()
12221212
}),
12231213
(NodeId(5), {
1224-
let mut builder = NodeBuilder::new(Role::InlineTextBox);
1214+
let mut builder = NodeBuilder::new(Role::TextRun);
12251215
builder.set_bounds(Rect {
12261216
x0: 12.0,
12271217
y0: 77.66666412353516,
@@ -1237,7 +1227,7 @@ mod tests {
12371227
builder.build()
12381228
}),
12391229
(NodeId(6), {
1240-
let mut builder = NodeBuilder::new(Role::InlineTextBox);
1230+
let mut builder = NodeBuilder::new(Role::TextRun);
12411231
builder.set_bounds(Rect {
12421232
x0: 12.0,
12431233
y0: 92.33332824707031,
@@ -1267,7 +1257,7 @@ mod tests {
12671257
builder.build()
12681258
}),
12691259
(NodeId(7), {
1270-
let mut builder = NodeBuilder::new(Role::InlineTextBox);
1260+
let mut builder = NodeBuilder::new(Role::TextRun);
12711261
builder.set_bounds(Rect {
12721262
x0: 12.0,
12731263
y0: 107.0,

platforms/atspi-common/src/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a> AdapterChangeHandler<'a> {
172172
}
173173

174174
fn emit_text_change_if_needed(&mut self, old_node: &Node, new_node: &Node) {
175-
if let Role::InlineTextBox | Role::GenericContainer = new_node.role() {
175+
if let Role::TextRun | Role::GenericContainer = new_node.role() {
176176
if let (Some(old_parent), Some(new_parent)) = (
177177
old_node.filtered_parent(&filter),
178178
new_node.filtered_parent(&filter),

platforms/atspi-common/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'a> NodeWrapper<'a> {
158158
Role::Iframe | Role::IframePresentational => AtspiRole::InternalFrame,
159159
// TODO: If there are unignored children, then it should be AtspiRole::ImageMap.
160160
Role::Image => AtspiRole::Image,
161-
Role::InlineTextBox => AtspiRole::Static,
161+
Role::TextRun => AtspiRole::Static,
162162
Role::Legend => AtspiRole::Label,
163163
// Layout table objects are treated the same as `Role::GenericContainer`.
164164
Role::LayoutTable => AtspiRole::Section,

platforms/macos/src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl EventGenerator {
173173
}
174174

175175
fn insert_text_change_if_needed(&mut self, node: &Node) {
176-
if node.role() != Role::InlineTextBox {
176+
if node.role() != Role::TextRun {
177177
return;
178178
}
179179
if let Some(node) = node.filtered_parent(&filter) {

platforms/macos/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn ns_role(node: &Node) -> &'static NSAccessibilityRole {
3636
unsafe {
3737
match role {
3838
Role::Unknown => NSAccessibilityUnknownRole,
39-
Role::InlineTextBox => NSAccessibilityUnknownRole,
39+
Role::TextRun => NSAccessibilityUnknownRole,
4040
Role::Cell => NSAccessibilityCellRole,
4141
Role::Label => NSAccessibilityStaticTextRole,
4242
Role::Image => NSAccessibilityImageRole,

platforms/windows/src/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl AdapterChangeHandler<'_> {
7474
}
7575

7676
fn insert_text_change_if_needed(&mut self, node: &Node) {
77-
if node.role() != Role::InlineTextBox {
77+
if node.role() != Role::TextRun {
7878
return;
7979
}
8080
if let Some(node) = node.filtered_parent(&filter) {

0 commit comments

Comments
 (0)