1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
//! Trait for defining the methods related to the event handlers shared by all
//! HTML elements.

use crate::interfaces::{event_target::EventTarget, html_element::HtmlElementBuilder};
use augdom::event::*;

/// An event which can be handled on any element.
pub trait GlobalEvent: Event + 'static {}

macro_rules! global_events {
    ($($property:ident <- $event:ident,)+) => {

        $(impl GlobalEvent for $event {})+

        /// These event handlers are defined on the [GlobalEventHandlers][mdn] mixin,
        /// and implemented by HTMLElement, Document, Window, as well as by
        /// WorkerGlobalScope for Web Workers.
        ///
        /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
        pub trait GlobalEventHandler:
            HtmlElementBuilder
            $(+ EventTarget<$event>)+
        {$(
            /// Set an event handler.
            fn $property(self, callback: impl FnMut(augdom::event::$event) + 'static) -> Self {
                self.on(callback)
            }
        )+}

    };
}

global_events! {
    onabort              <- Abort,
    onblur               <- Blur,
    oncancel             <- Cancel,
    oncanplay            <- CanPlay,
    oncanplaythrough     <- CanPlayThrough,
    onchange             <- Change,
    onclick              <- Click,
    onclose              <- CloseWebsocket,
    oncontextmenu        <- ContextMenu,
    oncuechange          <- CueChange,
    ondblclick           <- DoubleClick,
    ondrag               <- Drag,
    ondragend            <- DragEnd,
    ondragenter          <- DragEnter,
    ondragexit           <- DragExit,
    ondragleave          <- DragLeave,
    ondragover           <- DragOver,
    ondragstart          <- DragStart,
    ondrop               <- Dropped,
    ondurationchange     <- DurationChange,
    onemptied            <- Emptied,
    onended              <- PlaybackEnded,
    onerror              <- ErrorEvent,
    onfocus              <- Focus,
    ongotpointercapture  <- GotPointerCapture,
    oninput              <- Input,
    oninvalid            <- Invalid,
    onkeydown            <- KeyDown,
    onkeypress           <- KeyPress,
    onkeyup              <- KeyUp,
    onload               <- ResourceLoad,
    onloadeddata         <- DataLoaded,
    onloadedmetadata     <- MetadataLoaded,
    onloadend            <- LoadEnd,
    onloadstart          <- LoadStart,
    onlostpointercapture <- LostPointerCapture,
    onmouseenter         <- MouseEnter,
    onmouseleave         <- MouseLeave,
    onmousemove          <- MouseMove,
    onmouseout           <- MouseOut,
    onmouseover          <- MouseOver,
    onmouseup            <- MouseUp,
    onpause              <- Pause,
    onplay               <- Play,
    onplaying            <- Playing,
    onpointercancel      <- PointerCancel,
    onpointerdown        <- PointerDown,
    onpointerenter       <- PointerEnter,
    onpointerleave       <- PointerLeave,
    onpointermove        <- PointerMove,
    onpointerout         <- PointerOut,
    onpointerover        <- PointerOver,
    onpointerup          <- PointerUp,
    onprogress           <- Progress,
    onratechange         <- PlaybackRateChange,
    onreset              <- FormReset,
    onresize             <- ViewResize,
    onscroll             <- Scroll,
    onseeked             <- Seeked,
    onseeking            <- Seeking,
    onselect             <- Select,
    onselectionchange    <- SelectionChange,
    onselectstart        <- SelectionStart,
    onshow               <- ContextMenuShow,
    onstalled            <- Stalled,
    onsubmit             <- Submit,
    onsuspend            <- Suspend,
    ontimeupdate         <- TimeUpdate,
    onvolumechange       <- VolumeChange,
    onwaiting            <- Waiting,
    onwheel              <- Wheel,
}