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 clickW
[] = {'c','l','i','c','k',0};
39 static const WCHAR onclickW
[] = {'o','n','c','l','i','c','k',0};
41 static const WCHAR loadW
[] = {'l','o','a','d',0};
42 static const WCHAR onloadW
[] = {'o','n','l','o','a','d',0};
50 #define EVENT_DEFAULTLISTENER 0x0001
52 static const event_info_t event_info
[] = {
53 {clickW
, onclickW
, EVENT_DEFAULTLISTENER
},
57 eventid_t
str_to_eid(LPCWSTR str
)
61 for(i
=0; i
< sizeof(event_info
)/sizeof(event_info
[0]); i
++) {
62 if(!strcmpW(event_info
[i
].name
, str
))
66 ERR("unknown type %s\n", debugstr_w(str
));
71 const IHTMLEventObjVtbl
*lpIHTMLEventObjVtbl
;
75 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
77 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
79 static HRESULT WINAPI
HTMLEventObj_QueryInterface(IHTMLEventObj
*iface
, REFIID riid
, void **ppv
)
81 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
85 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
86 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
87 *ppv
= HTMLEVENTOBJ(This
);
88 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
89 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
90 *ppv
= HTMLEVENTOBJ(This
);
91 }else if(IsEqualGUID(&IID_IHTMLEventObj
, riid
)) {
92 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This
, ppv
);
93 *ppv
= HTMLEVENTOBJ(This
);
97 IUnknown_AddRef((IUnknown
*)*ppv
);
101 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
102 return E_NOINTERFACE
;
105 static ULONG WINAPI
HTMLEventObj_AddRef(IHTMLEventObj
*iface
)
107 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
108 LONG ref
= InterlockedIncrement(&This
->ref
);
110 TRACE("(%p) ref=%d\n", This
, ref
);
115 static ULONG WINAPI
HTMLEventObj_Release(IHTMLEventObj
*iface
)
117 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
118 LONG ref
= InterlockedDecrement(&This
->ref
);
120 TRACE("(%p) ref=%d\n", This
, ref
);
128 static HRESULT WINAPI
HTMLEventObj_GetTypeInfoCount(IHTMLEventObj
*iface
, UINT
*pctinfo
)
130 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
131 FIXME("(%p)->(%p)\n", This
, pctinfo
);
135 static HRESULT WINAPI
HTMLEventObj_GetTypeInfo(IHTMLEventObj
*iface
, UINT iTInfo
,
136 LCID lcid
, ITypeInfo
**ppTInfo
)
138 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
139 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
143 static HRESULT WINAPI
HTMLEventObj_GetIDsOfNames(IHTMLEventObj
*iface
, REFIID riid
,
144 LPOLESTR
*rgszNames
, UINT cNames
,
145 LCID lcid
, DISPID
*rgDispId
)
147 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
148 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
153 static HRESULT WINAPI
HTMLEventObj_Invoke(IHTMLEventObj
*iface
, DISPID dispIdMember
,
154 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
155 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
157 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
158 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
159 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
163 static HRESULT WINAPI
HTMLEventObj_get_srcElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
165 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
166 FIXME("(%p)->(%p)\n", This
, p
);
170 static HRESULT WINAPI
HTMLEventObj_get_altKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
172 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
173 FIXME("(%p)->(%p)\n", This
, p
);
177 static HRESULT WINAPI
HTMLEventObj_get_ctrlKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
179 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
180 FIXME("(%p)->(%p)\n", This
, p
);
184 static HRESULT WINAPI
HTMLEventObj_get_shiftKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
186 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
187 FIXME("(%p)->(%p)\n", This
, p
);
191 static HRESULT WINAPI
HTMLEventObj_put_returnValue(IHTMLEventObj
*iface
, VARIANT v
)
193 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
194 FIXME("(%p)->()\n", This
);
198 static HRESULT WINAPI
HTMLEventObj_get_returnValue(IHTMLEventObj
*iface
, VARIANT
*p
)
200 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
201 FIXME("(%p)->(%p)\n", This
, p
);
205 static HRESULT WINAPI
HTMLEventObj_put_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL v
)
207 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
208 FIXME("(%p)->(%x)\n", This
, v
);
212 static HRESULT WINAPI
HTMLEventObj_get_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
214 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
215 FIXME("(%p)->(%p)\n", This
, p
);
219 static HRESULT WINAPI
HTMLEventObj_get_fromElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
221 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
222 FIXME("(%p)->(%p)\n", This
, p
);
226 static HRESULT WINAPI
HTMLEventObj_get_toElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
228 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
229 FIXME("(%p)->(%p)\n", This
, p
);
233 static HRESULT WINAPI
HTMLEventObj_put_keyCode(IHTMLEventObj
*iface
, long v
)
235 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
236 FIXME("(%p)->(%ld)\n", This
, v
);
240 static HRESULT WINAPI
HTMLEventObj_get_keyCode(IHTMLEventObj
*iface
, long *p
)
242 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
243 FIXME("(%p)->(%p)\n", This
, p
);
247 static HRESULT WINAPI
HTMLEventObj_get_button(IHTMLEventObj
*iface
, long *p
)
249 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
250 FIXME("(%p)->(%p)\n", This
, p
);
254 static HRESULT WINAPI
HTMLEventObj_get_type(IHTMLEventObj
*iface
, BSTR
*p
)
256 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
257 FIXME("(%p)->(%p)\n", This
, p
);
261 static HRESULT WINAPI
HTMLEventObj_get_qualifier(IHTMLEventObj
*iface
, BSTR
*p
)
263 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
264 FIXME("(%p)->(%p)\n", This
, p
);
268 static HRESULT WINAPI
HTMLEventObj_get_reason(IHTMLEventObj
*iface
, long *p
)
270 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
271 FIXME("(%p)->(%p)\n", This
, p
);
275 static HRESULT WINAPI
HTMLEventObj_get_x(IHTMLEventObj
*iface
, long *p
)
277 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
278 FIXME("(%p)->(%p)\n", This
, p
);
282 static HRESULT WINAPI
HTMLEventObj_get_y(IHTMLEventObj
*iface
, long *p
)
284 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
285 FIXME("(%p)->(%p)\n", This
, p
);
289 static HRESULT WINAPI
HTMLEventObj_get_clientX(IHTMLEventObj
*iface
, long *p
)
291 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
292 FIXME("(%p)->(%p)\n", This
, p
);
296 static HRESULT WINAPI
HTMLEventObj_get_clientY(IHTMLEventObj
*iface
, long *p
)
298 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
299 FIXME("(%p)->(%p)\n", This
, p
);
303 static HRESULT WINAPI
HTMLEventObj_get_offsetX(IHTMLEventObj
*iface
, long *p
)
305 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
306 FIXME("(%p)->(%p)\n", This
, p
);
310 static HRESULT WINAPI
HTMLEventObj_get_offsetY(IHTMLEventObj
*iface
, long *p
)
312 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
313 FIXME("(%p)->(%p)\n", This
, p
);
317 static HRESULT WINAPI
HTMLEventObj_get_screenX(IHTMLEventObj
*iface
, long *p
)
319 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
320 FIXME("(%p)->(%p)\n", This
, p
);
324 static HRESULT WINAPI
HTMLEventObj_get_screenY(IHTMLEventObj
*iface
, long *p
)
326 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
327 FIXME("(%p)->(%p)\n", This
, p
);
331 static HRESULT WINAPI
HTMLEventObj_get_srcFilter(IHTMLEventObj
*iface
, IDispatch
**p
)
333 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
334 FIXME("(%p)->(%p)\n", This
, p
);
338 #undef HTMLEVENTOBJ_THIS
340 static const IHTMLEventObjVtbl HTMLEventObjVtbl
= {
341 HTMLEventObj_QueryInterface
,
343 HTMLEventObj_Release
,
344 HTMLEventObj_GetTypeInfoCount
,
345 HTMLEventObj_GetTypeInfo
,
346 HTMLEventObj_GetIDsOfNames
,
348 HTMLEventObj_get_srcElement
,
349 HTMLEventObj_get_altKey
,
350 HTMLEventObj_get_ctrlKey
,
351 HTMLEventObj_get_shiftKey
,
352 HTMLEventObj_put_returnValue
,
353 HTMLEventObj_get_returnValue
,
354 HTMLEventObj_put_cancelBubble
,
355 HTMLEventObj_get_cancelBubble
,
356 HTMLEventObj_get_fromElement
,
357 HTMLEventObj_get_toElement
,
358 HTMLEventObj_put_keyCode
,
359 HTMLEventObj_get_keyCode
,
360 HTMLEventObj_get_button
,
361 HTMLEventObj_get_type
,
362 HTMLEventObj_get_qualifier
,
363 HTMLEventObj_get_reason
,
366 HTMLEventObj_get_clientX
,
367 HTMLEventObj_get_clientY
,
368 HTMLEventObj_get_offsetX
,
369 HTMLEventObj_get_offsetY
,
370 HTMLEventObj_get_screenX
,
371 HTMLEventObj_get_screenY
,
372 HTMLEventObj_get_srcFilter
375 static IHTMLEventObj
*create_event(void)
379 ret
= heap_alloc(sizeof(*ret
));
380 ret
->lpIHTMLEventObjVtbl
= &HTMLEventObjVtbl
;
383 return HTMLEVENTOBJ(ret
);
386 void fire_event(HTMLDocument
*doc
, eventid_t eid
, nsIDOMNode
*target
)
390 node
= get_node(doc
, target
, FALSE
);
394 if(node
->event_target
&& node
->event_target
->event_table
[eid
]) {
395 doc
->window
->event
= create_event();
397 call_disp_func(doc
, node
->event_target
->event_table
[eid
]);
399 IHTMLEventObj_Release(doc
->window
->event
);
400 doc
->window
->event
= NULL
;
404 static HRESULT
set_node_event_disp(HTMLDOMNode
*node
, eventid_t eid
, IDispatch
*disp
)
406 if(!node
->event_target
)
407 node
->event_target
= heap_alloc_zero(sizeof(event_target_t
));
408 else if(node
->event_target
->event_table
[eid
])
409 IDispatch_Release(node
->event_target
->event_table
[eid
]);
411 IDispatch_AddRef(disp
);
412 node
->event_target
->event_table
[eid
] = disp
;
414 if((event_info
[eid
].flags
& EVENT_DEFAULTLISTENER
) && !node
->doc
->nscontainer
->event_vector
[eid
]) {
415 node
->doc
->nscontainer
->event_vector
[eid
] = TRUE
;
416 add_nsevent_listener(node
->doc
->nscontainer
, event_info
[eid
].name
);
422 HRESULT
set_node_event(HTMLDOMNode
*node
, eventid_t eid
, VARIANT
*var
)
426 return set_node_event_disp(node
, eid
, V_DISPATCH(var
));
429 FIXME("not supported vt=%d\n", V_VT(var
));
435 void check_event_attr(HTMLDocument
*doc
, nsIDOMElement
*nselem
)
437 const PRUnichar
*attr_value
;
438 nsAString attr_name_str
, attr_value_str
;
444 nsAString_Init(&attr_value_str
, NULL
);
445 nsAString_Init(&attr_name_str
, NULL
);
447 for(i
=0; i
< EVENTID_LAST
; i
++) {
448 nsAString_SetData(&attr_name_str
, event_info
[i
].attr_name
);
449 nsres
= nsIDOMElement_GetAttribute(nselem
, &attr_name_str
, &attr_value_str
);
450 if(NS_SUCCEEDED(nsres
)) {
451 nsAString_GetData(&attr_value_str
, &attr_value
);
455 TRACE("%p.%s = %s\n", nselem
, debugstr_w(event_info
[i
].attr_name
), debugstr_w(attr_value
));
457 disp
= script_parse_event(doc
, attr_value
);
459 node
= get_node(doc
, (nsIDOMNode
*)nselem
, TRUE
);
460 set_node_event_disp(node
, i
, disp
);
461 IDispatch_Release(disp
);
466 nsAString_Finish(&attr_value_str
);
467 nsAString_Finish(&attr_name_str
);
470 void release_event_target(event_target_t
*event_target
)
474 for(i
=0; i
< EVENTID_LAST
; i
++) {
475 if(event_target
->event_table
[i
])
476 IDispatch_Release(event_target
->event_table
[i
]);
479 heap_free(event_target
);