servoshell: Enable accesskit integration. (#37519)

These changes ensure that our browser shell can integrate with
screenreaders. We do not provide any accessibility information about
webview content yet, which requires further API design work in both
Servo, accesskit, and egui.

Testing: No a11y-specific testing at this point; just verifying that
existing tests continue to pass.
Fixes: part of #4344

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-06-24 23:52:49 -04:00 committed by GitHub
parent d114feb0fa
commit ef5784da0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 743 additions and 56 deletions

View file

@ -27,7 +27,7 @@ use winit::event_loop::{ActiveEventLoop, ControlFlow};
use winit::window::WindowId;
use super::app_state::AppState;
use super::events_loop::{EventsLoop, WakerEvent};
use super::events_loop::{AppEvent, EventLoopProxy, EventsLoop};
use super::minibrowser::{Minibrowser, MinibrowserEvent};
use super::{headed_window, headless_window};
use crate::desktop::app_state::RunningAppState;
@ -45,6 +45,7 @@ pub struct App {
suspended: Cell<bool>,
minibrowser: Option<Minibrowser>,
waker: Box<dyn EventLoopWaker>,
proxy: Option<EventLoopProxy>,
initial_url: ServoUrl,
t_start: Instant,
t: Instant,
@ -89,6 +90,7 @@ impl App {
windows: HashMap::new(),
minibrowser: None,
waker: events_loop.create_event_loop_waker(),
proxy: events_loop.event_loop_proxy(),
initial_url: initial_url.clone(),
t_start: t,
t,
@ -103,10 +105,12 @@ impl App {
assert_eq!(headless, event_loop.is_none());
let window = match event_loop {
Some(event_loop) => {
let proxy = self.proxy.take().expect("Must have a proxy available");
let window = headed_window::Window::new(&self.servoshell_preferences, event_loop);
self.minibrowser = Some(Minibrowser::new(
window.offscreen_rendering_context(),
&window,
event_loop,
proxy,
self.initial_url.clone(),
));
Rc::new(window)
@ -238,7 +242,7 @@ impl App {
/// continue.
pub fn handle_events_with_headless(&mut self) -> bool {
let now = Instant::now();
let event = winit::event::Event::UserEvent(WakerEvent);
let event = winit::event::Event::UserEvent(AppEvent::Waker);
trace_winit_event!(
event,
"@{:?} (+{:?}) {event:?}",
@ -360,7 +364,7 @@ impl App {
}
}
impl ApplicationHandler<WakerEvent> for App {
impl ApplicationHandler<AppEvent> for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
self.init(Some(event_loop));
}
@ -468,7 +472,20 @@ impl ApplicationHandler<WakerEvent> for App {
self.handle_events_with_winit(event_loop, window);
}
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: WakerEvent) {
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: AppEvent) {
if let AppEvent::Accessibility(ref event) = event {
let Some(ref mut minibrowser) = self.minibrowser else {
return;
};
if !minibrowser.handle_accesskit_event(&event.window_event) {
return;
}
if let Some(window) = self.windows.get(&event.window_id) {
window.winit_window().unwrap().request_redraw();
}
return;
}
let now = Instant::now();
let event = winit::event::Event::UserEvent(event);
trace_winit_event!(