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:
Héctor Ramón 2019-08-08 23:51:41 +02:00 committed by Hal Gentz
parent e897d70733
commit dbdde3d781
2 changed files with 18 additions and 17 deletions

View file

@ -49,15 +49,14 @@ impl Canvas {
.try_into()
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?;
document()
.body()
.ok_or_else(|| os_error!(OsError("Failed to find body node".to_owned())))?
.append_child(&canvas);
// TODO: Set up unique ids
// A tabindex is needed in order to capture local keyboard events.
// A "0" value means that the element should be focusable in
// sequential keyboard navigation, but its order is defined by the
// document's source order.
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
canvas
.set_attribute("tabindex", "0")
.expect("Failed to set a tabindex");
.map_err(|_| os_error!(OsError("Failed to set a tabindex".to_owned())))?;
Ok(Canvas {
raw: canvas,