Instead of hardcoding it, which will be necessary as the amount of event types implemented grows.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlevent.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/dlls/mshtml/htmlevent.c b/dlls/mshtml/htmlevent.c index f28dd63..c25b85f 100644 --- a/dlls/mshtml/htmlevent.c +++ b/dlls/mshtml/htmlevent.c @@ -2373,6 +2373,26 @@ static BOOL check_event_iface(nsIDOMEvent *event, REFIID riid) return TRUE; }
+static DOMEvent *message_event_ctor(nsIDOMEvent *nsevent, dispex_static_data_t **dispex_data) +{ + DOMMessageEvent *message_event = heap_alloc_zero(sizeof(*message_event)); + if(!message_event) + return NULL; + + message_event->IDOMMessageEvent_iface.lpVtbl = &DOMMessageEventVtbl; + message_event->event.query_interface = DOMMessageEvent_query_interface; + message_event->event.destroy = DOMMessageEvent_destroy; + *dispex_data = &DOMMessageEvent_dispex; + return &message_event->event; +} + +static const struct { + DOMEvent* (*proc)(nsIDOMEvent*,dispex_static_data_t**); + compat_mode_t min_mode; +} event_type_ctors[ARRAY_SIZE(event_types)] = { + [EVENT_TYPE_MESSAGE] = { message_event_ctor, COMPAT_MODE_QUIRKS }, +}; + static DOMEvent *alloc_event(nsIDOMEvent *nsevent, compat_mode_t compat_mode, eventid_t event_id) { dispex_static_data_t *dispex_data = &DOMEvent_dispex; @@ -2389,16 +2409,11 @@ static DOMEvent *alloc_event(nsIDOMEvent *nsevent, compat_mode_t compat_mode, ev custom_event->event.destroy = DOMCustomEvent_destroy; event = &custom_event->event; dispex_data = &DOMCustomEvent_dispex; - }else if(event_id == EVENTID_MESSAGE) { - DOMMessageEvent *message_event = heap_alloc_zero(sizeof(*message_event)); - if(!message_event) + }else if(event_id != EVENTID_LAST && event_type_ctors[event_info[event_id].type].proc && + compat_mode >= event_type_ctors[event_info[event_id].type].min_mode) { + event = event_type_ctors[event_info[event_id].type].proc(nsevent, &dispex_data); + if(!event) return NULL; - - message_event->IDOMMessageEvent_iface.lpVtbl = &DOMMessageEventVtbl; - message_event->event.query_interface = DOMMessageEvent_query_interface; - message_event->event.destroy = DOMMessageEvent_destroy; - event = &message_event->event; - dispex_data = &DOMMessageEvent_dispex; }else { event = heap_alloc_zero(sizeof(*event)); if(!event)