d3dx9/tests: Implemented CloneMesh test.
[wine/multimedia.git] / dlls / mshtml / htmlimg.c
blob0e8a60478230fad5fa7e4b3425b9f30e6960d2ed
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 HTMLElement element;
38 IHTMLImgElement IHTMLImgElement_iface;
40 nsIDOMHTMLImageElement *nsimg;
41 } HTMLImgElement;
43 static inline HTMLImgElement *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
45 return CONTAINING_RECORD(iface, HTMLImgElement, IHTMLImgElement_iface);
48 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
50 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
52 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
57 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
64 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
66 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
71 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
79 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
80 ppTInfo);
83 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
88 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
89 cNames, lcid, rgDispId);
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)
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);
101 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
103 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
104 FIXME("(%p)->(%x)\n", This, v);
105 return E_NOTIMPL;
108 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
110 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
111 FIXME("(%p)->(%p)\n", This, p);
112 return E_NOTIMPL;
115 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
117 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
118 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
119 return E_NOTIMPL;
122 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
124 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
125 FIXME("(%p)->(%p)\n", This, p);
126 return E_NOTIMPL;
129 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
131 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
132 FIXME("(%p)->(%p)\n", This, p);
133 return E_NOTIMPL;
136 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
138 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
139 FIXME("(%p)->(%p)\n", This, p);
140 return E_NOTIMPL;
143 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
145 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
146 FIXME("(%p)->(%p)\n", This, p);
147 return E_NOTIMPL;
150 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
152 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
153 FIXME("(%p)->(%p)\n", This, p);
154 return E_NOTIMPL;
157 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
159 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
160 FIXME("(%p)->(%p)\n", This, p);
161 return E_NOTIMPL;
164 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
166 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
167 FIXME("(%p)->(%p)\n", This, p);
168 return E_NOTIMPL;
171 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
173 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
174 FIXME("(%p)->(%p)\n", This, p);
175 return E_NOTIMPL;
178 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
180 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
181 FIXME("(%p)->(%p)\n", This, p);
182 return E_NOTIMPL;
185 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
187 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
188 FIXME("(%p)->()\n", This);
189 return E_NOTIMPL;
192 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
194 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
195 FIXME("(%p)->(%p)\n", This, p);
196 return E_NOTIMPL;
199 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
201 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
202 FIXME("(%p)->(%d)\n", This, v);
203 return E_NOTIMPL;
206 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
208 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
209 FIXME("(%p)->(%p)\n", This, p);
210 return E_NOTIMPL;
213 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
215 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
216 FIXME("(%p)->(%d)\n", This, v);
217 return E_NOTIMPL;
220 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
222 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
223 FIXME("(%p)->(%p)\n", This, p);
224 return E_NOTIMPL;
227 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
229 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
230 nsAString alt_str;
231 nsresult nsres;
233 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
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);
241 return S_OK;
244 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
246 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
247 nsAString alt_str;
248 nsresult nsres;
250 TRACE("(%p)->(%p)\n", This, p);
252 nsAString_Init(&alt_str, NULL);
253 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
254 if(NS_SUCCEEDED(nsres)) {
255 const PRUnichar *alt;
257 nsAString_GetData(&alt_str, &alt);
258 *p = *alt ? SysAllocString(alt) : NULL;
259 }else {
260 ERR("GetAlt failed: %08x\n", nsres);
262 nsAString_Finish(&alt_str);
264 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
267 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
269 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
270 nsAString src_str;
271 nsresult nsres;
273 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
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);
281 return NS_OK;
284 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
286 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
287 const PRUnichar *src;
288 nsAString src_str;
289 nsresult nsres;
290 HRESULT hres = S_OK;
292 static const WCHAR blockedW[] = {'B','L','O','C','K','E','D',':',':',0};
294 TRACE("(%p)->(%p)\n", This, p);
296 nsAString_Init(&src_str, NULL);
297 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
298 if(NS_SUCCEEDED(nsres)) {
299 nsAString_GetData(&src_str, &src);
301 if(!strncmpiW(src, blockedW, sizeof(blockedW)/sizeof(WCHAR)-1)) {
302 TRACE("returning BLOCKED::\n");
303 *p = SysAllocString(blockedW);
304 if(!*p)
305 hres = E_OUTOFMEMORY;
306 }else {
307 hres = nsuri_to_url(src, TRUE, p);
309 }else {
310 ERR("GetSrc failed: %08x\n", nsres);
311 hres = E_FAIL;
314 nsAString_Finish(&src_str);
315 return hres;
318 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
320 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
321 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
322 return E_NOTIMPL;
325 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
327 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
328 FIXME("(%p)->(%p)\n", This, p);
329 return E_NOTIMPL;
332 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
334 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
335 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
341 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
346 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
348 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
349 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
350 return E_NOTIMPL;
353 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
355 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
356 FIXME("(%p)->(%p)\n", This, p);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
362 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
363 FIXME("(%p)->(%p)\n", This, p);
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
369 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
370 FIXME("(%p)->(%p)\n", This, p);
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
376 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
377 FIXME("(%p)->()\n", This);
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
383 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
384 FIXME("(%p)->(%p)\n", This, p);
385 return E_NOTIMPL;
388 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
390 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
391 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
392 return E_NOTIMPL;
395 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
397 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
398 FIXME("(%p)->(%p)\n", This, p);
399 return E_NOTIMPL;
402 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
404 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
406 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
408 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
411 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
413 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
415 TRACE("(%p)->(%p)\n", This, p);
417 return get_node_event(&This->element.node, EVENTID_LOAD, p);
420 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
422 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
423 FIXME("(%p)->()\n", This);
424 return E_NOTIMPL;
427 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
429 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
430 FIXME("(%p)->(%p)\n", This, p);
431 return E_NOTIMPL;
434 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
436 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
437 FIXME("(%p)->()\n", This);
438 return E_NOTIMPL;
441 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
443 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
444 FIXME("(%p)->(%p)\n", This, p);
445 return E_NOTIMPL;
448 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
450 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
451 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
452 return E_NOTIMPL;
455 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
457 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
458 nsAString strName;
459 nsresult nsres;
461 TRACE("(%p)->(%p)\n", This, p);
463 nsAString_Init(&strName, NULL);
464 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &strName);
465 if(NS_SUCCEEDED(nsres)) {
466 const PRUnichar *str;
468 nsAString_GetData(&strName, &str);
469 *p = *str ? SysAllocString(str) : NULL;
470 }else {
471 ERR("GetName failed: %08x\n", nsres);
473 nsAString_Finish(&strName);
475 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
478 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
480 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
481 nsresult nsres;
483 TRACE("(%p)->(%d)\n", This, v);
485 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
486 if(NS_FAILED(nsres)) {
487 ERR("SetWidth failed: %08x\n", nsres);
488 return E_FAIL;
491 return S_OK;
494 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
496 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
497 PRInt32 width;
498 nsresult nsres;
500 TRACE("(%p)->(%p)\n", This, p);
502 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
503 if(NS_FAILED(nsres)) {
504 ERR("GetWidth failed: %08x\n", nsres);
505 return E_FAIL;
508 *p = width;
509 return S_OK;
512 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
514 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
515 nsresult nsres;
517 TRACE("(%p)->(%d)\n", This, v);
519 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
520 if(NS_FAILED(nsres)) {
521 ERR("SetHeight failed: %08x\n", nsres);
522 return E_FAIL;
525 return S_OK;
528 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
530 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
531 PRInt32 height;
532 nsresult nsres;
534 TRACE("(%p)->(%p)\n", This, p);
536 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
537 if(NS_FAILED(nsres)) {
538 ERR("GetHeight failed: %08x\n", nsres);
539 return E_FAIL;
542 *p = height;
543 return S_OK;
546 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
548 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
549 FIXME("(%p)->()\n", This);
550 return E_NOTIMPL;
553 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
555 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
556 FIXME("(%p)->(%p)\n", This, p);
557 return E_NOTIMPL;
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
618 static inline HTMLImgElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
620 return CONTAINING_RECORD(iface, HTMLImgElement, element.node);
623 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
625 HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
627 *ppv = NULL;
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);
636 IUnknown_AddRef((IUnknown*)*ppv);
637 return S_OK;
640 static void HTMLImgElement_destructor(HTMLDOMNode *iface)
642 HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
644 if(This->nsimg)
645 nsIDOMHTMLImageElement_Release(This->nsimg);
647 HTMLElement_destructor(&This->element.node);
650 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
652 HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
654 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
657 static const NodeImplVtbl HTMLImgElementImplVtbl = {
658 HTMLImgElement_QI,
659 HTMLImgElement_destructor,
660 HTMLElement_clone,
661 HTMLElement_get_attr_col,
662 NULL,
663 NULL,
664 NULL,
665 NULL,
666 NULL,
667 NULL,
668 HTMLImgElement_get_readystate
671 static const tid_t HTMLImgElement_iface_tids[] = {
672 HTMLELEMENT_TIDS,
673 IHTMLImgElement_tid,
676 static dispex_static_data_t HTMLImgElement_dispex = {
677 NULL,
678 DispHTMLImg_tid,
679 NULL,
680 HTMLImgElement_iface_tids
683 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
685 HTMLImgElement *ret;
686 nsresult nsres;
688 ret = heap_alloc_zero(sizeof(HTMLImgElement));
689 if(!ret)
690 return E_OUTOFMEMORY;
692 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
693 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
695 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
696 if(NS_FAILED(nsres)) {
697 ERR("Could not get nsIDOMHTMLImageElement: %08x\n", nsres);
698 heap_free(ret);
699 return E_FAIL;
702 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
704 *elem = &ret->element;
705 return S_OK;
708 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
710 return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
713 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
714 REFIID riid, void **ppv)
716 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
718 *ppv = NULL;
720 if(IsEqualGUID(&IID_IUnknown, riid)) {
721 TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
722 *ppv = &This->IHTMLImageElementFactory_iface;
723 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
724 TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
725 *ppv = &This->IHTMLImageElementFactory_iface;
726 }else if(dispex_query_interface(&This->dispex, riid, ppv))
727 return *ppv ? S_OK : E_NOINTERFACE;
729 if(*ppv) {
730 IUnknown_AddRef((IUnknown*)*ppv);
731 return S_OK;
734 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
735 return E_NOINTERFACE;
738 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
740 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
741 LONG ref = InterlockedIncrement(&This->ref);
743 TRACE("(%p) ref=%d\n", This, ref);
745 return ref;
748 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
750 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
751 LONG ref = InterlockedDecrement(&This->ref);
753 TRACE("(%p) ref=%d\n", This, ref);
755 if(!ref)
756 heap_free(This);
758 return ref;
761 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
762 UINT *pctinfo)
764 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
765 FIXME("(%p)->(%p)\n", This, pctinfo);
766 return E_NOTIMPL;
769 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
770 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
772 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
773 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
774 return E_NOTIMPL;
777 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
778 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
779 DISPID *rgDispId)
781 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
782 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
783 cNames, lcid, rgDispId);
784 return E_NOTIMPL;
787 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
788 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
789 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
790 UINT *puArgErr)
792 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
793 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
794 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
795 return E_NOTIMPL;
798 static LONG var_to_size(const VARIANT *v)
800 switch(V_VT(v)) {
801 case VT_EMPTY:
802 return 0;
803 case VT_I4:
804 return V_I4(v);
805 case VT_BSTR: {
806 LONG ret;
807 HRESULT hres;
809 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
810 if(FAILED(hres)) {
811 FIXME("VarI4FromStr failed: %08x\n", hres);
812 return 0;
814 return ret;
816 default:
817 FIXME("unsupported size %s\n", debugstr_variant(v));
819 return 0;
822 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
823 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
825 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
826 IHTMLImgElement *img;
827 HTMLElement *elem;
828 nsIDOMHTMLElement *nselem;
829 LONG l;
830 HRESULT hres;
832 static const PRUnichar imgW[] = {'I','M','G',0};
834 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
835 debugstr_variant(&height), img_elem);
837 if(!This->window || !This->window->doc) {
838 WARN("NULL doc\n");
839 return E_UNEXPECTED;
842 *img_elem = NULL;
844 hres = create_nselem(This->window->doc, imgW, &nselem);
845 if(FAILED(hres))
846 return hres;
848 hres = HTMLElement_Create(This->window->doc, (nsIDOMNode*)nselem, FALSE, &elem);
849 nsIDOMHTMLElement_Release(nselem);
850 if(FAILED(hres)) {
851 ERR("HTMLElement_Create failed\n");
852 return hres;
855 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
856 (void**)&img);
857 if(FAILED(hres)) {
858 ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
859 return hres;
862 l = var_to_size(&width);
863 if(l)
864 IHTMLImgElement_put_width(img, l);
865 l = var_to_size(&height);
866 if(l)
867 IHTMLImgElement_put_height(img, l);
869 *img_elem = img;
870 return S_OK;
873 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
874 HTMLImageElementFactory_QueryInterface,
875 HTMLImageElementFactory_AddRef,
876 HTMLImageElementFactory_Release,
877 HTMLImageElementFactory_GetTypeInfoCount,
878 HTMLImageElementFactory_GetTypeInfo,
879 HTMLImageElementFactory_GetIDsOfNames,
880 HTMLImageElementFactory_Invoke,
881 HTMLImageElementFactory_create
884 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
886 return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
889 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
890 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
891 IServiceProvider *caller)
893 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
894 IHTMLImgElement *img;
895 VARIANT empty, *width, *height;
896 HRESULT hres;
897 int argc = params->cArgs - params->cNamedArgs;
899 V_VT(res) = VT_NULL;
901 V_VT(&empty) = VT_EMPTY;
903 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
904 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
906 hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
907 &img);
908 if(FAILED(hres))
909 return hres;
911 V_VT(res) = VT_DISPATCH;
912 V_DISPATCH(res) = (IDispatch*)img;
914 return S_OK;
917 static const tid_t HTMLImageElementFactory_iface_tids[] = {
918 IHTMLImageElementFactory_tid,
922 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
923 HTMLImageElementFactory_value,
924 NULL,
925 NULL,
926 NULL
929 static dispex_static_data_t HTMLImageElementFactory_dispex = {
930 &HTMLImageElementFactory_dispex_vtbl,
931 IHTMLImageElementFactory_tid,
932 NULL,
933 HTMLImageElementFactory_iface_tids
936 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow *window)
938 HTMLImageElementFactory *ret;
940 ret = heap_alloc(sizeof(HTMLImageElementFactory));
942 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
943 ret->ref = 1;
944 ret->window = window;
946 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
947 &HTMLImageElementFactory_dispex);
949 return ret;