1 module libwasm.bindings.EventTarget;
2 
3 import libwasm.types;
4 
5 import memutils.ct: tuple;
6 import libwasm.bindings.Event;
7 import libwasm.bindings.EventHandler;
8 import libwasm.bindings.EventListener;
9 
10 @safe:
11 nothrow:
12 
13 struct AddEventListenerOptions {
14   nothrow:
15   libwasm.bindings.EventTarget.EventListenerOptions _parent;
16   alias _parent this;
17   this(Handle h) {
18     _parent = .EventListenerOptions(h);
19   }
20   static auto create() {
21     return AddEventListenerOptions(libwasm_add__object());
22   }
23   void passive()(bool passive) {
24     Object_Call_bool__void(this._parent, "passive", passive);
25   }
26   bool passive()() {
27     return Object_Getter__bool(this._parent, "passive");
28   }
29   void once()(bool once) {
30     Object_Call_bool__void(this._parent, "once", once);
31   }
32   bool once()() {
33     return Object_Getter__bool(this._parent, "once");
34   }
35   void wantUntrusted()(bool wantUntrusted) {
36     Object_Call_bool__void(this._parent, "wantUntrusted", wantUntrusted);
37   }
38   bool wantUntrusted()() {
39     return Object_Getter__bool(this._parent, "wantUntrusted");
40   }
41 }
42 struct EventListenerOptions {
43   nothrow:
44   JsHandle handle;
45   alias handle this;
46   this(Handle h) {
47     this.handle = JsHandle(h);
48   }
49   static auto create() {
50     return EventListenerOptions(libwasm_add__object());
51   }
52   void capture()(bool capture) {
53     Object_Call_bool__void(this.handle, "capture", capture);
54   }
55   bool capture()() {
56     return Object_Getter__bool(this.handle, "capture");
57   }
58   void mozSystemGroup()(bool mozSystemGroup) {
59     Object_Call_bool__void(this.handle, "mozSystemGroup", mozSystemGroup);
60   }
61   bool mozSystemGroup()() {
62     return Object_Getter__bool(this.handle, "mozSystemGroup");
63   }
64 }
65 struct EventTarget {
66   nothrow:
67   JsHandle handle;
68   alias handle this;
69   this(Handle h) {
70     this.handle = JsHandle(h);
71   }
72   void addEventListener(T1, T3)(string type, scope auto ref Optional!(T1) listener, scope ref SumType!(AddEventListenerOptions, bool) options, scope auto ref Optional!(T3) wantsUntrusted /* = no!(bool) */) if (isTOrPointer!(T1, EventListener) && isTOrPointer!(T3, bool)) {
73     EventTarget_addEventListener(this.handle, type, !listener.empty, listener.front.handle, options, !wantsUntrusted.empty, wantsUntrusted.front);
74   }
75   void addEventListener(T1)(string type, scope auto ref Optional!(T1) listener, scope ref SumType!(AddEventListenerOptions, bool) options) if (isTOrPointer!(T1, EventListener)) {
76     EventTarget_addEventListener_0(this.handle, type, !listener.empty, listener.front.handle, options);
77   }
78   void addEventListener(T1)(string type, scope auto ref Optional!(T1) listener) if (isTOrPointer!(T1, EventListener)) {
79     EventTarget_addEventListener_1(this.handle, type, !listener.empty, listener.front.handle);
80   }
81   void removeEventListener(T1)(string type, scope auto ref Optional!(T1) listener, scope ref SumType!(EventListenerOptions, bool) options) if (isTOrPointer!(T1, EventListener)) {
82     EventTarget_removeEventListener(this.handle, type, !listener.empty, listener.front.handle, options);
83   }
84   void removeEventListener(T1)(string type, scope auto ref Optional!(T1) listener) if (isTOrPointer!(T1, EventListener)) {
85     EventTarget_removeEventListener_0(this.handle, type, !listener.empty, listener.front.handle);
86   }
87   bool dispatchEvent()(scope ref Event event) {
88     return Serialize_Object_VarArgCall!bool(this.handle, "dispatchEvent", "Handle", tuple(cast(Handle)event.handle));
89   }
90   void setEventHandler(T1)(string type, scope auto ref Optional!(T1) handler) if (isTOrPointer!(T1, EventHandlerNonNull)) {
91     EventTarget_setEventHandler(this.handle, type, !handler.empty, handler.front);
92   }
93   EventHandler getEventHandler()(string type) {
94     return EventTarget_getEventHandler(this.handle, type);
95   }
96   auto ownerGlobal()() {
97     return recastOpt!(WindowProxy)(Object_Getter__OptionalHandle(this.handle, "ownerGlobal"));
98   }
99 }
100 
101 
102 extern (C) void EventTarget_addEventListener(Handle, string, bool, Handle, scope ref SumType!(AddEventListenerOptions, bool), bool, bool);
103 extern (C) void EventTarget_addEventListener_0(Handle, string, bool, Handle, scope ref SumType!(AddEventListenerOptions, bool));
104 extern (C) void EventTarget_addEventListener_1(Handle, string, bool, Handle);
105 extern (C) void EventTarget_removeEventListener(Handle, string, bool, Handle, scope ref SumType!(EventListenerOptions, bool));
106 extern (C) void EventTarget_removeEventListener_0(Handle, string, bool, Handle);
107 extern (C) void EventTarget_setEventHandler(Handle, string, bool, EventHandlerNonNull);
108 extern (C) EventHandler EventTarget_getEventHandler(Handle, string);