Add cursor grab for web target (#2025)

* Add cursor grab

* Update feature matrix, changelog and platform information

* Add proper error propagation

* Remove "expect" from fallible code

    code would crash if handling pointer capture outside of winit on
    every mouse click

    we swallow the error since we could not think of a case where this
    would fail in a way that would want to handle that it fails

* Remove unnecessary implementation comment

Co-authored-by: Will Crichton <wcrichto@cs.stanford.edu>
This commit is contained in:
TotalKrill 2022-01-05 11:13:46 +01:00 committed by GitHub
parent 25ff30ee8c
commit c5c99d2357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 7 deletions

View file

@ -89,6 +89,20 @@ impl Canvas {
})
}
pub fn set_cursor_grab(&self, grab: bool) -> Result<(), RootOE> {
if grab {
self.raw().request_pointer_lock();
} else {
let window = 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())))?;
document.exit_pointer_lock();
}
Ok(())
}
pub fn set_attribute(&self, attribute: &str, value: &str) {
self.common
.raw