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 errorW
[] = {'e','r','r','o','r',0};
72 static const WCHAR onerrorW
[] = {'o','n','e','r','r','o','r',0};
74 static const WCHAR focusW
[] = {'f','o','c','u','s',0};
75 static const WCHAR onfocusW
[] = {'o','n','f','o','c','u','s',0};
77 static const WCHAR keydownW
[] = {'k','e','y','d','o','w','n',0};
78 static const WCHAR onkeydownW
[] = {'o','n','k','e','y','d','o','w','n',0};
80 static const WCHAR keypressW
[] = {'k','e','y','p','r','e','s','s',0};
81 static const WCHAR onkeypressW
[] = {'o','n','k','e','y','p','r','e','s','s',0};
83 static const WCHAR keyupW
[] = {'k','e','y','u','p',0};
84 static const WCHAR onkeyupW
[] = {'o','n','k','e','y','u','p',0};
86 static const WCHAR loadW
[] = {'l','o','a','d',0};
87 static const WCHAR onloadW
[] = {'o','n','l','o','a','d',0};
89 static const WCHAR mousedownW
[] = {'m','o','u','s','e','d','o','w','n',0};
90 static const WCHAR onmousedownW
[] = {'o','n','m','o','u','s','e','d','o','w','n',0};
92 static const WCHAR mousemoveW
[] = {'m','o','u','s','e','m','o','v','e',0};
93 static const WCHAR onmousemoveW
[] = {'o','n','m','o','u','s','e','m','o','v','e',0};
95 static const WCHAR mouseoutW
[] = {'m','o','u','s','e','o','u','t',0};
96 static const WCHAR onmouseoutW
[] = {'o','n','m','o','u','s','e','o','u','t',0};
98 static const WCHAR mouseoverW
[] = {'m','o','u','s','e','o','v','e','r',0};
99 static const WCHAR onmouseoverW
[] = {'o','n','m','o','u','s','e','o','v','e','r',0};
101 static const WCHAR mouseupW
[] = {'m','o','u','s','e','u','p',0};
102 static const WCHAR onmouseupW
[] = {'o','n','m','o','u','s','e','u','p',0};
104 static const WCHAR pasteW
[] = {'p','a','s','t','e',0};
105 static const WCHAR onpasteW
[] = {'o','n','p','a','s','t','e',0};
107 static const WCHAR readystatechangeW
[] = {'r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
108 static const WCHAR onreadystatechangeW
[] = {'o','n','r','e','a','d','y','s','t','a','t','e','c','h','a','n','g','e',0};
110 static const WCHAR resizeW
[] = {'r','e','s','i','z','e',0};
111 static const WCHAR onresizeW
[] = {'o','n','r','e','s','i','z','e',0};
113 static const WCHAR selectstartW
[] = {'s','e','l','e','c','t','s','t','a','r','t',0};
114 static const WCHAR onselectstartW
[] = {'o','n','s','e','l','e','c','t','s','t','a','r','t',0};
116 static const WCHAR submitW
[] = {'s','u','b','m','i','t',0};
117 static const WCHAR onsubmitW
[] = {'o','n','s','u','b','m','i','t',0};
119 static const WCHAR HTMLEventsW
[] = {'H','T','M','L','E','v','e','n','t','s',0};
120 static const WCHAR KeyboardEventW
[] = {'K','e','y','b','o','a','r','d','E','v','e','n','t',0};
121 static const WCHAR MouseEventW
[] = {'M','o','u','s','e','E','v','e','n','t',0};
130 static const WCHAR
*event_types
[] = {
145 #define EVENT_DEFAULTLISTENER 0x0001
146 #define EVENT_BUBBLE 0x0002
147 #define EVENT_FORWARDBODY 0x0004
148 #define EVENT_NODEHANDLER 0x0008
149 #define EVENT_CANCELABLE 0x0010
150 #define EVENT_HASDEFAULTHANDLERS 0x0020
152 static const event_info_t event_info
[] = {
153 {beforeunloadW
, onbeforeunloadW
, EVENTT_NONE
, DISPID_EVMETH_ONBEFOREUNLOAD
,
154 EVENT_DEFAULTLISTENER
|EVENT_FORWARDBODY
},
155 {blurW
, onblurW
, EVENTT_HTML
, DISPID_EVMETH_ONBLUR
,
156 EVENT_DEFAULTLISTENER
},
157 {changeW
, onchangeW
, EVENTT_HTML
, DISPID_EVMETH_ONCHANGE
,
158 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
159 {clickW
, onclickW
, EVENTT_MOUSE
, DISPID_EVMETH_ONCLICK
,
160 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
|EVENT_CANCELABLE
|EVENT_HASDEFAULTHANDLERS
},
161 {contextmenuW
, oncontextmenuW
, EVENTT_MOUSE
, DISPID_EVMETH_ONCONTEXTMENU
,
162 EVENT_BUBBLE
|EVENT_CANCELABLE
},
163 {dblclickW
, ondblclickW
, EVENTT_MOUSE
, DISPID_EVMETH_ONDBLCLICK
,
164 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
|EVENT_CANCELABLE
},
165 {dragW
, ondragW
, EVENTT_MOUSE
, DISPID_EVMETH_ONDRAG
,
167 {dragstartW
, ondragstartW
, EVENTT_MOUSE
, DISPID_EVMETH_ONDRAGSTART
,
169 {errorW
, onerrorW
, EVENTT_NONE
, DISPID_EVMETH_ONERROR
,
171 {focusW
, onfocusW
, EVENTT_HTML
, DISPID_EVMETH_ONFOCUS
,
172 EVENT_DEFAULTLISTENER
},
173 {keydownW
, onkeydownW
, EVENTT_KEY
, DISPID_EVMETH_ONKEYDOWN
,
174 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
175 {keypressW
, onkeypressW
, EVENTT_KEY
, DISPID_EVMETH_ONKEYPRESS
,
176 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
177 {keyupW
, onkeyupW
, EVENTT_KEY
, DISPID_EVMETH_ONKEYUP
,
178 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
179 {loadW
, onloadW
, EVENTT_HTML
, DISPID_EVMETH_ONLOAD
,
181 {mousedownW
, onmousedownW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEDOWN
,
182 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
183 {mousemoveW
, onmousemoveW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEMOVE
,
184 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
185 {mouseoutW
, onmouseoutW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEOUT
,
186 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
187 {mouseoverW
, onmouseoverW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEOVER
,
188 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
189 {mouseupW
, onmouseupW
, EVENTT_MOUSE
, DISPID_EVMETH_ONMOUSEUP
,
190 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
191 {pasteW
, onpasteW
, EVENTT_NONE
, DISPID_EVMETH_ONPASTE
,
193 {readystatechangeW
, onreadystatechangeW
, EVENTT_NONE
, DISPID_EVMETH_ONREADYSTATECHANGE
,
195 {resizeW
, onresizeW
, EVENTT_NONE
, DISPID_EVMETH_ONRESIZE
,
196 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
},
197 {selectstartW
, onselectstartW
, EVENTT_MOUSE
, DISPID_EVMETH_ONSELECTSTART
,
199 {submitW
, onsubmitW
, EVENTT_HTML
, DISPID_EVMETH_ONSUBMIT
,
200 EVENT_DEFAULTLISTENER
|EVENT_BUBBLE
|EVENT_CANCELABLE
}
203 static const eventid_t node_handled_list
[] = { EVENTID_ERROR
, EVENTID_LOAD
};
205 eventid_t
str_to_eid(LPCWSTR str
)
209 for(i
=0; i
< sizeof(event_info
)/sizeof(event_info
[0]); i
++) {
210 if(!strcmpW(event_info
[i
].name
, str
))
214 ERR("unknown type %s\n", debugstr_w(str
));
218 static eventid_t
attr_to_eid(LPCWSTR str
)
222 for(i
=0; i
< sizeof(event_info
)/sizeof(event_info
[0]); i
++) {
223 if(!strcmpW(event_info
[i
].attr_name
, str
))
230 static DWORD
get_node_handler_mask(eventid_t eid
)
234 for(i
=0; i
<sizeof(node_handled_list
)/sizeof(*node_handled_list
); i
++) {
235 if(node_handled_list
[i
] == eid
)
239 ERR("Invalid eid %d\n", eid
);
245 IHTMLEventObj IHTMLEventObj_iface
;
250 const event_info_t
*type
;
251 nsIDOMEvent
*nsevent
;
252 BOOL prevent_default
;
256 static inline HTMLEventObj
*impl_from_IHTMLEventObj(IHTMLEventObj
*iface
)
258 return CONTAINING_RECORD(iface
, HTMLEventObj
, IHTMLEventObj_iface
);
261 static HRESULT WINAPI
HTMLEventObj_QueryInterface(IHTMLEventObj
*iface
, REFIID riid
, void **ppv
)
263 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
267 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
268 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
269 *ppv
= &This
->IHTMLEventObj_iface
;
270 }else if(IsEqualGUID(&IID_IHTMLEventObj
, riid
)) {
271 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This
, ppv
);
272 *ppv
= &This
->IHTMLEventObj_iface
;
273 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
274 return *ppv
? S_OK
: E_NOINTERFACE
;
278 IUnknown_AddRef((IUnknown
*)*ppv
);
282 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
283 return E_NOINTERFACE
;
286 static ULONG WINAPI
HTMLEventObj_AddRef(IHTMLEventObj
*iface
)
288 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
289 LONG ref
= InterlockedIncrement(&This
->ref
);
291 TRACE("(%p) ref=%d\n", This
, ref
);
296 static ULONG WINAPI
HTMLEventObj_Release(IHTMLEventObj
*iface
)
298 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
299 LONG ref
= InterlockedDecrement(&This
->ref
);
301 TRACE("(%p) ref=%d\n", This
, ref
);
305 IHTMLDOMNode_Release(&This
->target
->IHTMLDOMNode_iface
);
307 nsIDOMEvent_Release(This
->nsevent
);
308 release_dispex(&This
->dispex
);
315 static HRESULT WINAPI
HTMLEventObj_GetTypeInfoCount(IHTMLEventObj
*iface
, UINT
*pctinfo
)
317 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
318 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
321 static HRESULT WINAPI
HTMLEventObj_GetTypeInfo(IHTMLEventObj
*iface
, UINT iTInfo
,
322 LCID lcid
, ITypeInfo
**ppTInfo
)
324 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
325 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
328 static HRESULT WINAPI
HTMLEventObj_GetIDsOfNames(IHTMLEventObj
*iface
, REFIID riid
,
329 LPOLESTR
*rgszNames
, UINT cNames
,
330 LCID lcid
, DISPID
*rgDispId
)
332 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
333 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
337 static HRESULT WINAPI
HTMLEventObj_Invoke(IHTMLEventObj
*iface
, DISPID dispIdMember
,
338 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
339 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
341 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
342 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
343 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
346 static HRESULT WINAPI
HTMLEventObj_get_srcElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
348 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
350 TRACE("(%p)->(%p)\n", This
, p
);
352 return IHTMLDOMNode_QueryInterface(&This
->target
->IHTMLDOMNode_iface
, &IID_IHTMLElement
,
356 static HRESULT WINAPI
HTMLEventObj_get_altKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
358 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
359 cpp_bool ret
= FALSE
;
361 TRACE("(%p)->(%p)\n", This
, p
);
364 nsIDOMKeyEvent
*key_event
;
367 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
368 if(NS_SUCCEEDED(nsres
)) {
369 nsIDOMKeyEvent_GetAltKey(key_event
, &ret
);
370 nsIDOMKeyEvent_Release(key_event
);
372 nsIDOMMouseEvent
*mouse_event
;
374 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
375 if(NS_SUCCEEDED(nsres
)) {
376 nsIDOMMouseEvent_GetAltKey(mouse_event
, &ret
);
377 nsIDOMMouseEvent_Release(mouse_event
);
382 *p
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
386 static HRESULT WINAPI
HTMLEventObj_get_ctrlKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
388 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
389 cpp_bool ret
= FALSE
;
391 TRACE("(%p)->(%p)\n", This
, p
);
394 nsIDOMKeyEvent
*key_event
;
397 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
398 if(NS_SUCCEEDED(nsres
)) {
399 nsIDOMKeyEvent_GetCtrlKey(key_event
, &ret
);
400 nsIDOMKeyEvent_Release(key_event
);
402 nsIDOMMouseEvent
*mouse_event
;
404 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
405 if(NS_SUCCEEDED(nsres
)) {
406 nsIDOMMouseEvent_GetCtrlKey(mouse_event
, &ret
);
407 nsIDOMMouseEvent_Release(mouse_event
);
412 *p
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
416 static HRESULT WINAPI
HTMLEventObj_get_shiftKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
418 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
419 cpp_bool ret
= FALSE
;
421 TRACE("(%p)->(%p)\n", This
, p
);
424 nsIDOMKeyEvent
*key_event
;
427 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
428 if(NS_SUCCEEDED(nsres
)) {
429 nsIDOMKeyEvent_GetShiftKey(key_event
, &ret
);
430 nsIDOMKeyEvent_Release(key_event
);
432 nsIDOMMouseEvent
*mouse_event
;
434 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
435 if(NS_SUCCEEDED(nsres
)) {
436 nsIDOMMouseEvent_GetShiftKey(mouse_event
, &ret
);
437 nsIDOMMouseEvent_Release(mouse_event
);
442 *p
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
446 static HRESULT WINAPI
HTMLEventObj_put_returnValue(IHTMLEventObj
*iface
, VARIANT v
)
448 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
450 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
452 if(V_VT(&v
) != VT_BOOL
) {
453 FIXME("unsupported value %s\n", debugstr_variant(&v
));
454 return DISP_E_BADVARTYPE
;
458 This
->prevent_default
= TRUE
;
462 static HRESULT WINAPI
HTMLEventObj_get_returnValue(IHTMLEventObj
*iface
, VARIANT
*p
)
464 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
466 FIXME("(%p)->(%p)\n", This
, p
);
472 static HRESULT WINAPI
HTMLEventObj_put_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL v
)
474 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
476 TRACE("(%p)->(%x)\n", This
, v
);
478 This
->cancel_bubble
= !!v
;
482 static HRESULT WINAPI
HTMLEventObj_get_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
484 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
486 TRACE("(%p)->(%p)\n", This
, p
);
488 *p
= This
->cancel_bubble
? VARIANT_TRUE
: VARIANT_FALSE
;
492 static HRESULT WINAPI
HTMLEventObj_get_fromElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
494 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
496 FIXME("(%p)->(%p)\n", This
, p
);
502 static HRESULT WINAPI
HTMLEventObj_get_toElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
504 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
506 FIXME("(%p)->(%p)\n", This
, p
);
512 static HRESULT WINAPI
HTMLEventObj_put_keyCode(IHTMLEventObj
*iface
, LONG v
)
514 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
515 FIXME("(%p)->(%d)\n", This
, v
);
519 static HRESULT WINAPI
HTMLEventObj_get_keyCode(IHTMLEventObj
*iface
, LONG
*p
)
521 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
522 PRUint32 key_code
= 0;
524 TRACE("(%p)->(%p)\n", This
, p
);
527 nsIDOMKeyEvent
*key_event
;
530 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
531 if(NS_SUCCEEDED(nsres
)) {
532 nsIDOMKeyEvent_GetKeyCode(key_event
, &key_code
);
533 nsIDOMKeyEvent_Release(key_event
);
541 static HRESULT WINAPI
HTMLEventObj_get_button(IHTMLEventObj
*iface
, LONG
*p
)
543 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
546 TRACE("(%p)->(%p)\n", This
, p
);
549 nsIDOMMouseEvent
*mouse_event
;
552 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
553 if(NS_SUCCEEDED(nsres
)) {
554 nsIDOMMouseEvent_GetButton(mouse_event
, &button
);
555 nsIDOMMouseEvent_Release(mouse_event
);
563 static HRESULT WINAPI
HTMLEventObj_get_type(IHTMLEventObj
*iface
, BSTR
*p
)
565 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
567 TRACE("(%p)->(%p)\n", This
, p
);
569 *p
= SysAllocString(This
->type
->name
);
570 return *p
? S_OK
: E_OUTOFMEMORY
;
573 static HRESULT WINAPI
HTMLEventObj_get_qualifier(IHTMLEventObj
*iface
, BSTR
*p
)
575 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
577 FIXME("(%p)->(%p)\n", This
, p
);
583 static HRESULT WINAPI
HTMLEventObj_get_reason(IHTMLEventObj
*iface
, LONG
*p
)
585 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
587 FIXME("(%p)->(%p)\n", This
, p
);
593 static HRESULT WINAPI
HTMLEventObj_get_x(IHTMLEventObj
*iface
, LONG
*p
)
595 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
597 FIXME("(%p)->(%p)\n", This
, p
);
603 static HRESULT WINAPI
HTMLEventObj_get_y(IHTMLEventObj
*iface
, LONG
*p
)
605 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
607 FIXME("(%p)->(%p)\n", This
, p
);
613 static HRESULT WINAPI
HTMLEventObj_get_clientX(IHTMLEventObj
*iface
, LONG
*p
)
615 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
618 TRACE("(%p)->(%p)\n", This
, p
);
621 nsIDOMMouseEvent
*mouse_event
;
624 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
625 if(NS_SUCCEEDED(nsres
)) {
626 nsIDOMMouseEvent_GetClientX(mouse_event
, &x
);
627 nsIDOMMouseEvent_Release(mouse_event
);
635 static HRESULT WINAPI
HTMLEventObj_get_clientY(IHTMLEventObj
*iface
, LONG
*p
)
637 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
640 TRACE("(%p)->(%p)\n", This
, p
);
643 nsIDOMMouseEvent
*mouse_event
;
646 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
647 if(NS_SUCCEEDED(nsres
)) {
648 nsIDOMMouseEvent_GetClientY(mouse_event
, &y
);
649 nsIDOMMouseEvent_Release(mouse_event
);
657 static HRESULT WINAPI
HTMLEventObj_get_offsetX(IHTMLEventObj
*iface
, LONG
*p
)
659 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
661 FIXME("(%p)->(%p)\n", This
, p
);
667 static HRESULT WINAPI
HTMLEventObj_get_offsetY(IHTMLEventObj
*iface
, LONG
*p
)
669 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
671 FIXME("(%p)->(%p)\n", This
, p
);
677 static HRESULT WINAPI
HTMLEventObj_get_screenX(IHTMLEventObj
*iface
, LONG
*p
)
679 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
682 TRACE("(%p)->(%p)\n", This
, p
);
685 nsIDOMMouseEvent
*mouse_event
;
688 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
689 if(NS_SUCCEEDED(nsres
)) {
690 nsIDOMMouseEvent_GetScreenX(mouse_event
, &x
);
691 nsIDOMMouseEvent_Release(mouse_event
);
699 static HRESULT WINAPI
HTMLEventObj_get_screenY(IHTMLEventObj
*iface
, LONG
*p
)
701 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
704 TRACE("(%p)->(%p)\n", This
, p
);
707 nsIDOMMouseEvent
*mouse_event
;
710 nsres
= nsIDOMEvent_QueryInterface(This
->nsevent
, &IID_nsIDOMMouseEvent
, (void**)&mouse_event
);
711 if(NS_SUCCEEDED(nsres
)) {
712 nsIDOMMouseEvent_GetScreenY(mouse_event
, &y
);
713 nsIDOMMouseEvent_Release(mouse_event
);
721 static HRESULT WINAPI
HTMLEventObj_get_srcFilter(IHTMLEventObj
*iface
, IDispatch
**p
)
723 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
725 FIXME("(%p)->(%p)\n", This
, p
);
731 static const IHTMLEventObjVtbl HTMLEventObjVtbl
= {
732 HTMLEventObj_QueryInterface
,
734 HTMLEventObj_Release
,
735 HTMLEventObj_GetTypeInfoCount
,
736 HTMLEventObj_GetTypeInfo
,
737 HTMLEventObj_GetIDsOfNames
,
739 HTMLEventObj_get_srcElement
,
740 HTMLEventObj_get_altKey
,
741 HTMLEventObj_get_ctrlKey
,
742 HTMLEventObj_get_shiftKey
,
743 HTMLEventObj_put_returnValue
,
744 HTMLEventObj_get_returnValue
,
745 HTMLEventObj_put_cancelBubble
,
746 HTMLEventObj_get_cancelBubble
,
747 HTMLEventObj_get_fromElement
,
748 HTMLEventObj_get_toElement
,
749 HTMLEventObj_put_keyCode
,
750 HTMLEventObj_get_keyCode
,
751 HTMLEventObj_get_button
,
752 HTMLEventObj_get_type
,
753 HTMLEventObj_get_qualifier
,
754 HTMLEventObj_get_reason
,
757 HTMLEventObj_get_clientX
,
758 HTMLEventObj_get_clientY
,
759 HTMLEventObj_get_offsetX
,
760 HTMLEventObj_get_offsetY
,
761 HTMLEventObj_get_screenX
,
762 HTMLEventObj_get_screenY
,
763 HTMLEventObj_get_srcFilter
766 static const tid_t HTMLEventObj_iface_tids
[] = {
771 static dispex_static_data_t HTMLEventObj_dispex
= {
775 HTMLEventObj_iface_tids
778 static HTMLEventObj
*create_event(HTMLDOMNode
*target
, eventid_t eid
, nsIDOMEvent
*nsevent
)
782 ret
= heap_alloc_zero(sizeof(*ret
));
786 ret
->IHTMLEventObj_iface
.lpVtbl
= &HTMLEventObjVtbl
;
788 ret
->type
= event_info
+eid
;
790 ret
->nsevent
= nsevent
;
792 nsIDOMEvent_AddRef(nsevent
);
793 }else if(event_types
[event_info
[eid
].type
]) {
797 nsAString_InitDepend(&type_str
, event_types
[event_info
[eid
].type
]);
798 nsres
= nsIDOMHTMLDocument_CreateEvent(target
->doc
->nsdoc
, &type_str
, &ret
->nsevent
);
799 nsAString_Finish(&type_str
);
800 if(NS_FAILED(nsres
)) {
801 ERR("Could not create event: %08x\n", nsres
);
802 IHTMLEventObj_Release(&ret
->IHTMLEventObj_iface
);
807 ret
->target
= target
;
808 IHTMLDOMNode_AddRef(&target
->IHTMLDOMNode_iface
);
810 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLEventObj_iface
, &HTMLEventObj_dispex
);
815 static HRESULT
call_disp_func(IDispatch
*disp
, DISPPARAMS
*dp
, VARIANT
*retv
)
821 memset(&ei
, 0, sizeof(ei
));
823 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
824 if(SUCCEEDED(hres
)) {
825 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, dp
, retv
, &ei
, NULL
);
826 IDispatchEx_Release(dispex
);
828 TRACE("Could not get IDispatchEx interface: %08x\n", hres
);
829 hres
= IDispatch_Invoke(disp
, 0, &IID_NULL
, GetUserDefaultLCID(), DISPATCH_METHOD
,
830 dp
, retv
, &ei
, NULL
);
836 static HRESULT
call_cp_func(IDispatch
*disp
, DISPID dispid
, VARIANT
*retv
)
838 DISPPARAMS dp
= {NULL
,NULL
,0,0};
842 memset(&ei
, 0, sizeof(ei
));
843 return IDispatch_Invoke(disp
, dispid
, &IID_NULL
, 0, DISPATCH_METHOD
, &dp
, retv
, &ei
, &argerr
);
846 static BOOL
is_cp_event(cp_static_data_t
*data
, DISPID dispid
)
855 hres
= get_dispids(data
->tid
, &data
->id_cnt
, &data
->ids
);
861 max
= data
->id_cnt
-1;
864 if(data
->ids
[i
] == dispid
)
867 if(data
->ids
[i
] < dispid
)
876 static void call_event_handlers(HTMLDocumentNode
*doc
, HTMLEventObj
*event_obj
, event_target_t
*event_target
,
877 ConnectionPointContainer
*cp_container
, eventid_t eid
, IDispatch
*this_obj
)
879 const BOOL cancelable
= event_info
[eid
].flags
& EVENT_CANCELABLE
;
880 handler_vector_t
*handler_vector
= NULL
;
886 handler_vector
= event_target
->event_table
[eid
];
888 if(handler_vector
&& handler_vector
->handler_prop
) {
889 DISPID named_arg
= DISPID_THIS
;
891 DISPPARAMS dp
= {&arg
, &named_arg
, 1, 1};
893 V_VT(&arg
) = VT_DISPATCH
;
894 V_DISPATCH(&arg
) = this_obj
;
897 TRACE("%s >>>\n", debugstr_w(event_info
[eid
].name
));
898 hres
= call_disp_func(handler_vector
->handler_prop
, &dp
, &v
);
900 TRACE("%s <<< %s\n", debugstr_w(event_info
[eid
].name
), debugstr_variant(&v
));
903 if(V_VT(&v
) == VT_BOOL
) {
905 event_obj
->prevent_default
= TRUE
;
906 }else if(V_VT(&v
) != VT_EMPTY
) {
907 FIXME("unhandled result %s\n", debugstr_variant(&v
));
912 WARN("%s <<< %08x\n", debugstr_w(event_info
[eid
].name
), hres
);
916 if(handler_vector
&& handler_vector
->handler_cnt
) {
918 DISPPARAMS dp
= {&arg
, NULL
, 1, 0};
920 V_VT(&arg
) = VT_DISPATCH
;
921 V_DISPATCH(&arg
) = (IDispatch
*)event_obj
;
923 i
= handler_vector
->handler_cnt
;
925 if(handler_vector
->handlers
[i
]) {
928 TRACE("%s [%d] >>>\n", debugstr_w(event_info
[eid
].name
), i
);
929 hres
= call_disp_func(handler_vector
->handlers
[i
], &dp
, &v
);
931 TRACE("%s [%d] <<<\n", debugstr_w(event_info
[eid
].name
), i
);
934 if(V_VT(&v
) == VT_BOOL
) {
936 event_obj
->prevent_default
= TRUE
;
937 }else if(V_VT(&v
) != VT_EMPTY
) {
938 FIXME("unhandled result %s\n", debugstr_variant(&v
));
943 WARN("%s [%d] <<< %08x\n", debugstr_w(event_info
[eid
].name
), i
, hres
);
952 if(cp_container
->forward_container
)
953 cp_container
= cp_container
->forward_container
;
955 for(cp
= cp_container
->cp_list
; cp
; cp
= cp
->next
) {
956 if(cp
->sinks_size
&& is_cp_event(cp
->data
, event_info
[eid
].dispid
)) {
957 for(i
=0; i
< cp
->sinks_size
; i
++) {
958 if(!cp
->sinks
[i
].disp
)
963 TRACE("cp %s [%d] >>>\n", debugstr_w(event_info
[eid
].name
), i
);
964 hres
= call_cp_func(cp
->sinks
[i
].disp
, event_info
[eid
].dispid
, &v
);
966 TRACE("cp %s [%d] <<<\n", debugstr_w(event_info
[eid
].name
), i
);
969 if(V_VT(&v
) == VT_BOOL
) {
971 event_obj
->prevent_default
= TRUE
;
972 }else if(V_VT(&v
) != VT_EMPTY
) {
973 FIXME("unhandled result %s\n", debugstr_variant(&v
));
978 WARN("cp %s [%d] <<< %08x\n", debugstr_w(event_info
[eid
].name
), i
, hres
);
986 void fire_event(HTMLDocumentNode
*doc
, eventid_t eid
, BOOL set_event
, nsIDOMNode
*target
, nsIDOMEvent
*nsevent
)
988 HTMLEventObj
*event_obj
= NULL
;
989 IHTMLEventObj
*prev_event
;
990 nsIDOMNode
*parent
, *nsnode
;
991 BOOL prevent_default
= FALSE
;
997 TRACE("(%p) %s\n", doc
, debugstr_w(event_info
[eid
].name
));
999 prev_event
= doc
->basedoc
.window
->event
;
1001 hres
= get_node(doc
, target
, TRUE
, &node
);
1005 event_obj
= create_event(node
, eid
, nsevent
);
1006 doc
->basedoc
.window
->event
= &event_obj
->IHTMLEventObj_iface
;
1008 doc
->basedoc
.window
->event
= NULL
;
1011 nsIDOMNode_GetNodeType(target
, &node_type
);
1013 nsIDOMNode_AddRef(nsnode
);
1018 hres
= get_node(doc
, nsnode
, FALSE
, &node
);
1019 if(SUCCEEDED(hres
) && node
)
1020 call_event_handlers(doc
, event_obj
, *get_node_event_target(node
),
1021 node
->cp_container
, eid
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1023 if(!(event_info
[eid
].flags
& EVENT_BUBBLE
) || (event_obj
&& event_obj
->cancel_bubble
))
1026 nsIDOMNode_GetParentNode(nsnode
, &parent
);
1027 nsIDOMNode_Release(nsnode
);
1032 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1033 }while(node_type
== ELEMENT_NODE
);
1035 if(!(event_info
[eid
].flags
& EVENT_BUBBLE
) || (event_obj
&& event_obj
->cancel_bubble
))
1039 if(event_info
[eid
].flags
& EVENT_FORWARDBODY
) {
1040 nsIDOMHTMLElement
*nsbody
;
1043 nsres
= nsIDOMHTMLDocument_GetBody(doc
->nsdoc
, &nsbody
);
1044 if(NS_SUCCEEDED(nsres
) && nsbody
) {
1045 hres
= get_node(doc
, (nsIDOMNode
*)nsbody
, FALSE
, &node
);
1046 if(SUCCEEDED(hres
) && node
)
1047 call_event_handlers(doc
, event_obj
, *get_node_event_target(node
),
1048 node
->cp_container
, eid
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1049 nsIDOMHTMLElement_Release(nsbody
);
1051 ERR("Could not get body: %08x\n", nsres
);
1055 call_event_handlers(doc
, event_obj
, doc
->node
.event_target
, &doc
->basedoc
.cp_container
, eid
,
1056 (IDispatch
*)&doc
->basedoc
.IHTMLDocument2_iface
);
1060 FIXME("unimplemented node type %d\n", node_type
);
1064 nsIDOMNode_Release(nsnode
);
1066 if(event_obj
&& event_obj
->prevent_default
)
1067 prevent_default
= TRUE
;
1068 doc
->basedoc
.window
->event
= prev_event
;
1070 IHTMLEventObj_Release(&event_obj
->IHTMLEventObj_iface
);
1072 if(!prevent_default
&& (event_info
[eid
].flags
& EVENT_HASDEFAULTHANDLERS
)) {
1073 nsIDOMNode_AddRef(target
);
1077 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
1081 if(node
&& node
->vtbl
->handle_event
) {
1082 hres
= node
->vtbl
->handle_event(node
, eid
, nsevent
, &prevent_default
);
1083 if(FAILED(hres
) || prevent_default
|| (event_obj
&& event_obj
->cancel_bubble
))
1087 nsres
= nsIDOMNode_GetParentNode(nsnode
, &parent
);
1088 if(NS_FAILED(nsres
))
1091 nsIDOMNode_Release(nsnode
);
1096 nsIDOMNode_Release(nsnode
);
1099 if(prevent_default
&& nsevent
) {
1100 TRACE("calling PreventDefault\n");
1101 nsIDOMEvent_PreventDefault(nsevent
);
1105 HRESULT
dispatch_event(HTMLDOMNode
*node
, const WCHAR
*event_name
, VARIANT
*event_obj
, VARIANT_BOOL
*cancelled
)
1109 eid
= attr_to_eid(event_name
);
1110 if(eid
== EVENTID_LAST
) {
1111 WARN("unknown event %s\n", debugstr_w(event_name
));
1112 return E_INVALIDARG
;
1115 if(event_obj
&& V_VT(event_obj
) != VT_EMPTY
&& V_VT(event_obj
) != VT_ERROR
)
1116 FIXME("event_obj not implemented\n");
1118 if(!(event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
)) {
1119 FIXME("not EVENT_DEFAULTEVENTHANDLER\n");
1123 fire_event(node
->doc
, eid
, TRUE
, node
->nsnode
, NULL
);
1125 *cancelled
= VARIANT_TRUE
; /* FIXME */
1129 HRESULT
call_fire_event(HTMLDOMNode
*node
, eventid_t eid
)
1133 if(node
->vtbl
->fire_event
) {
1134 BOOL handled
= FALSE
;
1136 hres
= node
->vtbl
->fire_event(node
, eid
, &handled
);
1141 fire_event(node
->doc
, eid
, TRUE
, node
->nsnode
, NULL
);
1145 static inline event_target_t
*get_event_target(event_target_t
**event_target_ptr
)
1147 if(!*event_target_ptr
)
1148 *event_target_ptr
= heap_alloc_zero(sizeof(event_target_t
));
1149 return *event_target_ptr
;
1152 static BOOL
alloc_handler_vector(event_target_t
*event_target
, eventid_t eid
, int cnt
)
1154 handler_vector_t
*new_vector
, *handler_vector
= event_target
->event_table
[eid
];
1156 if(handler_vector
) {
1157 if(cnt
<= handler_vector
->handler_cnt
)
1160 new_vector
= heap_realloc_zero(handler_vector
, sizeof(handler_vector_t
) + sizeof(IDispatch
*)*cnt
);
1162 new_vector
= heap_alloc_zero(sizeof(handler_vector_t
) + sizeof(IDispatch
*)*cnt
);
1168 new_vector
->handler_cnt
= cnt
;
1169 event_target
->event_table
[eid
] = new_vector
;
1173 static HRESULT
ensure_nsevent_handler(HTMLDocumentNode
*doc
, event_target_t
*event_target
, nsIDOMNode
*nsnode
, eventid_t eid
)
1178 if(event_info
[eid
].flags
& EVENT_NODEHANDLER
) {
1181 mask
= get_node_handler_mask(eid
);
1182 if(event_target
->node_handlers_mask
& mask
)
1185 add_nsevent_listener(doc
, nsnode
, event_info
[eid
].name
);
1186 event_target
->node_handlers_mask
|= mask
;
1190 if(!(event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
))
1193 if(!doc
->event_vector
[eid
]) {
1194 doc
->event_vector
[eid
] = TRUE
;
1195 add_nsevent_listener(doc
, NULL
, event_info
[eid
].name
);
1201 void detach_events(HTMLDocumentNode
*doc
)
1203 if(doc
->event_vector
) {
1206 for(i
=0; i
< EVENTID_LAST
; i
++) {
1207 if(doc
->event_vector
[i
])
1208 detach_nsevent(doc
, event_info
[i
].name
);
1212 release_nsevents(doc
);
1216 static HRESULT
remove_event_handler(event_target_t
**event_target
, eventid_t eid
)
1218 if(*event_target
&& (*event_target
)->event_table
[eid
] && (*event_target
)->event_table
[eid
]->handler_prop
) {
1219 IDispatch_Release((*event_target
)->event_table
[eid
]->handler_prop
);
1220 (*event_target
)->event_table
[eid
]->handler_prop
= NULL
;
1226 static HRESULT
set_event_handler_disp(event_target_t
**event_target_ptr
, nsIDOMNode
*nsnode
, HTMLDocumentNode
*doc
,
1227 eventid_t eid
, IDispatch
*disp
)
1229 event_target_t
*event_target
;
1232 return remove_event_handler(event_target_ptr
, eid
);
1234 event_target
= get_event_target(event_target_ptr
);
1236 return E_OUTOFMEMORY
;
1238 if(!alloc_handler_vector(event_target
, eid
, 0))
1239 return E_OUTOFMEMORY
;
1241 if(event_target
->event_table
[eid
]->handler_prop
)
1242 IDispatch_Release(event_target
->event_table
[eid
]->handler_prop
);
1244 event_target
->event_table
[eid
]->handler_prop
= disp
;
1245 IDispatch_AddRef(disp
);
1247 return ensure_nsevent_handler(doc
, event_target
, nsnode
, eid
);
1250 HRESULT
set_event_handler(event_target_t
**event_target
, nsIDOMNode
*nsnode
, HTMLDocumentNode
*doc
, eventid_t eid
, VARIANT
*var
)
1254 return remove_event_handler(event_target
, eid
);
1257 return set_event_handler_disp(event_target
, nsnode
, doc
, eid
, V_DISPATCH(var
));
1260 FIXME("not handler %s\n", debugstr_variant(var
));
1269 HRESULT
get_event_handler(event_target_t
**event_target
, eventid_t eid
, VARIANT
*var
)
1271 if(*event_target
&& (*event_target
)->event_table
[eid
] && (*event_target
)->event_table
[eid
]->handler_prop
) {
1272 V_VT(var
) = VT_DISPATCH
;
1273 V_DISPATCH(var
) = (*event_target
)->event_table
[eid
]->handler_prop
;
1274 IDispatch_AddRef(V_DISPATCH(var
));
1276 V_VT(var
) = VT_NULL
;
1282 HRESULT
attach_event(event_target_t
**event_target_ptr
, nsIDOMNode
*nsnode
, HTMLDocument
*doc
, BSTR name
,
1283 IDispatch
*disp
, VARIANT_BOOL
*res
)
1285 event_target_t
*event_target
;
1289 eid
= attr_to_eid(name
);
1290 if(eid
== EVENTID_LAST
) {
1291 WARN("Unknown event\n");
1292 *res
= VARIANT_TRUE
;
1296 event_target
= get_event_target(event_target_ptr
);
1298 return E_OUTOFMEMORY
;
1300 if(event_target
->event_table
[eid
]) {
1301 while(i
< event_target
->event_table
[eid
]->handler_cnt
&& event_target
->event_table
[eid
]->handlers
[i
])
1303 if(i
== event_target
->event_table
[eid
]->handler_cnt
&& !alloc_handler_vector(event_target
, eid
, i
+1))
1304 return E_OUTOFMEMORY
;
1305 }else if(!alloc_handler_vector(event_target
, eid
, i
+1)) {
1306 return E_OUTOFMEMORY
;
1309 IDispatch_AddRef(disp
);
1310 event_target
->event_table
[eid
]->handlers
[i
] = disp
;
1312 *res
= VARIANT_TRUE
;
1313 return ensure_nsevent_handler(doc
->doc_node
, event_target
, nsnode
, eid
);
1316 HRESULT
detach_event(event_target_t
*event_target
, HTMLDocument
*doc
, BSTR name
, IDispatch
*disp
)
1324 eid
= attr_to_eid(name
);
1325 if(eid
== EVENTID_LAST
) {
1326 WARN("Unknown event\n");
1330 if(!event_target
->event_table
[eid
])
1333 while(i
< event_target
->event_table
[eid
]->handler_cnt
) {
1334 if(event_target
->event_table
[eid
]->handlers
[i
] == disp
) {
1335 IDispatch_Release(event_target
->event_table
[eid
]->handlers
[i
]);
1336 event_target
->event_table
[eid
]->handlers
[i
] = NULL
;
1344 void update_cp_events(HTMLWindow
*window
, event_target_t
**event_target_ptr
, cp_static_data_t
*cp
, nsIDOMNode
*nsnode
)
1346 event_target_t
*event_target
;
1349 event_target
= get_event_target(event_target_ptr
);
1353 for(i
=0; i
< EVENTID_LAST
; i
++) {
1354 if((event_info
[i
].flags
& EVENT_DEFAULTLISTENER
) && is_cp_event(cp
, event_info
[i
].dispid
))
1355 ensure_nsevent_handler(window
->doc
, event_target
, nsnode
, i
);
1359 void check_event_attr(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
)
1361 const PRUnichar
*attr_value
;
1362 nsAString attr_name_str
, attr_value_str
;
1369 nsAString_Init(&attr_value_str
, NULL
);
1370 nsAString_Init(&attr_name_str
, NULL
);
1372 for(i
=0; i
< EVENTID_LAST
; i
++) {
1373 nsAString_SetData(&attr_name_str
, event_info
[i
].attr_name
);
1374 nsres
= nsIDOMElement_GetAttribute(nselem
, &attr_name_str
, &attr_value_str
);
1375 if(NS_SUCCEEDED(nsres
)) {
1376 nsAString_GetData(&attr_value_str
, &attr_value
);
1380 TRACE("%p.%s = %s\n", nselem
, debugstr_w(event_info
[i
].attr_name
), debugstr_w(attr_value
));
1382 disp
= script_parse_event(doc
->basedoc
.window
, attr_value
);
1384 hres
= get_node(doc
, (nsIDOMNode
*)nselem
, TRUE
, &node
);
1386 set_event_handler_disp(get_node_event_target(node
), node
->nsnode
, node
->doc
, i
, disp
);
1387 IDispatch_Release(disp
);
1392 nsAString_Finish(&attr_value_str
);
1393 nsAString_Finish(&attr_name_str
);
1396 HRESULT
doc_init_events(HTMLDocumentNode
*doc
)
1401 doc
->event_vector
= heap_alloc_zero(EVENTID_LAST
*sizeof(BOOL
));
1402 if(!doc
->event_vector
)
1403 return E_OUTOFMEMORY
;
1407 for(i
=0; i
< EVENTID_LAST
; i
++) {
1408 if(event_info
[i
].flags
& EVENT_HASDEFAULTHANDLERS
) {
1409 hres
= ensure_nsevent_handler(doc
, NULL
, NULL
, i
);
1418 void release_event_target(event_target_t
*event_target
)
1422 for(i
=0; i
< EVENTID_LAST
; i
++) {
1423 if(event_target
->event_table
[i
]) {
1424 if(event_target
->event_table
[i
]->handler_prop
)
1425 IDispatch_Release(event_target
->event_table
[i
]->handler_prop
);
1426 for(j
=0; j
< event_target
->event_table
[i
]->handler_cnt
; j
++)
1427 if(event_target
->event_table
[i
]->handlers
[j
])
1428 IDispatch_Release(event_target
->event_table
[i
]->handlers
[j
]);
1432 heap_free(event_target
);