2 * Copyright 2008-2009 Jacek Caban for CodeWeavers
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.
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.
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
29 #include "mshtml_private.h"
30 #include "htmlevent.h"
31 #include "htmlscript.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 IDispatch *handler_prop;
40 IDispatch *handlers[0];
43 struct event_target_t {
44 DWORD node_handlers_mask;
45 handler_vector_t *event_table[EVENTID_LAST];
48 static const WCHAR abortW[] = {'a','b','o','r','t',0};
49 static const WCHAR onabortW[] = {'o','n','a','b','o','r','t',0};
51 static const WCHAR beforeunloadW[] = {'b','e','f','o','r','e','u','n','l','o','a','d',0};
52 static const WCHAR onbeforeunloadW[] = {'o','n','b','e','f','o','r','e','u','n','l','o','a','d',0};
54 static const WCHAR blurW[] = {'b','l','u','r',0};
55 static const WCHAR onblurW[] = {'o','n','b','l','u','r',0};
57 static const WCHAR changeW[] = {'c','h','a','n','g','e',0};
58 static const WCHAR onchangeW[] = {'o','n','c','h','a','n','g','e',0};
60 static const WCHAR clickW[] = {'c','l','i','c','k',0};
61 static const WCHAR onclickW[] = {'o','n','c','l','i','c','k',0};
63 static const WCHAR contextmenuW[] = {'c','o','n','t','e','x','t','m','e','n','u',0};
64 static const WCHAR oncontextmenuW[] = {'o','n','c','o','n','t','e','x','t','m','e','n','u',0};
66 static const WCHAR dataavailableW[] = {'d','a','t','a','a','v','a','i','l','a','b','l','e',0};
67 static const WCHAR ondataavailableW[] = {'o','n','d','a','t','a','a','v','a','i','l','a','b','l','e',0};
69 static const WCHAR dblclickW[] = {'d','b','l','c','l','i','c','k',0};
70 static const WCHAR ondblclickW[] = {'o','n','d','b','l','c','l','i','c','k',0};
72 static const WCHAR dragW[] = {'d','r','a','g',0};
73 static const WCHAR ondragW[] = {'o','n','d','r','a','g',0};
75 static const WCHAR dragstartW[] = {'d','r','a','g','s','t','a','r','t',0};
76 static const WCHAR ondragstartW[] = {'o','n','d','r','a','g','s','t','a','r','t',0};
78 static const WCHAR errorW[] = {'e','r','r','o','r',0};
79 static const WCHAR onerrorW[] = {'o','n','e','r','r','o','r',0};
81 static const WCHAR focusW[] = {'f','o','c','u','s',0};
82 static const WCHAR onfocusW[] = {'o','n','f','o','c','u','s',0};
84 static const WCHAR helpW[] = {'h','e','l','p',0};
85 static const WCHAR onhelpW[] = {'o','n','h','e','l','p',0};
87 static const WCHAR keydownW[] = {'k','e','y','d','o','w','n',0};
88 static const WCHAR onkeydownW[] = {'o','n','k','e','y','d','o','w','n',0};
90 static const WCHAR keypressW[] = {'k','e','y','p','r','e','s','s',0};
91 static const WCHAR onkeypressW[] = {'o','n','k','e','y','p','r','e','s','s',0};
93 static const WCHAR keyupW[] = {'k','e','y','u','p',0};
94 static const WCHAR onkeyupW[] = {'o','n','k','e','y','u','p',0};
96 static const WCHAR loadW[] = {'l','o','a','d',0};
97 static const WCHAR onloadW[] = {'o','n','l','o','a','d',0};
99 static const WCHAR mousedownW[] = {'m','o','u','s','e','d','o','w','n',0};
100 static const WCHAR onmousedownW[] = {'o','n','m','o','u','s','e','d','o','w','n',0};
102 static const WCHAR mousemoveW[] = {'m','o','u','s','e','m','o','v','e',0};
103 static const WCHAR onmousemoveW[] = {'o','n','m','o','u','s','e','m','o','v','e',0};
105 static const WCHAR mouseoutW[] = {'m','o','u','s','e','o','u','t',0};
106 static const WCHAR onmouseoutW[] = {'o','n','m','o','u','s','e','o','u','t',0};
108 static const WCHAR mouseoverW[] = {'m','o','u','s','e','o','v','e','r',0};
109 static const WCHAR onmouseoverW[] = {'o','n','m','o','u','s','e','o','v','e','r',0};
111 static const WCHAR mouseupW[] = {'m','o','u','s','e','u','p',0};
112 static const WCHAR onmouseupW[] = {'o','n','m','o','u','s','e','u','p',0};
114 static const WCHAR pasteW[] = {'p','a','s','t','e',0};
115 static const WCHAR onpasteW[] = {'o','n','p','a','s','t','e',0};
117 static const WCHAR readystatechangeW[] = {'r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
118 static const WCHAR onreadystatechangeW[] = {'o','n','r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
120 static const WCHAR resizeW[] = {'r','e','s','i','z','e',0};
121 static const WCHAR onresizeW[] = {'o','n','r','e','s','i','z','e',0};
123 static const WCHAR scrollW[] = {'s','c','r','o','l','l',0};
124 static const WCHAR onscrollW[] = {'o','n','s','c','r','o','l','l',0};
126 static const WCHAR selectstartW[] = {'s','e','l','e','c','t','s','t','a','r','t',0};
127 static const WCHAR onselectstartW[] = {'o','n','s','e','l','e','c','t','s','t','a','r','t',0};
129 static const WCHAR submitW[] = {'s','u','b','m','i','t',0};
130 static const WCHAR onsubmitW[] = {'o','n','s','u','b','m','i','t',0};
132 static const WCHAR HTMLEventsW[] = {'H','T','M','L','E','v','e','n','t','s',0};
133 static const WCHAR KeyboardEventW[] = {'K','e','y','b','o','a','r','d','E','v','e','n','t',0};
134 static const WCHAR MouseEventW[] = {'M','o','u','s','e','E','v','e','n','t',0};
143 static const WCHAR *event_types[] = {
158 #define EVENT_DEFAULTLISTENER 0x0001
159 #define EVENT_BUBBLE 0x0002
160 #define EVENT_FORWARDBODY 0x0004
161 #define EVENT_NODEHANDLER 0x0008
162 #define EVENT_CANCELABLE 0x0010
163 #define EVENT_HASDEFAULTHANDLERS 0x0020
165 static const event_info_t event_info[] = {
166 {abortW, onabortW, EVENTT_NONE, DISPID_EVMETH_ONABORT,
168 {beforeunloadW, onbeforeunloadW, EVENTT_NONE, DISPID_EVMETH_ONBEFOREUNLOAD,
169 EVENT_DEFAULTLISTENER|EVENT_FORWARDBODY},
170 {blurW, onblurW, EVENTT_HTML, DISPID_EVMETH_ONBLUR,
171 EVENT_DEFAULTLISTENER},
172 {changeW, onchangeW, EVENTT_HTML, DISPID_EVMETH_ONCHANGE,
173 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
174 {clickW, onclickW, EVENTT_MOUSE, DISPID_EVMETH_ONCLICK,
175 EVENT_DEFAULTLISTENER|EVENT_BUBBLE|EVENT_CANCELABLE|EVENT_HASDEFAULTHANDLERS},
176 {contextmenuW, oncontextmenuW, EVENTT_MOUSE, DISPID_EVMETH_ONCONTEXTMENU,
177 EVENT_BUBBLE|EVENT_CANCELABLE},
178 {dataavailableW, ondataavailableW, EVENTT_NONE, DISPID_EVMETH_ONDATAAVAILABLE,
180 {dblclickW, ondblclickW, EVENTT_MOUSE, DISPID_EVMETH_ONDBLCLICK,
181 EVENT_DEFAULTLISTENER|EVENT_BUBBLE|EVENT_CANCELABLE},
182 {dragW, ondragW, EVENTT_MOUSE, DISPID_EVMETH_ONDRAG,
184 {dragstartW, ondragstartW, EVENTT_MOUSE, DISPID_EVMETH_ONDRAGSTART,
186 {errorW, onerrorW, EVENTT_NONE, DISPID_EVMETH_ONERROR,
188 {focusW, onfocusW, EVENTT_HTML, DISPID_EVMETH_ONFOCUS,
189 EVENT_DEFAULTLISTENER},
190 {helpW, onhelpW, EVENTT_KEY, DISPID_EVMETH_ONHELP,
191 EVENT_BUBBLE|EVENT_CANCELABLE},
192 {keydownW, onkeydownW, EVENTT_KEY, DISPID_EVMETH_ONKEYDOWN,
193 EVENT_DEFAULTLISTENER|EVENT_BUBBLE|EVENT_HASDEFAULTHANDLERS},
194 {keypressW, onkeypressW, EVENTT_KEY, DISPID_EVMETH_ONKEYPRESS,
195 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
196 {keyupW, onkeyupW, EVENTT_KEY, DISPID_EVMETH_ONKEYUP,
197 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
198 {loadW, onloadW, EVENTT_HTML, DISPID_EVMETH_ONLOAD,
200 {mousedownW, onmousedownW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEDOWN,
201 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
202 {mousemoveW, onmousemoveW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEMOVE,
203 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
204 {mouseoutW, onmouseoutW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEOUT,
205 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
206 {mouseoverW, onmouseoverW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEOVER,
207 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
208 {mouseupW, onmouseupW, EVENTT_MOUSE, DISPID_EVMETH_ONMOUSEUP,
209 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
210 {pasteW, onpasteW, EVENTT_NONE, DISPID_EVMETH_ONPASTE,
212 {readystatechangeW, onreadystatechangeW, EVENTT_NONE, DISPID_EVMETH_ONREADYSTATECHANGE,
214 {resizeW, onresizeW, EVENTT_NONE, DISPID_EVMETH_ONRESIZE,
215 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
216 {scrollW, onscrollW, EVENTT_HTML, DISPID_EVMETH_ONSCROLL,
217 EVENT_DEFAULTLISTENER|EVENT_BUBBLE},
218 {selectstartW, onselectstartW, EVENTT_MOUSE, DISPID_EVMETH_ONSELECTSTART,
220 {submitW, onsubmitW, EVENTT_HTML, DISPID_EVMETH_ONSUBMIT,
221 EVENT_DEFAULTLISTENER|EVENT_BUBBLE|EVENT_CANCELABLE}
224 static const eventid_t node_handled_list[] = { EVENTID_ABORT, EVENTID_ERROR, EVENTID_LOAD };
226 eventid_t str_to_eid(LPCWSTR str)
230 for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
231 if(!strcmpW(event_info[i].name, str))
235 ERR("unknown type %s\n", debugstr_w(str));
239 static eventid_t attr_to_eid(LPCWSTR str)
243 for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
244 if(!strcmpW(event_info[i].attr_name, str))
251 static DWORD get_node_handler_mask(eventid_t eid)
255 for(i=0; i<sizeof(node_handled_list)/sizeof(*node_handled_list); i++) {
256 if(node_handled_list[i] == eid)
260 ERR("Invalid eid %d\n", eid);
266 IHTMLEventObj IHTMLEventObj_iface;
271 const event_info_t *type;
272 nsIDOMEvent *nsevent;
273 BOOL prevent_default;
277 static inline HTMLEventObj *impl_from_IHTMLEventObj(IHTMLEventObj *iface)
279 return CONTAINING_RECORD(iface, HTMLEventObj, IHTMLEventObj_iface);
282 static HRESULT WINAPI HTMLEventObj_QueryInterface(IHTMLEventObj *iface, REFIID riid, void **ppv)
284 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
288 if(IsEqualGUID(&IID_IUnknown, riid)) {
289 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
290 *ppv = &This->IHTMLEventObj_iface;
291 }else if(IsEqualGUID(&IID_IHTMLEventObj, riid)) {
292 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This, ppv);
293 *ppv = &This->IHTMLEventObj_iface;
294 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
295 return *ppv ? S_OK : E_NOINTERFACE;
299 IUnknown_AddRef((IUnknown*)*ppv);
303 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
304 return E_NOINTERFACE;
307 static ULONG WINAPI HTMLEventObj_AddRef(IHTMLEventObj *iface)
309 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
310 LONG ref = InterlockedIncrement(&This->ref);
312 TRACE("(%p) ref=%d\n", This, ref);
317 static ULONG WINAPI HTMLEventObj_Release(IHTMLEventObj *iface)
319 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
320 LONG ref = InterlockedDecrement(&This->ref);
322 TRACE("(%p) ref=%d\n", This, ref);
326 IHTMLDOMNode_Release(&This->target->IHTMLDOMNode_iface);
328 nsIDOMEvent_Release(This->nsevent);
329 release_dispex(&This->dispex);
336 static HRESULT WINAPI HTMLEventObj_GetTypeInfoCount(IHTMLEventObj *iface, UINT *pctinfo)
338 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
339 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
342 static HRESULT WINAPI HTMLEventObj_GetTypeInfo(IHTMLEventObj *iface, UINT iTInfo,
343 LCID lcid, ITypeInfo **ppTInfo)
345 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
346 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
349 static HRESULT WINAPI HTMLEventObj_GetIDsOfNames(IHTMLEventObj *iface, REFIID riid,
350 LPOLESTR *rgszNames, UINT cNames,
351 LCID lcid, DISPID *rgDispId)
353 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
354 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
358 static HRESULT WINAPI HTMLEventObj_Invoke(IHTMLEventObj *iface, DISPID dispIdMember,
359 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
360 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
362 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
363 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
364 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
367 static HRESULT WINAPI HTMLEventObj_get_srcElement(IHTMLEventObj *iface, IHTMLElement **p)
369 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
371 TRACE("(%p)->(%p)\n", This, p);
375 IHTMLDOMNode_QueryInterface(&This->target->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
379 static HRESULT WINAPI HTMLEventObj_get_altKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
381 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
382 cpp_bool ret = FALSE;
384 TRACE("(%p)->(%p)\n", This, p);
387 nsIDOMKeyEvent *key_event;
390 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
391 if(NS_SUCCEEDED(nsres)) {
392 nsIDOMKeyEvent_GetAltKey(key_event, &ret);
393 nsIDOMKeyEvent_Release(key_event);
395 nsIDOMMouseEvent *mouse_event;
397 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
398 if(NS_SUCCEEDED(nsres)) {
399 nsIDOMMouseEvent_GetAltKey(mouse_event, &ret);
400 nsIDOMMouseEvent_Release(mouse_event);
405 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
409 static HRESULT WINAPI HTMLEventObj_get_ctrlKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
411 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
412 cpp_bool ret = FALSE;
414 TRACE("(%p)->(%p)\n", This, p);
417 nsIDOMKeyEvent *key_event;
420 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
421 if(NS_SUCCEEDED(nsres)) {
422 nsIDOMKeyEvent_GetCtrlKey(key_event, &ret);
423 nsIDOMKeyEvent_Release(key_event);
425 nsIDOMMouseEvent *mouse_event;
427 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
428 if(NS_SUCCEEDED(nsres)) {
429 nsIDOMMouseEvent_GetCtrlKey(mouse_event, &ret);
430 nsIDOMMouseEvent_Release(mouse_event);
435 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
439 static HRESULT WINAPI HTMLEventObj_get_shiftKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
441 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
442 cpp_bool ret = FALSE;
444 TRACE("(%p)->(%p)\n", This, p);
447 nsIDOMKeyEvent *key_event;
450 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
451 if(NS_SUCCEEDED(nsres)) {
452 nsIDOMKeyEvent_GetShiftKey(key_event, &ret);
453 nsIDOMKeyEvent_Release(key_event);
455 nsIDOMMouseEvent *mouse_event;
457 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
458 if(NS_SUCCEEDED(nsres)) {
459 nsIDOMMouseEvent_GetShiftKey(mouse_event, &ret);
460 nsIDOMMouseEvent_Release(mouse_event);
465 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
469 static HRESULT WINAPI HTMLEventObj_put_returnValue(IHTMLEventObj *iface, VARIANT v)
471 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
473 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
475 if(V_VT(&v) != VT_BOOL) {
476 FIXME("unsupported value %s\n", debugstr_variant(&v));
477 return DISP_E_BADVARTYPE;
481 This->prevent_default = TRUE;
485 static HRESULT WINAPI HTMLEventObj_get_returnValue(IHTMLEventObj *iface, VARIANT *p)
487 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
489 FIXME("(%p)->(%p)\n", This, p);
495 static HRESULT WINAPI HTMLEventObj_put_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL v)
497 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
499 TRACE("(%p)->(%x)\n", This, v);
501 This->cancel_bubble = !!v;
505 static HRESULT WINAPI HTMLEventObj_get_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL *p)
507 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
509 TRACE("(%p)->(%p)\n", This, p);
511 *p = This->cancel_bubble ? VARIANT_TRUE : VARIANT_FALSE;
515 static HRESULT WINAPI HTMLEventObj_get_fromElement(IHTMLEventObj *iface, IHTMLElement **p)
517 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
519 FIXME("(%p)->(%p)\n", This, p);
525 static HRESULT WINAPI HTMLEventObj_get_toElement(IHTMLEventObj *iface, IHTMLElement **p)
527 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
529 FIXME("(%p)->(%p)\n", This, p);
535 static HRESULT WINAPI HTMLEventObj_put_keyCode(IHTMLEventObj *iface, LONG v)
537 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
538 FIXME("(%p)->(%d)\n", This, v);
542 static HRESULT WINAPI HTMLEventObj_get_keyCode(IHTMLEventObj *iface, LONG *p)
544 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
545 PRUint32 key_code = 0;
547 TRACE("(%p)->(%p)\n", This, p);
550 nsIDOMKeyEvent *key_event;
553 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMKeyEvent, (void**)&key_event);
554 if(NS_SUCCEEDED(nsres)) {
555 nsIDOMKeyEvent_GetKeyCode(key_event, &key_code);
556 nsIDOMKeyEvent_Release(key_event);
564 static HRESULT WINAPI HTMLEventObj_get_button(IHTMLEventObj *iface, LONG *p)
566 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
569 TRACE("(%p)->(%p)\n", This, p);
572 nsIDOMMouseEvent *mouse_event;
575 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
576 if(NS_SUCCEEDED(nsres)) {
577 nsIDOMMouseEvent_GetButton(mouse_event, &button);
578 nsIDOMMouseEvent_Release(mouse_event);
586 static HRESULT WINAPI HTMLEventObj_get_type(IHTMLEventObj *iface, BSTR *p)
588 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
590 TRACE("(%p)->(%p)\n", This, p);
597 *p = SysAllocString(This->type->name);
598 return *p ? S_OK : E_OUTOFMEMORY;
601 static HRESULT WINAPI HTMLEventObj_get_qualifier(IHTMLEventObj *iface, BSTR *p)
603 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
605 FIXME("(%p)->(%p)\n", This, p);
611 static HRESULT WINAPI HTMLEventObj_get_reason(IHTMLEventObj *iface, LONG *p)
613 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
615 FIXME("(%p)->(%p)\n", This, p);
621 static HRESULT WINAPI HTMLEventObj_get_x(IHTMLEventObj *iface, LONG *p)
623 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
625 FIXME("(%p)->(%p)\n", This, p);
631 static HRESULT WINAPI HTMLEventObj_get_y(IHTMLEventObj *iface, LONG *p)
633 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
635 FIXME("(%p)->(%p)\n", This, p);
641 static HRESULT WINAPI HTMLEventObj_get_clientX(IHTMLEventObj *iface, LONG *p)
643 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
646 TRACE("(%p)->(%p)\n", This, p);
649 nsIDOMMouseEvent *mouse_event;
652 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
653 if(NS_SUCCEEDED(nsres)) {
654 nsIDOMMouseEvent_GetClientX(mouse_event, &x);
655 nsIDOMMouseEvent_Release(mouse_event);
663 static HRESULT WINAPI HTMLEventObj_get_clientY(IHTMLEventObj *iface, LONG *p)
665 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
668 TRACE("(%p)->(%p)\n", This, p);
671 nsIDOMMouseEvent *mouse_event;
674 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
675 if(NS_SUCCEEDED(nsres)) {
676 nsIDOMMouseEvent_GetClientY(mouse_event, &y);
677 nsIDOMMouseEvent_Release(mouse_event);
685 static HRESULT WINAPI HTMLEventObj_get_offsetX(IHTMLEventObj *iface, LONG *p)
687 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
689 FIXME("(%p)->(%p)\n", This, p);
695 static HRESULT WINAPI HTMLEventObj_get_offsetY(IHTMLEventObj *iface, LONG *p)
697 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
699 FIXME("(%p)->(%p)\n", This, p);
705 static HRESULT WINAPI HTMLEventObj_get_screenX(IHTMLEventObj *iface, LONG *p)
707 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
710 TRACE("(%p)->(%p)\n", This, p);
713 nsIDOMMouseEvent *mouse_event;
716 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
717 if(NS_SUCCEEDED(nsres)) {
718 nsIDOMMouseEvent_GetScreenX(mouse_event, &x);
719 nsIDOMMouseEvent_Release(mouse_event);
727 static HRESULT WINAPI HTMLEventObj_get_screenY(IHTMLEventObj *iface, LONG *p)
729 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
732 TRACE("(%p)->(%p)\n", This, p);
735 nsIDOMMouseEvent *mouse_event;
738 nsres = nsIDOMEvent_QueryInterface(This->nsevent, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
739 if(NS_SUCCEEDED(nsres)) {
740 nsIDOMMouseEvent_GetScreenY(mouse_event, &y);
741 nsIDOMMouseEvent_Release(mouse_event);
749 static HRESULT WINAPI HTMLEventObj_get_srcFilter(IHTMLEventObj *iface, IDispatch **p)
751 HTMLEventObj *This = impl_from_IHTMLEventObj(iface);
753 FIXME("(%p)->(%p)\n", This, p);
759 static const IHTMLEventObjVtbl HTMLEventObjVtbl = {
760 HTMLEventObj_QueryInterface,
762 HTMLEventObj_Release,
763 HTMLEventObj_GetTypeInfoCount,
764 HTMLEventObj_GetTypeInfo,
765 HTMLEventObj_GetIDsOfNames,
767 HTMLEventObj_get_srcElement,
768 HTMLEventObj_get_altKey,
769 HTMLEventObj_get_ctrlKey,
770 HTMLEventObj_get_shiftKey,
771 HTMLEventObj_put_returnValue,
772 HTMLEventObj_get_returnValue,
773 HTMLEventObj_put_cancelBubble,
774 HTMLEventObj_get_cancelBubble,
775 HTMLEventObj_get_fromElement,
776 HTMLEventObj_get_toElement,
777 HTMLEventObj_put_keyCode,
778 HTMLEventObj_get_keyCode,
779 HTMLEventObj_get_button,
780 HTMLEventObj_get_type,
781 HTMLEventObj_get_qualifier,
782 HTMLEventObj_get_reason,
785 HTMLEventObj_get_clientX,
786 HTMLEventObj_get_clientY,
787 HTMLEventObj_get_offsetX,
788 HTMLEventObj_get_offsetY,
789 HTMLEventObj_get_screenX,
790 HTMLEventObj_get_screenY,
791 HTMLEventObj_get_srcFilter
794 static inline HTMLEventObj *unsafe_impl_from_IHTMLEventObj(IHTMLEventObj *iface)
796 return iface->lpVtbl == &HTMLEventObjVtbl ? impl_from_IHTMLEventObj(iface) : NULL;
799 static const tid_t HTMLEventObj_iface_tids[] = {
804 static dispex_static_data_t HTMLEventObj_dispex = {
808 HTMLEventObj_iface_tids
811 static HTMLEventObj *create_event(void)
815 ret = heap_alloc_zero(sizeof(*ret));
819 ret->IHTMLEventObj_iface.lpVtbl = &HTMLEventObjVtbl;
822 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLEventObj_iface, &HTMLEventObj_dispex);
827 static HRESULT set_event_info(HTMLEventObj *event, HTMLDOMNode *target, eventid_t eid, nsIDOMEvent *nsevent)
829 event->type = event_info+eid;
830 event->nsevent = nsevent;
833 nsIDOMEvent_AddRef(nsevent);
834 }else if(event_types[event_info[eid].type]) {
838 nsAString_InitDepend(&type_str, event_types[event_info[eid].type]);
839 nsres = nsIDOMHTMLDocument_CreateEvent(target->doc->nsdoc, &type_str, &event->nsevent);
840 nsAString_Finish(&type_str);
841 if(NS_FAILED(nsres)) {
842 ERR("Could not create event: %08x\n", nsres);
847 event->target = target;
849 IHTMLDOMNode_AddRef(&target->IHTMLDOMNode_iface);
853 HRESULT create_event_obj(IHTMLEventObj **ret)
857 event = create_event();
859 return E_OUTOFMEMORY;
861 *ret = &event->IHTMLEventObj_iface;
865 static HRESULT call_disp_func(IDispatch *disp, DISPPARAMS *dp, VARIANT *retv)
871 memset(&ei, 0, sizeof(ei));
873 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
874 if(SUCCEEDED(hres)) {
875 hres = IDispatchEx_InvokeEx(dispex, 0, GetUserDefaultLCID(), DISPATCH_METHOD, dp, retv, &ei, NULL);
876 IDispatchEx_Release(dispex);
878 TRACE("Could not get IDispatchEx interface: %08x\n", hres);
879 hres = IDispatch_Invoke(disp, 0, &IID_NULL, GetUserDefaultLCID(), DISPATCH_METHOD,
880 dp, retv, &ei, NULL);
886 static HRESULT call_cp_func(IDispatch *disp, DISPID dispid, VARIANT *retv)
888 DISPPARAMS dp = {NULL,NULL,0,0};
892 memset(&ei, 0, sizeof(ei));
893 return IDispatch_Invoke(disp, dispid, &IID_NULL, 0, DISPATCH_METHOD, &dp, retv, &ei, &argerr);
896 static BOOL is_cp_event(cp_static_data_t *data, DISPID dispid)
905 hres = get_dispids(data->tid, &data->id_cnt, &data->ids);
911 max = data->id_cnt-1;
914 if(data->ids[i] == dispid)
917 if(data->ids[i] < dispid)
926 static void call_event_handlers(HTMLDocumentNode *doc, HTMLEventObj *event_obj, event_target_t *event_target,
927 ConnectionPointContainer *cp_container, eventid_t eid, IDispatch *this_obj)
929 const BOOL cancelable = event_info[eid].flags & EVENT_CANCELABLE;
930 handler_vector_t *handler_vector = NULL;
936 handler_vector = event_target->event_table[eid];
938 if(handler_vector && handler_vector->handler_prop) {
939 DISPID named_arg = DISPID_THIS;
941 DISPPARAMS dp = {&arg, &named_arg, 1, 1};
943 V_VT(&arg) = VT_DISPATCH;
944 V_DISPATCH(&arg) = this_obj;
947 TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
948 hres = call_disp_func(handler_vector->handler_prop, &dp, &v);
950 TRACE("%s <<< %s\n", debugstr_w(event_info[eid].name), debugstr_variant(&v));
953 if(V_VT(&v) == VT_BOOL) {
955 event_obj->prevent_default = TRUE;
956 }else if(V_VT(&v) != VT_EMPTY) {
957 FIXME("unhandled result %s\n", debugstr_variant(&v));
962 WARN("%s <<< %08x\n", debugstr_w(event_info[eid].name), hres);
966 if(handler_vector && handler_vector->handler_cnt) {
968 DISPPARAMS dp = {&arg, NULL, 1, 0};
970 V_VT(&arg) = VT_DISPATCH;
971 V_DISPATCH(&arg) = (IDispatch*)event_obj;
973 i = handler_vector->handler_cnt;
975 if(handler_vector->handlers[i]) {
978 TRACE("%s [%d] >>>\n", debugstr_w(event_info[eid].name), i);
979 hres = call_disp_func(handler_vector->handlers[i], &dp, &v);
981 TRACE("%s [%d] <<<\n", debugstr_w(event_info[eid].name), i);
984 if(V_VT(&v) == VT_BOOL) {
986 event_obj->prevent_default = TRUE;
987 }else if(V_VT(&v) != VT_EMPTY) {
988 FIXME("unhandled result %s\n", debugstr_variant(&v));
993 WARN("%s [%d] <<< %08x\n", debugstr_w(event_info[eid].name), i, hres);
1000 * NOTE: CP events may require doc_obj reference, which we don't own. We make sure that
1001 * it's safe to call event handler by checking nsevent_listener, which is NULL for
1002 * detached documents.
1004 if(cp_container && doc->nsevent_listener) {
1005 ConnectionPoint *cp;
1007 if(cp_container->forward_container)
1008 cp_container = cp_container->forward_container;
1010 for(cp = cp_container->cp_list; cp; cp = cp->next) {
1011 if(cp->sinks_size && is_cp_event(cp->data, event_info[eid].dispid)) {
1012 for(i=0; doc->nsevent_listener && i < cp->sinks_size; i++) {
1013 if(!cp->sinks[i].disp)
1016 V_VT(&v) = VT_EMPTY;
1018 TRACE("cp %s [%d] >>>\n", debugstr_w(event_info[eid].name), i);
1019 hres = call_cp_func(cp->sinks[i].disp, event_info[eid].dispid, &v);
1021 TRACE("cp %s [%d] <<<\n", debugstr_w(event_info[eid].name), i);
1024 if(V_VT(&v) == VT_BOOL) {
1026 event_obj->prevent_default = TRUE;
1027 }else if(V_VT(&v) != VT_EMPTY) {
1028 FIXME("unhandled result %s\n", debugstr_variant(&v));
1033 WARN("cp %s [%d] <<< %08x\n", debugstr_w(event_info[eid].name), i, hres);
1037 if(!doc->nsevent_listener)
1044 static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *event_obj,
1045 nsIDOMNode *target, IDispatch *script_this)
1047 IHTMLEventObj *prev_event;
1048 nsIDOMNode *parent, *nsnode;
1049 BOOL prevent_default = FALSE;
1050 HTMLInnerWindow *window;
1056 TRACE("(%p) %s\n", doc, debugstr_w(event_info[eid].name));
1058 htmldoc_addref(&doc->basedoc);
1060 window = doc->window;
1061 prev_event = window->event;
1062 window->event = event_obj ? &event_obj->IHTMLEventObj_iface : NULL;
1064 nsIDOMNode_GetNodeType(target, &node_type);
1066 nsIDOMNode_AddRef(nsnode);
1071 hres = get_node(doc, nsnode, FALSE, &node);
1072 if(SUCCEEDED(hres) && node) {
1073 call_event_handlers(doc, event_obj, *get_node_event_target(node),
1074 node->cp_container, eid, script_this ? script_this : (IDispatch*)&node->IHTMLDOMNode_iface);
1078 if(!(event_info[eid].flags & EVENT_BUBBLE) || (event_obj && event_obj->cancel_bubble))
1081 nsIDOMNode_GetParentNode(nsnode, &parent);
1082 nsIDOMNode_Release(nsnode);
1087 nsIDOMNode_GetNodeType(nsnode, &node_type);
1088 }while(node_type == ELEMENT_NODE);
1090 if(!(event_info[eid].flags & EVENT_BUBBLE) || (event_obj && event_obj->cancel_bubble))
1094 if(event_info[eid].flags & EVENT_FORWARDBODY) {
1095 nsIDOMHTMLElement *nsbody;
1098 nsres = nsIDOMHTMLDocument_GetBody(doc->nsdoc, &nsbody);
1099 if(NS_SUCCEEDED(nsres) && nsbody) {
1100 hres = get_node(doc, (nsIDOMNode*)nsbody, FALSE, &node);
1101 if(SUCCEEDED(hres) && node) {
1102 call_event_handlers(doc, event_obj, *get_node_event_target(node),
1103 node->cp_container, eid, script_this ? script_this : (IDispatch*)&node->IHTMLDOMNode_iface);
1106 nsIDOMHTMLElement_Release(nsbody);
1108 ERR("Could not get body: %08x\n", nsres);
1112 call_event_handlers(doc, event_obj, doc->node.event_target, &doc->basedoc.cp_container, eid,
1113 script_this ? script_this : (IDispatch*)&doc->basedoc.IHTMLDocument2_iface);
1117 FIXME("unimplemented node type %d\n", node_type);
1121 nsIDOMNode_Release(nsnode);
1123 if(event_obj && event_obj->prevent_default)
1124 prevent_default = TRUE;
1125 window->event = prev_event;
1127 if(!prevent_default && (event_info[eid].flags & EVENT_HASDEFAULTHANDLERS)) {
1128 nsIDOMNode_AddRef(target);
1132 hres = get_node(doc, nsnode, TRUE, &node);
1137 if(node->vtbl->handle_event)
1138 hres = node->vtbl->handle_event(node, eid, event_obj ? event_obj->nsevent : NULL, &prevent_default);
1140 if(FAILED(hres) || prevent_default || (event_obj && event_obj->cancel_bubble))
1144 nsres = nsIDOMNode_GetParentNode(nsnode, &parent);
1145 if(NS_FAILED(nsres))
1148 nsIDOMNode_Release(nsnode);
1153 nsIDOMNode_Release(nsnode);
1156 if(prevent_default && event_obj && event_obj->nsevent) {
1157 TRACE("calling PreventDefault\n");
1158 nsIDOMEvent_PreventDefault(event_obj->nsevent);
1161 htmldoc_release(&doc->basedoc);
1164 void fire_event(HTMLDocumentNode *doc, eventid_t eid, BOOL set_event, nsIDOMNode *target, nsIDOMEvent *nsevent,
1165 IDispatch *script_this)
1167 HTMLEventObj *event_obj = NULL;
1172 hres = get_node(doc, target, TRUE, &node);
1176 event_obj = create_event();
1181 hres = set_event_info(event_obj, node, eid, nsevent);
1183 IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
1188 fire_event_obj(doc, eid, event_obj, target, script_this);
1191 IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
1194 HRESULT dispatch_event(HTMLDOMNode *node, const WCHAR *event_name, VARIANT *event_var, VARIANT_BOOL *cancelled)
1196 HTMLEventObj *event_obj = NULL;
1200 eid = attr_to_eid(event_name);
1201 if(eid == EVENTID_LAST) {
1202 WARN("unknown event %s\n", debugstr_w(event_name));
1203 return E_INVALIDARG;
1206 if(event_var && V_VT(event_var) != VT_EMPTY && V_VT(event_var) != VT_ERROR) {
1207 if(V_VT(event_var) != VT_DISPATCH) {
1208 FIXME("event_var %s not supported\n", debugstr_variant(event_var));
1212 if(V_DISPATCH(event_var)) {
1213 IHTMLEventObj *event_iface;
1215 hres = IDispatch_QueryInterface(V_DISPATCH(event_var), &IID_IHTMLEventObj, (void**)&event_iface);
1217 FIXME("No IHTMLEventObj iface\n");
1221 event_obj = unsafe_impl_from_IHTMLEventObj(event_iface);
1223 ERR("Not our IHTMLEventObj?\n");
1224 IHTMLEventObj_Release(event_iface);
1231 hres = set_event_info(event_obj, node, eid, NULL);
1233 fire_event_obj(node->doc, eid, event_obj, node->nsnode, NULL);
1235 IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
1239 if(!(event_info[eid].flags & EVENT_DEFAULTLISTENER)) {
1240 FIXME("not EVENT_DEFAULTEVENTHANDLER\n");
1244 fire_event(node->doc, eid, TRUE, node->nsnode, NULL, NULL);
1247 *cancelled = VARIANT_TRUE; /* FIXME */
1251 HRESULT call_fire_event(HTMLDOMNode *node, eventid_t eid)
1255 if(node->vtbl->fire_event) {
1256 BOOL handled = FALSE;
1258 hres = node->vtbl->fire_event(node, eid, &handled);
1263 fire_event(node->doc, eid, TRUE, node->nsnode, NULL, NULL);
1267 static inline event_target_t *get_event_target(event_target_t **event_target_ptr)
1269 if(!*event_target_ptr)
1270 *event_target_ptr = heap_alloc_zero(sizeof(event_target_t));
1271 return *event_target_ptr;
1274 static BOOL alloc_handler_vector(event_target_t *event_target, eventid_t eid, int cnt)
1276 handler_vector_t *new_vector, *handler_vector = event_target->event_table[eid];
1278 if(handler_vector) {
1279 if(cnt <= handler_vector->handler_cnt)
1282 new_vector = heap_realloc_zero(handler_vector, sizeof(handler_vector_t) + sizeof(IDispatch*)*cnt);
1284 new_vector = heap_alloc_zero(sizeof(handler_vector_t) + sizeof(IDispatch*)*cnt);
1290 new_vector->handler_cnt = cnt;
1291 event_target->event_table[eid] = new_vector;
1295 static HRESULT ensure_nsevent_handler(HTMLDocumentNode *doc, event_target_t *event_target, nsIDOMNode *nsnode, eventid_t eid)
1300 if(event_info[eid].flags & EVENT_NODEHANDLER) {
1303 mask = get_node_handler_mask(eid);
1304 if(event_target->node_handlers_mask & mask)
1307 add_nsevent_listener(doc, nsnode, event_info[eid].name);
1308 event_target->node_handlers_mask |= mask;
1312 if(!(event_info[eid].flags & EVENT_DEFAULTLISTENER))
1315 if(!doc->event_vector[eid]) {
1316 doc->event_vector[eid] = TRUE;
1317 add_nsevent_listener(doc, NULL, event_info[eid].name);
1323 void detach_events(HTMLDocumentNode *doc)
1325 if(doc->event_vector) {
1328 for(i=0; i < EVENTID_LAST; i++) {
1329 if(doc->event_vector[i]) {
1330 detach_nsevent(doc, event_info[i].name);
1331 doc->event_vector[i] = FALSE;
1336 release_nsevents(doc);
1340 static HRESULT remove_event_handler(event_target_t **event_target, eventid_t eid)
1342 if(*event_target && (*event_target)->event_table[eid] && (*event_target)->event_table[eid]->handler_prop) {
1343 IDispatch_Release((*event_target)->event_table[eid]->handler_prop);
1344 (*event_target)->event_table[eid]->handler_prop = NULL;
1350 static HRESULT set_event_handler_disp(event_target_t **event_target_ptr, nsIDOMNode *nsnode, HTMLDocumentNode *doc,
1351 eventid_t eid, IDispatch *disp)
1353 event_target_t *event_target;
1356 return remove_event_handler(event_target_ptr, eid);
1358 event_target = get_event_target(event_target_ptr);
1360 return E_OUTOFMEMORY;
1362 if(!alloc_handler_vector(event_target, eid, 0))
1363 return E_OUTOFMEMORY;
1365 if(event_target->event_table[eid]->handler_prop)
1366 IDispatch_Release(event_target->event_table[eid]->handler_prop);
1368 event_target->event_table[eid]->handler_prop = disp;
1369 IDispatch_AddRef(disp);
1371 return ensure_nsevent_handler(doc, event_target, nsnode, eid);
1374 HRESULT set_event_handler(event_target_t **event_target, nsIDOMNode *nsnode, HTMLDocumentNode *doc, eventid_t eid, VARIANT *var)
1378 return remove_event_handler(event_target, eid);
1381 return set_event_handler_disp(event_target, nsnode, doc, eid, V_DISPATCH(var));
1384 FIXME("not handler %s\n", debugstr_variant(var));
1393 HRESULT get_event_handler(event_target_t **event_target, eventid_t eid, VARIANT *var)
1395 if(*event_target && (*event_target)->event_table[eid] && (*event_target)->event_table[eid]->handler_prop) {
1396 V_VT(var) = VT_DISPATCH;
1397 V_DISPATCH(var) = (*event_target)->event_table[eid]->handler_prop;
1398 IDispatch_AddRef(V_DISPATCH(var));
1400 V_VT(var) = VT_NULL;
1406 HRESULT attach_event(event_target_t **event_target_ptr, nsIDOMNode *nsnode, HTMLDocument *doc, BSTR name,
1407 IDispatch *disp, VARIANT_BOOL *res)
1409 event_target_t *event_target;
1413 eid = attr_to_eid(name);
1414 if(eid == EVENTID_LAST) {
1415 WARN("Unknown event\n");
1416 *res = VARIANT_TRUE;
1420 event_target = get_event_target(event_target_ptr);
1422 return E_OUTOFMEMORY;
1424 if(event_target->event_table[eid]) {
1425 while(i < event_target->event_table[eid]->handler_cnt && event_target->event_table[eid]->handlers[i])
1427 if(i == event_target->event_table[eid]->handler_cnt && !alloc_handler_vector(event_target, eid, i+1))
1428 return E_OUTOFMEMORY;
1429 }else if(!alloc_handler_vector(event_target, eid, i+1)) {
1430 return E_OUTOFMEMORY;
1433 IDispatch_AddRef(disp);
1434 event_target->event_table[eid]->handlers[i] = disp;
1436 *res = VARIANT_TRUE;
1437 return ensure_nsevent_handler(doc->doc_node, event_target, nsnode, eid);
1440 HRESULT detach_event(event_target_t *event_target, HTMLDocument *doc, BSTR name, IDispatch *disp)
1448 eid = attr_to_eid(name);
1449 if(eid == EVENTID_LAST) {
1450 WARN("Unknown event\n");
1454 if(!event_target->event_table[eid])
1457 while(i < event_target->event_table[eid]->handler_cnt) {
1458 if(event_target->event_table[eid]->handlers[i] == disp) {
1459 IDispatch_Release(event_target->event_table[eid]->handlers[i]);
1460 event_target->event_table[eid]->handlers[i] = NULL;
1468 void bind_elem_event(HTMLDocumentNode *doc, HTMLElement *elem, const WCHAR *event, IDispatch *disp)
1472 TRACE("(%p %p %s %p)\n", doc, elem, debugstr_w(event), disp);
1474 eid = attr_to_eid(event);
1475 if(eid == EVENTID_LAST) {
1476 WARN("Unsupported event %s\n", debugstr_w(event));
1480 set_event_handler_disp(&elem->node.event_target, elem->node.nsnode, doc, eid, disp);
1483 void update_cp_events(HTMLInnerWindow *window, event_target_t **event_target_ptr, cp_static_data_t *cp, nsIDOMNode *nsnode)
1485 event_target_t *event_target;
1488 event_target = get_event_target(event_target_ptr);
1492 for(i=0; i < EVENTID_LAST; i++) {
1493 if((event_info[i].flags & EVENT_DEFAULTLISTENER) && is_cp_event(cp, event_info[i].dispid))
1494 ensure_nsevent_handler(window->doc, event_target, nsnode, i);
1498 void check_event_attr(HTMLDocumentNode *doc, nsIDOMElement *nselem)
1500 const PRUnichar *attr_value;
1501 nsAString attr_name_str, attr_value_str;
1508 nsAString_Init(&attr_value_str, NULL);
1509 nsAString_Init(&attr_name_str, NULL);
1511 for(i=0; i < EVENTID_LAST; i++) {
1512 nsAString_SetData(&attr_name_str, event_info[i].attr_name);
1513 nsres = nsIDOMElement_GetAttribute(nselem, &attr_name_str, &attr_value_str);
1514 if(NS_SUCCEEDED(nsres)) {
1515 nsAString_GetData(&attr_value_str, &attr_value);
1519 TRACE("%p.%s = %s\n", nselem, debugstr_w(event_info[i].attr_name), debugstr_w(attr_value));
1521 disp = script_parse_event(doc->window, attr_value);
1523 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1524 if(SUCCEEDED(hres)) {
1525 set_event_handler_disp(get_node_event_target(node), node->nsnode, node->doc, i, disp);
1528 IDispatch_Release(disp);
1533 nsAString_Finish(&attr_value_str);
1534 nsAString_Finish(&attr_name_str);
1537 HRESULT doc_init_events(HTMLDocumentNode *doc)
1542 doc->event_vector = heap_alloc_zero(EVENTID_LAST*sizeof(BOOL));
1543 if(!doc->event_vector)
1544 return E_OUTOFMEMORY;
1548 for(i=0; i < EVENTID_LAST; i++) {
1549 if(event_info[i].flags & EVENT_HASDEFAULTHANDLERS) {
1550 hres = ensure_nsevent_handler(doc, NULL, NULL, i);
1559 void release_event_target(event_target_t *event_target)
1563 for(i=0; i < EVENTID_LAST; i++) {
1564 if(event_target->event_table[i]) {
1565 if(event_target->event_table[i]->handler_prop)
1566 IDispatch_Release(event_target->event_table[i]->handler_prop);
1567 for(j=0; j < event_target->event_table[i]->handler_cnt; j++)
1568 if(event_target->event_table[i]->handlers[j])
1569 IDispatch_Release(event_target->event_table[i]->handlers[j]);
1573 heap_free(event_target);