mshtml: Added noscript tag handling tests.
[wine] / dlls / mshtml / htmlimg.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20 #include <assert.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28
29 #include "wine/debug.h"
30
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 typedef struct {
37     HTMLElement element;
38
39     IHTMLImgElement IHTMLImgElement_iface;
40
41     nsIDOMHTMLImageElement *nsimg;
42 } HTMLImgElement;
43
44 static inline HTMLImgElement *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
45 {
46     return CONTAINING_RECORD(iface, HTMLImgElement, IHTMLImgElement_iface);
47 }
48
49 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
50 {
51     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
52
53     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
54 }
55
56 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
57 {
58     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
59
60     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
61 }
62
63 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
64 {
65     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
66
67     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
68 }
69
70 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
71 {
72     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
73     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
74 }
75
76 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
77                                               LCID lcid, ITypeInfo **ppTInfo)
78 {
79     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
80     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
81             ppTInfo);
82 }
83
84 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
85                                                 LPOLESTR *rgszNames, UINT cNames,
86                                                 LCID lcid, DISPID *rgDispId)
87 {
88     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
89     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
90             cNames, lcid, rgDispId);
91 }
92
93 static HRESULT WINAPI HTMLImgElement_Invoke(IHTMLImgElement *iface, DISPID dispIdMember,
94                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 {
97     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
98     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
99             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 }
101
102 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
103 {
104     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
105     FIXME("(%p)->(%x)\n", This, v);
106     return E_NOTIMPL;
107 }
108
109 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
110 {
111     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
112     FIXME("(%p)->(%p)\n", This, p);
113     return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
117 {
118     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
119     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
120     return E_NOTIMPL;
121 }
122
123 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
124 {
125     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
126     FIXME("(%p)->(%p)\n", This, p);
127     return E_NOTIMPL;
128 }
129
130 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
131 {
132     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
133     FIXME("(%p)->(%p)\n", This, p);
134     return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
138 {
139     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
140     FIXME("(%p)->(%p)\n", This, p);
141     return E_NOTIMPL;
142 }
143
144 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
145 {
146     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
147     FIXME("(%p)->(%p)\n", This, p);
148     return E_NOTIMPL;
149 }
150
151 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
152 {
153     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
154     FIXME("(%p)->(%p)\n", This, p);
155     return E_NOTIMPL;
156 }
157
158 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
159 {
160     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
161     FIXME("(%p)->(%p)\n", This, p);
162     return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
166 {
167     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
168     FIXME("(%p)->(%p)\n", This, p);
169     return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
173 {
174     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
175     FIXME("(%p)->(%p)\n", This, p);
176     return E_NOTIMPL;
177 }
178
179 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
180 {
181     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
182     FIXME("(%p)->(%p)\n", This, p);
183     return E_NOTIMPL;
184 }
185
186 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
187 {
188     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
189     FIXME("(%p)->()\n", This);
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
194 {
195     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
196     FIXME("(%p)->(%p)\n", This, p);
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
201 {
202     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
203     FIXME("(%p)->(%d)\n", This, v);
204     return E_NOTIMPL;
205 }
206
207 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
208 {
209     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
210     FIXME("(%p)->(%p)\n", This, p);
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
215 {
216     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
217     FIXME("(%p)->(%d)\n", This, v);
218     return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
222 {
223     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
224     FIXME("(%p)->(%p)\n", This, p);
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
229 {
230     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
231     nsAString alt_str;
232     nsresult nsres;
233
234     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
235
236     nsAString_InitDepend(&alt_str, v);
237     nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
238     nsAString_Finish(&alt_str);
239     if(NS_FAILED(nsres))
240         ERR("SetAlt failed: %08x\n", nsres);
241
242     return S_OK;
243 }
244
245 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
246 {
247     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
248     nsAString alt_str;
249     nsresult nsres;
250
251     TRACE("(%p)->(%p)\n", This, p);
252
253     nsAString_Init(&alt_str, NULL);
254     nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
255     return return_nsstr(nsres, &alt_str, p);
256 }
257
258 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
259 {
260     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
261     nsAString src_str;
262     nsresult nsres;
263
264     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
265
266     nsAString_InitDepend(&src_str, v);
267     nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
268     nsAString_Finish(&src_str);
269     if(NS_FAILED(nsres))
270         ERR("SetSrc failed: %08x\n", nsres);
271
272     return NS_OK;
273 }
274
275 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
276 {
277     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
278     const PRUnichar *src;
279     nsAString src_str;
280     nsresult nsres;
281     HRESULT hres = S_OK;
282
283     static const WCHAR blockedW[] = {'B','L','O','C','K','E','D',':',':',0};
284
285     TRACE("(%p)->(%p)\n", This, p);
286
287     nsAString_Init(&src_str, NULL);
288     nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
289     if(NS_SUCCEEDED(nsres)) {
290         nsAString_GetData(&src_str, &src);
291
292         if(!strncmpiW(src, blockedW, sizeof(blockedW)/sizeof(WCHAR)-1)) {
293             TRACE("returning BLOCKED::\n");
294             *p = SysAllocString(blockedW);
295             if(!*p)
296                 hres = E_OUTOFMEMORY;
297         }else {
298             hres = nsuri_to_url(src, TRUE, p);
299         }
300     }else {
301         ERR("GetSrc failed: %08x\n", nsres);
302         hres = E_FAIL;
303     }
304
305     nsAString_Finish(&src_str);
306     return hres;
307 }
308
309 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
310 {
311     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
312     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
317 {
318     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
319     FIXME("(%p)->(%p)\n", This, p);
320     return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
324 {
325     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
326     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
327     return E_NOTIMPL;
328 }
329
330 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
331 {
332     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
333     FIXME("(%p)->(%p)\n", This, p);
334     return E_NOTIMPL;
335 }
336
337 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
338 {
339     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
340     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
341     return E_NOTIMPL;
342 }
343
344 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
345 {
346     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
347     FIXME("(%p)->(%p)\n", This, p);
348     return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
352 {
353     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
354     FIXME("(%p)->(%p)\n", This, p);
355     return E_NOTIMPL;
356 }
357
358 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
359 {
360     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
361     FIXME("(%p)->(%p)\n", This, p);
362     return E_NOTIMPL;
363 }
364
365 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
366 {
367     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
368     FIXME("(%p)->()\n", This);
369     return E_NOTIMPL;
370 }
371
372 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
373 {
374     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
375     FIXME("(%p)->(%p)\n", This, p);
376     return E_NOTIMPL;
377 }
378
379 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
380 {
381     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
382     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
383     return E_NOTIMPL;
384 }
385
386 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
387 {
388     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
389     FIXME("(%p)->(%p)\n", This, p);
390     return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
394 {
395     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
396
397     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
398
399     return set_node_event(&This->element.node, EVENTID_LOAD, &v);
400 }
401
402 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
403 {
404     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
405
406     TRACE("(%p)->(%p)\n", This, p);
407
408     return get_node_event(&This->element.node, EVENTID_LOAD, p);
409 }
410
411 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
412 {
413     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
414
415     TRACE("(%p)->()\n", This);
416
417     return set_node_event(&This->element.node, EVENTID_ERROR, &v);
418 }
419
420 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
421 {
422     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
423
424     TRACE("(%p)->(%p)\n", This, p);
425
426     return get_node_event(&This->element.node, EVENTID_ERROR, p);
427 }
428
429 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
430 {
431     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
432     FIXME("(%p)->()\n", This);
433     return E_NOTIMPL;
434 }
435
436 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
437 {
438     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
439     FIXME("(%p)->(%p)\n", This, p);
440     return E_NOTIMPL;
441 }
442
443 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
444 {
445     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
446     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
447     return E_NOTIMPL;
448 }
449
450 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
451 {
452     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
453     nsAString name;
454     nsresult nsres;
455
456     TRACE("(%p)->(%p)\n", This, p);
457
458     nsAString_Init(&name, NULL);
459     nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
460     return return_nsstr(nsres, &name, p);
461 }
462
463 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
464 {
465     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
466     nsresult nsres;
467
468     TRACE("(%p)->(%d)\n", This, v);
469
470     nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
471     if(NS_FAILED(nsres)) {
472         ERR("SetWidth failed: %08x\n", nsres);
473         return E_FAIL;
474     }
475
476     return S_OK;
477 }
478
479 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
480 {
481     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
482     PRUint32 width;
483     nsresult nsres;
484
485     TRACE("(%p)->(%p)\n", This, p);
486
487     nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
488     if(NS_FAILED(nsres)) {
489         ERR("GetWidth failed: %08x\n", nsres);
490         return E_FAIL;
491     }
492
493     *p = width;
494     return S_OK;
495 }
496
497 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
498 {
499     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
500     nsresult nsres;
501
502     TRACE("(%p)->(%d)\n", This, v);
503
504     nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
505     if(NS_FAILED(nsres)) {
506         ERR("SetHeight failed: %08x\n", nsres);
507         return E_FAIL;
508     }
509
510     return S_OK;
511 }
512
513 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
514 {
515     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
516     PRUint32 height;
517     nsresult nsres;
518
519     TRACE("(%p)->(%p)\n", This, p);
520
521     nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
522     if(NS_FAILED(nsres)) {
523         ERR("GetHeight failed: %08x\n", nsres);
524         return E_FAIL;
525     }
526
527     *p = height;
528     return S_OK;
529 }
530
531 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
532 {
533     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
534     FIXME("(%p)->()\n", This);
535     return E_NOTIMPL;
536 }
537
538 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
539 {
540     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
541     FIXME("(%p)->(%p)\n", This, p);
542     return E_NOTIMPL;
543 }
544
545 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
546     HTMLImgElement_QueryInterface,
547     HTMLImgElement_AddRef,
548     HTMLImgElement_Release,
549     HTMLImgElement_GetTypeInfoCount,
550     HTMLImgElement_GetTypeInfo,
551     HTMLImgElement_GetIDsOfNames,
552     HTMLImgElement_Invoke,
553     HTMLImgElement_put_isMap,
554     HTMLImgElement_get_isMap,
555     HTMLImgElement_put_useMap,
556     HTMLImgElement_get_useMap,
557     HTMLImgElement_get_mimeType,
558     HTMLImgElement_get_fileSize,
559     HTMLImgElement_get_fileCreatedDate,
560     HTMLImgElement_get_fileModifiedDate,
561     HTMLImgElement_get_fileUpdatedDate,
562     HTMLImgElement_get_protocol,
563     HTMLImgElement_get_href,
564     HTMLImgElement_get_nameProp,
565     HTMLImgElement_put_border,
566     HTMLImgElement_get_border,
567     HTMLImgElement_put_vspace,
568     HTMLImgElement_get_vspace,
569     HTMLImgElement_put_hspace,
570     HTMLImgElement_get_hspace,
571     HTMLImgElement_put_alt,
572     HTMLImgElement_get_alt,
573     HTMLImgElement_put_src,
574     HTMLImgElement_get_src,
575     HTMLImgElement_put_lowsrc,
576     HTMLImgElement_get_lowsrc,
577     HTMLImgElement_put_vrml,
578     HTMLImgElement_get_vrml,
579     HTMLImgElement_put_dynsrc,
580     HTMLImgElement_get_dynsrc,
581     HTMLImgElement_get_readyState,
582     HTMLImgElement_get_complete,
583     HTMLImgElement_put_loop,
584     HTMLImgElement_get_loop,
585     HTMLImgElement_put_align,
586     HTMLImgElement_get_align,
587     HTMLImgElement_put_onload,
588     HTMLImgElement_get_onload,
589     HTMLImgElement_put_onerror,
590     HTMLImgElement_get_onerror,
591     HTMLImgElement_put_onabort,
592     HTMLImgElement_get_onabort,
593     HTMLImgElement_put_name,
594     HTMLImgElement_get_name,
595     HTMLImgElement_put_width,
596     HTMLImgElement_get_width,
597     HTMLImgElement_put_height,
598     HTMLImgElement_get_height,
599     HTMLImgElement_put_start,
600     HTMLImgElement_get_start
601 };
602
603 static inline HTMLImgElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
604 {
605     return CONTAINING_RECORD(iface, HTMLImgElement, element.node);
606 }
607
608 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
609 {
610     HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
611
612     *ppv = NULL;
613
614     if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
615         TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
616         *ppv = &This->IHTMLImgElement_iface;
617     }else {
618         return HTMLElement_QI(&This->element.node, riid, ppv);
619     }
620
621     IUnknown_AddRef((IUnknown*)*ppv);
622     return S_OK;
623 }
624
625 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
626 {
627     HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
628
629     return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
630 }
631
632 static const NodeImplVtbl HTMLImgElementImplVtbl = {
633     HTMLImgElement_QI,
634     HTMLElement_destructor,
635     HTMLElement_clone,
636     HTMLElement_handle_event,
637     HTMLElement_get_attr_col,
638     NULL,
639     NULL,
640     NULL,
641     NULL,
642     NULL,
643     HTMLImgElement_get_readystate
644 };
645
646 static const tid_t HTMLImgElement_iface_tids[] = {
647     HTMLELEMENT_TIDS,
648     IHTMLImgElement_tid,
649     0
650 };
651 static dispex_static_data_t HTMLImgElement_dispex = {
652     NULL,
653     DispHTMLImg_tid,
654     NULL,
655     HTMLImgElement_iface_tids
656 };
657
658 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
659 {
660     HTMLImgElement *ret;
661     nsresult nsres;
662
663     ret = heap_alloc_zero(sizeof(HTMLImgElement));
664     if(!ret)
665         return E_OUTOFMEMORY;
666
667     ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
668     ret->element.node.vtbl = &HTMLImgElementImplVtbl;
669
670     HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
671
672     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
673
674     /* Share nsimg reference with nsnode */
675     assert(nsres == NS_OK && (nsIDOMNode*)ret->nsimg == ret->element.node.nsnode);
676     nsIDOMNode_Release(ret->element.node.nsnode);
677
678     *elem = &ret->element;
679     return S_OK;
680 }
681
682 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
683 {
684     return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
685 }
686
687 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
688         REFIID riid, void **ppv)
689 {
690     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
691
692     *ppv = NULL;
693
694     if(IsEqualGUID(&IID_IUnknown, riid)) {
695         TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
696         *ppv = &This->IHTMLImageElementFactory_iface;
697     }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
698         TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
699         *ppv = &This->IHTMLImageElementFactory_iface;
700     }else if(dispex_query_interface(&This->dispex, riid, ppv))
701         return *ppv ? S_OK : E_NOINTERFACE;
702
703     if(*ppv) {
704         IUnknown_AddRef((IUnknown*)*ppv);
705         return S_OK;
706     }
707
708     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
709     return E_NOINTERFACE;
710 }
711
712 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
713 {
714     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
715     LONG ref = InterlockedIncrement(&This->ref);
716
717     TRACE("(%p) ref=%d\n", This, ref);
718
719     return ref;
720 }
721
722 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
723 {
724     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
725     LONG ref = InterlockedDecrement(&This->ref);
726
727     TRACE("(%p) ref=%d\n", This, ref);
728
729     if(!ref)
730         heap_free(This);
731
732     return ref;
733 }
734
735 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
736         UINT *pctinfo)
737 {
738     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
739     FIXME("(%p)->(%p)\n", This, pctinfo);
740     return E_NOTIMPL;
741 }
742
743 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
744         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
745 {
746     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
747     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
748     return E_NOTIMPL;
749 }
750
751 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
752         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
753         DISPID *rgDispId)
754 {
755     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
756     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
757             cNames, lcid, rgDispId);
758     return E_NOTIMPL;
759 }
760
761 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
762         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
763         DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
764         UINT *puArgErr)
765 {
766     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
767     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
768             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
769     return E_NOTIMPL;
770 }
771
772 static LONG var_to_size(const VARIANT *v)
773 {
774     switch(V_VT(v)) {
775     case VT_EMPTY:
776         return 0;
777     case VT_I4:
778         return V_I4(v);
779     case VT_BSTR: {
780         LONG ret;
781         HRESULT hres;
782
783         hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
784         if(FAILED(hres)) {
785             FIXME("VarI4FromStr failed: %08x\n", hres);
786             return 0;
787         }
788         return ret;
789     }
790     default:
791         FIXME("unsupported size %s\n", debugstr_variant(v));
792     }
793     return 0;
794 }
795
796 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
797         VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
798 {
799     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
800     HTMLDocumentNode *doc;
801     IHTMLImgElement *img;
802     HTMLElement *elem;
803     nsIDOMHTMLElement *nselem;
804     LONG l;
805     HRESULT hres;
806
807     static const PRUnichar imgW[] = {'I','M','G',0};
808
809     TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
810             debugstr_variant(&height), img_elem);
811
812     if(!This->window || !This->window->doc) {
813         WARN("NULL doc\n");
814         return E_UNEXPECTED;
815     }
816
817     doc = This->window->doc;
818
819     *img_elem = NULL;
820
821     hres = create_nselem(doc, imgW, &nselem);
822     if(FAILED(hres))
823         return hres;
824
825     hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
826     nsIDOMHTMLElement_Release(nselem);
827     if(FAILED(hres)) {
828         ERR("HTMLElement_Create failed\n");
829         return hres;
830     }
831
832     hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
833             (void**)&img);
834     IHTMLElement_Release(&elem->IHTMLElement_iface);
835     if(FAILED(hres)) {
836         ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
837         return hres;
838     }
839
840     l = var_to_size(&width);
841     if(l)
842         IHTMLImgElement_put_width(img, l);
843     l = var_to_size(&height);
844     if(l)
845         IHTMLImgElement_put_height(img, l);
846
847     *img_elem = img;
848     return S_OK;
849 }
850
851 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
852     HTMLImageElementFactory_QueryInterface,
853     HTMLImageElementFactory_AddRef,
854     HTMLImageElementFactory_Release,
855     HTMLImageElementFactory_GetTypeInfoCount,
856     HTMLImageElementFactory_GetTypeInfo,
857     HTMLImageElementFactory_GetIDsOfNames,
858     HTMLImageElementFactory_Invoke,
859     HTMLImageElementFactory_create
860 };
861
862 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
863 {
864     return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
865 }
866
867 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
868         WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
869         IServiceProvider *caller)
870 {
871     HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
872     IHTMLImgElement *img;
873     VARIANT empty, *width, *height;
874     HRESULT hres;
875     int argc = params->cArgs - params->cNamedArgs;
876
877     V_VT(res) = VT_NULL;
878
879     V_VT(&empty) = VT_EMPTY;
880
881     width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
882     height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
883
884     hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
885             &img);
886     if(FAILED(hres))
887         return hres;
888
889     V_VT(res) = VT_DISPATCH;
890     V_DISPATCH(res) = (IDispatch*)img;
891
892     return S_OK;
893 }
894
895 static const tid_t HTMLImageElementFactory_iface_tids[] = {
896     IHTMLImageElementFactory_tid,
897     0
898 };
899
900 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
901     HTMLImageElementFactory_value,
902     NULL,
903     NULL,
904     NULL
905 };
906
907 static dispex_static_data_t HTMLImageElementFactory_dispex = {
908     &HTMLImageElementFactory_dispex_vtbl,
909     IHTMLImageElementFactory_tid,
910     NULL,
911     HTMLImageElementFactory_iface_tids
912 };
913
914 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
915 {
916     HTMLImageElementFactory *ret;
917
918     ret = heap_alloc(sizeof(HTMLImageElementFactory));
919     if(!ret)
920         return E_OUTOFMEMORY;
921
922     ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
923     ret->ref = 1;
924     ret->window = window;
925
926     init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
927             &HTMLImageElementFactory_dispex);
928
929     *ret_val = ret;
930     return S_OK;
931 }