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