ntdll: Rename local variables in heap_reallocate.
[wine.git] / dlls / mshtml / htmlimg.c
blob4483a5ed5ac4be65b8aa6ce8893d7601ef3e5bb5
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 struct HTMLImg {
36 HTMLElement element;
38 IHTMLImgElement IHTMLImgElement_iface;
40 nsIDOMHTMLImageElement *nsimg;
43 static inline HTMLImg *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
45 return CONTAINING_RECORD(iface, HTMLImg, IHTMLImgElement_iface);
48 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
50 HTMLImg *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 HTMLImg *This = impl_from_IHTMLImgElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
64 HTMLImg *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 HTMLImg *This = impl_from_IHTMLImgElement(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLImg *This = impl_from_IHTMLImgElement(iface);
79 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.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 HTMLImg *This = impl_from_IHTMLImgElement(iface);
88 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.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 HTMLImg *This = impl_from_IHTMLImgElement(iface);
97 return IDispatchEx_Invoke(&This->element.node.event_target.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 HTMLImg *This = impl_from_IHTMLImgElement(iface);
104 nsresult nsres;
106 TRACE("(%p)->(%x)\n", This, v);
108 nsres = nsIDOMHTMLImageElement_SetIsMap(This->nsimg, v != VARIANT_FALSE);
109 if (NS_FAILED(nsres)) {
110 ERR("Set IsMap failed: %08lx\n", nsres);
111 return E_FAIL;
114 return S_OK;
117 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
119 HTMLImg *This = impl_from_IHTMLImgElement(iface);
120 cpp_bool b;
121 nsresult nsres;
123 TRACE("(%p)->(%p)\n", This, p);
125 if (p == NULL)
126 return E_INVALIDARG;
128 nsres = nsIDOMHTMLImageElement_GetIsMap(This->nsimg, &b);
129 if (NS_FAILED(nsres)) {
130 ERR("Get IsMap failed: %08lx\n", nsres);
131 return E_FAIL;
134 *p = variant_bool(b);
135 return S_OK;
138 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
140 HTMLImg *This = impl_from_IHTMLImgElement(iface);
141 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
142 return E_NOTIMPL;
145 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
147 HTMLImg *This = impl_from_IHTMLImgElement(iface);
148 FIXME("(%p)->(%p)\n", This, p);
149 return E_NOTIMPL;
152 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
154 HTMLImg *This = impl_from_IHTMLImgElement(iface);
155 FIXME("(%p)->(%p)\n", This, p);
156 return E_NOTIMPL;
159 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
161 HTMLImg *This = impl_from_IHTMLImgElement(iface);
162 FIXME("(%p)->(%p)\n", This, p);
163 return E_NOTIMPL;
166 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
168 HTMLImg *This = impl_from_IHTMLImgElement(iface);
169 FIXME("(%p)->(%p)\n", This, p);
170 return E_NOTIMPL;
173 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
175 HTMLImg *This = impl_from_IHTMLImgElement(iface);
176 FIXME("(%p)->(%p)\n", This, p);
177 return E_NOTIMPL;
180 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
182 HTMLImg *This = impl_from_IHTMLImgElement(iface);
183 FIXME("(%p)->(%p)\n", This, p);
184 return E_NOTIMPL;
187 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
189 HTMLImg *This = impl_from_IHTMLImgElement(iface);
190 FIXME("(%p)->(%p)\n", This, p);
191 return E_NOTIMPL;
194 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
196 HTMLImg *This = impl_from_IHTMLImgElement(iface);
197 FIXME("(%p)->(%p)\n", This, p);
198 return E_NOTIMPL;
201 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
203 HTMLImg *This = impl_from_IHTMLImgElement(iface);
204 FIXME("(%p)->(%p)\n", This, p);
205 return E_NOTIMPL;
208 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
210 HTMLImg *This = impl_from_IHTMLImgElement(iface);
211 FIXME("(%p)->()\n", This);
212 return E_NOTIMPL;
215 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
217 HTMLImg *This = impl_from_IHTMLImgElement(iface);
218 FIXME("(%p)->(%p)\n", This, p);
219 return E_NOTIMPL;
222 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
224 HTMLImg *This = impl_from_IHTMLImgElement(iface);
225 FIXME("(%p)->(%ld)\n", This, v);
226 return E_NOTIMPL;
229 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
231 HTMLImg *This = impl_from_IHTMLImgElement(iface);
232 FIXME("(%p)->(%p)\n", This, p);
233 return E_NOTIMPL;
236 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
238 HTMLImg *This = impl_from_IHTMLImgElement(iface);
239 FIXME("(%p)->(%ld)\n", This, v);
240 return E_NOTIMPL;
243 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
245 HTMLImg *This = impl_from_IHTMLImgElement(iface);
246 FIXME("(%p)->(%p)\n", This, p);
247 return E_NOTIMPL;
250 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
252 HTMLImg *This = impl_from_IHTMLImgElement(iface);
253 nsAString alt_str;
254 nsresult nsres;
256 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
258 nsAString_InitDepend(&alt_str, v);
259 nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
260 nsAString_Finish(&alt_str);
261 if(NS_FAILED(nsres))
262 ERR("SetAlt failed: %08lx\n", nsres);
264 return S_OK;
267 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
269 HTMLImg *This = impl_from_IHTMLImgElement(iface);
270 nsAString alt_str;
271 nsresult nsres;
273 TRACE("(%p)->(%p)\n", This, p);
275 nsAString_Init(&alt_str, NULL);
276 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
277 return return_nsstr(nsres, &alt_str, p);
280 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
282 HTMLImg *This = impl_from_IHTMLImgElement(iface);
283 nsAString src_str;
284 nsresult nsres;
286 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
288 nsAString_InitDepend(&src_str, v);
289 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
290 nsAString_Finish(&src_str);
291 if(NS_FAILED(nsres))
292 ERR("SetSrc failed: %08lx\n", nsres);
294 return S_OK;
297 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
299 HTMLImg *This = impl_from_IHTMLImgElement(iface);
300 const PRUnichar *src;
301 nsAString src_str;
302 nsresult nsres;
303 HRESULT hres = S_OK;
305 TRACE("(%p)->(%p)\n", This, p);
307 nsAString_Init(&src_str, NULL);
308 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
309 if(NS_SUCCEEDED(nsres)) {
310 nsAString_GetData(&src_str, &src);
312 if(!wcsnicmp(src, L"BLOCKED::", ARRAY_SIZE(L"BLOCKED::")-1)) {
313 TRACE("returning BLOCKED::\n");
314 *p = SysAllocString(L"BLOCKED::");
315 if(!*p)
316 hres = E_OUTOFMEMORY;
317 }else {
318 hres = nsuri_to_url(src, TRUE, p);
320 }else {
321 ERR("GetSrc failed: %08lx\n", nsres);
322 hres = E_FAIL;
325 nsAString_Finish(&src_str);
326 return hres;
329 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
331 HTMLImg *This = impl_from_IHTMLImgElement(iface);
332 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
333 return E_NOTIMPL;
336 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
338 HTMLImg *This = impl_from_IHTMLImgElement(iface);
339 FIXME("(%p)->(%p)\n", This, p);
340 return E_NOTIMPL;
343 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
345 HTMLImg *This = impl_from_IHTMLImgElement(iface);
346 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
347 return E_NOTIMPL;
350 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
352 HTMLImg *This = impl_from_IHTMLImgElement(iface);
353 FIXME("(%p)->(%p)\n", This, p);
354 return E_NOTIMPL;
357 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
359 HTMLImg *This = impl_from_IHTMLImgElement(iface);
360 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
361 return E_NOTIMPL;
364 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
366 HTMLImg *This = impl_from_IHTMLImgElement(iface);
367 FIXME("(%p)->(%p)\n", This, p);
368 return E_NOTIMPL;
371 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
373 HTMLImg *This = impl_from_IHTMLImgElement(iface);
374 FIXME("(%p)->(%p)\n", This, p);
375 return E_NOTIMPL;
378 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
380 HTMLImg *This = impl_from_IHTMLImgElement(iface);
381 cpp_bool complete;
382 nsresult nsres;
384 TRACE("(%p)->(%p)\n", This, p);
386 nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
387 if(NS_FAILED(nsres)) {
388 ERR("GetComplete failed: %08lx\n", nsres);
389 return E_FAIL;
392 *p = variant_bool(complete);
393 return S_OK;
396 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
398 HTMLImg *This = impl_from_IHTMLImgElement(iface);
399 FIXME("(%p)->()\n", This);
400 return E_NOTIMPL;
403 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
405 HTMLImg *This = impl_from_IHTMLImgElement(iface);
406 FIXME("(%p)->(%p)\n", This, p);
407 return E_NOTIMPL;
410 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
412 HTMLImg *This = impl_from_IHTMLImgElement(iface);
413 nsAString str;
414 nsresult nsres;
416 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
418 nsAString_InitDepend(&str, v);
420 nsres = nsIDOMHTMLImageElement_SetAlign(This->nsimg, &str);
421 nsAString_Finish(&str);
422 if (NS_FAILED(nsres)){
423 ERR("Set Align(%s) failed: %08lx\n", debugstr_w(v), nsres);
424 return E_FAIL;
427 return S_OK;
430 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
432 HTMLImg *This = impl_from_IHTMLImgElement(iface);
433 nsAString str;
434 nsresult nsres;
436 TRACE("(%p)->(%p)\n", This, p);
438 nsAString_Init(&str, NULL);
439 nsres = nsIDOMHTMLImageElement_GetAlign(This->nsimg, &str);
441 return return_nsstr(nsres, &str, p);
444 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
446 HTMLImg *This = impl_from_IHTMLImgElement(iface);
448 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
450 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
453 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
455 HTMLImg *This = impl_from_IHTMLImgElement(iface);
457 TRACE("(%p)->(%p)\n", This, p);
459 return get_node_event(&This->element.node, EVENTID_LOAD, p);
462 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
464 HTMLImg *This = impl_from_IHTMLImgElement(iface);
466 TRACE("(%p)->()\n", This);
468 return set_node_event(&This->element.node, EVENTID_ERROR, &v);
471 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
473 HTMLImg *This = impl_from_IHTMLImgElement(iface);
475 TRACE("(%p)->(%p)\n", This, p);
477 return get_node_event(&This->element.node, EVENTID_ERROR, p);
480 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
482 HTMLImg *This = impl_from_IHTMLImgElement(iface);
484 TRACE("(%p)->()\n", This);
486 return set_node_event(&This->element.node, EVENTID_ABORT, &v);
489 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
491 HTMLImg *This = impl_from_IHTMLImgElement(iface);
493 TRACE("(%p)->(%p)\n", This, p);
495 return get_node_event(&This->element.node, EVENTID_ABORT, p);
498 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
500 HTMLImg *This = impl_from_IHTMLImgElement(iface);
501 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
502 return E_NOTIMPL;
505 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
507 HTMLImg *This = impl_from_IHTMLImgElement(iface);
508 nsAString name;
509 nsresult nsres;
511 TRACE("(%p)->(%p)\n", This, p);
513 nsAString_Init(&name, NULL);
514 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
515 return return_nsstr(nsres, &name, p);
518 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
520 HTMLImg *This = impl_from_IHTMLImgElement(iface);
521 nsresult nsres;
523 TRACE("(%p)->(%ld)\n", This, v);
525 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
526 if(NS_FAILED(nsres)) {
527 ERR("SetWidth failed: %08lx\n", nsres);
528 return E_FAIL;
531 return S_OK;
534 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
536 HTMLImg *This = impl_from_IHTMLImgElement(iface);
537 UINT32 width;
538 nsresult nsres;
540 TRACE("(%p)->(%p)\n", This, p);
542 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
543 if(NS_FAILED(nsres)) {
544 ERR("GetWidth failed: %08lx\n", nsres);
545 return E_FAIL;
548 *p = width;
549 return S_OK;
552 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
554 HTMLImg *This = impl_from_IHTMLImgElement(iface);
555 nsresult nsres;
557 TRACE("(%p)->(%ld)\n", This, v);
559 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
560 if(NS_FAILED(nsres)) {
561 ERR("SetHeight failed: %08lx\n", nsres);
562 return E_FAIL;
565 return S_OK;
568 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
570 HTMLImg *This = impl_from_IHTMLImgElement(iface);
571 UINT32 height;
572 nsresult nsres;
574 TRACE("(%p)->(%p)\n", This, p);
576 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
577 if(NS_FAILED(nsres)) {
578 ERR("GetHeight failed: %08lx\n", nsres);
579 return E_FAIL;
582 *p = height;
583 return S_OK;
586 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
588 HTMLImg *This = impl_from_IHTMLImgElement(iface);
589 FIXME("(%p)->()\n", This);
590 return E_NOTIMPL;
593 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
595 HTMLImg *This = impl_from_IHTMLImgElement(iface);
596 FIXME("(%p)->(%p)\n", This, p);
597 return E_NOTIMPL;
600 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
601 HTMLImgElement_QueryInterface,
602 HTMLImgElement_AddRef,
603 HTMLImgElement_Release,
604 HTMLImgElement_GetTypeInfoCount,
605 HTMLImgElement_GetTypeInfo,
606 HTMLImgElement_GetIDsOfNames,
607 HTMLImgElement_Invoke,
608 HTMLImgElement_put_isMap,
609 HTMLImgElement_get_isMap,
610 HTMLImgElement_put_useMap,
611 HTMLImgElement_get_useMap,
612 HTMLImgElement_get_mimeType,
613 HTMLImgElement_get_fileSize,
614 HTMLImgElement_get_fileCreatedDate,
615 HTMLImgElement_get_fileModifiedDate,
616 HTMLImgElement_get_fileUpdatedDate,
617 HTMLImgElement_get_protocol,
618 HTMLImgElement_get_href,
619 HTMLImgElement_get_nameProp,
620 HTMLImgElement_put_border,
621 HTMLImgElement_get_border,
622 HTMLImgElement_put_vspace,
623 HTMLImgElement_get_vspace,
624 HTMLImgElement_put_hspace,
625 HTMLImgElement_get_hspace,
626 HTMLImgElement_put_alt,
627 HTMLImgElement_get_alt,
628 HTMLImgElement_put_src,
629 HTMLImgElement_get_src,
630 HTMLImgElement_put_lowsrc,
631 HTMLImgElement_get_lowsrc,
632 HTMLImgElement_put_vrml,
633 HTMLImgElement_get_vrml,
634 HTMLImgElement_put_dynsrc,
635 HTMLImgElement_get_dynsrc,
636 HTMLImgElement_get_readyState,
637 HTMLImgElement_get_complete,
638 HTMLImgElement_put_loop,
639 HTMLImgElement_get_loop,
640 HTMLImgElement_put_align,
641 HTMLImgElement_get_align,
642 HTMLImgElement_put_onload,
643 HTMLImgElement_get_onload,
644 HTMLImgElement_put_onerror,
645 HTMLImgElement_get_onerror,
646 HTMLImgElement_put_onabort,
647 HTMLImgElement_get_onabort,
648 HTMLImgElement_put_name,
649 HTMLImgElement_get_name,
650 HTMLImgElement_put_width,
651 HTMLImgElement_get_width,
652 HTMLImgElement_put_height,
653 HTMLImgElement_get_height,
654 HTMLImgElement_put_start,
655 HTMLImgElement_get_start
658 static inline HTMLImg *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
660 return CONTAINING_RECORD(iface, HTMLImg, element.node);
663 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
665 HTMLImg *This = impl_from_HTMLDOMNode(iface);
667 *ppv = NULL;
669 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
670 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
671 *ppv = &This->IHTMLImgElement_iface;
672 }else {
673 return HTMLElement_QI(&This->element.node, riid, ppv);
676 IUnknown_AddRef((IUnknown*)*ppv);
677 return S_OK;
680 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
682 HTMLImg *This = impl_from_HTMLDOMNode(iface);
684 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
687 static void HTMLImgElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
689 HTMLImg *This = impl_from_HTMLDOMNode(iface);
691 if(This->nsimg)
692 note_cc_edge((nsISupports*)This->nsimg, "This->nsimg", cb);
695 static void HTMLImgElement_unlink(HTMLDOMNode *iface)
697 HTMLImg *This = impl_from_HTMLDOMNode(iface);
699 if(This->nsimg) {
700 nsIDOMHTMLImageElement *nsimg = This->nsimg;
702 This->nsimg = NULL;
703 nsIDOMHTMLImageElement_Release(nsimg);
707 static const NodeImplVtbl HTMLImgElementImplVtbl = {
708 &CLSID_HTMLImg,
709 HTMLImgElement_QI,
710 HTMLElement_destructor,
711 HTMLElement_cpc,
712 HTMLElement_clone,
713 HTMLElement_handle_event,
714 HTMLElement_get_attr_col,
715 NULL,
716 NULL,
717 NULL,
718 NULL,
719 HTMLImgElement_get_readystate,
720 NULL,
721 NULL,
722 NULL,
723 HTMLImgElement_traverse,
724 HTMLImgElement_unlink
727 static const tid_t HTMLImgElement_iface_tids[] = {
728 HTMLELEMENT_TIDS,
729 IHTMLImgElement_tid,
732 static dispex_static_data_t HTMLImgElement_dispex = {
733 L"HTMLImageElement",
734 NULL,
735 DispHTMLImg_tid,
736 HTMLImgElement_iface_tids,
737 HTMLElement_init_dispex_info
740 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
742 HTMLImg *ret;
743 nsresult nsres;
745 ret = heap_alloc_zero(sizeof(HTMLImg));
746 if(!ret)
747 return E_OUTOFMEMORY;
749 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
750 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
752 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
754 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
755 assert(nsres == NS_OK);
757 *elem = &ret->element;
758 return S_OK;
761 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
763 return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
766 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
767 REFIID riid, void **ppv)
769 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
771 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
773 if(IsEqualGUID(&IID_IUnknown, riid)) {
774 *ppv = &This->IHTMLImageElementFactory_iface;
775 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
776 *ppv = &This->IHTMLImageElementFactory_iface;
777 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
778 return *ppv ? S_OK : E_NOINTERFACE;
779 }else {
780 *ppv = NULL;
781 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
782 return E_NOINTERFACE;
785 IUnknown_AddRef((IUnknown*)*ppv);
786 return S_OK;
789 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
791 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
792 LONG ref = InterlockedIncrement(&This->ref);
794 TRACE("(%p) ref=%ld\n", This, ref);
796 return ref;
799 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
801 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
802 LONG ref = InterlockedDecrement(&This->ref);
804 TRACE("(%p) ref=%ld\n", This, ref);
806 if(!ref)
807 heap_free(This);
809 return ref;
812 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
813 UINT *pctinfo)
815 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
816 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
819 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
820 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
822 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
823 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
826 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
827 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
828 DISPID *rgDispId)
830 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
831 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
834 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
835 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
836 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
837 UINT *puArgErr)
839 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
840 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
841 pDispParams, pVarResult, pExcepInfo, puArgErr);
844 static LONG var_to_size(const VARIANT *v)
846 switch(V_VT(v)) {
847 case VT_EMPTY:
848 return 0;
849 case VT_I4:
850 return V_I4(v);
851 case VT_BSTR: {
852 LONG ret;
853 HRESULT hres;
855 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
856 if(FAILED(hres)) {
857 FIXME("VarI4FromStr failed: %08lx\n", hres);
858 return 0;
860 return ret;
862 default:
863 FIXME("unsupported size %s\n", debugstr_variant(v));
865 return 0;
868 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
869 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
871 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
872 HTMLDocumentNode *doc;
873 IHTMLImgElement *img;
874 HTMLElement *elem;
875 nsIDOMElement *nselem;
876 LONG l;
877 HRESULT hres;
879 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
880 debugstr_variant(&height), img_elem);
882 if(!This->window || !This->window->doc) {
883 WARN("NULL doc\n");
884 return E_UNEXPECTED;
887 doc = This->window->doc;
889 *img_elem = NULL;
891 hres = create_nselem(doc, L"IMG", &nselem);
892 if(FAILED(hres))
893 return hres;
895 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
896 nsIDOMElement_Release(nselem);
897 if(FAILED(hres)) {
898 ERR("HTMLElement_Create failed\n");
899 return hres;
902 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
903 (void**)&img);
904 IHTMLElement_Release(&elem->IHTMLElement_iface);
905 if(FAILED(hres)) {
906 ERR("IHTMLElement_QueryInterface failed: 0x%08lx\n", hres);
907 return hres;
910 l = var_to_size(&width);
911 if(l)
912 IHTMLImgElement_put_width(img, l);
913 l = var_to_size(&height);
914 if(l)
915 IHTMLImgElement_put_height(img, l);
917 *img_elem = img;
918 return S_OK;
921 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
922 HTMLImageElementFactory_QueryInterface,
923 HTMLImageElementFactory_AddRef,
924 HTMLImageElementFactory_Release,
925 HTMLImageElementFactory_GetTypeInfoCount,
926 HTMLImageElementFactory_GetTypeInfo,
927 HTMLImageElementFactory_GetIDsOfNames,
928 HTMLImageElementFactory_Invoke,
929 HTMLImageElementFactory_create
932 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
934 return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
937 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
938 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
939 IServiceProvider *caller)
941 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
942 IHTMLImgElement *img;
943 VARIANT empty, *width, *height;
944 HRESULT hres;
945 int argc = params->cArgs - params->cNamedArgs;
947 V_VT(res) = VT_NULL;
949 V_VT(&empty) = VT_EMPTY;
951 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
952 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
954 hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
955 &img);
956 if(FAILED(hres))
957 return hres;
959 V_VT(res) = VT_DISPATCH;
960 V_DISPATCH(res) = (IDispatch*)img;
962 return S_OK;
965 static const tid_t HTMLImageElementFactory_iface_tids[] = {
966 IHTMLImageElementFactory_tid,
970 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
971 HTMLImageElementFactory_value,
972 NULL,
973 NULL,
974 NULL
977 static dispex_static_data_t HTMLImageElementFactory_dispex = {
978 L"Function",
979 &HTMLImageElementFactory_dispex_vtbl,
980 IHTMLImageElementFactory_tid,
981 HTMLImageElementFactory_iface_tids
984 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
986 HTMLImageElementFactory *ret;
988 ret = heap_alloc(sizeof(HTMLImageElementFactory));
989 if(!ret)
990 return E_OUTOFMEMORY;
992 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
993 ret->ref = 1;
994 ret->window = window;
996 init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
997 &HTMLImageElementFactory_dispex, dispex_compat_mode(&window->event_target.dispex));
999 *ret_val = ret;
1000 return S_OK;