Commit 29389b87 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Added IHTMLElement2::detachEvent implementation.

parent 07b62a8d
......@@ -655,8 +655,10 @@ static HRESULT WINAPI HTMLElement2_attachEvent(IHTMLElement2 *iface, BSTR event,
static HRESULT WINAPI HTMLElement2_detachEvent(IHTMLElement2 *iface, BSTR event, IDispatch *pDisp)
{
HTMLElement *This = HTMLELEM2_THIS(iface);
FIXME("(%p)->(%s %p)\n", This, debugstr_w(event), pDisp);
return E_NOTIMPL;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(event), pDisp);
return detach_event(*get_node_event_target(&This->node), &This->node.doc->basedoc, event, pDisp);
}
static HRESULT WINAPI HTMLElement2_get_readyState(IHTMLElement2 *iface, VARIANT *p)
......
......@@ -867,6 +867,9 @@ static void call_event_handlers(HTMLDocumentNode *doc, IHTMLEventObj *event_obj,
for(cp = cp_container->cp_list; cp; cp = cp->next) {
if(cp->sinks_size && is_cp_event(cp->data, event_info[eid].dispid)) {
for(i=0; i < cp->sinks_size; i++) {
if(!cp->sinks[i].disp)
continue;
TRACE("cp %s [%d] >>>\n", debugstr_w(event_info[eid].name), i);
hres = call_cp_func(cp->sinks[i].disp, event_info[eid].dispid);
if(hres == S_OK)
......@@ -1128,6 +1131,34 @@ HRESULT attach_event(event_target_t **event_target_ptr, HTMLDocument *doc, BSTR
return S_OK;
}
HRESULT detach_event(event_target_t *event_target, HTMLDocument *doc, BSTR name, IDispatch *disp)
{
eventid_t eid;
DWORD i = 0;
if(!event_target)
return S_OK;
eid = attr_to_eid(name);
if(eid == EVENTID_LAST) {
WARN("Unknown event\n");
return S_OK;
}
if(!event_target->event_table[eid])
return S_OK;
while(i < event_target->event_table[eid]->handler_cnt) {
if(event_target->event_table[eid]->handlers[i] == disp) {
IDispatch_Release(event_target->event_table[eid]->handlers[i]);
event_target->event_table[eid]->handlers[i] = NULL;
}
i++;
}
return S_OK;
}
void update_cp_events(HTMLWindow *window, cp_static_data_t *cp)
{
int i;
......
......@@ -46,6 +46,7 @@ void fire_event(HTMLDocumentNode*,eventid_t,nsIDOMNode*,nsIDOMEvent*);
HRESULT set_event_handler(event_target_t**,HTMLDocumentNode*,eventid_t,VARIANT*);
HRESULT get_event_handler(event_target_t**,eventid_t,VARIANT*);
HRESULT attach_event(event_target_t**,HTMLDocument*,BSTR,IDispatch*,VARIANT_BOOL*);
HRESULT detach_event(event_target_t*,HTMLDocument*,BSTR,IDispatch*);
HRESULT dispatch_event(HTMLDOMNode*,const WCHAR*,VARIANT*,VARIANT_BOOL*);
HRESULT call_event(HTMLDOMNode*,eventid_t);
void update_cp_events(HTMLWindow*,cp_static_data_t*);
......
......@@ -675,6 +675,20 @@ static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea,
ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
}
#define elem_detach_event(a,b,c) _elem_detach_event(__LINE__,a,b,c)
static void _elem_detach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
{
IHTMLElement2 *elem = _get_elem2_iface(line, unk);
BSTR name;
HRESULT hres;
name = a2bstr(namea);
hres = IHTMLElement2_detachEvent(elem, name, disp);
IHTMLElement2_Release(elem);
SysFreeString(name);
ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
}
static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
{
*ppv = NULL;
......@@ -1228,6 +1242,29 @@ static void test_onclick(IHTMLDocument2 *doc)
unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
V_VT(&v) = VT_NULL;
hres = IHTMLElement_put_onclick(div, v);
ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
hres = IHTMLElement_get_onclick(div, &v);
ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
ok(V_VT(&v) == VT_NULL, "get_onclick returned vt %d\n", V_VT(&v));
elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
elem_detach_event((IUnknown*)div, "test", (IDispatch*)&div_onclick_disp);
SET_EXPECT(div_onclick_attached);
SET_EXPECT(body_onclick);
SET_EXPECT(document_onclick);
hres = IHTMLElement_click(div);
ok(hres == S_OK, "click failed: %08x\n", hres);
CHECK_CALLED(div_onclick_attached);
CHECK_CALLED(body_onclick);
CHECK_CALLED(document_onclick);
IHTMLElement_Release(div);
IHTMLElement_Release(body);
}
......
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