mshtml: Send load event synchronously for img elements that loaded instantly in legac...
[wine.git] / dlls / mshtml / htmlimg.c
blobd8c377413f0a7342fb32fb64624bf52ea9ac0f0f
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;
42 eventid_t skip_event;
45 static inline HTMLImg *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
47 return CONTAINING_RECORD(iface, HTMLImg, IHTMLImgElement_iface);
50 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
52 HTMLImg *This = impl_from_IHTMLImgElement(iface);
54 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
57 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
59 HTMLImg *This = impl_from_IHTMLImgElement(iface);
61 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
64 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
66 HTMLImg *This = impl_from_IHTMLImgElement(iface);
68 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
71 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
73 HTMLImg *This = impl_from_IHTMLImgElement(iface);
74 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
77 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
78 LCID lcid, ITypeInfo **ppTInfo)
80 HTMLImg *This = impl_from_IHTMLImgElement(iface);
81 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
82 ppTInfo);
85 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
86 LPOLESTR *rgszNames, UINT cNames,
87 LCID lcid, DISPID *rgDispId)
89 HTMLImg *This = impl_from_IHTMLImgElement(iface);
90 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
91 cNames, lcid, rgDispId);
94 static HRESULT WINAPI HTMLImgElement_Invoke(IHTMLImgElement *iface, DISPID dispIdMember,
95 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
96 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
98 HTMLImg *This = impl_from_IHTMLImgElement(iface);
99 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
100 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
103 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
105 HTMLImg *This = impl_from_IHTMLImgElement(iface);
106 nsresult nsres;
108 TRACE("(%p)->(%x)\n", This, v);
110 nsres = nsIDOMHTMLImageElement_SetIsMap(This->nsimg, v != VARIANT_FALSE);
111 if (NS_FAILED(nsres)) {
112 ERR("Set IsMap failed: %08lx\n", nsres);
113 return E_FAIL;
116 return S_OK;
119 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
121 HTMLImg *This = impl_from_IHTMLImgElement(iface);
122 cpp_bool b;
123 nsresult nsres;
125 TRACE("(%p)->(%p)\n", This, p);
127 if (p == NULL)
128 return E_INVALIDARG;
130 nsres = nsIDOMHTMLImageElement_GetIsMap(This->nsimg, &b);
131 if (NS_FAILED(nsres)) {
132 ERR("Get IsMap failed: %08lx\n", nsres);
133 return E_FAIL;
136 *p = variant_bool(b);
137 return S_OK;
140 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
142 HTMLImg *This = impl_from_IHTMLImgElement(iface);
143 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
144 return E_NOTIMPL;
147 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
149 HTMLImg *This = impl_from_IHTMLImgElement(iface);
150 FIXME("(%p)->(%p)\n", This, p);
151 return E_NOTIMPL;
154 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
156 HTMLImg *This = impl_from_IHTMLImgElement(iface);
157 FIXME("(%p)->(%p)\n", This, p);
158 return E_NOTIMPL;
161 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
163 HTMLImg *This = impl_from_IHTMLImgElement(iface);
164 FIXME("(%p)->(%p)\n", This, p);
165 return E_NOTIMPL;
168 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
170 HTMLImg *This = impl_from_IHTMLImgElement(iface);
171 FIXME("(%p)->(%p)\n", This, p);
172 return E_NOTIMPL;
175 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
177 HTMLImg *This = impl_from_IHTMLImgElement(iface);
178 FIXME("(%p)->(%p)\n", This, p);
179 return E_NOTIMPL;
182 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
184 HTMLImg *This = impl_from_IHTMLImgElement(iface);
185 FIXME("(%p)->(%p)\n", This, p);
186 return E_NOTIMPL;
189 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
191 HTMLImg *This = impl_from_IHTMLImgElement(iface);
192 FIXME("(%p)->(%p)\n", This, p);
193 return E_NOTIMPL;
196 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
198 HTMLImg *This = impl_from_IHTMLImgElement(iface);
199 FIXME("(%p)->(%p)\n", This, p);
200 return E_NOTIMPL;
203 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
205 HTMLImg *This = impl_from_IHTMLImgElement(iface);
206 FIXME("(%p)->(%p)\n", This, p);
207 return E_NOTIMPL;
210 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
212 HTMLImg *This = impl_from_IHTMLImgElement(iface);
213 FIXME("(%p)->()\n", This);
214 return E_NOTIMPL;
217 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
219 HTMLImg *This = impl_from_IHTMLImgElement(iface);
220 FIXME("(%p)->(%p)\n", This, p);
221 return E_NOTIMPL;
224 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
226 HTMLImg *This = impl_from_IHTMLImgElement(iface);
227 FIXME("(%p)->(%ld)\n", This, v);
228 return E_NOTIMPL;
231 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
233 HTMLImg *This = impl_from_IHTMLImgElement(iface);
234 FIXME("(%p)->(%p)\n", This, p);
235 return E_NOTIMPL;
238 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
240 HTMLImg *This = impl_from_IHTMLImgElement(iface);
241 FIXME("(%p)->(%ld)\n", This, v);
242 return E_NOTIMPL;
245 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
247 HTMLImg *This = impl_from_IHTMLImgElement(iface);
248 FIXME("(%p)->(%p)\n", This, p);
249 return E_NOTIMPL;
252 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
254 HTMLImg *This = impl_from_IHTMLImgElement(iface);
255 nsAString alt_str;
256 nsresult nsres;
258 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
260 nsAString_InitDepend(&alt_str, v);
261 nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
262 nsAString_Finish(&alt_str);
263 if(NS_FAILED(nsres))
264 ERR("SetAlt failed: %08lx\n", nsres);
266 return S_OK;
269 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
271 HTMLImg *This = impl_from_IHTMLImgElement(iface);
272 nsAString alt_str;
273 nsresult nsres;
275 TRACE("(%p)->(%p)\n", This, p);
277 nsAString_Init(&alt_str, NULL);
278 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
279 return return_nsstr(nsres, &alt_str, p);
282 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
284 HTMLImg *This = impl_from_IHTMLImgElement(iface);
285 HRESULT hres = S_OK;
286 nsAString src_str;
287 nsresult nsres;
289 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
291 nsAString_InitDepend(&src_str, v);
292 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
293 nsAString_Finish(&src_str);
294 if(NS_FAILED(nsres))
295 ERR("SetSrc failed: %08lx\n", nsres);
297 if(dispex_compat_mode(&This->element.node.event_target.dispex) < COMPAT_MODE_IE9) {
298 eventid_t eventid;
299 cpp_bool complete;
300 UINT32 height = 0;
301 DOMEvent *event;
303 /* Synchronously send load event if the image was completed immediately (such as from cache) */
304 This->skip_event = EVENTID_INVALID;
306 nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
307 if(NS_SUCCEEDED(nsres) && complete) {
308 nsIDOMHTMLImageElement_GetNaturalHeight(This->nsimg, &height);
309 eventid = height ? EVENTID_LOAD : EVENTID_ERROR;
311 hres = create_document_event(This->element.node.doc, eventid, &event);
312 if(SUCCEEDED(hres)) {
313 This->skip_event = eventid;
314 dispatch_event(&This->element.node.event_target, event);
315 IDOMEvent_Release(&event->IDOMEvent_iface);
319 return hres;
322 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
324 HTMLImg *This = impl_from_IHTMLImgElement(iface);
325 const PRUnichar *src;
326 nsAString src_str;
327 nsresult nsres;
328 HRESULT hres = S_OK;
330 TRACE("(%p)->(%p)\n", This, p);
332 nsAString_Init(&src_str, NULL);
333 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
334 if(NS_SUCCEEDED(nsres)) {
335 nsAString_GetData(&src_str, &src);
337 if(!wcsnicmp(src, L"BLOCKED::", ARRAY_SIZE(L"BLOCKED::")-1)) {
338 TRACE("returning BLOCKED::\n");
339 *p = SysAllocString(L"BLOCKED::");
340 if(!*p)
341 hres = E_OUTOFMEMORY;
342 }else {
343 hres = nsuri_to_url(src, TRUE, p);
345 }else {
346 ERR("GetSrc failed: %08lx\n", nsres);
347 hres = E_FAIL;
350 nsAString_Finish(&src_str);
351 return hres;
354 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
356 HTMLImg *This = impl_from_IHTMLImgElement(iface);
357 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
358 return E_NOTIMPL;
361 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
363 HTMLImg *This = impl_from_IHTMLImgElement(iface);
364 FIXME("(%p)->(%p)\n", This, p);
365 return E_NOTIMPL;
368 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
370 HTMLImg *This = impl_from_IHTMLImgElement(iface);
371 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
372 return E_NOTIMPL;
375 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
377 HTMLImg *This = impl_from_IHTMLImgElement(iface);
378 FIXME("(%p)->(%p)\n", This, p);
379 return E_NOTIMPL;
382 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
384 HTMLImg *This = impl_from_IHTMLImgElement(iface);
385 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
386 return E_NOTIMPL;
389 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
391 HTMLImg *This = impl_from_IHTMLImgElement(iface);
392 FIXME("(%p)->(%p)\n", This, p);
393 return E_NOTIMPL;
396 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
398 HTMLImg *This = impl_from_IHTMLImgElement(iface);
399 FIXME("(%p)->(%p)\n", This, p);
400 return E_NOTIMPL;
403 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
405 HTMLImg *This = impl_from_IHTMLImgElement(iface);
406 cpp_bool complete;
407 nsresult nsres;
409 TRACE("(%p)->(%p)\n", This, p);
411 nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
412 if(NS_FAILED(nsres)) {
413 ERR("GetComplete failed: %08lx\n", nsres);
414 return E_FAIL;
417 *p = variant_bool(complete);
418 return S_OK;
421 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
423 HTMLImg *This = impl_from_IHTMLImgElement(iface);
424 FIXME("(%p)->()\n", This);
425 return E_NOTIMPL;
428 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
430 HTMLImg *This = impl_from_IHTMLImgElement(iface);
431 FIXME("(%p)->(%p)\n", This, p);
432 return E_NOTIMPL;
435 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
437 HTMLImg *This = impl_from_IHTMLImgElement(iface);
438 nsAString str;
439 nsresult nsres;
441 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
443 nsAString_InitDepend(&str, v);
445 nsres = nsIDOMHTMLImageElement_SetAlign(This->nsimg, &str);
446 nsAString_Finish(&str);
447 if (NS_FAILED(nsres)){
448 ERR("Set Align(%s) failed: %08lx\n", debugstr_w(v), nsres);
449 return E_FAIL;
452 return S_OK;
455 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
457 HTMLImg *This = impl_from_IHTMLImgElement(iface);
458 nsAString str;
459 nsresult nsres;
461 TRACE("(%p)->(%p)\n", This, p);
463 nsAString_Init(&str, NULL);
464 nsres = nsIDOMHTMLImageElement_GetAlign(This->nsimg, &str);
466 return return_nsstr(nsres, &str, p);
469 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
471 HTMLImg *This = impl_from_IHTMLImgElement(iface);
473 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
475 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
478 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
480 HTMLImg *This = impl_from_IHTMLImgElement(iface);
482 TRACE("(%p)->(%p)\n", This, p);
484 return get_node_event(&This->element.node, EVENTID_LOAD, p);
487 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
489 HTMLImg *This = impl_from_IHTMLImgElement(iface);
491 TRACE("(%p)->()\n", This);
493 return set_node_event(&This->element.node, EVENTID_ERROR, &v);
496 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
498 HTMLImg *This = impl_from_IHTMLImgElement(iface);
500 TRACE("(%p)->(%p)\n", This, p);
502 return get_node_event(&This->element.node, EVENTID_ERROR, p);
505 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
507 HTMLImg *This = impl_from_IHTMLImgElement(iface);
509 TRACE("(%p)->()\n", This);
511 return set_node_event(&This->element.node, EVENTID_ABORT, &v);
514 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
516 HTMLImg *This = impl_from_IHTMLImgElement(iface);
518 TRACE("(%p)->(%p)\n", This, p);
520 return get_node_event(&This->element.node, EVENTID_ABORT, p);
523 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
525 HTMLImg *This = impl_from_IHTMLImgElement(iface);
526 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
527 return E_NOTIMPL;
530 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
532 HTMLImg *This = impl_from_IHTMLImgElement(iface);
533 nsAString name;
534 nsresult nsres;
536 TRACE("(%p)->(%p)\n", This, p);
538 nsAString_Init(&name, NULL);
539 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
540 return return_nsstr(nsres, &name, p);
543 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
545 HTMLImg *This = impl_from_IHTMLImgElement(iface);
546 nsresult nsres;
548 TRACE("(%p)->(%ld)\n", This, v);
550 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
551 if(NS_FAILED(nsres)) {
552 ERR("SetWidth failed: %08lx\n", nsres);
553 return E_FAIL;
556 return S_OK;
559 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
561 HTMLImg *This = impl_from_IHTMLImgElement(iface);
562 UINT32 width;
563 nsresult nsres;
565 TRACE("(%p)->(%p)\n", This, p);
567 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
568 if(NS_FAILED(nsres)) {
569 ERR("GetWidth failed: %08lx\n", nsres);
570 return E_FAIL;
573 *p = width;
574 return S_OK;
577 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
579 HTMLImg *This = impl_from_IHTMLImgElement(iface);
580 nsresult nsres;
582 TRACE("(%p)->(%ld)\n", This, v);
584 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
585 if(NS_FAILED(nsres)) {
586 ERR("SetHeight failed: %08lx\n", nsres);
587 return E_FAIL;
590 return S_OK;
593 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
595 HTMLImg *This = impl_from_IHTMLImgElement(iface);
596 UINT32 height;
597 nsresult nsres;
599 TRACE("(%p)->(%p)\n", This, p);
601 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
602 if(NS_FAILED(nsres)) {
603 ERR("GetHeight failed: %08lx\n", nsres);
604 return E_FAIL;
607 *p = height;
608 return S_OK;
611 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
613 HTMLImg *This = impl_from_IHTMLImgElement(iface);
614 FIXME("(%p)->()\n", This);
615 return E_NOTIMPL;
618 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
620 HTMLImg *This = impl_from_IHTMLImgElement(iface);
621 FIXME("(%p)->(%p)\n", This, p);
622 return E_NOTIMPL;
625 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
626 HTMLImgElement_QueryInterface,
627 HTMLImgElement_AddRef,
628 HTMLImgElement_Release,
629 HTMLImgElement_GetTypeInfoCount,
630 HTMLImgElement_GetTypeInfo,
631 HTMLImgElement_GetIDsOfNames,
632 HTMLImgElement_Invoke,
633 HTMLImgElement_put_isMap,
634 HTMLImgElement_get_isMap,
635 HTMLImgElement_put_useMap,
636 HTMLImgElement_get_useMap,
637 HTMLImgElement_get_mimeType,
638 HTMLImgElement_get_fileSize,
639 HTMLImgElement_get_fileCreatedDate,
640 HTMLImgElement_get_fileModifiedDate,
641 HTMLImgElement_get_fileUpdatedDate,
642 HTMLImgElement_get_protocol,
643 HTMLImgElement_get_href,
644 HTMLImgElement_get_nameProp,
645 HTMLImgElement_put_border,
646 HTMLImgElement_get_border,
647 HTMLImgElement_put_vspace,
648 HTMLImgElement_get_vspace,
649 HTMLImgElement_put_hspace,
650 HTMLImgElement_get_hspace,
651 HTMLImgElement_put_alt,
652 HTMLImgElement_get_alt,
653 HTMLImgElement_put_src,
654 HTMLImgElement_get_src,
655 HTMLImgElement_put_lowsrc,
656 HTMLImgElement_get_lowsrc,
657 HTMLImgElement_put_vrml,
658 HTMLImgElement_get_vrml,
659 HTMLImgElement_put_dynsrc,
660 HTMLImgElement_get_dynsrc,
661 HTMLImgElement_get_readyState,
662 HTMLImgElement_get_complete,
663 HTMLImgElement_put_loop,
664 HTMLImgElement_get_loop,
665 HTMLImgElement_put_align,
666 HTMLImgElement_get_align,
667 HTMLImgElement_put_onload,
668 HTMLImgElement_get_onload,
669 HTMLImgElement_put_onerror,
670 HTMLImgElement_get_onerror,
671 HTMLImgElement_put_onabort,
672 HTMLImgElement_get_onabort,
673 HTMLImgElement_put_name,
674 HTMLImgElement_get_name,
675 HTMLImgElement_put_width,
676 HTMLImgElement_get_width,
677 HTMLImgElement_put_height,
678 HTMLImgElement_get_height,
679 HTMLImgElement_put_start,
680 HTMLImgElement_get_start
683 static inline HTMLImg *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
685 return CONTAINING_RECORD(iface, HTMLImg, element.node);
688 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
690 HTMLImg *This = impl_from_HTMLDOMNode(iface);
692 *ppv = NULL;
694 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
695 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
696 *ppv = &This->IHTMLImgElement_iface;
697 }else {
698 return HTMLElement_QI(&This->element.node, riid, ppv);
701 IUnknown_AddRef((IUnknown*)*ppv);
702 return S_OK;
705 static HRESULT HTMLImgElement_dispatch_nsevent_hook(HTMLDOMNode *iface, DOMEvent *event)
707 HTMLImg *This = impl_from_HTMLDOMNode(iface);
709 if(event->event_id == This->skip_event) {
710 This->skip_event = EVENTID_INVALID;
711 return S_OK;
714 return S_FALSE;
717 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
719 HTMLImg *This = impl_from_HTMLDOMNode(iface);
721 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
724 static void HTMLImgElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
726 HTMLImg *This = impl_from_HTMLDOMNode(iface);
728 if(This->nsimg)
729 note_cc_edge((nsISupports*)This->nsimg, "This->nsimg", cb);
732 static void HTMLImgElement_unlink(HTMLDOMNode *iface)
734 HTMLImg *This = impl_from_HTMLDOMNode(iface);
736 if(This->nsimg) {
737 nsIDOMHTMLImageElement *nsimg = This->nsimg;
739 This->nsimg = NULL;
740 nsIDOMHTMLImageElement_Release(nsimg);
744 static const NodeImplVtbl HTMLImgElementImplVtbl = {
745 &CLSID_HTMLImg,
746 HTMLImgElement_QI,
747 HTMLElement_destructor,
748 HTMLElement_cpc,
749 HTMLElement_clone,
750 HTMLImgElement_dispatch_nsevent_hook,
751 HTMLElement_handle_event,
752 HTMLElement_get_attr_col,
753 NULL,
754 NULL,
755 NULL,
756 NULL,
757 HTMLImgElement_get_readystate,
758 NULL,
759 NULL,
760 NULL,
761 NULL,
762 HTMLImgElement_traverse,
763 HTMLImgElement_unlink
766 static const tid_t HTMLImgElement_iface_tids[] = {
767 HTMLELEMENT_TIDS,
771 static void HTMLImgElement_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
773 static const dispex_hook_t img_ie11_hooks[] = {
774 {DISPID_IHTMLIMGELEMENT_FILESIZE, NULL},
775 {DISPID_UNKNOWN}
778 HTMLElement_init_dispex_info(info, mode);
780 dispex_info_add_interface(info, IHTMLImgElement_tid, mode >= COMPAT_MODE_IE11 ? img_ie11_hooks : NULL);
783 static dispex_static_data_t HTMLImgElement_dispex = {
784 L"HTMLImageElement",
785 NULL,
786 DispHTMLImg_tid,
787 HTMLImgElement_iface_tids,
788 HTMLImgElement_init_dispex_info
791 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
793 HTMLImg *ret;
794 nsresult nsres;
796 ret = calloc(1, sizeof(HTMLImg));
797 if(!ret)
798 return E_OUTOFMEMORY;
800 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
801 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
802 ret->skip_event = EVENTID_INVALID;
804 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
806 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
807 assert(nsres == NS_OK);
809 *elem = &ret->element;
810 return S_OK;
813 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
815 return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
818 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
819 REFIID riid, void **ppv)
821 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
823 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
825 if(IsEqualGUID(&IID_IUnknown, riid)) {
826 *ppv = &This->IHTMLImageElementFactory_iface;
827 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
828 *ppv = &This->IHTMLImageElementFactory_iface;
829 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
830 return *ppv ? S_OK : E_NOINTERFACE;
831 }else {
832 *ppv = NULL;
833 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
834 return E_NOINTERFACE;
837 IUnknown_AddRef((IUnknown*)*ppv);
838 return S_OK;
841 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
843 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
844 LONG ref = InterlockedIncrement(&This->ref);
846 TRACE("(%p) ref=%ld\n", This, ref);
848 return ref;
851 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
853 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
854 LONG ref = InterlockedDecrement(&This->ref);
856 TRACE("(%p) ref=%ld\n", This, ref);
858 if(!ref)
859 free(This);
861 return ref;
864 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
865 UINT *pctinfo)
867 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
868 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
871 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
872 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
874 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
875 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
878 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
879 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
880 DISPID *rgDispId)
882 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
883 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
886 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
887 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
888 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
889 UINT *puArgErr)
891 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
892 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
893 pDispParams, pVarResult, pExcepInfo, puArgErr);
896 static LONG var_to_size(const VARIANT *v)
898 switch(V_VT(v)) {
899 case VT_EMPTY:
900 return 0;
901 case VT_I4:
902 return V_I4(v);
903 case VT_BSTR: {
904 LONG ret;
905 HRESULT hres;
907 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
908 if(FAILED(hres)) {
909 FIXME("VarI4FromStr failed: %08lx\n", hres);
910 return 0;
912 return ret;
914 default:
915 FIXME("unsupported size %s\n", debugstr_variant(v));
917 return 0;
920 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
921 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
923 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
924 HTMLDocumentNode *doc;
925 IHTMLImgElement *img;
926 HTMLElement *elem;
927 nsIDOMElement *nselem;
928 LONG l;
929 HRESULT hres;
931 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
932 debugstr_variant(&height), img_elem);
934 if(!This->window || !This->window->doc) {
935 WARN("NULL doc\n");
936 return E_UNEXPECTED;
939 doc = This->window->doc;
941 *img_elem = NULL;
943 hres = create_nselem(doc, L"IMG", &nselem);
944 if(FAILED(hres))
945 return hres;
947 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
948 nsIDOMElement_Release(nselem);
949 if(FAILED(hres)) {
950 ERR("HTMLElement_Create failed\n");
951 return hres;
954 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
955 (void**)&img);
956 IHTMLElement_Release(&elem->IHTMLElement_iface);
957 if(FAILED(hres)) {
958 ERR("IHTMLElement_QueryInterface failed: 0x%08lx\n", hres);
959 return hres;
962 l = var_to_size(&width);
963 if(l)
964 IHTMLImgElement_put_width(img, l);
965 l = var_to_size(&height);
966 if(l)
967 IHTMLImgElement_put_height(img, l);
969 *img_elem = img;
970 return S_OK;
973 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
974 HTMLImageElementFactory_QueryInterface,
975 HTMLImageElementFactory_AddRef,
976 HTMLImageElementFactory_Release,
977 HTMLImageElementFactory_GetTypeInfoCount,
978 HTMLImageElementFactory_GetTypeInfo,
979 HTMLImageElementFactory_GetIDsOfNames,
980 HTMLImageElementFactory_Invoke,
981 HTMLImageElementFactory_create
984 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
986 return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
989 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
990 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
991 IServiceProvider *caller)
993 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
994 IHTMLImgElement *img;
995 VARIANT empty, *width, *height;
996 HRESULT hres;
997 int argc = params->cArgs - params->cNamedArgs;
999 V_VT(res) = VT_NULL;
1001 V_VT(&empty) = VT_EMPTY;
1003 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
1004 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
1006 hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
1007 &img);
1008 if(FAILED(hres))
1009 return hres;
1011 V_VT(res) = VT_DISPATCH;
1012 V_DISPATCH(res) = (IDispatch*)img;
1014 return S_OK;
1017 static const tid_t HTMLImageElementFactory_iface_tids[] = {
1018 IHTMLImageElementFactory_tid,
1022 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
1023 HTMLImageElementFactory_value,
1024 NULL,
1025 NULL,
1026 NULL
1029 static dispex_static_data_t HTMLImageElementFactory_dispex = {
1030 L"Function",
1031 &HTMLImageElementFactory_dispex_vtbl,
1032 IHTMLImageElementFactory_tid,
1033 HTMLImageElementFactory_iface_tids
1036 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
1038 HTMLImageElementFactory *ret;
1040 ret = malloc(sizeof(HTMLImageElementFactory));
1041 if(!ret)
1042 return E_OUTOFMEMORY;
1044 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
1045 ret->ref = 1;
1046 ret->window = window;
1048 init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
1049 &HTMLImageElementFactory_dispex, dispex_compat_mode(&window->event_target.dispex));
1051 *ret_val = ret;
1052 return S_OK;