atl80: Added AtlComModuleRegisterServer implementation (based on AtlModuleRegisterSer...
[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     cpp_bool complete;
362     nsresult nsres;
363
364     TRACE("(%p)->(%p)\n", This, p);
365
366     nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
367     if(NS_FAILED(nsres)) {
368         ERR("GetComplete failed: %08x\n", nsres);
369         return E_FAIL;
370     }
371
372     *p = complete ? VARIANT_TRUE : VARIANT_FALSE;
373     return S_OK;
374 }
375
376 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
377 {
378     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
379     FIXME("(%p)->()\n", This);
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
384 {
385     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
386     FIXME("(%p)->(%p)\n", This, p);
387     return E_NOTIMPL;
388 }
389
390 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
391 {
392     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
393     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
394     return E_NOTIMPL;
395 }
396
397 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
398 {
399     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
400     FIXME("(%p)->(%p)\n", This, p);
401     return E_NOTIMPL;
402 }
403
404 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
405 {
406     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
407
408     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
409
410     return set_node_event(&This->element.node, EVENTID_LOAD, &v);
411 }
412
413 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
414 {
415     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
416
417     TRACE("(%p)->(%p)\n", This, p);
418
419     return get_node_event(&This->element.node, EVENTID_LOAD, p);
420 }
421
422 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
423 {
424     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
425
426     TRACE("(%p)->()\n", This);
427
428     return set_node_event(&This->element.node, EVENTID_ERROR, &v);
429 }
430
431 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
432 {
433     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
434
435     TRACE("(%p)->(%p)\n", This, p);
436
437     return get_node_event(&This->element.node, EVENTID_ERROR, p);
438 }
439
440 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
441 {
442     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
443
444     TRACE("(%p)->()\n", This);
445
446     return set_node_event(&This->element.node, EVENTID_ABORT, &v);
447 }
448
449 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
450 {
451     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
452
453     TRACE("(%p)->(%p)\n", This, p);
454
455     return get_node_event(&This->element.node, EVENTID_ABORT, p);
456 }
457
458 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
459 {
460     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
461     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
462     return E_NOTIMPL;
463 }
464
465 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
466 {
467     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
468     nsAString name;
469     nsresult nsres;
470
471     TRACE("(%p)->(%p)\n", This, p);
472
473     nsAString_Init(&name, NULL);
474     nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
475     return return_nsstr(nsres, &name, p);
476 }
477
478 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
479 {
480     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
481     nsresult nsres;
482
483     TRACE("(%p)->(%d)\n", This, v);
484
485     nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
486     if(NS_FAILED(nsres)) {
487         ERR("SetWidth failed: %08x\n", nsres);
488         return E_FAIL;
489     }
490
491     return S_OK;
492 }
493
494 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
495 {
496     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
497     PRUint32 width;
498     nsresult nsres;
499
500     TRACE("(%p)->(%p)\n", This, p);
501
502     nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
503     if(NS_FAILED(nsres)) {
504         ERR("GetWidth failed: %08x\n", nsres);
505         return E_FAIL;
506     }
507
508     *p = width;
509     return S_OK;
510 }
511
512 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
513 {
514     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
515     nsresult nsres;
516
517     TRACE("(%p)->(%d)\n", This, v);
518
519     nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
520     if(NS_FAILED(nsres)) {
521         ERR("SetHeight failed: %08x\n", nsres);
522         return E_FAIL;
523     }
524
525     return S_OK;
526 }
527
528 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
529 {
530     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
531     PRUint32 height;
532     nsresult nsres;
533
534     TRACE("(%p)->(%p)\n", This, p);
535
536     nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
537     if(NS_FAILED(nsres)) {
538         ERR("GetHeight failed: %08x\n", nsres);
539         return E_FAIL;
540     }
541
542     *p = height;
543     return S_OK;
544 }
545
546 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
547 {
548     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
549     FIXME("(%p)->()\n", This);
550     return E_NOTIMPL;
551 }
552
553 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
554 {
555     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
556     FIXME("(%p)->(%p)\n", This, p);
557     return E_NOTIMPL;
558 }
559
560 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
561     HTMLImgElement_QueryInterface,
562     HTMLImgElement_AddRef,
563     HTMLImgElement_Release,
564     HTMLImgElement_GetTypeInfoCount,
565     HTMLImgElement_GetTypeInfo,
566     HTMLImgElement_GetIDsOfNames,
567     HTMLImgElement_Invoke,
568     HTMLImgElement_put_isMap,
569     HTMLImgElement_get_isMap,
570     HTMLImgElement_put_useMap,
571     HTMLImgElement_get_useMap,
572     HTMLImgElement_get_mimeType,
573     HTMLImgElement_get_fileSize,
574     HTMLImgElement_get_fileCreatedDate,
575     HTMLImgElement_get_fileModifiedDate,
576     HTMLImgElement_get_fileUpdatedDate,
577     HTMLImgElement_get_protocol,
578     HTMLImgElement_get_href,
579     HTMLImgElement_get_nameProp,
580     HTMLImgElement_put_border,
581     HTMLImgElement_get_border,
582     HTMLImgElement_put_vspace,
583     HTMLImgElement_get_vspace,
584     HTMLImgElement_put_hspace,
585     HTMLImgElement_get_hspace,
586     HTMLImgElement_put_alt,
587     HTMLImgElement_get_alt,
588     HTMLImgElement_put_src,
589     HTMLImgElement_get_src,
590     HTMLImgElement_put_lowsrc,
591     HTMLImgElement_get_lowsrc,
592     HTMLImgElement_put_vrml,
593     HTMLImgElement_get_vrml,
594     HTMLImgElement_put_dynsrc,
595     HTMLImgElement_get_dynsrc,
596     HTMLImgElement_get_readyState,
597     HTMLImgElement_get_complete,
598     HTMLImgElement_put_loop,
599     HTMLImgElement_get_loop,
600     HTMLImgElement_put_align,
601     HTMLImgElement_get_align,
602     HTMLImgElement_put_onload,
603     HTMLImgElement_get_onload,
604     HTMLImgElement_put_onerror,
605     HTMLImgElement_get_onerror,
606     HTMLImgElement_put_onabort,
607     HTMLImgElement_get_onabort,
608     HTMLImgElement_put_name,
609     HTMLImgElement_get_name,
610     HTMLImgElement_put_width,
611     HTMLImgElement_get_width,
612     HTMLImgElement_put_height,
613     HTMLImgElement_get_height,
614     HTMLImgElement_put_start,
615     HTMLImgElement_get_start
616 };
617
618 static inline HTMLImgElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
619 {
620     return CONTAINING_RECORD(iface, HTMLImgElement, element.node);
621 }
622
623 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
624 {
625     HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
626
627     *ppv = NULL;
628
629     if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
630         TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
631         *ppv = &This->IHTMLImgElement_iface;
632     }else {
633         return HTMLElement_QI(&This->element.node, riid, ppv);
634     }
635
636     IUnknown_AddRef((IUnknown*)*ppv);
637     return S_OK;
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     HTMLElement_destructor,
650     HTMLElement_clone,
651     HTMLElement_handle_event,
652     HTMLElement_get_attr_col,
653     NULL,
654     NULL,
655     NULL,
656     NULL,
657     NULL,
658     HTMLImgElement_get_readystate
659 };
660
661 static const tid_t HTMLImgElement_iface_tids[] = {
662     HTMLELEMENT_TIDS,
663     IHTMLImgElement_tid,
664     0
665 };
666 static dispex_static_data_t HTMLImgElement_dispex = {
667     NULL,
668     DispHTMLImg_tid,
669     NULL,
670     HTMLImgElement_iface_tids
671 };
672
673 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
674 {
675     HTMLImgElement *ret;
676     nsresult nsres;
677
678     ret = heap_alloc_zero(sizeof(HTMLImgElement));
679     if(!ret)
680         return E_OUTOFMEMORY;
681
682     ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
683     ret->element.node.vtbl = &HTMLImgElementImplVtbl;
684
685     HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
686
687     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
688
689     /* Share nsimg reference with nsnode */
690     assert(nsres == NS_OK && (nsIDOMNode*)ret->nsimg == ret->element.node.nsnode);
691     nsIDOMNode_Release(ret->element.node.nsnode);
692
693     *elem = &ret->element;
694     return S_OK;
695 }
696
697 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
698 {
699     return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
700 }
701
702 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
703         REFIID riid, void **ppv)
704 {
705     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
706
707     *ppv = NULL;
708
709     if(IsEqualGUID(&IID_IUnknown, riid)) {
710         TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
711         *ppv = &This->IHTMLImageElementFactory_iface;
712     }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
713         TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
714         *ppv = &This->IHTMLImageElementFactory_iface;
715     }else if(dispex_query_interface(&This->dispex, riid, ppv))
716         return *ppv ? S_OK : E_NOINTERFACE;
717
718     if(*ppv) {
719         IUnknown_AddRef((IUnknown*)*ppv);
720         return S_OK;
721     }
722
723     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
724     return E_NOINTERFACE;
725 }
726
727 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
728 {
729     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
730     LONG ref = InterlockedIncrement(&This->ref);
731
732     TRACE("(%p) ref=%d\n", This, ref);
733
734     return ref;
735 }
736
737 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
738 {
739     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
740     LONG ref = InterlockedDecrement(&This->ref);
741
742     TRACE("(%p) ref=%d\n", This, ref);
743
744     if(!ref)
745         heap_free(This);
746
747     return ref;
748 }
749
750 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
751         UINT *pctinfo)
752 {
753     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
754     FIXME("(%p)->(%p)\n", This, pctinfo);
755     return E_NOTIMPL;
756 }
757
758 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
759         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
760 {
761     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
762     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
763     return E_NOTIMPL;
764 }
765
766 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
767         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
768         DISPID *rgDispId)
769 {
770     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
771     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
772             cNames, lcid, rgDispId);
773     return E_NOTIMPL;
774 }
775
776 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
777         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
778         DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
779         UINT *puArgErr)
780 {
781     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
782     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
783             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
784     return E_NOTIMPL;
785 }
786
787 static LONG var_to_size(const VARIANT *v)
788 {
789     switch(V_VT(v)) {
790     case VT_EMPTY:
791         return 0;
792     case VT_I4:
793         return V_I4(v);
794     case VT_BSTR: {
795         LONG ret;
796         HRESULT hres;
797
798         hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
799         if(FAILED(hres)) {
800             FIXME("VarI4FromStr failed: %08x\n", hres);
801             return 0;
802         }
803         return ret;
804     }
805     default:
806         FIXME("unsupported size %s\n", debugstr_variant(v));
807     }
808     return 0;
809 }
810
811 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
812         VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
813 {
814     HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
815     HTMLDocumentNode *doc;
816     IHTMLImgElement *img;
817     HTMLElement *elem;
818     nsIDOMHTMLElement *nselem;
819     LONG l;
820     HRESULT hres;
821
822     static const PRUnichar imgW[] = {'I','M','G',0};
823
824     TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
825             debugstr_variant(&height), img_elem);
826
827     if(!This->window || !This->window->doc) {
828         WARN("NULL doc\n");
829         return E_UNEXPECTED;
830     }
831
832     doc = This->window->doc;
833
834     *img_elem = NULL;
835
836     hres = create_nselem(doc, imgW, &nselem);
837     if(FAILED(hres))
838         return hres;
839
840     hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
841     nsIDOMHTMLElement_Release(nselem);
842     if(FAILED(hres)) {
843         ERR("HTMLElement_Create failed\n");
844         return hres;
845     }
846
847     hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
848             (void**)&img);
849     IHTMLElement_Release(&elem->IHTMLElement_iface);
850     if(FAILED(hres)) {
851         ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
852         return hres;
853     }
854
855     l = var_to_size(&width);
856     if(l)
857         IHTMLImgElement_put_width(img, l);
858     l = var_to_size(&height);
859     if(l)
860         IHTMLImgElement_put_height(img, l);
861
862     *img_elem = img;
863     return S_OK;
864 }
865
866 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
867     HTMLImageElementFactory_QueryInterface,
868     HTMLImageElementFactory_AddRef,
869     HTMLImageElementFactory_Release,
870     HTMLImageElementFactory_GetTypeInfoCount,
871     HTMLImageElementFactory_GetTypeInfo,
872     HTMLImageElementFactory_GetIDsOfNames,
873     HTMLImageElementFactory_Invoke,
874     HTMLImageElementFactory_create
875 };
876
877 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
878 {
879     return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
880 }
881
882 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
883         WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
884         IServiceProvider *caller)
885 {
886     HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
887     IHTMLImgElement *img;
888     VARIANT empty, *width, *height;
889     HRESULT hres;
890     int argc = params->cArgs - params->cNamedArgs;
891
892     V_VT(res) = VT_NULL;
893
894     V_VT(&empty) = VT_EMPTY;
895
896     width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
897     height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
898
899     hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
900             &img);
901     if(FAILED(hres))
902         return hres;
903
904     V_VT(res) = VT_DISPATCH;
905     V_DISPATCH(res) = (IDispatch*)img;
906
907     return S_OK;
908 }
909
910 static const tid_t HTMLImageElementFactory_iface_tids[] = {
911     IHTMLImageElementFactory_tid,
912     0
913 };
914
915 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
916     HTMLImageElementFactory_value,
917     NULL,
918     NULL,
919     NULL
920 };
921
922 static dispex_static_data_t HTMLImageElementFactory_dispex = {
923     &HTMLImageElementFactory_dispex_vtbl,
924     IHTMLImageElementFactory_tid,
925     NULL,
926     HTMLImageElementFactory_iface_tids
927 };
928
929 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
930 {
931     HTMLImageElementFactory *ret;
932
933     ret = heap_alloc(sizeof(HTMLImageElementFactory));
934     if(!ret)
935         return E_OUTOFMEMORY;
936
937     ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
938     ret->ref = 1;
939     ret->window = window;
940
941     init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
942             &HTMLImageElementFactory_dispex);
943
944     *ret_val = ret;
945     return S_OK;
946 }