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
);
1062 TRACE("(%p)->(%p)\n", This
, p
);
1064 *p
= variant_bool(This
->trusted
);
1068 static HRESULT WINAPI
DOMEvent_put_cancelBubble(IDOMEvent
*iface
, VARIANT_BOOL v
)
1070 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1071 FIXME("(%p)->(%x)\n", This
, v
);
1075 static HRESULT WINAPI
DOMEvent_get_cancelBubble(IDOMEvent
*iface
, VARIANT_BOOL
*p
)
1077 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1078 FIXME("(%p)->(%p)\n", This
, p
);
1082 static HRESULT WINAPI
DOMEvent_get_srcElement(IDOMEvent
*iface
, IHTMLElement
**p
)
1084 DOMEvent
*This
= impl_from_IDOMEvent(iface
);
1086 TRACE("(%p)->(%p)\n", This
, p
);
1089 IDispatchEx_QueryInterface(&This
->target
->dispex
.IDispatchEx_iface
, &IID_IHTMLElement
, (void**)p
);
1095 static const IDOMEventVtbl DOMEventVtbl
= {
1096 DOMEvent_QueryInterface
,
1099 DOMEvent_GetTypeInfoCount
,
1100 DOMEvent_GetTypeInfo
,
1101 DOMEvent_GetIDsOfNames
,
1103 DOMEvent_get_bubbles
,
1104 DOMEvent_get_cancelable
,
1105 DOMEvent_get_currentTarget
,
1106 DOMEvent_get_defaultPrevented
,
1107 DOMEvent_get_eventPhase
,
1108 DOMEvent_get_target
,
1109 DOMEvent_get_timeStamp
,
1112 DOMEvent_preventDefault
,
1113 DOMEvent_stopPropagation
,
1114 DOMEvent_stopImmediatePropagation
,
1115 DOMEvent_get_isTrusted
,
1116 DOMEvent_put_cancelBubble
,
1117 DOMEvent_get_cancelBubble
,
1118 DOMEvent_get_srcElement
1121 static inline DOMEvent
*impl_from_IDOMUIEvent(IDOMUIEvent
*iface
)
1123 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMUIEvent_iface
);
1126 static HRESULT WINAPI
DOMUIEvent_QueryInterface(IDOMUIEvent
*iface
, REFIID riid
, void **ppv
)
1128 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1129 return IDOMEvent_QueryInterface(&This
->IDOMEvent_iface
, riid
, ppv
);
1132 static ULONG WINAPI
DOMUIEvent_AddRef(IDOMUIEvent
*iface
)
1134 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1135 return IDOMEvent_AddRef(&This
->IDOMEvent_iface
);
1138 static ULONG WINAPI
DOMUIEvent_Release(IDOMUIEvent
*iface
)
1140 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1141 return IDOMEvent_Release(&This
->IDOMEvent_iface
);
1144 static HRESULT WINAPI
DOMUIEvent_GetTypeInfoCount(IDOMUIEvent
*iface
, UINT
*pctinfo
)
1146 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1147 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1150 static HRESULT WINAPI
DOMUIEvent_GetTypeInfo(IDOMUIEvent
*iface
, UINT iTInfo
,
1151 LCID lcid
, ITypeInfo
**ppTInfo
)
1153 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1154 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1157 static HRESULT WINAPI
DOMUIEvent_GetIDsOfNames(IDOMUIEvent
*iface
, REFIID riid
,
1158 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1160 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1161 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1165 static HRESULT WINAPI
DOMUIEvent_Invoke(IDOMUIEvent
*iface
, DISPID dispIdMember
,
1166 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1167 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1169 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1170 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1171 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1174 static HRESULT WINAPI
DOMUIEvent_get_view(IDOMUIEvent
*iface
, IHTMLWindow2
**p
)
1176 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1177 mozIDOMWindowProxy
*moz_window
;
1178 HTMLOuterWindow
*view
= NULL
;
1181 TRACE("(%p)->(%p)\n", This
, p
);
1183 nsres
= nsIDOMUIEvent_GetView(This
->ui_event
, &moz_window
);
1184 if(NS_FAILED(nsres
))
1188 view
= mozwindow_to_window(moz_window
);
1189 mozIDOMWindowProxy_Release(moz_window
);
1192 IHTMLWindow2_AddRef((*p
= &view
->base
.inner_window
->base
.IHTMLWindow2_iface
));
1198 static HRESULT WINAPI
DOMUIEvent_get_detail(IDOMUIEvent
*iface
, LONG
*p
)
1200 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1204 TRACE("(%p)->(%p)\n", This
, p
);
1206 nsres
= nsIDOMUIEvent_GetDetail(This
->ui_event
, &detail
);
1207 if(NS_FAILED(nsres
))
1214 static HRESULT WINAPI
DOMUIEvent_initUIEvent(IDOMUIEvent
*iface
, BSTR type
, VARIANT_BOOL can_bubble
,
1215 VARIANT_BOOL cancelable
, IHTMLWindow2
*view
, LONG detail
)
1217 DOMEvent
*This
= impl_from_IDOMUIEvent(iface
);
1222 TRACE("(%p)->(%s %x %x %p %x)\n", This
, debugstr_w(type
), can_bubble
, cancelable
, view
, detail
);
1225 TRACE("called on already dispatched event\n");
1230 FIXME("view argument is not supported\n");
1232 hres
= IDOMEvent_initEvent(&This
->IDOMEvent_iface
, type
, can_bubble
, cancelable
);
1236 nsAString_InitDepend(&type_str
, type
);
1237 nsres
= nsIDOMUIEvent_InitUIEvent(This
->ui_event
, &type_str
, !!can_bubble
, !!cancelable
,
1238 NULL
/* FIXME */, detail
);
1239 nsAString_Finish(&type_str
);
1240 if(NS_FAILED(nsres
)) {
1241 FIXME("InitUIEvent failed: %08x\n", nsres
);
1248 static const IDOMUIEventVtbl DOMUIEventVtbl
= {
1249 DOMUIEvent_QueryInterface
,
1252 DOMUIEvent_GetTypeInfoCount
,
1253 DOMUIEvent_GetTypeInfo
,
1254 DOMUIEvent_GetIDsOfNames
,
1256 DOMUIEvent_get_view
,
1257 DOMUIEvent_get_detail
,
1258 DOMUIEvent_initUIEvent
1261 static inline DOMEvent
*impl_from_IDOMMouseEvent(IDOMMouseEvent
*iface
)
1263 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMMouseEvent_iface
);
1266 static HRESULT WINAPI
DOMMouseEvent_QueryInterface(IDOMMouseEvent
*iface
, REFIID riid
, void **ppv
)
1268 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1269 return IDOMEvent_QueryInterface(&This
->IDOMEvent_iface
, riid
, ppv
);
1272 static ULONG WINAPI
DOMMouseEvent_AddRef(IDOMMouseEvent
*iface
)
1274 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1275 return IDOMEvent_AddRef(&This
->IDOMEvent_iface
);
1278 static ULONG WINAPI
DOMMouseEvent_Release(IDOMMouseEvent
*iface
)
1280 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1281 return IDOMEvent_Release(&This
->IDOMEvent_iface
);
1284 static HRESULT WINAPI
DOMMouseEvent_GetTypeInfoCount(IDOMMouseEvent
*iface
, UINT
*pctinfo
)
1286 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1287 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1290 static HRESULT WINAPI
DOMMouseEvent_GetTypeInfo(IDOMMouseEvent
*iface
, UINT iTInfo
,
1291 LCID lcid
, ITypeInfo
**ppTInfo
)
1293 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1294 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1297 static HRESULT WINAPI
DOMMouseEvent_GetIDsOfNames(IDOMMouseEvent
*iface
, REFIID riid
,
1298 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1300 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1301 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1305 static HRESULT WINAPI
DOMMouseEvent_Invoke(IDOMMouseEvent
*iface
, DISPID dispIdMember
,
1306 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1307 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1309 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1310 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1311 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1314 static HRESULT WINAPI
DOMMouseEvent_get_screenX(IDOMMouseEvent
*iface
, LONG
*p
)
1316 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1320 TRACE("(%p)->(%p)\n", This
, p
);
1322 nsres
= nsIDOMMouseEvent_GetScreenX(This
->mouse_event
, &screen_x
);
1323 if(NS_FAILED(nsres
))
1330 static HRESULT WINAPI
DOMMouseEvent_get_screenY(IDOMMouseEvent
*iface
, LONG
*p
)
1332 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1336 TRACE("(%p)->(%p)\n", This
, p
);
1338 nsres
= nsIDOMMouseEvent_GetScreenY(This
->mouse_event
, &screen_y
);
1339 if(NS_FAILED(nsres
))
1346 static HRESULT WINAPI
DOMMouseEvent_get_clientX(IDOMMouseEvent
*iface
, LONG
*p
)
1348 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1352 TRACE("(%p)->(%p)\n", This
, p
);
1354 nsres
= nsIDOMMouseEvent_GetClientX(This
->mouse_event
, &client_x
);
1355 if(NS_FAILED(nsres
))
1362 static HRESULT WINAPI
DOMMouseEvent_get_clientY(IDOMMouseEvent
*iface
, LONG
*p
)
1364 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1368 TRACE("(%p)->(%p)\n", This
, p
);
1370 nsres
= nsIDOMMouseEvent_GetClientY(This
->mouse_event
, &client_y
);
1371 if(NS_FAILED(nsres
))
1378 static HRESULT WINAPI
DOMMouseEvent_get_ctrlKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1380 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1384 TRACE("(%p)->(%p)\n", This
, p
);
1386 nsres
= nsIDOMMouseEvent_GetCtrlKey(This
->mouse_event
, &r
);
1387 if(NS_FAILED(nsres
))
1390 *p
= variant_bool(r
);
1394 static HRESULT WINAPI
DOMMouseEvent_get_shiftKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1396 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1400 TRACE("(%p)->(%p)\n", This
, p
);
1402 nsres
= nsIDOMMouseEvent_GetShiftKey(This
->mouse_event
, &r
);
1403 if(NS_FAILED(nsres
))
1406 *p
= variant_bool(r
);
1410 static HRESULT WINAPI
DOMMouseEvent_get_altKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1412 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1416 TRACE("(%p)->(%p)\n", This
, p
);
1418 nsres
= nsIDOMMouseEvent_GetAltKey(This
->mouse_event
, &r
);
1419 if(NS_FAILED(nsres
))
1422 *p
= variant_bool(r
);
1426 static HRESULT WINAPI
DOMMouseEvent_get_metaKey(IDOMMouseEvent
*iface
, VARIANT_BOOL
*p
)
1428 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1432 TRACE("(%p)->(%p)\n", This
, p
);
1434 nsres
= nsIDOMMouseEvent_GetMetaKey(This
->mouse_event
, &r
);
1435 if(NS_FAILED(nsres
))
1438 *p
= variant_bool(r
);
1442 static HRESULT WINAPI
DOMMouseEvent_get_button(IDOMMouseEvent
*iface
, USHORT
*p
)
1444 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1448 TRACE("(%p)->(%p)\n", This
, p
);
1450 nsres
= nsIDOMMouseEvent_GetButton(This
->mouse_event
, &r
);
1451 if(NS_FAILED(nsres
))
1458 static HRESULT WINAPI
DOMMouseEvent_get_relatedTarget(IDOMMouseEvent
*iface
, IEventTarget
**p
)
1460 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1461 nsIDOMEventTarget
*related_target
;
1462 nsIDOMNode
*target_node
;
1467 TRACE("(%p)->(%p)\n", This
, p
);
1469 nsres
= nsIDOMMouseEvent_GetRelatedTarget(This
->mouse_event
, &related_target
);
1470 if(NS_FAILED(nsres
))
1473 if(!related_target
) {
1478 nsres
= nsIDOMEventTarget_QueryInterface(related_target
, &IID_nsIDOMNode
, (void**)&target_node
);
1479 nsIDOMEventTarget_Release(related_target
);
1480 if(NS_FAILED(nsres
)) {
1481 FIXME("Only node targets supported\n");
1485 hres
= get_node(target_node
, TRUE
, &node
);
1486 nsIDOMNode_Release(target_node
);
1490 *p
= &node
->event_target
.IEventTarget_iface
;
1494 static HRESULT WINAPI
DOMMouseEvent_initMouseEvent(IDOMMouseEvent
*iface
, BSTR type
,
1495 VARIANT_BOOL can_bubble
, VARIANT_BOOL cancelable
, IHTMLWindow2
*view
, LONG detail
,
1496 LONG screen_x
, LONG screen_y
, LONG client_x
, LONG client_y
, VARIANT_BOOL ctrl_key
,
1497 VARIANT_BOOL alt_key
, VARIANT_BOOL shift_key
, VARIANT_BOOL meta_key
, USHORT button
,
1498 IEventTarget
*related_target
)
1500 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1501 nsIDOMEventTarget
*nstarget
= NULL
;
1506 TRACE("(%p)->(%s %x %x %p %d %d %d %d %d %x %x %x %x %u %p)\n", This
, debugstr_w(type
),
1507 can_bubble
, cancelable
, view
, detail
, screen_x
, screen_y
, client_x
, client_y
,
1508 ctrl_key
, alt_key
, shift_key
, meta_key
, button
, related_target
);
1511 TRACE("called on already dispatched event\n");
1516 FIXME("view argument is not supported\n");
1518 if(related_target
) {
1519 hres
= get_gecko_target(related_target
, &nstarget
);
1524 hres
= IDOMEvent_initEvent(&This
->IDOMEvent_iface
, type
, can_bubble
, cancelable
);
1525 if(SUCCEEDED(hres
)) {
1526 nsAString_InitDepend(&type_str
, type
);
1527 nsres
= nsIDOMMouseEvent_InitMouseEvent(This
->mouse_event
, &type_str
, can_bubble
, cancelable
,
1528 NULL
/* FIXME */, detail
, screen_x
, screen_y
,
1529 client_x
, client_y
, !!ctrl_key
, !!alt_key
, !!shift_key
,
1530 !!meta_key
, button
, nstarget
);
1531 nsAString_Finish(&type_str
);
1532 if(NS_FAILED(nsres
)) {
1533 FIXME("InitMouseEvent failed: %08x\n", nsres
);
1539 nsIDOMEventTarget_Release(nstarget
);
1543 static HRESULT WINAPI
DOMMouseEvent_getModifierState(IDOMMouseEvent
*iface
, BSTR key
,
1544 VARIANT_BOOL
*activated
)
1546 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1547 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(key
), activated
);
1551 static HRESULT WINAPI
DOMMouseEvent_get_buttons(IDOMMouseEvent
*iface
, USHORT
*p
)
1553 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1557 TRACE("(%p)->(%p)\n", This
, p
);
1559 nsres
= nsIDOMMouseEvent_GetButtons(This
->mouse_event
, &r
);
1560 if(NS_FAILED(nsres
))
1567 static HRESULT WINAPI
DOMMouseEvent_get_fromElement(IDOMMouseEvent
*iface
, IHTMLElement
**p
)
1569 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1570 IEventTarget
*related_target
= NULL
;
1572 TRACE("(%p)->(%p)\n", This
, p
);
1574 if(This
->event_id
!= EVENTID_LAST
) {
1575 HRESULT hres
= S_OK
;
1576 if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_FROM_RELATED
)
1577 hres
= IDOMMouseEvent_get_relatedTarget(&This
->IDOMMouseEvent_iface
, &related_target
);
1578 else if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_TO_RELATED
)
1579 hres
= IDOMEvent_get_target(&This
->IDOMEvent_iface
, &related_target
);
1584 if(!related_target
) {
1589 IEventTarget_QueryInterface(related_target
, &IID_IHTMLElement
, (void**)p
);
1593 static HRESULT WINAPI
DOMMouseEvent_get_toElement(IDOMMouseEvent
*iface
, IHTMLElement
**p
)
1595 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1596 IEventTarget
*related_target
= NULL
;
1598 TRACE("(%p)->(%p)\n", This
, p
);
1600 if(This
->event_id
!= EVENTID_LAST
) {
1601 HRESULT hres
= S_OK
;
1602 if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_TO_RELATED
)
1603 hres
= IDOMMouseEvent_get_relatedTarget(&This
->IDOMMouseEvent_iface
, &related_target
);
1604 else if(event_info
[This
->event_id
].flags
& EVENT_MOUSE_FROM_RELATED
)
1605 hres
= IDOMEvent_get_target(&This
->IDOMEvent_iface
, &related_target
);
1610 if(!related_target
) {
1615 IEventTarget_QueryInterface(related_target
, &IID_IHTMLElement
, (void**)p
);
1619 static HRESULT WINAPI
DOMMouseEvent_get_x(IDOMMouseEvent
*iface
, LONG
*p
)
1621 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1622 FIXME("(%p)->(%p)\n", This
, p
);
1626 static HRESULT WINAPI
DOMMouseEvent_get_y(IDOMMouseEvent
*iface
, LONG
*p
)
1628 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1629 FIXME("(%p)->(%p)\n", This
, p
);
1633 static HRESULT WINAPI
DOMMouseEvent_get_offsetX(IDOMMouseEvent
*iface
, LONG
*p
)
1635 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1637 FIXME("(%p)->(%p) returning 0\n", This
, p
);
1643 static HRESULT WINAPI
DOMMouseEvent_get_offsetY(IDOMMouseEvent
*iface
, LONG
*p
)
1645 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1647 FIXME("(%p)->(%p) returning 0\n", This
, p
);
1653 static HRESULT WINAPI
DOMMouseEvent_get_pageX(IDOMMouseEvent
*iface
, LONG
*p
)
1655 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1659 TRACE("(%p)->(%p)\n", This
, p
);
1661 nsres
= nsIDOMMouseEvent_GetPageX(This
->mouse_event
, &r
);
1662 if(NS_FAILED(nsres
))
1669 static HRESULT WINAPI
DOMMouseEvent_get_pageY(IDOMMouseEvent
*iface
, LONG
*p
)
1671 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1675 TRACE("(%p)->(%p)\n", This
, p
);
1677 nsres
= nsIDOMMouseEvent_GetPageY(This
->mouse_event
, &r
);
1678 if(NS_FAILED(nsres
))
1685 static HRESULT WINAPI
DOMMouseEvent_get_layerX(IDOMMouseEvent
*iface
, LONG
*p
)
1687 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1688 FIXME("(%p)->(%p)\n", This
, p
);
1692 static HRESULT WINAPI
DOMMouseEvent_get_layerY(IDOMMouseEvent
*iface
, LONG
*p
)
1694 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1695 FIXME("(%p)->(%p)\n", This
, p
);
1699 static HRESULT WINAPI
DOMMouseEvent_get_which(IDOMMouseEvent
*iface
, USHORT
*p
)
1701 DOMEvent
*This
= impl_from_IDOMMouseEvent(iface
);
1705 TRACE("(%p)->(%p)\n", This
, p
);
1707 nsres
= nsIDOMMouseEvent_GetWhich(This
->mouse_event
, &r
);
1708 if(NS_FAILED(nsres
))
1715 static const IDOMMouseEventVtbl DOMMouseEventVtbl
= {
1716 DOMMouseEvent_QueryInterface
,
1717 DOMMouseEvent_AddRef
,
1718 DOMMouseEvent_Release
,
1719 DOMMouseEvent_GetTypeInfoCount
,
1720 DOMMouseEvent_GetTypeInfo
,
1721 DOMMouseEvent_GetIDsOfNames
,
1722 DOMMouseEvent_Invoke
,
1723 DOMMouseEvent_get_screenX
,
1724 DOMMouseEvent_get_screenY
,
1725 DOMMouseEvent_get_clientX
,
1726 DOMMouseEvent_get_clientY
,
1727 DOMMouseEvent_get_ctrlKey
,
1728 DOMMouseEvent_get_shiftKey
,
1729 DOMMouseEvent_get_altKey
,
1730 DOMMouseEvent_get_metaKey
,
1731 DOMMouseEvent_get_button
,
1732 DOMMouseEvent_get_relatedTarget
,
1733 DOMMouseEvent_initMouseEvent
,
1734 DOMMouseEvent_getModifierState
,
1735 DOMMouseEvent_get_buttons
,
1736 DOMMouseEvent_get_fromElement
,
1737 DOMMouseEvent_get_toElement
,
1738 DOMMouseEvent_get_x
,
1739 DOMMouseEvent_get_y
,
1740 DOMMouseEvent_get_offsetX
,
1741 DOMMouseEvent_get_offsetY
,
1742 DOMMouseEvent_get_pageX
,
1743 DOMMouseEvent_get_pageY
,
1744 DOMMouseEvent_get_layerX
,
1745 DOMMouseEvent_get_layerY
,
1746 DOMMouseEvent_get_which
1749 static inline DOMEvent
*impl_from_IDOMKeyboardEvent(IDOMKeyboardEvent
*iface
)
1751 return CONTAINING_RECORD(iface
, DOMEvent
, IDOMKeyboardEvent_iface
);
1754 static HRESULT WINAPI
DOMKeyboardEvent_QueryInterface(IDOMKeyboardEvent
*iface
, REFIID riid
, void **ppv
)
1756 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1757 return IDOMEvent_QueryInterface(&This
->IDOMEvent_iface
, riid
, ppv
);
1760 static ULONG WINAPI
DOMKeyboardEvent_AddRef(IDOMKeyboardEvent
*iface
)
1762 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1763 return IDOMEvent_AddRef(&This
->IDOMEvent_iface
);
1766 static ULONG WINAPI
DOMKeyboardEvent_Release(IDOMKeyboardEvent
*iface
)
1768 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1769 return IDOMEvent_Release(&This
->IDOMEvent_iface
);
1772 static HRESULT WINAPI
DOMKeyboardEvent_GetTypeInfoCount(IDOMKeyboardEvent
*iface
, UINT
*pctinfo
)
1774 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1775 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1778 static HRESULT WINAPI
DOMKeyboardEvent_GetTypeInfo(IDOMKeyboardEvent
*iface
, UINT iTInfo
,
1779 LCID lcid
, ITypeInfo
**ppTInfo
)
1781 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1782 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1785 static HRESULT WINAPI
DOMKeyboardEvent_GetIDsOfNames(IDOMKeyboardEvent
*iface
, REFIID riid
,
1786 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1788 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1789 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1793 static HRESULT WINAPI
DOMKeyboardEvent_Invoke(IDOMKeyboardEvent
*iface
, DISPID dispIdMember
,
1794 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1795 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1797 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1798 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1799 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1802 static HRESULT WINAPI
DOMKeyboardEvent_get_key(IDOMKeyboardEvent
*iface
, BSTR
*p
)
1804 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1808 TRACE("(%p)->(%p)\n", This
, p
);
1811 nsAString_Init(&key_str
, NULL
);
1812 nsres
= nsIDOMKeyEvent_GetKey(This
->keyboard_event
, &key_str
);
1813 return return_nsstr(nsres
, &key_str
, p
);
1816 static HRESULT WINAPI
DOMKeyboardEvent_get_location(IDOMKeyboardEvent
*iface
, ULONG
*p
)
1818 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1822 TRACE("(%p)->(%p)\n", This
, p
);
1824 nsres
= nsIDOMKeyEvent_GetLocation(This
->keyboard_event
, &r
);
1825 if(NS_FAILED(nsres
))
1832 static HRESULT WINAPI
DOMKeyboardEvent_get_ctrlKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1834 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1838 TRACE("(%p)->(%p)\n", This
, p
);
1840 nsres
= nsIDOMKeyEvent_GetCtrlKey(This
->keyboard_event
, &r
);
1841 if(NS_FAILED(nsres
))
1844 *p
= variant_bool(r
);
1848 static HRESULT WINAPI
DOMKeyboardEvent_get_shiftKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1850 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1854 TRACE("(%p)->(%p)\n", This
, p
);
1856 nsres
= nsIDOMKeyEvent_GetShiftKey(This
->keyboard_event
, &r
);
1857 if(NS_FAILED(nsres
))
1860 *p
= variant_bool(r
);
1864 static HRESULT WINAPI
DOMKeyboardEvent_get_altKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1866 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1870 TRACE("(%p)->(%p)\n", This
, p
);
1872 nsres
= nsIDOMKeyEvent_GetAltKey(This
->keyboard_event
, &r
);
1873 if(NS_FAILED(nsres
))
1876 *p
= variant_bool(r
);
1880 static HRESULT WINAPI
DOMKeyboardEvent_get_metaKey(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1882 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1886 TRACE("(%p)->(%p)\n", This
, p
);
1888 nsres
= nsIDOMKeyEvent_GetMetaKey(This
->keyboard_event
, &r
);
1889 if(NS_FAILED(nsres
))
1892 *p
= variant_bool(r
);
1896 static HRESULT WINAPI
DOMKeyboardEvent_get_repeat(IDOMKeyboardEvent
*iface
, VARIANT_BOOL
*p
)
1898 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1902 TRACE("(%p)->(%p)\n", This
, p
);
1904 nsres
= nsIDOMKeyEvent_GetRepeat(This
->keyboard_event
, &r
);
1905 if(NS_FAILED(nsres
))
1908 *p
= variant_bool(r
);
1912 static HRESULT WINAPI
DOMKeyboardEvent_getModifierState(IDOMKeyboardEvent
*iface
, BSTR key
,
1913 VARIANT_BOOL
*state
)
1915 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1916 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(key
), state
);
1920 static HRESULT WINAPI
DOMKeyboardEvent_initKeyboardEvent(IDOMKeyboardEvent
*iface
, BSTR type
,
1921 VARIANT_BOOL can_bubble
, VARIANT_BOOL cancelable
, IHTMLWindow2
*view
, BSTR key
,
1922 ULONG location
, BSTR modifiers_list
, VARIANT_BOOL repeat
, BSTR locale
)
1924 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1925 FIXME("(%p)->(%s %x %x %p %s %u %s %x %s)\n", This
, debugstr_w(type
), can_bubble
,
1926 cancelable
, view
, debugstr_w(key
), location
, debugstr_w(modifiers_list
),
1927 repeat
, debugstr_w(locale
));
1931 static HRESULT WINAPI
DOMKeyboardEvent_get_keyCode(IDOMKeyboardEvent
*iface
, LONG
*p
)
1933 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1937 TRACE("(%p)->(%p)\n", This
, p
);
1939 nsres
= nsIDOMKeyEvent_GetKeyCode(This
->keyboard_event
, &r
);
1940 if(NS_FAILED(nsres
))
1947 static HRESULT WINAPI
DOMKeyboardEvent_get_charCode(IDOMKeyboardEvent
*iface
, LONG
*p
)
1949 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1953 TRACE("(%p)->(%p)\n", This
, p
);
1955 nsres
= nsIDOMKeyEvent_GetKeyCode(This
->keyboard_event
, &r
);
1956 if(NS_FAILED(nsres
))
1963 static HRESULT WINAPI
DOMKeyboardEvent_get_which(IDOMKeyboardEvent
*iface
, LONG
*p
)
1965 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1969 TRACE("(%p)->(%p)\n", This
, p
);
1971 nsres
= nsIDOMKeyEvent_GetWhich(This
->keyboard_event
, &r
);
1972 if(NS_FAILED(nsres
))
1979 static HRESULT WINAPI
DOMKeyboardEvent_get_char(IDOMKeyboardEvent
*iface
, VARIANT
*p
)
1981 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1982 FIXME("(%p)->(%p)\n", This
, p
);
1986 static HRESULT WINAPI
DOMKeyboardEvent_get_locale(IDOMKeyboardEvent
*iface
, BSTR
*p
)
1988 DOMEvent
*This
= impl_from_IDOMKeyboardEvent(iface
);
1989 FIXME("(%p)->(%p)\n", This
, p
);
1993 static const IDOMKeyboardEventVtbl DOMKeyboardEventVtbl
= {
1994 DOMKeyboardEvent_QueryInterface
,
1995 DOMKeyboardEvent_AddRef
,
1996 DOMKeyboardEvent_Release
,
1997 DOMKeyboardEvent_GetTypeInfoCount
,
1998 DOMKeyboardEvent_GetTypeInfo
,
1999 DOMKeyboardEvent_GetIDsOfNames
,
2000 DOMKeyboardEvent_Invoke
,
2001 DOMKeyboardEvent_get_key
,
2002 DOMKeyboardEvent_get_location
,
2003 DOMKeyboardEvent_get_ctrlKey
,
2004 DOMKeyboardEvent_get_shiftKey
,
2005 DOMKeyboardEvent_get_altKey
,
2006 DOMKeyboardEvent_get_metaKey
,
2007 DOMKeyboardEvent_get_repeat
,
2008 DOMKeyboardEvent_getModifierState
,
2009 DOMKeyboardEvent_initKeyboardEvent
,
2010 DOMKeyboardEvent_get_keyCode
,
2011 DOMKeyboardEvent_get_charCode
,
2012 DOMKeyboardEvent_get_which
,
2013 DOMKeyboardEvent_get_char
,
2014 DOMKeyboardEvent_get_locale
2019 IDOMCustomEvent IDOMCustomEvent_iface
;
2023 static inline DOMCustomEvent
*impl_from_IDOMCustomEvent(IDOMCustomEvent
*iface
)
2025 return CONTAINING_RECORD(iface
, DOMCustomEvent
, IDOMCustomEvent_iface
);
2028 static HRESULT WINAPI
DOMCustomEvent_QueryInterface(IDOMCustomEvent
*iface
, REFIID riid
, void **ppv
)
2030 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2031 return IDOMEvent_QueryInterface(&This
->event
.IDOMEvent_iface
, riid
, ppv
);
2034 static ULONG WINAPI
DOMCustomEvent_AddRef(IDOMCustomEvent
*iface
)
2036 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2037 return IDOMEvent_AddRef(&This
->event
.IDOMEvent_iface
);
2040 static ULONG WINAPI
DOMCustomEvent_Release(IDOMCustomEvent
*iface
)
2042 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2043 return IDOMEvent_Release(&This
->event
.IDOMEvent_iface
);
2046 static HRESULT WINAPI
DOMCustomEvent_GetTypeInfoCount(IDOMCustomEvent
*iface
, UINT
*pctinfo
)
2048 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2049 return IDispatchEx_GetTypeInfoCount(&This
->event
.dispex
.IDispatchEx_iface
, pctinfo
);
2052 static HRESULT WINAPI
DOMCustomEvent_GetTypeInfo(IDOMCustomEvent
*iface
, UINT iTInfo
,
2053 LCID lcid
, ITypeInfo
**ppTInfo
)
2055 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2056 return IDispatchEx_GetTypeInfo(&This
->event
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
2059 static HRESULT WINAPI
DOMCustomEvent_GetIDsOfNames(IDOMCustomEvent
*iface
, REFIID riid
,
2060 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
2062 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2063 return IDispatchEx_GetIDsOfNames(&This
->event
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
2067 static HRESULT WINAPI
DOMCustomEvent_Invoke(IDOMCustomEvent
*iface
, DISPID dispIdMember
,
2068 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
2069 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
2071 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2072 return IDispatchEx_Invoke(&This
->event
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
2073 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2076 static HRESULT WINAPI
DOMCustomEvent_get_detail(IDOMCustomEvent
*iface
, VARIANT
*p
)
2078 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2080 TRACE("(%p)->(%p)\n", This
, p
);
2083 return VariantCopy(p
, &This
->detail
);
2086 static HRESULT WINAPI
DOMCustomEvent_initCustomEvent(IDOMCustomEvent
*iface
, BSTR type
, VARIANT_BOOL can_bubble
,
2087 VARIANT_BOOL cancelable
, VARIANT
*detail
)
2089 DOMCustomEvent
*This
= impl_from_IDOMCustomEvent(iface
);
2092 TRACE("(%p)->(%s %x %x %s)\n", This
, debugstr_w(type
), can_bubble
, cancelable
, debugstr_variant(detail
));
2094 hres
= IDOMEvent_initEvent(&This
->event
.IDOMEvent_iface
, type
, can_bubble
, cancelable
);
2098 return VariantCopy(&This
->detail
, detail
);
2101 static const IDOMCustomEventVtbl DOMCustomEventVtbl
= {
2102 DOMCustomEvent_QueryInterface
,
2103 DOMCustomEvent_AddRef
,
2104 DOMCustomEvent_Release
,
2105 DOMCustomEvent_GetTypeInfoCount
,
2106 DOMCustomEvent_GetTypeInfo
,
2107 DOMCustomEvent_GetIDsOfNames
,
2108 DOMCustomEvent_Invoke
,
2109 DOMCustomEvent_get_detail
,
2110 DOMCustomEvent_initCustomEvent
2113 static DOMCustomEvent
*DOMCustomEvent_from_DOMEvent(DOMEvent
*event
)
2115 return CONTAINING_RECORD(event
, DOMCustomEvent
, event
);
2118 static void *DOMCustomEvent_query_interface(DOMEvent
*event
, REFIID riid
)
2120 DOMCustomEvent
*custom_event
= DOMCustomEvent_from_DOMEvent(event
);
2121 if(IsEqualGUID(&IID_IDOMCustomEvent
, riid
))
2122 return &custom_event
->IDOMCustomEvent_iface
;
2126 static void DOMCustomEvent_destroy(DOMEvent
*event
)
2128 DOMCustomEvent
*custom_event
= DOMCustomEvent_from_DOMEvent(event
);
2129 VariantClear(&custom_event
->detail
);
2133 static const tid_t DOMEvent_iface_tids
[] = {
2138 static dispex_static_data_t DOMEvent_dispex
= {
2144 static const tid_t DOMUIEvent_iface_tids
[] = {
2150 static dispex_static_data_t DOMUIEvent_dispex
= {
2153 DOMUIEvent_iface_tids
2156 static const tid_t DOMMouseEvent_iface_tids
[] = {
2163 static dispex_static_data_t DOMMouseEvent_dispex
= {
2165 DispDOMMouseEvent_tid
,
2166 DOMMouseEvent_iface_tids
2169 static const tid_t DOMKeyboardEvent_iface_tids
[] = {
2172 IDOMKeyboardEvent_tid
,
2176 static dispex_static_data_t DOMKeyboardEvent_dispex
= {
2178 DispDOMKeyboardEvent_tid
,
2179 DOMKeyboardEvent_iface_tids
2182 static const tid_t DOMCustomEvent_iface_tids
[] = {
2184 IDOMCustomEvent_tid
,
2188 static dispex_static_data_t DOMCustomEvent_dispex
= {
2190 DispDOMCustomEvent_tid
,
2191 DOMCustomEvent_iface_tids
2194 static BOOL
check_event_iface(nsIDOMEvent
*event
, REFIID riid
)
2199 nsres
= nsIDOMEvent_QueryInterface(event
, riid
, (void**)&iface
);
2200 if(NS_FAILED(nsres
))
2203 nsISupports_Release(iface
);
2207 static DOMEvent
*alloc_event(nsIDOMEvent
*nsevent
, compat_mode_t compat_mode
, eventid_t event_id
)
2209 dispex_static_data_t
*dispex_data
= &DOMEvent_dispex
;
2210 DOMEvent
*event
= NULL
;
2213 if(check_event_iface(nsevent
, &IID_nsIDOMCustomEvent
)) {
2214 DOMCustomEvent
*custom_event
= heap_alloc_zero(sizeof(*custom_event
));
2218 custom_event
->IDOMCustomEvent_iface
.lpVtbl
= &DOMCustomEventVtbl
;
2219 custom_event
->event
.query_interface
= DOMCustomEvent_query_interface
;
2220 custom_event
->event
.destroy
= DOMCustomEvent_destroy
;
2221 event
= &custom_event
->event
;
2222 dispex_data
= &DOMCustomEvent_dispex
;
2224 event
= heap_alloc_zero(sizeof(*event
));
2229 event
->IDOMEvent_iface
.lpVtbl
= &DOMEventVtbl
;
2230 event
->IDOMUIEvent_iface
.lpVtbl
= &DOMUIEventVtbl
;
2231 event
->IDOMMouseEvent_iface
.lpVtbl
= &DOMMouseEventVtbl
;
2232 event
->IDOMKeyboardEvent_iface
.lpVtbl
= &DOMKeyboardEventVtbl
;
2234 event
->event_id
= event_id
;
2235 if(event_id
!= EVENTID_LAST
) {
2236 event
->type
= heap_strdupW(event_info
[event_id
].name
);
2241 event
->bubbles
= (event_info
[event_id
].flags
& EVENT_BUBBLES
) != 0;
2242 event
->cancelable
= (event_info
[event_id
].flags
& EVENT_CANCELABLE
) != 0;
2244 nsIDOMEvent_AddRef(event
->nsevent
= nsevent
);
2246 event
->time_stamp
= get_time_stamp();
2248 nsres
= nsIDOMEvent_QueryInterface(nsevent
, &IID_nsIDOMUIEvent
, (void**)&event
->ui_event
);
2249 if(NS_SUCCEEDED(nsres
))
2250 dispex_data
= &DOMUIEvent_dispex
;
2252 event
->ui_event
= NULL
;
2254 nsres
= nsIDOMEvent_QueryInterface(nsevent
, &IID_nsIDOMMouseEvent
, (void**)&event
->mouse_event
);
2255 if(NS_SUCCEEDED(nsres
))
2256 dispex_data
= &DOMMouseEvent_dispex
;
2258 event
->mouse_event
= NULL
;
2260 nsres
= nsIDOMEvent_QueryInterface(nsevent
, &IID_nsIDOMKeyEvent
, (void**)&event
->keyboard_event
);
2261 if(NS_SUCCEEDED(nsres
))
2262 dispex_data
= &DOMKeyboardEvent_dispex
;
2264 event
->keyboard_event
= NULL
;
2266 init_dispatch(&event
->dispex
, (IUnknown
*)&event
->IDOMEvent_iface
, dispex_data
, compat_mode
);
2270 HRESULT
create_event_from_nsevent(nsIDOMEvent
*nsevent
, compat_mode_t compat_mode
, DOMEvent
**ret_event
)
2272 eventid_t event_id
= EVENTID_LAST
;
2277 nsAString_Init(&nsstr
, NULL
);
2278 nsres
= nsIDOMEvent_GetType(nsevent
, &nsstr
);
2279 if(NS_SUCCEEDED(nsres
)) {
2281 nsAString_GetData(&nsstr
, &type
);
2282 event_id
= str_to_eid(type
);
2283 if(event_id
== EVENTID_LAST
)
2284 FIXME("unknown event type %s\n", debugstr_w(type
));
2286 ERR("GetType failed: %08x\n", nsres
);
2288 nsAString_Finish(&nsstr
);
2290 event
= alloc_event(nsevent
, compat_mode
, event_id
);
2292 return E_OUTOFMEMORY
;
2294 event
->trusted
= TRUE
;
2299 HRESULT
create_document_event_str(HTMLDocumentNode
*doc
, const WCHAR
*type
, IDOMEvent
**ret_event
)
2301 nsIDOMEvent
*nsevent
;
2306 nsAString_InitDepend(&nsstr
, type
);
2307 nsres
= nsIDOMHTMLDocument_CreateEvent(doc
->nsdoc
, &nsstr
, &nsevent
);
2308 nsAString_Finish(&nsstr
);
2309 if(NS_FAILED(nsres
)) {
2310 FIXME("CreateEvent(%s) failed: %08x\n", debugstr_w(type
), nsres
);
2314 event
= alloc_event(nsevent
, dispex_compat_mode(&doc
->node
.event_target
.dispex
), EVENTID_LAST
);
2315 nsIDOMEvent_Release(nsevent
);
2317 return E_OUTOFMEMORY
;
2319 *ret_event
= &event
->IDOMEvent_iface
;
2323 HRESULT
create_document_event(HTMLDocumentNode
*doc
, eventid_t event_id
, DOMEvent
**ret_event
)
2325 nsIDOMEvent
*nsevent
;
2330 nsAString_InitDepend(&nsstr
, event_types
[event_info
[event_id
].type
]);
2331 nsres
= nsIDOMHTMLDocument_CreateEvent(doc
->nsdoc
, &nsstr
, &nsevent
);
2332 nsAString_Finish(&nsstr
);
2333 if(NS_FAILED(nsres
)) {
2334 FIXME("CreateEvent(%s) failed: %08x\n", debugstr_w(event_types
[event_info
[event_id
].type
]), nsres
);
2338 event
= alloc_event(nsevent
, dispex_compat_mode(&doc
->node
.event_target
.dispex
), event_id
);
2340 return E_OUTOFMEMORY
;
2342 event
->event_id
= event_id
;
2343 event
->trusted
= TRUE
;
2348 static HRESULT
call_disp_func(IDispatch
*disp
, DISPPARAMS
*dp
, VARIANT
*retv
)
2350 IDispatchEx
*dispex
;
2354 memset(&ei
, 0, sizeof(ei
));
2356 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
2357 if(SUCCEEDED(hres
)) {
2358 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, dp
, retv
, &ei
, NULL
);
2359 IDispatchEx_Release(dispex
);
2361 TRACE("Could not get IDispatchEx interface: %08x\n", hres
);
2362 hres
= IDispatch_Invoke(disp
, 0, &IID_NULL
, GetUserDefaultLCID(), DISPATCH_METHOD
,
2363 dp
, retv
, &ei
, NULL
);
2369 static HRESULT
call_cp_func(IDispatch
*disp
, DISPID dispid
, IHTMLEventObj
*event_obj
, VARIANT
*retv
)
2371 DISPPARAMS dp
= {NULL
,NULL
,0,0};
2376 TRACE("%p,%d,%p,%p\n", disp
, dispid
, event_obj
, retv
);
2379 V_VT(&event_arg
) = VT_DISPATCH
;
2380 V_DISPATCH(&event_arg
) = (IDispatch
*)event_obj
;
2381 dp
.rgvarg
= &event_arg
;
2385 memset(&ei
, 0, sizeof(ei
));
2386 return IDispatch_Invoke(disp
, dispid
, &IID_NULL
, 0, DISPATCH_METHOD
, &dp
, retv
, &ei
, &argerr
);
2389 static BOOL
use_event_quirks(EventTarget
*event_target
)
2391 return dispex_compat_mode(&event_target
->dispex
) < COMPAT_MODE_IE9
;
2394 static BOOL
is_cp_event(cp_static_data_t
*data
, DISPID dispid
)
2399 if(!data
|| dispid
== DISPID_UNKNOWN
)
2403 hres
= get_dispids(data
->tid
, &data
->id_cnt
, &data
->ids
);
2409 max
= data
->id_cnt
-1;
2412 if(data
->ids
[i
] == dispid
)
2415 if(data
->ids
[i
] < dispid
)
2424 static void call_event_handlers(EventTarget
*event_target
, DOMEvent
*event
, dispatch_mode_t dispatch_mode
)
2426 const listener_container_t
*container
= get_listener_container(event_target
, event
->type
, FALSE
);
2427 event_listener_t
*listener
, listeners_buf
[8], *listeners
= listeners_buf
;
2428 unsigned listeners_cnt
, listeners_size
;
2429 ConnectionPointContainer
*cp_container
= NULL
;
2430 const event_target_vtbl_t
*vtbl
= NULL
;
2431 BOOL skip_onevent_listener
= FALSE
;
2435 assert(!event
->current_target
);
2436 event
->current_target
= event_target
;
2438 if(container
&& !list_empty(&container
->listeners
) && event
->phase
!= DEP_CAPTURING_PHASE
) {
2439 listener
= LIST_ENTRY(list_tail(&container
->listeners
), event_listener_t
, entry
);
2440 if(listener
&& listener
->function
&& listener
->type
== LISTENER_TYPE_ONEVENT
2441 && use_event_quirks(event_target
)) {
2442 DISPID named_arg
= DISPID_THIS
;
2444 DISPPARAMS dp
= {&arg
, &named_arg
, 1, 1};
2446 skip_onevent_listener
= TRUE
;
2448 V_VT(&arg
) = VT_DISPATCH
;
2449 V_DISPATCH(&arg
) = (IDispatch
*)&event_target
->dispex
.IDispatchEx_iface
;
2450 V_VT(&v
) = VT_EMPTY
;
2452 TRACE("%p %s >>>\n", event_target
, debugstr_w(event
->type
));
2453 hres
= call_disp_func(listener
->function
, &dp
, &v
);
2455 TRACE("%p %s <<< %s\n", event_target
, debugstr_w(event
->type
), debugstr_variant(&v
));
2457 if(event
->cancelable
) {
2458 if(V_VT(&v
) == VT_BOOL
) {
2460 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2461 }else if(V_VT(&v
) != VT_EMPTY
) {
2462 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2467 WARN("%p %s <<< %08x\n", event_target
, debugstr_w(event
->type
), hres
);
2473 listeners_size
= ARRAY_SIZE(listeners_buf
);
2476 LIST_FOR_EACH_ENTRY(listener
, &container
->listeners
, event_listener_t
, entry
) {
2477 if(!listener
->function
)
2479 switch(listener
->type
) {
2480 case LISTENER_TYPE_ONEVENT
:
2481 if(skip_onevent_listener
|| event
->phase
== DEP_CAPTURING_PHASE
)
2484 case LISTENER_TYPE_CAPTURE
:
2485 if(event
->phase
== DEP_BUBBLING_PHASE
|| dispatch_mode
== DISPATCH_LEGACY
)
2488 case LISTENER_TYPE_BUBBLE
:
2489 if(event
->phase
== DEP_CAPTURING_PHASE
|| dispatch_mode
== DISPATCH_LEGACY
)
2492 case LISTENER_TYPE_ATTACHED
:
2493 if(event
->phase
== DEP_CAPTURING_PHASE
|| dispatch_mode
== DISPATCH_STANDARD
)
2498 if(listeners_cnt
== listeners_size
) {
2499 event_listener_t
*new_listeners
;
2500 if(listeners
== listeners_buf
) {
2501 new_listeners
= heap_alloc(listeners_size
* 2 * sizeof(*new_listeners
));
2504 memcpy(new_listeners
, listeners
, listeners_cnt
* sizeof(*listeners
));
2506 new_listeners
= heap_realloc(listeners
, listeners_size
* 2 * sizeof(*new_listeners
));
2508 listeners
= new_listeners
;
2509 listeners_size
*= 2;
2512 listeners
[listeners_cnt
].type
= listener
->type
;
2513 IDispatch_AddRef(listeners
[listeners_cnt
].function
= listener
->function
);
2518 for(listener
= listeners
; !event
->stop_immediate_propagation
2519 && listener
< listeners
+ listeners_cnt
; listener
++) {
2520 if(listener
->type
!= LISTENER_TYPE_ATTACHED
) {
2521 DISPID named_arg
= DISPID_THIS
;
2523 DISPPARAMS dp
= {args
, &named_arg
, 2, 1};
2525 V_VT(args
) = VT_DISPATCH
;
2526 V_DISPATCH(args
) = (IDispatch
*)&event_target
->dispex
.IDispatchEx_iface
;
2527 V_VT(args
+1) = VT_DISPATCH
;
2528 V_DISPATCH(args
+1) = dispatch_mode
== DISPATCH_LEGACY
2529 ? (IDispatch
*)event
->event_obj
: (IDispatch
*)&event
->IDOMEvent_iface
;
2530 V_VT(&v
) = VT_EMPTY
;
2532 TRACE("%p %s >>>\n", event_target
, debugstr_w(event
->type
));
2533 hres
= call_disp_func(listener
->function
, &dp
, &v
);
2535 TRACE("%p %s <<< %s\n", event_target
, debugstr_w(event
->type
),
2536 debugstr_variant(&v
));
2538 if(event
->cancelable
) {
2539 if(V_VT(&v
) == VT_BOOL
) {
2541 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2542 }else if(V_VT(&v
) != VT_EMPTY
) {
2543 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2548 WARN("%p %s <<< %08x\n", event_target
, debugstr_w(event
->type
), hres
);
2552 DISPPARAMS dp
= {&arg
, NULL
, 1, 0};
2554 V_VT(&arg
) = VT_DISPATCH
;
2555 V_DISPATCH(&arg
) = (IDispatch
*)event
->event_obj
;
2556 V_VT(&v
) = VT_EMPTY
;
2558 TRACE("%p %s attached >>>\n", event_target
, debugstr_w(event
->type
));
2559 hres
= call_disp_func(listener
->function
, &dp
, &v
);
2561 TRACE("%p %s attached <<<\n", event_target
, debugstr_w(event
->type
));
2563 if(event
->cancelable
) {
2564 if(V_VT(&v
) == VT_BOOL
) {
2566 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2567 }else if(V_VT(&v
) != VT_EMPTY
) {
2568 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2573 WARN("%p %s attached <<< %08x\n", event_target
, debugstr_w(event
->type
), hres
);
2578 for(listener
= listeners
; listener
< listeners
+ listeners_cnt
; listener
++)
2579 IDispatch_Release(listener
->function
);
2580 if(listeners
!= listeners_buf
)
2581 heap_free(listeners
);
2583 if(event
->phase
!= DEP_CAPTURING_PHASE
&& event
->event_id
!= EVENTID_LAST
2584 && event_info
[event
->event_id
].dispid
&& (vtbl
= dispex_get_vtbl(&event_target
->dispex
))
2585 && vtbl
->get_cp_container
)
2586 cp_container
= vtbl
->get_cp_container(&event_target
->dispex
);
2588 if(cp_container
->cps
) {
2589 ConnectionPoint
*cp
;
2592 for(j
=0; cp_container
->cp_entries
[j
].riid
; j
++) {
2593 cp
= cp_container
->cps
+ j
;
2594 if(!cp
->sinks_size
|| !is_cp_event(cp
->data
, event_info
[event
->event_id
].dispid
))
2597 for(i
=0; i
< cp
->sinks_size
; i
++) {
2598 if(!cp
->sinks
[i
].disp
)
2601 V_VT(&v
) = VT_EMPTY
;
2603 TRACE("%p cp %s [%u] >>>\n", event_target
, debugstr_w(event
->type
), i
);
2604 hres
= call_cp_func(cp
->sinks
[i
].disp
, event_info
[event
->event_id
].dispid
,
2605 cp
->data
->pass_event_arg
? event
->event_obj
: NULL
, &v
);
2607 TRACE("%p cp %s [%u] <<<\n", event_target
, debugstr_w(event
->type
), i
);
2609 if(event
->cancelable
) {
2610 if(V_VT(&v
) == VT_BOOL
) {
2612 IDOMEvent_preventDefault(&event
->IDOMEvent_iface
);
2613 }else if(V_VT(&v
) != VT_EMPTY
) {
2614 FIXME("unhandled result %s\n", debugstr_variant(&v
));
2619 WARN("%p cp %s [%u] <<< %08x\n", event_target
, debugstr_w(event
->type
), i
, hres
);
2624 IConnectionPointContainer_Release(&cp_container
->IConnectionPointContainer_iface
);
2627 event
->current_target
= NULL
;
2630 static HRESULT
dispatch_event_object(EventTarget
*event_target
, DOMEvent
*event
,
2631 dispatch_mode_t dispatch_mode
, VARIANT_BOOL
*r
)
2633 EventTarget
*target_chain_buf
[8], **target_chain
= target_chain_buf
;
2634 unsigned chain_cnt
, chain_buf_size
, i
;
2635 const event_target_vtbl_t
*vtbl
, *target_vtbl
;
2636 HTMLEventObj
*event_obj_ref
= NULL
;
2637 IHTMLEventObj
*prev_event
= NULL
;
2641 TRACE("(%p) %s\n", event_target
, debugstr_w(event
->type
));
2644 FIXME("Uninitialized event.\n");
2648 if(event
->current_target
) {
2649 FIXME("event is being dispatched.\n");
2653 iter
= event_target
;
2654 IEventTarget_AddRef(&event_target
->IEventTarget_iface
);
2657 chain_buf_size
= ARRAY_SIZE(target_chain_buf
);
2660 if(chain_cnt
== chain_buf_size
) {
2661 EventTarget
**new_chain
;
2662 if(target_chain
== target_chain_buf
) {
2663 new_chain
= heap_alloc(chain_buf_size
* 2 * sizeof(*new_chain
));
2666 memcpy(new_chain
, target_chain
, chain_buf_size
* sizeof(*new_chain
));
2668 new_chain
= heap_realloc(target_chain
, chain_buf_size
* 2 * sizeof(*new_chain
));
2672 chain_buf_size
*= 2;
2673 target_chain
= new_chain
;
2676 target_chain
[chain_cnt
++] = iter
;
2678 if(!(vtbl
= dispex_get_vtbl(&iter
->dispex
)) || !vtbl
->get_parent_event_target
)
2680 iter
= vtbl
->get_parent_event_target(&iter
->dispex
);
2683 if(!event
->event_obj
&& !event
->no_event_obj
) {
2684 event_obj_ref
= alloc_event_obj(event
, dispex_compat_mode(&event
->dispex
));
2686 event
->event_obj
= &event_obj_ref
->IHTMLEventObj_iface
;
2689 target_vtbl
= dispex_get_vtbl(&event_target
->dispex
);
2690 if(target_vtbl
&& target_vtbl
->set_current_event
)
2691 prev_event
= target_vtbl
->set_current_event(&event_target
->dispex
, event
->event_obj
);
2694 IEventTarget_Release(&event
->target
->IEventTarget_iface
);
2695 event
->target
= event_target
;
2696 IEventTarget_AddRef(&event_target
->IEventTarget_iface
);
2698 event
->phase
= DEP_CAPTURING_PHASE
;
2700 while(!event
->stop_propagation
&& i
)
2701 call_event_handlers(target_chain
[i
--], event
, dispatch_mode
);
2703 if(!event
->stop_propagation
) {
2704 event
->phase
= DEP_AT_TARGET
;
2705 call_event_handlers(target_chain
[0], event
, dispatch_mode
);
2708 if(event
->bubbles
) {
2709 event
->phase
= DEP_BUBBLING_PHASE
;
2710 for(i
= 1; !event
->stop_propagation
&& i
< chain_cnt
; i
++)
2711 call_event_handlers(target_chain
[i
], event
, dispatch_mode
);
2715 *r
= variant_bool(!event
->prevent_default
);
2717 if(target_vtbl
&& target_vtbl
->set_current_event
) {
2718 prev_event
= target_vtbl
->set_current_event(&event_target
->dispex
, prev_event
);
2720 IHTMLEventObj_Release(prev_event
);
2723 if(event
->event_id
!= EVENTID_LAST
&& (event_info
[event
->event_id
].flags
& EVENT_HASDEFAULTHANDLERS
)) {
2724 BOOL prevent_default
= event
->prevent_default
;
2725 for(i
= 0; !prevent_default
&& i
< chain_cnt
; i
++) {
2726 vtbl
= dispex_get_vtbl(&target_chain
[i
]->dispex
);
2727 if(!vtbl
|| !vtbl
->handle_event_default
)
2729 hres
= vtbl
->handle_event_default(&event_target
->dispex
, event
->event_id
,
2730 event
->nsevent
, &prevent_default
);
2731 if(FAILED(hres
) || event
->stop_propagation
)
2734 nsIDOMEvent_PreventDefault(event
->nsevent
);
2738 event
->prevent_default
= FALSE
;
2740 event
->event_obj
= NULL
;
2741 IHTMLEventObj_Release(&event_obj_ref
->IHTMLEventObj_iface
);
2744 for(i
= 0; i
< chain_cnt
; i
++)
2745 IEventTarget_Release(&target_chain
[i
]->IEventTarget_iface
);
2746 if(target_chain
!= target_chain_buf
)
2747 heap_free(target_chain
);
2752 void dispatch_event(EventTarget
*event_target
, DOMEvent
*event
)
2754 dispatch_event_object(event_target
, event
, DISPATCH_BOTH
, NULL
);
2757 * We may have registered multiple Gecko listeners for the same event type,
2758 * but we already dispatched event to all relevant targets. Stop event
2759 * propagation here to avoid events being dispatched multiple times.
2761 if(event
->event_id
!= EVENTID_LAST
&& (event_info
[event
->event_id
].flags
& EVENT_BIND_TO_TARGET
))
2762 nsIDOMEvent_StopPropagation(event
->nsevent
);
2765 HRESULT
fire_event(HTMLDOMNode
*node
, const WCHAR
*event_name
, VARIANT
*event_var
, VARIANT_BOOL
*cancelled
)
2767 HTMLEventObj
*event_obj
= NULL
;
2769 HRESULT hres
= S_OK
;
2771 eid
= attr_to_eid(event_name
);
2772 if(eid
== EVENTID_LAST
) {
2773 WARN("unknown event %s\n", debugstr_w(event_name
));
2774 return E_INVALIDARG
;
2777 if(event_var
&& V_VT(event_var
) != VT_EMPTY
&& V_VT(event_var
) != VT_ERROR
) {
2778 if(V_VT(event_var
) != VT_DISPATCH
) {
2779 FIXME("event_var %s not supported\n", debugstr_variant(event_var
));
2783 if(V_DISPATCH(event_var
)) {
2784 IHTMLEventObj
*event_iface
;
2786 hres
= IDispatch_QueryInterface(V_DISPATCH(event_var
), &IID_IHTMLEventObj
, (void**)&event_iface
);
2788 FIXME("No IHTMLEventObj iface\n");
2792 event_obj
= unsafe_impl_from_IHTMLEventObj(event_iface
);
2794 ERR("Not our IHTMLEventObj?\n");
2795 IHTMLEventObj_Release(event_iface
);
2802 event_obj
= alloc_event_obj(NULL
, dispex_compat_mode(&node
->event_target
.dispex
));
2804 return E_OUTOFMEMORY
;
2807 if(!event_obj
->event
)
2808 hres
= create_document_event(node
->doc
, eid
, &event_obj
->event
);
2810 if(SUCCEEDED(hres
)) {
2811 event_obj
->event
->event_obj
= &event_obj
->IHTMLEventObj_iface
;
2812 dispatch_event_object(&node
->event_target
, event_obj
->event
, DISPATCH_LEGACY
, NULL
);
2813 event_obj
->event
->event_obj
= NULL
;
2816 IHTMLEventObj_Release(&event_obj
->IHTMLEventObj_iface
);
2820 *cancelled
= VARIANT_TRUE
; /* FIXME */
2824 HRESULT
ensure_doc_nsevent_handler(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, eventid_t eid
)
2826 TRACE("%s\n", debugstr_w(event_info
[eid
].name
));
2832 case EVENTID_FOCUSIN
:
2833 doc
->event_vector
[eid
] = TRUE
;
2834 eid
= EVENTID_FOCUS
;
2836 case EVENTID_FOCUSOUT
:
2837 doc
->event_vector
[eid
] = TRUE
;
2846 if(event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
) {
2848 }else if(event_info
[eid
].flags
& EVENT_BIND_TO_TARGET
) {
2850 nsnode
= doc
->node
.nsnode
;
2855 if(!nsnode
|| nsnode
== doc
->node
.nsnode
) {
2856 if(doc
->event_vector
[eid
])
2858 doc
->event_vector
[eid
] = TRUE
;
2861 add_nsevent_listener(doc
, nsnode
, event_info
[eid
].name
);
2865 void detach_events(HTMLDocumentNode
*doc
)
2867 if(doc
->event_vector
) {
2870 for(i
=0; i
< EVENTID_LAST
; i
++) {
2871 if(doc
->event_vector
[i
]) {
2872 detach_nsevent(doc
, event_info
[i
].name
);
2873 doc
->event_vector
[i
] = FALSE
;
2878 release_nsevents(doc
);
2881 static HRESULT
get_event_dispex_ref(EventTarget
*event_target
, eventid_t eid
, BOOL alloc
, VARIANT
**ret
)
2886 lstrcpyW(buf
+2, event_info
[eid
].name
);
2887 return dispex_get_dprop_ref(&event_target
->dispex
, buf
, alloc
, ret
);
2890 static event_listener_t
*get_onevent_listener(EventTarget
*event_target
, eventid_t eid
, BOOL alloc
)
2892 listener_container_t
*container
;
2893 event_listener_t
*listener
;
2895 container
= get_listener_container(event_target
, event_info
[eid
].name
, alloc
);
2899 LIST_FOR_EACH_ENTRY_REV(listener
, &container
->listeners
, event_listener_t
, entry
) {
2900 if(listener
->type
== LISTENER_TYPE_ONEVENT
)
2907 listener
= heap_alloc(sizeof(*listener
));
2911 listener
->type
= LISTENER_TYPE_ONEVENT
;
2912 listener
->function
= NULL
;
2913 list_add_tail(&container
->listeners
, &listener
->entry
);
2917 static void remove_event_handler(EventTarget
*event_target
, eventid_t eid
)
2919 event_listener_t
*listener
;
2923 hres
= get_event_dispex_ref(event_target
, eid
, FALSE
, &store
);
2925 VariantClear(store
);
2927 listener
= get_onevent_listener(event_target
, eid
, FALSE
);
2928 if(listener
&& listener
->function
) {
2929 IDispatch_Release(listener
->function
);
2930 listener
->function
= NULL
;
2934 static HRESULT
set_event_handler_disp(EventTarget
*event_target
, eventid_t eid
, IDispatch
*disp
)
2936 event_listener_t
*listener
;
2938 if(event_info
[eid
].flags
& EVENT_FIXME
)
2939 FIXME("unimplemented event %s\n", debugstr_w(event_info
[eid
].name
));
2941 remove_event_handler(event_target
, eid
);
2945 listener
= get_onevent_listener(event_target
, eid
, TRUE
);
2947 return E_OUTOFMEMORY
;
2949 if(listener
->function
)
2950 IDispatch_Release(listener
->function
);
2952 IDispatch_AddRef(listener
->function
= disp
);
2956 HRESULT
set_event_handler(EventTarget
*event_target
, eventid_t eid
, VARIANT
*var
)
2960 if(use_event_quirks(event_target
)) {
2961 WARN("attempt to set to VT_EMPTY in quirks mode\n");
2966 remove_event_handler(event_target
, eid
);
2970 return set_event_handler_disp(event_target
, eid
, V_DISPATCH(var
));
2976 if(!use_event_quirks(event_target
))
2977 FIXME("Setting to string %s not supported\n", debugstr_w(V_BSTR(var
)));
2980 * Setting event handler to string is a rare case and we don't want to
2981 * complicate nor increase memory of listener_container_t for that. Instead,
2982 * we store the value in DispatchEx, which can already handle custom
2985 remove_event_handler(event_target
, eid
);
2987 hres
= get_event_dispex_ref(event_target
, eid
, TRUE
, &v
);
2991 V_BSTR(v
) = SysAllocString(V_BSTR(var
));
2993 return E_OUTOFMEMORY
;
2999 FIXME("not handler %s\n", debugstr_variant(var
));
3006 HRESULT
get_event_handler(EventTarget
*event_target
, eventid_t eid
, VARIANT
*var
)
3008 event_listener_t
*listener
;
3012 hres
= get_event_dispex_ref(event_target
, eid
, FALSE
, &v
);
3013 if(SUCCEEDED(hres
) && V_VT(v
) != VT_EMPTY
) {
3014 V_VT(var
) = VT_EMPTY
;
3015 return VariantCopy(var
, v
);
3018 listener
= get_onevent_listener(event_target
, eid
, FALSE
);
3019 if(listener
&& listener
->function
) {
3020 V_VT(var
) = VT_DISPATCH
;
3021 V_DISPATCH(var
) = listener
->function
;
3022 IDispatch_AddRef(V_DISPATCH(var
));
3024 V_VT(var
) = VT_NULL
;
3030 HRESULT
attach_event(EventTarget
*event_target
, BSTR name
, IDispatch
*disp
, VARIANT_BOOL
*res
)
3032 listener_container_t
*container
;
3033 event_listener_t
*listener
;
3036 eid
= attr_to_eid(name
);
3037 if(eid
== EVENTID_LAST
) {
3038 WARN("Unknown event\n");
3039 *res
= VARIANT_TRUE
;
3043 container
= get_listener_container(event_target
, event_info
[eid
].name
, TRUE
);
3045 return E_OUTOFMEMORY
;
3047 listener
= heap_alloc(sizeof(*listener
));
3049 return E_OUTOFMEMORY
;
3051 listener
->type
= LISTENER_TYPE_ATTACHED
;
3052 IDispatch_AddRef(listener
->function
= disp
);
3053 if(use_event_quirks(event_target
))
3054 list_add_head(&container
->listeners
, &listener
->entry
);
3056 list_add_tail(&container
->listeners
, &listener
->entry
);
3058 *res
= VARIANT_TRUE
;
3062 HRESULT
detach_event(EventTarget
*event_target
, BSTR name
, IDispatch
*disp
)
3066 eid
= attr_to_eid(name
);
3067 if(eid
== EVENTID_LAST
) {
3068 WARN("Unknown event\n");
3072 remove_event_listener(event_target
, event_info
[eid
].name
, LISTENER_TYPE_ATTACHED
, disp
);
3076 void bind_target_event(HTMLDocumentNode
*doc
, EventTarget
*event_target
, const WCHAR
*event
, IDispatch
*disp
)
3080 TRACE("(%p %p %s %p)\n", doc
, event_target
, debugstr_w(event
), disp
);
3082 eid
= attr_to_eid(event
);
3083 if(eid
== EVENTID_LAST
) {
3084 WARN("Unsupported event %s\n", debugstr_w(event
));
3088 set_event_handler_disp(event_target
, eid
, disp
);
3091 void update_doc_cp_events(HTMLDocumentNode
*doc
, cp_static_data_t
*cp
)
3095 for(i
=0; i
< EVENTID_LAST
; i
++) {
3096 if((event_info
[i
].flags
& EVENT_DEFAULTLISTENER
) && is_cp_event(cp
, event_info
[i
].dispid
))
3097 ensure_doc_nsevent_handler(doc
, NULL
, i
);
3101 void check_event_attr(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
)
3103 nsIDOMMozNamedAttrMap
*attr_map
;
3104 const PRUnichar
*name
, *value
;
3105 nsAString name_str
, value_str
;
3106 HTMLDOMNode
*node
= NULL
;
3115 nsres
= nsIDOMElement_HasAttributes(nselem
, &has_attrs
);
3116 if(NS_FAILED(nsres
) || !has_attrs
)
3119 nsres
= nsIDOMElement_GetAttributes(nselem
, &attr_map
);
3120 if(NS_FAILED(nsres
))
3123 nsres
= nsIDOMMozNamedAttrMap_GetLength(attr_map
, &length
);
3124 assert(nsres
== NS_OK
);
3126 nsAString_Init(&name_str
, NULL
);
3127 nsAString_Init(&value_str
, NULL
);
3129 for(i
= 0; i
< length
; i
++) {
3130 nsres
= nsIDOMMozNamedAttrMap_Item(attr_map
, i
, &attr
);
3131 if(NS_FAILED(nsres
))
3134 nsres
= nsIDOMAttr_GetName(attr
, &name_str
);
3135 if(NS_FAILED(nsres
)) {
3136 nsIDOMAttr_Release(attr
);
3140 nsAString_GetData(&name_str
, &name
);
3141 eid
= attr_to_eid(name
);
3142 if(eid
== EVENTID_LAST
) {
3143 nsIDOMAttr_Release(attr
);
3147 nsres
= nsIDOMAttr_GetValue(attr
, &value_str
);
3148 nsIDOMAttr_Release(attr
);
3149 if(NS_FAILED(nsres
))
3152 nsAString_GetData(&value_str
, &value
);
3156 TRACE("%p.%s = %s\n", nselem
, debugstr_w(name
), debugstr_w(value
));
3158 disp
= script_parse_event(doc
->window
, value
);
3163 hres
= get_node((nsIDOMNode
*)nselem
, TRUE
, &node
);
3165 IDispatch_Release(disp
);
3170 set_event_handler_disp(get_node_event_prop_target(node
, eid
), eid
, disp
);
3171 IDispatch_Release(disp
);
3176 nsAString_Finish(&name_str
);
3177 nsAString_Finish(&value_str
);
3178 nsIDOMMozNamedAttrMap_Release(attr_map
);
3181 HRESULT
doc_init_events(HTMLDocumentNode
*doc
)
3186 doc
->event_vector
= heap_alloc_zero(EVENTID_LAST
*sizeof(BOOL
));
3187 if(!doc
->event_vector
)
3188 return E_OUTOFMEMORY
;
3192 for(i
=0; i
< EVENTID_LAST
; i
++) {
3193 if(event_info
[i
].flags
& EVENT_HASDEFAULTHANDLERS
) {
3194 hres
= ensure_doc_nsevent_handler(doc
, NULL
, i
);
3203 static inline EventTarget
*impl_from_IEventTarget(IEventTarget
*iface
)
3205 return CONTAINING_RECORD(iface
, EventTarget
, IEventTarget_iface
);
3208 static HRESULT WINAPI
EventTarget_QueryInterface(IEventTarget
*iface
, REFIID riid
, void **ppv
)
3210 EventTarget
*This
= impl_from_IEventTarget(iface
);
3211 return IDispatchEx_QueryInterface(&This
->dispex
.IDispatchEx_iface
, riid
, ppv
);
3214 static ULONG WINAPI
EventTarget_AddRef(IEventTarget
*iface
)
3216 EventTarget
*This
= impl_from_IEventTarget(iface
);
3217 return IDispatchEx_AddRef(&This
->dispex
.IDispatchEx_iface
);
3220 static ULONG WINAPI
EventTarget_Release(IEventTarget
*iface
)
3222 EventTarget
*This
= impl_from_IEventTarget(iface
);
3223 return IDispatchEx_Release(&This
->dispex
.IDispatchEx_iface
);
3226 static HRESULT WINAPI
EventTarget_GetTypeInfoCount(IEventTarget
*iface
, UINT
*pctinfo
)
3228 EventTarget
*This
= impl_from_IEventTarget(iface
);
3229 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
3232 static HRESULT WINAPI
EventTarget_GetTypeInfo(IEventTarget
*iface
, UINT iTInfo
,
3233 LCID lcid
, ITypeInfo
**ppTInfo
)
3235 EventTarget
*This
= impl_from_IEventTarget(iface
);
3236 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
3239 static HRESULT WINAPI
EventTarget_GetIDsOfNames(IEventTarget
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
3240 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
3242 EventTarget
*This
= impl_from_IEventTarget(iface
);
3243 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
,
3244 rgszNames
, cNames
, lcid
, rgDispId
);
3247 static HRESULT WINAPI
EventTarget_Invoke(IEventTarget
*iface
, DISPID dispIdMember
,
3248 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
3249 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
3251 EventTarget
*This
= impl_from_IEventTarget(iface
);
3252 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
,
3253 riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
3256 static HRESULT WINAPI
EventTarget_addEventListener(IEventTarget
*iface
, BSTR type
,
3257 IDispatch
*function
, VARIANT_BOOL capture
)
3259 EventTarget
*This
= impl_from_IEventTarget(iface
);
3260 listener_type_t listener_type
= capture
? LISTENER_TYPE_CAPTURE
: LISTENER_TYPE_BUBBLE
;
3261 listener_container_t
*container
;
3262 event_listener_t
*listener
;
3264 TRACE("(%p)->(%s %p %x)\n", This
, debugstr_w(type
), function
, capture
);
3266 container
= get_listener_container(This
, type
, TRUE
);
3268 return E_OUTOFMEMORY
;
3270 /* check for duplicates */
3271 LIST_FOR_EACH_ENTRY(listener
, &container
->listeners
, event_listener_t
, entry
) {
3272 if(listener
->type
== listener_type
&& listener
->function
== function
)
3276 listener
= heap_alloc(sizeof(*listener
));
3278 return E_OUTOFMEMORY
;
3280 listener
->type
= listener_type
;
3281 IDispatch_AddRef(listener
->function
= function
);
3282 list_add_tail(&container
->listeners
, &listener
->entry
);
3286 static HRESULT WINAPI
EventTarget_removeEventListener(IEventTarget
*iface
, BSTR type
,
3287 IDispatch
*listener
, VARIANT_BOOL capture
)
3289 EventTarget
*This
= impl_from_IEventTarget(iface
);
3291 TRACE("(%p)->(%s %p %x)\n", This
, debugstr_w(type
), listener
, capture
);
3293 remove_event_listener(This
, type
, capture
? LISTENER_TYPE_CAPTURE
: LISTENER_TYPE_BUBBLE
, listener
);
3297 static HRESULT WINAPI
EventTarget_dispatchEvent(IEventTarget
*iface
, IDOMEvent
*event_iface
, VARIANT_BOOL
*result
)
3299 EventTarget
*This
= impl_from_IEventTarget(iface
);
3300 DOMEvent
*event
= unsafe_impl_from_IDOMEvent(event_iface
);
3302 TRACE("(%p)->(%p %p)\n", This
, event
, result
);
3305 WARN("Invalid event\n");
3306 return E_INVALIDARG
;
3309 return dispatch_event_object(This
, event
, DISPATCH_STANDARD
, result
);
3312 static HRESULT
IEventTarget_addEventListener_hook(DispatchEx
*dispex
, LCID lcid
, WORD flags
,
3313 DISPPARAMS
*dp
, VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
3315 /* If only two arguments were given, implicitly set capture to false */
3316 if((flags
& DISPATCH_METHOD
) && dp
->cArgs
== 2 && !dp
->cNamedArgs
) {
3318 DISPPARAMS new_dp
= {args
, NULL
, 3, 0};
3319 V_VT(args
) = VT_BOOL
;
3320 V_BOOL(args
) = VARIANT_FALSE
;
3321 args
[1] = dp
->rgvarg
[0];
3322 args
[2] = dp
->rgvarg
[1];
3324 TRACE("implicit capture\n");
3326 return IDispatchEx_InvokeEx(&dispex
->IDispatchEx_iface
, DISPID_IEVENTTARGET_ADDEVENTLISTENER
,
3327 lcid
, flags
, &new_dp
, res
, ei
, caller
);
3330 return S_FALSE
; /* fallback to default */
3333 static HRESULT
IEventTarget_removeEventListener_hook(DispatchEx
*dispex
, LCID lcid
, WORD flags
,
3334 DISPPARAMS
*dp
, VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
3336 /* If only two arguments were given, implicitly set capture to false */
3337 if((flags
& DISPATCH_METHOD
) && dp
->cArgs
== 2 && !dp
->cNamedArgs
) {
3339 DISPPARAMS new_dp
= {args
, NULL
, 3, 0};
3340 V_VT(args
) = VT_BOOL
;
3341 V_BOOL(args
) = VARIANT_FALSE
;
3342 args
[1] = dp
->rgvarg
[0];
3343 args
[2] = dp
->rgvarg
[1];
3345 TRACE("implicit capture\n");
3347 return IDispatchEx_InvokeEx(&dispex
->IDispatchEx_iface
, DISPID_IEVENTTARGET_REMOVEEVENTLISTENER
,
3348 lcid
, flags
, &new_dp
, res
, ei
, caller
);
3351 return S_FALSE
; /* fallback to default */
3354 static const IEventTargetVtbl EventTargetVtbl
= {
3355 EventTarget_QueryInterface
,
3357 EventTarget_Release
,
3358 EventTarget_GetTypeInfoCount
,
3359 EventTarget_GetTypeInfo
,
3360 EventTarget_GetIDsOfNames
,
3362 EventTarget_addEventListener
,
3363 EventTarget_removeEventListener
,
3364 EventTarget_dispatchEvent
3367 static EventTarget
*unsafe_impl_from_IEventTarget(IEventTarget
*iface
)
3369 return iface
&& iface
->lpVtbl
== &EventTargetVtbl
? impl_from_IEventTarget(iface
) : NULL
;
3372 static HRESULT
get_gecko_target(IEventTarget
*target
, nsIDOMEventTarget
**ret
)
3374 EventTarget
*event_target
= unsafe_impl_from_IEventTarget(target
);
3375 const event_target_vtbl_t
*vtbl
;
3379 WARN("Not our IEventTarget implementation\n");
3380 return E_INVALIDARG
;
3383 vtbl
= (const event_target_vtbl_t
*)dispex_get_vtbl(&event_target
->dispex
);
3384 nsres
= nsISupports_QueryInterface(vtbl
->get_gecko_target(&event_target
->dispex
),
3385 &IID_nsIDOMEventTarget
, (void**)ret
);
3386 assert(nsres
== NS_OK
);
3390 HRESULT
EventTarget_QI(EventTarget
*event_target
, REFIID riid
, void **ppv
)
3392 if(IsEqualGUID(riid
, &IID_IEventTarget
)) {
3393 if(use_event_quirks(event_target
)) {
3394 WARN("IEventTarget queried, but not supported by in document mode\n");
3396 return E_NOINTERFACE
;
3398 IEventTarget_AddRef(&event_target
->IEventTarget_iface
);
3399 *ppv
= &event_target
->IEventTarget_iface
;
3403 if(dispex_query_interface(&event_target
->dispex
, riid
, ppv
))
3404 return *ppv
? S_OK
: E_NOINTERFACE
;
3406 WARN("(%p)->(%s %p)\n", event_target
, debugstr_mshtml_guid(riid
), ppv
);
3408 return E_NOINTERFACE
;
3411 void EventTarget_init_dispex_info(dispex_data_t
*dispex_info
, compat_mode_t compat_mode
)
3413 static const dispex_hook_t IEventTarget_hooks
[] = {
3414 {DISPID_IEVENTTARGET_ADDEVENTLISTENER
, IEventTarget_addEventListener_hook
},
3415 {DISPID_IEVENTTARGET_REMOVEEVENTLISTENER
, IEventTarget_removeEventListener_hook
},
3419 if(compat_mode
>= COMPAT_MODE_IE9
)
3420 dispex_info_add_interface(dispex_info
, IEventTarget_tid
, IEventTarget_hooks
);
3423 static int event_id_cmp(const void *key
, const struct wine_rb_entry
*entry
)
3425 return wcscmp(key
, WINE_RB_ENTRY_VALUE(entry
, listener_container_t
, entry
)->type
);
3428 void EventTarget_Init(EventTarget
*event_target
, IUnknown
*outer
, dispex_static_data_t
*dispex_data
,
3429 compat_mode_t compat_mode
)
3431 init_dispatch(&event_target
->dispex
, outer
, dispex_data
, compat_mode
);
3432 event_target
->IEventTarget_iface
.lpVtbl
= &EventTargetVtbl
;
3433 wine_rb_init(&event_target
->handler_map
, event_id_cmp
);
3436 void release_event_target(EventTarget
*event_target
)
3438 listener_container_t
*iter
, *iter2
;
3440 WINE_RB_FOR_EACH_ENTRY_DESTRUCTOR(iter
, iter2
, &event_target
->handler_map
, listener_container_t
, entry
) {
3441 while(!list_empty(&iter
->listeners
)) {
3442 event_listener_t
*listener
= LIST_ENTRY(list_head(&iter
->listeners
), event_listener_t
, entry
);
3443 if(listener
->function
)
3444 IDispatch_Release(listener
->function
);
3445 list_remove(&listener
->entry
);
3446 heap_free(listener
);