mshtml: Added element keydown, mouseup and mousedown event implementation.
[wine] / dlls / mshtml / htmlevent.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "mshtml_private.h"
29 #include "htmlevent.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 struct event_target_t {
36     IDispatch *event_table[EVENTID_LAST];
37 };
38
39 static const WCHAR blurW[] = {'b','l','u','r',0};
40 static const WCHAR onblurW[] = {'o','n','b','l','u','r',0};
41
42 static const WCHAR changeW[] = {'c','h','a','n','g','e',0};
43 static const WCHAR onchangeW[] = {'o','n','c','h','a','n','g','e',0};
44
45 static const WCHAR clickW[] = {'c','l','i','c','k',0};
46 static const WCHAR onclickW[] = {'o','n','c','l','i','c','k',0};
47
48 static const WCHAR dragW[] = {'d','r','a','g',0};
49 static const WCHAR ondragW[] = {'o','n','d','r','a','g',0};
50
51 static const WCHAR focusW[] = {'f','o','c','u','s',0};
52 static const WCHAR onfocusW[] = {'o','n','f','o','c','u','s',0};
53
54 static const WCHAR keydownW[] = {'k','e','y','d','o','w','n',0};
55 static const WCHAR onkeydownW[] = {'o','n','k','e','y','d','o','w','n',0};
56
57 static const WCHAR keyupW[] = {'k','e','y','u','p',0};
58 static const WCHAR onkeyupW[] = {'o','n','k','e','y','u','p',0};
59
60 static const WCHAR loadW[] = {'l','o','a','d',0};
61 static const WCHAR onloadW[] = {'o','n','l','o','a','d',0};
62
63 static const WCHAR mousedownW[] = {'m','o','u','s','e','d','o','w','n',0};
64 static const WCHAR onmousedownW[] = {'o','n','m','o','u','s','e','d','o','w','n',0};
65
66 static const WCHAR mouseoverW[] = {'m','o','u','s','e','o','v','e','r',0};
67 static const WCHAR onmouseoverW[] = {'o','n','m','o','u','s','e','o','v','e','r',0};
68
69 static const WCHAR mouseupW[] = {'m','o','u','s','e','u','p',0};
70 static const WCHAR onmouseupW[] = {'o','n','m','o','u','s','e','u','p',0};
71
72 static const WCHAR pasteW[] = {'p','a','s','t','e',0};
73 static const WCHAR onpasteW[] = {'o','n','p','a','s','t','e',0};
74
75 typedef struct {
76     LPCWSTR name;
77     LPCWSTR attr_name;
78     DWORD flags;
79 } event_info_t;
80
81 #define EVENT_DEFAULTLISTENER    0x0001
82 #define EVENT_BUBBLE             0x0002
83
84 static const event_info_t event_info[] = {
85     {blurW,         onblurW,         EVENT_DEFAULTLISTENER},
86     {changeW,       onchangeW,       EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
87     {clickW,        onclickW,        EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
88     {dragW,         ondragW,         0},
89     {focusW,        onfocusW,        EVENT_DEFAULTLISTENER},
90     {keydownW,      onkeydownW,      EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
91     {keyupW,        onkeyupW,        EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
92     {loadW,         onloadW,         0},
93     {mousedownW,    onmousedownW,    EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
94     {mouseoverW,    onmouseoverW,    EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
95     {mouseupW,      onmouseupW,      EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
96     {pasteW,        onpasteW,        0}
97 };
98
99 eventid_t str_to_eid(LPCWSTR str)
100 {
101     int i;
102
103     for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
104         if(!strcmpW(event_info[i].name, str))
105             return i;
106     }
107
108     ERR("unknown type %s\n", debugstr_w(str));
109     return EVENTID_LAST;
110 }
111
112 typedef struct {
113     DispatchEx dispex;
114     const IHTMLEventObjVtbl  *lpIHTMLEventObjVtbl;
115
116     LONG ref;
117
118     HTMLDOMNode *target;
119 } HTMLEventObj;
120
121 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
122
123 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
124
125 static HRESULT WINAPI HTMLEventObj_QueryInterface(IHTMLEventObj *iface, REFIID riid, void **ppv)
126 {
127     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
128
129     *ppv = NULL;
130
131     if(IsEqualGUID(&IID_IUnknown, riid)) {
132         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
133         *ppv = HTMLEVENTOBJ(This);
134     }else if(IsEqualGUID(&IID_IHTMLEventObj, riid)) {
135         TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This, ppv);
136         *ppv = HTMLEVENTOBJ(This);
137     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
138         return *ppv ? S_OK : E_NOINTERFACE;
139     }
140
141     if(*ppv) {
142         IUnknown_AddRef((IUnknown*)*ppv);
143         return S_OK;
144     }
145
146     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
147     return E_NOINTERFACE;
148 }
149
150 static ULONG WINAPI HTMLEventObj_AddRef(IHTMLEventObj *iface)
151 {
152     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
153     LONG ref = InterlockedIncrement(&This->ref);
154
155     TRACE("(%p) ref=%d\n", This, ref);
156
157     return ref;
158 }
159
160 static ULONG WINAPI HTMLEventObj_Release(IHTMLEventObj *iface)
161 {
162     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
163     LONG ref = InterlockedDecrement(&This->ref);
164
165     TRACE("(%p) ref=%d\n", This, ref);
166
167     if(!ref)
168         heap_free(This);
169
170     return ref;
171 }
172
173 static HRESULT WINAPI HTMLEventObj_GetTypeInfoCount(IHTMLEventObj *iface, UINT *pctinfo)
174 {
175     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
176     FIXME("(%p)->(%p)\n", This, pctinfo);
177     return E_NOTIMPL;
178 }
179
180 static HRESULT WINAPI HTMLEventObj_GetTypeInfo(IHTMLEventObj *iface, UINT iTInfo,
181                                               LCID lcid, ITypeInfo **ppTInfo)
182 {
183     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
184     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
185     return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI HTMLEventObj_GetIDsOfNames(IHTMLEventObj *iface, REFIID riid,
189                                                 LPOLESTR *rgszNames, UINT cNames,
190                                                 LCID lcid, DISPID *rgDispId)
191 {
192     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
193     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
194           lcid, rgDispId);
195     return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI HTMLEventObj_Invoke(IHTMLEventObj *iface, DISPID dispIdMember,
199                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
200                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
201 {
202     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
203     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
204           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
205     return E_NOTIMPL;
206 }
207
208 static HRESULT WINAPI HTMLEventObj_get_srcElement(IHTMLEventObj *iface, IHTMLElement **p)
209 {
210     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
211
212     TRACE("(%p)->(%p)\n", This, p);
213
214     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This->target), &IID_IHTMLElement, (void**)p);
215 }
216
217 static HRESULT WINAPI HTMLEventObj_get_altKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
218 {
219     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
220     FIXME("(%p)->(%p)\n", This, p);
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI HTMLEventObj_get_ctrlKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
225 {
226     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
227     FIXME("(%p)->(%p)\n", This, p);
228     return E_NOTIMPL;
229 }
230
231 static HRESULT WINAPI HTMLEventObj_get_shiftKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
232 {
233     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
234     FIXME("(%p)->(%p)\n", This, p);
235     return E_NOTIMPL;
236 }
237
238 static HRESULT WINAPI HTMLEventObj_put_returnValue(IHTMLEventObj *iface, VARIANT v)
239 {
240     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
241     FIXME("(%p)->()\n", This);
242     return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI HTMLEventObj_get_returnValue(IHTMLEventObj *iface, VARIANT *p)
246 {
247     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
248     FIXME("(%p)->(%p)\n", This, p);
249     return E_NOTIMPL;
250 }
251
252 static HRESULT WINAPI HTMLEventObj_put_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL v)
253 {
254     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
255     FIXME("(%p)->(%x)\n", This, v);
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI HTMLEventObj_get_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL *p)
260 {
261     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
262     FIXME("(%p)->(%p)\n", This, p);
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI HTMLEventObj_get_fromElement(IHTMLEventObj *iface, IHTMLElement **p)
267 {
268     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
269     FIXME("(%p)->(%p)\n", This, p);
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI HTMLEventObj_get_toElement(IHTMLEventObj *iface, IHTMLElement **p)
274 {
275     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
276     FIXME("(%p)->(%p)\n", This, p);
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI HTMLEventObj_put_keyCode(IHTMLEventObj *iface, long v)
281 {
282     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
283     FIXME("(%p)->(%ld)\n", This, v);
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI HTMLEventObj_get_keyCode(IHTMLEventObj *iface, long *p)
288 {
289     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
290     FIXME("(%p)->(%p)\n", This, p);
291     return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI HTMLEventObj_get_button(IHTMLEventObj *iface, long *p)
295 {
296     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
297     FIXME("(%p)->(%p)\n", This, p);
298     return E_NOTIMPL;
299 }
300
301 static HRESULT WINAPI HTMLEventObj_get_type(IHTMLEventObj *iface, BSTR *p)
302 {
303     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
304     FIXME("(%p)->(%p)\n", This, p);
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI HTMLEventObj_get_qualifier(IHTMLEventObj *iface, BSTR *p)
309 {
310     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
311     FIXME("(%p)->(%p)\n", This, p);
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI HTMLEventObj_get_reason(IHTMLEventObj *iface, long *p)
316 {
317     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
318     FIXME("(%p)->(%p)\n", This, p);
319     return E_NOTIMPL;
320 }
321
322 static HRESULT WINAPI HTMLEventObj_get_x(IHTMLEventObj *iface, long *p)
323 {
324     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
325     FIXME("(%p)->(%p)\n", This, p);
326     return E_NOTIMPL;
327 }
328
329 static HRESULT WINAPI HTMLEventObj_get_y(IHTMLEventObj *iface, long *p)
330 {
331     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
332     FIXME("(%p)->(%p)\n", This, p);
333     return E_NOTIMPL;
334 }
335
336 static HRESULT WINAPI HTMLEventObj_get_clientX(IHTMLEventObj *iface, long *p)
337 {
338     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
339     FIXME("(%p)->(%p)\n", This, p);
340     return E_NOTIMPL;
341 }
342
343 static HRESULT WINAPI HTMLEventObj_get_clientY(IHTMLEventObj *iface, long *p)
344 {
345     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
346     FIXME("(%p)->(%p)\n", This, p);
347     return E_NOTIMPL;
348 }
349
350 static HRESULT WINAPI HTMLEventObj_get_offsetX(IHTMLEventObj *iface, long *p)
351 {
352     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
353     FIXME("(%p)->(%p)\n", This, p);
354     return E_NOTIMPL;
355 }
356
357 static HRESULT WINAPI HTMLEventObj_get_offsetY(IHTMLEventObj *iface, long *p)
358 {
359     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
360     FIXME("(%p)->(%p)\n", This, p);
361     return E_NOTIMPL;
362 }
363
364 static HRESULT WINAPI HTMLEventObj_get_screenX(IHTMLEventObj *iface, long *p)
365 {
366     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
367     FIXME("(%p)->(%p)\n", This, p);
368     return E_NOTIMPL;
369 }
370
371 static HRESULT WINAPI HTMLEventObj_get_screenY(IHTMLEventObj *iface, long *p)
372 {
373     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
374     FIXME("(%p)->(%p)\n", This, p);
375     return E_NOTIMPL;
376 }
377
378 static HRESULT WINAPI HTMLEventObj_get_srcFilter(IHTMLEventObj *iface, IDispatch **p)
379 {
380     HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
381     FIXME("(%p)->(%p)\n", This, p);
382     return E_NOTIMPL;
383 }
384
385 #undef HTMLEVENTOBJ_THIS
386
387 static const IHTMLEventObjVtbl HTMLEventObjVtbl = {
388     HTMLEventObj_QueryInterface,
389     HTMLEventObj_AddRef,
390     HTMLEventObj_Release,
391     HTMLEventObj_GetTypeInfoCount,
392     HTMLEventObj_GetTypeInfo,
393     HTMLEventObj_GetIDsOfNames,
394     HTMLEventObj_Invoke,
395     HTMLEventObj_get_srcElement,
396     HTMLEventObj_get_altKey,
397     HTMLEventObj_get_ctrlKey,
398     HTMLEventObj_get_shiftKey,
399     HTMLEventObj_put_returnValue,
400     HTMLEventObj_get_returnValue,
401     HTMLEventObj_put_cancelBubble,
402     HTMLEventObj_get_cancelBubble,
403     HTMLEventObj_get_fromElement,
404     HTMLEventObj_get_toElement,
405     HTMLEventObj_put_keyCode,
406     HTMLEventObj_get_keyCode,
407     HTMLEventObj_get_button,
408     HTMLEventObj_get_type,
409     HTMLEventObj_get_qualifier,
410     HTMLEventObj_get_reason,
411     HTMLEventObj_get_x,
412     HTMLEventObj_get_y,
413     HTMLEventObj_get_clientX,
414     HTMLEventObj_get_clientY,
415     HTMLEventObj_get_offsetX,
416     HTMLEventObj_get_offsetY,
417     HTMLEventObj_get_screenX,
418     HTMLEventObj_get_screenY,
419     HTMLEventObj_get_srcFilter
420 };
421
422 static const tid_t HTMLEventObj_iface_tids[] = {
423     IHTMLEventObj_tid,
424     0
425 };
426
427 static dispex_static_data_t HTMLEventObj_dispex = {
428     NULL,
429     DispCEventObj_tid,
430     NULL,
431     HTMLEventObj_iface_tids
432 };
433
434 static IHTMLEventObj *create_event(HTMLDOMNode *target)
435 {
436     HTMLEventObj *ret;
437
438     ret = heap_alloc(sizeof(*ret));
439     ret->lpIHTMLEventObjVtbl = &HTMLEventObjVtbl;
440     ret->ref = 1;
441     ret->target = target;
442     IHTMLDOMNode_AddRef(HTMLDOMNODE(target));
443
444     init_dispex(&ret->dispex, (IUnknown*)HTMLEVENTOBJ(ret), &HTMLEventObj_dispex);
445
446     return HTMLEVENTOBJ(ret);
447 }
448
449 void fire_event(HTMLDocument *doc, eventid_t eid, nsIDOMNode *target)
450 {
451     IHTMLEventObj *prev_event, *event_obj = NULL;
452     nsIDOMNode *parent, *nsnode;
453     HTMLDOMNode *node;
454     PRUint16 node_type;
455
456     nsIDOMNode_GetNodeType(target, &node_type);
457     if(node_type != ELEMENT_NODE) {
458         FIXME("node type %d node supported\n", node_type);
459         return;
460     }
461
462     prev_event = doc->window->event;
463     nsnode = target;
464     nsIDOMNode_AddRef(nsnode);
465
466     while(1) {
467         node = get_node(doc, nsnode, FALSE);
468
469         if(node && node->event_target && node->event_target->event_table[eid]) {
470             if(!event_obj)
471                 event_obj = doc->window->event = create_event(get_node(doc, target, TRUE));
472
473             TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
474             call_disp_func(doc, node->event_target->event_table[eid], (IDispatch*)HTMLDOMNODE(node));
475             TRACE("%s <<<\n", debugstr_w(event_info[eid].name));
476         }
477
478         if(!(event_info[eid].flags & EVENT_BUBBLE))
479             break;
480
481         nsIDOMNode_GetParentNode(nsnode, &parent);
482         nsIDOMNode_Release(nsnode);
483         nsnode = parent;
484         if(!nsnode)
485             break;
486
487         nsIDOMNode_GetNodeType(nsnode, &node_type);
488         if(node_type != ELEMENT_NODE)
489             break;
490     }
491
492     if(nsnode)
493         nsIDOMNode_Release(nsnode);
494
495     if((event_info[eid].flags & EVENT_BUBBLE) && doc->event_target && doc->event_target->event_table[eid]) {
496         if(!event_obj)
497             event_obj = doc->window->event = create_event(get_node(doc, target, TRUE));
498
499         TRACE("doc %s >>>\n", debugstr_w(event_info[eid].name));
500         call_disp_func(doc, doc->event_target->event_table[eid], (IDispatch*)HTMLDOC(doc));
501         TRACE("doc %s <<<\n", debugstr_w(event_info[eid].name));
502     }
503
504     if(event_obj) {
505         IHTMLEventObj_Release(event_obj);
506         doc->window->event = prev_event;
507     }
508 }
509
510 static HRESULT set_event_handler_disp(event_target_t **event_target, HTMLDocument *doc, eventid_t eid, IDispatch *disp)
511 {
512     if(!*event_target)
513         *event_target = heap_alloc_zero(sizeof(event_target_t));
514     else if((*event_target)->event_table[eid])
515         IDispatch_Release((*event_target)->event_table[eid]);
516
517     (*event_target)->event_table[eid] = disp;
518     if(!disp)
519         return S_OK;
520     IDispatch_AddRef(disp);
521
522     if(event_info[eid].flags & EVENT_DEFAULTLISTENER) {
523         if(!doc->nscontainer->event_vector) {
524             doc->nscontainer->event_vector = heap_alloc_zero(EVENTID_LAST*sizeof(BOOL));
525             if(!doc->nscontainer->event_vector)
526                 return E_OUTOFMEMORY;
527         }
528
529         if(!doc->nscontainer->event_vector[eid]) {
530             doc->nscontainer->event_vector[eid] = TRUE;
531             add_nsevent_listener(doc->nscontainer, event_info[eid].name);
532         }
533     }
534
535     return S_OK;
536 }
537
538 HRESULT set_event_handler(event_target_t **event_target, HTMLDocument *doc, eventid_t eid, VARIANT *var)
539 {
540     switch(V_VT(var)) {
541     case VT_NULL:
542         if(*event_target && (*event_target)->event_table[eid]) {
543             IDispatch_Release((*event_target)->event_table[eid]);
544             (*event_target)->event_table[eid] = NULL;
545         }
546         break;
547
548     case VT_DISPATCH:
549         return set_event_handler_disp(event_target, doc, eid, V_DISPATCH(var));
550
551     default:
552         FIXME("not supported vt=%d\n", V_VT(var));
553         return E_NOTIMPL;
554     }
555
556     return S_OK;
557 }
558
559 HRESULT get_event_handler(event_target_t **event_target, eventid_t eid, VARIANT *var)
560 {
561     if(*event_target && (*event_target)->event_table[eid]) {
562         V_VT(var) = VT_DISPATCH;
563         V_DISPATCH(var) = (*event_target)->event_table[eid];
564         IDispatch_AddRef(V_DISPATCH(var));
565     }else {
566         V_VT(var) = VT_NULL;
567     }
568
569     return S_OK;
570 }
571
572 void check_event_attr(HTMLDocument *doc, nsIDOMElement *nselem)
573 {
574     const PRUnichar *attr_value;
575     nsAString attr_name_str, attr_value_str;
576     IDispatch *disp;
577     HTMLDOMNode *node;
578     int i;
579     nsresult nsres;
580
581     nsAString_Init(&attr_value_str, NULL);
582     nsAString_Init(&attr_name_str, NULL);
583
584     for(i=0; i < EVENTID_LAST; i++) {
585         nsAString_SetData(&attr_name_str, event_info[i].attr_name);
586         nsres = nsIDOMElement_GetAttribute(nselem, &attr_name_str, &attr_value_str);
587         if(NS_SUCCEEDED(nsres)) {
588             nsAString_GetData(&attr_value_str, &attr_value);
589             if(!*attr_value)
590                 continue;
591
592             TRACE("%p.%s = %s\n", nselem, debugstr_w(event_info[i].attr_name), debugstr_w(attr_value));
593
594             disp = script_parse_event(doc, attr_value);
595             if(disp) {
596                 node = get_node(doc, (nsIDOMNode*)nselem, TRUE);
597                 set_event_handler_disp(&node->event_target, node->doc, i, disp);
598                 IDispatch_Release(disp);
599             }
600         }
601     }
602
603     nsAString_Finish(&attr_value_str);
604     nsAString_Finish(&attr_name_str);
605 }
606
607 void release_event_target(event_target_t *event_target)
608 {
609     int i;
610
611     for(i=0; i < EVENTID_LAST; i++) {
612         if(event_target->event_table[i])
613             IDispatch_Release(event_target->event_table[i]);
614     }
615
616     heap_free(event_target);
617 }