mshtml: Improved IDOMMouseEvent::offset[XY] stubs.
[wine.git] / dlls / mshtml / htmlimg.c
blob90681e47834a1e6f0752faa88a1077334cd888ec
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>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.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 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
51 HTMLImg *This = impl_from_IHTMLImgElement(iface);
53 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
56 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
58 HTMLImg *This = impl_from_IHTMLImgElement(iface);
60 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
63 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
65 HTMLImg *This = impl_from_IHTMLImgElement(iface);
67 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
70 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
72 HTMLImg *This = impl_from_IHTMLImgElement(iface);
73 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
76 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
77 LCID lcid, ITypeInfo **ppTInfo)
79 HTMLImg *This = impl_from_IHTMLImgElement(iface);
80 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
81 ppTInfo);
84 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
85 LPOLESTR *rgszNames, UINT cNames,
86 LCID lcid, DISPID *rgDispId)
88 HTMLImg *This = impl_from_IHTMLImgElement(iface);
89 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
90 cNames, lcid, rgDispId);
93 static HRESULT WINAPI HTMLImgElement_Invoke(IHTMLImgElement *iface, DISPID dispIdMember,
94 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
97 HTMLImg *This = impl_from_IHTMLImgElement(iface);
98 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
99 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
102 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
104 HTMLImg *This = impl_from_IHTMLImgElement(iface);
105 nsresult nsres;
107 TRACE("(%p)->(%x)\n", This, v);
109 nsres = nsIDOMHTMLImageElement_SetIsMap(This->nsimg, v != VARIANT_FALSE);
110 if (NS_FAILED(nsres)) {
111 ERR("Set IsMap failed: %08x\n", nsres);
112 return E_FAIL;
115 return S_OK;
118 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
120 HTMLImg *This = impl_from_IHTMLImgElement(iface);
121 cpp_bool b;
122 nsresult nsres;
124 TRACE("(%p)->(%p)\n", This, p);
126 if (p == NULL)
127 return E_INVALIDARG;
129 nsres = nsIDOMHTMLImageElement_GetIsMap(This->nsimg, &b);
130 if (NS_FAILED(nsres)) {
131 ERR("Get IsMap failed: %08x\n", nsres);
132 return E_FAIL;
135 *p = variant_bool(b);
136 return S_OK;
139 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
141 HTMLImg *This = impl_from_IHTMLImgElement(iface);
142 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
143 return E_NOTIMPL;
146 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
148 HTMLImg *This = impl_from_IHTMLImgElement(iface);
149 FIXME("(%p)->(%p)\n", This, p);
150 return E_NOTIMPL;
153 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
155 HTMLImg *This = impl_from_IHTMLImgElement(iface);
156 FIXME("(%p)->(%p)\n", This, p);
157 return E_NOTIMPL;
160 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
162 HTMLImg *This = impl_from_IHTMLImgElement(iface);
163 FIXME("(%p)->(%p)\n", This, p);
164 return E_NOTIMPL;
167 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
169 HTMLImg *This = impl_from_IHTMLImgElement(iface);
170 FIXME("(%p)->(%p)\n", This, p);
171 return E_NOTIMPL;
174 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
176 HTMLImg *This = impl_from_IHTMLImgElement(iface);
177 FIXME("(%p)->(%p)\n", This, p);
178 return E_NOTIMPL;
181 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
183 HTMLImg *This = impl_from_IHTMLImgElement(iface);
184 FIXME("(%p)->(%p)\n", This, p);
185 return E_NOTIMPL;
188 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
190 HTMLImg *This = impl_from_IHTMLImgElement(iface);
191 FIXME("(%p)->(%p)\n", This, p);
192 return E_NOTIMPL;
195 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
197 HTMLImg *This = impl_from_IHTMLImgElement(iface);
198 FIXME("(%p)->(%p)\n", This, p);
199 return E_NOTIMPL;
202 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
204 HTMLImg *This = impl_from_IHTMLImgElement(iface);
205 FIXME("(%p)->(%p)\n", This, p);
206 return E_NOTIMPL;
209 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
211 HTMLImg *This = impl_from_IHTMLImgElement(iface);
212 FIXME("(%p)->()\n", This);
213 return E_NOTIMPL;
216 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
218 HTMLImg *This = impl_from_IHTMLImgElement(iface);
219 FIXME("(%p)->(%p)\n", This, p);
220 return E_NOTIMPL;
223 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
225 HTMLImg *This = impl_from_IHTMLImgElement(iface);
226 FIXME("(%p)->(%d)\n", This, v);
227 return E_NOTIMPL;
230 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
232 HTMLImg *This = impl_from_IHTMLImgElement(iface);
233 FIXME("(%p)->(%p)\n", This, p);
234 return E_NOTIMPL;
237 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
239 HTMLImg *This = impl_from_IHTMLImgElement(iface);
240 FIXME("(%p)->(%d)\n", This, v);
241 return E_NOTIMPL;
244 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
246 HTMLImg *This = impl_from_IHTMLImgElement(iface);
247 FIXME("(%p)->(%p)\n", This, p);
248 return E_NOTIMPL;
251 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
253 HTMLImg *This = impl_from_IHTMLImgElement(iface);
254 nsAString alt_str;
255 nsresult nsres;
257 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
259 nsAString_InitDepend(&alt_str, v);
260 nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
261 nsAString_Finish(&alt_str);
262 if(NS_FAILED(nsres))
263 ERR("SetAlt failed: %08x\n", nsres);
265 return S_OK;
268 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
270 HTMLImg *This = impl_from_IHTMLImgElement(iface);
271 nsAString alt_str;
272 nsresult nsres;
274 TRACE("(%p)->(%p)\n", This, p);
276 nsAString_Init(&alt_str, NULL);
277 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
278 return return_nsstr(nsres, &alt_str, p);
281 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
283 HTMLImg *This = impl_from_IHTMLImgElement(iface);
284 nsAString src_str;
285 nsresult nsres;
287 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
289 nsAString_InitDepend(&src_str, v);
290 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
291 nsAString_Finish(&src_str);
292 if(NS_FAILED(nsres))
293 ERR("SetSrc failed: %08x\n", nsres);
295 return S_OK;
298 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
300 HTMLImg *This = impl_from_IHTMLImgElement(iface);
301 const PRUnichar *src;
302 nsAString src_str;
303 nsresult nsres;
304 HRESULT hres = S_OK;
306 static const WCHAR blockedW[] = {'B','L','O','C','K','E','D',':',':',0};
308 TRACE("(%p)->(%p)\n", This, p);
310 nsAString_Init(&src_str, NULL);
311 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
312 if(NS_SUCCEEDED(nsres)) {
313 nsAString_GetData(&src_str, &src);
315 if(!strncmpiW(src, blockedW, sizeof(blockedW)/sizeof(WCHAR)-1)) {
316 TRACE("returning BLOCKED::\n");
317 *p = SysAllocString(blockedW);
318 if(!*p)
319 hres = E_OUTOFMEMORY;
320 }else {
321 hres = nsuri_to_url(src, TRUE, p);
323 }else {
324 ERR("GetSrc failed: %08x\n", nsres);
325 hres = E_FAIL;
328 nsAString_Finish(&src_str);
329 return hres;
332 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
334 HTMLImg *This = impl_from_IHTMLImgElement(iface);
335 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
341 HTMLImg *This = impl_from_IHTMLImgElement(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
346 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
348 HTMLImg *This = impl_from_IHTMLImgElement(iface);
349 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
350 return E_NOTIMPL;
353 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
355 HTMLImg *This = impl_from_IHTMLImgElement(iface);
356 FIXME("(%p)->(%p)\n", This, p);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
362 HTMLImg *This = impl_from_IHTMLImgElement(iface);
363 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
369 HTMLImg *This = impl_from_IHTMLImgElement(iface);
370 FIXME("(%p)->(%p)\n", This, p);
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
376 HTMLImg *This = impl_from_IHTMLImgElement(iface);
377 FIXME("(%p)->(%p)\n", This, p);
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
383 HTMLImg *This = impl_from_IHTMLImgElement(iface);
384 cpp_bool complete;
385 nsresult nsres;
387 TRACE("(%p)->(%p)\n", This, p);
389 nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
390 if(NS_FAILED(nsres)) {
391 ERR("GetComplete failed: %08x\n", nsres);
392 return E_FAIL;
395 *p = variant_bool(complete);
396 return S_OK;
399 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
401 HTMLImg *This = impl_from_IHTMLImgElement(iface);
402 FIXME("(%p)->()\n", This);
403 return E_NOTIMPL;
406 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
408 HTMLImg *This = impl_from_IHTMLImgElement(iface);
409 FIXME("(%p)->(%p)\n", This, p);
410 return E_NOTIMPL;
413 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
415 HTMLImg *This = impl_from_IHTMLImgElement(iface);
416 nsAString str;
417 nsresult nsres;
419 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
421 nsAString_InitDepend(&str, v);
423 nsres = nsIDOMHTMLImageElement_SetAlign(This->nsimg, &str);
424 nsAString_Finish(&str);
425 if (NS_FAILED(nsres)){
426 ERR("Set Align(%s) failed: %08x\n", debugstr_w(v), nsres);
427 return E_FAIL;
430 return S_OK;
433 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
435 HTMLImg *This = impl_from_IHTMLImgElement(iface);
436 nsAString str;
437 nsresult nsres;
439 TRACE("(%p)->(%p)\n", This, p);
441 nsAString_Init(&str, NULL);
442 nsres = nsIDOMHTMLImageElement_GetAlign(This->nsimg, &str);
444 return return_nsstr(nsres, &str, p);
447 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
449 HTMLImg *This = impl_from_IHTMLImgElement(iface);
451 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
453 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
456 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
458 HTMLImg *This = impl_from_IHTMLImgElement(iface);
460 TRACE("(%p)->(%p)\n", This, p);
462 return get_node_event(&This->element.node, EVENTID_LOAD, p);
465 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
467 HTMLImg *This = impl_from_IHTMLImgElement(iface);
469 TRACE("(%p)->()\n", This);
471 return set_node_event(&This->element.node, EVENTID_ERROR, &v);
474 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
476 HTMLImg *This = impl_from_IHTMLImgElement(iface);
478 TRACE("(%p)->(%p)\n", This, p);
480 return get_node_event(&This->element.node, EVENTID_ERROR, p);
483 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
485 HTMLImg *This = impl_from_IHTMLImgElement(iface);
487 TRACE("(%p)->()\n", This);
489 return set_node_event(&This->element.node, EVENTID_ABORT, &v);
492 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
494 HTMLImg *This = impl_from_IHTMLImgElement(iface);
496 TRACE("(%p)->(%p)\n", This, p);
498 return get_node_event(&This->element.node, EVENTID_ABORT, p);
501 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
503 HTMLImg *This = impl_from_IHTMLImgElement(iface);
504 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
505 return E_NOTIMPL;
508 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
510 HTMLImg *This = impl_from_IHTMLImgElement(iface);
511 nsAString name;
512 nsresult nsres;
514 TRACE("(%p)->(%p)\n", This, p);
516 nsAString_Init(&name, NULL);
517 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
518 return return_nsstr(nsres, &name, p);
521 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
523 HTMLImg *This = impl_from_IHTMLImgElement(iface);
524 nsresult nsres;
526 TRACE("(%p)->(%d)\n", This, v);
528 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
529 if(NS_FAILED(nsres)) {
530 ERR("SetWidth failed: %08x\n", nsres);
531 return E_FAIL;
534 return S_OK;
537 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
539 HTMLImg *This = impl_from_IHTMLImgElement(iface);
540 UINT32 width;
541 nsresult nsres;
543 TRACE("(%p)->(%p)\n", This, p);
545 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
546 if(NS_FAILED(nsres)) {
547 ERR("GetWidth failed: %08x\n", nsres);
548 return E_FAIL;
551 *p = width;
552 return S_OK;
555 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
557 HTMLImg *This = impl_from_IHTMLImgElement(iface);
558 nsresult nsres;
560 TRACE("(%p)->(%d)\n", This, v);
562 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
563 if(NS_FAILED(nsres)) {
564 ERR("SetHeight failed: %08x\n", nsres);
565 return E_FAIL;
568 return S_OK;
571 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
573 HTMLImg *This = impl_from_IHTMLImgElement(iface);
574 UINT32 height;
575 nsresult nsres;
577 TRACE("(%p)->(%p)\n", This, p);
579 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
580 if(NS_FAILED(nsres)) {
581 ERR("GetHeight failed: %08x\n", nsres);
582 return E_FAIL;
585 *p = height;
586 return S_OK;
589 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
591 HTMLImg *This = impl_from_IHTMLImgElement(iface);
592 FIXME("(%p)->()\n", This);
593 return E_NOTIMPL;
596 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
598 HTMLImg *This = impl_from_IHTMLImgElement(iface);
599 FIXME("(%p)->(%p)\n", This, p);
600 return E_NOTIMPL;
603 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
604 HTMLImgElement_QueryInterface,
605 HTMLImgElement_AddRef,
606 HTMLImgElement_Release,
607 HTMLImgElement_GetTypeInfoCount,
608 HTMLImgElement_GetTypeInfo,
609 HTMLImgElement_GetIDsOfNames,
610 HTMLImgElement_Invoke,
611 HTMLImgElement_put_isMap,
612 HTMLImgElement_get_isMap,
613 HTMLImgElement_put_useMap,
614 HTMLImgElement_get_useMap,
615 HTMLImgElement_get_mimeType,
616 HTMLImgElement_get_fileSize,
617 HTMLImgElement_get_fileCreatedDate,
618 HTMLImgElement_get_fileModifiedDate,
619 HTMLImgElement_get_fileUpdatedDate,
620 HTMLImgElement_get_protocol,
621 HTMLImgElement_get_href,
622 HTMLImgElement_get_nameProp,
623 HTMLImgElement_put_border,
624 HTMLImgElement_get_border,
625 HTMLImgElement_put_vspace,
626 HTMLImgElement_get_vspace,
627 HTMLImgElement_put_hspace,
628 HTMLImgElement_get_hspace,
629 HTMLImgElement_put_alt,
630 HTMLImgElement_get_alt,
631 HTMLImgElement_put_src,
632 HTMLImgElement_get_src,
633 HTMLImgElement_put_lowsrc,
634 HTMLImgElement_get_lowsrc,
635 HTMLImgElement_put_vrml,
636 HTMLImgElement_get_vrml,
637 HTMLImgElement_put_dynsrc,
638 HTMLImgElement_get_dynsrc,
639 HTMLImgElement_get_readyState,
640 HTMLImgElement_get_complete,
641 HTMLImgElement_put_loop,
642 HTMLImgElement_get_loop,
643 HTMLImgElement_put_align,
644 HTMLImgElement_get_align,
645 HTMLImgElement_put_onload,
646 HTMLImgElement_get_onload,
647 HTMLImgElement_put_onerror,
648 HTMLImgElement_get_onerror,
649 HTMLImgElement_put_onabort,
650 HTMLImgElement_get_onabort,
651 HTMLImgElement_put_name,
652 HTMLImgElement_get_name,
653 HTMLImgElement_put_width,
654 HTMLImgElement_get_width,
655 HTMLImgElement_put_height,
656 HTMLImgElement_get_height,
657 HTMLImgElement_put_start,
658 HTMLImgElement_get_start
661 static inline HTMLImg *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
663 return CONTAINING_RECORD(iface, HTMLImg, element.node);
666 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
668 HTMLImg *This = impl_from_HTMLDOMNode(iface);
670 *ppv = NULL;
672 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
673 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
674 *ppv = &This->IHTMLImgElement_iface;
675 }else {
676 return HTMLElement_QI(&This->element.node, riid, ppv);
679 IUnknown_AddRef((IUnknown*)*ppv);
680 return S_OK;
683 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
685 HTMLImg *This = impl_from_HTMLDOMNode(iface);
687 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
690 static void HTMLImgElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
692 HTMLImg *This = impl_from_HTMLDOMNode(iface);
694 if(This->nsimg)
695 note_cc_edge((nsISupports*)This->nsimg, "This->nsimg", cb);
698 static void HTMLImgElement_unlink(HTMLDOMNode *iface)
700 HTMLImg *This = impl_from_HTMLDOMNode(iface);
702 if(This->nsimg) {
703 nsIDOMHTMLImageElement *nsimg = This->nsimg;
705 This->nsimg = NULL;
706 nsIDOMHTMLImageElement_Release(nsimg);
710 static const NodeImplVtbl HTMLImgElementImplVtbl = {
711 &CLSID_HTMLImg,
712 HTMLImgElement_QI,
713 HTMLElement_destructor,
714 HTMLElement_cpc,
715 HTMLElement_clone,
716 HTMLElement_handle_event,
717 HTMLElement_get_attr_col,
718 NULL,
719 NULL,
720 NULL,
721 NULL,
722 HTMLImgElement_get_readystate,
723 NULL,
724 NULL,
725 NULL,
726 HTMLImgElement_traverse,
727 HTMLImgElement_unlink
730 static const tid_t HTMLImgElement_iface_tids[] = {
731 HTMLELEMENT_TIDS,
732 IHTMLImgElement_tid,
735 static dispex_static_data_t HTMLImgElement_dispex = {
736 NULL,
737 DispHTMLImg_tid,
738 HTMLImgElement_iface_tids,
739 HTMLElement_init_dispex_info
742 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
744 HTMLImg *ret;
745 nsresult nsres;
747 ret = heap_alloc_zero(sizeof(HTMLImg));
748 if(!ret)
749 return E_OUTOFMEMORY;
751 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
752 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
754 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
756 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
757 assert(nsres == NS_OK);
759 *elem = &ret->element;
760 return S_OK;
763 static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
765 return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
768 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
769 REFIID riid, void **ppv)
771 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
773 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
775 if(IsEqualGUID(&IID_IUnknown, riid)) {
776 *ppv = &This->IHTMLImageElementFactory_iface;
777 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
778 *ppv = &This->IHTMLImageElementFactory_iface;
779 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
780 return *ppv ? S_OK : E_NOINTERFACE;
781 }else {
782 *ppv = NULL;
783 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
784 return E_NOINTERFACE;
787 IUnknown_AddRef((IUnknown*)*ppv);
788 return S_OK;
791 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
793 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
794 LONG ref = InterlockedIncrement(&This->ref);
796 TRACE("(%p) ref=%d\n", This, ref);
798 return ref;
801 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
803 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
804 LONG ref = InterlockedDecrement(&This->ref);
806 TRACE("(%p) ref=%d\n", This, ref);
808 if(!ref)
809 heap_free(This);
811 return ref;
814 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
815 UINT *pctinfo)
817 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
818 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
821 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
822 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
824 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
825 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
828 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
829 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
830 DISPID *rgDispId)
832 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
833 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
836 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
837 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
838 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
839 UINT *puArgErr)
841 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
842 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
843 pDispParams, pVarResult, pExcepInfo, puArgErr);
846 static LONG var_to_size(const VARIANT *v)
848 switch(V_VT(v)) {
849 case VT_EMPTY:
850 return 0;
851 case VT_I4:
852 return V_I4(v);
853 case VT_BSTR: {
854 LONG ret;
855 HRESULT hres;
857 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
858 if(FAILED(hres)) {
859 FIXME("VarI4FromStr failed: %08x\n", hres);
860 return 0;
862 return ret;
864 default:
865 FIXME("unsupported size %s\n", debugstr_variant(v));
867 return 0;
870 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
871 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
873 HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
874 HTMLDocumentNode *doc;
875 IHTMLImgElement *img;
876 HTMLElement *elem;
877 nsIDOMElement *nselem;
878 LONG l;
879 HRESULT hres;
881 static const PRUnichar imgW[] = {'I','M','G',0};
883 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
884 debugstr_variant(&height), img_elem);
886 if(!This->window || !This->window->doc) {
887 WARN("NULL doc\n");
888 return E_UNEXPECTED;
891 doc = This->window->doc;
893 *img_elem = NULL;
895 hres = create_nselem(doc, imgW, &nselem);
896 if(FAILED(hres))
897 return hres;
899 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
900 nsIDOMElement_Release(nselem);
901 if(FAILED(hres)) {
902 ERR("HTMLElement_Create failed\n");
903 return hres;
906 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
907 (void**)&img);
908 IHTMLElement_Release(&elem->IHTMLElement_iface);
909 if(FAILED(hres)) {
910 ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
911 return hres;
914 l = var_to_size(&width);
915 if(l)
916 IHTMLImgElement_put_width(img, l);
917 l = var_to_size(&height);
918 if(l)
919 IHTMLImgElement_put_height(img, l);
921 *img_elem = img;
922 return S_OK;
925 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
926 HTMLImageElementFactory_QueryInterface,
927 HTMLImageElementFactory_AddRef,
928 HTMLImageElementFactory_Release,
929 HTMLImageElementFactory_GetTypeInfoCount,
930 HTMLImageElementFactory_GetTypeInfo,
931 HTMLImageElementFactory_GetIDsOfNames,
932 HTMLImageElementFactory_Invoke,
933 HTMLImageElementFactory_create
936 static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
938 return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
941 static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
942 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
943 IServiceProvider *caller)
945 HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
946 IHTMLImgElement *img;
947 VARIANT empty, *width, *height;
948 HRESULT hres;
949 int argc = params->cArgs - params->cNamedArgs;
951 V_VT(res) = VT_NULL;
953 V_VT(&empty) = VT_EMPTY;
955 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
956 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
958 hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
959 &img);
960 if(FAILED(hres))
961 return hres;
963 V_VT(res) = VT_DISPATCH;
964 V_DISPATCH(res) = (IDispatch*)img;
966 return S_OK;
969 static const tid_t HTMLImageElementFactory_iface_tids[] = {
970 IHTMLImageElementFactory_tid,
974 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
975 HTMLImageElementFactory_value,
976 NULL,
977 NULL,
978 NULL
981 static dispex_static_data_t HTMLImageElementFactory_dispex = {
982 &HTMLImageElementFactory_dispex_vtbl,
983 IHTMLImageElementFactory_tid,
984 HTMLImageElementFactory_iface_tids
987 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
989 HTMLImageElementFactory *ret;
991 ret = heap_alloc(sizeof(HTMLImageElementFactory));
992 if(!ret)
993 return E_OUTOFMEMORY;
995 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
996 ret->ref = 1;
997 ret->window = window;
999 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
1000 &HTMLImageElementFactory_dispex);
1002 *ret_val = ret;
1003 return S_OK;