2 * Copyright 2008 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
28 #include "mshtml_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
34 struct event_target_t
{
35 IDispatch
*event_table
[EVENTID_LAST
];
38 static const WCHAR changeW
[] = {'c','h','a','n','g','e',0};
39 static const WCHAR onchangeW
[] = {'o','n','c','h','a','n','g','e',0};
41 static const WCHAR clickW
[] = {'c','l','i','c','k',0};
42 static const WCHAR onclickW
[] = {'o','n','c','l','i','c','k',0};
44 static const WCHAR keyupW
[] = {'k','e','y','u','p',0};
45 static const WCHAR onkeyupW
[] = {'o','n','k','e','y','u','p',0};
47 static const WCHAR loadW
[] = {'l','o','a','d',0};
48 static const WCHAR onloadW
[] = {'o','n','l','o','a','d',0};
56 #define EVENT_DEFAULTLISTENER 0x0001
58 static const event_info_t event_info
[] = {
59 {changeW
, onchangeW
, EVENT_DEFAULTLISTENER
},
60 {clickW
, onclickW
, EVENT_DEFAULTLISTENER
},
61 {keyupW
, onkeyupW
, EVENT_DEFAULTLISTENER
},
65 eventid_t
str_to_eid(LPCWSTR str
)
69 for(i
=0; i
< sizeof(event_info
)/sizeof(event_info
[0]); i
++) {
70 if(!strcmpW(event_info
[i
].name
, str
))
74 ERR("unknown type %s\n", debugstr_w(str
));
79 const IHTMLEventObjVtbl
*lpIHTMLEventObjVtbl
;
83 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
85 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
87 static HRESULT WINAPI
HTMLEventObj_QueryInterface(IHTMLEventObj
*iface
, REFIID riid
, void **ppv
)
89 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
93 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
94 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
95 *ppv
= HTMLEVENTOBJ(This
);
96 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
97 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
98 *ppv
= HTMLEVENTOBJ(This
);
99 }else if(IsEqualGUID(&IID_IHTMLEventObj
, riid
)) {
100 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This
, ppv
);
101 *ppv
= HTMLEVENTOBJ(This
);
105 IUnknown_AddRef((IUnknown
*)*ppv
);
109 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
110 return E_NOINTERFACE
;
113 static ULONG WINAPI
HTMLEventObj_AddRef(IHTMLEventObj
*iface
)
115 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
116 LONG ref
= InterlockedIncrement(&This
->ref
);
118 TRACE("(%p) ref=%d\n", This
, ref
);
123 static ULONG WINAPI
HTMLEventObj_Release(IHTMLEventObj
*iface
)
125 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
126 LONG ref
= InterlockedDecrement(&This
->ref
);
128 TRACE("(%p) ref=%d\n", This
, ref
);
136 static HRESULT WINAPI
HTMLEventObj_GetTypeInfoCount(IHTMLEventObj
*iface
, UINT
*pctinfo
)
138 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
139 FIXME("(%p)->(%p)\n", This
, pctinfo
);
143 static HRESULT WINAPI
HTMLEventObj_GetTypeInfo(IHTMLEventObj
*iface
, UINT iTInfo
,
144 LCID lcid
, ITypeInfo
**ppTInfo
)
146 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
147 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
151 static HRESULT WINAPI
HTMLEventObj_GetIDsOfNames(IHTMLEventObj
*iface
, REFIID riid
,
152 LPOLESTR
*rgszNames
, UINT cNames
,
153 LCID lcid
, DISPID
*rgDispId
)
155 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
156 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
161 static HRESULT WINAPI
HTMLEventObj_Invoke(IHTMLEventObj
*iface
, DISPID dispIdMember
,
162 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
163 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
165 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
166 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
167 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
171 static HRESULT WINAPI
HTMLEventObj_get_srcElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
173 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
174 FIXME("(%p)->(%p)\n", This
, p
);
178 static HRESULT WINAPI
HTMLEventObj_get_altKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
180 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
181 FIXME("(%p)->(%p)\n", This
, p
);
185 static HRESULT WINAPI
HTMLEventObj_get_ctrlKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
187 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
188 FIXME("(%p)->(%p)\n", This
, p
);
192 static HRESULT WINAPI
HTMLEventObj_get_shiftKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
194 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
195 FIXME("(%p)->(%p)\n", This
, p
);
199 static HRESULT WINAPI
HTMLEventObj_put_returnValue(IHTMLEventObj
*iface
, VARIANT v
)
201 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
202 FIXME("(%p)->()\n", This
);
206 static HRESULT WINAPI
HTMLEventObj_get_returnValue(IHTMLEventObj
*iface
, VARIANT
*p
)
208 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
209 FIXME("(%p)->(%p)\n", This
, p
);
213 static HRESULT WINAPI
HTMLEventObj_put_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL v
)
215 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
216 FIXME("(%p)->(%x)\n", This
, v
);
220 static HRESULT WINAPI
HTMLEventObj_get_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
222 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
223 FIXME("(%p)->(%p)\n", This
, p
);
227 static HRESULT WINAPI
HTMLEventObj_get_fromElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
229 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
230 FIXME("(%p)->(%p)\n", This
, p
);
234 static HRESULT WINAPI
HTMLEventObj_get_toElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
236 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
237 FIXME("(%p)->(%p)\n", This
, p
);
241 static HRESULT WINAPI
HTMLEventObj_put_keyCode(IHTMLEventObj
*iface
, long v
)
243 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
244 FIXME("(%p)->(%ld)\n", This
, v
);
248 static HRESULT WINAPI
HTMLEventObj_get_keyCode(IHTMLEventObj
*iface
, long *p
)
250 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
251 FIXME("(%p)->(%p)\n", This
, p
);
255 static HRESULT WINAPI
HTMLEventObj_get_button(IHTMLEventObj
*iface
, long *p
)
257 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
258 FIXME("(%p)->(%p)\n", This
, p
);
262 static HRESULT WINAPI
HTMLEventObj_get_type(IHTMLEventObj
*iface
, BSTR
*p
)
264 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
265 FIXME("(%p)->(%p)\n", This
, p
);
269 static HRESULT WINAPI
HTMLEventObj_get_qualifier(IHTMLEventObj
*iface
, BSTR
*p
)
271 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
272 FIXME("(%p)->(%p)\n", This
, p
);
276 static HRESULT WINAPI
HTMLEventObj_get_reason(IHTMLEventObj
*iface
, long *p
)
278 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
279 FIXME("(%p)->(%p)\n", This
, p
);
283 static HRESULT WINAPI
HTMLEventObj_get_x(IHTMLEventObj
*iface
, long *p
)
285 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
286 FIXME("(%p)->(%p)\n", This
, p
);
290 static HRESULT WINAPI
HTMLEventObj_get_y(IHTMLEventObj
*iface
, long *p
)
292 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
293 FIXME("(%p)->(%p)\n", This
, p
);
297 static HRESULT WINAPI
HTMLEventObj_get_clientX(IHTMLEventObj
*iface
, long *p
)
299 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
300 FIXME("(%p)->(%p)\n", This
, p
);
304 static HRESULT WINAPI
HTMLEventObj_get_clientY(IHTMLEventObj
*iface
, long *p
)
306 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
307 FIXME("(%p)->(%p)\n", This
, p
);
311 static HRESULT WINAPI
HTMLEventObj_get_offsetX(IHTMLEventObj
*iface
, long *p
)
313 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
314 FIXME("(%p)->(%p)\n", This
, p
);
318 static HRESULT WINAPI
HTMLEventObj_get_offsetY(IHTMLEventObj
*iface
, long *p
)
320 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
321 FIXME("(%p)->(%p)\n", This
, p
);
325 static HRESULT WINAPI
HTMLEventObj_get_screenX(IHTMLEventObj
*iface
, long *p
)
327 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
328 FIXME("(%p)->(%p)\n", This
, p
);
332 static HRESULT WINAPI
HTMLEventObj_get_screenY(IHTMLEventObj
*iface
, long *p
)
334 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
335 FIXME("(%p)->(%p)\n", This
, p
);
339 static HRESULT WINAPI
HTMLEventObj_get_srcFilter(IHTMLEventObj
*iface
, IDispatch
**p
)
341 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
342 FIXME("(%p)->(%p)\n", This
, p
);
346 #undef HTMLEVENTOBJ_THIS
348 static const IHTMLEventObjVtbl HTMLEventObjVtbl
= {
349 HTMLEventObj_QueryInterface
,
351 HTMLEventObj_Release
,
352 HTMLEventObj_GetTypeInfoCount
,
353 HTMLEventObj_GetTypeInfo
,
354 HTMLEventObj_GetIDsOfNames
,
356 HTMLEventObj_get_srcElement
,
357 HTMLEventObj_get_altKey
,
358 HTMLEventObj_get_ctrlKey
,
359 HTMLEventObj_get_shiftKey
,
360 HTMLEventObj_put_returnValue
,
361 HTMLEventObj_get_returnValue
,
362 HTMLEventObj_put_cancelBubble
,
363 HTMLEventObj_get_cancelBubble
,
364 HTMLEventObj_get_fromElement
,
365 HTMLEventObj_get_toElement
,
366 HTMLEventObj_put_keyCode
,
367 HTMLEventObj_get_keyCode
,
368 HTMLEventObj_get_button
,
369 HTMLEventObj_get_type
,
370 HTMLEventObj_get_qualifier
,
371 HTMLEventObj_get_reason
,
374 HTMLEventObj_get_clientX
,
375 HTMLEventObj_get_clientY
,
376 HTMLEventObj_get_offsetX
,
377 HTMLEventObj_get_offsetY
,
378 HTMLEventObj_get_screenX
,
379 HTMLEventObj_get_screenY
,
380 HTMLEventObj_get_srcFilter
383 static IHTMLEventObj
*create_event(void)
387 ret
= heap_alloc(sizeof(*ret
));
388 ret
->lpIHTMLEventObjVtbl
= &HTMLEventObjVtbl
;
391 return HTMLEVENTOBJ(ret
);
394 void fire_event(HTMLDocument
*doc
, eventid_t eid
, nsIDOMNode
*target
)
398 node
= get_node(doc
, target
, FALSE
);
402 if(node
->event_target
&& node
->event_target
->event_table
[eid
]) {
403 doc
->window
->event
= create_event();
405 TRACE("%s >>>\n", debugstr_w(event_info
[eid
].name
));
406 call_disp_func(doc
, node
->event_target
->event_table
[eid
]);
407 TRACE("%s <<<\n", debugstr_w(event_info
[eid
].name
));
409 IHTMLEventObj_Release(doc
->window
->event
);
410 doc
->window
->event
= NULL
;
414 static HRESULT
set_node_event_disp(HTMLDOMNode
*node
, eventid_t eid
, IDispatch
*disp
)
416 if(!node
->event_target
)
417 node
->event_target
= heap_alloc_zero(sizeof(event_target_t
));
418 else if(node
->event_target
->event_table
[eid
])
419 IDispatch_Release(node
->event_target
->event_table
[eid
]);
421 IDispatch_AddRef(disp
);
422 node
->event_target
->event_table
[eid
] = disp
;
424 if((event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
) && !node
->doc
->nscontainer
->event_vector
[eid
]) {
425 node
->doc
->nscontainer
->event_vector
[eid
] = TRUE
;
426 add_nsevent_listener(node
->doc
->nscontainer
, event_info
[eid
].name
);
432 HRESULT
set_node_event(HTMLDOMNode
*node
, eventid_t eid
, VARIANT
*var
)
436 return set_node_event_disp(node
, eid
, V_DISPATCH(var
));
439 FIXME("not supported vt=%d\n", V_VT(var
));
445 void check_event_attr(HTMLDocument
*doc
, nsIDOMElement
*nselem
)
447 const PRUnichar
*attr_value
;
448 nsAString attr_name_str
, attr_value_str
;
454 nsAString_Init(&attr_value_str
, NULL
);
455 nsAString_Init(&attr_name_str
, NULL
);
457 for(i
=0; i
< EVENTID_LAST
; i
++) {
458 nsAString_SetData(&attr_name_str
, event_info
[i
].attr_name
);
459 nsres
= nsIDOMElement_GetAttribute(nselem
, &attr_name_str
, &attr_value_str
);
460 if(NS_SUCCEEDED(nsres
)) {
461 nsAString_GetData(&attr_value_str
, &attr_value
);
465 TRACE("%p.%s = %s\n", nselem
, debugstr_w(event_info
[i
].attr_name
), debugstr_w(attr_value
));
467 disp
= script_parse_event(doc
, attr_value
);
469 node
= get_node(doc
, (nsIDOMNode
*)nselem
, TRUE
);
470 set_node_event_disp(node
, i
, disp
);
471 IDispatch_Release(disp
);
476 nsAString_Finish(&attr_value_str
);
477 nsAString_Finish(&attr_name_str
);
480 void release_event_target(event_target_t
*event_target
)
484 for(i
=0; i
< EVENTID_LAST
; i
++) {
485 if(event_target
->event_table
[i
])
486 IDispatch_Release(event_target
->event_table
[i
]);
489 heap_free(event_target
);