54429c34a2098902abca0bae1fbaa291b111541b
[reactos.git] / reactos / dll / win32 / mshtml / htmlevent.c
1 /*
2 * Copyright 2008-2009 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 #include "mshtmdid.h"
28
29 #include "mshtml_private.h"
30 #include "htmlevent.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 typedef struct {
37 IDispatch *handler_prop;
38 DWORD handler_cnt;
39 IDispatch *handlers[0];
40 } handler_vector_t;
41
42 struct event_target_t {
43 handler_vector_t *event_table[EVENTID_LAST];
44 };
45
46 static const WCHAR beforeunloadW[] = {'b','e','f','o','r','e','u','n','l','o','a','d',0};
47 static const WCHAR onbeforeunloadW[] = {'o','n','b','e','f','o','r','e','u','n','l','o','a','d',0};
48
49 static const WCHAR blurW[] = {'b','l','u','r',0};
50 static const WCHAR onblurW[] = {'o','n','b','l','u','r',0};
51
52 static const WCHAR changeW[] = {'c','h','a','n','g','e',0};
53 static const WCHAR onchangeW[] = {'o','n','c','h','a','n','g','e',0};
54
55 static const WCHAR clickW[] = {'c','l','i','c','k',0};
56 static const WCHAR onclickW[] = {'o','n','c','l','i','c','k',0};
57
58 static const WCHAR dblclickW[] = {'d','b','l','c','l','i','c','k',0};
59 static const WCHAR ondblclickW[] = {'o','n','d','b','l','c','l','i','c','k',0};
60
61 static const WCHAR dragW[] = {'d','r','a','g',0};
62 static const WCHAR ondragW[] = {'o','n','d','r','a','g',0};
63
64 static const WCHAR dragstartW[] = {'d','r','a','g','s','t','a','r','t',0};
65 static const WCHAR ondragstartW[] = {'o','n','d','r','a','g','s','t','a','r','t',0};
66
67 static const WCHAR focusW[] = {'f','o','c','u','s',0};
68 static const WCHAR onfocusW[] = {'o','n','f','o','c','u','s',0};
69
70 static const WCHAR keydownW[] = {'k','e','y','d','o','w','n',0};
71 static const WCHAR onkeydownW[] = {'o','n','k','e','y','d','o','w','n',0};
72
73 static const WCHAR keyupW[] = {'k','e','y','u','p',0};
74 static const WCHAR onkeyupW[] = {'o','n','k','e','y','u','p',0};
75
76 static const WCHAR loadW[] = {'l','o','a','d',0};
77 static const WCHAR onloadW[] = {'o','n','l','o','a','d',0};
78
79 static const WCHAR mousedownW[] = {'m','o','u','s','e','d','o','w','n',0};
80 static const WCHAR onmousedownW[] = {'o','n','m','o','u','s','e','d','o','w','n',0};
81
82 static const WCHAR mouseoutW[] = {'m','o','u','s','e','o','u','t',0};
83 static const WCHAR onmouseoutW[] = {'o','n','m','o','u','s','e','o','u','t',0};
84
85 static const WCHAR mouseoverW[] = {'m','o','u','s','e','o','v','e','r',0};
86 static const WCHAR onmouseoverW[] = {'o','n','m','o','u','s','e','o','v','e','r',0};
87
88 static const WCHAR mouseupW[] = {'m','o','u','s','e','u','p',0};
89 static const WCHAR onmouseupW[] = {'o','n','m','o','u','s','e','u','p',0};
90
91 static const WCHAR pasteW[] = {'p','a','s','t','e',0};
92 static const WCHAR onpasteW[] = {'o','n','p','a','s','t','e',0};
93
94 static const WCHAR readystatechangeW[] = {'r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
95 static const WCHAR onreadystatechangeW[] = {'o','n','r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
96
97 static const WCHAR resizeW[] = {'r','e','s','i','z','e',0};
98 static const WCHAR onresizeW[] = {'o','n','r','e','s','i','z','e',0};
99
100 static const WCHAR selectstartW[] = {'s','e','l','e','c','t','s','t','a','r','t',0};
101 static const WCHAR onselectstartW[] = {'o','n','s','e','l','e','c','t','s','t','a','r','t',0};
102
103 static const WCHAR HTMLEventsW[] = {'H','T','M','L','E','v','e','n','t','s',0};
104 static const WCHAR KeyboardEventW[] = {'K','e','y','b','o','a','r','d','E','v','e','n','t',0};
105 static const WCHAR MouseEventW[] = {'M','o','u','s','e','E','v','e','n','t',0};
106
107 enum {
108 EVENTT_NONE,
109 EVENTT_HTML,
110 EVENTT_KEY,
111 EVENTT_MOUSE
112 };
113
114 static const WCHAR *event_types[] = {
115 NULL,
116 HTMLEventsW,
117 KeyboardEventW,
118 MouseEventW
119 };
120
121 typedef struct {
122 LPCWSTR name;
123 LPCWSTR attr_name;
124 DWORD type;
125 DISPID dispid;
126 DWORD flags;
127 } event_info_t;
128
129 #define EVENT_DEFAULTLISTENER 0x0001
130 #define EVENT_BUBBLE 0x0002
131 #define EVENT_FORWARDBODY 0x0004
132
133 static const event_info_t event_info[] = {
134 {beforeunloadW, onbeforeunloadW, EVENTT_NONE, DISPID_EVMETH_ONBEFOREUNLOAD,
135 EVENT_DEFAULTLISTENER|EVENT_FORWARDBODY},
136 {blurW, onblurW, EVENTT_HTML, DISPID_EVMETH_ONBLUR,
137 EVENT_DEFAULTLISTENER},
138 {changeW, onchangeW, EVENTT_HTML, DISPID_EVMETH_ONCHANGE,
139 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
140 {clickW, onclickW, EVENTT_MOUSE, DISPID_EVMETH_ONCLICK,
141 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
142 {dblclickW, ondblclickW, EVENTT_MOUSE, DISPID_EVMETH_ONDBLCLICK,
143 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
144 {dragW, ondragW, EVENTT_MOUSE, DISPID_EVMETH_ONDRAG,
145 0},
146 {dragstartW, ondragstartW, EVENTT_MOUSE, DISPID_EVMETH_ONDRAGSTART,
147 0},
148 {focusW, onfocusW, EVENTT_HTML, DISPID_EVMETH_ONFOCUS,
149 EVENT_DEFAULTLISTENER},
150 {keydownW, onkeydownW, EVENTT_KEY, DISPID_EVMETH_ONKEYDOWN,
151 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
152 {keyupW, onkeyupW, EVENTT_KEY, DISPID_EVMETH_ONKEYUP,
153 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
154 {loadW, onloadW, EVENTT_HTML, DISPID_EVMETH_ONLOAD,
155 0},
156 {mousedownW, onmousedownW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEDOWN,
157 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
158 {mouseoutW, onmouseoutW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEOUT,
159 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
160 {mouseoverW, onmouseoverW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEOVER,
161 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
162 {mouseupW, onmouseupW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEUP,
163 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
164 {pasteW, onpasteW, EVENTT_NONE, DISPID_EVMETH_ONPASTE,
165 0},
166 {readystatechangeW, onreadystatechangeW, EVENTT_NONE, DISPID_EVMETH_ONREADYSTATECHANGE,
167 0},
168 {resizeW, onresizeW, EVENTT_NONE, DISPID_EVMETH_ONRESIZE,
169 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
170 {selectstartW, onselectstartW, EVENTT_MOUSE, DISPID_EVMETH_ONSELECTSTART,
171 0}
172 };
173
174 eventid_t str_to_eid(LPCWSTR str)
175 {
176 int i;
177
178 for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
179 if(!strcmpW(event_info[i].name, str))
180 return i;
181 }
182
183 ERR("unknown type %s\n", debugstr_w(str));
184 return EVENTID_LAST;
185 }
186
187 static eventid_t attr_to_eid(LPCWSTR str)
188 {
189 int i;
190
191 for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
192 if(!strcmpW(event_info[i].attr_name, str))
193 return i;
194 }
195
196 return EVENTID_LAST;
197 }
198
199 typedef struct {
200 DispatchEx dispex;
201 const IHTMLEventObjVtbl *lpIHTMLEventObjVtbl;
202
203 LONG ref;
204
205 HTMLDOMNode *target;
206 const event_info_t *type;
207 nsIDOMEvent *nsevent;
208 } HTMLEventObj;
209
210 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
211
212 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
213
214 static HRESULT WINAPI HTMLEventObj_QueryInterface(IHTMLEventObj *iface, REFIID riid, void **ppv)
215 {
216 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
217
218 *ppv = NULL;
219
220 if(IsEqualGUID(&IID_IUnknown, riid)) {
221 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
222 *ppv = HTMLEVENTOBJ(This);
223 }else if(IsEqualGUID(&IID_IHTMLEventObj, riid)) {
224 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This, ppv);
225 *ppv = HTMLEVENTOBJ(This);
226 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
227 return *ppv ? S_OK : E_NOINTERFACE;
228 }
229
230 if(*ppv) {
231 IUnknown_AddRef((IUnknown*)*ppv);
232 return S_OK;
233 }
234
235 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
236 return E_NOINTERFACE;
237 }
238
239 static ULONG WINAPI HTMLEventObj_AddRef(IHTMLEventObj *iface)
240 {
241 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
242 LONG ref = InterlockedIncrement(&This->ref);
243
244 TRACE("(%p) ref=%d\n", This, ref);
245
246 return ref;
247 }
248
249 static ULONG WINAPI HTMLEventObj_Release(IHTMLEventObj *iface)
250 {
251 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
252 LONG ref = InterlockedDecrement(&This->ref);
253
254 TRACE("(%p) ref=%d\n", This, ref);
255
256 if(!ref) {
257 if(This->nsevent)
258 nsIDOMEvent_Release(This->nsevent);
259 release_dispex(&This->dispex);
260 heap_free(This);
261 }
262
263 return ref;
264 }
265
266 static HRESULT WINAPI HTMLEventObj_GetTypeInfoCount(IHTMLEventObj *iface, UINT *pctinfo)
267 {
268 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
269 FIXME("(%p)->(%p)\n", This, pctinfo);
270 return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI HTMLEventObj_GetTypeInfo(IHTMLEventObj *iface, UINT iTInfo,
274 LCID lcid, ITypeInfo **ppTInfo)
275 {
276 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
277 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
278 return E_NOTIMPL;
279 }
280
281 static HRESULT WINAPI HTMLEventObj_GetIDsOfNames(IHTMLEventObj *iface, REFIID riid,
282 LPOLESTR *rgszNames, UINT cNames,
283 LCID lcid, DISPID *rgDispId)
284 {
285 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
286 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
287 lcid, rgDispId);
288 return E_NOTIMPL;
289 }
290
291 static HRESULT WINAPI HTMLEventObj_Invoke(IHTMLEventObj *iface, DISPID dispIdMember,
292 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
293 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
294 {
295 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
296 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
297 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
298 return E_NOTIMPL;
299 }
300
301 static HRESULT WINAPI HTMLEventObj_get_srcElement(IHTMLEventObj *iface, IHTMLElement **p)
302 {
303 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
304
305 TRACE("(%p)->(%p)\n", This, p);
306
307 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This->target), &IID_IHTMLElement, (void**)p);
308 }
309
310 static HRESULT WINAPI HTMLEventObj_get_altKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
311 {
312 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
313 PRBool ret = FALSE;
314
315 TRACE("(%p)->(%p)\n", This, p);
316
317 if(This->nsevent) {
318 nsIDOMKeyEvent *key_event;
319 nsresult nsres;
320
321 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
322 if(NS_SUCCEEDED(nsres)) {
323 nsIDOMKeyEvent_GetAltKey(key_event, &ret);
324 nsIDOMKeyEvent_Release(key_event);
325 }else {
326 nsIDOMMouseEvent *mouse_event;
327
328 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
329 if(NS_SUCCEEDED(nsres)) {
330 nsIDOMMouseEvent_GetAltKey(mouse_event, &ret);
331 nsIDOMMouseEvent_Release(mouse_event);
332 }
333 }
334 }
335
336 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
337 return S_OK;
338 }
339
340 static HRESULT WINAPI HTMLEventObj_get_ctrlKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
341 {
342 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
343 PRBool ret = FALSE;
344
345 TRACE("(%p)->(%p)\n", This, p);
346
347 if(This->nsevent) {
348 nsIDOMKeyEvent *key_event;
349 nsresult nsres;
350
351 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
352 if(NS_SUCCEEDED(nsres)) {
353 nsIDOMKeyEvent_GetCtrlKey(key_event, &ret);
354 nsIDOMKeyEvent_Release(key_event);
355 }else {
356 nsIDOMMouseEvent *mouse_event;
357
358 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
359 if(NS_SUCCEEDED(nsres)) {
360 nsIDOMMouseEvent_GetCtrlKey(mouse_event, &ret);
361 nsIDOMMouseEvent_Release(mouse_event);
362 }
363 }
364 }
365
366 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
367 return S_OK;
368 }
369
370 static HRESULT WINAPI HTMLEventObj_get_shiftKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
371 {
372 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
373 PRBool ret = FALSE;
374
375 TRACE("(%p)->(%p)\n", This, p);
376
377 if(This->nsevent) {
378 nsIDOMKeyEvent *key_event;
379 nsresult nsres;
380
381 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
382 if(NS_SUCCEEDED(nsres)) {
383 nsIDOMKeyEvent_GetShiftKey(key_event, &ret);
384 nsIDOMKeyEvent_Release(key_event);
385 }else {
386 nsIDOMMouseEvent *mouse_event;
387
388 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
389 if(NS_SUCCEEDED(nsres)) {
390 nsIDOMMouseEvent_GetShiftKey(mouse_event, &ret);
391 nsIDOMMouseEvent_Release(mouse_event);
392 }
393 }
394 }
395
396 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
397 return S_OK;
398 }
399
400 static HRESULT WINAPI HTMLEventObj_put_returnValue(IHTMLEventObj *iface, VARIANT v)
401 {
402 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
403 FIXME("(%p)->()\n", This);
404 return E_NOTIMPL;
405 }
406
407 static HRESULT WINAPI HTMLEventObj_get_returnValue(IHTMLEventObj *iface, VARIANT *p)
408 {
409 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
410
411 FIXME("(%p)->(%p)\n", This, p);
412
413 V_VT(p) = VT_EMPTY;
414 return S_OK;
415 }
416
417 static HRESULT WINAPI HTMLEventObj_put_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL v)
418 {
419 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
420 FIXME("(%p)->(%x)\n", This, v);
421 return E_NOTIMPL;
422 }
423
424 static HRESULT WINAPI HTMLEventObj_get_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL *p)
425 {
426 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
427
428 FIXME("(%p)->(%p)\n", This, p);
429
430 *p = VARIANT_FALSE;
431 return S_OK;
432 }
433
434 static HRESULT WINAPI HTMLEventObj_get_fromElement(IHTMLEventObj *iface, IHTMLElement **p)
435 {
436 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
437
438 FIXME("(%p)->(%p)\n", This, p);
439
440 *p = NULL;
441 return S_OK;
442 }
443
444 static HRESULT WINAPI HTMLEventObj_get_toElement(IHTMLEventObj *iface, IHTMLElement **p)
445 {
446 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
447
448 FIXME("(%p)->(%p)\n", This, p);
449
450 *p = NULL;
451 return S_OK;
452 }
453
454 static HRESULT WINAPI HTMLEventObj_put_keyCode(IHTMLEventObj *iface, LONG v)
455 {
456 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
457 FIXME("(%p)->(%d)\n", This, v);
458 return E_NOTIMPL;
459 }
460
461 static HRESULT WINAPI HTMLEventObj_get_keyCode(IHTMLEventObj *iface, LONG *p)
462 {
463 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
464 PRUint32 key_code = 0;
465
466 TRACE("(%p)->(%p)\n", This, p);
467
468 if(This->nsevent) {
469 nsIDOMKeyEvent *key_event;
470 nsresult nsres;
471
472 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
473 if(NS_SUCCEEDED(nsres)) {
474 nsIDOMKeyEvent_GetKeyCode(key_event, &key_code);
475 nsIDOMKeyEvent_Release(key_event);
476 }
477 }
478
479 *p = key_code;
480 return S_OK;
481 }
482
483 static HRESULT WINAPI HTMLEventObj_get_button(IHTMLEventObj *iface, LONG *p)
484 {
485 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
486 PRUint16 button = 0;
487
488 TRACE("(%p)->(%p)\n", This, p);
489
490 if(This->nsevent) {
491 nsIDOMMouseEvent *mouse_event;
492 nsresult nsres;
493
494 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
495 if(NS_SUCCEEDED(nsres)) {
496 nsIDOMMouseEvent_GetButton(mouse_event, &button);
497 nsIDOMMouseEvent_Release(mouse_event);
498 }
499 }
500
501 *p = button;
502 return S_OK;
503 }
504
505 static HRESULT WINAPI HTMLEventObj_get_type(IHTMLEventObj *iface, BSTR *p)
506 {
507 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
508
509 TRACE("(%p)->(%p)\n", This, p);
510
511 *p = SysAllocString(This->type->name);
512 return *p ? S_OK : E_OUTOFMEMORY;
513 }
514
515 static HRESULT WINAPI HTMLEventObj_get_qualifier(IHTMLEventObj *iface, BSTR *p)
516 {
517 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
518
519 FIXME("(%p)->(%p)\n", This, p);
520
521 *p = NULL;
522 return S_OK;
523 }
524
525 static HRESULT WINAPI HTMLEventObj_get_reason(IHTMLEventObj *iface, LONG *p)
526 {
527 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
528
529 FIXME("(%p)->(%p)\n", This, p);
530
531 *p = 0;
532 return S_OK;
533 }
534
535 static HRESULT WINAPI HTMLEventObj_get_x(IHTMLEventObj *iface, LONG *p)
536 {
537 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
538
539 FIXME("(%p)->(%p)\n", This, p);
540
541 *p = -1;
542 return S_OK;
543 }
544
545 static HRESULT WINAPI HTMLEventObj_get_y(IHTMLEventObj *iface, LONG *p)
546 {
547 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
548
549 FIXME("(%p)->(%p)\n", This, p);
550
551 *p = -1;
552 return S_OK;
553 }
554
555 static HRESULT WINAPI HTMLEventObj_get_clientX(IHTMLEventObj *iface, LONG *p)
556 {
557 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
558 PRInt32 x = 0;
559
560 TRACE("(%p)->(%p)\n", This, p);
561
562 if(This->nsevent) {
563 nsIDOMMouseEvent *mouse_event;
564 nsresult nsres;
565
566 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
567 if(NS_SUCCEEDED(nsres)) {
568 nsIDOMMouseEvent_GetClientX(mouse_event, &x);
569 nsIDOMMouseEvent_Release(mouse_event);
570 }
571 }
572
573 *p = x;
574 return S_OK;
575 }
576
577 static HRESULT WINAPI HTMLEventObj_get_clientY(IHTMLEventObj *iface, LONG *p)
578 {
579 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
580 PRInt32 y = 0;
581
582 TRACE("(%p)->(%p)\n", This, p);
583
584 if(This->nsevent) {
585 nsIDOMMouseEvent *mouse_event;
586 nsresult nsres;
587
588 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
589 if(NS_SUCCEEDED(nsres)) {
590 nsIDOMMouseEvent_GetClientY(mouse_event, &y);
591 nsIDOMMouseEvent_Release(mouse_event);
592 }
593 }
594
595 *p = y;
596 return S_OK;
597 }
598
599 static HRESULT WINAPI HTMLEventObj_get_offsetX(IHTMLEventObj *iface, LONG *p)
600 {
601 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
602
603 FIXME("(%p)->(%p)\n", This, p);
604
605 *p = 0;
606 return S_OK;
607 }
608
609 static HRESULT WINAPI HTMLEventObj_get_offsetY(IHTMLEventObj *iface, LONG *p)
610 {
611 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
612
613 FIXME("(%p)->(%p)\n", This, p);
614
615 *p = 0;
616 return S_OK;
617 }
618
619 static HRESULT WINAPI HTMLEventObj_get_screenX(IHTMLEventObj *iface, LONG *p)
620 {
621 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
622 PRInt32 x = 0;
623
624 TRACE("(%p)->(%p)\n", This, p);
625
626 if(This->nsevent) {
627 nsIDOMMouseEvent *mouse_event;
628 nsresult nsres;
629
630 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
631 if(NS_SUCCEEDED(nsres)) {
632 nsIDOMMouseEvent_GetScreenX(mouse_event, &x);
633 nsIDOMMouseEvent_Release(mouse_event);
634 }
635 }
636
637 *p = x;
638 return S_OK;
639 }
640
641 static HRESULT WINAPI HTMLEventObj_get_screenY(IHTMLEventObj *iface, LONG *p)
642 {
643 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
644 PRInt32 y = 0;
645
646 TRACE("(%p)->(%p)\n", This, p);
647
648 if(This->nsevent) {
649 nsIDOMMouseEvent *mouse_event;
650 nsresult nsres;
651
652 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
653 if(NS_SUCCEEDED(nsres)) {
654 nsIDOMMouseEvent_GetScreenY(mouse_event, &y);
655 nsIDOMMouseEvent_Release(mouse_event);
656 }
657 }
658
659 *p = y;
660 return S_OK;
661 }
662
663 static HRESULT WINAPI HTMLEventObj_get_srcFilter(IHTMLEventObj *iface, IDispatch **p)
664 {
665 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
666
667 FIXME("(%p)->(%p)\n", This, p);
668
669 *p = NULL;
670 return S_OK;
671 }
672
673 #undef HTMLEVENTOBJ_THIS
674
675 static const IHTMLEventObjVtbl HTMLEventObjVtbl = {
676 HTMLEventObj_QueryInterface,
677 HTMLEventObj_AddRef,
678 HTMLEventObj_Release,
679 HTMLEventObj_GetTypeInfoCount,
680 HTMLEventObj_GetTypeInfo,
681 HTMLEventObj_GetIDsOfNames,
682 HTMLEventObj_Invoke,
683 HTMLEventObj_get_srcElement,
684 HTMLEventObj_get_altKey,
685 HTMLEventObj_get_ctrlKey,
686 HTMLEventObj_get_shiftKey,
687 HTMLEventObj_put_returnValue,
688 HTMLEventObj_get_returnValue,
689 HTMLEventObj_put_cancelBubble,
690 HTMLEventObj_get_cancelBubble,
691 HTMLEventObj_get_fromElement,
692 HTMLEventObj_get_toElement,
693 HTMLEventObj_put_keyCode,
694 HTMLEventObj_get_keyCode,
695 HTMLEventObj_get_button,
696 HTMLEventObj_get_type,
697 HTMLEventObj_get_qualifier,
698 HTMLEventObj_get_reason,
699 HTMLEventObj_get_x,
700 HTMLEventObj_get_y,
701 HTMLEventObj_get_clientX,
702 HTMLEventObj_get_clientY,
703 HTMLEventObj_get_offsetX,
704 HTMLEventObj_get_offsetY,
705 HTMLEventObj_get_screenX,
706 HTMLEventObj_get_screenY,
707 HTMLEventObj_get_srcFilter
708 };
709
710 static const tid_t HTMLEventObj_iface_tids[] = {
711 IHTMLEventObj_tid,
712 0
713 };
714
715 static dispex_static_data_t HTMLEventObj_dispex = {
716 NULL,
717 DispCEventObj_tid,
718 NULL,
719 HTMLEventObj_iface_tids
720 };
721
722 static IHTMLEventObj *create_event(HTMLDOMNode *target, eventid_t eid, nsIDOMEvent *nsevent)
723 {
724 HTMLEventObj *ret;
725
726 ret = heap_alloc(sizeof(*ret));
727 if(!ret)
728 return NULL;
729
730 ret->lpIHTMLEventObjVtbl = &HTMLEventObjVtbl;
731 ret->ref = 1;
732 ret->type = event_info+eid;
733
734 ret->nsevent = nsevent;
735 if(nsevent) {
736 nsIDOMEvent_AddRef(nsevent);
737 }else if(event_types[event_info[eid].type]) {
738 nsIDOMDocumentEvent *doc_event;
739 nsresult nsres;
740
741 nsres = nsIDOMHTMLDocument_QueryInterface(target->doc->nsdoc, &IID_nsIDOMDocumentEvent,
742 (void**)&doc_event);
743 if(NS_SUCCEEDED(nsres)) {
744 nsAString type_str;
745
746 nsAString_InitDepend(&type_str, event_types[event_info[eid].type]);
747 nsres = nsIDOMDocumentEvent_CreateEvent(doc_event, &type_str, &ret->nsevent);
748 nsAString_Finish(&type_str);
749 nsIDOMDocumentEvent_Release(doc_event);
750 }
751 if(NS_FAILED(nsres)) {
752 ERR("Could not create event: %08x\n", nsres);
753 IHTMLEventObj_Release(HTMLEVENTOBJ(ret));
754 return NULL;
755 }
756 }
757
758 ret->target = target;
759 IHTMLDOMNode_AddRef(HTMLDOMNODE(target));
760
761 init_dispex(&ret->dispex, (IUnknown*)HTMLEVENTOBJ(ret), &HTMLEventObj_dispex);
762
763 return HTMLEVENTOBJ(ret);
764 }
765
766 static HRESULT call_cp_func(IDispatch *disp, DISPID dispid)
767 {
768 DISPPARAMS dp = {NULL,NULL,0,0};
769 ULONG argerr;
770 EXCEPINFO ei;
771 VARIANT vres;
772 HRESULT hres;
773
774 V_VT(&vres) = VT_EMPTY;
775 memset(&ei, 0, sizeof(ei));
776 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, 0, DISPATCH_METHOD, &dp, &vres, &ei, &argerr);
777 if(SUCCEEDED(hres) && V_VT(&vres) != VT_EMPTY) {
778 FIXME("handle result %s\n", debugstr_variant(&vres));
779 VariantClear(&vres);
780 }
781
782 return hres;
783 }
784
785 static BOOL is_cp_event(cp_static_data_t *data, DISPID dispid)
786 {
787 int min, max, i;
788 HRESULT hres;
789
790 if(!data)
791 return FALSE;
792
793 if(!data->ids) {
794 hres = get_dispids(data->tid, &data->id_cnt, &data->ids);
795 if(FAILED(hres))
796 return FALSE;
797 }
798
799 min = 0;
800 max = data->id_cnt-1;
801 while(min <= max) {
802 i = (min+max)/2;
803 if(data->ids[i] == dispid)
804 return TRUE;
805
806 if(data->ids[i] < dispid)
807 min = i+1;
808 else
809 max = i-1;
810 }
811
812 return FALSE;
813 }
814
815 static void call_event_handlers(HTMLDocumentNode *doc, IHTMLEventObj *event_obj, event_target_t *event_target,
816 ConnectionPointContainer *cp_container, eventid_t eid, IDispatch *this_obj)
817 {
818 handler_vector_t *handler_vector = NULL;
819 int i;
820 HRESULT hres;
821
822 if(event_target)
823 handler_vector = event_target->event_table[eid];
824
825 if(handler_vector && handler_vector->handler_prop) {
826 DISPID named_arg = DISPID_THIS;
827 VARIANTARG arg;
828 DISPPARAMS dp = {&arg, &named_arg, 1, 1};
829
830 V_VT(&arg) = VT_DISPATCH;
831 V_DISPATCH(&arg) = this_obj;
832
833 TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
834 hres = call_disp_func(handler_vector->handler_prop, &dp);
835 if(hres == S_OK)
836 TRACE("%s <<<\n", debugstr_w(event_info[eid].name));
837 else
838 WARN("%s <<< %08x\n", debugstr_w(event_info[eid].name), hres);
839 }
840
841 if(handler_vector && handler_vector->handler_cnt) {
842 VARIANTARG arg;
843 DISPPARAMS dp = {&arg, NULL, 1, 0};
844
845 V_VT(&arg) = VT_DISPATCH;
846 V_DISPATCH(&arg) = (IDispatch*)event_obj;
847
848 i = handler_vector->handler_cnt;
849 while(i--) {
850 if(handler_vector->handlers[i]) {
851 TRACE("%s [%d] >>>\n", debugstr_w(event_info[eid].name), i);
852 hres = call_disp_func(handler_vector->handlers[i], &dp);
853 if(hres == S_OK)
854 TRACE("%s [%d] <<<\n", debugstr_w(event_info[eid].name), i);
855 else
856 WARN("%s [%d] <<< %08x\n", debugstr_w(event_info[eid].name), i, hres);
857 }
858 }
859 }
860
861 if(cp_container) {
862 ConnectionPoint *cp;
863
864 if(cp_container->forward_container)
865 cp_container = cp_container->forward_container;
866
867 for(cp = cp_container->cp_list; cp; cp = cp->next) {
868 if(cp->sinks_size && is_cp_event(cp->data, event_info[eid].dispid)) {
869 for(i=0; i < cp->sinks_size; i++) {
870 if(!cp->sinks[i].disp)
871 continue;
872
873 TRACE("cp %s [%d] >>>\n", debugstr_w(event_info[eid].name), i);
874 hres = call_cp_func(cp->sinks[i].disp, event_info[eid].dispid);
875 if(hres == S_OK)
876 TRACE("cp %s [%d] <<<\n", debugstr_w(event_info[eid].name), i);
877 else
878 WARN("cp %s [%d] <<< %08x\n", debugstr_w(event_info[eid].name), i, hres);
879 }
880 }
881 }
882 }
883 }
884
885 void fire_event(HTMLDocumentNode *doc, eventid_t eid, nsIDOMNode *target, nsIDOMEvent *nsevent)
886 {
887 IHTMLEventObj *prev_event, *event_obj = NULL;
888 nsIDOMNode *parent, *nsnode;
889 HTMLDOMNode *node;
890 PRUint16 node_type;
891
892 TRACE("(%p) %s\n", doc, debugstr_w(event_info[eid].name));
893
894 prev_event = doc->basedoc.window->event;
895 event_obj = doc->basedoc.window->event = create_event(get_node(doc, target, TRUE), eid, nsevent);
896
897 nsIDOMNode_GetNodeType(target, &node_type);
898 nsnode = target;
899 nsIDOMNode_AddRef(nsnode);
900
901 switch(node_type) {
902 case ELEMENT_NODE:
903 do {
904 node = get_node(doc, nsnode, FALSE);
905 if(node)
906 call_event_handlers(doc, event_obj, *get_node_event_target(node), node->cp_container, eid,
907 (IDispatch*)HTMLDOMNODE(node));
908
909 if(!(event_info[eid].flags & EVENT_BUBBLE))
910 break;
911
912 nsIDOMNode_GetParentNode(nsnode, &parent);
913 nsIDOMNode_Release(nsnode);
914 nsnode = parent;
915 if(!nsnode)
916 break;
917
918 nsIDOMNode_GetNodeType(nsnode, &node_type);
919 }while(node_type == ELEMENT_NODE);
920
921 if(!(event_info[eid].flags & EVENT_BUBBLE))
922 break;
923
924 case DOCUMENT_NODE:
925 if(event_info[eid].flags & EVENT_FORWARDBODY) {
926 nsIDOMHTMLElement *nsbody;
927 nsresult nsres;
928
929 nsres = nsIDOMHTMLDocument_GetBody(doc->nsdoc, &nsbody);
930 if(NS_SUCCEEDED(nsres) && nsbody) {
931 node = get_node(doc, (nsIDOMNode*)nsbody, FALSE);
932 if(node)
933 call_event_handlers(doc, event_obj, *get_node_event_target(node), node->cp_container,
934 eid, (IDispatch*)HTMLDOMNODE(node));
935 nsIDOMHTMLElement_Release(nsbody);
936 }else {
937 ERR("Could not get body: %08x\n", nsres);
938 }
939 }
940
941 call_event_handlers(doc, event_obj, doc->node.event_target, &doc->basedoc.cp_container, eid,
942 (IDispatch*)HTMLDOC(&doc->basedoc));
943 break;
944
945 default:
946 FIXME("unimplemented node type %d\n", node_type);
947 }
948
949 if(nsnode)
950 nsIDOMNode_Release(nsnode);
951
952 IHTMLEventObj_Release(event_obj);
953 doc->basedoc.window->event = prev_event;
954 }
955
956 HRESULT dispatch_event(HTMLDOMNode *node, const WCHAR *event_name, VARIANT *event_obj, VARIANT_BOOL *cancelled)
957 {
958 eventid_t eid;
959
960 eid = attr_to_eid(event_name);
961 if(eid == EVENTID_LAST) {
962 WARN("unknown event %s\n", debugstr_w(event_name));
963 return E_INVALIDARG;
964 }
965
966 if(event_obj && V_VT(event_obj) != VT_EMPTY && V_VT(event_obj) != VT_ERROR)
967 FIXME("event_obj not implemented\n");
968
969 if(!(event_info[eid].flags & EVENT_DEFAULTLISTENER)) {
970 FIXME("not EVENT_DEFAULTEVENTHANDLER\n");
971 return E_NOTIMPL;
972 }
973
974 fire_event(node->doc, eid, node->nsnode, NULL);
975
976 *cancelled = VARIANT_TRUE; /* FIXME */
977 return S_OK;
978 }
979
980 HRESULT call_event(HTMLDOMNode *node, eventid_t eid)
981 {
982 HRESULT hres;
983
984 if(node->vtbl->call_event) {
985 BOOL handled = FALSE;
986
987 hres = node->vtbl->call_event(node, eid, &handled);
988 if(handled)
989 return hres;
990 }
991
992 fire_event(node->doc, eid, node->nsnode, NULL);
993 return S_OK;
994 }
995
996 static inline event_target_t *get_event_target(event_target_t **event_target_ptr)
997 {
998 if(!*event_target_ptr)
999 *event_target_ptr = heap_alloc_zero(sizeof(event_target_t));
1000 return *event_target_ptr;
1001 }
1002
1003 static BOOL alloc_handler_vector(event_target_t *event_target, eventid_t eid, int cnt)
1004 {
1005 handler_vector_t *new_vector, *handler_vector = event_target->event_table[eid];
1006
1007 if(handler_vector) {
1008 if(cnt <= handler_vector->handler_cnt)
1009 return TRUE;
1010
1011 new_vector = heap_realloc_zero(handler_vector, sizeof(handler_vector_t) + sizeof(IDispatch*)*cnt);
1012 }else {
1013 new_vector = heap_alloc_zero(sizeof(handler_vector_t) + sizeof(IDispatch*)*cnt);
1014 }
1015
1016 if(!new_vector)
1017 return FALSE;
1018
1019 new_vector->handler_cnt = cnt;
1020 event_target->event_table[eid] = new_vector;
1021 return TRUE;
1022 }
1023
1024 static HRESULT ensure_nsevent_handler(HTMLDocumentNode *doc, eventid_t eid)
1025 {
1026 if(!doc->nsdoc || !(event_info[eid].flags & EVENT_DEFAULTLISTENER))
1027 return S_OK;
1028
1029 if(!doc->event_vector) {
1030 doc->event_vector = heap_alloc_zero(EVENTID_LAST*sizeof(BOOL));
1031 if(!doc->event_vector)
1032 return E_OUTOFMEMORY;
1033 }
1034
1035 if(!doc->event_vector[eid]) {
1036 doc->event_vector[eid] = TRUE;
1037 add_nsevent_listener(doc, event_info[eid].name);
1038 }
1039
1040 return S_OK;
1041 }
1042
1043 static HRESULT set_event_handler_disp(event_target_t **event_target_ptr, HTMLDocumentNode *doc,
1044 eventid_t eid, IDispatch *disp)
1045 {
1046 event_target_t *event_target;
1047
1048 event_target = get_event_target(event_target_ptr);
1049 if(!event_target)
1050 return E_OUTOFMEMORY;
1051
1052 if(!alloc_handler_vector(event_target, eid, 0))
1053 return E_OUTOFMEMORY;
1054
1055 if(event_target->event_table[eid]->handler_prop)
1056 IDispatch_Release(event_target->event_table[eid]->handler_prop);
1057
1058 event_target->event_table[eid]->handler_prop = disp;
1059 if(!disp)
1060 return S_OK;
1061 IDispatch_AddRef(disp);
1062
1063 return ensure_nsevent_handler(doc, eid);
1064 }
1065
1066 HRESULT set_event_handler(event_target_t **event_target, HTMLDocumentNode *doc, eventid_t eid, VARIANT *var)
1067 {
1068 switch(V_VT(var)) {
1069 case VT_NULL:
1070 if(*event_target && (*event_target)->event_table[eid] && (*event_target)->event_table[eid]->handler_prop) {
1071 IDispatch_Release((*event_target)->event_table[eid]->handler_prop);
1072 (*event_target)->event_table[eid]->handler_prop = NULL;
1073 }
1074 break;
1075
1076 case VT_DISPATCH:
1077 return set_event_handler_disp(event_target, doc, eid, V_DISPATCH(var));
1078
1079 default:
1080 FIXME("not supported vt=%d\n", V_VT(var));
1081 case VT_EMPTY:
1082 return E_NOTIMPL;
1083 }
1084
1085 return S_OK;
1086 }
1087
1088 HRESULT get_event_handler(event_target_t **event_target, eventid_t eid, VARIANT *var)
1089 {
1090 if(*event_target && (*event_target)->event_table[eid] && (*event_target)->event_table[eid]->handler_prop) {
1091 V_VT(var) = VT_DISPATCH;
1092 V_DISPATCH(var) = (*event_target)->event_table[eid]->handler_prop;
1093 IDispatch_AddRef(V_DISPATCH(var));
1094 }else {
1095 V_VT(var) = VT_NULL;
1096 }
1097
1098 return S_OK;
1099 }
1100
1101 HRESULT attach_event(event_target_t **event_target_ptr, HTMLDocument *doc, BSTR name, IDispatch *disp, VARIANT_BOOL *res)
1102 {
1103 event_target_t *event_target;
1104 eventid_t eid;
1105 DWORD i = 0;
1106
1107 eid = attr_to_eid(name);
1108 if(eid == EVENTID_LAST) {
1109 WARN("Unknown event\n");
1110 *res = VARIANT_TRUE;
1111 return S_OK;
1112 }
1113
1114 event_target = get_event_target(event_target_ptr);
1115 if(!event_target)
1116 return E_OUTOFMEMORY;
1117
1118 if(event_target->event_table[eid]) {
1119 while(i < event_target->event_table[eid]->handler_cnt && event_target->event_table[eid]->handlers[i])
1120 i++;
1121 if(i == event_target->event_table[eid]->handler_cnt && !alloc_handler_vector(event_target, eid, i+1))
1122 return E_OUTOFMEMORY;
1123 }else if(!alloc_handler_vector(event_target, eid, i+1)) {
1124 return E_OUTOFMEMORY;
1125 }
1126
1127 IDispatch_AddRef(disp);
1128 event_target->event_table[eid]->handlers[i] = disp;
1129
1130 *res = VARIANT_TRUE;
1131 return ensure_nsevent_handler(doc->doc_node, eid);
1132 }
1133
1134 HRESULT detach_event(event_target_t *event_target, HTMLDocument *doc, BSTR name, IDispatch *disp)
1135 {
1136 eventid_t eid;
1137 DWORD i = 0;
1138
1139 if(!event_target)
1140 return S_OK;
1141
1142 eid = attr_to_eid(name);
1143 if(eid == EVENTID_LAST) {
1144 WARN("Unknown event\n");
1145 return S_OK;
1146 }
1147
1148 if(!event_target->event_table[eid])
1149 return S_OK;
1150
1151 while(i < event_target->event_table[eid]->handler_cnt) {
1152 if(event_target->event_table[eid]->handlers[i] == disp) {
1153 IDispatch_Release(event_target->event_table[eid]->handlers[i]);
1154 event_target->event_table[eid]->handlers[i] = NULL;
1155 }
1156 i++;
1157 }
1158
1159 return S_OK;
1160 }
1161
1162 void update_cp_events(HTMLWindow *window, cp_static_data_t *cp)
1163 {
1164 int i;
1165
1166 for(i=0; i < EVENTID_LAST; i++) {
1167 if((event_info[i].flags & EVENT_DEFAULTLISTENER) && is_cp_event(cp, event_info[i].dispid))
1168 ensure_nsevent_handler(window->doc, i);
1169 }
1170 }
1171
1172 void check_event_attr(HTMLDocumentNode *doc, nsIDOMElement *nselem)
1173 {
1174 const PRUnichar *attr_value;
1175 nsAString attr_name_str, attr_value_str;
1176 IDispatch *disp;
1177 HTMLDOMNode *node;
1178 int i;
1179 nsresult nsres;
1180
1181 nsAString_Init(&attr_value_str, NULL);
1182 nsAString_Init(&attr_name_str, NULL);
1183
1184 for(i=0; i < EVENTID_LAST; i++) {
1185 nsAString_SetData(&attr_name_str, event_info[i].attr_name);
1186 nsres = nsIDOMElement_GetAttribute(nselem, &attr_name_str, &attr_value_str);
1187 if(NS_SUCCEEDED(nsres)) {
1188 nsAString_GetData(&attr_value_str, &attr_value);
1189 if(!*attr_value)
1190 continue;
1191
1192 TRACE("%p.%s = %s\n", nselem, debugstr_w(event_info[i].attr_name), debugstr_w(attr_value));
1193
1194 disp = script_parse_event(doc->basedoc.window, attr_value);
1195 if(disp) {
1196 node = get_node(doc, (nsIDOMNode*)nselem, TRUE);
1197 set_event_handler_disp(get_node_event_target(node), node->doc, i, disp);
1198 IDispatch_Release(disp);
1199 }
1200 }
1201 }
1202
1203 nsAString_Finish(&attr_value_str);
1204 nsAString_Finish(&attr_name_str);
1205 }
1206
1207 void release_event_target(event_target_t *event_target)
1208 {
1209 int i, j;
1210
1211 for(i=0; i < EVENTID_LAST; i++) {
1212 if(event_target->event_table[i]) {
1213 if(event_target->event_table[i]->handler_prop)
1214 IDispatch_Release(event_target->event_table[i]->handler_prop);
1215 for(j=0; j < event_target->event_table[i]->handler_cnt; j++)
1216 IDispatch_Release(event_target->event_table[i]->handlers[j]);
1217 }
1218 }
1219
1220 heap_free(event_target);
1221 }