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"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 IDispatch
*handler_prop
;
39 IDispatch
*handlers
[0];
42 struct event_target_t
{
43 DWORD node_handlers_mask
;
44 handler_vector_t
*event_table
[EVENTID_LAST
];
47 static const WCHAR beforeunloadW
[] = {'b','e','f','o','r','e','u','n','l','o','a','d',0};
48 static const WCHAR onbeforeunloadW
[] = {'o','n','b','e','f','o','r','e','u','n','l','o','a','d',0};
50 static const WCHAR blurW
[] = {'b','l','u','r',0};
51 static const WCHAR onblurW
[] = {'o','n','b','l','u','r',0};
53 static const WCHAR changeW
[] = {'c','h','a','n','g','e',0};
54 static const WCHAR onchangeW
[] = {'o','n','c','h','a','n','g','e',0};
56 static const WCHAR clickW
[] = {'c','l','i','c','k',0};
57 static const WCHAR onclickW
[] = {'o','n','c','l','i','c','k',0};
59 static const WCHAR contextmenuW
[] = {'c','o','n','t','e','x','t','m','e','n','u',0};
60 static const WCHAR oncontextmenuW
[] = {'o','n','c','o','n','t','e','x','t','m','e','n','u',0};
62 static const WCHAR dblclickW
[] = {'d','b','l','c','l','i','c','k',0};
63 static const WCHAR ondblclickW
[] = {'o','n','d','b','l','c','l','i','c','k',0};
65 static const WCHAR dragW
[] = {'d','r','a','g',0};
66 static const WCHAR ondragW
[] = {'o','n','d','r','a','g',0};
68 static const WCHAR dragstartW
[] = {'d','r','a','g','s','t','a','r','t',0};
69 static const WCHAR ondragstartW
[] = {'o','n','d','r','a','g','s','t','a','r','t',0};
71 static const WCHAR focusW
[] = {'f','o','c','u','s',0};
72 static const WCHAR onfocusW
[] = {'o','n','f','o','c','u','s',0};
74 static const WCHAR keydownW
[] = {'k','e','y','d','o','w','n',0};
75 static const WCHAR onkeydownW
[] = {'o','n','k','e','y','d','o','w','n',0};
77 static const WCHAR keyupW
[] = {'k','e','y','u','p',0};
78 static const WCHAR onkeyupW
[] = {'o','n','k','e','y','u','p',0};
80 static const WCHAR loadW
[] = {'l','o','a','d',0};
81 static const WCHAR onloadW
[] = {'o','n','l','o','a','d',0};
83 static const WCHAR mousedownW
[] = {'m','o','u','s','e','d','o','w','n',0};
84 static const WCHAR onmousedownW
[] = {'o','n','m','o','u','s','e','d','o','w','n',0};
86 static const WCHAR mousemoveW
[] = {'m','o','u','s','e','m','o','v','e',0};
87 static const WCHAR onmousemoveW
[] = {'o','n','m','o','u','s','e','m','o','v','e',0};
89 static const WCHAR mouseoutW
[] = {'m','o','u','s','e','o','u','t',0};
90 static const WCHAR onmouseoutW
[] = {'o','n','m','o','u','s','e','o','u','t',0};
92 static const WCHAR mouseoverW
[] = {'m','o','u','s','e','o','v','e','r',0};
93 static const WCHAR onmouseoverW
[] = {'o','n','m','o','u','s','e','o','v','e','r',0};
95 static const WCHAR mouseupW
[] = {'m','o','u','s','e','u','p',0};
96 static const WCHAR onmouseupW
[] = {'o','n','m','o','u','s','e','u','p',0};
98 static const WCHAR pasteW
[] = {'p','a','s','t','e',0};
99 static const WCHAR onpasteW
[] = {'o','n','p','a','s','t','e',0};
101 static const WCHAR readystatechangeW
[] = {'r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
102 static const WCHAR onreadystatechangeW
[] = {'o','n','r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
104 static const WCHAR resizeW
[] = {'r','e','s','i','z','e',0};
105 static const WCHAR onresizeW
[] = {'o','n','r','e','s','i','z','e',0};
107 static const WCHAR selectstartW
[] = {'s','e','l','e','c','t','s','t','a','r','t',0};
108 static const WCHAR onselectstartW
[] = {'o','n','s','e','l','e','c','t','s','t','a','r','t',0};
110 static const WCHAR submitW
[] = {'s','u','b','m','i','t',0};
111 static const WCHAR onsubmitW
[] = {'o','n','s','u','b','m','i','t',0};
113 static const WCHAR HTMLEventsW
[] = {'H','T','M','L','E','v','e','n','t','s',0};
114 static const WCHAR KeyboardEventW
[] = {'K','e','y','b','o','a','r','d','E','v','e','n','t',0};
115 static const WCHAR MouseEventW
[] = {'M','o','u','s','e','E','v','e','n','t',0};
124 static const WCHAR
*event_types
[] = {
139 #define EVENT_DEFAULTLISTENER 0x0001
140 #define EVENT_BUBBLE 0x0002
141 #define EVENT_FORWARDBODY 0x0004
142 #define EVENT_NODEHANDLER 0x0008
143 #define EVENT_CANCELABLE 0x0010
144 #define EVENT_HASDEFAULTHANDLERS 0x0020
146 static const event_info_t event_info
[] = {
147 {beforeunloadW
, onbeforeunloadW
, EVENTT_NONE
, DISPID_EVMETH_ONBEFOREUNLOAD
,
148 EVENT_DEFAULTLISTENER
|EVENT_FORWARDBODY
},
149 {blurW
, onblurW
, EVENTT_HTML
, DISPID_EVMETH_ONBLUR
,
150 EVENT_DEFAULTLISTENER
},
151 {changeW
, onchangeW
, EVENTT_HTML
, DISPID_EVMETH_ONCHANGE
,
152 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
153 {clickW
, onclickW
, EVENTT_MOUSE
, DISPID_EVMETH_ONCLICK
,
154 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
|EVENT_CANCELABLE
|EVENT_HASDEFAULTHANDLERS
},
155 {contextmenuW
, oncontextmenuW
, EVENTT_MOUSE
, DISPID_EVMETH_ONCONTEXTMENU
,
156 EVENT_BUBBLE
|EVENT_CANCELABLE
},
157 {dblclickW
, ondblclickW
, EVENTT_MOUSE
, DISPID_EVMETH_ONDBLCLICK
,
158 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
|EVENT_CANCELABLE
},
159 {dragW
, ondragW
, EVENTT_MOUSE
, DISPID_EVMETH_ONDRAG
,
161 {dragstartW
, ondragstartW
, EVENTT_MOUSE
, DISPID_EVMETH_ONDRAGSTART
,
163 {focusW
, onfocusW
, EVENTT_HTML
, DISPID_EVMETH_ONFOCUS
,
164 EVENT_DEFAULTLISTENER
},
165 {keydownW
, onkeydownW
, EVENTT_KEY
, DISPID_EVMETH_ONKEYDOWN
,
166 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
167 {keyupW
, onkeyupW
, EVENTT_KEY
, DISPID_EVMETH_ONKEYUP
,
168 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
169 {loadW
, onloadW
, EVENTT_HTML
, DISPID_EVMETH_ONLOAD
,
171 {mousedownW
, onmousedownW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEDOWN
,
172 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
173 {mousemoveW
, onmousemoveW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEMOVE
,
174 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
175 {mouseoutW
, onmouseoutW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEOUT
,
176 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
177 {mouseoverW
, onmouseoverW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEOVER
,
178 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
179 {mouseupW
, onmouseupW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEUP
,
180 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
181 {pasteW
, onpasteW
, EVENTT_NONE
, DISPID_EVMETH_ONPASTE
,
183 {readystatechangeW
, onreadystatechangeW
, EVENTT_NONE
, DISPID_EVMETH_ONREADYSTATECHANGE
,
185 {resizeW
, onresizeW
, EVENTT_NONE
, DISPID_EVMETH_ONRESIZE
,
186 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
187 {selectstartW
, onselectstartW
, EVENTT_MOUSE
, DISPID_EVMETH_ONSELECTSTART
,
189 {submitW
, onsubmitW
, EVENTT_HTML
, DISPID_EVMETH_ONSUBMIT
,
190 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
|EVENT_CANCELABLE
}
193 static const eventid_t node_handled_list
[] = { EVENTID_LOAD
};
195 eventid_t
str_to_eid(LPCWSTR str
)
199 for(i
=0; i
< sizeof(event_info
)/sizeof(event_info
[0]); i
++) {
200 if(!strcmpW(event_info
[i
].name
, str
))
204 ERR("unknown type %s\n", debugstr_w(str
));
208 static eventid_t
attr_to_eid(LPCWSTR str
)
212 for(i
=0; i
< sizeof(event_info
)/sizeof(event_info
[0]); i
++) {
213 if(!strcmpW(event_info
[i
].attr_name
, str
))
220 static DWORD
get_node_handler_mask(eventid_t eid
)
224 for(i
=0; i
<sizeof(node_handled_list
)/sizeof(*node_handled_list
); i
++) {
225 if(node_handled_list
[i
] == eid
)
229 ERR("Invalid eid %d\n", eid
);
235 IHTMLEventObj IHTMLEventObj_iface
;
240 const event_info_t
*type
;
241 nsIDOMEvent
*nsevent
;
242 BOOL prevent_default
;
245 static inline HTMLEventObj
*impl_from_IHTMLEventObj(IHTMLEventObj
*iface
)
247 return CONTAINING_RECORD(iface
, HTMLEventObj
, IHTMLEventObj_iface
);
250 static HRESULT WINAPI
HTMLEventObj_QueryInterface(IHTMLEventObj
*iface
, REFIID riid
, void **ppv
)
252 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
256 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
257 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
258 *ppv
= &This
->IHTMLEventObj_iface
;
259 }else if(IsEqualGUID(&IID_IHTMLEventObj
, riid
)) {
260 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This
, ppv
);
261 *ppv
= &This
->IHTMLEventObj_iface
;
262 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
263 return *ppv
? S_OK
: E_NOINTERFACE
;
267 IUnknown_AddRef((IUnknown
*)*ppv
);
271 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
272 return E_NOINTERFACE
;
275 static ULONG WINAPI
HTMLEventObj_AddRef(IHTMLEventObj
*iface
)
277 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
278 LONG ref
= InterlockedIncrement(&This
->ref
);
280 TRACE("(%p) ref=%d\n", This
, ref
);
285 static ULONG WINAPI
HTMLEventObj_Release(IHTMLEventObj
*iface
)
287 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
288 LONG ref
= InterlockedDecrement(&This
->ref
);
290 TRACE("(%p) ref=%d\n", This
, ref
);
294 IHTMLDOMNode_Release(&This
->target
->IHTMLDOMNode_iface
);
296 nsIDOMEvent_Release(This
->nsevent
);
297 release_dispex(&This
->dispex
);
304 static HRESULT WINAPI
HTMLEventObj_GetTypeInfoCount(IHTMLEventObj
*iface
, UINT
*pctinfo
)
306 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
307 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
310 static HRESULT WINAPI
HTMLEventObj_GetTypeInfo(IHTMLEventObj
*iface
, UINT iTInfo
,
311 LCID lcid
, ITypeInfo
**ppTInfo
)
313 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
314 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
317 static HRESULT WINAPI
HTMLEventObj_GetIDsOfNames(IHTMLEventObj
*iface
, REFIID riid
,
318 LPOLESTR
*rgszNames
, UINT cNames
,
319 LCID lcid
, DISPID
*rgDispId
)
321 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
322 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
326 static HRESULT WINAPI
HTMLEventObj_Invoke(IHTMLEventObj
*iface
, DISPID dispIdMember
,
327 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
328 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
330 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
331 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
332 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
335 static HRESULT WINAPI
HTMLEventObj_get_srcElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
337 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
339 TRACE("(%p)->(%p)\n", This
, p
);
341 return IHTMLDOMNode_QueryInterface(&This
->target
->IHTMLDOMNode_iface
, &IID_IHTMLElement
,
345 static HRESULT WINAPI
HTMLEventObj_get_altKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
347 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
348 cpp_bool ret
= FALSE
;
350 TRACE("(%p)->(%p)\n", This
, p
);
353 nsIDOMKeyEvent
*key_event
;
356 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
357 if(NS_SUCCEEDED(nsres
)) {
358 nsIDOMKeyEvent_GetAltKey(key_event
, &ret
);
359 nsIDOMKeyEvent_Release(key_event
);
361 nsIDOMMouseEvent
*mouse_event
;
363 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
364 if(NS_SUCCEEDED(nsres
)) {
365 nsIDOMMouseEvent_GetAltKey(mouse_event
, &ret
);
366 nsIDOMMouseEvent_Release(mouse_event
);
371 *p
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
375 static HRESULT WINAPI
HTMLEventObj_get_ctrlKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
377 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
378 cpp_bool ret
= FALSE
;
380 TRACE("(%p)->(%p)\n", This
, p
);
383 nsIDOMKeyEvent
*key_event
;
386 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
387 if(NS_SUCCEEDED(nsres
)) {
388 nsIDOMKeyEvent_GetCtrlKey(key_event
, &ret
);
389 nsIDOMKeyEvent_Release(key_event
);
391 nsIDOMMouseEvent
*mouse_event
;
393 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
394 if(NS_SUCCEEDED(nsres
)) {
395 nsIDOMMouseEvent_GetCtrlKey(mouse_event
, &ret
);
396 nsIDOMMouseEvent_Release(mouse_event
);
401 *p
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
405 static HRESULT WINAPI
HTMLEventObj_get_shiftKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
407 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
408 cpp_bool ret
= FALSE
;
410 TRACE("(%p)->(%p)\n", This
, p
);
413 nsIDOMKeyEvent
*key_event
;
416 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
417 if(NS_SUCCEEDED(nsres
)) {
418 nsIDOMKeyEvent_GetShiftKey(key_event
, &ret
);
419 nsIDOMKeyEvent_Release(key_event
);
421 nsIDOMMouseEvent
*mouse_event
;
423 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
424 if(NS_SUCCEEDED(nsres
)) {
425 nsIDOMMouseEvent_GetShiftKey(mouse_event
, &ret
);
426 nsIDOMMouseEvent_Release(mouse_event
);
431 *p
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
435 static HRESULT WINAPI
HTMLEventObj_put_returnValue(IHTMLEventObj
*iface
, VARIANT v
)
437 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
439 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
441 if(V_VT(&v
) != VT_BOOL
) {
442 FIXME("unsupported vt %d\n", V_VT(&v
));
443 return DISP_E_BADVARTYPE
;
447 This
->prevent_default
= TRUE
;
451 static HRESULT WINAPI
HTMLEventObj_get_returnValue(IHTMLEventObj
*iface
, VARIANT
*p
)
453 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
455 FIXME("(%p)->(%p)\n", This
, p
);
461 static HRESULT WINAPI
HTMLEventObj_put_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL v
)
463 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
464 FIXME("(%p)->(%x)\n", This
, v
);
468 static HRESULT WINAPI
HTMLEventObj_get_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
470 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
472 FIXME("(%p)->(%p)\n", This
, p
);
478 static HRESULT WINAPI
HTMLEventObj_get_fromElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
480 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
482 FIXME("(%p)->(%p)\n", This
, p
);
488 static HRESULT WINAPI
HTMLEventObj_get_toElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
490 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
492 FIXME("(%p)->(%p)\n", This
, p
);
498 static HRESULT WINAPI
HTMLEventObj_put_keyCode(IHTMLEventObj
*iface
, LONG v
)
500 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
501 FIXME("(%p)->(%d)\n", This
, v
);
505 static HRESULT WINAPI
HTMLEventObj_get_keyCode(IHTMLEventObj
*iface
, LONG
*p
)
507 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
508 PRUint32 key_code
= 0;
510 TRACE("(%p)->(%p)\n", This
, p
);
513 nsIDOMKeyEvent
*key_event
;
516 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
517 if(NS_SUCCEEDED(nsres
)) {
518 nsIDOMKeyEvent_GetKeyCode(key_event
, &key_code
);
519 nsIDOMKeyEvent_Release(key_event
);
527 static HRESULT WINAPI
HTMLEventObj_get_button(IHTMLEventObj
*iface
, LONG
*p
)
529 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
532 TRACE("(%p)->(%p)\n", This
, p
);
535 nsIDOMMouseEvent
*mouse_event
;
538 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
539 if(NS_SUCCEEDED(nsres
)) {
540 nsIDOMMouseEvent_GetButton(mouse_event
, &button
);
541 nsIDOMMouseEvent_Release(mouse_event
);
549 static HRESULT WINAPI
HTMLEventObj_get_type(IHTMLEventObj
*iface
, BSTR
*p
)
551 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
553 TRACE("(%p)->(%p)\n", This
, p
);
555 *p
= SysAllocString(This
->type
->name
);
556 return *p
? S_OK
: E_OUTOFMEMORY
;
559 static HRESULT WINAPI
HTMLEventObj_get_qualifier(IHTMLEventObj
*iface
, BSTR
*p
)
561 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
563 FIXME("(%p)->(%p)\n", This
, p
);
569 static HRESULT WINAPI
HTMLEventObj_get_reason(IHTMLEventObj
*iface
, LONG
*p
)
571 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
573 FIXME("(%p)->(%p)\n", This
, p
);
579 static HRESULT WINAPI
HTMLEventObj_get_x(IHTMLEventObj
*iface
, LONG
*p
)
581 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
583 FIXME("(%p)->(%p)\n", This
, p
);
589 static HRESULT WINAPI
HTMLEventObj_get_y(IHTMLEventObj
*iface
, LONG
*p
)
591 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
593 FIXME("(%p)->(%p)\n", This
, p
);
599 static HRESULT WINAPI
HTMLEventObj_get_clientX(IHTMLEventObj
*iface
, LONG
*p
)
601 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
604 TRACE("(%p)->(%p)\n", This
, p
);
607 nsIDOMMouseEvent
*mouse_event
;
610 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
611 if(NS_SUCCEEDED(nsres
)) {
612 nsIDOMMouseEvent_GetClientX(mouse_event
, &x
);
613 nsIDOMMouseEvent_Release(mouse_event
);
621 static HRESULT WINAPI
HTMLEventObj_get_clientY(IHTMLEventObj
*iface
, LONG
*p
)
623 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
626 TRACE("(%p)->(%p)\n", This
, p
);
629 nsIDOMMouseEvent
*mouse_event
;
632 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
633 if(NS_SUCCEEDED(nsres
)) {
634 nsIDOMMouseEvent_GetClientY(mouse_event
, &y
);
635 nsIDOMMouseEvent_Release(mouse_event
);
643 static HRESULT WINAPI
HTMLEventObj_get_offsetX(IHTMLEventObj
*iface
, LONG
*p
)
645 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
647 FIXME("(%p)->(%p)\n", This
, p
);
653 static HRESULT WINAPI
HTMLEventObj_get_offsetY(IHTMLEventObj
*iface
, LONG
*p
)
655 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
657 FIXME("(%p)->(%p)\n", This
, p
);
663 static HRESULT WINAPI
HTMLEventObj_get_screenX(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_GetScreenX(mouse_event
, &x
);
677 nsIDOMMouseEvent_Release(mouse_event
);
685 static HRESULT WINAPI
HTMLEventObj_get_screenY(IHTMLEventObj
*iface
, LONG
*p
)
687 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
690 TRACE("(%p)->(%p)\n", This
, p
);
693 nsIDOMMouseEvent
*mouse_event
;
696 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
697 if(NS_SUCCEEDED(nsres
)) {
698 nsIDOMMouseEvent_GetScreenY(mouse_event
, &y
);
699 nsIDOMMouseEvent_Release(mouse_event
);
707 static HRESULT WINAPI
HTMLEventObj_get_srcFilter(IHTMLEventObj
*iface
, IDispatch
**p
)
709 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
711 FIXME("(%p)->(%p)\n", This
, p
);
717 static const IHTMLEventObjVtbl HTMLEventObjVtbl
= {
718 HTMLEventObj_QueryInterface
,
720 HTMLEventObj_Release
,
721 HTMLEventObj_GetTypeInfoCount
,
722 HTMLEventObj_GetTypeInfo
,
723 HTMLEventObj_GetIDsOfNames
,
725 HTMLEventObj_get_srcElement
,
726 HTMLEventObj_get_altKey
,
727 HTMLEventObj_get_ctrlKey
,
728 HTMLEventObj_get_shiftKey
,
729 HTMLEventObj_put_returnValue
,
730 HTMLEventObj_get_returnValue
,
731 HTMLEventObj_put_cancelBubble
,
732 HTMLEventObj_get_cancelBubble
,
733 HTMLEventObj_get_fromElement
,
734 HTMLEventObj_get_toElement
,
735 HTMLEventObj_put_keyCode
,
736 HTMLEventObj_get_keyCode
,
737 HTMLEventObj_get_button
,
738 HTMLEventObj_get_type
,
739 HTMLEventObj_get_qualifier
,
740 HTMLEventObj_get_reason
,
743 HTMLEventObj_get_clientX
,
744 HTMLEventObj_get_clientY
,
745 HTMLEventObj_get_offsetX
,
746 HTMLEventObj_get_offsetY
,
747 HTMLEventObj_get_screenX
,
748 HTMLEventObj_get_screenY
,
749 HTMLEventObj_get_srcFilter
752 static const tid_t HTMLEventObj_iface_tids
[] = {
757 static dispex_static_data_t HTMLEventObj_dispex
= {
761 HTMLEventObj_iface_tids
764 static HTMLEventObj
*create_event(HTMLDOMNode
*target
, eventid_t eid
, nsIDOMEvent
*nsevent
)
768 ret
= heap_alloc_zero(sizeof(*ret
));
772 ret
->IHTMLEventObj_iface
.lpVtbl
= &HTMLEventObjVtbl
;
774 ret
->type
= event_info
+eid
;
776 ret
->nsevent
= nsevent
;
778 nsIDOMEvent_AddRef(nsevent
);
779 }else if(event_types
[event_info
[eid
].type
]) {
783 nsAString_InitDepend(&type_str
, event_types
[event_info
[eid
].type
]);
784 nsres
= nsIDOMHTMLDocument_CreateEvent(target
->doc
->nsdoc
, &type_str
, &ret
->nsevent
);
785 nsAString_Finish(&type_str
);
786 if(NS_FAILED(nsres
)) {
787 ERR("Could not create event: %08x\n", nsres
);
788 IHTMLEventObj_Release(&ret
->IHTMLEventObj_iface
);
793 ret
->target
= target
;
794 IHTMLDOMNode_AddRef(&target
->IHTMLDOMNode_iface
);
796 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLEventObj_iface
, &HTMLEventObj_dispex
);
801 static HRESULT
call_disp_func(IDispatch
*disp
, DISPPARAMS
*dp
, VARIANT
*retv
)
807 memset(&ei
, 0, sizeof(ei
));
809 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
810 if(SUCCEEDED(hres
)) {
811 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, dp
, retv
, &ei
, NULL
);
812 IDispatchEx_Release(dispex
);
814 TRACE("Could not get IDispatchEx interface: %08x\n", hres
);
815 hres
= IDispatch_Invoke(disp
, 0, &IID_NULL
, GetUserDefaultLCID(), DISPATCH_METHOD
,
816 dp
, retv
, &ei
, NULL
);
822 static HRESULT
call_cp_func(IDispatch
*disp
, DISPID dispid
, VARIANT
*retv
)
824 DISPPARAMS dp
= {NULL
,NULL
,0,0};
828 memset(&ei
, 0, sizeof(ei
));
829 return IDispatch_Invoke(disp
, dispid
, &IID_NULL
, 0, DISPATCH_METHOD
, &dp
, retv
, &ei
, &argerr
);
832 static BOOL
is_cp_event(cp_static_data_t
*data
, DISPID dispid
)
841 hres
= get_dispids(data
->tid
, &data
->id_cnt
, &data
->ids
);
847 max
= data
->id_cnt
-1;
850 if(data
->ids
[i
] == dispid
)
853 if(data
->ids
[i
] < dispid
)
862 static void call_event_handlers(HTMLDocumentNode
*doc
, HTMLEventObj
*event_obj
, event_target_t
*event_target
,
863 ConnectionPointContainer
*cp_container
, eventid_t eid
, IDispatch
*this_obj
)
865 const BOOL cancelable
= event_info
[eid
].flags
& EVENT_CANCELABLE
;
866 handler_vector_t
*handler_vector
= NULL
;
872 handler_vector
= event_target
->event_table
[eid
];
874 if(handler_vector
&& handler_vector
->handler_prop
) {
875 DISPID named_arg
= DISPID_THIS
;
877 DISPPARAMS dp
= {&arg
, &named_arg
, 1, 1};
879 V_VT(&arg
) = VT_DISPATCH
;
880 V_DISPATCH(&arg
) = this_obj
;
883 TRACE("%s >>>\n", debugstr_w(event_info
[eid
].name
));
884 hres
= call_disp_func(handler_vector
->handler_prop
, &dp
, &v
);
886 TRACE("%s <<< %s\n", debugstr_w(event_info
[eid
].name
), debugstr_variant(&v
));
889 if(V_VT(&v
) == VT_BOOL
) {
891 event_obj
->prevent_default
= TRUE
;
892 }else if(V_VT(&v
) != VT_EMPTY
) {
893 FIXME("unhandled result %s\n", debugstr_variant(&v
));
898 WARN("%s <<< %08x\n", debugstr_w(event_info
[eid
].name
), hres
);
902 if(handler_vector
&& handler_vector
->handler_cnt
) {
904 DISPPARAMS dp
= {&arg
, NULL
, 1, 0};
906 V_VT(&arg
) = VT_DISPATCH
;
907 V_DISPATCH(&arg
) = (IDispatch
*)event_obj
;
909 i
= handler_vector
->handler_cnt
;
911 if(handler_vector
->handlers
[i
]) {
914 TRACE("%s [%d] >>>\n", debugstr_w(event_info
[eid
].name
), i
);
915 hres
= call_disp_func(handler_vector
->handlers
[i
], &dp
, &v
);
917 TRACE("%s [%d] <<<\n", debugstr_w(event_info
[eid
].name
), i
);
920 if(V_VT(&v
) == VT_BOOL
) {
922 event_obj
->prevent_default
= TRUE
;
923 }else if(V_VT(&v
) != VT_EMPTY
) {
924 FIXME("unhandled result %s\n", debugstr_variant(&v
));
929 WARN("%s [%d] <<< %08x\n", debugstr_w(event_info
[eid
].name
), i
, hres
);
938 if(cp_container
->forward_container
)
939 cp_container
= cp_container
->forward_container
;
941 for(cp
= cp_container
->cp_list
; cp
; cp
= cp
->next
) {
942 if(cp
->sinks_size
&& is_cp_event(cp
->data
, event_info
[eid
].dispid
)) {
943 for(i
=0; i
< cp
->sinks_size
; i
++) {
944 if(!cp
->sinks
[i
].disp
)
949 TRACE("cp %s [%d] >>>\n", debugstr_w(event_info
[eid
].name
), i
);
950 hres
= call_cp_func(cp
->sinks
[i
].disp
, event_info
[eid
].dispid
, &v
);
952 TRACE("cp %s [%d] <<<\n", debugstr_w(event_info
[eid
].name
), i
);
955 if(V_VT(&v
) == VT_BOOL
) {
957 event_obj
->prevent_default
= TRUE
;
958 }else if(V_VT(&v
) != VT_EMPTY
) {
959 FIXME("unhandled result %s\n", debugstr_variant(&v
));
964 WARN("cp %s [%d] <<< %08x\n", debugstr_w(event_info
[eid
].name
), i
, hres
);
972 void fire_event(HTMLDocumentNode
*doc
, eventid_t eid
, BOOL set_event
, nsIDOMNode
*target
, nsIDOMEvent
*nsevent
)
974 HTMLEventObj
*event_obj
= NULL
;
975 IHTMLEventObj
*prev_event
;
976 nsIDOMNode
*parent
, *nsnode
;
977 BOOL prevent_default
= FALSE
;
983 TRACE("(%p) %s\n", doc
, debugstr_w(event_info
[eid
].name
));
985 prev_event
= doc
->basedoc
.window
->event
;
987 hres
= get_node(doc
, target
, TRUE
, &node
);
991 event_obj
= create_event(node
, eid
, nsevent
);
992 doc
->basedoc
.window
->event
= &event_obj
->IHTMLEventObj_iface
;
994 doc
->basedoc
.window
->event
= NULL
;
997 nsIDOMNode_GetNodeType(target
, &node_type
);
999 nsIDOMNode_AddRef(nsnode
);
1004 hres
= get_node(doc
, nsnode
, FALSE
, &node
);
1005 if(SUCCEEDED(hres
) && node
)
1006 call_event_handlers(doc
, event_obj
, *get_node_event_target(node
),
1007 node
->cp_container
, eid
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1009 if(!(event_info
[eid
].flags
& EVENT_BUBBLE
))
1012 nsIDOMNode_GetParentNode(nsnode
, &parent
);
1013 nsIDOMNode_Release(nsnode
);
1018 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1019 }while(node_type
== ELEMENT_NODE
);
1021 if(!(event_info
[eid
].flags
& EVENT_BUBBLE
))
1025 if(event_info
[eid
].flags
& EVENT_FORWARDBODY
) {
1026 nsIDOMHTMLElement
*nsbody
;
1029 nsres
= nsIDOMHTMLDocument_GetBody(doc
->nsdoc
, &nsbody
);
1030 if(NS_SUCCEEDED(nsres
) && nsbody
) {
1031 hres
= get_node(doc
, (nsIDOMNode
*)nsbody
, FALSE
, &node
);
1032 if(SUCCEEDED(hres
) && node
)
1033 call_event_handlers(doc
, event_obj
, *get_node_event_target(node
),
1034 node
->cp_container
, eid
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1035 nsIDOMHTMLElement_Release(nsbody
);
1037 ERR("Could not get body: %08x\n", nsres
);
1041 call_event_handlers(doc
, event_obj
, doc
->node
.event_target
, &doc
->basedoc
.cp_container
, eid
,
1042 (IDispatch
*)&doc
->basedoc
.IHTMLDocument2_iface
);
1046 FIXME("unimplemented node type %d\n", node_type
);
1050 nsIDOMNode_Release(nsnode
);
1052 if(event_obj
&& event_obj
->prevent_default
)
1053 prevent_default
= TRUE
;
1054 doc
->basedoc
.window
->event
= prev_event
;
1056 IHTMLEventObj_Release(&event_obj
->IHTMLEventObj_iface
);
1058 if(!prevent_default
&& (event_info
[eid
].flags
& EVENT_HASDEFAULTHANDLERS
)) {
1059 nsIDOMNode_AddRef(target
);
1063 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
1067 if(node
&& node
->vtbl
->handle_event
) {
1068 hres
= node
->vtbl
->handle_event(node
, eid
, nsevent
, &prevent_default
);
1069 if(FAILED(hres
) || prevent_default
)
1073 nsres
= nsIDOMNode_GetParentNode(nsnode
, &parent
);
1074 if(NS_FAILED(nsres
))
1077 nsIDOMNode_Release(nsnode
);
1082 nsIDOMNode_Release(nsnode
);
1085 if(prevent_default
&& nsevent
) {
1086 TRACE("calling PreventDefault\n");
1087 nsIDOMEvent_PreventDefault(nsevent
);
1091 HRESULT
dispatch_event(HTMLDOMNode
*node
, const WCHAR
*event_name
, VARIANT
*event_obj
, VARIANT_BOOL
*cancelled
)
1095 eid
= attr_to_eid(event_name
);
1096 if(eid
== EVENTID_LAST
) {
1097 WARN("unknown event %s\n", debugstr_w(event_name
));
1098 return E_INVALIDARG
;
1101 if(event_obj
&& V_VT(event_obj
) != VT_EMPTY
&& V_VT(event_obj
) != VT_ERROR
)
1102 FIXME("event_obj not implemented\n");
1104 if(!(event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
)) {
1105 FIXME("not EVENT_DEFAULTEVENTHANDLER\n");
1109 fire_event(node
->doc
, eid
, TRUE
, node
->nsnode
, NULL
);
1111 *cancelled
= VARIANT_TRUE
; /* FIXME */
1115 HRESULT
call_fire_event(HTMLDOMNode
*node
, eventid_t eid
)
1119 if(node
->vtbl
->fire_event
) {
1120 BOOL handled
= FALSE
;
1122 hres
= node
->vtbl
->fire_event(node
, eid
, &handled
);
1127 fire_event(node
->doc
, eid
, TRUE
, node
->nsnode
, NULL
);
1131 static inline event_target_t
*get_event_target(event_target_t
**event_target_ptr
)
1133 if(!*event_target_ptr
)
1134 *event_target_ptr
= heap_alloc_zero(sizeof(event_target_t
));
1135 return *event_target_ptr
;
1138 static BOOL
alloc_handler_vector(event_target_t
*event_target
, eventid_t eid
, int cnt
)
1140 handler_vector_t
*new_vector
, *handler_vector
= event_target
->event_table
[eid
];
1142 if(handler_vector
) {
1143 if(cnt
<= handler_vector
->handler_cnt
)
1146 new_vector
= heap_realloc_zero(handler_vector
, sizeof(handler_vector_t
) + sizeof(IDispatch
*)*cnt
);
1148 new_vector
= heap_alloc_zero(sizeof(handler_vector_t
) + sizeof(IDispatch
*)*cnt
);
1154 new_vector
->handler_cnt
= cnt
;
1155 event_target
->event_table
[eid
] = new_vector
;
1159 static HRESULT
ensure_nsevent_handler(HTMLDocumentNode
*doc
, event_target_t
*event_target
, nsIDOMNode
*nsnode
, eventid_t eid
)
1164 if(event_info
[eid
].flags
& EVENT_NODEHANDLER
) {
1167 mask
= get_node_handler_mask(eid
);
1168 if(event_target
->node_handlers_mask
& mask
)
1171 add_nsevent_listener(doc
, nsnode
, event_info
[eid
].name
);
1172 event_target
->node_handlers_mask
|= mask
;
1176 if(!(event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
))
1179 if(!doc
->event_vector
[eid
]) {
1180 doc
->event_vector
[eid
] = TRUE
;
1181 add_nsevent_listener(doc
, NULL
, event_info
[eid
].name
);
1187 void detach_events(HTMLDocumentNode
*doc
)
1191 if(!doc
->event_vector
)
1194 for(i
=0; i
< EVENTID_LAST
; i
++) {
1195 if(doc
->event_vector
[i
])
1196 detach_nsevent(doc
, event_info
[i
].name
);
1201 static HRESULT
remove_event_handler(event_target_t
**event_target
, eventid_t eid
)
1203 if(*event_target
&& (*event_target
)->event_table
[eid
] && (*event_target
)->event_table
[eid
]->handler_prop
) {
1204 IDispatch_Release((*event_target
)->event_table
[eid
]->handler_prop
);
1205 (*event_target
)->event_table
[eid
]->handler_prop
= NULL
;
1211 static HRESULT
set_event_handler_disp(event_target_t
**event_target_ptr
, nsIDOMNode
*nsnode
, HTMLDocumentNode
*doc
,
1212 eventid_t eid
, IDispatch
*disp
)
1214 event_target_t
*event_target
;
1217 return remove_event_handler(event_target_ptr
, eid
);
1219 event_target
= get_event_target(event_target_ptr
);
1221 return E_OUTOFMEMORY
;
1223 if(!alloc_handler_vector(event_target
, eid
, 0))
1224 return E_OUTOFMEMORY
;
1226 if(event_target
->event_table
[eid
]->handler_prop
)
1227 IDispatch_Release(event_target
->event_table
[eid
]->handler_prop
);
1229 event_target
->event_table
[eid
]->handler_prop
= disp
;
1230 IDispatch_AddRef(disp
);
1232 return ensure_nsevent_handler(doc
, event_target
, nsnode
, eid
);
1235 HRESULT
set_event_handler(event_target_t
**event_target
, nsIDOMNode
*nsnode
, HTMLDocumentNode
*doc
, eventid_t eid
, VARIANT
*var
)
1239 return remove_event_handler(event_target
, eid
);
1242 return set_event_handler_disp(event_target
, nsnode
, doc
, eid
, V_DISPATCH(var
));
1245 FIXME("not supported vt=%d\n", V_VT(var
));
1254 HRESULT
get_event_handler(event_target_t
**event_target
, eventid_t eid
, VARIANT
*var
)
1256 if(*event_target
&& (*event_target
)->event_table
[eid
] && (*event_target
)->event_table
[eid
]->handler_prop
) {
1257 V_VT(var
) = VT_DISPATCH
;
1258 V_DISPATCH(var
) = (*event_target
)->event_table
[eid
]->handler_prop
;
1259 IDispatch_AddRef(V_DISPATCH(var
));
1261 V_VT(var
) = VT_NULL
;
1267 HRESULT
attach_event(event_target_t
**event_target_ptr
, nsIDOMNode
*nsnode
, HTMLDocument
*doc
, BSTR name
,
1268 IDispatch
*disp
, VARIANT_BOOL
*res
)
1270 event_target_t
*event_target
;
1274 eid
= attr_to_eid(name
);
1275 if(eid
== EVENTID_LAST
) {
1276 WARN("Unknown event\n");
1277 *res
= VARIANT_TRUE
;
1281 event_target
= get_event_target(event_target_ptr
);
1283 return E_OUTOFMEMORY
;
1285 if(event_target
->event_table
[eid
]) {
1286 while(i
< event_target
->event_table
[eid
]->handler_cnt
&& event_target
->event_table
[eid
]->handlers
[i
])
1288 if(i
== event_target
->event_table
[eid
]->handler_cnt
&& !alloc_handler_vector(event_target
, eid
, i
+1))
1289 return E_OUTOFMEMORY
;
1290 }else if(!alloc_handler_vector(event_target
, eid
, i
+1)) {
1291 return E_OUTOFMEMORY
;
1294 IDispatch_AddRef(disp
);
1295 event_target
->event_table
[eid
]->handlers
[i
] = disp
;
1297 *res
= VARIANT_TRUE
;
1298 return ensure_nsevent_handler(doc
->doc_node
, event_target
, nsnode
, eid
);
1301 HRESULT
detach_event(event_target_t
*event_target
, HTMLDocument
*doc
, BSTR name
, IDispatch
*disp
)
1309 eid
= attr_to_eid(name
);
1310 if(eid
== EVENTID_LAST
) {
1311 WARN("Unknown event\n");
1315 if(!event_target
->event_table
[eid
])
1318 while(i
< event_target
->event_table
[eid
]->handler_cnt
) {
1319 if(event_target
->event_table
[eid
]->handlers
[i
] == disp
) {
1320 IDispatch_Release(event_target
->event_table
[eid
]->handlers
[i
]);
1321 event_target
->event_table
[eid
]->handlers
[i
] = NULL
;
1329 void update_cp_events(HTMLWindow
*window
, event_target_t
**event_target_ptr
, cp_static_data_t
*cp
, nsIDOMNode
*nsnode
)
1331 event_target_t
*event_target
;
1334 event_target
= get_event_target(event_target_ptr
);
1338 for(i
=0; i
< EVENTID_LAST
; i
++) {
1339 if((event_info
[i
].flags
& EVENT_DEFAULTLISTENER
) && is_cp_event(cp
, event_info
[i
].dispid
))
1340 ensure_nsevent_handler(window
->doc
, event_target
, nsnode
, i
);
1344 void check_event_attr(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
)
1346 const PRUnichar
*attr_value
;
1347 nsAString attr_name_str
, attr_value_str
;
1354 nsAString_Init(&attr_value_str
, NULL
);
1355 nsAString_Init(&attr_name_str
, NULL
);
1357 for(i
=0; i
< EVENTID_LAST
; i
++) {
1358 nsAString_SetData(&attr_name_str
, event_info
[i
].attr_name
);
1359 nsres
= nsIDOMElement_GetAttribute(nselem
, &attr_name_str
, &attr_value_str
);
1360 if(NS_SUCCEEDED(nsres
)) {
1361 nsAString_GetData(&attr_value_str
, &attr_value
);
1365 TRACE("%p.%s = %s\n", nselem
, debugstr_w(event_info
[i
].attr_name
), debugstr_w(attr_value
));
1367 disp
= script_parse_event(doc
->basedoc
.window
, attr_value
);
1369 hres
= get_node(doc
, (nsIDOMNode
*)nselem
, TRUE
, &node
);
1371 set_event_handler_disp(get_node_event_target(node
), node
->nsnode
, node
->doc
, i
, disp
);
1372 IDispatch_Release(disp
);
1377 nsAString_Finish(&attr_value_str
);
1378 nsAString_Finish(&attr_name_str
);
1381 HRESULT
doc_init_events(HTMLDocumentNode
*doc
)
1386 doc
->event_vector
= heap_alloc_zero(EVENTID_LAST
*sizeof(BOOL
));
1387 if(!doc
->event_vector
)
1388 return E_OUTOFMEMORY
;
1392 for(i
=0; i
< EVENTID_LAST
; i
++) {
1393 if(event_info
[i
].flags
& EVENT_HASDEFAULTHANDLERS
) {
1394 hres
= ensure_nsevent_handler(doc
, NULL
, NULL
, i
);
1403 void release_event_target(event_target_t
*event_target
)
1407 for(i
=0; i
< EVENTID_LAST
; i
++) {
1408 if(event_target
->event_table
[i
]) {
1409 if(event_target
->event_table
[i
]->handler_prop
)
1410 IDispatch_Release(event_target
->event_table
[i
]->handler_prop
);
1411 for(j
=0; j
< event_target
->event_table
[i
]->handler_cnt
; j
++)
1412 if(event_target
->event_table
[i
]->handlers
[j
])
1413 IDispatch_Release(event_target
->event_table
[i
]->handlers
[j
]);
1417 heap_free(event_target
);