Commit 189cb568 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Use vtbl for binding to event in attach_event.

parent 1e875980
......@@ -2032,7 +2032,7 @@ static HRESULT WINAPI HTMLDocument3_attachEvent(IHTMLDocument3 *iface, BSTR even
TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
return attach_event(&This->doc_node->node.event_target, This, event, pDisp, pfResult);
return attach_event(&This->doc_node->node.event_target, event, pDisp, pfResult);
}
static HRESULT WINAPI HTMLDocument3_detachEvent(IHTMLDocument3 *iface, BSTR event,
......@@ -4571,12 +4571,19 @@ static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
return S_OK;
}
static void HTMLDocumentNode_bind_event(DispatchEx *dispex, int eid)
{
HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
ensure_doc_nsevent_handler(This, eid);
}
static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
NULL,
NULL,
HTMLDocumentNode_invoke,
NULL
NULL,
NULL,
HTMLDocumentNode_bind_event
};
static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
......
......@@ -2566,7 +2566,7 @@ static HRESULT WINAPI HTMLElement2_attachEvent(IHTMLElement2 *iface, BSTR event,
TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
return attach_event(&This->node.event_target, &This->node.doc->basedoc, event, pDisp, pfResult);
return attach_event(&This->node.event_target, event, pDisp, pfResult);
}
static HRESULT WINAPI HTMLElement2_detachEvent(IHTMLElement2 *iface, BSTR event, IDispatch *pDisp)
......@@ -3996,6 +3996,12 @@ static event_target_t **HTMLElement_get_event_target_ptr(DispatchEx *dispex)
: &This->node.event_target.ptr;
}
static void HTMLElement_bind_event(DispatchEx *dispex, int eid)
{
HTMLElement *This = impl_from_DispatchEx(dispex);
This->node.doc->node.event_target.dispex.data->vtbl->bind_event(&This->node.doc->node.event_target.dispex, eid);
}
static const tid_t HTMLElement_iface_tids[] = {
HTMLELEMENT_TIDS,
0
......@@ -4006,7 +4012,8 @@ static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
HTMLElement_get_dispid,
HTMLElement_invoke,
HTMLElement_populate_props,
HTMLElement_get_event_target_ptr
HTMLElement_get_event_target_ptr,
HTMLElement_bind_event
};
static dispex_static_data_t HTMLElement_dispex = {
......
......@@ -1336,7 +1336,7 @@ static BOOL alloc_handler_vector(event_target_t *event_target, eventid_t eid, in
return TRUE;
}
static HRESULT ensure_nsevent_handler(HTMLDocumentNode *doc, eventid_t eid)
HRESULT ensure_doc_nsevent_handler(HTMLDocumentNode *doc, eventid_t eid)
{
nsIDOMNode *nsnode = NULL;
......@@ -1374,6 +1374,13 @@ void detach_events(HTMLDocumentNode *doc)
release_nsevents(doc);
}
static void bind_event(EventTarget *event_target, eventid_t eid)
{
if(event_target->dispex.data->vtbl->bind_event)
event_target->dispex.data->vtbl->bind_event(&event_target->dispex, eid);
else
FIXME("Unsupported event binding on target %p\n", event_target);
}
static void remove_event_handler(EventTarget *event_target, eventid_t eid)
{
......@@ -1410,7 +1417,7 @@ static HRESULT set_event_handler_disp(EventTarget *event_target, HTMLDocumentNod
data->event_table[eid]->handler_prop = disp;
IDispatch_AddRef(disp);
return ensure_nsevent_handler(doc, eid);
return ensure_doc_nsevent_handler(doc, eid);
}
HRESULT set_event_handler(EventTarget *event_target, HTMLDocumentNode *doc, eventid_t eid, VARIANT *var)
......@@ -1478,8 +1485,7 @@ HRESULT get_event_handler(EventTarget *event_target, eventid_t eid, VARIANT *var
return S_OK;
}
HRESULT attach_event(EventTarget *event_target, HTMLDocument *doc, BSTR name,
IDispatch *disp, VARIANT_BOOL *res)
HRESULT attach_event(EventTarget *event_target, BSTR name, IDispatch *disp, VARIANT_BOOL *res)
{
event_target_t *data;
eventid_t eid;
......@@ -1508,8 +1514,10 @@ HRESULT attach_event(EventTarget *event_target, HTMLDocument *doc, BSTR name,
IDispatch_AddRef(disp);
data->event_table[eid]->handlers[i] = disp;
bind_event(event_target, eid);
*res = VARIANT_TRUE;
return ensure_nsevent_handler(doc->doc_node, eid);
return S_OK;
}
HRESULT detach_event(EventTarget *event_target, HTMLDocument *doc, BSTR name, IDispatch *disp)
......@@ -1563,7 +1571,7 @@ void update_doc_cp_events(HTMLDocumentNode *doc, cp_static_data_t *cp)
for(i=0; i < EVENTID_LAST; i++) {
if((event_info[i].flags & EVENT_DEFAULTLISTENER) && is_cp_event(cp, event_info[i].dispid))
ensure_nsevent_handler(doc, i);
ensure_doc_nsevent_handler(doc, i);
}
}
......@@ -1612,7 +1620,7 @@ HRESULT doc_init_events(HTMLDocumentNode *doc)
for(i=0; i < EVENTID_LAST; i++) {
if(event_info[i].flags & EVENT_HASDEFAULTHANDLERS) {
hres = ensure_nsevent_handler(doc, i);
hres = ensure_doc_nsevent_handler(doc, i);
if(FAILED(hres))
return hres;
}
......
......@@ -56,7 +56,7 @@ void release_event_target(event_target_t*) DECLSPEC_HIDDEN;
void fire_event(HTMLDocumentNode*,eventid_t,BOOL,nsIDOMNode*,nsIDOMEvent*,IDispatch*) DECLSPEC_HIDDEN;
HRESULT set_event_handler(EventTarget*,HTMLDocumentNode*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
HRESULT get_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
HRESULT attach_event(EventTarget*,HTMLDocument*,BSTR,IDispatch*,VARIANT_BOOL*) DECLSPEC_HIDDEN;
HRESULT attach_event(EventTarget*,BSTR,IDispatch*,VARIANT_BOOL*) DECLSPEC_HIDDEN;
HRESULT detach_event(EventTarget*,HTMLDocument*,BSTR,IDispatch*) DECLSPEC_HIDDEN;
HRESULT dispatch_event(HTMLDOMNode*,const WCHAR*,VARIANT*,VARIANT_BOOL*) DECLSPEC_HIDDEN;
HRESULT call_fire_event(HTMLDOMNode*,eventid_t) DECLSPEC_HIDDEN;
......@@ -65,6 +65,7 @@ HRESULT doc_init_events(HTMLDocumentNode*) DECLSPEC_HIDDEN;
void detach_events(HTMLDocumentNode *doc) DECLSPEC_HIDDEN;
HRESULT create_event_obj(IHTMLEventObj**) DECLSPEC_HIDDEN;
void bind_target_event(HTMLDocumentNode*,EventTarget*,const WCHAR*,IDispatch*) DECLSPEC_HIDDEN;
HRESULT ensure_doc_nsevent_handler(HTMLDocumentNode*,eventid_t) DECLSPEC_HIDDEN;
void init_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN;
void release_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN;
......
......@@ -1654,7 +1654,7 @@ static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, I
return E_FAIL;
}
return attach_event(&window->event_target, &window->doc->basedoc, event, pDisp, pfResult);
return attach_event(&window->event_target, event, pDisp, pfResult);
}
static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
......@@ -2854,12 +2854,19 @@ static event_target_t **HTMLWindow_get_event_target_ptr(DispatchEx *dispex)
return &This->doc->body_event_target;
}
static void HTMLWindow_bind_event(DispatchEx *dispex, int eid)
{
HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
This->doc->node.event_target.dispex.data->vtbl->bind_event(&This->doc->node.event_target.dispex, eid);
}
static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
NULL,
NULL,
HTMLWindow_invoke,
NULL,
HTMLWindow_get_event_target_ptr
HTMLWindow_get_event_target_ptr,
HTMLWindow_bind_event
};
static const tid_t HTMLWindow_iface_tids[] = {
......
......@@ -232,6 +232,7 @@ typedef struct {
HRESULT (*populate_props)(DispatchEx*);
/* We abuse this vtbl for EventTarget functions to avoid separated vtbl. */
event_target_t **(*get_event_target_ptr)(DispatchEx*);
void (*bind_event)(DispatchEx*,int);
} dispex_static_data_vtbl_t;
typedef struct {
......
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