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
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
32 #include "htmlscript.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
39 LISTENER_TYPE_CAPTURE
,
41 LISTENER_TYPE_ONEVENT
,
42 LISTENER_TYPE_ATTACHED
52 struct wine_rb_entry entry
;
53 struct list listeners
;
55 } listener_container_t
;
74 static const WCHAR
*event_types
[] = {
92 /* Use Gecko default listener (it's registered on window object for DOM nodes). */
93 #define EVENT_DEFAULTLISTENER 0x0001
94 /* Register Gecko listener on target itself (unlike EVENT_DEFAULTLISTENER). */
95 #define EVENT_BIND_TO_TARGET 0x0002
96 /* Event bubbles by default (unless explicitly specified otherwise). */
97 #define EVENT_BUBBLES 0x0004
98 /* Event is cancelable by default (unless explicitly specified otherwise). */
99 #define EVENT_CANCELABLE 0x0008
100 /* Event may have default handler (so we always have to register Gecko listener). */
101 #define EVENT_HASDEFAULTHANDLERS 0x0020
102 /* Ecent is not supported properly, print FIXME message when it's used. */
103 #define EVENT_FIXME 0x0040
105 /* mouse event flags for fromElement and toElement implementation */
106 #define EVENT_MOUSE_TO_RELATED 0x0100
107 #define EVENT_MOUSE_FROM_RELATED 0x0200
109 static const event_info_t event_info
[] = {
110 {L
"abort", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONABORT
,
111 EVENT_BIND_TO_TARGET
},
112 {L
"animationend", EVENT_TYPE_EVENT
, DISPID_EVPROP_ONANIMATIONEND
,
113 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
},
114 {L
"animationstart", EVENT_TYPE_EVENT
, DISPID_EVPROP_ONANIMATIONSTART
,
115 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
},
116 {L
"beforeactivate", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONBEFOREACTIVATE
,
117 EVENT_FIXME
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
118 {L
"beforeunload", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONBEFOREUNLOAD
,
119 EVENT_DEFAULTLISTENER
| EVENT_CANCELABLE
},
120 {L
"blur", EVENT_TYPE_FOCUS
, DISPID_EVMETH_ONBLUR
,
121 EVENT_DEFAULTLISTENER
},
122 {L
"change", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONCHANGE
,
123 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
},
124 {L
"click", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONCLICK
,
125 EVENT_DEFAULTLISTENER
| EVENT_HASDEFAULTHANDLERS
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
126 {L
"contextmenu", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONCONTEXTMENU
,
127 EVENT_BUBBLES
| EVENT_CANCELABLE
},
128 {L
"dataavailable", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONDATAAVAILABLE
,
129 EVENT_FIXME
| EVENT_BUBBLES
},
130 {L
"dblclick", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONDBLCLICK
,
131 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
132 {L
"DOMContentLoaded", EVENT_TYPE_EVENT
, 0,
133 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
134 {L
"drag", EVENT_TYPE_DRAG
, DISPID_EVMETH_ONDRAG
,
135 EVENT_FIXME
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
136 {L
"dragstart", EVENT_TYPE_DRAG
, DISPID_EVMETH_ONDRAGSTART
,
137 EVENT_FIXME
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
138 {L
"error", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONERROR
,
139 EVENT_BIND_TO_TARGET
},
140 {L
"focus", EVENT_TYPE_FOCUS
, DISPID_EVMETH_ONFOCUS
,
141 EVENT_DEFAULTLISTENER
},
142 {L
"focusin", EVENT_TYPE_FOCUS
, DISPID_EVMETH_ONFOCUSIN
,
144 {L
"focusout", EVENT_TYPE_FOCUS
, DISPID_EVMETH_ONFOCUSOUT
,
146 {L
"help", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONHELP
,
147 EVENT_BUBBLES
| EVENT_CANCELABLE
},
148 {L
"input", EVENT_TYPE_EVENT
, DISPID_UNKNOWN
,
149 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
},
150 {L
"keydown", EVENT_TYPE_KEYBOARD
, DISPID_EVMETH_ONKEYDOWN
,
151 EVENT_DEFAULTLISTENER
| EVENT_HASDEFAULTHANDLERS
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
152 {L
"keypress", EVENT_TYPE_KEYBOARD
, DISPID_EVMETH_ONKEYPRESS
,
153 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
154 {L
"keyup", EVENT_TYPE_KEYBOARD
, DISPID_EVMETH_ONKEYUP
,
155 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
156 {L
"load", EVENT_TYPE_UIEVENT
, DISPID_EVMETH_ONLOAD
,
157 EVENT_BIND_TO_TARGET
},
158 {L
"message", EVENT_TYPE_MESSAGE
, DISPID_EVMETH_ONMESSAGE
,
160 {L
"mousedown", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONMOUSEDOWN
,
161 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
162 {L
"mousemove", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONMOUSEMOVE
,
163 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
| EVENT_MOUSE_FROM_RELATED
},
164 {L
"mouseout", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONMOUSEOUT
,
165 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
| EVENT_MOUSE_TO_RELATED
},
166 {L
"mouseover", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONMOUSEOVER
,
167 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
| EVENT_MOUSE_FROM_RELATED
},
168 {L
"mouseup", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONMOUSEUP
,
169 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
170 {L
"mousewheel", EVENT_TYPE_MOUSE
, DISPID_EVMETH_ONMOUSEWHEEL
,
172 {L
"msthumbnailclick", EVENT_TYPE_MOUSE
, DISPID_EVPROP_ONMSTHUMBNAILCLICK
,
174 {L
"paste", EVENT_TYPE_CLIPBOARD
, DISPID_EVMETH_ONPASTE
,
175 EVENT_FIXME
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
176 {L
"readystatechange", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONREADYSTATECHANGE
,
178 {L
"resize", EVENT_TYPE_UIEVENT
, DISPID_EVMETH_ONRESIZE
,
179 EVENT_DEFAULTLISTENER
},
180 {L
"scroll", EVENT_TYPE_UIEVENT
, DISPID_EVMETH_ONSCROLL
,
181 EVENT_DEFAULTLISTENER
| EVENT_BUBBLES
/* FIXME: not for elements */},
182 {L
"selectionchange", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONSELECTIONCHANGE
,
184 {L
"selectstart", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONSELECTSTART
,
185 EVENT_FIXME
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
186 {L
"submit", EVENT_TYPE_EVENT
, DISPID_EVMETH_ONSUBMIT
,
187 EVENT_DEFAULTLISTENER
| EVENT_HASDEFAULTHANDLERS
| EVENT_BUBBLES
| EVENT_CANCELABLE
},
188 {L
"unload", EVENT_TYPE_UIEVENT
, DISPID_EVMETH_ONUNLOAD
,
192 C_ASSERT(ARRAY_SIZE(event_info
) == EVENTID_LAST
);
194 static eventid_t
str_to_eid(const WCHAR
*str
)
198 for(i
=0; i
< ARRAY_SIZE(event_info
); i
++) {
199 if(!wcscmp(event_info
[i
].name
, str
))
206 static eventid_t
attr_to_eid(const WCHAR
*str
)
210 if((str
[0] != 'o' && str
[0] != 'O') || (str
[1] != 'n' && str
[1] != 'N'))
213 for(i
=0; i
< ARRAY_SIZE(event_info
); i
++) {
214 if(!wcscmp(event_info
[i
].name
, str
+2) && event_info
[i
].dispid
)
221 static listener_container_t
*get_listener_container(EventTarget
*event_target
, const WCHAR
*type
, BOOL alloc
)
223 const event_target_vtbl_t
*vtbl
;
224 listener_container_t
*container
;
225 struct wine_rb_entry
*entry
;
229 entry
= wine_rb_get(&event_target
->handler_map
, type
);
231 return WINE_RB_ENTRY_VALUE(entry
, listener_container_t
, entry
);
235 eid
= str_to_eid(type
);
236 if(eid
!= EVENTID_LAST
&& (event_info
[eid
].flags
& EVENT_FIXME
))
237 FIXME("unimplemented event %s\n", debugstr_w(event_info
[eid
].name
));
239 type_len
= lstrlenW(type
);
240 container
= heap_alloc(FIELD_OFFSET(listener_container_t
, type
[type_len
+1]));
243 memcpy(container
->type
, type
, (type_len
+ 1) * sizeof(WCHAR
));
244 list_init(&container
->listeners
);
245 vtbl
= dispex_get_vtbl(&event_target
->dispex
);
247 vtbl
->bind_event(&event_target
->dispex
, eid
);
249 FIXME("Unsupported event binding on target %p\n", event_target
);
251 wine_rb_put(&event_target
->handler_map
, container
->type
, &container
->entry
);
255 static void remove_event_listener(EventTarget
*event_target
, const WCHAR
*type_name
, listener_type_t type
, IDispatch
*function
)
257 listener_container_t
*container
;
258 event_listener_t
*listener
;
260 container
= get_listener_container(event_target
, type_name
, FALSE
);
264 LIST_FOR_EACH_ENTRY(listener
, &container
->listeners
, event_listener_t
, entry
) {
265 if(listener
->function
== function
&& listener
->type
== type
) {
266 IDispatch_Release(listener
->function
);
267 list_remove(&listener
->entry
);
274 static HRESULT
get_gecko_target(IEventTarget
*,nsIDOMEventTarget
**);
278 IHTMLEventObj IHTMLEventObj_iface
;
283 VARIANT return_value
;
286 static inline HTMLEventObj
*impl_from_IHTMLEventObj(IHTMLEventObj
*iface
)
288 return CONTAINING_RECORD(iface
, HTMLEventObj
, IHTMLEventObj_iface
);
291 static HRESULT WINAPI
HTMLEventObj_QueryInterface(IHTMLEventObj
*iface
, REFIID riid
, void **ppv
)
293 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
295 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
297 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
298 *ppv
= &This
->IHTMLEventObj_iface
;
299 }else if(IsEqualGUID(&IID_IHTMLEventObj
, riid
)) {
300 *ppv
= &This
->IHTMLEventObj_iface
;
301 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
302 return *ppv
? S_OK
: E_NOINTERFACE
;
305 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
306 return E_NOINTERFACE
;
309 IUnknown_AddRef((IUnknown
*)*ppv
);
313 static ULONG WINAPI
HTMLEventObj_AddRef(IHTMLEventObj
*iface
)
315 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
316 LONG ref
= InterlockedIncrement(&This
->ref
);
318 TRACE("(%p) ref=%d\n", This
, ref
);
323 static ULONG WINAPI
HTMLEventObj_Release(IHTMLEventObj
*iface
)
325 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
326 LONG ref
= InterlockedDecrement(&This
->ref
);
328 TRACE("(%p) ref=%d\n", This
, ref
);
332 IDOMEvent_Release(&This
->event
->IDOMEvent_iface
);
333 release_dispex(&This
->dispex
);
340 static HRESULT WINAPI
HTMLEventObj_GetTypeInfoCount(IHTMLEventObj
*iface
, UINT
*pctinfo
)
342 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
343 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
346 static HRESULT WINAPI
HTMLEventObj_GetTypeInfo(IHTMLEventObj
*iface
, UINT iTInfo
,
347 LCID lcid
, ITypeInfo
**ppTInfo
)
349 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
350 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
353 static HRESULT WINAPI
HTMLEventObj_GetIDsOfNames(IHTMLEventObj
*iface
, REFIID riid
,
354 LPOLESTR
*rgszNames
, UINT cNames
,
355 LCID lcid
, DISPID
*rgDispId
)
357 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
358 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
362 static HRESULT WINAPI
HTMLEventObj_Invoke(IHTMLEventObj
*iface
, DISPID dispIdMember
,
363 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
364 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
366 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
367 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
368 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
371 static HRESULT WINAPI
HTMLEventObj_get_srcElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
373 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
375 TRACE("(%p)->(%p)\n", This
, p
);
382 return IDOMEvent_get_srcElement(&This
->event
->IDOMEvent_iface
, p
);
385 static HRESULT WINAPI
HTMLEventObj_get_altKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
387 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
388 cpp_bool ret
= FALSE
;
390 TRACE("(%p)->(%p)\n", This
, p
);
392 if(This
->event
&& This
->event
->mouse_event
)
393 return IDOMMouseEvent_get_altKey(&This
->event
->IDOMMouseEvent_iface
, p
);
395 if(This
->event
&& This
->event
->keyboard_event
)
396 return IDOMKeyboardEvent_get_altKey(&This
->event
->IDOMKeyboardEvent_iface
, p
);
398 *p
= variant_bool(ret
);
402 static HRESULT WINAPI
HTMLEventObj_get_ctrlKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
404 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
405 cpp_bool ret
= FALSE
;
407 TRACE("(%p)->(%p)\n", This
, p
);
409 if(This
->event
&& This
->event
->mouse_event
)
410 return IDOMMouseEvent_get_ctrlKey(&This
->event
->IDOMMouseEvent_iface
, p
);
412 if(This
->event
&& This
->event
->keyboard_event
)
413 return IDOMKeyboardEvent_get_ctrlKey(&This
->event
->IDOMKeyboardEvent_iface
, p
);
415 *p
= variant_bool(ret
);
419 static HRESULT WINAPI
HTMLEventObj_get_shiftKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
421 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
422 cpp_bool ret
= FALSE
;
424 TRACE("(%p)->(%p)\n", This
, p
);
426 if(This
->event
&& This
->event
->mouse_event
)
427 return IDOMMouseEvent_get_shiftKey(&This
->event
->IDOMMouseEvent_iface
, p
);
429 if(This
->event
&& This
->event
->keyboard_event
)
430 return IDOMKeyboardEvent_get_shiftKey(&This
->event
->IDOMKeyboardEvent_iface
, p
);
432 *p
= variant_bool(ret
);
436 static HRESULT WINAPI
HTMLEventObj_put_returnValue(IHTMLEventObj
*iface
, VARIANT v
)
438 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
440 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
442 if(V_VT(&v
) != VT_BOOL
) {
443 FIXME("unsupported value %s\n", debugstr_variant(&v
));
444 return DISP_E_BADVARTYPE
;
447 This
->return_value
= v
;
448 if(!V_BOOL(&v
) && This
->event
)
449 IDOMEvent_preventDefault(&This
->event
->IDOMEvent_iface
);
453 static HRESULT WINAPI
HTMLEventObj_get_returnValue(IHTMLEventObj
*iface
, VARIANT
*p
)
455 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
457 TRACE("(%p)->(%p)\n", This
, p
);
460 return VariantCopy(p
, &This
->return_value
);
463 static HRESULT WINAPI
HTMLEventObj_put_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL v
)
465 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
467 TRACE("(%p)->(%x)\n", This
, v
);
470 IDOMEvent_stopPropagation(&This
->event
->IDOMEvent_iface
);
474 static HRESULT WINAPI
HTMLEventObj_get_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
476 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
478 TRACE("(%p)->(%p)\n", This
, p
);
480 *p
= variant_bool(This
->event
&& This
->event
->stop_propagation
);
484 static HRESULT WINAPI
HTMLEventObj_get_fromElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
486 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
488 TRACE("(%p)->(%p)\n", This
, p
);
490 if(This
->event
&& This
->event
->mouse_event
)
491 return IDOMMouseEvent_get_fromElement(&This
->event
->IDOMMouseEvent_iface
, p
);
497 static HRESULT WINAPI
HTMLEventObj_get_toElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
499 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
501 TRACE("(%p)->(%p)\n", This
, p
);
503 if(This
->event
&& This
->event
->mouse_event
)
504 return IDOMMouseEvent_get_toElement(&This
->event
->IDOMMouseEvent_iface
, p
);
510 static HRESULT WINAPI
HTMLEventObj_put_keyCode(IHTMLEventObj
*iface
, LONG v
)
512 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
513 FIXME("(%p)->(%d)\n", This
, v
);
517 static HRESULT WINAPI
HTMLEventObj_get_keyCode(IHTMLEventObj
*iface
, LONG
*p
)
519 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
521 TRACE("(%p)->(%p)\n", This
, p
);
523 if(This
->event
&& This
->event
->keyboard_event
)
524 return IDOMKeyboardEvent_get_keyCode(&This
->event
->IDOMKeyboardEvent_iface
, p
);
530 static HRESULT WINAPI
HTMLEventObj_get_button(IHTMLEventObj
*iface
, LONG
*p
)
532 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
535 TRACE("(%p)->(%p)\n", This
, p
);
537 if(This
->event
&& This
->event
->mouse_event
) {
539 hres
= IDOMMouseEvent_get_button(&This
->event
->IDOMMouseEvent_iface
, &button
);
548 static HRESULT WINAPI
HTMLEventObj_get_type(IHTMLEventObj
*iface
, BSTR
*p
)
550 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
552 TRACE("(%p)->(%p)\n", This
, p
);
559 return IDOMEvent_get_type(&This
->event
->IDOMEvent_iface
, p
);
562 static HRESULT WINAPI
HTMLEventObj_get_qualifier(IHTMLEventObj
*iface
, BSTR
*p
)
564 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
566 FIXME("(%p)->(%p)\n", This
, p
);
572 static HRESULT WINAPI
HTMLEventObj_get_reason(IHTMLEventObj
*iface
, LONG
*p
)
574 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
576 FIXME("(%p)->(%p)\n", This
, p
);
582 static HRESULT WINAPI
HTMLEventObj_get_x(IHTMLEventObj
*iface
, LONG
*p
)
584 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
587 TRACE("(%p)->(%p)\n", This
, p
);
589 if(This
->event
&& This
->event
->ui_event
) {
592 /* NOTE: pageX is not exactly right here. */
593 nsres
= nsIDOMUIEvent_GetPageX(This
->event
->ui_event
, &x
);
594 assert(nsres
== NS_OK
);
601 static HRESULT WINAPI
HTMLEventObj_get_y(IHTMLEventObj
*iface
, LONG
*p
)
603 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
606 TRACE("(%p)->(%p)\n", This
, p
);
608 if(This
->event
&& This
->event
->ui_event
) {
611 /* NOTE: pageY is not exactly right here. */
612 nsres
= nsIDOMUIEvent_GetPageY(This
->event
->ui_event
, &y
);
613 assert(nsres
== NS_OK
);
620 static HRESULT WINAPI
HTMLEventObj_get_clientX(IHTMLEventObj
*iface
, LONG
*p
)
622 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
624 TRACE("(%p)->(%p)\n", This
, p
);
626 if(This
->event
&& This
->event
->mouse_event
)
627 return IDOMMouseEvent_get_clientX(&This
->event
->IDOMMouseEvent_iface
, p
);
633 static HRESULT WINAPI
HTMLEventObj_get_clientY(IHTMLEventObj
*iface
, LONG
*p
)
635 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
637 TRACE("(%p)->(%p)\n", This
, p
);
639 if(This
->event
&& This
->event
->mouse_event
)
640 return IDOMMouseEvent_get_clientY(&This
->event
->IDOMMouseEvent_iface
, p
);
646 static HRESULT WINAPI
HTMLEventObj_get_offsetX(IHTMLEventObj
*iface
, LONG
*p
)
648 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
650 TRACE("(%p)->(%p)\n", This
, p
);
652 if(This
->event
&& This
->event
->mouse_event
)
653 return IDOMMouseEvent_get_offsetX(&This
->event
->IDOMMouseEvent_iface
, p
);
659 static HRESULT WINAPI
HTMLEventObj_get_offsetY(IHTMLEventObj
*iface
, LONG
*p
)
661 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
663 TRACE("(%p)->(%p)\n", This
, p
);
665 if(This
->event
&& This
->event
->mouse_event
)
666 return IDOMMouseEvent_get_offsetY(&This
->event
->IDOMMouseEvent_iface
, p
);
672 static HRESULT WINAPI
HTMLEventObj_get_screenX(IHTMLEventObj
*iface
, LONG
*p
)
674 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
676 TRACE("(%p)->(%p)\n", This
, p
);
678 if(This
->event
&& This
->event
->mouse_event
)
679 return IDOMMouseEvent_get_screenX(&This
->event
->IDOMMouseEvent_iface
, p
);
685 static HRESULT WINAPI
HTMLEventObj_get_screenY(IHTMLEventObj
*iface
, LONG
*p
)
687 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
689 TRACE("(%p)->(%p)\n", This
, p
);
691 if(This
->event
&& This
->event
->mouse_event
)
692 return IDOMMouseEvent_get_screenY(&This
->event
->IDOMMouseEvent_iface
, p
);
698 static HRESULT WINAPI
HTMLEventObj_get_srcFilter(IHTMLEventObj
*iface
, IDispatch
**p
)
700 HTMLEventObj
*This
= impl_from_IHTMLEventObj(iface
);
702 FIXME("(%p)->(%p)\n", This
, p
);
708 static const IHTMLEventObjVtbl HTMLEventObjVtbl
= {
709 HTMLEventObj_QueryInterface
,
711 HTMLEventObj_Release
,
712 HTMLEventObj_GetTypeInfoCount
,
713 HTMLEventObj_GetTypeInfo
,
714 HTMLEventObj_GetIDsOfNames
,
716 HTMLEventObj_get_srcElement
,
717 HTMLEventObj_get_altKey
,
718 HTMLEventObj_get_ctrlKey
,
719 HTMLEventObj_get_shiftKey
,
720 HTMLEventObj_put_returnValue
,
721 HTMLEventObj_get_returnValue
,
722 HTMLEventObj_put_cancelBubble
,
723 HTMLEventObj_get_cancelBubble
,
724 HTMLEventObj_get_fromElement
,
725 HTMLEventObj_get_toElement
,
726 HTMLEventObj_put_keyCode
,
727 HTMLEventObj_get_keyCode
,
728 HTMLEventObj_get_button
,
729 HTMLEventObj_get_type
,
730 HTMLEventObj_get_qualifier
,
731 HTMLEventObj_get_reason
,
734 HTMLEventObj_get_clientX
,
735 HTMLEventObj_get_clientY
,
736 HTMLEventObj_get_offsetX
,
737 HTMLEventObj_get_offsetY
,
738 HTMLEventObj_get_screenX
,
739 HTMLEventObj_get_screenY
,
740 HTMLEventObj_get_srcFilter
743 static inline HTMLEventObj
*unsafe_impl_from_IHTMLEventObj(IHTMLEventObj
*iface
)
745 return iface
->lpVtbl
== &HTMLEventObjVtbl
? impl_from_IHTMLEventObj(iface
) : NULL
;
748 static const tid_t HTMLEventObj_iface_tids
[] = {
753 static dispex_static_data_t HTMLEventObj_dispex
= {
756 HTMLEventObj_iface_tids
759 static HTMLEventObj
*alloc_event_obj(DOMEvent
*event
, compat_mode_t compat_mode
)
761 HTMLEventObj
*event_obj
;
763 event_obj
= heap_alloc_zero(sizeof(*event_obj
));
767 event_obj
->IHTMLEventObj_iface
.lpVtbl
= &HTMLEventObjVtbl
;
769 event_obj
->event
= event
;
771 IDOMEvent_AddRef(&event
->IDOMEvent_iface
);
773 init_dispatch(&event_obj
->dispex
, (IUnknown
*)&event_obj
->IHTMLEventObj_iface
, &HTMLEventObj_dispex
, compat_mode
);
777 HRESULT
create_event_obj(compat_mode_t compat_mode
, IHTMLEventObj
**ret
)
779 HTMLEventObj
*event_obj
;
781 event_obj
= alloc_event_obj(NULL
, compat_mode
);
783 return E_OUTOFMEMORY
;
785 *ret
= &event_obj
->IHTMLEventObj_iface
;
789 static inline DOMEvent
*impl_from_IDOMEvent(IDOMEvent
*iface
)
791 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMEvent_iface
);
794 static const IDOMEventVtbl DOMEventVtbl
;
796 static inline DOMEvent
*unsafe_impl_from_IDOMEvent(IDOMEvent
*iface
)
798 return iface
&& iface
->lpVtbl
== &DOMEventVtbl
? impl_from_IDOMEvent(iface
) : NULL
;
801 static HRESULT WINAPI
DOMEvent_QueryInterface(IDOMEvent
*iface
, REFIID riid
, void **ppv
)
803 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
805 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
807 if(IsEqualGUID(&IID_IUnknown
, riid
))
808 *ppv
= &This
->IDOMEvent_iface
;
809 else if(IsEqualGUID(&IID_IDOMEvent
, riid
))
810 *ppv
= &This
->IDOMEvent_iface
;
811 else if(This
->ui_event
&& IsEqualGUID(&IID_IDOMUIEvent
, riid
))
812 *ppv
= &This
->IDOMUIEvent_iface
;
813 else if(This
->mouse_event
&& IsEqualGUID(&IID_IDOMMouseEvent
, riid
))
814 *ppv
= &This
->IDOMMouseEvent_iface
;
815 else if(This
->keyboard_event
&& IsEqualGUID(&IID_IDOMKeyboardEvent
, riid
))
816 *ppv
= &This
->IDOMKeyboardEvent_iface
;
817 else if(dispex_query_interface(&This
->dispex
, riid
, ppv
))
818 return *ppv
? S_OK
: E_NOINTERFACE
;
819 else if(!This
->query_interface
|| !(*ppv
= This
->query_interface(This
, riid
))) {
821 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
822 return E_NOINTERFACE
;
825 IUnknown_AddRef((IUnknown
*)*ppv
);
829 static ULONG WINAPI
DOMEvent_AddRef(IDOMEvent
*iface
)
831 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
832 LONG ref
= InterlockedIncrement(&This
->ref
);
834 TRACE("(%p) ref=%u\n", This
, ref
);
839 static ULONG WINAPI
DOMEvent_Release(IDOMEvent
*iface
)
841 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
842 LONG ref
= InterlockedDecrement(&This
->ref
);
844 TRACE("(%p) ref=%u\n", This
, ref
);
850 nsIDOMUIEvent_Release(This
->ui_event
);
851 if(This
->mouse_event
)
852 nsIDOMMouseEvent_Release(This
->mouse_event
);
853 if(This
->keyboard_event
)
854 nsIDOMKeyEvent_Release(This
->keyboard_event
);
856 IEventTarget_Release(&This
->target
->IEventTarget_iface
);
857 nsIDOMEvent_Release(This
->nsevent
);
858 release_dispex(&This
->dispex
);
859 heap_free(This
->type
);
866 static HRESULT WINAPI
DOMEvent_GetTypeInfoCount(IDOMEvent
*iface
, UINT
*pctinfo
)
868 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
869 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
872 static HRESULT WINAPI
DOMEvent_GetTypeInfo(IDOMEvent
*iface
, UINT iTInfo
,
873 LCID lcid
, ITypeInfo
**ppTInfo
)
875 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
876 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
879 static HRESULT WINAPI
DOMEvent_GetIDsOfNames(IDOMEvent
*iface
, REFIID riid
,
880 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
882 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
883 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
887 static HRESULT WINAPI
DOMEvent_Invoke(IDOMEvent
*iface
, DISPID dispIdMember
,
888 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
889 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
891 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
892 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
893 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
896 static HRESULT WINAPI
DOMEvent_get_bubbles(IDOMEvent
*iface
, VARIANT_BOOL
*p
)
898 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
900 TRACE("(%p)->(%p)\n", This
, p
);
902 *p
= variant_bool(This
->bubbles
);
906 static HRESULT WINAPI
DOMEvent_get_cancelable(IDOMEvent
*iface
, VARIANT_BOOL
*p
)
908 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
910 TRACE("(%p)->(%p)\n", This
, p
);
912 *p
= variant_bool(This
->cancelable
);
916 static HRESULT WINAPI
DOMEvent_get_currentTarget(IDOMEvent
*iface
, IEventTarget
**p
)
918 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
920 TRACE("(%p)->(%p)\n", This
, p
);
922 if(This
->current_target
)
923 IEventTarget_AddRef(*p
= &This
->current_target
->IEventTarget_iface
);
929 static HRESULT WINAPI
DOMEvent_get_defaultPrevented(IDOMEvent
*iface
, VARIANT_BOOL
*p
)
931 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
933 TRACE("(%p)->(%p)\n", This
, p
);
935 *p
= variant_bool(This
->prevent_default
);
939 static HRESULT WINAPI
DOMEvent_get_eventPhase(IDOMEvent
*iface
, USHORT
*p
)
941 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
943 TRACE("(%p)->(%p)\n", This
, p
);
949 static HRESULT WINAPI
DOMEvent_get_target(IDOMEvent
*iface
, IEventTarget
**p
)
951 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
953 TRACE("(%p)->(%p)\n", This
, p
);
956 IEventTarget_AddRef(*p
= &This
->target
->IEventTarget_iface
);
962 static HRESULT WINAPI
DOMEvent_get_timeStamp(IDOMEvent
*iface
, ULONGLONG
*p
)
964 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
966 TRACE("(%p)->(%p)\n", This
, p
);
968 *p
= This
->time_stamp
;
972 static HRESULT WINAPI
DOMEvent_get_type(IDOMEvent
*iface
, BSTR
*p
)
974 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
976 TRACE("(%p)->(%p)\n", This
, p
);
979 *p
= SysAllocString(This
->type
);
981 return E_OUTOFMEMORY
;
989 #define nsIDOMEvent_InitEvent(_this,type,bubbles,cancelable) \
990 ((void (WINAPI*)(void*,nsIDOMEvent*,const nsAString*,cpp_bool,cpp_bool)) \
991 &call_thiscall_func)((_this)->lpVtbl->InitEvent,_this,type,bubbles,cancelable)
995 static HRESULT WINAPI
DOMEvent_initEvent(IDOMEvent
*iface
, BSTR type
, VARIANT_BOOL can_bubble
, VARIANT_BOOL cancelable
)
997 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1000 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_w(type
), can_bubble
, cancelable
);
1003 TRACE("called on already dispatched event\n");
1007 heap_free(This
->type
);
1008 This
->type
= heap_strdupW(type
);
1010 return E_OUTOFMEMORY
;
1011 This
->event_id
= str_to_eid(type
);
1013 This
->bubbles
= !!can_bubble
;
1014 This
->cancelable
= !!cancelable
;
1016 nsAString_InitDepend(&nsstr
, type
);
1017 nsIDOMEvent_InitEvent(This
->nsevent
, &nsstr
, This
->bubbles
, This
->cancelable
);
1018 nsAString_Finish(&nsstr
);
1023 static HRESULT WINAPI
DOMEvent_preventDefault(IDOMEvent
*iface
)
1025 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1027 TRACE("(%p)\n", This
);
1029 if(This
->current_target
&& This
->cancelable
) {
1030 This
->prevent_default
= TRUE
;
1031 nsIDOMEvent_PreventDefault(This
->nsevent
);
1036 static HRESULT WINAPI
DOMEvent_stopPropagation(IDOMEvent
*iface
)
1038 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1040 TRACE("(%p)\n", This
);
1042 This
->stop_propagation
= TRUE
;
1043 nsIDOMEvent_StopPropagation(This
->nsevent
);
1047 static HRESULT WINAPI
DOMEvent_stopImmediatePropagation(IDOMEvent
*iface
)
1049 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1051 TRACE("(%p)\n", This
);
1053 This
->stop_immediate_propagation
= This
->stop_propagation
= TRUE
;
1054 nsIDOMEvent_StopImmediatePropagation(This
->nsevent
);
1058 static HRESULT WINAPI
DOMEvent_get_isTrusted(IDOMEvent
*iface
, VARIANT_BOOL
*p
)
1060 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1061 FIXME("(%p)->(%p)\n", This
, p
);
1065 static HRESULT WINAPI
DOMEvent_put_cancelBubble(IDOMEvent
*iface
, VARIANT_BOOL v
)
1067 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1068 FIXME("(%p)->(%x)\n", This
, v
);
1072 static HRESULT WINAPI
DOMEvent_get_cancelBubble(IDOMEvent
*iface
, VARIANT_BOOL
*p
)
1074 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1075 FIXME("(%p)->(%p)\n", This
, p
);
1079 static HRESULT WINAPI
DOMEvent_get_srcElement(IDOMEvent
*iface
, IHTMLElement
**p
)
1081 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1083 TRACE("(%p)->(%p)\n", This
, p
);
1086 IDispatchEx_QueryInterface(&This
->target
->dispex
.IDispatchEx_iface
, &IID_IHTMLElement
, (void**)p
);
1092 static const IDOMEventVtbl DOMEventVtbl
= {
1093 DOMEvent_QueryInterface
,
1096 DOMEvent_GetTypeInfoCount
,
1097 DOMEvent_GetTypeInfo
,
1098 DOMEvent_GetIDsOfNames
,
1100 DOMEvent_get_bubbles
,
1101 DOMEvent_get_cancelable
,
1102 DOMEvent_get_currentTarget
,
1103 DOMEvent_get_defaultPrevented
,
1104 DOMEvent_get_eventPhase
,
1105 DOMEvent_get_target
,
1106 DOMEvent_get_timeStamp
,
1109 DOMEvent_preventDefault
,
1110 DOMEvent_stopPropagation
,
1111 DOMEvent_stopImmediatePropagation
,
1112 DOMEvent_get_isTrusted
,
1113 DOMEvent_put_cancelBubble
,
1114 DOMEvent_get_cancelBubble
,
1115 DOMEvent_get_srcElement
1118 static inline DOMEvent
*impl_from_IDOMUIEvent(IDOMUIEvent
*iface
)
1120 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMUIEvent_iface
);
1123 static HRESULT WINAPI
DOMUIEvent_QueryInterface(IDOMUIEvent
*iface
, REFIID riid
, void **ppv
)
1125 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1126 return IDOMEvent_QueryInterface(&This
->IDOMEvent_iface
, riid
, ppv
);
1129 static ULONG WINAPI
DOMUIEvent_AddRef(IDOMUIEvent
*iface
)
1131 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1132 return IDOMEvent_AddRef(&This
->IDOMEvent_iface
);
1135 static ULONG WINAPI
DOMUIEvent_Release(IDOMUIEvent
*iface
)
1137 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1138 return IDOMEvent_Release(&This
->IDOMEvent_iface
);
1141 static HRESULT WINAPI
DOMUIEvent_GetTypeInfoCount(IDOMUIEvent
*iface
, UINT
*pctinfo
)
1143 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1144 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1147 static HRESULT WINAPI
DOMUIEvent_GetTypeInfo(IDOMUIEvent
*iface
, UINT iTInfo
,
1148 LCID lcid
, ITypeInfo
**ppTInfo
)
1150 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1151 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1154 static HRESULT WINAPI
DOMUIEvent_GetIDsOfNames(IDOMUIEvent
*iface
, REFIID riid
,
1155 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1157 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1158 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1162 static HRESULT WINAPI
DOMUIEvent_Invoke(IDOMUIEvent
*iface
, DISPID dispIdMember
,
1163 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1164 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1166 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1167 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1168 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1171 static HRESULT WINAPI
DOMUIEvent_get_view(IDOMUIEvent
*iface
, IHTMLWindow2
**p
)
1173 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1174 mozIDOMWindowProxy
*moz_window
;
1175 HTMLOuterWindow
*view
= NULL
;
1178 TRACE("(%p)->(%p)\n", This
, p
);
1180 nsres
= nsIDOMUIEvent_GetView(This
->ui_event
, &moz_window
);
1181 if(NS_FAILED(nsres
))
1185 view
= mozwindow_to_window(moz_window
);
1186 mozIDOMWindowProxy_Release(moz_window
);
1189 IHTMLWindow2_AddRef((*p
= &view
->base
.inner_window
->base
.IHTMLWindow2_iface
));
1195 static HRESULT WINAPI
DOMUIEvent_get_detail(IDOMUIEvent
*iface
, LONG
*p
)
1197 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1201 TRACE("(%p)->(%p)\n", This
, p
);
1203 nsres
= nsIDOMUIEvent_GetDetail(This
->ui_event
, &detail
);
1204 if(NS_FAILED(nsres
))
1211 static HRESULT WINAPI
DOMUIEvent_initUIEvent(IDOMUIEvent
*iface
, BSTR type
, VARIANT_BOOL can_bubble
,
1212 VARIANT_BOOL cancelable
, IHTMLWindow2
*view
, LONG detail
)
1214 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1219 TRACE("(%p)->(%s %x %x %p %x)\n", This
, debugstr_w(type
), can_bubble
, cancelable
, view
, detail
);
1222 TRACE("called on already dispatched event\n");
1227 FIXME("view argument is not supported\n");
1229 hres
= IDOMEvent_initEvent(&This
->IDOMEvent_iface
, type
, can_bubble
, cancelable
);
1233 nsAString_InitDepend(&type_str
, type
);
1234 nsres
= nsIDOMUIEvent_InitUIEvent(This
->ui_event
, &type_str
, !!can_bubble
, !!cancelable
,
1235 NULL
/* FIXME */, detail
);
1236 nsAString_Finish(&type_str
);
1237 if(NS_FAILED(nsres
)) {
1238 FIXME("InitUIEvent failed: %08x\n", nsres
);
1245 static const IDOMUIEventVtbl DOMUIEventVtbl
= {
1246 DOMUIEvent_QueryInterface
,
1249 DOMUIEvent_GetTypeInfoCount
,
1250 DOMUIEvent_GetTypeInfo
,
1251 DOMUIEvent_GetIDsOfNames
,
1253 DOMUIEvent_get_view
,
1254 DOMUIEvent_get_detail
,
1255 DOMUIEvent_initUIEvent
1258 static inline DOMEvent
*impl_from_IDOMMouseEvent(IDOMMouseEvent
*iface
)
1260 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMMouseEvent_iface
);
1263 static HRESULT WINAPI
DOMMouseEvent_QueryInterface(IDOMMouseEvent
*iface
, REFIID riid
, void **ppv
)
1265 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1266 return IDOMEvent_QueryInterface(&This
->IDOMEvent_iface
, riid
, ppv
);
1269 static ULONG WINAPI
DOMMouseEvent_AddRef(IDOMMouseEvent
*iface
)
1271 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1272 return IDOMEvent_AddRef(&This
->IDOMEvent_iface
);
1275 static ULONG WINAPI
DOMMouseEvent_Release(IDOMMouseEvent
*iface
)
1277 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1278 return IDOMEvent_Release(&This
->IDOMEvent_iface
);
1281 static HRESULT WINAPI
DOMMouseEvent_GetTypeInfoCount(IDOMMouseEvent
*iface
, UINT
*pctinfo
)
1283 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1284 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1287 static HRESULT WINAPI
DOMMouseEvent_GetTypeInfo(IDOMMouseEvent
*iface
, UINT iTInfo
,
1288 LCID lcid
, ITypeInfo
**ppTInfo
)
1290 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1291 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1294 static HRESULT WINAPI
DOMMouseEvent_GetIDsOfNames(IDOMMouseEvent
*iface
, REFIID riid
,
1295 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1297 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1298 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1302 static HRESULT WINAPI
DOMMouseEvent_Invoke(IDOMMouseEvent
*iface
, DISPID dispIdMember
,
1303 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1304 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1306 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1307 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1308 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1311 static HRESULT WINAPI
DOMMouseEvent_get_screenX(IDOMMouseEvent
*iface
, LONG
*p
)
1313 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1317 TRACE("(%p)->(%p)\n", This
, p
);
1319 nsres
= nsIDOMMouseEvent_GetScreenX(This
->mouse_event
, &screen_x
);
1320 if(NS_FAILED(nsres
))
1327 static HRESULT WINAPI
DOMMouseEvent_get_screenY(IDOMMouseEvent
*iface
, LONG
*p
)
1329 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1333 TRACE("(%p)->(%p)\n", This
, p
);
1335 nsres
= nsIDOMMouseEvent_GetScreenY(This
->mouse_event
, &screen_y
);
1336 if(NS_FAILED(nsres
))
1343 static HRESULT WINAPI
DOMMouseEvent_get_clientX(IDOMMouseEvent
*iface
, LONG
*p
)
1345 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1349 TRACE("(%p)->(%p)\n", This
, p
);
1351 nsres
= nsIDOMMouseEvent_GetClientX(This
->mouse_event
, &client_x
);
1352 if(NS_FAILED(nsres
))
1359 static HRESULT WINAPI
DOMMouseEvent_get_clientY(IDOMMouseEvent
*iface
, LONG
*p
)
1361 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1365 TRACE("(%p)->(%p)\n", This
, p
);
1367 nsres
= nsIDOMMouseEvent_GetClientY(This
->mouse_event
, &client_y
);
1368 if(NS_FAILED(nsres
))
1375 static HRESULT WINAPI
DOMMouseEvent_get_ctrlKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1377 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1381 TRACE("(%p)->(%p)\n", This
, p
);
1383 nsres
= nsIDOMMouseEvent_GetCtrlKey(This
->mouse_event
, &r
);
1384 if(NS_FAILED(nsres
))
1387 *p
= variant_bool(r
);
1391 static HRESULT WINAPI
DOMMouseEvent_get_shiftKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1393 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1397 TRACE("(%p)->(%p)\n", This
, p
);
1399 nsres
= nsIDOMMouseEvent_GetShiftKey(This
->mouse_event
, &r
);
1400 if(NS_FAILED(nsres
))
1403 *p
= variant_bool(r
);
1407 static HRESULT WINAPI
DOMMouseEvent_get_altKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1409 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1413 TRACE("(%p)->(%p)\n", This
, p
);
1415 nsres
= nsIDOMMouseEvent_GetAltKey(This
->mouse_event
, &r
);
1416 if(NS_FAILED(nsres
))
1419 *p
= variant_bool(r
);
1423 static HRESULT WINAPI
DOMMouseEvent_get_metaKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1425 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1429 TRACE("(%p)->(%p)\n", This
, p
);
1431 nsres
= nsIDOMMouseEvent_GetMetaKey(This
->mouse_event
, &r
);
1432 if(NS_FAILED(nsres
))
1435 *p
= variant_bool(r
);
1439 static HRESULT WINAPI
DOMMouseEvent_get_button(IDOMMouseEvent
*iface
, USHORT
*p
)
1441 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1445 TRACE("(%p)->(%p)\n", This
, p
);
1447 nsres
= nsIDOMMouseEvent_GetButton(This
->mouse_event
, &r
);
1448 if(NS_FAILED(nsres
))
1455 static HRESULT WINAPI
DOMMouseEvent_get_relatedTarget(IDOMMouseEvent
*iface
, IEventTarget
**p
)
1457 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1458 nsIDOMEventTarget
*related_target
;
1459 nsIDOMNode
*target_node
;
1464 TRACE("(%p)->(%p)\n", This
, p
);
1466 nsres
= nsIDOMMouseEvent_GetRelatedTarget(This
->mouse_event
, &related_target
);
1467 if(NS_FAILED(nsres
))
1470 if(!related_target
) {
1475 nsres
= nsIDOMEventTarget_QueryInterface(related_target
, &IID_nsIDOMNode
, (void**)&target_node
);
1476 nsIDOMEventTarget_Release(related_target
);
1477 if(NS_FAILED(nsres
)) {
1478 FIXME("Only node targets supported\n");
1482 hres
= get_node(target_node
, TRUE
, &node
);
1483 nsIDOMNode_Release(target_node
);
1487 *p
= &node
->event_target
.IEventTarget_iface
;
1491 static HRESULT WINAPI
DOMMouseEvent_initMouseEvent(IDOMMouseEvent
*iface
, BSTR type
,
1492 VARIANT_BOOL can_bubble
, VARIANT_BOOL cancelable
, IHTMLWindow2
*view
, LONG detail
,
1493 LONG screen_x
, LONG screen_y
, LONG client_x
, LONG client_y
, VARIANT_BOOL ctrl_key
,
1494 VARIANT_BOOL alt_key
, VARIANT_BOOL shift_key
, VARIANT_BOOL meta_key
, USHORT button
,
1495 IEventTarget
*related_target
)
1497 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1498 nsIDOMEventTarget
*nstarget
= NULL
;
1503 TRACE("(%p)->(%s %x %x %p %d %d %d %d %d %x %x %x %x %u %p)\n", This
, debugstr_w(type
),
1504 can_bubble
, cancelable
, view
, detail
, screen_x
, screen_y
, client_x
, client_y
,
1505 ctrl_key
, alt_key
, shift_key
, meta_key
, button
, related_target
);
1508 TRACE("called on already dispatched event\n");
1513 FIXME("view argument is not supported\n");
1515 if(related_target
) {
1516 hres
= get_gecko_target(related_target
, &nstarget
);
1521 hres
= IDOMEvent_initEvent(&This
->IDOMEvent_iface
, type
, can_bubble
, cancelable
);
1522 if(SUCCEEDED(hres
)) {
1523 nsAString_InitDepend(&type_str
, type
);
1524 nsres
= nsIDOMMouseEvent_InitMouseEvent(This
->mouse_event
, &type_str
, can_bubble
, cancelable
,
1525 NULL
/* FIXME */, detail
, screen_x
, screen_y
,
1526 client_x
, client_y
, !!ctrl_key
, !!alt_key
, !!shift_key
,
1527 !!meta_key
, button
, nstarget
);
1528 nsAString_Finish(&type_str
);
1529 if(NS_FAILED(nsres
)) {
1530 FIXME("InitMouseEvent failed: %08x\n", nsres
);
1536 nsIDOMEventTarget_Release(nstarget
);
1540 static HRESULT WINAPI
DOMMouseEvent_getModifierState(IDOMMouseEvent
*iface
, BSTR key
,
1541 VARIANT_BOOL
*activated
)
1543 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1544 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(key
), activated
);
1548 static HRESULT WINAPI
DOMMouseEvent_get_buttons(IDOMMouseEvent
*iface
, USHORT
*p
)
1550 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1554 TRACE("(%p)->(%p)\n", This
, p
);
1556 nsres
= nsIDOMMouseEvent_GetButtons(This
->mouse_event
, &r
);
1557 if(NS_FAILED(nsres
))
1564 static HRESULT WINAPI
DOMMouseEvent_get_fromElement(IDOMMouseEvent
*iface
, IHTMLElement
**p
)
1566 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1567 IEventTarget
*related_target
= NULL
;
1569 TRACE("(%p)->(%p)\n", This
, p
);
1571 if(This
->event_id
!= EVENTID_LAST
) {
1572 HRESULT hres
= S_OK
;
1573 if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_FROM_RELATED
)
1574 hres
= IDOMMouseEvent_get_relatedTarget(&This
->IDOMMouseEvent_iface
, &related_target
);
1575 else if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_TO_RELATED
)
1576 hres
= IDOMEvent_get_target(&This
->IDOMEvent_iface
, &related_target
);
1581 if(!related_target
) {
1586 IEventTarget_QueryInterface(related_target
, &IID_IHTMLElement
, (void**)p
);
1590 static HRESULT WINAPI
DOMMouseEvent_get_toElement(IDOMMouseEvent
*iface
, IHTMLElement
**p
)
1592 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1593 IEventTarget
*related_target
= NULL
;
1595 TRACE("(%p)->(%p)\n", This
, p
);
1597 if(This
->event_id
!= EVENTID_LAST
) {
1598 HRESULT hres
= S_OK
;
1599 if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_TO_RELATED
)
1600 hres
= IDOMMouseEvent_get_relatedTarget(&This
->IDOMMouseEvent_iface
, &related_target
);
1601 else if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_FROM_RELATED
)
1602 hres
= IDOMEvent_get_target(&This
->IDOMEvent_iface
, &related_target
);
1607 if(!related_target
) {
1612 IEventTarget_QueryInterface(related_target
, &IID_IHTMLElement
, (void**)p
);
1616 static HRESULT WINAPI
DOMMouseEvent_get_x(IDOMMouseEvent
*iface
, LONG
*p
)
1618 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1619 FIXME("(%p)->(%p)\n", This
, p
);
1623 static HRESULT WINAPI
DOMMouseEvent_get_y(IDOMMouseEvent
*iface
, LONG
*p
)
1625 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1626 FIXME("(%p)->(%p)\n", This
, p
);
1630 static HRESULT WINAPI
DOMMouseEvent_get_offsetX(IDOMMouseEvent
*iface
, LONG
*p
)
1632 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1634 FIXME("(%p)->(%p) returning 0\n", This
, p
);
1640 static HRESULT WINAPI
DOMMouseEvent_get_offsetY(IDOMMouseEvent
*iface
, LONG
*p
)
1642 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1644 FIXME("(%p)->(%p) returning 0\n", This
, p
);
1650 static HRESULT WINAPI
DOMMouseEvent_get_pageX(IDOMMouseEvent
*iface
, LONG
*p
)
1652 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1656 TRACE("(%p)->(%p)\n", This
, p
);
1658 nsres
= nsIDOMMouseEvent_GetPageX(This
->mouse_event
, &r
);
1659 if(NS_FAILED(nsres
))
1666 static HRESULT WINAPI
DOMMouseEvent_get_pageY(IDOMMouseEvent
*iface
, LONG
*p
)
1668 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1672 TRACE("(%p)->(%p)\n", This
, p
);
1674 nsres
= nsIDOMMouseEvent_GetPageY(This
->mouse_event
, &r
);
1675 if(NS_FAILED(nsres
))
1682 static HRESULT WINAPI
DOMMouseEvent_get_layerX(IDOMMouseEvent
*iface
, LONG
*p
)
1684 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1685 FIXME("(%p)->(%p)\n", This
, p
);
1689 static HRESULT WINAPI
DOMMouseEvent_get_layerY(IDOMMouseEvent
*iface
, LONG
*p
)
1691 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1692 FIXME("(%p)->(%p)\n", This
, p
);
1696 static HRESULT WINAPI
DOMMouseEvent_get_which(IDOMMouseEvent
*iface
, USHORT
*p
)
1698 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1702 TRACE("(%p)->(%p)\n", This
, p
);
1704 nsres
= nsIDOMMouseEvent_GetWhich(This
->mouse_event
, &r
);
1705 if(NS_FAILED(nsres
))
1712 static const IDOMMouseEventVtbl DOMMouseEventVtbl
= {
1713 DOMMouseEvent_QueryInterface
,
1714 DOMMouseEvent_AddRef
,
1715 DOMMouseEvent_Release
,
1716 DOMMouseEvent_GetTypeInfoCount
,
1717 DOMMouseEvent_GetTypeInfo
,
1718 DOMMouseEvent_GetIDsOfNames
,
1719 DOMMouseEvent_Invoke
,
1720 DOMMouseEvent_get_screenX
,
1721 DOMMouseEvent_get_screenY
,
1722 DOMMouseEvent_get_clientX
,
1723 DOMMouseEvent_get_clientY
,
1724 DOMMouseEvent_get_ctrlKey
,
1725 DOMMouseEvent_get_shiftKey
,
1726 DOMMouseEvent_get_altKey
,
1727 DOMMouseEvent_get_metaKey
,
1728 DOMMouseEvent_get_button
,
1729 DOMMouseEvent_get_relatedTarget
,
1730 DOMMouseEvent_initMouseEvent
,
1731 DOMMouseEvent_getModifierState
,
1732 DOMMouseEvent_get_buttons
,
1733 DOMMouseEvent_get_fromElement
,
1734 DOMMouseEvent_get_toElement
,
1735 DOMMouseEvent_get_x
,
1736 DOMMouseEvent_get_y
,
1737 DOMMouseEvent_get_offsetX
,
1738 DOMMouseEvent_get_offsetY
,
1739 DOMMouseEvent_get_pageX
,
1740 DOMMouseEvent_get_pageY
,
1741 DOMMouseEvent_get_layerX
,
1742 DOMMouseEvent_get_layerY
,
1743 DOMMouseEvent_get_which
1746 static inline DOMEvent
*impl_from_IDOMKeyboardEvent(IDOMKeyboardEvent
*iface
)
1748 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMKeyboardEvent_iface
);
1751 static HRESULT WINAPI
DOMKeyboardEvent_QueryInterface(IDOMKeyboardEvent
*iface
, REFIID riid
, void **ppv
)
1753 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1754 return IDOMEvent_QueryInterface(&This
->IDOMEvent_iface
, riid
, ppv
);
1757 static ULONG WINAPI
DOMKeyboardEvent_AddRef(IDOMKeyboardEvent
*iface
)
1759 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1760 return IDOMEvent_AddRef(&This
->IDOMEvent_iface
);
1763 static ULONG WINAPI
DOMKeyboardEvent_Release(IDOMKeyboardEvent
*iface
)
1765 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1766 return IDOMEvent_Release(&This
->IDOMEvent_iface
);
1769 static HRESULT WINAPI
DOMKeyboardEvent_GetTypeInfoCount(IDOMKeyboardEvent
*iface
, UINT
*pctinfo
)
1771 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1772 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1775 static HRESULT WINAPI
DOMKeyboardEvent_GetTypeInfo(IDOMKeyboardEvent
*iface
, UINT iTInfo
,
1776 LCID lcid
, ITypeInfo
**ppTInfo
)
1778 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1779 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1782 static HRESULT WINAPI
DOMKeyboardEvent_GetIDsOfNames(IDOMKeyboardEvent
*iface
, REFIID riid
,
1783 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1785 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1786 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1790 static HRESULT WINAPI
DOMKeyboardEvent_Invoke(IDOMKeyboardEvent
*iface
, DISPID dispIdMember
,
1791 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1792 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1794 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1795 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1796 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1799 static HRESULT WINAPI
DOMKeyboardEvent_get_key(IDOMKeyboardEvent
*iface
, BSTR
*p
)
1801 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1805 TRACE("(%p)->(%p)\n", This
, p
);
1808 nsAString_Init(&key_str
, NULL
);
1809 nsres
= nsIDOMKeyEvent_GetKey(This
->keyboard_event
, &key_str
);
1810 return return_nsstr(nsres
, &key_str
, p
);
1813 static HRESULT WINAPI
DOMKeyboardEvent_get_location(IDOMKeyboardEvent
*iface
, ULONG
*p
)
1815 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1819 TRACE("(%p)->(%p)\n", This
, p
);
1821 nsres
= nsIDOMKeyEvent_GetLocation(This
->keyboard_event
, &r
);
1822 if(NS_FAILED(nsres
))
1829 static HRESULT WINAPI
DOMKeyboardEvent_get_ctrlKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1831 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1835 TRACE("(%p)->(%p)\n", This
, p
);
1837 nsres
= nsIDOMKeyEvent_GetCtrlKey(This
->keyboard_event
, &r
);
1838 if(NS_FAILED(nsres
))
1841 *p
= variant_bool(r
);
1845 static HRESULT WINAPI
DOMKeyboardEvent_get_shiftKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1847 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1851 TRACE("(%p)->(%p)\n", This
, p
);
1853 nsres
= nsIDOMKeyEvent_GetShiftKey(This
->keyboard_event
, &r
);
1854 if(NS_FAILED(nsres
))
1857 *p
= variant_bool(r
);
1861 static HRESULT WINAPI
DOMKeyboardEvent_get_altKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1863 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1867 TRACE("(%p)->(%p)\n", This
, p
);
1869 nsres
= nsIDOMKeyEvent_GetAltKey(This
->keyboard_event
, &r
);
1870 if(NS_FAILED(nsres
))
1873 *p
= variant_bool(r
);
1877 static HRESULT WINAPI
DOMKeyboardEvent_get_metaKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1879 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1883 TRACE("(%p)->(%p)\n", This
, p
);
1885 nsres
= nsIDOMKeyEvent_GetMetaKey(This
->keyboard_event
, &r
);
1886 if(NS_FAILED(nsres
))
1889 *p
= variant_bool(r
);
1893 static HRESULT WINAPI
DOMKeyboardEvent_get_repeat(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1895 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1899 TRACE("(%p)->(%p)\n", This
, p
);
1901 nsres
= nsIDOMKeyEvent_GetRepeat(This
->keyboard_event
, &r
);
1902 if(NS_FAILED(nsres
))
1905 *p
= variant_bool(r
);
1909 static HRESULT WINAPI
DOMKeyboardEvent_getModifierState(IDOMKeyboardEvent
*iface
, BSTR key
,
1910 VARIANT_BOOL
*state
)
1912 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1913 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(key
), state
);
1917 static HRESULT WINAPI
DOMKeyboardEvent_initKeyboardEvent(IDOMKeyboardEvent
*iface
, BSTR type
,
1918 VARIANT_BOOL can_bubble
, VARIANT_BOOL cancelable
, IHTMLWindow2
*view
, BSTR key
,
1919 ULONG location
, BSTR modifiers_list
, VARIANT_BOOL repeat
, BSTR locale
)
1921 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1922 FIXME("(%p)->(%s %x %x %p %s %u %s %x %s)\n", This
, debugstr_w(type
), can_bubble
,
1923 cancelable
, view
, debugstr_w(key
), location
, debugstr_w(modifiers_list
),
1924 repeat
, debugstr_w(locale
));
1928 static HRESULT WINAPI
DOMKeyboardEvent_get_keyCode(IDOMKeyboardEvent
*iface
, LONG
*p
)
1930 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1934 TRACE("(%p)->(%p)\n", This
, p
);
1936 nsres
= nsIDOMKeyEvent_GetKeyCode(This
->keyboard_event
, &r
);
1937 if(NS_FAILED(nsres
))
1944 static HRESULT WINAPI
DOMKeyboardEvent_get_charCode(IDOMKeyboardEvent
*iface
, LONG
*p
)
1946 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1950 TRACE("(%p)->(%p)\n", This
, p
);
1952 nsres
= nsIDOMKeyEvent_GetKeyCode(This
->keyboard_event
, &r
);
1953 if(NS_FAILED(nsres
))
1960 static HRESULT WINAPI
DOMKeyboardEvent_get_which(IDOMKeyboardEvent
*iface
, LONG
*p
)
1962 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1966 TRACE("(%p)->(%p)\n", This
, p
);
1968 nsres
= nsIDOMKeyEvent_GetWhich(This
->keyboard_event
, &r
);
1969 if(NS_FAILED(nsres
))
1976 static HRESULT WINAPI
DOMKeyboardEvent_get_char(IDOMKeyboardEvent
*iface
, VARIANT
*p
)
1978 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1979 FIXME("(%p)->(%p)\n", This
, p
);
1983 static HRESULT WINAPI
DOMKeyboardEvent_get_locale(IDOMKeyboardEvent
*iface
, BSTR
*p
)
1985 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1986 FIXME("(%p)->(%p)\n", This
, p
);
1990 static const IDOMKeyboardEventVtbl DOMKeyboardEventVtbl
= {
1991 DOMKeyboardEvent_QueryInterface
,
1992 DOMKeyboardEvent_AddRef
,
1993 DOMKeyboardEvent_Release
,
1994 DOMKeyboardEvent_GetTypeInfoCount
,
1995 DOMKeyboardEvent_GetTypeInfo
,
1996 DOMKeyboardEvent_GetIDsOfNames
,
1997 DOMKeyboardEvent_Invoke
,
1998 DOMKeyboardEvent_get_key
,
1999 DOMKeyboardEvent_get_location
,
2000 DOMKeyboardEvent_get_ctrlKey
,
2001 DOMKeyboardEvent_get_shiftKey
,
2002 DOMKeyboardEvent_get_altKey
,
2003 DOMKeyboardEvent_get_metaKey
,
2004 DOMKeyboardEvent_get_repeat
,
2005 DOMKeyboardEvent_getModifierState
,
2006 DOMKeyboardEvent_initKeyboardEvent
,
2007 DOMKeyboardEvent_get_keyCode
,
2008 DOMKeyboardEvent_get_charCode
,
2009 DOMKeyboardEvent_get_which
,
2010 DOMKeyboardEvent_get_char
,
2011 DOMKeyboardEvent_get_locale
2016 IDOMCustomEvent IDOMCustomEvent_iface
;
2020 static inline DOMCustomEvent
*impl_from_IDOMCustomEvent(IDOMCustomEvent
*iface
)
2022 return CONTAINING_RECORD(iface
, DOMCustomEvent
, IDOMCustomEvent_iface
);
2025 static HRESULT WINAPI
DOMCustomEvent_QueryInterface(IDOMCustomEvent
*iface
, REFIID riid
, void **ppv
)
2027 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2028 return IDOMEvent_QueryInterface(&This
->event
.IDOMEvent_iface
, riid
, ppv
);
2031 static ULONG WINAPI
DOMCustomEvent_AddRef(IDOMCustomEvent
*iface
)
2033 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2034 return IDOMEvent_AddRef(&This
->event
.IDOMEvent_iface
);
2037 static ULONG WINAPI
DOMCustomEvent_Release(IDOMCustomEvent
*iface
)
2039 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2040 return IDOMEvent_Release(&This
->event
.IDOMEvent_iface
);
2043 static HRESULT WINAPI
DOMCustomEvent_GetTypeInfoCount(IDOMCustomEvent
*iface
, UINT
*pctinfo
)
2045 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2046 return IDispatchEx_GetTypeInfoCount(&This
->event
.dispex
.IDispatchEx_iface
, pctinfo
);
2049 static HRESULT WINAPI
DOMCustomEvent_GetTypeInfo(IDOMCustomEvent
*iface
, UINT iTInfo
,
2050 LCID lcid
, ITypeInfo
**ppTInfo
)
2052 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2053 return IDispatchEx_GetTypeInfo(&This
->event
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
2056 static HRESULT WINAPI
DOMCustomEvent_GetIDsOfNames(IDOMCustomEvent
*iface
, REFIID riid
,
2057 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
2059 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2060 return IDispatchEx_GetIDsOfNames(&This
->event
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
2064 static HRESULT WINAPI
DOMCustomEvent_Invoke(IDOMCustomEvent
*iface
, DISPID dispIdMember
,
2065 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
2066 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
2068 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2069 return IDispatchEx_Invoke(&This
->event
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
2070 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2073 static HRESULT WINAPI
DOMCustomEvent_get_detail(IDOMCustomEvent
*iface
, VARIANT
*p
)
2075 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2077 TRACE("(%p)->(%p)\n", This
, p
);
2080 return VariantCopy(p
, &This
->detail
);
2083 static HRESULT WINAPI
DOMCustomEvent_initCustomEvent(IDOMCustomEvent
*iface
, BSTR type
, VARIANT_BOOL can_bubble
,
2084 VARIANT_BOOL cancelable
, VARIANT
*detail
)
2086 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2089 TRACE("(%p)->(%s %x %x %s)\n", This
, debugstr_w(type
), can_bubble
, cancelable
, debugstr_variant(detail
));
2091 hres
= IDOMEvent_initEvent(&This
->event
.IDOMEvent_iface
, type
, can_bubble
, cancelable
);
2095 return VariantCopy(&This
->detail
, detail
);
2098 static const IDOMCustomEventVtbl DOMCustomEventVtbl
= {
2099 DOMCustomEvent_QueryInterface
,
2100 DOMCustomEvent_AddRef
,
2101 DOMCustomEvent_Release
,
2102 DOMCustomEvent_GetTypeInfoCount
,
2103 DOMCustomEvent_GetTypeInfo
,
2104 DOMCustomEvent_GetIDsOfNames
,
2105 DOMCustomEvent_Invoke
,
2106 DOMCustomEvent_get_detail
,
2107 DOMCustomEvent_initCustomEvent
2110 static DOMCustomEvent
*DOMCustomEvent_from_DOMEvent(DOMEvent
*event
)
2112 return CONTAINING_RECORD(event
, DOMCustomEvent
, event
);
2115 static void *DOMCustomEvent_query_interface(DOMEvent
*event
, REFIID riid
)
2117 DOMCustomEvent
*custom_event
= DOMCustomEvent_from_DOMEvent(event
);
2118 if(IsEqualGUID(&IID_IDOMCustomEvent
, riid
))
2119 return &custom_event
->IDOMCustomEvent_iface
;
2123 static void DOMCustomEvent_destroy(DOMEvent
*event
)
2125 DOMCustomEvent
*custom_event
= DOMCustomEvent_from_DOMEvent(event
);
2126 VariantClear(&custom_event
->detail
);
2130 static const tid_t DOMEvent_iface_tids
[] = {
2135 static dispex_static_data_t DOMEvent_dispex
= {
2141 static const tid_t DOMUIEvent_iface_tids
[] = {
2147 static dispex_static_data_t DOMUIEvent_dispex
= {
2150 DOMUIEvent_iface_tids
2153 static const tid_t DOMMouseEvent_iface_tids
[] = {
2160 static dispex_static_data_t DOMMouseEvent_dispex
= {
2162 DispDOMMouseEvent_tid
,
2163 DOMMouseEvent_iface_tids
2166 static const tid_t DOMKeyboardEvent_iface_tids
[] = {
2169 IDOMKeyboardEvent_tid
,
2173 static dispex_static_data_t DOMKeyboardEvent_dispex
= {
2175 DispDOMKeyboardEvent_tid
,
2176 DOMKeyboardEvent_iface_tids
2179 static const tid_t DOMCustomEvent_iface_tids
[] = {
2181 IDOMCustomEvent_tid
,
2185 static dispex_static_data_t DOMCustomEvent_dispex
= {
2187 DispDOMCustomEvent_tid
,
2188 DOMCustomEvent_iface_tids
2191 static BOOL
check_event_iface(nsIDOMEvent
*event
, REFIID riid
)
2196 nsres
= nsIDOMEvent_QueryInterface(event
, riid
, (void**)&iface
);
2197 if(NS_FAILED(nsres
))
2200 nsISupports_Release(iface
);
2204 static DOMEvent
*alloc_event(nsIDOMEvent
*nsevent
, compat_mode_t compat_mode
, eventid_t event_id
)
2206 dispex_static_data_t
*dispex_data
= &DOMEvent_dispex
;
2207 DOMEvent
*event
= NULL
;
2211 /* 1601 to 1970 is 369 years plus 89 leap days */
2212 const ULONGLONG time_epoch
= (ULONGLONG
)(369 * 365 + 89) * 86400 * 1000;
2214 if(check_event_iface(nsevent
, &IID_nsIDOMCustomEvent
)) {
2215 DOMCustomEvent
*custom_event
= heap_alloc_zero(sizeof(*custom_event
));
2219 custom_event
->IDOMCustomEvent_iface
.lpVtbl
= &DOMCustomEventVtbl
;
2220 custom_event
->event
.query_interface
= DOMCustomEvent_query_interface
;
2221 custom_event
->event
.destroy
= DOMCustomEvent_destroy
;
2222 event
= &custom_event
->event
;
2223 dispex_data
= &DOMCustomEvent_dispex
;
2225 event
= heap_alloc_zero(sizeof(*event
));
2230 event
->IDOMEvent_iface
.lpVtbl
= &DOMEventVtbl
;
2231 event
->IDOMUIEvent_iface
.lpVtbl
= &DOMUIEventVtbl
;
2232 event
->IDOMMouseEvent_iface
.lpVtbl
= &DOMMouseEventVtbl
;
2233 event
->IDOMKeyboardEvent_iface
.lpVtbl
= &DOMKeyboardEventVtbl
;
2235 event
->event_id
= event_id
;
2236 if(event_id
!= EVENTID_LAST
) {
2237 event
->type
= heap_strdupW(event_info
[event_id
].name
);
2242 event
->bubbles
= (event_info
[event_id
].flags
& EVENT_BUBBLES
) != 0;
2243 event
->cancelable
= (event_info
[event_id
].flags
& EVENT_CANCELABLE
) != 0;
2245 nsIDOMEvent_AddRef(event
->nsevent
= nsevent
);
2247 GetSystemTimeAsFileTime(&time
);
2248 event
->time_stamp
= (((ULONGLONG
)time
.dwHighDateTime
<<32) + time
.dwLowDateTime
) / 10000
2251 nsres
= nsIDOMEvent_QueryInterface(nsevent
, &IID_nsIDOMUIEvent
, (void**)&event
->ui_event
);
2252 if(NS_SUCCEEDED(nsres
))
2253 dispex_data
= &DOMUIEvent_dispex
;
2255 event
->ui_event
= NULL
;
2257 nsres
= nsIDOMEvent_QueryInterface(nsevent
, &IID_nsIDOMMouseEvent
, (void**)&event
->mouse_event
);
2258 if(NS_SUCCEEDED(nsres
))
2259 dispex_data
= &DOMMouseEvent_dispex
;
2261 event
->mouse_event
= NULL
;
2263 nsres
= nsIDOMEvent_QueryInterface(nsevent
, &IID_nsIDOMKeyEvent
, (void**)&event
->keyboard_event
);
2264 if(NS_SUCCEEDED(nsres
))
2265 dispex_data
= &DOMKeyboardEvent_dispex
;
2267 event
->keyboard_event
= NULL
;
2269 init_dispatch(&event
->dispex
, (IUnknown
*)&event
->IDOMEvent_iface
, dispex_data
, compat_mode
);
2273 HRESULT
create_event_from_nsevent(nsIDOMEvent
*nsevent
, compat_mode_t compat_mode
, DOMEvent
**ret_event
)
2275 eventid_t event_id
= EVENTID_LAST
;
2280 nsAString_Init(&nsstr
, NULL
);
2281 nsres
= nsIDOMEvent_GetType(nsevent
, &nsstr
);
2282 if(NS_SUCCEEDED(nsres
)) {
2284 nsAString_GetData(&nsstr
, &type
);
2285 event_id
= str_to_eid(type
);
2286 if(event_id
== EVENTID_LAST
)
2287 FIXME("unknown event type %s\n", debugstr_w(type
));
2289 ERR("GetType failed: %08x\n", nsres
);
2291 nsAString_Finish(&nsstr
);
2293 event
= alloc_event(nsevent
, compat_mode
, event_id
);
2295 return E_OUTOFMEMORY
;
2301 HRESULT
create_document_event_str(HTMLDocumentNode
*doc
, const WCHAR
*type
, IDOMEvent
**ret_event
)
2303 nsIDOMEvent
*nsevent
;
2308 nsAString_InitDepend(&nsstr
, type
);
2309 nsres
= nsIDOMHTMLDocument_CreateEvent(doc
->nsdoc
, &nsstr
, &nsevent
);
2310 nsAString_Finish(&nsstr
);
2311 if(NS_FAILED(nsres
)) {
2312 FIXME("CreateEvent(%s) failed: %08x\n", debugstr_w(type
), nsres
);
2316 event
= alloc_event(nsevent
, dispex_compat_mode(&doc
->node
.event_target
.dispex
), EVENTID_LAST
);
2317 nsIDOMEvent_Release(nsevent
);
2319 return E_OUTOFMEMORY
;
2321 *ret_event
= &event
->IDOMEvent_iface
;
2325 HRESULT
create_document_event(HTMLDocumentNode
*doc
, eventid_t event_id
, DOMEvent
**ret_event
)
2327 nsIDOMEvent
*nsevent
;
2332 nsAString_InitDepend(&nsstr
, event_types
[event_info
[event_id
].type
]);
2333 nsres
= nsIDOMHTMLDocument_CreateEvent(doc
->nsdoc
, &nsstr
, &nsevent
);
2334 nsAString_Finish(&nsstr
);
2335 if(NS_FAILED(nsres
)) {
2336 FIXME("CreateEvent(%s) failed: %08x\n", debugstr_w(event_types
[event_info
[event_id
].type
]), nsres
);
2340 event
= alloc_event(nsevent
, dispex_compat_mode(&doc
->node
.event_target
.dispex
), event_id
);
2342 return E_OUTOFMEMORY
;
2344 event
->event_id
= event_id
;
2349 static HRESULT
call_disp_func(IDispatch
*disp
, DISPPARAMS
*dp
, VARIANT
*retv
)
2351 IDispatchEx
*dispex
;
2355 memset(&ei
, 0, sizeof(ei
));
2357 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
2358 if(SUCCEEDED(hres
)) {
2359 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, dp
, retv
, &ei
, NULL
);
2360 IDispatchEx_Release(dispex
);
2362 TRACE("Could not get IDispatchEx interface: %08x\n", hres
);
2363 hres
= IDispatch_Invoke(disp
, 0, &IID_NULL
, GetUserDefaultLCID(), DISPATCH_METHOD
,
2364 dp
, retv
, &ei
, NULL
);
2370 static HRESULT
call_cp_func(IDispatch
*disp
, DISPID dispid
, IHTMLEventObj
*event_obj
, VARIANT
*retv
)
2372 DISPPARAMS dp
= {NULL
,NULL
,0,0};
2377 TRACE("%p,%d,%p,%p\n", disp
, dispid
, event_obj
, retv
);
2380 V_VT(&event_arg
) = VT_DISPATCH
;
2381 V_DISPATCH(&event_arg
) = (IDispatch
*)event_obj
;
2382 dp
.rgvarg
= &event_arg
;
2386 memset(&ei
, 0, sizeof(ei
));
2387 return IDispatch_Invoke(disp
, dispid
, &IID_NULL
, 0, DISPATCH_METHOD
, &dp
, retv
, &ei
, &argerr
);
2390 static BOOL
use_event_quirks(EventTarget
*event_target
)
2392 return dispex_compat_mode(&event_target
->dispex
) < COMPAT_MODE_IE9
;
2395 static BOOL
is_cp_event(cp_static_data_t
*data
, DISPID dispid
)
2400 if(!data
|| dispid
== DISPID_UNKNOWN
)
2404 hres
= get_dispids(data
->tid
, &data
->id_cnt
, &data
->ids
);
2410 max
= data
->id_cnt
-1;
2413 if(data
->ids
[i
] == dispid
)
2416 if(data
->ids
[i
] < dispid
)
2425 static void call_event_handlers(EventTarget
*event_target
, DOMEvent
*event
, dispatch_mode_t dispatch_mode
)
2427 const listener_container_t
*container
= get_listener_container(event_target
, event
->type
, FALSE
);
2428 event_listener_t
*listener
, listeners_buf
[8], *listeners
= listeners_buf
;
2429 unsigned listeners_cnt
, listeners_size
;
2430 ConnectionPointContainer
*cp_container
= NULL
;
2431 const event_target_vtbl_t
*vtbl
= NULL
;
2432 BOOL skip_onevent_listener
= FALSE
;
2436 assert(!event
->current_target
);
2437 event
->current_target
= event_target
;
2439 if(container
&& !list_empty(&container
->listeners
) && event
->phase
!= DEP_CAPTURING_PHASE
) {
2440 listener
= LIST_ENTRY(list_tail(&container
->listeners
), event_listener_t
, entry
);
2441 if(listener
&& listener
->function
&& listener
->type
== LISTENER_TYPE_ONEVENT
2442 && use_event_quirks(event_target
)) {
2443 DISPID named_arg
= DISPID_THIS
;
2445 DISPPARAMS dp
= {&arg
, &named_arg
, 1, 1};
2447 skip_onevent_listener
= TRUE
;
2449 V_VT(&arg
) = VT_DISPATCH
;
2450 V_DISPATCH(&arg
) = (IDispatch
*)&event_target
->dispex
.IDispatchEx_iface
;
2451 V_VT(&v
) = VT_EMPTY
;
2453 TRACE("%p %s >>>\n", event_target
, debugstr_w(event
->type
));
2454 hres
= call_disp_func(listener
->function
, &dp
, &v
);
2456 TRACE("%p %s <<< %s\n", event_target
, debugstr_w(event
->type
), debugstr_variant(&v
));
2458 if(event
->cancelable
) {
2459 if(V_VT(&v
) == VT_BOOL
) {
2461 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2462 }else if(V_VT(&v
) != VT_EMPTY
) {
2463 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2468 WARN("%p %s <<< %08x\n", event_target
, debugstr_w(event
->type
), hres
);
2474 listeners_size
= ARRAY_SIZE(listeners_buf
);
2477 LIST_FOR_EACH_ENTRY(listener
, &container
->listeners
, event_listener_t
, entry
) {
2478 if(!listener
->function
)
2480 switch(listener
->type
) {
2481 case LISTENER_TYPE_ONEVENT
:
2482 if(skip_onevent_listener
|| event
->phase
== DEP_CAPTURING_PHASE
)
2485 case LISTENER_TYPE_CAPTURE
:
2486 if(event
->phase
== DEP_BUBBLING_PHASE
|| dispatch_mode
== DISPATCH_LEGACY
)
2489 case LISTENER_TYPE_BUBBLE
:
2490 if(event
->phase
== DEP_CAPTURING_PHASE
|| dispatch_mode
== DISPATCH_LEGACY
)
2493 case LISTENER_TYPE_ATTACHED
:
2494 if(event
->phase
== DEP_CAPTURING_PHASE
|| dispatch_mode
== DISPATCH_STANDARD
)
2499 if(listeners_cnt
== listeners_size
) {
2500 event_listener_t
*new_listeners
;
2501 if(listeners
== listeners_buf
) {
2502 new_listeners
= heap_alloc(listeners_size
* 2 * sizeof(*new_listeners
));
2505 memcpy(new_listeners
, listeners
, listeners_cnt
* sizeof(*listeners
));
2507 new_listeners
= heap_realloc(listeners
, listeners_size
* 2 * sizeof(*new_listeners
));
2509 listeners
= new_listeners
;
2510 listeners_size
*= 2;
2513 listeners
[listeners_cnt
].type
= listener
->type
;
2514 IDispatch_AddRef(listeners
[listeners_cnt
].function
= listener
->function
);
2519 for(listener
= listeners
; !event
->stop_immediate_propagation
2520 && listener
< listeners
+ listeners_cnt
; listener
++) {
2521 if(listener
->type
!= LISTENER_TYPE_ATTACHED
) {
2522 DISPID named_arg
= DISPID_THIS
;
2524 DISPPARAMS dp
= {args
, &named_arg
, 2, 1};
2526 V_VT(args
) = VT_DISPATCH
;
2527 V_DISPATCH(args
) = (IDispatch
*)&event_target
->dispex
.IDispatchEx_iface
;
2528 V_VT(args
+1) = VT_DISPATCH
;
2529 V_DISPATCH(args
+1) = dispatch_mode
== DISPATCH_LEGACY
2530 ? (IDispatch
*)event
->event_obj
: (IDispatch
*)&event
->IDOMEvent_iface
;
2531 V_VT(&v
) = VT_EMPTY
;
2533 TRACE("%p %s >>>\n", event_target
, debugstr_w(event
->type
));
2534 hres
= call_disp_func(listener
->function
, &dp
, &v
);
2536 TRACE("%p %s <<< %s\n", event_target
, debugstr_w(event
->type
),
2537 debugstr_variant(&v
));
2539 if(event
->cancelable
) {
2540 if(V_VT(&v
) == VT_BOOL
) {
2542 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2543 }else if(V_VT(&v
) != VT_EMPTY
) {
2544 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2549 WARN("%p %s <<< %08x\n", event_target
, debugstr_w(event
->type
), hres
);
2553 DISPPARAMS dp
= {&arg
, NULL
, 1, 0};
2555 V_VT(&arg
) = VT_DISPATCH
;
2556 V_DISPATCH(&arg
) = (IDispatch
*)event
->event_obj
;
2557 V_VT(&v
) = VT_EMPTY
;
2559 TRACE("%p %s attached >>>\n", event_target
, debugstr_w(event
->type
));
2560 hres
= call_disp_func(listener
->function
, &dp
, &v
);
2562 TRACE("%p %s attached <<<\n", event_target
, debugstr_w(event
->type
));
2564 if(event
->cancelable
) {
2565 if(V_VT(&v
) == VT_BOOL
) {
2567 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2568 }else if(V_VT(&v
) != VT_EMPTY
) {
2569 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2574 WARN("%p %s attached <<< %08x\n", event_target
, debugstr_w(event
->type
), hres
);
2579 for(listener
= listeners
; listener
< listeners
+ listeners_cnt
; listener
++)
2580 IDispatch_Release(listener
->function
);
2581 if(listeners
!= listeners_buf
)
2582 heap_free(listeners
);
2584 if(event
->phase
!= DEP_CAPTURING_PHASE
&& event
->event_id
!= EVENTID_LAST
2585 && event_info
[event
->event_id
].dispid
&& (vtbl
= dispex_get_vtbl(&event_target
->dispex
))
2586 && vtbl
->get_cp_container
)
2587 cp_container
= vtbl
->get_cp_container(&event_target
->dispex
);
2589 if(cp_container
->cps
) {
2590 ConnectionPoint
*cp
;
2593 for(j
=0; cp_container
->cp_entries
[j
].riid
; j
++) {
2594 cp
= cp_container
->cps
+ j
;
2595 if(!cp
->sinks_size
|| !is_cp_event(cp
->data
, event_info
[event
->event_id
].dispid
))
2598 for(i
=0; i
< cp
->sinks_size
; i
++) {
2599 if(!cp
->sinks
[i
].disp
)
2602 V_VT(&v
) = VT_EMPTY
;
2604 TRACE("%p cp %s [%u] >>>\n", event_target
, debugstr_w(event
->type
), i
);
2605 hres
= call_cp_func(cp
->sinks
[i
].disp
, event_info
[event
->event_id
].dispid
,
2606 cp
->data
->pass_event_arg
? event
->event_obj
: NULL
, &v
);
2608 TRACE("%p cp %s [%u] <<<\n", event_target
, debugstr_w(event
->type
), i
);
2610 if(event
->cancelable
) {
2611 if(V_VT(&v
) == VT_BOOL
) {
2613 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2614 }else if(V_VT(&v
) != VT_EMPTY
) {
2615 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2620 WARN("%p cp %s [%u] <<< %08x\n", event_target
, debugstr_w(event
->type
), i
, hres
);
2625 IConnectionPointContainer_Release(&cp_container
->IConnectionPointContainer_iface
);
2628 event
->current_target
= NULL
;
2631 static HRESULT
dispatch_event_object(EventTarget
*event_target
, DOMEvent
*event
,
2632 dispatch_mode_t dispatch_mode
, VARIANT_BOOL
*r
)
2634 EventTarget
*target_chain_buf
[8], **target_chain
= target_chain_buf
;
2635 unsigned chain_cnt
, chain_buf_size
, i
;
2636 const event_target_vtbl_t
*vtbl
, *target_vtbl
;
2637 HTMLEventObj
*event_obj_ref
= NULL
;
2638 IHTMLEventObj
*prev_event
= NULL
;
2642 TRACE("(%p) %s\n", event_target
, debugstr_w(event
->type
));
2645 FIXME("Uninitialized event.\n");
2649 if(event
->current_target
) {
2650 FIXME("event is being dispatched.\n");
2654 iter
= event_target
;
2655 IEventTarget_AddRef(&event_target
->IEventTarget_iface
);
2658 chain_buf_size
= ARRAY_SIZE(target_chain_buf
);
2661 if(chain_cnt
== chain_buf_size
) {
2662 EventTarget
**new_chain
;
2663 if(target_chain
== target_chain_buf
) {
2664 new_chain
= heap_alloc(chain_buf_size
* 2 * sizeof(*new_chain
));
2667 memcpy(new_chain
, target_chain
, chain_buf_size
* sizeof(*new_chain
));
2669 new_chain
= heap_realloc(target_chain
, chain_buf_size
* 2 * sizeof(*new_chain
));
2673 chain_buf_size
*= 2;
2674 target_chain
= new_chain
;
2677 target_chain
[chain_cnt
++] = iter
;
2679 if(!(vtbl
= dispex_get_vtbl(&iter
->dispex
)) || !vtbl
->get_parent_event_target
)
2681 iter
= vtbl
->get_parent_event_target(&iter
->dispex
);
2684 if(!event
->event_obj
&& !event
->no_event_obj
) {
2685 event_obj_ref
= alloc_event_obj(event
, dispex_compat_mode(&event
->dispex
));
2687 event
->event_obj
= &event_obj_ref
->IHTMLEventObj_iface
;
2690 target_vtbl
= dispex_get_vtbl(&event_target
->dispex
);
2691 if(target_vtbl
&& target_vtbl
->set_current_event
)
2692 prev_event
= target_vtbl
->set_current_event(&event_target
->dispex
, event
->event_obj
);
2695 IEventTarget_Release(&event
->target
->IEventTarget_iface
);
2696 event
->target
= event_target
;
2697 IEventTarget_AddRef(&event_target
->IEventTarget_iface
);
2699 event
->phase
= DEP_CAPTURING_PHASE
;
2701 while(!event
->stop_propagation
&& i
)
2702 call_event_handlers(target_chain
[i
--], event
, dispatch_mode
);
2704 if(!event
->stop_propagation
) {
2705 event
->phase
= DEP_AT_TARGET
;
2706 call_event_handlers(target_chain
[0], event
, dispatch_mode
);
2709 if(event
->bubbles
) {
2710 event
->phase
= DEP_BUBBLING_PHASE
;
2711 for(i
= 1; !event
->stop_propagation
&& i
< chain_cnt
; i
++)
2712 call_event_handlers(target_chain
[i
], event
, dispatch_mode
);
2716 *r
= variant_bool(!event
->prevent_default
);
2718 if(target_vtbl
&& target_vtbl
->set_current_event
) {
2719 prev_event
= target_vtbl
->set_current_event(&event_target
->dispex
, prev_event
);
2721 IHTMLEventObj_Release(prev_event
);
2724 if(event
->event_id
!= EVENTID_LAST
&& (event_info
[event
->event_id
].flags
& EVENT_HASDEFAULTHANDLERS
)) {
2725 BOOL prevent_default
= event
->prevent_default
;
2726 for(i
= 0; !prevent_default
&& i
< chain_cnt
; i
++) {
2727 vtbl
= dispex_get_vtbl(&target_chain
[i
]->dispex
);
2728 if(!vtbl
|| !vtbl
->handle_event_default
)
2730 hres
= vtbl
->handle_event_default(&event_target
->dispex
, event
->event_id
,
2731 event
->nsevent
, &prevent_default
);
2732 if(FAILED(hres
) || event
->stop_propagation
)
2735 nsIDOMEvent_PreventDefault(event
->nsevent
);
2739 event
->prevent_default
= FALSE
;
2741 event
->event_obj
= NULL
;
2742 IHTMLEventObj_Release(&event_obj_ref
->IHTMLEventObj_iface
);
2745 for(i
= 0; i
< chain_cnt
; i
++)
2746 IEventTarget_Release(&target_chain
[i
]->IEventTarget_iface
);
2747 if(target_chain
!= target_chain_buf
)
2748 heap_free(target_chain
);
2753 void dispatch_event(EventTarget
*event_target
, DOMEvent
*event
)
2755 dispatch_event_object(event_target
, event
, DISPATCH_BOTH
, NULL
);
2758 * We may have registered multiple Gecko listeners for the same event type,
2759 * but we already dispatched event to all relevant targets. Stop event
2760 * propagation here to avoid events being dispatched multiple times.
2762 if(event
->event_id
!= EVENTID_LAST
&& (event_info
[event
->event_id
].flags
& EVENT_BIND_TO_TARGET
))
2763 nsIDOMEvent_StopPropagation(event
->nsevent
);
2766 HRESULT
fire_event(HTMLDOMNode
*node
, const WCHAR
*event_name
, VARIANT
*event_var
, VARIANT_BOOL
*cancelled
)
2768 HTMLEventObj
*event_obj
= NULL
;
2770 HRESULT hres
= S_OK
;
2772 eid
= attr_to_eid(event_name
);
2773 if(eid
== EVENTID_LAST
) {
2774 WARN("unknown event %s\n", debugstr_w(event_name
));
2775 return E_INVALIDARG
;
2778 if(event_var
&& V_VT(event_var
) != VT_EMPTY
&& V_VT(event_var
) != VT_ERROR
) {
2779 if(V_VT(event_var
) != VT_DISPATCH
) {
2780 FIXME("event_var %s not supported\n", debugstr_variant(event_var
));
2784 if(V_DISPATCH(event_var
)) {
2785 IHTMLEventObj
*event_iface
;
2787 hres
= IDispatch_QueryInterface(V_DISPATCH(event_var
), &IID_IHTMLEventObj
, (void**)&event_iface
);
2789 FIXME("No IHTMLEventObj iface\n");
2793 event_obj
= unsafe_impl_from_IHTMLEventObj(event_iface
);
2795 ERR("Not our IHTMLEventObj?\n");
2796 IHTMLEventObj_Release(event_iface
);
2803 event_obj
= alloc_event_obj(NULL
, dispex_compat_mode(&node
->event_target
.dispex
));
2805 return E_OUTOFMEMORY
;
2808 if(!event_obj
->event
)
2809 hres
= create_document_event(node
->doc
, eid
, &event_obj
->event
);
2811 if(SUCCEEDED(hres
)) {
2812 event_obj
->event
->event_obj
= &event_obj
->IHTMLEventObj_iface
;
2813 dispatch_event_object(&node
->event_target
, event_obj
->event
, DISPATCH_LEGACY
, NULL
);
2814 event_obj
->event
->event_obj
= NULL
;
2817 IHTMLEventObj_Release(&event_obj
->IHTMLEventObj_iface
);
2821 *cancelled
= VARIANT_TRUE
; /* FIXME */
2825 HRESULT
ensure_doc_nsevent_handler(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, eventid_t eid
)
2827 TRACE("%s\n", debugstr_w(event_info
[eid
].name
));
2833 case EVENTID_FOCUSIN
:
2834 doc
->event_vector
[eid
] = TRUE
;
2835 eid
= EVENTID_FOCUS
;
2837 case EVENTID_FOCUSOUT
:
2838 doc
->event_vector
[eid
] = TRUE
;
2847 if(event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
) {
2849 }else if(event_info
[eid
].flags
& EVENT_BIND_TO_TARGET
) {
2851 nsnode
= doc
->node
.nsnode
;
2856 if(!nsnode
|| nsnode
== doc
->node
.nsnode
) {
2857 if(doc
->event_vector
[eid
])
2859 doc
->event_vector
[eid
] = TRUE
;
2862 add_nsevent_listener(doc
, nsnode
, event_info
[eid
].name
);
2866 void detach_events(HTMLDocumentNode
*doc
)
2868 if(doc
->event_vector
) {
2871 for(i
=0; i
< EVENTID_LAST
; i
++) {
2872 if(doc
->event_vector
[i
]) {
2873 detach_nsevent(doc
, event_info
[i
].name
);
2874 doc
->event_vector
[i
] = FALSE
;
2879 release_nsevents(doc
);
2882 static HRESULT
get_event_dispex_ref(EventTarget
*event_target
, eventid_t eid
, BOOL alloc
, VARIANT
**ret
)
2887 lstrcpyW(buf
+2, event_info
[eid
].name
);
2888 return dispex_get_dprop_ref(&event_target
->dispex
, buf
, alloc
, ret
);
2891 static event_listener_t
*get_onevent_listener(EventTarget
*event_target
, eventid_t eid
, BOOL alloc
)
2893 listener_container_t
*container
;
2894 event_listener_t
*listener
;
2896 container
= get_listener_container(event_target
, event_info
[eid
].name
, alloc
);
2900 LIST_FOR_EACH_ENTRY_REV(listener
, &container
->listeners
, event_listener_t
, entry
) {
2901 if(listener
->type
== LISTENER_TYPE_ONEVENT
)
2908 listener
= heap_alloc(sizeof(*listener
));
2912 listener
->type
= LISTENER_TYPE_ONEVENT
;
2913 listener
->function
= NULL
;
2914 list_add_tail(&container
->listeners
, &listener
->entry
);
2918 static void remove_event_handler(EventTarget
*event_target
, eventid_t eid
)
2920 event_listener_t
*listener
;
2924 hres
= get_event_dispex_ref(event_target
, eid
, FALSE
, &store
);
2926 VariantClear(store
);
2928 listener
= get_onevent_listener(event_target
, eid
, FALSE
);
2929 if(listener
&& listener
->function
) {
2930 IDispatch_Release(listener
->function
);
2931 listener
->function
= NULL
;
2935 static HRESULT
set_event_handler_disp(EventTarget
*event_target
, eventid_t eid
, IDispatch
*disp
)
2937 event_listener_t
*listener
;
2939 if(event_info
[eid
].flags
& EVENT_FIXME
)
2940 FIXME("unimplemented event %s\n", debugstr_w(event_info
[eid
].name
));
2942 remove_event_handler(event_target
, eid
);
2946 listener
= get_onevent_listener(event_target
, eid
, TRUE
);
2948 return E_OUTOFMEMORY
;
2950 if(listener
->function
)
2951 IDispatch_Release(listener
->function
);
2953 IDispatch_AddRef(listener
->function
= disp
);
2957 HRESULT
set_event_handler(EventTarget
*event_target
, eventid_t eid
, VARIANT
*var
)
2961 if(use_event_quirks(event_target
)) {
2962 WARN("attempt to set to VT_EMPTY in quirks mode\n");
2967 remove_event_handler(event_target
, eid
);
2971 return set_event_handler_disp(event_target
, eid
, V_DISPATCH(var
));
2977 if(!use_event_quirks(event_target
))
2978 FIXME("Setting to string %s not supported\n", debugstr_w(V_BSTR(var
)));
2981 * Setting event handler to string is a rare case and we don't want to
2982 * complicate nor increase memory of listener_container_t for that. Instead,
2983 * we store the value in DispatchEx, which can already handle custom
2986 remove_event_handler(event_target
, eid
);
2988 hres
= get_event_dispex_ref(event_target
, eid
, TRUE
, &v
);
2992 V_BSTR(v
) = SysAllocString(V_BSTR(var
));
2994 return E_OUTOFMEMORY
;
3000 FIXME("not handler %s\n", debugstr_variant(var
));
3007 HRESULT
get_event_handler(EventTarget
*event_target
, eventid_t eid
, VARIANT
*var
)
3009 event_listener_t
*listener
;
3013 hres
= get_event_dispex_ref(event_target
, eid
, FALSE
, &v
);
3014 if(SUCCEEDED(hres
) && V_VT(v
) != VT_EMPTY
) {
3015 V_VT(var
) = VT_EMPTY
;
3016 return VariantCopy(var
, v
);
3019 listener
= get_onevent_listener(event_target
, eid
, FALSE
);
3020 if(listener
&& listener
->function
) {
3021 V_VT(var
) = VT_DISPATCH
;
3022 V_DISPATCH(var
) = listener
->function
;
3023 IDispatch_AddRef(V_DISPATCH(var
));
3025 V_VT(var
) = VT_NULL
;
3031 HRESULT
attach_event(EventTarget
*event_target
, BSTR name
, IDispatch
*disp
, VARIANT_BOOL
*res
)
3033 listener_container_t
*container
;
3034 event_listener_t
*listener
;
3037 eid
= attr_to_eid(name
);
3038 if(eid
== EVENTID_LAST
) {
3039 WARN("Unknown event\n");
3040 *res
= VARIANT_TRUE
;
3044 container
= get_listener_container(event_target
, event_info
[eid
].name
, TRUE
);
3046 return E_OUTOFMEMORY
;
3048 listener
= heap_alloc(sizeof(*listener
));
3050 return E_OUTOFMEMORY
;
3052 listener
->type
= LISTENER_TYPE_ATTACHED
;
3053 IDispatch_AddRef(listener
->function
= disp
);
3054 if(use_event_quirks(event_target
))
3055 list_add_head(&container
->listeners
, &listener
->entry
);
3057 list_add_tail(&container
->listeners
, &listener
->entry
);
3059 *res
= VARIANT_TRUE
;
3063 HRESULT
detach_event(EventTarget
*event_target
, BSTR name
, IDispatch
*disp
)
3067 eid
= attr_to_eid(name
);
3068 if(eid
== EVENTID_LAST
) {
3069 WARN("Unknown event\n");
3073 remove_event_listener(event_target
, event_info
[eid
].name
, LISTENER_TYPE_ATTACHED
, disp
);
3077 void bind_target_event(HTMLDocumentNode
*doc
, EventTarget
*event_target
, const WCHAR
*event
, IDispatch
*disp
)
3081 TRACE("(%p %p %s %p)\n", doc
, event_target
, debugstr_w(event
), disp
);
3083 eid
= attr_to_eid(event
);
3084 if(eid
== EVENTID_LAST
) {
3085 WARN("Unsupported event %s\n", debugstr_w(event
));
3089 set_event_handler_disp(event_target
, eid
, disp
);
3092 void update_doc_cp_events(HTMLDocumentNode
*doc
, cp_static_data_t
*cp
)
3096 for(i
=0; i
< EVENTID_LAST
; i
++) {
3097 if((event_info
[i
].flags
& EVENT_DEFAULTLISTENER
) && is_cp_event(cp
, event_info
[i
].dispid
))
3098 ensure_doc_nsevent_handler(doc
, NULL
, i
);
3102 void check_event_attr(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
)
3104 nsIDOMMozNamedAttrMap
*attr_map
;
3105 const PRUnichar
*name
, *value
;
3106 nsAString name_str
, value_str
;
3107 HTMLDOMNode
*node
= NULL
;
3116 nsres
= nsIDOMElement_HasAttributes(nselem
, &has_attrs
);
3117 if(NS_FAILED(nsres
) || !has_attrs
)
3120 nsres
= nsIDOMElement_GetAttributes(nselem
, &attr_map
);
3121 if(NS_FAILED(nsres
))
3124 nsres
= nsIDOMMozNamedAttrMap_GetLength(attr_map
, &length
);
3125 assert(nsres
== NS_OK
);
3127 nsAString_Init(&name_str
, NULL
);
3128 nsAString_Init(&value_str
, NULL
);
3130 for(i
= 0; i
< length
; i
++) {
3131 nsres
= nsIDOMMozNamedAttrMap_Item(attr_map
, i
, &attr
);
3132 if(NS_FAILED(nsres
))
3135 nsres
= nsIDOMAttr_GetName(attr
, &name_str
);
3136 if(NS_FAILED(nsres
)) {
3137 nsIDOMAttr_Release(attr
);
3141 nsAString_GetData(&name_str
, &name
);
3142 eid
= attr_to_eid(name
);
3143 if(eid
== EVENTID_LAST
) {
3144 nsIDOMAttr_Release(attr
);
3148 nsres
= nsIDOMAttr_GetValue(attr
, &value_str
);
3149 nsIDOMAttr_Release(attr
);
3150 if(NS_FAILED(nsres
))
3153 nsAString_GetData(&value_str
, &value
);
3157 TRACE("%p.%s = %s\n", nselem
, debugstr_w(name
), debugstr_w(value
));
3159 disp
= script_parse_event(doc
->window
, value
);
3164 hres
= get_node((nsIDOMNode
*)nselem
, TRUE
, &node
);
3166 IDispatch_Release(disp
);
3171 set_event_handler_disp(get_node_event_prop_target(node
, eid
), eid
, disp
);
3172 IDispatch_Release(disp
);
3177 nsAString_Finish(&name_str
);
3178 nsAString_Finish(&value_str
);
3179 nsIDOMMozNamedAttrMap_Release(attr_map
);
3182 HRESULT
doc_init_events(HTMLDocumentNode
*doc
)
3187 doc
->event_vector
= heap_alloc_zero(EVENTID_LAST
*sizeof(BOOL
));
3188 if(!doc
->event_vector
)
3189 return E_OUTOFMEMORY
;
3193 for(i
=0; i
< EVENTID_LAST
; i
++) {
3194 if(event_info
[i
].flags
& EVENT_HASDEFAULTHANDLERS
) {
3195 hres
= ensure_doc_nsevent_handler(doc
, NULL
, i
);
3204 static inline EventTarget
*impl_from_IEventTarget(IEventTarget
*iface
)
3206 return CONTAINING_RECORD(iface
, EventTarget
, IEventTarget_iface
);
3209 static HRESULT WINAPI
EventTarget_QueryInterface(IEventTarget
*iface
, REFIID riid
, void **ppv
)
3211 EventTarget
*This
= impl_from_IEventTarget(iface
);
3212 return IDispatchEx_QueryInterface(&This
->dispex
.IDispatchEx_iface
, riid
, ppv
);
3215 static ULONG WINAPI
EventTarget_AddRef(IEventTarget
*iface
)
3217 EventTarget
*This
= impl_from_IEventTarget(iface
);
3218 return IDispatchEx_AddRef(&This
->dispex
.IDispatchEx_iface
);
3221 static ULONG WINAPI
EventTarget_Release(IEventTarget
*iface
)
3223 EventTarget
*This
= impl_from_IEventTarget(iface
);
3224 return IDispatchEx_Release(&This
->dispex
.IDispatchEx_iface
);
3227 static HRESULT WINAPI
EventTarget_GetTypeInfoCount(IEventTarget
*iface
, UINT
*pctinfo
)
3229 EventTarget
*This
= impl_from_IEventTarget(iface
);
3230 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
3233 static HRESULT WINAPI
EventTarget_GetTypeInfo(IEventTarget
*iface
, UINT iTInfo
,
3234 LCID lcid
, ITypeInfo
**ppTInfo
)
3236 EventTarget
*This
= impl_from_IEventTarget(iface
);
3237 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
3240 static HRESULT WINAPI
EventTarget_GetIDsOfNames(IEventTarget
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
3241 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
3243 EventTarget
*This
= impl_from_IEventTarget(iface
);
3244 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
,
3245 rgszNames
, cNames
, lcid
, rgDispId
);
3248 static HRESULT WINAPI
EventTarget_Invoke(IEventTarget
*iface
, DISPID dispIdMember
,
3249 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
3250 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
3252 EventTarget
*This
= impl_from_IEventTarget(iface
);
3253 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
,
3254 riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
3257 static HRESULT WINAPI
EventTarget_addEventListener(IEventTarget
*iface
, BSTR type
,
3258 IDispatch
*function
, VARIANT_BOOL capture
)
3260 EventTarget
*This
= impl_from_IEventTarget(iface
);
3261 listener_type_t listener_type
= capture
? LISTENER_TYPE_CAPTURE
: LISTENER_TYPE_BUBBLE
;
3262 listener_container_t
*container
;
3263 event_listener_t
*listener
;
3265 TRACE("(%p)->(%s %p %x)\n", This
, debugstr_w(type
), function
, capture
);
3267 container
= get_listener_container(This
, type
, TRUE
);
3269 return E_OUTOFMEMORY
;
3271 /* check for duplicates */
3272 LIST_FOR_EACH_ENTRY(listener
, &container
->listeners
, event_listener_t
, entry
) {
3273 if(listener
->type
== listener_type
&& listener
->function
== function
)
3277 listener
= heap_alloc(sizeof(*listener
));
3279 return E_OUTOFMEMORY
;
3281 listener
->type
= listener_type
;
3282 IDispatch_AddRef(listener
->function
= function
);
3283 list_add_tail(&container
->listeners
, &listener
->entry
);
3287 static HRESULT WINAPI
EventTarget_removeEventListener(IEventTarget
*iface
, BSTR type
,
3288 IDispatch
*listener
, VARIANT_BOOL capture
)
3290 EventTarget
*This
= impl_from_IEventTarget(iface
);
3292 TRACE("(%p)->(%s %p %x)\n", This
, debugstr_w(type
), listener
, capture
);
3294 remove_event_listener(This
, type
, capture
? LISTENER_TYPE_CAPTURE
: LISTENER_TYPE_BUBBLE
, listener
);
3298 static HRESULT WINAPI
EventTarget_dispatchEvent(IEventTarget
*iface
, IDOMEvent
*event_iface
, VARIANT_BOOL
*result
)
3300 EventTarget
*This
= impl_from_IEventTarget(iface
);
3301 DOMEvent
*event
= unsafe_impl_from_IDOMEvent(event_iface
);
3303 TRACE("(%p)->(%p %p)\n", This
, event
, result
);
3306 WARN("Invalid event\n");
3307 return E_INVALIDARG
;
3310 return dispatch_event_object(This
, event
, DISPATCH_STANDARD
, result
);
3313 static HRESULT
IEventTarget_addEventListener_hook(DispatchEx
*dispex
, LCID lcid
, WORD flags
,
3314 DISPPARAMS
*dp
, VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
3316 /* If only two arguments were given, implicitly set capture to false */
3317 if((flags
& DISPATCH_METHOD
) && dp
->cArgs
== 2 && !dp
->cNamedArgs
) {
3319 DISPPARAMS new_dp
= {args
, NULL
, 3, 0};
3320 V_VT(args
) = VT_BOOL
;
3321 V_BOOL(args
) = VARIANT_FALSE
;
3322 args
[1] = dp
->rgvarg
[0];
3323 args
[2] = dp
->rgvarg
[1];
3325 TRACE("implicit capture\n");
3327 return IDispatchEx_InvokeEx(&dispex
->IDispatchEx_iface
, DISPID_IEVENTTARGET_ADDEVENTLISTENER
,
3328 lcid
, flags
, &new_dp
, res
, ei
, caller
);
3331 return S_FALSE
; /* fallback to default */
3334 static HRESULT
IEventTarget_removeEventListener_hook(DispatchEx
*dispex
, LCID lcid
, WORD flags
,
3335 DISPPARAMS
*dp
, VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
3337 /* If only two arguments were given, implicitly set capture to false */
3338 if((flags
& DISPATCH_METHOD
) && dp
->cArgs
== 2 && !dp
->cNamedArgs
) {
3340 DISPPARAMS new_dp
= {args
, NULL
, 3, 0};
3341 V_VT(args
) = VT_BOOL
;
3342 V_BOOL(args
) = VARIANT_FALSE
;
3343 args
[1] = dp
->rgvarg
[0];
3344 args
[2] = dp
->rgvarg
[1];
3346 TRACE("implicit capture\n");
3348 return IDispatchEx_InvokeEx(&dispex
->IDispatchEx_iface
, DISPID_IEVENTTARGET_REMOVEEVENTLISTENER
,
3349 lcid
, flags
, &new_dp
, res
, ei
, caller
);
3352 return S_FALSE
; /* fallback to default */
3355 static const IEventTargetVtbl EventTargetVtbl
= {
3356 EventTarget_QueryInterface
,
3358 EventTarget_Release
,
3359 EventTarget_GetTypeInfoCount
,
3360 EventTarget_GetTypeInfo
,
3361 EventTarget_GetIDsOfNames
,
3363 EventTarget_addEventListener
,
3364 EventTarget_removeEventListener
,
3365 EventTarget_dispatchEvent
3368 static EventTarget
*unsafe_impl_from_IEventTarget(IEventTarget
*iface
)
3370 return iface
&& iface
->lpVtbl
== &EventTargetVtbl
? impl_from_IEventTarget(iface
) : NULL
;
3373 static HRESULT
get_gecko_target(IEventTarget
*target
, nsIDOMEventTarget
**ret
)
3375 EventTarget
*event_target
= unsafe_impl_from_IEventTarget(target
);
3376 const event_target_vtbl_t
*vtbl
;
3380 WARN("Not our IEventTarget implementation\n");
3381 return E_INVALIDARG
;
3384 vtbl
= (const event_target_vtbl_t
*)dispex_get_vtbl(&event_target
->dispex
);
3385 nsres
= nsISupports_QueryInterface(vtbl
->get_gecko_target(&event_target
->dispex
),
3386 &IID_nsIDOMEventTarget
, (void**)ret
);
3387 assert(nsres
== NS_OK
);
3391 HRESULT
EventTarget_QI(EventTarget
*event_target
, REFIID riid
, void **ppv
)
3393 if(IsEqualGUID(riid
, &IID_IEventTarget
)) {
3394 if(use_event_quirks(event_target
)) {
3395 WARN("IEventTarget queried, but not supported by in document mode\n");
3397 return E_NOINTERFACE
;
3399 IEventTarget_AddRef(&event_target
->IEventTarget_iface
);
3400 *ppv
= &event_target
->IEventTarget_iface
;
3404 if(dispex_query_interface(&event_target
->dispex
, riid
, ppv
))
3405 return *ppv
? S_OK
: E_NOINTERFACE
;
3407 WARN("(%p)->(%s %p)\n", event_target
, debugstr_mshtml_guid(riid
), ppv
);
3409 return E_NOINTERFACE
;
3412 void EventTarget_init_dispex_info(dispex_data_t
*dispex_info
, compat_mode_t compat_mode
)
3414 static const dispex_hook_t IEventTarget_hooks
[] = {
3415 {DISPID_IEVENTTARGET_ADDEVENTLISTENER
, IEventTarget_addEventListener_hook
},
3416 {DISPID_IEVENTTARGET_REMOVEEVENTLISTENER
, IEventTarget_removeEventListener_hook
},
3420 if(compat_mode
>= COMPAT_MODE_IE9
)
3421 dispex_info_add_interface(dispex_info
, IEventTarget_tid
, IEventTarget_hooks
);
3424 static int event_id_cmp(const void *key
, const struct wine_rb_entry
*entry
)
3426 return wcscmp(key
, WINE_RB_ENTRY_VALUE(entry
, listener_container_t
, entry
)->type
);
3429 void EventTarget_Init(EventTarget
*event_target
, IUnknown
*outer
, dispex_static_data_t
*dispex_data
,
3430 compat_mode_t compat_mode
)
3432 init_dispatch(&event_target
->dispex
, outer
, dispex_data
, compat_mode
);
3433 event_target
->IEventTarget_iface
.lpVtbl
= &EventTargetVtbl
;
3434 wine_rb_init(&event_target
->handler_map
, event_id_cmp
);
3437 void release_event_target(EventTarget
*event_target
)
3439 listener_container_t
*iter
, *iter2
;
3441 WINE_RB_FOR_EACH_ENTRY_DESTRUCTOR(iter
, iter2
, &event_target
->handler_map
, listener_container_t
, entry
) {
3442 while(!list_empty(&iter
->listeners
)) {
3443 event_listener_t
*listener
= LIST_ENTRY(list_head(&iter
->listeners
), event_listener_t
, entry
);
3444 if(listener
->function
)
3445 IDispatch_Release(listener
->function
);
3446 list_remove(&listener
->entry
);
3447 heap_free(listener
);