mshtml: Moved image_factory to HTMLInnerWindow.
[wine/multimedia.git] / dlls / mshtml / htmlimg.c
blobadb40d5fea16ad4fe62888757f3c3ed8ee19bee1
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 return return_nsstr(nsres, &alt_str, p);
257 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
259 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
260 nsAString src_str;
261 nsresult nsres;
263 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
265 nsAString_InitDepend(&src_str, v);
266 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
267 nsAString_Finish(&src_str);
268 if(NS_FAILED(nsres))
269 ERR("SetSrc failed: %08x\n", nsres);
271 return NS_OK;
274 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
276 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
277 const PRUnichar *src;
278 nsAString src_str;
279 nsresult nsres;
280 HRESULT hres = S_OK;
282 static const WCHAR blockedW[] = {'B','L','O','C','K','E','D',':',':',0};
284 TRACE("(%p)->(%p)\n", This, p);
286 nsAString_Init(&src_str, NULL);
287 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
288 if(NS_SUCCEEDED(nsres)) {
289 nsAString_GetData(&src_str, &src);
291 if(!strncmpiW(src, blockedW, sizeof(blockedW)/sizeof(WCHAR)-1)) {
292 TRACE("returning BLOCKED::\n");
293 *p = SysAllocString(blockedW);
294 if(!*p)
295 hres = E_OUTOFMEMORY;
296 }else {
297 hres = nsuri_to_url(src, TRUE, p);
299 }else {
300 ERR("GetSrc failed: %08x\n", nsres);
301 hres = E_FAIL;
304 nsAString_Finish(&src_str);
305 return hres;
308 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
310 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
311 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
312 return E_NOTIMPL;
315 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
317 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
318 FIXME("(%p)->(%p)\n", This, p);
319 return E_NOTIMPL;
322 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
324 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
325 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
326 return E_NOTIMPL;
329 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
331 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
332 FIXME("(%p)->(%p)\n", This, p);
333 return E_NOTIMPL;
336 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
338 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
339 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
340 return E_NOTIMPL;
343 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
345 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
346 FIXME("(%p)->(%p)\n", This, p);
347 return E_NOTIMPL;
350 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
352 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
353 FIXME("(%p)->(%p)\n", This, p);
354 return E_NOTIMPL;
357 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
359 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
360 FIXME("(%p)->(%p)\n", This, p);
361 return E_NOTIMPL;
364 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
366 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
367 FIXME("(%p)->()\n", This);
368 return E_NOTIMPL;
371 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
373 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
374 FIXME("(%p)->(%p)\n", This, p);
375 return E_NOTIMPL;
378 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
380 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
381 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
382 return E_NOTIMPL;
385 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
387 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
388 FIXME("(%p)->(%p)\n", This, p);
389 return E_NOTIMPL;
392 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
394 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
396 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
398 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
401 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
403 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
405 TRACE("(%p)->(%p)\n", This, p);
407 return get_node_event(&This->element.node, EVENTID_LOAD, p);
410 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
412 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
414 TRACE("(%p)->()\n", This);
416 return set_node_event(&This->element.node, EVENTID_ERROR, &v);
419 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
421 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
423 TRACE("(%p)->(%p)\n", This, p);
425 return get_node_event(&This->element.node, EVENTID_ERROR, p);
428 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
430 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
431 FIXME("(%p)->()\n", This);
432 return E_NOTIMPL;
435 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
437 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
438 FIXME("(%p)->(%p)\n", This, p);
439 return E_NOTIMPL;
442 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
444 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
445 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
446 return E_NOTIMPL;
449 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
451 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
452 nsAString name;
453 nsresult nsres;
455 TRACE("(%p)->(%p)\n", This, p);
457 nsAString_Init(&name, NULL);
458 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
459 return return_nsstr(nsres, &name, p);
462 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
464 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
465 nsresult nsres;
467 TRACE("(%p)->(%d)\n", This, v);
469 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
470 if(NS_FAILED(nsres)) {
471 ERR("SetWidth failed: %08x\n", nsres);
472 return E_FAIL;
475 return S_OK;
478 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
480 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
481 PRUint32 width;
482 nsresult nsres;
484 TRACE("(%p)->(%p)\n", This, p);
486 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
487 if(NS_FAILED(nsres)) {
488 ERR("GetWidth failed: %08x\n", nsres);
489 return E_FAIL;
492 *p = width;
493 return S_OK;
496 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
498 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
499 nsresult nsres;
501 TRACE("(%p)->(%d)\n", This, v);
503 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
504 if(NS_FAILED(nsres)) {
505 ERR("SetHeight failed: %08x\n", nsres);
506 return E_FAIL;
509 return S_OK;
512 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
514 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
515 PRUint32 height;
516 nsresult nsres;
518 TRACE("(%p)->(%p)\n", This, p);
520 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
521 if(NS_FAILED(nsres)) {
522 ERR("GetHeight failed: %08x\n", nsres);
523 return E_FAIL;
526 *p = height;
527 return S_OK;
530 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
532 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
533 FIXME("(%p)->()\n", This);
534 return E_NOTIMPL;
537 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
539 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
540 FIXME("(%p)->(%p)\n", This, p);
541 return E_NOTIMPL;
544 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
545 HTMLImgElement_QueryInterface,
546 HTMLImgElement_AddRef,
547 HTMLImgElement_Release,
548 HTMLImgElement_GetTypeInfoCount,
549 HTMLImgElement_GetTypeInfo,
550 HTMLImgElement_GetIDsOfNames,
551 HTMLImgElement_Invoke,
552 HTMLImgElement_put_isMap,
553 HTMLImgElement_get_isMap,
554 HTMLImgElement_put_useMap,
555 HTMLImgElement_get_useMap,
556 HTMLImgElement_get_mimeType,
557 HTMLImgElement_get_fileSize,
558 HTMLImgElement_get_fileCreatedDate,
559 HTMLImgElement_get_fileModifiedDate,
560 HTMLImgElement_get_fileUpdatedDate,
561 HTMLImgElement_get_protocol,
562 HTMLImgElement_get_href,
563 HTMLImgElement_get_nameProp,
564 HTMLImgElement_put_border,
565 HTMLImgElement_get_border,
566 HTMLImgElement_put_vspace,
567 HTMLImgElement_get_vspace,
568 HTMLImgElement_put_hspace,
569 HTMLImgElement_get_hspace,
570 HTMLImgElement_put_alt,
571 HTMLImgElement_get_alt,
572 HTMLImgElement_put_src,
573 HTMLImgElement_get_src,
574 HTMLImgElement_put_lowsrc,
575 HTMLImgElement_get_lowsrc,
576 HTMLImgElement_put_vrml,
577 HTMLImgElement_get_vrml,
578 HTMLImgElement_put_dynsrc,
579 HTMLImgElement_get_dynsrc,
580 HTMLImgElement_get_readyState,
581 HTMLImgElement_get_complete,
582 HTMLImgElement_put_loop,
583 HTMLImgElement_get_loop,
584 HTMLImgElement_put_align,
585 HTMLImgElement_get_align,
586 HTMLImgElement_put_onload,
587 HTMLImgElement_get_onload,
588 HTMLImgElement_put_onerror,
589 HTMLImgElement_get_onerror,
590 HTMLImgElement_put_onabort,
591 HTMLImgElement_get_onabort,
592 HTMLImgElement_put_name,
593 HTMLImgElement_get_name,
594 HTMLImgElement_put_width,
595 HTMLImgElement_get_width,
596 HTMLImgElement_put_height,
597 HTMLImgElement_get_height,
598 HTMLImgElement_put_start,
599 HTMLImgElement_get_start
602 static inline HTMLImgElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
604 return CONTAINING_RECORD(iface, HTMLImgElement, element.node);
607 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
609 HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
611 *ppv = NULL;
613 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
614 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
615 *ppv = &This->IHTMLImgElement_iface;
616 }else {
617 return HTMLElement_QI(&This->element.node, riid, ppv);
620 IUnknown_AddRef((IUnknown*)*ppv);
621 return S_OK;
624 static void HTMLImgElement_destructor(HTMLDOMNode *iface)
626 HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
628 if(This->nsimg)
629 nsIDOMHTMLImageElement_Release(This->nsimg);
631 HTMLElement_destructor(&This->element.node);
634 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
636 HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
638 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
641 static const NodeImplVtbl HTMLImgElementImplVtbl = {
642 HTMLImgElement_QI,
643 HTMLImgElement_destructor,
644 HTMLElement_clone,
645 HTMLElement_get_attr_col,
646 NULL,
647 NULL,
648 NULL,
649 NULL,
650 NULL,
651 NULL,
652 HTMLImgElement_get_readystate
655 static const tid_t HTMLImgElement_iface_tids[] = {
656 HTMLELEMENT_TIDS,
657 IHTMLImgElement_tid,
660 static dispex_static_data_t HTMLImgElement_dispex = {
661 NULL,
662 DispHTMLImg_tid,
663 NULL,
664 HTMLImgElement_iface_tids
667 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
669 HTMLImgElement *ret;
670 nsresult nsres;
672 ret = heap_alloc_zero(sizeof(HTMLImgElement));
673 if(!ret)
674 return E_OUTOFMEMORY;
676 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
677 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
679 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
680 if(NS_FAILED(nsres)) {
681 ERR("Could not get nsIDOMHTMLImageElement: %08x\n", nsres);
682 heap_free(ret);
683 return E_FAIL;
686 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
688 *elem = &ret->element;
689 return S_OK;
692 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
694 return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
697 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
698 REFIID riid, void **ppv)
700 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
702 *ppv = NULL;
704 if(IsEqualGUID(&IID_IUnknown, riid)) {
705 TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
706 *ppv = &This->IHTMLImageElementFactory_iface;
707 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
708 TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
709 *ppv = &This->IHTMLImageElementFactory_iface;
710 }else if(dispex_query_interface(&This->dispex, riid, ppv))
711 return *ppv ? S_OK : E_NOINTERFACE;
713 if(*ppv) {
714 IUnknown_AddRef((IUnknown*)*ppv);
715 return S_OK;
718 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
719 return E_NOINTERFACE;
722 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
724 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
725 LONG ref = InterlockedIncrement(&This->ref);
727 TRACE("(%p) ref=%d\n", This, ref);
729 return ref;
732 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
734 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
735 LONG ref = InterlockedDecrement(&This->ref);
737 TRACE("(%p) ref=%d\n", This, ref);
739 if(!ref)
740 heap_free(This);
742 return ref;
745 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
746 UINT *pctinfo)
748 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
749 FIXME("(%p)->(%p)\n", This, pctinfo);
750 return E_NOTIMPL;
753 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
754 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
756 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
757 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
758 return E_NOTIMPL;
761 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
762 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
763 DISPID *rgDispId)
765 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
766 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
767 cNames, lcid, rgDispId);
768 return E_NOTIMPL;
771 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
772 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
773 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
774 UINT *puArgErr)
776 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
777 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
778 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
779 return E_NOTIMPL;
782 static LONG var_to_size(const VARIANT *v)
784 switch(V_VT(v)) {
785 case VT_EMPTY:
786 return 0;
787 case VT_I4:
788 return V_I4(v);
789 case VT_BSTR: {
790 LONG ret;
791 HRESULT hres;
793 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
794 if(FAILED(hres)) {
795 FIXME("VarI4FromStr failed: %08x\n", hres);
796 return 0;
798 return ret;
800 default:
801 FIXME("unsupported size %s\n", debugstr_variant(v));
803 return 0;
806 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
807 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
809 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
810 HTMLDocumentNode *doc;
811 IHTMLImgElement *img;
812 HTMLElement *elem;
813 nsIDOMHTMLElement *nselem;
814 LONG l;
815 HRESULT hres;
817 static const PRUnichar imgW[] = {'I','M','G',0};
819 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
820 debugstr_variant(&height), img_elem);
822 if(!This->window || !This->window->base.inner_window->doc) {
823 WARN("NULL doc\n");
824 return E_UNEXPECTED;
827 doc = This->window->base.inner_window->doc;
829 *img_elem = NULL;
831 hres = create_nselem(doc, imgW, &nselem);
832 if(FAILED(hres))
833 return hres;
835 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
836 nsIDOMHTMLElement_Release(nselem);
837 if(FAILED(hres)) {
838 ERR("HTMLElement_Create failed\n");
839 return hres;
842 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
843 (void**)&img);
844 if(FAILED(hres)) {
845 ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
846 return hres;
849 l = var_to_size(&width);
850 if(l)
851 IHTMLImgElement_put_width(img, l);
852 l = var_to_size(&height);
853 if(l)
854 IHTMLImgElement_put_height(img, l);
856 *img_elem = img;
857 return S_OK;
860 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
861 HTMLImageElementFactory_QueryInterface,
862 HTMLImageElementFactory_AddRef,
863 HTMLImageElementFactory_Release,
864 HTMLImageElementFactory_GetTypeInfoCount,
865 HTMLImageElementFactory_GetTypeInfo,
866 HTMLImageElementFactory_GetIDsOfNames,
867 HTMLImageElementFactory_Invoke,
868 HTMLImageElementFactory_create
871 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
873 return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
876 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
877 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
878 IServiceProvider *caller)
880 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
881 IHTMLImgElement *img;
882 VARIANT empty, *width, *height;
883 HRESULT hres;
884 int argc = params->cArgs - params->cNamedArgs;
886 V_VT(res) = VT_NULL;
888 V_VT(&empty) = VT_EMPTY;
890 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
891 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
893 hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
894 &img);
895 if(FAILED(hres))
896 return hres;
898 V_VT(res) = VT_DISPATCH;
899 V_DISPATCH(res) = (IDispatch*)img;
901 return S_OK;
904 static const tid_t HTMLImageElementFactory_iface_tids[] = {
905 IHTMLImageElementFactory_tid,
909 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
910 HTMLImageElementFactory_value,
911 NULL,
912 NULL,
913 NULL
916 static dispex_static_data_t HTMLImageElementFactory_dispex = {
917 &HTMLImageElementFactory_dispex_vtbl,
918 IHTMLImageElementFactory_tid,
919 NULL,
920 HTMLImageElementFactory_iface_tids
923 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
925 HTMLImageElementFactory *ret;
927 ret = heap_alloc(sizeof(HTMLImageElementFactory));
928 if(!ret)
929 return E_OUTOFMEMORY;
931 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
932 ret->ref = 1;
933 ret->window = window;
935 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
936 &HTMLImageElementFactory_dispex);
938 *ret_val = ret;
939 return S_OK;