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};
49 static const event_info_t event_info[] = {
55 const IHTMLEventObjVtbl *lpIHTMLEventObjVtbl;
59 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
61 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
63 static HRESULT WINAPI HTMLEventObj_QueryInterface(IHTMLEventObj *iface, REFIID riid, void **ppv)
65 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
69 if(IsEqualGUID(&IID_IUnknown, riid)) {
70 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
71 *ppv = HTMLEVENTOBJ(This);
72 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
73 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
74 *ppv = HTMLEVENTOBJ(This);
75 }else if(IsEqualGUID(&IID_IHTMLEventObj, riid)) {
76 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This, ppv);
77 *ppv = HTMLEVENTOBJ(This);
81 IUnknown_AddRef((IUnknown*)*ppv);
85 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
89 static ULONG WINAPI HTMLEventObj_AddRef(IHTMLEventObj *iface)
91 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
92 LONG ref = InterlockedIncrement(&This->ref);
94 TRACE("(%p) ref=%d\n", This, ref);
99 static ULONG WINAPI HTMLEventObj_Release(IHTMLEventObj *iface)
101 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
102 LONG ref = InterlockedDecrement(&This->ref);
104 TRACE("(%p) ref=%d\n", This, ref);
112 static HRESULT WINAPI HTMLEventObj_GetTypeInfoCount(IHTMLEventObj *iface, UINT *pctinfo)
114 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
115 FIXME("(%p)->(%p)\n", This, pctinfo);
119 static HRESULT WINAPI HTMLEventObj_GetTypeInfo(IHTMLEventObj *iface, UINT iTInfo,
120 LCID lcid, ITypeInfo **ppTInfo)
122 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
123 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
127 static HRESULT WINAPI HTMLEventObj_GetIDsOfNames(IHTMLEventObj *iface, REFIID riid,
128 LPOLESTR *rgszNames, UINT cNames,
129 LCID lcid, DISPID *rgDispId)
131 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
132 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
137 static HRESULT WINAPI HTMLEventObj_Invoke(IHTMLEventObj *iface, DISPID dispIdMember,
138 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
139 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
141 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
142 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
143 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
147 static HRESULT WINAPI HTMLEventObj_get_srcElement(IHTMLEventObj *iface, IHTMLElement **p)
149 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
150 FIXME("(%p)->(%p)\n", This, p);
154 static HRESULT WINAPI HTMLEventObj_get_altKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
156 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
157 FIXME("(%p)->(%p)\n", This, p);
161 static HRESULT WINAPI HTMLEventObj_get_ctrlKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
163 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
164 FIXME("(%p)->(%p)\n", This, p);
168 static HRESULT WINAPI HTMLEventObj_get_shiftKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
170 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
171 FIXME("(%p)->(%p)\n", This, p);
175 static HRESULT WINAPI HTMLEventObj_put_returnValue(IHTMLEventObj *iface, VARIANT v)
177 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
178 FIXME("(%p)->()\n", This);
182 static HRESULT WINAPI HTMLEventObj_get_returnValue(IHTMLEventObj *iface, VARIANT *p)
184 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
185 FIXME("(%p)->(%p)\n", This, p);
189 static HRESULT WINAPI HTMLEventObj_put_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL v)
191 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
192 FIXME("(%p)->(%x)\n", This, v);
196 static HRESULT WINAPI HTMLEventObj_get_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL *p)
198 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
199 FIXME("(%p)->(%p)\n", This, p);
203 static HRESULT WINAPI HTMLEventObj_get_fromElement(IHTMLEventObj *iface, IHTMLElement **p)
205 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
206 FIXME("(%p)->(%p)\n", This, p);
210 static HRESULT WINAPI HTMLEventObj_get_toElement(IHTMLEventObj *iface, IHTMLElement **p)
212 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
213 FIXME("(%p)->(%p)\n", This, p);
217 static HRESULT WINAPI HTMLEventObj_put_keyCode(IHTMLEventObj *iface, long v)
219 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
220 FIXME("(%p)->(%ld)\n", This, v);
224 static HRESULT WINAPI HTMLEventObj_get_keyCode(IHTMLEventObj *iface, long *p)
226 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
227 FIXME("(%p)->(%p)\n", This, p);
231 static HRESULT WINAPI HTMLEventObj_get_button(IHTMLEventObj *iface, long *p)
233 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
234 FIXME("(%p)->(%p)\n", This, p);
238 static HRESULT WINAPI HTMLEventObj_get_type(IHTMLEventObj *iface, BSTR *p)
240 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
241 FIXME("(%p)->(%p)\n", This, p);
245 static HRESULT WINAPI HTMLEventObj_get_qualifier(IHTMLEventObj *iface, BSTR *p)
247 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
248 FIXME("(%p)->(%p)\n", This, p);
252 static HRESULT WINAPI HTMLEventObj_get_reason(IHTMLEventObj *iface, long *p)
254 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
255 FIXME("(%p)->(%p)\n", This, p);
259 static HRESULT WINAPI HTMLEventObj_get_x(IHTMLEventObj *iface, long *p)
261 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
262 FIXME("(%p)->(%p)\n", This, p);
266 static HRESULT WINAPI HTMLEventObj_get_y(IHTMLEventObj *iface, long *p)
268 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
269 FIXME("(%p)->(%p)\n", This, p);
273 static HRESULT WINAPI HTMLEventObj_get_clientX(IHTMLEventObj *iface, long *p)
275 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
276 FIXME("(%p)->(%p)\n", This, p);
280 static HRESULT WINAPI HTMLEventObj_get_clientY(IHTMLEventObj *iface, long *p)
282 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
283 FIXME("(%p)->(%p)\n", This, p);
287 static HRESULT WINAPI HTMLEventObj_get_offsetX(IHTMLEventObj *iface, long *p)
289 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
290 FIXME("(%p)->(%p)\n", This, p);
294 static HRESULT WINAPI HTMLEventObj_get_offsetY(IHTMLEventObj *iface, long *p)
296 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
297 FIXME("(%p)->(%p)\n", This, p);
301 static HRESULT WINAPI HTMLEventObj_get_screenX(IHTMLEventObj *iface, long *p)
303 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
304 FIXME("(%p)->(%p)\n", This, p);
308 static HRESULT WINAPI HTMLEventObj_get_screenY(IHTMLEventObj *iface, long *p)
310 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
311 FIXME("(%p)->(%p)\n", This, p);
315 static HRESULT WINAPI HTMLEventObj_get_srcFilter(IHTMLEventObj *iface, IDispatch **p)
317 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
318 FIXME("(%p)->(%p)\n", This, p);
322 #undef HTMLEVENTOBJ_THIS
324 static const IHTMLEventObjVtbl HTMLEventObjVtbl = {
325 HTMLEventObj_QueryInterface,
327 HTMLEventObj_Release,
328 HTMLEventObj_GetTypeInfoCount,
329 HTMLEventObj_GetTypeInfo,
330 HTMLEventObj_GetIDsOfNames,
332 HTMLEventObj_get_srcElement,
333 HTMLEventObj_get_altKey,
334 HTMLEventObj_get_ctrlKey,
335 HTMLEventObj_get_shiftKey,
336 HTMLEventObj_put_returnValue,
337 HTMLEventObj_get_returnValue,
338 HTMLEventObj_put_cancelBubble,
339 HTMLEventObj_get_cancelBubble,
340 HTMLEventObj_get_fromElement,
341 HTMLEventObj_get_toElement,
342 HTMLEventObj_put_keyCode,
343 HTMLEventObj_get_keyCode,
344 HTMLEventObj_get_button,
345 HTMLEventObj_get_type,
346 HTMLEventObj_get_qualifier,
347 HTMLEventObj_get_reason,
350 HTMLEventObj_get_clientX,
351 HTMLEventObj_get_clientY,
352 HTMLEventObj_get_offsetX,
353 HTMLEventObj_get_offsetY,
354 HTMLEventObj_get_screenX,
355 HTMLEventObj_get_screenY,
356 HTMLEventObj_get_srcFilter
359 static IHTMLEventObj *create_event(void)
363 ret = heap_alloc(sizeof(*ret));
364 ret->lpIHTMLEventObjVtbl = &HTMLEventObjVtbl;
367 return HTMLEVENTOBJ(ret);
370 void fire_event(HTMLDocument *doc, eventid_t eid, nsIDOMNode *target)
374 node = get_node(doc, target, FALSE);
378 if(node->event_target && node->event_target->event_table[eid]) {
379 doc->window->event = create_event();
381 call_disp_func(doc, node->event_target->event_table[eid]);
383 IHTMLEventObj_Release(doc->window->event);
384 doc->window->event = NULL;
388 void check_event_attr(HTMLDocument *doc, nsIDOMElement *nselem)
390 const PRUnichar *attr_value;
391 nsAString attr_name_str, attr_value_str;
397 nsAString_Init(&attr_value_str, NULL);
398 nsAString_Init(&attr_name_str, NULL);
400 for(i=0; i < EVENTID_LAST; i++) {
401 nsAString_SetData(&attr_name_str, event_info[i].attr_name);
402 nsres = nsIDOMElement_GetAttribute(nselem, &attr_name_str, &attr_value_str);
403 if(NS_SUCCEEDED(nsres)) {
404 nsAString_GetData(&attr_value_str, &attr_value);
408 TRACE("%p.%s = %s\n", nselem, debugstr_w(event_info[i].attr_name), debugstr_w(attr_value));
410 disp = script_parse_event(doc, attr_value);
412 node = get_node(doc, (nsIDOMNode*)nselem, TRUE);
413 if(!node->event_target)
414 node->event_target = heap_alloc_zero(sizeof(event_target_t));
415 node->event_target->event_table[i] = disp;
420 nsAString_Finish(&attr_value_str);
421 nsAString_Finish(&attr_name_str);
424 void release_event_target(event_target_t *event_target)
428 for(i=0; i < EVENTID_LAST; i++) {
429 if(event_target->event_table[i])
430 IDispatch_Release(event_target->event_table[i]);
433 heap_free(event_target);