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