Commit 519ef7c5 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

mshtml: Use an event mask and list in XMLHttpReqEventListener.

Instead of hardcoding each event, since there will be plenty more. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 5eec1429
...@@ -226,6 +226,11 @@ static eventid_t attr_to_eid(const WCHAR *str) ...@@ -226,6 +226,11 @@ static eventid_t attr_to_eid(const WCHAR *str)
return EVENTID_LAST; return EVENTID_LAST;
} }
const WCHAR *get_event_name(eventid_t eid)
{
return event_info[eid].name;
}
static listener_container_t *get_listener_container(EventTarget *event_target, const WCHAR *type, BOOL alloc) static listener_container_t *get_listener_container(EventTarget *event_target, const WCHAR *type, BOOL alloc)
{ {
const event_target_vtbl_t *vtbl; const event_target_vtbl_t *vtbl;
......
...@@ -93,6 +93,7 @@ typedef struct DOMEvent { ...@@ -93,6 +93,7 @@ typedef struct DOMEvent {
BOOL no_event_obj; BOOL no_event_obj;
} DOMEvent; } DOMEvent;
const WCHAR *get_event_name(eventid_t) DECLSPEC_HIDDEN;
void check_event_attr(HTMLDocumentNode*,nsIDOMElement*) DECLSPEC_HIDDEN; void check_event_attr(HTMLDocumentNode*,nsIDOMElement*) DECLSPEC_HIDDEN;
void release_event_target(EventTarget*) DECLSPEC_HIDDEN; void release_event_target(EventTarget*) DECLSPEC_HIDDEN;
HRESULT set_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN; HRESULT set_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
......
...@@ -94,12 +94,16 @@ static HRESULT return_nscstr(nsresult nsres, nsACString *nscstr, BSTR *p) ...@@ -94,12 +94,16 @@ static HRESULT return_nscstr(nsresult nsres, nsACString *nscstr, BSTR *p)
return S_OK; return S_OK;
} }
static const eventid_t events[] = {
EVENTID_READYSTATECHANGE,
EVENTID_LOAD,
};
typedef struct { typedef struct {
nsIDOMEventListener nsIDOMEventListener_iface; nsIDOMEventListener nsIDOMEventListener_iface;
LONG ref; LONG ref;
HTMLXMLHttpRequest *xhr; HTMLXMLHttpRequest *xhr;
BOOL readystatechange_event; DWORD events_mask;
BOOL load_event;
} XMLHttpReqEventListener; } XMLHttpReqEventListener;
struct HTMLXMLHttpRequest { struct HTMLXMLHttpRequest {
...@@ -115,21 +119,17 @@ struct HTMLXMLHttpRequest { ...@@ -115,21 +119,17 @@ struct HTMLXMLHttpRequest {
static void detach_xhr_event_listener(XMLHttpReqEventListener *event_listener) static void detach_xhr_event_listener(XMLHttpReqEventListener *event_listener)
{ {
nsIDOMEventTarget *event_target; nsIDOMEventTarget *event_target;
DWORD events_mask, i;
nsAString str; nsAString str;
nsresult nsres; nsresult nsres;
nsres = nsIXMLHttpRequest_QueryInterface(event_listener->xhr->nsxhr, &IID_nsIDOMEventTarget, (void**)&event_target); nsres = nsIXMLHttpRequest_QueryInterface(event_listener->xhr->nsxhr, &IID_nsIDOMEventTarget, (void**)&event_target);
assert(nsres == NS_OK); assert(nsres == NS_OK);
if(event_listener->readystatechange_event) { for(events_mask = event_listener->events_mask, i = 0; events_mask; events_mask >>= 1, i++) {
nsAString_InitDepend(&str, L"onreadystatechange"); if(!(events_mask & 1))
nsres = nsIDOMEventTarget_RemoveEventListener(event_target, &str, &event_listener->nsIDOMEventListener_iface, FALSE); continue;
nsAString_Finish(&str); nsAString_InitDepend(&str, get_event_name(events[i]));
assert(nsres == NS_OK);
}
if(event_listener->load_event) {
nsAString_InitDepend(&str, L"load");
nsres = nsIDOMEventTarget_RemoveEventListener(event_target, &str, &event_listener->nsIDOMEventListener_iface, FALSE); nsres = nsIDOMEventTarget_RemoveEventListener(event_target, &str, &event_listener->nsIDOMEventListener_iface, FALSE);
nsAString_Finish(&str); nsAString_Finish(&str);
assert(nsres == NS_OK); assert(nsres == NS_OK);
...@@ -941,22 +941,18 @@ static void HTMLXMLHttpRequest_bind_event(DispatchEx *dispex, eventid_t eid) ...@@ -941,22 +941,18 @@ static void HTMLXMLHttpRequest_bind_event(DispatchEx *dispex, eventid_t eid)
{ {
HTMLXMLHttpRequest *This = impl_from_DispatchEx(dispex); HTMLXMLHttpRequest *This = impl_from_DispatchEx(dispex);
nsIDOMEventTarget *nstarget; nsIDOMEventTarget *nstarget;
const WCHAR *type_name;
nsAString type_str; nsAString type_str;
const WCHAR *name;
nsresult nsres; nsresult nsres;
unsigned i;
TRACE("(%p)\n", This); TRACE("(%p)\n", This);
switch(eid) { for(i = 0; i < ARRAY_SIZE(events); i++)
case EVENTID_READYSTATECHANGE: if(eid == events[i])
type_name = L"readystatechange"; break;
break; if(i >= ARRAY_SIZE(events))
case EVENTID_LOAD:
type_name = L"load";
break;
default:
return; return;
}
if(!This->event_listener) { if(!This->event_listener) {
This->event_listener = heap_alloc(sizeof(*This->event_listener)); This->event_listener = heap_alloc(sizeof(*This->event_listener));
...@@ -966,25 +962,22 @@ static void HTMLXMLHttpRequest_bind_event(DispatchEx *dispex, eventid_t eid) ...@@ -966,25 +962,22 @@ static void HTMLXMLHttpRequest_bind_event(DispatchEx *dispex, eventid_t eid)
This->event_listener->nsIDOMEventListener_iface.lpVtbl = &XMLHttpReqEventListenerVtbl; This->event_listener->nsIDOMEventListener_iface.lpVtbl = &XMLHttpReqEventListenerVtbl;
This->event_listener->ref = 1; This->event_listener->ref = 1;
This->event_listener->xhr = This; This->event_listener->xhr = This;
This->event_listener->readystatechange_event = FALSE; This->event_listener->events_mask = 0;
This->event_listener->load_event = FALSE;
} }
nsres = nsIXMLHttpRequest_QueryInterface(This->nsxhr, &IID_nsIDOMEventTarget, (void**)&nstarget); nsres = nsIXMLHttpRequest_QueryInterface(This->nsxhr, &IID_nsIDOMEventTarget, (void**)&nstarget);
assert(nsres == NS_OK); assert(nsres == NS_OK);
nsAString_InitDepend(&type_str, type_name); name = get_event_name(events[i]);
nsAString_InitDepend(&type_str, name);
nsres = nsIDOMEventTarget_AddEventListener(nstarget, &type_str, &This->event_listener->nsIDOMEventListener_iface, FALSE, TRUE, 2); nsres = nsIDOMEventTarget_AddEventListener(nstarget, &type_str, &This->event_listener->nsIDOMEventListener_iface, FALSE, TRUE, 2);
nsAString_Finish(&type_str); nsAString_Finish(&type_str);
if(NS_FAILED(nsres)) if(NS_FAILED(nsres))
ERR("AddEventListener(%s) failed: %08lx\n", debugstr_w(type_name), nsres); ERR("AddEventListener(%s) failed: %08lx\n", debugstr_w(name), nsres);
nsIDOMEventTarget_Release(nstarget); nsIDOMEventTarget_Release(nstarget);
if(eid == EVENTID_READYSTATECHANGE) This->event_listener->events_mask |= 1 << i;
This->event_listener->readystatechange_event = TRUE;
else
This->event_listener->load_event = TRUE;
} }
static void HTMLXMLHttpRequest_init_dispex_info(dispex_data_t *info, compat_mode_t compat_mode) static void HTMLXMLHttpRequest_init_dispex_info(dispex_data_t *info, compat_mode_t compat_mode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment