use webcore::value::{Reference, Value};
use webcore::try_from::{TryFrom, TryInto};
pub trait IEvent: AsRef< Reference > + TryFrom< Value > {
fn event_type( &self ) -> String {
js!( return @{self.as_ref()}.type; ).try_into().unwrap()
}
fn prevent_default( &self ) {
js! { @(no_return)
@{self.as_ref()}.preventDefault();
}
}
}
pub trait ConcreteEvent: IEvent {
fn static_event_type() -> &'static str;
}
pub struct Event( Reference );
impl IEvent for Event {}
reference_boilerplate! {
Event,
instanceof Event
}
pub struct ChangeEvent( Reference );
impl IEvent for ChangeEvent {}
impl ConcreteEvent for ChangeEvent {
#[inline]
fn static_event_type() -> &'static str {
"change"
}
}
reference_boilerplate! {
ChangeEvent,
instanceof Event
convertible to Event
}
pub trait IUiEvent: IEvent {
}
pub struct UiEvent( Reference );
impl IEvent for UiEvent {}
impl IUiEvent for UiEvent {}
reference_boilerplate! {
UiEvent,
instanceof UiEvent
convertible to Event
}
pub trait IMouseEvent: IUiEvent {
}
pub struct MouseEvent( Reference );
impl IEvent for MouseEvent {}
impl IUiEvent for MouseEvent {}
impl IMouseEvent for MouseEvent {}
reference_boilerplate! {
MouseEvent,
instanceof MouseEvent
convertible to Event
convertible to UiEvent
}
pub struct ClickEvent( Reference );
impl IEvent for ClickEvent {}
impl IUiEvent for ClickEvent {}
impl IMouseEvent for ClickEvent {}
impl ConcreteEvent for ClickEvent {
#[inline]
fn static_event_type() -> &'static str {
"click"
}
}
reference_boilerplate! {
ClickEvent,
instanceof MouseEvent
convertible to Event
convertible to UiEvent
convertible to MouseEvent
}
pub struct DoubleClickEvent( Reference );
impl IEvent for DoubleClickEvent {}
impl IUiEvent for DoubleClickEvent {}
impl IMouseEvent for DoubleClickEvent {}
impl ConcreteEvent for DoubleClickEvent {
#[inline]
fn static_event_type() -> &'static str {
"dblclick"
}
}
reference_boilerplate! {
DoubleClickEvent,
instanceof MouseEvent
convertible to Event
convertible to UiEvent
convertible to MouseEvent
}
pub trait IKeyboardEvent: IEvent {
fn key( &self ) -> String {
js!( return @{self.as_ref()}.key; ).into_string().unwrap()
}
}
pub struct KeyboardEvent( Reference );
impl IEvent for KeyboardEvent {}
impl IKeyboardEvent for KeyboardEvent {}
reference_boilerplate! {
KeyboardEvent,
instanceof KeyboardEvent
convertible to Event
}
pub struct KeypressEvent( Reference );
impl IEvent for KeypressEvent {}
impl IKeyboardEvent for KeypressEvent {}
impl ConcreteEvent for KeypressEvent {
#[inline]
fn static_event_type() -> &'static str {
"keypress"
}
}
reference_boilerplate! {
KeypressEvent,
instanceof KeyboardEvent
convertible to Event
convertible to KeyboardEvent
}
pub trait IFocusEvent: IEvent {
}
pub struct FocusRelatedEvent( Reference );
impl IEvent for FocusRelatedEvent {}
impl IFocusEvent for FocusRelatedEvent {}
reference_boilerplate! {
FocusRelatedEvent,
instanceof FocusEvent
convertible to Event
}
pub struct FocusEvent( Reference );
impl IEvent for FocusEvent {}
impl IFocusEvent for FocusEvent {}
impl ConcreteEvent for FocusEvent {
#[inline]
fn static_event_type() -> &'static str {
"focus"
}
}
reference_boilerplate! {
FocusEvent,
instanceof FocusEvent
convertible to Event
convertible to FocusRelatedEvent
}
pub struct BlurEvent( Reference );
impl IEvent for BlurEvent {}
impl IFocusEvent for BlurEvent {}
impl ConcreteEvent for BlurEvent {
#[inline]
fn static_event_type() -> &'static str {
"blur"
}
}
reference_boilerplate! {
BlurEvent,
instanceof FocusEvent
convertible to Event
convertible to FocusRelatedEvent
}
pub struct HashChangeEvent( Reference );
impl IEvent for HashChangeEvent {}
impl ConcreteEvent for HashChangeEvent {
#[inline]
fn static_event_type() -> &'static str {
"hashchange"
}
}
reference_boilerplate! {
HashChangeEvent,
instanceof HashChangeEvent
convertible to Event
}