use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct InputEvent {
inner: UIEvent,
}
impl FromVal for InputEvent {
fn from_val(v: &Any) -> Self {
InputEvent {
inner: UIEvent::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 InputEvent {
type Target = UIEvent;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for InputEvent {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for InputEvent {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for InputEvent {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<InputEvent> for Any {
fn from(s: InputEvent) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&InputEvent> for Any {
fn from(s: &InputEvent) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(InputEvent);
impl InputEvent {
pub fn data(&self) -> JsString {
self.inner.get("data").as_::<JsString>()
}
}
impl InputEvent {
pub fn is_composing(&self) -> bool {
self.inner.get("isComposing").as_::<bool>()
}
}
impl InputEvent {
pub fn input_type(&self) -> JsString {
self.inner.get("inputType").as_::<JsString>()
}
}
impl InputEvent {
pub fn data_transfer(&self) -> DataTransfer {
self.inner.get("dataTransfer").as_::<DataTransfer>()
}
}
impl InputEvent {
pub fn new(type_: &JsString) -> InputEvent {
Self {
inner: Any::global("InputEvent")
.new(&[type_.into()])
.as_::<UIEvent>(),
}
}
}
impl InputEvent {
pub fn new_with_event_init_dict(
type_: &JsString,
event_init_dict: &InputEventInit,
) -> InputEvent {
Self {
inner: Any::global("InputEvent")
.new(&[type_.into(), event_init_dict.into()])
.as_::<UIEvent>(),
}
}
}
impl InputEvent {
pub fn get_target_ranges(&self) -> TypedArray<StaticRange> {
self.inner
.call("getTargetRanges", &[])
.as_::<TypedArray<StaticRange>>()
}
}