mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
Stop appending canvas to document in web platform (#1089)
* Stop appending canvas to document in web platform * Remove `tabindex` TODO in web backend * Return `OsError` instead of panicking on web canvas creation
This commit is contained in:
parent
e897d70733
commit
dbdde3d781
|
@ -49,15 +49,14 @@ impl Canvas {
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?;
|
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?;
|
||||||
|
|
||||||
document()
|
// A tabindex is needed in order to capture local keyboard events.
|
||||||
.body()
|
// A "0" value means that the element should be focusable in
|
||||||
.ok_or_else(|| os_error!(OsError("Failed to find body node".to_owned())))?
|
// sequential keyboard navigation, but its order is defined by the
|
||||||
.append_child(&canvas);
|
// document's source order.
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
|
||||||
// TODO: Set up unique ids
|
|
||||||
canvas
|
canvas
|
||||||
.set_attribute("tabindex", "0")
|
.set_attribute("tabindex", "0")
|
||||||
.expect("Failed to set a tabindex");
|
.map_err(|_| os_error!(OsError("Failed to set a tabindex".to_owned())))?;
|
||||||
|
|
||||||
Ok(Canvas {
|
Ok(Canvas {
|
||||||
raw: canvas,
|
raw: canvas,
|
||||||
|
|
|
@ -34,24 +34,26 @@ impl Canvas {
|
||||||
where
|
where
|
||||||
F: 'static + Fn(),
|
F: 'static + Fn(),
|
||||||
{
|
{
|
||||||
let window = web_sys::window().expect("Failed to obtain window");
|
let window =
|
||||||
let document = window.document().expect("Failed to obtain document");
|
web_sys::window().ok_or(os_error!(OsError("Failed to obtain window".to_owned())))?;
|
||||||
|
|
||||||
|
let document = window
|
||||||
|
.document()
|
||||||
|
.ok_or(os_error!(OsError("Failed to obtain document".to_owned())))?;
|
||||||
|
|
||||||
let canvas: HtmlCanvasElement = document
|
let canvas: HtmlCanvasElement = document
|
||||||
.create_element("canvas")
|
.create_element("canvas")
|
||||||
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?
|
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?
|
||||||
.unchecked_into();
|
.unchecked_into();
|
||||||
|
|
||||||
document
|
// A tabindex is needed in order to capture local keyboard events.
|
||||||
.body()
|
// A "0" value means that the element should be focusable in
|
||||||
.ok_or_else(|| os_error!(OsError("Failed to find body node".to_owned())))?
|
// sequential keyboard navigation, but its order is defined by the
|
||||||
.append_child(&canvas)
|
// document's source order.
|
||||||
.map_err(|_| os_error!(OsError("Failed to append canvas".to_owned())))?;
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
|
||||||
|
|
||||||
// TODO: Set up unique ids
|
|
||||||
canvas
|
canvas
|
||||||
.set_attribute("tabindex", "0")
|
.set_attribute("tabindex", "0")
|
||||||
.expect("Failed to set a tabindex");
|
.map_err(|_| os_error!(OsError("Failed to set a tabindex".to_owned())))?;
|
||||||
|
|
||||||
Ok(Canvas {
|
Ok(Canvas {
|
||||||
raw: canvas,
|
raw: canvas,
|
||||||
|
|
Loading…
Reference in a new issue