include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / mshtml / htmlimg.c
blobfb3be13b918cd3528cf47005404f7e671a763ebb
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"
27 #include "mshtmdid.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36 struct HTMLImg {
37 HTMLElement element;
39 IHTMLImgElement IHTMLImgElement_iface;
41 nsIDOMHTMLImageElement *nsimg;
44 static inline HTMLImg *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
46 return CONTAINING_RECORD(iface, HTMLImg, IHTMLImgElement_iface);
49 DISPEX_IDISPATCH_IMPL(HTMLImgElement, IHTMLImgElement,
50 impl_from_IHTMLImgElement(iface)->element.node.event_target.dispex)
52 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
54 HTMLImg *This = impl_from_IHTMLImgElement(iface);
55 nsresult nsres;
57 TRACE("(%p)->(%x)\n", This, v);
59 nsres = nsIDOMHTMLImageElement_SetIsMap(This->nsimg, v != VARIANT_FALSE);
60 if (NS_FAILED(nsres)) {
61 ERR("Set IsMap failed: %08lx\n", nsres);
62 return E_FAIL;
65 return S_OK;
68 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
70 HTMLImg *This = impl_from_IHTMLImgElement(iface);
71 cpp_bool b;
72 nsresult nsres;
74 TRACE("(%p)->(%p)\n", This, p);
76 if (p == NULL)
77 return E_INVALIDARG;
79 nsres = nsIDOMHTMLImageElement_GetIsMap(This->nsimg, &b);
80 if (NS_FAILED(nsres)) {
81 ERR("Get IsMap failed: %08lx\n", nsres);
82 return E_FAIL;
85 *p = variant_bool(b);
86 return S_OK;
89 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
91 HTMLImg *This = impl_from_IHTMLImgElement(iface);
92 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
93 return E_NOTIMPL;
96 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
98 HTMLImg *This = impl_from_IHTMLImgElement(iface);
99 FIXME("(%p)->(%p)\n", This, p);
100 return E_NOTIMPL;
103 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
105 HTMLImg *This = impl_from_IHTMLImgElement(iface);
106 FIXME("(%p)->(%p)\n", This, p);
107 return E_NOTIMPL;
110 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
112 HTMLImg *This = impl_from_IHTMLImgElement(iface);
113 FIXME("(%p)->(%p)\n", This, p);
114 return E_NOTIMPL;
117 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
119 HTMLImg *This = impl_from_IHTMLImgElement(iface);
120 FIXME("(%p)->(%p)\n", This, p);
121 return E_NOTIMPL;
124 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
126 HTMLImg *This = impl_from_IHTMLImgElement(iface);
127 FIXME("(%p)->(%p)\n", This, p);
128 return E_NOTIMPL;
131 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
133 HTMLImg *This = impl_from_IHTMLImgElement(iface);
134 FIXME("(%p)->(%p)\n", This, p);
135 return E_NOTIMPL;
138 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
140 HTMLImg *This = impl_from_IHTMLImgElement(iface);
141 FIXME("(%p)->(%p)\n", This, p);
142 return E_NOTIMPL;
145 static HRESULT WINAPI HTMLImgElement_get_href(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_nameProp(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_put_border(IHTMLImgElement *iface, VARIANT v)
161 HTMLImg *This = impl_from_IHTMLImgElement(iface);
162 FIXME("(%p)->()\n", This);
163 return E_NOTIMPL;
166 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
168 HTMLImg *This = impl_from_IHTMLImgElement(iface);
169 FIXME("(%p)->(%p)\n", This, p);
170 return E_NOTIMPL;
173 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
175 HTMLImg *This = impl_from_IHTMLImgElement(iface);
176 FIXME("(%p)->(%ld)\n", This, v);
177 return E_NOTIMPL;
180 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
182 HTMLImg *This = impl_from_IHTMLImgElement(iface);
183 FIXME("(%p)->(%p)\n", This, p);
184 return E_NOTIMPL;
187 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
189 HTMLImg *This = impl_from_IHTMLImgElement(iface);
190 FIXME("(%p)->(%ld)\n", This, v);
191 return E_NOTIMPL;
194 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
196 HTMLImg *This = impl_from_IHTMLImgElement(iface);
197 FIXME("(%p)->(%p)\n", This, p);
198 return E_NOTIMPL;
201 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
203 HTMLImg *This = impl_from_IHTMLImgElement(iface);
204 nsAString alt_str;
205 nsresult nsres;
207 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
209 nsAString_InitDepend(&alt_str, v);
210 nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
211 nsAString_Finish(&alt_str);
212 if(NS_FAILED(nsres))
213 ERR("SetAlt failed: %08lx\n", nsres);
215 return S_OK;
218 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
220 HTMLImg *This = impl_from_IHTMLImgElement(iface);
221 nsAString alt_str;
222 nsresult nsres;
224 TRACE("(%p)->(%p)\n", This, p);
226 nsAString_Init(&alt_str, NULL);
227 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
228 return return_nsstr(nsres, &alt_str, p);
231 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
233 HTMLImg *This = impl_from_IHTMLImgElement(iface);
234 nsAString src_str;
235 nsresult nsres;
237 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
239 nsAString_InitDepend(&src_str, v);
240 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
241 nsAString_Finish(&src_str);
242 return map_nsresult(nsres);
245 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
247 HTMLImg *This = impl_from_IHTMLImgElement(iface);
248 const PRUnichar *src;
249 nsAString src_str;
250 nsresult nsres;
251 HRESULT hres = S_OK;
253 TRACE("(%p)->(%p)\n", This, p);
255 nsAString_Init(&src_str, NULL);
256 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
257 if(NS_SUCCEEDED(nsres)) {
258 nsAString_GetData(&src_str, &src);
260 if(!wcsnicmp(src, L"BLOCKED::", ARRAY_SIZE(L"BLOCKED::")-1)) {
261 TRACE("returning BLOCKED::\n");
262 *p = SysAllocString(L"BLOCKED::");
263 if(!*p)
264 hres = E_OUTOFMEMORY;
265 }else {
266 hres = nsuri_to_url(src, TRUE, p);
268 }else {
269 ERR("GetSrc failed: %08lx\n", nsres);
270 hres = E_FAIL;
273 nsAString_Finish(&src_str);
274 return hres;
277 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
279 HTMLImg *This = impl_from_IHTMLImgElement(iface);
280 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
281 return E_NOTIMPL;
284 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
286 HTMLImg *This = impl_from_IHTMLImgElement(iface);
287 FIXME("(%p)->(%p)\n", This, p);
288 return E_NOTIMPL;
291 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
293 HTMLImg *This = impl_from_IHTMLImgElement(iface);
294 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
295 return E_NOTIMPL;
298 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
300 HTMLImg *This = impl_from_IHTMLImgElement(iface);
301 FIXME("(%p)->(%p)\n", This, p);
302 return E_NOTIMPL;
305 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
307 HTMLImg *This = impl_from_IHTMLImgElement(iface);
308 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
309 return E_NOTIMPL;
312 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
314 HTMLImg *This = impl_from_IHTMLImgElement(iface);
315 FIXME("(%p)->(%p)\n", This, p);
316 return E_NOTIMPL;
319 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
321 HTMLImg *This = impl_from_IHTMLImgElement(iface);
322 FIXME("(%p)->(%p)\n", This, p);
323 return E_NOTIMPL;
326 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
328 HTMLImg *This = impl_from_IHTMLImgElement(iface);
329 cpp_bool complete;
330 nsresult nsres;
332 TRACE("(%p)->(%p)\n", This, p);
334 nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
335 if(NS_FAILED(nsres)) {
336 ERR("GetComplete failed: %08lx\n", nsres);
337 return E_FAIL;
340 *p = variant_bool(complete);
341 return S_OK;
344 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
346 HTMLImg *This = impl_from_IHTMLImgElement(iface);
347 FIXME("(%p)->()\n", This);
348 return E_NOTIMPL;
351 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
353 HTMLImg *This = impl_from_IHTMLImgElement(iface);
354 FIXME("(%p)->(%p)\n", This, p);
355 return E_NOTIMPL;
358 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
360 HTMLImg *This = impl_from_IHTMLImgElement(iface);
361 nsAString str;
362 nsresult nsres;
364 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
366 nsAString_InitDepend(&str, v);
368 nsres = nsIDOMHTMLImageElement_SetAlign(This->nsimg, &str);
369 nsAString_Finish(&str);
370 if (NS_FAILED(nsres)){
371 ERR("Set Align(%s) failed: %08lx\n", debugstr_w(v), nsres);
372 return E_FAIL;
375 return S_OK;
378 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
380 HTMLImg *This = impl_from_IHTMLImgElement(iface);
381 nsAString str;
382 nsresult nsres;
384 TRACE("(%p)->(%p)\n", This, p);
386 nsAString_Init(&str, NULL);
387 nsres = nsIDOMHTMLImageElement_GetAlign(This->nsimg, &str);
389 return return_nsstr(nsres, &str, p);
392 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
394 HTMLImg *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 HTMLImg *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 HTMLImg *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 HTMLImg *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 HTMLImg *This = impl_from_IHTMLImgElement(iface);
432 TRACE("(%p)->()\n", This);
434 return set_node_event(&This->element.node, EVENTID_ABORT, &v);
437 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
439 HTMLImg *This = impl_from_IHTMLImgElement(iface);
441 TRACE("(%p)->(%p)\n", This, p);
443 return get_node_event(&This->element.node, EVENTID_ABORT, p);
446 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
448 HTMLImg *This = impl_from_IHTMLImgElement(iface);
449 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
450 return E_NOTIMPL;
453 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
455 HTMLImg *This = impl_from_IHTMLImgElement(iface);
456 nsAString name;
457 nsresult nsres;
459 TRACE("(%p)->(%p)\n", This, p);
461 nsAString_Init(&name, NULL);
462 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
463 return return_nsstr(nsres, &name, p);
466 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
468 HTMLImg *This = impl_from_IHTMLImgElement(iface);
469 nsresult nsres;
471 TRACE("(%p)->(%ld)\n", This, v);
473 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
474 if(NS_FAILED(nsres)) {
475 ERR("SetWidth failed: %08lx\n", nsres);
476 return E_FAIL;
479 return S_OK;
482 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
484 HTMLImg *This = impl_from_IHTMLImgElement(iface);
485 UINT32 width;
486 nsresult nsres;
488 TRACE("(%p)->(%p)\n", This, p);
490 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
491 if(NS_FAILED(nsres)) {
492 ERR("GetWidth failed: %08lx\n", nsres);
493 return E_FAIL;
496 *p = width;
497 return S_OK;
500 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
502 HTMLImg *This = impl_from_IHTMLImgElement(iface);
503 nsresult nsres;
505 TRACE("(%p)->(%ld)\n", This, v);
507 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
508 if(NS_FAILED(nsres)) {
509 ERR("SetHeight failed: %08lx\n", nsres);
510 return E_FAIL;
513 return S_OK;
516 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
518 HTMLImg *This = impl_from_IHTMLImgElement(iface);
519 UINT32 height;
520 nsresult nsres;
522 TRACE("(%p)->(%p)\n", This, p);
524 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
525 if(NS_FAILED(nsres)) {
526 ERR("GetHeight failed: %08lx\n", nsres);
527 return E_FAIL;
530 *p = height;
531 return S_OK;
534 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
536 HTMLImg *This = impl_from_IHTMLImgElement(iface);
537 FIXME("(%p)->()\n", This);
538 return E_NOTIMPL;
541 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
543 HTMLImg *This = impl_from_IHTMLImgElement(iface);
544 FIXME("(%p)->(%p)\n", This, p);
545 return E_NOTIMPL;
548 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
549 HTMLImgElement_QueryInterface,
550 HTMLImgElement_AddRef,
551 HTMLImgElement_Release,
552 HTMLImgElement_GetTypeInfoCount,
553 HTMLImgElement_GetTypeInfo,
554 HTMLImgElement_GetIDsOfNames,
555 HTMLImgElement_Invoke,
556 HTMLImgElement_put_isMap,
557 HTMLImgElement_get_isMap,
558 HTMLImgElement_put_useMap,
559 HTMLImgElement_get_useMap,
560 HTMLImgElement_get_mimeType,
561 HTMLImgElement_get_fileSize,
562 HTMLImgElement_get_fileCreatedDate,
563 HTMLImgElement_get_fileModifiedDate,
564 HTMLImgElement_get_fileUpdatedDate,
565 HTMLImgElement_get_protocol,
566 HTMLImgElement_get_href,
567 HTMLImgElement_get_nameProp,
568 HTMLImgElement_put_border,
569 HTMLImgElement_get_border,
570 HTMLImgElement_put_vspace,
571 HTMLImgElement_get_vspace,
572 HTMLImgElement_put_hspace,
573 HTMLImgElement_get_hspace,
574 HTMLImgElement_put_alt,
575 HTMLImgElement_get_alt,
576 HTMLImgElement_put_src,
577 HTMLImgElement_get_src,
578 HTMLImgElement_put_lowsrc,
579 HTMLImgElement_get_lowsrc,
580 HTMLImgElement_put_vrml,
581 HTMLImgElement_get_vrml,
582 HTMLImgElement_put_dynsrc,
583 HTMLImgElement_get_dynsrc,
584 HTMLImgElement_get_readyState,
585 HTMLImgElement_get_complete,
586 HTMLImgElement_put_loop,
587 HTMLImgElement_get_loop,
588 HTMLImgElement_put_align,
589 HTMLImgElement_get_align,
590 HTMLImgElement_put_onload,
591 HTMLImgElement_get_onload,
592 HTMLImgElement_put_onerror,
593 HTMLImgElement_get_onerror,
594 HTMLImgElement_put_onabort,
595 HTMLImgElement_get_onabort,
596 HTMLImgElement_put_name,
597 HTMLImgElement_get_name,
598 HTMLImgElement_put_width,
599 HTMLImgElement_get_width,
600 HTMLImgElement_put_height,
601 HTMLImgElement_get_height,
602 HTMLImgElement_put_start,
603 HTMLImgElement_get_start
606 static inline HTMLImg *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
608 return CONTAINING_RECORD(iface, HTMLImg, element.node);
611 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
613 HTMLImg *This = impl_from_HTMLDOMNode(iface);
615 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
618 static inline HTMLImg *HTMLImg_from_DispatchEx(DispatchEx *iface)
620 return CONTAINING_RECORD(iface, HTMLImg, element.node.event_target.dispex);
623 static void *HTMLImgElement_query_interface(DispatchEx *dispex, REFIID riid)
625 HTMLImg *This = HTMLImg_from_DispatchEx(dispex);
627 if(IsEqualGUID(&IID_IHTMLImgElement, riid))
628 return &This->IHTMLImgElement_iface;
630 return HTMLElement_query_interface(&This->element.node.event_target.dispex, riid);
633 static void HTMLImgElement_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
635 HTMLImg *This = HTMLImg_from_DispatchEx(dispex);
636 HTMLElement_traverse(dispex, cb);
638 if(This->nsimg)
639 note_cc_edge((nsISupports*)This->nsimg, "nsimg", cb);
642 static void HTMLImgElement_unlink(DispatchEx *dispex)
644 HTMLImg *This = HTMLImg_from_DispatchEx(dispex);
645 HTMLElement_unlink(dispex);
646 unlink_ref(&This->nsimg);
649 static const NodeImplVtbl HTMLImgElementImplVtbl = {
650 .clsid = &CLSID_HTMLImg,
651 .cpc_entries = HTMLElement_cpc,
652 .clone = HTMLElement_clone,
653 .get_attr_col = HTMLElement_get_attr_col,
654 .get_readystate = HTMLImgElement_get_readystate,
657 static const event_target_vtbl_t HTMLImgElement_event_target_vtbl = {
659 HTMLELEMENT_DISPEX_VTBL_ENTRIES,
660 .query_interface= HTMLImgElement_query_interface,
661 .destructor = HTMLElement_destructor,
662 .traverse = HTMLImgElement_traverse,
663 .unlink = HTMLImgElement_unlink
665 HTMLELEMENT_EVENT_TARGET_VTBL_ENTRIES,
666 .handle_event = HTMLElement_handle_event
669 static const tid_t HTMLImgElement_iface_tids[] = {
670 HTMLELEMENT_TIDS,
674 static void HTMLImgElement_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
676 static const dispex_hook_t img_ie11_hooks[] = {
677 {DISPID_IHTMLIMGELEMENT_FILESIZE, NULL},
678 {DISPID_UNKNOWN}
681 HTMLElement_init_dispex_info(info, mode);
683 dispex_info_add_interface(info, IHTMLImgElement_tid, mode >= COMPAT_MODE_IE11 ? img_ie11_hooks : NULL);
686 static dispex_static_data_t HTMLImgElement_dispex = {
687 "HTMLImageElement",
688 &HTMLImgElement_event_target_vtbl.dispex_vtbl,
689 DispHTMLImg_tid,
690 HTMLImgElement_iface_tids,
691 HTMLImgElement_init_dispex_info
694 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
696 HTMLImg *ret;
697 nsresult nsres;
699 ret = calloc(1, sizeof(HTMLImg));
700 if(!ret)
701 return E_OUTOFMEMORY;
703 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
704 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
706 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
708 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
709 assert(nsres == NS_OK);
711 *elem = &ret->element;
712 return S_OK;
715 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
717 return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
720 DISPEX_IDISPATCH_IMPL(HTMLImageElementFactory, IHTMLImageElementFactory,
721 impl_from_IHTMLImageElementFactory(iface)->dispex)
723 static LONG var_to_size(const VARIANT *v)
725 switch(V_VT(v)) {
726 case VT_EMPTY:
727 return 0;
728 case VT_I4:
729 return V_I4(v);
730 case VT_BSTR: {
731 LONG ret;
732 HRESULT hres;
734 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
735 if(FAILED(hres)) {
736 FIXME("VarI4FromStr failed: %08lx\n", hres);
737 return 0;
739 return ret;
741 default:
742 FIXME("unsupported size %s\n", debugstr_variant(v));
744 return 0;
747 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
748 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
750 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
751 HTMLDocumentNode *doc = This->window->doc;
752 IHTMLImgElement *img;
753 HTMLElement *elem;
754 nsIDOMElement *nselem;
755 LONG l;
756 HRESULT hres;
758 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
759 debugstr_variant(&height), img_elem);
761 *img_elem = NULL;
763 hres = create_nselem(doc, L"IMG", &nselem);
764 if(FAILED(hres))
765 return hres;
767 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
768 nsIDOMElement_Release(nselem);
769 if(FAILED(hres)) {
770 ERR("HTMLElement_Create failed\n");
771 return hres;
774 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
775 (void**)&img);
776 IHTMLElement_Release(&elem->IHTMLElement_iface);
777 if(FAILED(hres)) {
778 ERR("IHTMLElement_QueryInterface failed: 0x%08lx\n", hres);
779 return hres;
782 l = var_to_size(&width);
783 if(l)
784 IHTMLImgElement_put_width(img, l);
785 l = var_to_size(&height);
786 if(l)
787 IHTMLImgElement_put_height(img, l);
789 *img_elem = img;
790 return S_OK;
793 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
794 HTMLImageElementFactory_QueryInterface,
795 HTMLImageElementFactory_AddRef,
796 HTMLImageElementFactory_Release,
797 HTMLImageElementFactory_GetTypeInfoCount,
798 HTMLImageElementFactory_GetTypeInfo,
799 HTMLImageElementFactory_GetIDsOfNames,
800 HTMLImageElementFactory_Invoke,
801 HTMLImageElementFactory_create
804 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
806 return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
809 static void *HTMLImageElementFactory_query_interface(DispatchEx *dispex, REFIID riid)
811 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
813 if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid))
814 return &This->IHTMLImageElementFactory_iface;
816 return NULL;
819 static void HTMLImageElementFactory_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
821 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
823 if(This->window)
824 note_cc_edge((nsISupports*)&This->window->base.IHTMLWindow2_iface, "window", cb);
827 static void HTMLImageElementFactory_unlink(DispatchEx *dispex)
829 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
831 if(This->window) {
832 HTMLInnerWindow *window = This->window;
833 This->window = NULL;
834 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
838 static void HTMLImageElementFactory_destructor(DispatchEx *dispex)
840 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
841 free(This);
844 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
845 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
846 IServiceProvider *caller)
848 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
849 IHTMLImgElement *img;
850 VARIANT empty, *width, *height;
851 HRESULT hres;
852 int argc = params->cArgs - params->cNamedArgs;
854 V_VT(res) = VT_NULL;
856 V_VT(&empty) = VT_EMPTY;
858 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
859 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
861 hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
862 &img);
863 if(FAILED(hres))
864 return hres;
866 V_VT(res) = VT_DISPATCH;
867 V_DISPATCH(res) = (IDispatch*)img;
869 return S_OK;
872 static const tid_t HTMLImageElementFactory_iface_tids[] = {
873 IHTMLImageElementFactory_tid,
877 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
878 .query_interface = HTMLImageElementFactory_query_interface,
879 .destructor = HTMLImageElementFactory_destructor,
880 .traverse = HTMLImageElementFactory_traverse,
881 .unlink = HTMLImageElementFactory_unlink,
882 .value = HTMLImageElementFactory_value,
885 static dispex_static_data_t HTMLImageElementFactory_dispex = {
886 "Function",
887 &HTMLImageElementFactory_dispex_vtbl,
888 IHTMLImageElementFactory_tid,
889 HTMLImageElementFactory_iface_tids
892 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
894 HTMLImageElementFactory *ret;
896 ret = malloc(sizeof(HTMLImageElementFactory));
897 if(!ret)
898 return E_OUTOFMEMORY;
900 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
901 ret->window = window;
902 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
904 init_dispatch(&ret->dispex, &HTMLImageElementFactory_dispex, NULL,
905 dispex_compat_mode(&window->event_target.dispex));
907 *ret_val = ret;
908 return S_OK;