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 loadW
[] = {'l','o','a','d',0};
39 static const WCHAR onloadW
[] = {'o','n','l','o','a','d',0};
46 static const event_info_t event_info
[] = {
51 const IHTMLEventObjVtbl
*lpIHTMLEventObjVtbl
;
55 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
57 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
59 static HRESULT WINAPI
HTMLEventObj_QueryInterface(IHTMLEventObj
*iface
, REFIID riid
, void **ppv
)
61 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
65 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
66 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
67 *ppv
= HTMLEVENTOBJ(This
);
68 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
69 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
70 *ppv
= HTMLEVENTOBJ(This
);
71 }else if(IsEqualGUID(&IID_IHTMLEventObj
, riid
)) {
72 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This
, ppv
);
73 *ppv
= HTMLEVENTOBJ(This
);
77 IUnknown_AddRef((IUnknown
*)*ppv
);
81 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
85 static ULONG WINAPI
HTMLEventObj_AddRef(IHTMLEventObj
*iface
)
87 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
88 LONG ref
= InterlockedIncrement(&This
->ref
);
90 TRACE("(%p) ref=%d\n", This
, ref
);
95 static ULONG WINAPI
HTMLEventObj_Release(IHTMLEventObj
*iface
)
97 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
98 LONG ref
= InterlockedDecrement(&This
->ref
);
100 TRACE("(%p) ref=%d\n", This
, ref
);
108 static HRESULT WINAPI
HTMLEventObj_GetTypeInfoCount(IHTMLEventObj
*iface
, UINT
*pctinfo
)
110 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
111 FIXME("(%p)->(%p)\n", This
, pctinfo
);
115 static HRESULT WINAPI
HTMLEventObj_GetTypeInfo(IHTMLEventObj
*iface
, UINT iTInfo
,
116 LCID lcid
, ITypeInfo
**ppTInfo
)
118 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
119 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
123 static HRESULT WINAPI
HTMLEventObj_GetIDsOfNames(IHTMLEventObj
*iface
, REFIID riid
,
124 LPOLESTR
*rgszNames
, UINT cNames
,
125 LCID lcid
, DISPID
*rgDispId
)
127 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
128 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
133 static HRESULT WINAPI
HTMLEventObj_Invoke(IHTMLEventObj
*iface
, DISPID dispIdMember
,
134 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
135 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
137 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
138 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
139 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
143 static HRESULT WINAPI
HTMLEventObj_get_srcElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
145 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
146 FIXME("(%p)->(%p)\n", This
, p
);
150 static HRESULT WINAPI
HTMLEventObj_get_altKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
152 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
153 FIXME("(%p)->(%p)\n", This
, p
);
157 static HRESULT WINAPI
HTMLEventObj_get_ctrlKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
159 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
160 FIXME("(%p)->(%p)\n", This
, p
);
164 static HRESULT WINAPI
HTMLEventObj_get_shiftKey(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
166 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
167 FIXME("(%p)->(%p)\n", This
, p
);
171 static HRESULT WINAPI
HTMLEventObj_put_returnValue(IHTMLEventObj
*iface
, VARIANT v
)
173 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
174 FIXME("(%p)->()\n", This
);
178 static HRESULT WINAPI
HTMLEventObj_get_returnValue(IHTMLEventObj
*iface
, VARIANT
*p
)
180 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
181 FIXME("(%p)->(%p)\n", This
, p
);
185 static HRESULT WINAPI
HTMLEventObj_put_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL v
)
187 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
188 FIXME("(%p)->(%x)\n", This
, v
);
192 static HRESULT WINAPI
HTMLEventObj_get_cancelBubble(IHTMLEventObj
*iface
, VARIANT_BOOL
*p
)
194 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
195 FIXME("(%p)->(%p)\n", This
, p
);
199 static HRESULT WINAPI
HTMLEventObj_get_fromElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
201 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
202 FIXME("(%p)->(%p)\n", This
, p
);
206 static HRESULT WINAPI
HTMLEventObj_get_toElement(IHTMLEventObj
*iface
, IHTMLElement
**p
)
208 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
209 FIXME("(%p)->(%p)\n", This
, p
);
213 static HRESULT WINAPI
HTMLEventObj_put_keyCode(IHTMLEventObj
*iface
, long v
)
215 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
216 FIXME("(%p)->(%ld)\n", This
, v
);
220 static HRESULT WINAPI
HTMLEventObj_get_keyCode(IHTMLEventObj
*iface
, long *p
)
222 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
223 FIXME("(%p)->(%p)\n", This
, p
);
227 static HRESULT WINAPI
HTMLEventObj_get_button(IHTMLEventObj
*iface
, long *p
)
229 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
230 FIXME("(%p)->(%p)\n", This
, p
);
234 static HRESULT WINAPI
HTMLEventObj_get_type(IHTMLEventObj
*iface
, BSTR
*p
)
236 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
237 FIXME("(%p)->(%p)\n", This
, p
);
241 static HRESULT WINAPI
HTMLEventObj_get_qualifier(IHTMLEventObj
*iface
, BSTR
*p
)
243 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
244 FIXME("(%p)->(%p)\n", This
, p
);
248 static HRESULT WINAPI
HTMLEventObj_get_reason(IHTMLEventObj
*iface
, long *p
)
250 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
251 FIXME("(%p)->(%p)\n", This
, p
);
255 static HRESULT WINAPI
HTMLEventObj_get_x(IHTMLEventObj
*iface
, long *p
)
257 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
258 FIXME("(%p)->(%p)\n", This
, p
);
262 static HRESULT WINAPI
HTMLEventObj_get_y(IHTMLEventObj
*iface
, long *p
)
264 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
265 FIXME("(%p)->(%p)\n", This
, p
);
269 static HRESULT WINAPI
HTMLEventObj_get_clientX(IHTMLEventObj
*iface
, long *p
)
271 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
272 FIXME("(%p)->(%p)\n", This
, p
);
276 static HRESULT WINAPI
HTMLEventObj_get_clientY(IHTMLEventObj
*iface
, long *p
)
278 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
279 FIXME("(%p)->(%p)\n", This
, p
);
283 static HRESULT WINAPI
HTMLEventObj_get_offsetX(IHTMLEventObj
*iface
, long *p
)
285 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
286 FIXME("(%p)->(%p)\n", This
, p
);
290 static HRESULT WINAPI
HTMLEventObj_get_offsetY(IHTMLEventObj
*iface
, long *p
)
292 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
293 FIXME("(%p)->(%p)\n", This
, p
);
297 static HRESULT WINAPI
HTMLEventObj_get_screenX(IHTMLEventObj
*iface
, long *p
)
299 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
300 FIXME("(%p)->(%p)\n", This
, p
);
304 static HRESULT WINAPI
HTMLEventObj_get_screenY(IHTMLEventObj
*iface
, long *p
)
306 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
307 FIXME("(%p)->(%p)\n", This
, p
);
311 static HRESULT WINAPI
HTMLEventObj_get_srcFilter(IHTMLEventObj
*iface
, IDispatch
**p
)
313 HTMLEventObj
*This
= HTMLEVENTOBJ_THIS(iface
);
314 FIXME("(%p)->(%p)\n", This
, p
);
318 #undef HTMLEVENTOBJ_THIS
320 static const IHTMLEventObjVtbl HTMLEventObjVtbl
= {
321 HTMLEventObj_QueryInterface
,
323 HTMLEventObj_Release
,
324 HTMLEventObj_GetTypeInfoCount
,
325 HTMLEventObj_GetTypeInfo
,
326 HTMLEventObj_GetIDsOfNames
,
328 HTMLEventObj_get_srcElement
,
329 HTMLEventObj_get_altKey
,
330 HTMLEventObj_get_ctrlKey
,
331 HTMLEventObj_get_shiftKey
,
332 HTMLEventObj_put_returnValue
,
333 HTMLEventObj_get_returnValue
,
334 HTMLEventObj_put_cancelBubble
,
335 HTMLEventObj_get_cancelBubble
,
336 HTMLEventObj_get_fromElement
,
337 HTMLEventObj_get_toElement
,
338 HTMLEventObj_put_keyCode
,
339 HTMLEventObj_get_keyCode
,
340 HTMLEventObj_get_button
,
341 HTMLEventObj_get_type
,
342 HTMLEventObj_get_qualifier
,
343 HTMLEventObj_get_reason
,
346 HTMLEventObj_get_clientX
,
347 HTMLEventObj_get_clientY
,
348 HTMLEventObj_get_offsetX
,
349 HTMLEventObj_get_offsetY
,
350 HTMLEventObj_get_screenX
,
351 HTMLEventObj_get_screenY
,
352 HTMLEventObj_get_srcFilter
355 static IHTMLEventObj
*create_event(void)
359 ret
= heap_alloc(sizeof(*ret
));
360 ret
->lpIHTMLEventObjVtbl
= &HTMLEventObjVtbl
;
363 return HTMLEVENTOBJ(ret
);
366 void fire_event(HTMLDocument
*doc
, eventid_t eid
, nsIDOMNode
*target
)
370 node
= get_node(doc
, target
, FALSE
);
374 if(node
->event_target
&& node
->event_target
->event_table
[eid
]) {
375 doc
->window
->event
= create_event();
377 call_disp_func(doc
, node
->event_target
->event_table
[eid
]);
379 IHTMLEventObj_Release(doc
->window
->event
);
380 doc
->window
->event
= NULL
;
384 void check_event_attr(HTMLDocument
*doc
, nsIDOMElement
*nselem
)
386 const PRUnichar
*attr_value
;
387 nsAString attr_name_str
, attr_value_str
;
393 nsAString_Init(&attr_value_str
, NULL
);
394 nsAString_Init(&attr_name_str
, NULL
);
396 for(i
=0; i
< EVENTID_LAST
; i
++) {
397 nsAString_SetData(&attr_name_str
, event_info
[i
].attr_name
);
398 nsres
= nsIDOMElement_GetAttribute(nselem
, &attr_name_str
, &attr_value_str
);
399 if(NS_SUCCEEDED(nsres
)) {
400 nsAString_GetData(&attr_value_str
, &attr_value
);
404 TRACE("%p.%s = %s\n", nselem
, debugstr_w(event_info
[i
].attr_name
), debugstr_w(attr_value
));
406 disp
= script_parse_event(doc
, attr_value
);
408 node
= get_node(doc
, (nsIDOMNode
*)nselem
, TRUE
);
409 if(!node
->event_target
)
410 node
->event_target
= heap_alloc_zero(sizeof(event_target_t
));
411 node
->event_target
->event_table
[i
] = disp
;
416 nsAString_Finish(&attr_value_str
);
417 nsAString_Finish(&attr_name_str
);
420 void release_event_target(event_target_t
*event_target
)
424 for(i
=0; i
< EVENTID_LAST
; i
++) {
425 if(event_target
->event_table
[i
])
426 IDispatch_Release(event_target
->event_table
[i
]);
429 heap_free(event_target
);