use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Keyboard {
inner: EventTarget,
}
impl FromVal for Keyboard {
fn from_val(v: &Any) -> Self {
Keyboard {
inner: EventTarget::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for Keyboard {
type Target = EventTarget;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Keyboard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Keyboard {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Keyboard {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Keyboard> for Any {
fn from(s: Keyboard) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Keyboard> for Any {
fn from(s: &Keyboard) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Keyboard);
impl Keyboard {
pub fn onlayoutchange(&self) -> Any {
self.inner.get("onlayoutchange").as_::<Any>()
}
pub fn set_onlayoutchange(&mut self, value: &Any) {
self.inner.set("onlayoutchange", value);
}
}
impl Keyboard {
pub fn lock(&self) -> Promise<Undefined> {
self.inner.call("lock", &[]).as_::<Promise<Undefined>>()
}
}
impl Keyboard {
pub fn lock_with_key_codes(&self, key_codes: &TypedArray<JsString>) -> Promise<Undefined> {
self.inner
.call("lock", &[key_codes.into()])
.as_::<Promise<Undefined>>()
}
}
impl Keyboard {
pub fn unlock(&self) -> Undefined {
self.inner.call("unlock", &[]).as_::<Undefined>()
}
}
impl Keyboard {
pub fn get_layout_map(&self) -> Promise<KeyboardLayoutMap> {
self.inner
.call("getLayoutMap", &[])
.as_::<Promise<KeyboardLayoutMap>>()
}
}