Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions platforms/android/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ fn enqueue_focus_event_if_applicable(
struct AdapterChangeHandler<'a> {
events: &'a mut Vec<QueuedEvent>,
node_id_map: &'a mut NodeIdMap,
accessibility_focus: Option<jint>,
enqueued_window_content_changed: bool,
}

impl<'a> AdapterChangeHandler<'a> {
fn new(events: &'a mut Vec<QueuedEvent>, node_id_map: &'a mut NodeIdMap) -> Self {
fn new(
events: &'a mut Vec<QueuedEvent>,
node_id_map: &'a mut NodeIdMap,
accessibility_focus: Option<jint>,
) -> Self {
Self {
events,
node_id_map,
accessibility_focus,
enqueued_window_content_changed: false,
}
}
Expand Down Expand Up @@ -142,6 +148,28 @@ impl TreeChangeHandler for AdapterChangeHandler<'_> {
y: scroll_y,
});
}
if old_node.numeric_value() != new_node.numeric_value() && new_node.data().value().is_none()
{
if let (Some(current), Some(min), Some(max)) = (
new_node.numeric_value(),
new_node.min_numeric_value(),
new_node.max_numeric_value(),
) {
let id = self.node_id_map.get_or_create_java_id(new_node);
let event_type = if self.accessibility_focus == Some(id) {
EVENT_VIEW_SELECTED
} else {
EVENT_VIEW_SCROLLED
};
self.events.push(QueuedEvent::RangeValueChanged {
virtual_view_id: id,
event_type,
current,
min,
max,
});
}
}
// TODO: other events
}

Expand Down Expand Up @@ -205,10 +233,11 @@ impl State {
fn update_tree(
events: &mut Vec<QueuedEvent>,
node_id_map: &mut NodeIdMap,
accessibility_focus: Option<jint>,
tree: &mut Tree,
update: TreeUpdate,
) {
let mut handler = AdapterChangeHandler::new(events, node_id_map);
let mut handler = AdapterChangeHandler::new(events, node_id_map, accessibility_focus);
tree.update_and_process_changes(update, &mut handler);
}

Expand Down Expand Up @@ -261,7 +290,13 @@ impl Adapter {
}
State::Active(tree) => {
let mut events = Vec::new();
update_tree(&mut events, &mut self.node_id_map, tree, update_factory());
update_tree(
&mut events,
&mut self.node_id_map,
self.accessibility_focus,
tree,
update_factory(),
);
Some(QueuedEvents(events))
}
}
Expand Down Expand Up @@ -518,7 +553,13 @@ impl Adapter {
tree_id,
focus: focus_id,
};
update_tree(events, &mut self.node_id_map, tree, update);
update_tree(
events,
&mut self.node_id_map,
self.accessibility_focus,
tree,
update,
);
let request = ActionRequest {
action: Action::SetTextSelection,
target_tree: tree_id,
Expand Down
46 changes: 46 additions & 0 deletions platforms/android/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ pub(crate) struct ScrollDimension {
pub(crate) max: Option<jint>,
}

fn send_range_value_changed(
env: &mut JNIEnv,
host: &JObject,
virtual_view_id: jint,
event_type: jint,
current: f64,
min: f64,
max: f64,
) {
let event = new_event(env, host, virtual_view_id, event_type);
let item_index = if max > min && current >= min && current <= max {
((current - min) * 100.0 / (max - min)) as jint
} else {
0
};
env.call_method(&event, "setItemCount", "(I)V", &[100i32.into()])
.unwrap();
env.call_method(&event, "setCurrentItemIndex", "(I)V", &[item_index.into()])
.unwrap();
send_completed_event(env, host, event);
}

fn send_scrolled(
env: &mut JNIEnv,
host: &JObject,
Expand Down Expand Up @@ -297,6 +319,13 @@ pub(crate) enum QueuedEvent {
x: Option<ScrollDimension>,
y: Option<ScrollDimension>,
},
RangeValueChanged {
virtual_view_id: jint,
event_type: jint,
current: f64,
min: f64,
max: f64,
},
InvalidateHost,
}

Expand Down Expand Up @@ -365,6 +394,23 @@ impl QueuedEvents {
} => {
send_scrolled(env, host, virtual_view_id, x, y);
}
QueuedEvent::RangeValueChanged {
virtual_view_id,
event_type,
current,
min,
max,
} => {
send_range_value_changed(
env,
host,
virtual_view_id,
event_type,
current,
min,
max,
);
}
QueuedEvent::InvalidateHost => {
env.call_method(host, "invalidate", "()V", &[]).unwrap();
}
Expand Down
34 changes: 34 additions & 0 deletions platforms/android/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,40 @@ impl NodeWrapper<'_> {
add_action(env, node_info, ACTION_SCROLL_FORWARD);
}

if self.0.data().value().is_none() {
if let (Some(current), Some(min), Some(max)) = (
self.0.numeric_value(),
self.0.min_numeric_value(),
self.0.max_numeric_value(),
) {
let range_info_class = env
.find_class("android/view/accessibility/AccessibilityNodeInfo$RangeInfo")
.unwrap();
let range_info = env
.call_static_method(
&range_info_class,
"obtain",
"(IFFF)Landroid/view/accessibility/AccessibilityNodeInfo$RangeInfo;",
&[
RANGE_TYPE_FLOAT.into(),
(min as f32).into(),
(max as f32).into(),
(current as f32).into(),
],
)
.unwrap()
.l()
.unwrap();
env.call_method(
node_info,
"setRangeInfo",
"(Landroid/view/accessibility/AccessibilityNodeInfo$RangeInfo;)V",
&[(&range_info).into()],
)
.unwrap();
}
}

let live = match self.0.live() {
Live::Off => LIVE_REGION_NONE,
Live::Polite => LIVE_REGION_POLITE,
Expand Down
3 changes: 3 additions & 0 deletions platforms/android/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) const ACTION_ARGUMENT_SELECTION_END_INT: &str = "ACTION_ARGUMENT_SELE
pub(crate) const CONTENT_CHANGE_TYPE_SUBTREE: jint = 1 << 0;

pub(crate) const EVENT_VIEW_CLICKED: jint = 1;
pub(crate) const EVENT_VIEW_SELECTED: jint = 1 << 2;
pub(crate) const EVENT_VIEW_FOCUSED: jint = 1 << 3;
pub(crate) const EVENT_VIEW_TEXT_CHANGED: jint = 1 << 4;
pub(crate) const EVENT_VIEW_HOVER_ENTER: jint = 1 << 7;
Expand Down Expand Up @@ -56,6 +57,8 @@ pub(crate) const MOVEMENT_GRANULARITY_WORD: jint = 1 << 1;
pub(crate) const MOVEMENT_GRANULARITY_LINE: jint = 1 << 2;
pub(crate) const MOVEMENT_GRANULARITY_PARAGRAPH: jint = 1 << 3;

pub(crate) const RANGE_TYPE_FLOAT: jint = 1;

#[derive(Debug, Default)]
pub(crate) struct NodeIdMap {
java_to_accesskit: HashMap<jint, NodeId>,
Expand Down