server: Add RIM_TYPEHID type / hid member to rawinput union.
[wine.git] / dlls / mshtml / htmlimg.c
blob2dfd53eb0b973211c8475870dc7f9d400b60d2e6
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 TRACE("(%p)->(%p)\n", This, p);
308 nsAString_Init(&src_str, NULL);
309 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
310 if(NS_SUCCEEDED(nsres)) {
311 nsAString_GetData(&src_str, &src);
313 if(!wcsnicmp(src, L"BLOCKED::", ARRAY_SIZE(L"BLOCKED::")-1)) {
314 TRACE("returning BLOCKED::\n");
315 *p = SysAllocString(L"BLOCKED::");
316 if(!*p)
317 hres = E_OUTOFMEMORY;
318 }else {
319 hres = nsuri_to_url(src, TRUE, p);
321 }else {
322 ERR("GetSrc failed: %08x\n", nsres);
323 hres = E_FAIL;
326 nsAString_Finish(&src_str);
327 return hres;
330 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
332 HTMLImg *This = impl_from_IHTMLImgElement(iface);
333 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
334 return E_NOTIMPL;
337 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
339 HTMLImg *This = impl_from_IHTMLImgElement(iface);
340 FIXME("(%p)->(%p)\n", This, p);
341 return E_NOTIMPL;
344 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
346 HTMLImg *This = impl_from_IHTMLImgElement(iface);
347 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
348 return E_NOTIMPL;
351 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *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_dynsrc(IHTMLImgElement *iface, BSTR v)
360 HTMLImg *This = impl_from_IHTMLImgElement(iface);
361 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
362 return E_NOTIMPL;
365 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
367 HTMLImg *This = impl_from_IHTMLImgElement(iface);
368 FIXME("(%p)->(%p)\n", This, p);
369 return E_NOTIMPL;
372 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
374 HTMLImg *This = impl_from_IHTMLImgElement(iface);
375 FIXME("(%p)->(%p)\n", This, p);
376 return E_NOTIMPL;
379 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
381 HTMLImg *This = impl_from_IHTMLImgElement(iface);
382 cpp_bool complete;
383 nsresult nsres;
385 TRACE("(%p)->(%p)\n", This, p);
387 nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
388 if(NS_FAILED(nsres)) {
389 ERR("GetComplete failed: %08x\n", nsres);
390 return E_FAIL;
393 *p = variant_bool(complete);
394 return S_OK;
397 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
399 HTMLImg *This = impl_from_IHTMLImgElement(iface);
400 FIXME("(%p)->()\n", This);
401 return E_NOTIMPL;
404 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
406 HTMLImg *This = impl_from_IHTMLImgElement(iface);
407 FIXME("(%p)->(%p)\n", This, p);
408 return E_NOTIMPL;
411 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
413 HTMLImg *This = impl_from_IHTMLImgElement(iface);
414 nsAString str;
415 nsresult nsres;
417 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
419 nsAString_InitDepend(&str, v);
421 nsres = nsIDOMHTMLImageElement_SetAlign(This->nsimg, &str);
422 nsAString_Finish(&str);
423 if (NS_FAILED(nsres)){
424 ERR("Set Align(%s) failed: %08x\n", debugstr_w(v), nsres);
425 return E_FAIL;
428 return S_OK;
431 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
433 HTMLImg *This = impl_from_IHTMLImgElement(iface);
434 nsAString str;
435 nsresult nsres;
437 TRACE("(%p)->(%p)\n", This, p);
439 nsAString_Init(&str, NULL);
440 nsres = nsIDOMHTMLImageElement_GetAlign(This->nsimg, &str);
442 return return_nsstr(nsres, &str, p);
445 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
447 HTMLImg *This = impl_from_IHTMLImgElement(iface);
449 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
451 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
454 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
456 HTMLImg *This = impl_from_IHTMLImgElement(iface);
458 TRACE("(%p)->(%p)\n", This, p);
460 return get_node_event(&This->element.node, EVENTID_LOAD, p);
463 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
465 HTMLImg *This = impl_from_IHTMLImgElement(iface);
467 TRACE("(%p)->()\n", This);
469 return set_node_event(&This->element.node, EVENTID_ERROR, &v);
472 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
474 HTMLImg *This = impl_from_IHTMLImgElement(iface);
476 TRACE("(%p)->(%p)\n", This, p);
478 return get_node_event(&This->element.node, EVENTID_ERROR, p);
481 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
483 HTMLImg *This = impl_from_IHTMLImgElement(iface);
485 TRACE("(%p)->()\n", This);
487 return set_node_event(&This->element.node, EVENTID_ABORT, &v);
490 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
492 HTMLImg *This = impl_from_IHTMLImgElement(iface);
494 TRACE("(%p)->(%p)\n", This, p);
496 return get_node_event(&This->element.node, EVENTID_ABORT, p);
499 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
501 HTMLImg *This = impl_from_IHTMLImgElement(iface);
502 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
503 return E_NOTIMPL;
506 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
508 HTMLImg *This = impl_from_IHTMLImgElement(iface);
509 nsAString name;
510 nsresult nsres;
512 TRACE("(%p)->(%p)\n", This, p);
514 nsAString_Init(&name, NULL);
515 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
516 return return_nsstr(nsres, &name, p);
519 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
521 HTMLImg *This = impl_from_IHTMLImgElement(iface);
522 nsresult nsres;
524 TRACE("(%p)->(%d)\n", This, v);
526 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
527 if(NS_FAILED(nsres)) {
528 ERR("SetWidth failed: %08x\n", nsres);
529 return E_FAIL;
532 return S_OK;
535 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
537 HTMLImg *This = impl_from_IHTMLImgElement(iface);
538 UINT32 width;
539 nsresult nsres;
541 TRACE("(%p)->(%p)\n", This, p);
543 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
544 if(NS_FAILED(nsres)) {
545 ERR("GetWidth failed: %08x\n", nsres);
546 return E_FAIL;
549 *p = width;
550 return S_OK;
553 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
555 HTMLImg *This = impl_from_IHTMLImgElement(iface);
556 nsresult nsres;
558 TRACE("(%p)->(%d)\n", This, v);
560 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
561 if(NS_FAILED(nsres)) {
562 ERR("SetHeight failed: %08x\n", nsres);
563 return E_FAIL;
566 return S_OK;
569 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
571 HTMLImg *This = impl_from_IHTMLImgElement(iface);
572 UINT32 height;
573 nsresult nsres;
575 TRACE("(%p)->(%p)\n", This, p);
577 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
578 if(NS_FAILED(nsres)) {
579 ERR("GetHeight failed: %08x\n", nsres);
580 return E_FAIL;
583 *p = height;
584 return S_OK;
587 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
589 HTMLImg *This = impl_from_IHTMLImgElement(iface);
590 FIXME("(%p)->()\n", This);
591 return E_NOTIMPL;
594 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
596 HTMLImg *This = impl_from_IHTMLImgElement(iface);
597 FIXME("(%p)->(%p)\n", This, p);
598 return E_NOTIMPL;
601 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
602 HTMLImgElement_QueryInterface,
603 HTMLImgElement_AddRef,
604 HTMLImgElement_Release,
605 HTMLImgElement_GetTypeInfoCount,
606 HTMLImgElement_GetTypeInfo,
607 HTMLImgElement_GetIDsOfNames,
608 HTMLImgElement_Invoke,
609 HTMLImgElement_put_isMap,
610 HTMLImgElement_get_isMap,
611 HTMLImgElement_put_useMap,
612 HTMLImgElement_get_useMap,
613 HTMLImgElement_get_mimeType,
614 HTMLImgElement_get_fileSize,
615 HTMLImgElement_get_fileCreatedDate,
616 HTMLImgElement_get_fileModifiedDate,
617 HTMLImgElement_get_fileUpdatedDate,
618 HTMLImgElement_get_protocol,
619 HTMLImgElement_get_href,
620 HTMLImgElement_get_nameProp,
621 HTMLImgElement_put_border,
622 HTMLImgElement_get_border,
623 HTMLImgElement_put_vspace,
624 HTMLImgElement_get_vspace,
625 HTMLImgElement_put_hspace,
626 HTMLImgElement_get_hspace,
627 HTMLImgElement_put_alt,
628 HTMLImgElement_get_alt,
629 HTMLImgElement_put_src,
630 HTMLImgElement_get_src,
631 HTMLImgElement_put_lowsrc,
632 HTMLImgElement_get_lowsrc,
633 HTMLImgElement_put_vrml,
634 HTMLImgElement_get_vrml,
635 HTMLImgElement_put_dynsrc,
636 HTMLImgElement_get_dynsrc,
637 HTMLImgElement_get_readyState,
638 HTMLImgElement_get_complete,
639 HTMLImgElement_put_loop,
640 HTMLImgElement_get_loop,
641 HTMLImgElement_put_align,
642 HTMLImgElement_get_align,
643 HTMLImgElement_put_onload,
644 HTMLImgElement_get_onload,
645 HTMLImgElement_put_onerror,
646 HTMLImgElement_get_onerror,
647 HTMLImgElement_put_onabort,
648 HTMLImgElement_get_onabort,
649 HTMLImgElement_put_name,
650 HTMLImgElement_get_name,
651 HTMLImgElement_put_width,
652 HTMLImgElement_get_width,
653 HTMLImgElement_put_height,
654 HTMLImgElement_get_height,
655 HTMLImgElement_put_start,
656 HTMLImgElement_get_start
659 static inline HTMLImg *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
661 return CONTAINING_RECORD(iface, HTMLImg, element.node);
664 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
666 HTMLImg *This = impl_from_HTMLDOMNode(iface);
668 *ppv = NULL;
670 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
671 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
672 *ppv = &This->IHTMLImgElement_iface;
673 }else {
674 return HTMLElement_QI(&This->element.node, riid, ppv);
677 IUnknown_AddRef((IUnknown*)*ppv);
678 return S_OK;
681 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
683 HTMLImg *This = impl_from_HTMLDOMNode(iface);
685 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
688 static void HTMLImgElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
690 HTMLImg *This = impl_from_HTMLDOMNode(iface);
692 if(This->nsimg)
693 note_cc_edge((nsISupports*)This->nsimg, "This->nsimg", cb);
696 static void HTMLImgElement_unlink(HTMLDOMNode *iface)
698 HTMLImg *This = impl_from_HTMLDOMNode(iface);
700 if(This->nsimg) {
701 nsIDOMHTMLImageElement *nsimg = This->nsimg;
703 This->nsimg = NULL;
704 nsIDOMHTMLImageElement_Release(nsimg);
708 static const NodeImplVtbl HTMLImgElementImplVtbl = {
709 &CLSID_HTMLImg,
710 HTMLImgElement_QI,
711 HTMLElement_destructor,
712 HTMLElement_cpc,
713 HTMLElement_clone,
714 HTMLElement_handle_event,
715 HTMLElement_get_attr_col,
716 NULL,
717 NULL,
718 NULL,
719 NULL,
720 HTMLImgElement_get_readystate,
721 NULL,
722 NULL,
723 NULL,
724 HTMLImgElement_traverse,
725 HTMLImgElement_unlink
728 static const tid_t HTMLImgElement_iface_tids[] = {
729 HTMLELEMENT_TIDS,
730 IHTMLImgElement_tid,
733 static dispex_static_data_t HTMLImgElement_dispex = {
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=%d\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=%d\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: %08x\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%08x\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 &HTMLImageElementFactory_dispex_vtbl,
979 IHTMLImageElementFactory_tid,
980 HTMLImageElementFactory_iface_tids
983 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
985 HTMLImageElementFactory *ret;
987 ret = heap_alloc(sizeof(HTMLImageElementFactory));
988 if(!ret)
989 return E_OUTOFMEMORY;
991 ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
992 ret->ref = 1;
993 ret->window = window;
995 init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
996 &HTMLImageElementFactory_dispex, dispex_compat_mode(&window->event_target.dispex));
998 *ret_val = ret;
999 return S_OK;