Skip to content

Commit fad11a1

Browse files
authored
refactor!: Refactor actions for scrolling by discrete units (#573)
1 parent 29584d4 commit fad11a1

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

common/src/lib.rs

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,13 @@ pub enum Action {
304304
/// Requires [`ActionRequest::data`] to be set to [`ActionData::Value`].
305305
ReplaceSelectedText,
306306

307-
// Scrolls by approximately one screen in a specific direction.
308-
// TBD: Do we need a doc comment on each of the values below?
309-
// Or does this awkwardness suggest a refactor?
310-
ScrollBackward,
307+
/// Scroll down by the specified unit.
311308
ScrollDown,
312-
ScrollForward,
309+
/// Scroll left by the specified unit.
313310
ScrollLeft,
311+
/// Scroll right by the specified unit.
314312
ScrollRight,
313+
/// Scroll up by the specified unit.
315314
ScrollUp,
316315

317316
/// Scroll any scrollable containers to make the target object visible
@@ -365,19 +364,17 @@ impl Action {
365364
8 => Some(Action::HideTooltip),
366365
9 => Some(Action::ShowTooltip),
367366
10 => Some(Action::ReplaceSelectedText),
368-
11 => Some(Action::ScrollBackward),
369-
12 => Some(Action::ScrollDown),
370-
13 => Some(Action::ScrollForward),
371-
14 => Some(Action::ScrollLeft),
372-
15 => Some(Action::ScrollRight),
373-
16 => Some(Action::ScrollUp),
374-
17 => Some(Action::ScrollIntoView),
375-
18 => Some(Action::ScrollToPoint),
376-
19 => Some(Action::SetScrollOffset),
377-
20 => Some(Action::SetTextSelection),
378-
21 => Some(Action::SetSequentialFocusNavigationStartingPoint),
379-
22 => Some(Action::SetValue),
380-
23 => Some(Action::ShowContextMenu),
367+
11 => Some(Action::ScrollDown),
368+
12 => Some(Action::ScrollLeft),
369+
13 => Some(Action::ScrollRight),
370+
14 => Some(Action::ScrollUp),
371+
15 => Some(Action::ScrollIntoView),
372+
16 => Some(Action::ScrollToPoint),
373+
17 => Some(Action::SetScrollOffset),
374+
18 => Some(Action::SetTextSelection),
375+
19 => Some(Action::SetSequentialFocusNavigationStartingPoint),
376+
20 => Some(Action::SetValue),
377+
21 => Some(Action::ShowContextMenu),
381378
_ => None,
382379
}
383380
}
@@ -2600,6 +2597,26 @@ pub struct TreeUpdate {
26002597
pub focus: NodeId,
26012598
}
26022599

2600+
/// The amount by which to scroll in the direction specified by one of the
2601+
/// `Scroll` actions.
2602+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2603+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2604+
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
2605+
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
2606+
#[cfg_attr(
2607+
feature = "pyo3",
2608+
pyclass(module = "accesskit", rename_all = "SCREAMING_SNAKE_CASE", eq)
2609+
)]
2610+
#[repr(u8)]
2611+
pub enum ScrollUnit {
2612+
/// A single item of a list, line of text (for vertical scrolling),
2613+
/// character (for horizontal scrolling), or an approximation of
2614+
/// one of these.
2615+
Item,
2616+
/// The amount of content that fits in the viewport.
2617+
Page,
2618+
}
2619+
26032620
#[derive(Clone, Debug, PartialEq)]
26042621
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26052622
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
@@ -2609,6 +2626,7 @@ pub enum ActionData {
26092626
CustomAction(i32),
26102627
Value(Box<str>),
26112628
NumericValue(f64),
2629+
ScrollUnit(ScrollUnit),
26122630
/// Optional target rectangle for [`Action::ScrollIntoView`], in
26132631
/// the coordinate space of the action's target node.
26142632
ScrollTargetRect(Rect),
@@ -2720,23 +2738,21 @@ mod tests {
27202738
assert_eq!(Action::n(8), Some(Action::HideTooltip));
27212739
assert_eq!(Action::n(9), Some(Action::ShowTooltip));
27222740
assert_eq!(Action::n(10), Some(Action::ReplaceSelectedText));
2723-
assert_eq!(Action::n(11), Some(Action::ScrollBackward));
2724-
assert_eq!(Action::n(12), Some(Action::ScrollDown));
2725-
assert_eq!(Action::n(13), Some(Action::ScrollForward));
2726-
assert_eq!(Action::n(14), Some(Action::ScrollLeft));
2727-
assert_eq!(Action::n(15), Some(Action::ScrollRight));
2728-
assert_eq!(Action::n(16), Some(Action::ScrollUp));
2729-
assert_eq!(Action::n(17), Some(Action::ScrollIntoView));
2730-
assert_eq!(Action::n(18), Some(Action::ScrollToPoint));
2731-
assert_eq!(Action::n(19), Some(Action::SetScrollOffset));
2732-
assert_eq!(Action::n(20), Some(Action::SetTextSelection));
2741+
assert_eq!(Action::n(11), Some(Action::ScrollDown));
2742+
assert_eq!(Action::n(12), Some(Action::ScrollLeft));
2743+
assert_eq!(Action::n(13), Some(Action::ScrollRight));
2744+
assert_eq!(Action::n(14), Some(Action::ScrollUp));
2745+
assert_eq!(Action::n(15), Some(Action::ScrollIntoView));
2746+
assert_eq!(Action::n(16), Some(Action::ScrollToPoint));
2747+
assert_eq!(Action::n(17), Some(Action::SetScrollOffset));
2748+
assert_eq!(Action::n(18), Some(Action::SetTextSelection));
27332749
assert_eq!(
2734-
Action::n(21),
2750+
Action::n(19),
27352751
Some(Action::SetSequentialFocusNavigationStartingPoint)
27362752
);
2737-
assert_eq!(Action::n(22), Some(Action::SetValue));
2738-
assert_eq!(Action::n(23), Some(Action::ShowContextMenu));
2739-
assert_eq!(Action::n(24), None);
2753+
assert_eq!(Action::n(20), Some(Action::SetValue));
2754+
assert_eq!(Action::n(21), Some(Action::ShowContextMenu));
2755+
assert_eq!(Action::n(22), None);
27402756
}
27412757

27422758
#[test]
@@ -2808,9 +2824,7 @@ mod tests {
28082824
assert!(!node.supports_action(Action::HideTooltip));
28092825
assert!(!node.supports_action(Action::ShowTooltip));
28102826
assert!(!node.supports_action(Action::ReplaceSelectedText));
2811-
assert!(!node.supports_action(Action::ScrollBackward));
28122827
assert!(!node.supports_action(Action::ScrollDown));
2813-
assert!(!node.supports_action(Action::ScrollForward));
28142828
assert!(!node.supports_action(Action::ScrollLeft));
28152829
assert!(!node.supports_action(Action::ScrollRight));
28162830
assert!(!node.supports_action(Action::ScrollUp));

0 commit comments

Comments
 (0)