mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
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:
parent
d114feb0fa
commit
ef5784da0d
9 changed files with 743 additions and 56 deletions
|
@ -16,15 +16,26 @@ use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
|
|||
|
||||
use super::app::App;
|
||||
|
||||
/// Another process or thread has kicked the OS event loop with EventLoopWaker.
|
||||
pub type EventLoopProxy = winit::event_loop::EventLoopProxy<AppEvent>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WakerEvent;
|
||||
pub enum AppEvent {
|
||||
/// Another process or thread has kicked the OS event loop with EventLoopWaker.
|
||||
Waker,
|
||||
Accessibility(accesskit_winit::Event),
|
||||
}
|
||||
|
||||
impl From<accesskit_winit::Event> for AppEvent {
|
||||
fn from(event: accesskit_winit::Event) -> AppEvent {
|
||||
AppEvent::Accessibility(event)
|
||||
}
|
||||
}
|
||||
|
||||
/// The real or fake OS event loop.
|
||||
#[allow(dead_code)]
|
||||
enum EventLoop {
|
||||
/// A real Winit windowing event loop.
|
||||
Winit(Option<winit::event_loop::EventLoop<WakerEvent>>),
|
||||
Winit(winit::event_loop::EventLoop<AppEvent>),
|
||||
/// A fake event loop which contains a signalling flag used to ensure
|
||||
/// that pending events get processed in a timely fashion, and a condition
|
||||
/// variable to allow waiting on that flag changing state.
|
||||
|
@ -38,16 +49,16 @@ impl EventsLoop {
|
|||
// but on Linux, the event loop requires a X11 server.
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
pub fn new(_headless: bool, _has_output_file: bool) -> Result<EventsLoop, EventLoopError> {
|
||||
Ok(EventsLoop(EventLoop::Winit(Some(
|
||||
Ok(EventsLoop(EventLoop::Winit(
|
||||
WinitEventLoop::with_user_event().build()?,
|
||||
))))
|
||||
)))
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn new(headless: bool, _has_output_file: bool) -> Result<EventsLoop, EventLoopError> {
|
||||
Ok(EventsLoop(if headless {
|
||||
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
|
||||
} else {
|
||||
EventLoop::Winit(Some(WinitEventLoop::with_user_event().build()?))
|
||||
EventLoop::Winit(WinitEventLoop::with_user_event().build()?)
|
||||
}))
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
|
@ -61,20 +72,22 @@ impl EventsLoop {
|
|||
// when generating an output file.
|
||||
event_loop_builder.with_activation_policy(ActivationPolicy::Prohibited);
|
||||
}
|
||||
EventLoop::Winit(Some(event_loop_builder.build()?))
|
||||
EventLoop::Winit(event_loop_builder.build()?)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl EventsLoop {
|
||||
pub(crate) fn event_loop_proxy(&self) -> Option<EventLoopProxy> {
|
||||
match self.0 {
|
||||
EventLoop::Winit(ref events_loop) => Some(events_loop.create_proxy()),
|
||||
EventLoop::Headless(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_event_loop_waker(&self) -> Box<dyn EventLoopWaker> {
|
||||
match self.0 {
|
||||
EventLoop::Winit(ref events_loop) => {
|
||||
let events_loop = events_loop
|
||||
.as_ref()
|
||||
.expect("Can't create waker for unavailable event loop.");
|
||||
Box::new(HeadedEventLoopWaker::new(events_loop))
|
||||
},
|
||||
EventLoop::Winit(ref events_loop) => Box::new(HeadedEventLoopWaker::new(events_loop)),
|
||||
EventLoop::Headless(ref data) => Box::new(HeadlessEventLoopWaker(data.clone())),
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +95,6 @@ impl EventsLoop {
|
|||
pub fn run_app(self, app: &mut App) {
|
||||
match self.0 {
|
||||
EventLoop::Winit(events_loop) => {
|
||||
let events_loop = events_loop.expect("Can't run an unavailable event loop.");
|
||||
events_loop
|
||||
.run_app(app)
|
||||
.expect("Failed while running events loop");
|
||||
|
@ -121,10 +133,10 @@ impl EventsLoop {
|
|||
}
|
||||
|
||||
struct HeadedEventLoopWaker {
|
||||
proxy: Arc<Mutex<winit::event_loop::EventLoopProxy<WakerEvent>>>,
|
||||
proxy: Arc<Mutex<winit::event_loop::EventLoopProxy<AppEvent>>>,
|
||||
}
|
||||
impl HeadedEventLoopWaker {
|
||||
fn new(events_loop: &winit::event_loop::EventLoop<WakerEvent>) -> HeadedEventLoopWaker {
|
||||
fn new(events_loop: &winit::event_loop::EventLoop<AppEvent>) -> HeadedEventLoopWaker {
|
||||
let proxy = Arc::new(Mutex::new(events_loop.create_proxy()));
|
||||
HeadedEventLoopWaker { proxy }
|
||||
}
|
||||
|
@ -132,7 +144,7 @@ impl HeadedEventLoopWaker {
|
|||
impl EventLoopWaker for HeadedEventLoopWaker {
|
||||
fn wake(&self) {
|
||||
// Kick the OS event loop awake.
|
||||
if let Err(err) = self.proxy.lock().unwrap().send_event(WakerEvent) {
|
||||
if let Err(err) = self.proxy.lock().unwrap().send_event(AppEvent::Waker) {
|
||||
warn!("Failed to wake up event loop ({}).", err);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue