strmbase: Implement BaseControlWindow.
[wine/multimedia.git] / dlls / mshtml / htmlelem.c
blob5f33f96e0dab4c4bd83def3f00f9635bd6af6087
1 /*
2 * Copyright 2006 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
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
29 #include "shlwapi.h"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
35 #include "htmlstyle.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR aW[] = {'A',0};
40 static const WCHAR bodyW[] = {'B','O','D','Y',0};
41 static const WCHAR embedW[] = {'E','M','B','E','D',0};
42 static const WCHAR formW[] = {'F','O','R','M',0};
43 static const WCHAR frameW[] = {'F','R','A','M','E',0};
44 static const WCHAR headW[] = {'H','E','A','D',0};
45 static const WCHAR iframeW[] = {'I','F','R','A','M','E',0};
46 static const WCHAR imgW[] = {'I','M','G',0};
47 static const WCHAR inputW[] = {'I','N','P','U','T',0};
48 static const WCHAR objectW[] = {'O','B','J','E','C','T',0};
49 static const WCHAR optionW[] = {'O','P','T','I','O','N',0};
50 static const WCHAR scriptW[] = {'S','C','R','I','P','T',0};
51 static const WCHAR selectW[] = {'S','E','L','E','C','T',0};
52 static const WCHAR styleW[] = {'S','T','Y','L','E',0};
53 static const WCHAR tableW[] = {'T','A','B','L','E',0};
54 static const WCHAR tdW[] = {'T','D',0};
55 static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
56 static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
57 static const WCHAR trW[] = {'T','R',0};
59 typedef struct {
60 const WCHAR *name;
61 HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
62 } tag_desc_t;
64 static const tag_desc_t tag_descs[] = {
65 {aW, HTMLAnchorElement_Create},
66 {bodyW, HTMLBodyElement_Create},
67 {embedW, HTMLEmbedElement_Create},
68 {formW, HTMLFormElement_Create},
69 {frameW, HTMLFrameElement_Create},
70 {headW, HTMLHeadElement_Create},
71 {iframeW, HTMLIFrame_Create},
72 {imgW, HTMLImgElement_Create},
73 {inputW, HTMLInputElement_Create},
74 {objectW, HTMLObjectElement_Create},
75 {optionW, HTMLOptionElement_Create},
76 {scriptW, HTMLScriptElement_Create},
77 {selectW, HTMLSelectElement_Create},
78 {styleW, HTMLStyleElement_Create},
79 {tableW, HTMLTable_Create},
80 {tdW, HTMLTableCell_Create},
81 {textareaW, HTMLTextAreaElement_Create},
82 {title_tagW, HTMLTitleElement_Create},
83 {trW, HTMLTableRow_Create}
86 static const tag_desc_t *get_tag_desc(const WCHAR *tag_name)
88 DWORD min=0, max=sizeof(tag_descs)/sizeof(*tag_descs)-1, i;
89 int r;
91 while(min <= max) {
92 i = (min+max)/2;
93 r = strcmpW(tag_name, tag_descs[i].name);
94 if(!r)
95 return tag_descs+i;
97 if(r < 0)
98 max = i-1;
99 else
100 min = i+1;
103 return NULL;
106 HRESULT replace_node_by_html(nsIDOMHTMLDocument *nsdoc, nsIDOMNode *nsnode, const WCHAR *html)
108 nsIDOMDocumentFragment *nsfragment;
109 nsIDOMNSRange *nsrange;
110 nsIDOMNode *nsparent;
111 nsIDOMRange *range;
112 nsAString html_str;
113 nsresult nsres;
114 HRESULT hres = S_OK;
116 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
117 if(NS_FAILED(nsres)) {
118 ERR("CreateRange failed: %08x\n", nsres);
119 return E_FAIL;
122 nsres = nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void**)&nsrange);
123 nsIDOMRange_Release(range);
124 if(NS_FAILED(nsres)) {
125 ERR("Could not get nsIDOMNSRange: %08x\n", nsres);
126 return E_FAIL;
129 nsAString_InitDepend(&html_str, html);
130 nsIDOMNSRange_CreateContextualFragment(nsrange, &html_str, &nsfragment);
131 nsIDOMNSRange_Release(nsrange);
132 nsAString_Finish(&html_str);
133 if(NS_FAILED(nsres)) {
134 ERR("CreateContextualFragment failed: %08x\n", nsres);
135 return E_FAIL;
138 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
139 if(NS_SUCCEEDED(nsres) && nsparent) {
140 nsIDOMNode *nstmp;
142 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
143 nsIDOMNode_Release(nsparent);
144 if(NS_FAILED(nsres)) {
145 ERR("ReplaceChild failed: %08x\n", nsres);
146 hres = E_FAIL;
147 }else if(nstmp) {
148 nsIDOMNode_Release(nstmp);
150 }else {
151 ERR("GetParentNode failed: %08x\n", nsres);
152 hres = E_FAIL;
155 nsIDOMDocumentFragment_Release(nsfragment);
156 return hres;
159 typedef struct
161 DispatchEx dispex;
162 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
164 LONG ref;
165 } HTMLFiltersCollection;
167 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
169 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
172 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
174 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
176 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
179 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
181 nsIDOMElement *nselem;
182 nsAString tag_str;
183 nsresult nsres;
185 if(!doc->nsdoc) {
186 WARN("NULL nsdoc\n");
187 return E_UNEXPECTED;
190 nsAString_InitDepend(&tag_str, tag);
191 nsres = nsIDOMDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
192 nsAString_Finish(&tag_str);
193 if(NS_FAILED(nsres)) {
194 ERR("CreateElement failed: %08x\n", nsres);
195 return E_FAIL;
198 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
199 nsIDOMElement_Release(nselem);
200 if(NS_FAILED(nsres)) {
201 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
202 return E_FAIL;
205 return S_OK;
208 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
209 REFIID riid, void **ppv)
211 HTMLElement *This = impl_from_IHTMLElement(iface);
213 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
216 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
218 HTMLElement *This = impl_from_IHTMLElement(iface);
220 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
223 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
225 HTMLElement *This = impl_from_IHTMLElement(iface);
227 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
230 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
232 HTMLElement *This = impl_from_IHTMLElement(iface);
233 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
236 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
237 LCID lcid, ITypeInfo **ppTInfo)
239 HTMLElement *This = impl_from_IHTMLElement(iface);
240 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
243 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
244 LPOLESTR *rgszNames, UINT cNames,
245 LCID lcid, DISPID *rgDispId)
247 HTMLElement *This = impl_from_IHTMLElement(iface);
248 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
249 lcid, rgDispId);
252 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
253 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
254 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
256 HTMLElement *This = impl_from_IHTMLElement(iface);
257 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
258 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
261 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
262 VARIANT AttributeValue, LONG lFlags)
264 HTMLElement *This = impl_from_IHTMLElement(iface);
265 HRESULT hres;
266 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
267 DISPPARAMS dispParams;
268 EXCEPINFO excep;
270 TRACE("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
272 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
273 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
274 if(FAILED(hres))
275 return hres;
277 dispParams.cArgs = 1;
278 dispParams.cNamedArgs = 1;
279 dispParams.rgdispidNamedArgs = &dispidNamed;
280 dispParams.rgvarg = &AttributeValue;
282 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
283 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
284 return hres;
287 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
288 LONG lFlags, VARIANT *AttributeValue)
290 HTMLElement *This = impl_from_IHTMLElement(iface);
291 DISPID dispid;
292 HRESULT hres;
293 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
294 EXCEPINFO excep;
296 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
298 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
299 fdexNameCaseInsensitive, &dispid);
300 if(hres == DISP_E_UNKNOWNNAME) {
301 V_VT(AttributeValue) = VT_NULL;
302 return S_OK;
305 if(FAILED(hres)) {
306 V_VT(AttributeValue) = VT_NULL;
307 return hres;
310 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
311 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
313 return hres;
316 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
317 LONG lFlags, VARIANT_BOOL *pfSuccess)
319 HTMLElement *This = impl_from_IHTMLElement(iface);
321 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
323 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
326 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
328 HTMLElement *This = impl_from_IHTMLElement(iface);
329 nsAString classname_str;
330 nsresult nsres;
332 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
334 if(!This->nselem) {
335 FIXME("NULL nselem\n");
336 return E_NOTIMPL;
339 nsAString_InitDepend(&classname_str, v);
340 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
341 nsAString_Finish(&classname_str);
342 if(NS_FAILED(nsres))
343 ERR("SetClassName failed: %08x\n", nsres);
345 return S_OK;
348 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
350 HTMLElement *This = impl_from_IHTMLElement(iface);
351 nsAString class_str;
352 nsresult nsres;
353 HRESULT hres = S_OK;
355 TRACE("(%p)->(%p)\n", This, p);
357 if(!This->nselem) {
358 FIXME("NULL nselem\n");
359 return E_NOTIMPL;
362 nsAString_Init(&class_str, NULL);
363 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
365 if(NS_SUCCEEDED(nsres)) {
366 const PRUnichar *class;
367 nsAString_GetData(&class_str, &class);
368 *p = *class ? SysAllocString(class) : NULL;
369 }else {
370 ERR("GetClassName failed: %08x\n", nsres);
371 hres = E_FAIL;
374 nsAString_Finish(&class_str);
376 TRACE("className=%s\n", debugstr_w(*p));
377 return hres;
380 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
382 HTMLElement *This = impl_from_IHTMLElement(iface);
383 nsAString id_str;
384 nsresult nsres;
386 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
388 if(!This->nselem) {
389 FIXME("nselem == NULL\n");
390 return S_OK;
393 nsAString_InitDepend(&id_str, v);
394 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
395 nsAString_Finish(&id_str);
396 if(NS_FAILED(nsres))
397 ERR("SetId failed: %08x\n", nsres);
399 return S_OK;
402 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
404 HTMLElement *This = impl_from_IHTMLElement(iface);
405 const PRUnichar *id;
406 nsAString id_str;
407 nsresult nsres;
409 TRACE("(%p)->(%p)\n", This, p);
411 *p = NULL;
413 if(!This->nselem)
414 return S_OK;
416 nsAString_Init(&id_str, NULL);
417 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
418 nsAString_GetData(&id_str, &id);
420 if(NS_FAILED(nsres))
421 ERR("GetId failed: %08x\n", nsres);
422 else if(*id)
423 *p = SysAllocString(id);
425 nsAString_Finish(&id_str);
426 return S_OK;
429 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
431 HTMLElement *This = impl_from_IHTMLElement(iface);
432 const PRUnichar *tag;
433 nsAString tag_str;
434 nsresult nsres;
436 TRACE("(%p)->(%p)\n", This, p);
438 if(!This->nselem) {
439 static const WCHAR comment_tagW[] = {'!',0};
441 WARN("NULL nselem, assuming comment\n");
443 *p = SysAllocString(comment_tagW);
444 return S_OK;
447 nsAString_Init(&tag_str, NULL);
448 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
449 if(NS_SUCCEEDED(nsres)) {
450 nsAString_GetData(&tag_str, &tag);
451 *p = SysAllocString(tag);
452 }else {
453 ERR("GetTagName failed: %08x\n", nsres);
454 *p = NULL;
456 nsAString_Finish(&tag_str);
458 return S_OK;
461 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
463 HTMLElement *This = impl_from_IHTMLElement(iface);
464 IHTMLDOMNode *node;
465 HRESULT hres;
467 TRACE("(%p)->(%p)\n", This, p);
469 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
470 if(FAILED(hres))
471 return hres;
473 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
474 IHTMLDOMNode_Release(node);
475 if(FAILED(hres))
476 *p = NULL;
478 return S_OK;
481 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
483 HTMLElement *This = impl_from_IHTMLElement(iface);
485 TRACE("(%p)->(%p)\n", This, p);
487 if(!This->style) {
488 nsIDOMElementCSSInlineStyle *nselemstyle;
489 nsIDOMCSSStyleDeclaration *nsstyle;
490 nsresult nsres;
491 HRESULT hres;
493 if(!This->nselem) {
494 FIXME("NULL nselem\n");
495 return E_NOTIMPL;
498 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
499 (void**)&nselemstyle);
500 if(NS_FAILED(nsres)) {
501 ERR("Could not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
502 return E_FAIL;
505 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
506 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
507 if(NS_FAILED(nsres)) {
508 ERR("GetStyle failed: %08x\n", nsres);
509 return E_FAIL;
512 hres = HTMLStyle_Create(This, nsstyle, &This->style);
513 nsIDOMCSSStyleDeclaration_Release(nsstyle);
514 if(FAILED(hres))
515 return hres;
518 *p = &This->style->IHTMLStyle_iface;
519 IHTMLStyle_AddRef(*p);
520 return S_OK;
523 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
525 HTMLElement *This = impl_from_IHTMLElement(iface);
526 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
527 return E_NOTIMPL;
530 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
532 HTMLElement *This = impl_from_IHTMLElement(iface);
533 FIXME("(%p)->(%p)\n", This, p);
534 return E_NOTIMPL;
537 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
539 HTMLElement *This = impl_from_IHTMLElement(iface);
541 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
543 return set_node_event(&This->node, EVENTID_CLICK, &v);
546 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
548 HTMLElement *This = impl_from_IHTMLElement(iface);
550 TRACE("(%p)->(%p)\n", This, p);
552 return get_node_event(&This->node, EVENTID_CLICK, p);
555 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
557 HTMLElement *This = impl_from_IHTMLElement(iface);
559 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
561 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
564 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
566 HTMLElement *This = impl_from_IHTMLElement(iface);
568 TRACE("(%p)->(%p)\n", This, p);
570 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
573 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
575 HTMLElement *This = impl_from_IHTMLElement(iface);
577 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
579 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
582 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
584 HTMLElement *This = impl_from_IHTMLElement(iface);
586 TRACE("(%p)->(%p)\n", This, p);
588 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
591 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
593 HTMLElement *This = impl_from_IHTMLElement(iface);
595 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
597 return set_node_event(&This->node, EVENTID_KEYUP, &v);
600 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
602 HTMLElement *This = impl_from_IHTMLElement(iface);
603 FIXME("(%p)->(%p)\n", This, p);
604 return E_NOTIMPL;
607 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
609 HTMLElement *This = impl_from_IHTMLElement(iface);
610 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
611 return E_NOTIMPL;
614 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
616 HTMLElement *This = impl_from_IHTMLElement(iface);
617 FIXME("(%p)->(%p)\n", This, p);
618 return E_NOTIMPL;
621 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
623 HTMLElement *This = impl_from_IHTMLElement(iface);
625 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
627 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
630 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
632 HTMLElement *This = impl_from_IHTMLElement(iface);
634 TRACE("(%p)->(%p)\n", This, p);
636 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
639 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
641 HTMLElement *This = impl_from_IHTMLElement(iface);
643 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
645 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
648 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
650 HTMLElement *This = impl_from_IHTMLElement(iface);
652 TRACE("(%p)->(%p)\n", This, p);
654 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
657 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
659 HTMLElement *This = impl_from_IHTMLElement(iface);
661 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
663 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
666 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
668 HTMLElement *This = impl_from_IHTMLElement(iface);
670 TRACE("(%p)->(%p)\n", This, p);
672 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
675 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
677 HTMLElement *This = impl_from_IHTMLElement(iface);
679 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
681 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
684 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
686 HTMLElement *This = impl_from_IHTMLElement(iface);
688 TRACE("(%p)->(%p)\n", This, p);
690 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
693 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
695 HTMLElement *This = impl_from_IHTMLElement(iface);
697 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
699 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
702 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
704 HTMLElement *This = impl_from_IHTMLElement(iface);
706 TRACE("(%p)->(%p)\n", This, p);
708 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
711 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
713 HTMLElement *This = impl_from_IHTMLElement(iface);
715 TRACE("(%p)->(%p)\n", This, p);
717 if(!p)
718 return E_POINTER;
720 if(This->node.vtbl->get_document)
721 return This->node.vtbl->get_document(&This->node, p);
723 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
724 IDispatch_AddRef(*p);
725 return S_OK;
728 static const WCHAR titleW[] = {'t','i','t','l','e',0};
730 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
732 HTMLElement *This = impl_from_IHTMLElement(iface);
733 nsAString title_str;
734 nsresult nsres;
736 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
738 if(!This->nselem) {
739 VARIANT *var;
740 HRESULT hres;
742 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
743 if(FAILED(hres))
744 return hres;
746 VariantClear(var);
747 V_VT(var) = VT_BSTR;
748 V_BSTR(var) = v ? SysAllocString(v) : NULL;
749 return S_OK;
752 nsAString_InitDepend(&title_str, v);
753 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
754 nsAString_Finish(&title_str);
755 if(NS_FAILED(nsres))
756 ERR("SetTitle failed: %08x\n", nsres);
758 return S_OK;
761 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
763 HTMLElement *This = impl_from_IHTMLElement(iface);
764 nsAString title_str;
765 nsresult nsres;
767 TRACE("(%p)->(%p)\n", This, p);
769 if(!This->nselem) {
770 VARIANT *var;
771 HRESULT hres;
773 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
774 if(hres == DISP_E_UNKNOWNNAME) {
775 *p = NULL;
776 }else if(V_VT(var) != VT_BSTR) {
777 FIXME("title = %s\n", debugstr_variant(var));
778 return E_FAIL;
779 }else {
780 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
783 return S_OK;
786 nsAString_Init(&title_str, NULL);
787 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
788 if(NS_SUCCEEDED(nsres)) {
789 const PRUnichar *title;
791 nsAString_GetData(&title_str, &title);
792 *p = *title ? SysAllocString(title) : NULL;
793 }else {
794 ERR("GetTitle failed: %08x\n", nsres);
795 return E_FAIL;
798 return S_OK;
801 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
803 HTMLElement *This = impl_from_IHTMLElement(iface);
804 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
805 return E_NOTIMPL;
808 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
810 HTMLElement *This = impl_from_IHTMLElement(iface);
811 FIXME("(%p)->(%p)\n", This, p);
812 return E_NOTIMPL;
815 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
817 HTMLElement *This = impl_from_IHTMLElement(iface);
819 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
821 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
824 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
826 HTMLElement *This = impl_from_IHTMLElement(iface);
828 TRACE("(%p)->(%p)\n", This, p);
830 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
833 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
835 HTMLElement *This = impl_from_IHTMLElement(iface);
836 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
837 return E_NOTIMPL;
840 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
841 VARIANT_BOOL *pfResult)
843 HTMLElement *This = impl_from_IHTMLElement(iface);
844 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
845 return E_NOTIMPL;
848 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
850 HTMLElement *This = impl_from_IHTMLElement(iface);
851 FIXME("(%p)->(%p)\n", This, p);
852 return E_NOTIMPL;
855 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
857 HTMLElement *This = impl_from_IHTMLElement(iface);
858 FIXME("(%p)->(%p)\n", This, p);
859 return E_NOTIMPL;
862 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
864 HTMLElement *This = impl_from_IHTMLElement(iface);
865 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
866 return E_NOTIMPL;
869 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
871 HTMLElement *This = impl_from_IHTMLElement(iface);
872 FIXME("(%p)->(%p)\n", This, p);
873 return E_NOTIMPL;
876 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
878 HTMLElement *This = impl_from_IHTMLElement(iface);
879 PRInt32 off_left = 0;
880 nsresult nsres;
882 TRACE("(%p)->(%p)\n", This, p);
884 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, &off_left);
885 if(NS_FAILED(nsres)) {
886 ERR("GetOffsetLeft failed: %08x\n", nsres);
887 return E_FAIL;
890 *p = off_left;
891 return S_OK;
894 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
896 HTMLElement *This = impl_from_IHTMLElement(iface);
897 PRInt32 top = 0;
898 nsresult nsres;
900 TRACE("(%p)->(%p)\n", This, p);
902 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, &top);
903 if(NS_FAILED(nsres)) {
904 ERR("GetOffsetTop failed: %08x\n", nsres);
905 return E_FAIL;
908 *p = top;
909 return S_OK;
912 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
914 HTMLElement *This = impl_from_IHTMLElement(iface);
915 PRInt32 offset = 0;
916 nsresult nsres;
918 TRACE("(%p)->(%p)\n", This, p);
920 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, &offset);
921 if(NS_FAILED(nsres)) {
922 ERR("GetOffsetWidth failed: %08x\n", nsres);
923 return E_FAIL;
926 *p = offset;
927 return S_OK;
930 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
932 HTMLElement *This = impl_from_IHTMLElement(iface);
933 PRInt32 offset = 0;
934 nsresult nsres;
936 TRACE("(%p)->(%p)\n", This, p);
938 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, &offset);
939 if(NS_FAILED(nsres)) {
940 ERR("GetOffsetHeight failed: %08x\n", nsres);
941 return E_FAIL;
944 *p = offset;
945 return S_OK;
948 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
950 HTMLElement *This = impl_from_IHTMLElement(iface);
951 nsIDOMElement *nsparent;
952 nsresult nsres;
953 HRESULT hres;
955 TRACE("(%p)->(%p)\n", This, p);
957 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
958 if(NS_FAILED(nsres)) {
959 ERR("GetOffsetParent failed: %08x\n", nsres);
960 return E_FAIL;
963 if(nsparent) {
964 HTMLDOMNode *node;
966 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
967 nsIDOMElement_Release(nsparent);
968 if(FAILED(hres))
969 return hres;
971 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
972 }else {
973 *p = NULL;
974 hres = S_OK;
977 return hres;
980 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
982 HTMLElement *This = impl_from_IHTMLElement(iface);
983 nsAString html_str;
984 nsresult nsres;
986 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
988 if(!This->nselem) {
989 FIXME("NULL nselem\n");
990 return E_NOTIMPL;
993 nsAString_InitDepend(&html_str, v);
994 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
995 nsAString_Finish(&html_str);
996 if(NS_FAILED(nsres)) {
997 FIXME("SetInnerHtml failed %08x\n", nsres);
998 return E_FAIL;
1001 return S_OK;
1004 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
1006 HTMLElement *This = impl_from_IHTMLElement(iface);
1007 nsAString html_str;
1008 nsresult nsres;
1010 TRACE("(%p)->(%p)\n", This, p);
1012 if(!This->nselem) {
1013 FIXME("NULL nselem\n");
1014 return E_NOTIMPL;
1017 nsAString_Init(&html_str, NULL);
1018 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
1019 if(NS_SUCCEEDED(nsres)) {
1020 const PRUnichar *html;
1022 nsAString_GetData(&html_str, &html);
1023 *p = *html ? SysAllocString(html) : NULL;
1024 }else {
1025 FIXME("SetInnerHtml failed %08x\n", nsres);
1026 *p = NULL;
1029 nsAString_Finish(&html_str);
1030 return S_OK;
1033 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
1035 HTMLElement *This = impl_from_IHTMLElement(iface);
1036 nsIDOMNode *nschild, *tmp;
1037 nsIDOMText *text_node;
1038 nsAString text_str;
1039 nsresult nsres;
1041 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1043 while(1) {
1044 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
1045 if(NS_FAILED(nsres)) {
1046 ERR("GetLastChild failed: %08x\n", nsres);
1047 return E_FAIL;
1049 if(!nschild)
1050 break;
1052 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1053 nsIDOMNode_Release(nschild);
1054 if(NS_FAILED(nsres)) {
1055 ERR("RemoveChild failed: %08x\n", nsres);
1056 return E_FAIL;
1058 nsIDOMNode_Release(tmp);
1061 nsAString_InitDepend(&text_str, v);
1062 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1063 nsAString_Finish(&text_str);
1064 if(NS_FAILED(nsres)) {
1065 ERR("CreateTextNode failed: %08x\n", nsres);
1066 return E_FAIL;
1069 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1070 if(NS_FAILED(nsres)) {
1071 ERR("AppendChild failed: %08x\n", nsres);
1072 return E_FAIL;
1075 nsIDOMNode_Release(tmp);
1076 return S_OK;
1079 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1081 HTMLElement *This = impl_from_IHTMLElement(iface);
1083 TRACE("(%p)->(%p)\n", This, p);
1085 return get_node_text(&This->node, p);
1088 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1090 HTMLElement *This = impl_from_IHTMLElement(iface);
1092 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1094 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1097 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1099 HTMLElement *This = impl_from_IHTMLElement(iface);
1100 nsAString html_str;
1101 HRESULT hres;
1103 WARN("(%p)->(%p) semi-stub\n", This, p);
1105 nsAString_Init(&html_str, NULL);
1106 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1107 if(SUCCEEDED(hres)) {
1108 const PRUnichar *html;
1110 nsAString_GetData(&html_str, &html);
1111 *p = SysAllocString(html);
1112 if(!*p)
1113 hres = E_OUTOFMEMORY;
1116 nsAString_Finish(&html_str);
1118 TRACE("ret %s\n", debugstr_w(*p));
1119 return hres;
1122 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1124 HTMLElement *This = impl_from_IHTMLElement(iface);
1125 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1126 return E_NOTIMPL;
1129 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1131 HTMLElement *This = impl_from_IHTMLElement(iface);
1132 FIXME("(%p)->(%p)\n", This, p);
1133 return E_NOTIMPL;
1136 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1138 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1139 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1140 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1141 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1142 nsresult nsres;
1144 if (!strcmpiW(where, wszBeforeBegin))
1146 nsIDOMNode *unused;
1147 nsIDOMNode *parent;
1148 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1149 if (!parent) return E_INVALIDARG;
1150 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1151 if (unused) nsIDOMNode_Release(unused);
1152 nsIDOMNode_Release(parent);
1154 else if (!strcmpiW(where, wszAfterBegin))
1156 nsIDOMNode *unused;
1157 nsIDOMNode *first_child;
1158 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1159 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1160 if (unused) nsIDOMNode_Release(unused);
1161 if (first_child) nsIDOMNode_Release(first_child);
1163 else if (!strcmpiW(where, wszBeforeEnd))
1165 nsIDOMNode *unused;
1166 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1167 if (unused) nsIDOMNode_Release(unused);
1169 else if (!strcmpiW(where, wszAfterEnd))
1171 nsIDOMNode *unused;
1172 nsIDOMNode *next_sibling;
1173 nsIDOMNode *parent;
1174 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1175 if (!parent) return E_INVALIDARG;
1177 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1178 if (next_sibling)
1180 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1181 nsIDOMNode_Release(next_sibling);
1183 else
1184 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1185 nsIDOMNode_Release(parent);
1186 if (unused) nsIDOMNode_Release(unused);
1188 else
1190 ERR("invalid where: %s\n", debugstr_w(where));
1191 return E_INVALIDARG;
1194 if (NS_FAILED(nsres))
1195 return E_FAIL;
1196 else
1197 return S_OK;
1200 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1201 BSTR html)
1203 HTMLElement *This = impl_from_IHTMLElement(iface);
1204 nsIDOMRange *range;
1205 nsIDOMNSRange *nsrange;
1206 nsIDOMNode *nsnode;
1207 nsAString ns_html;
1208 nsresult nsres;
1209 HRESULT hr;
1211 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1213 if(!This->node.doc->nsdoc) {
1214 WARN("NULL nsdoc\n");
1215 return E_UNEXPECTED;
1218 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1219 if(NS_FAILED(nsres))
1221 ERR("CreateRange failed: %08x\n", nsres);
1222 return E_FAIL;
1225 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1227 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
1228 nsIDOMRange_Release(range);
1229 if(NS_FAILED(nsres))
1231 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
1232 return E_FAIL;
1235 nsAString_InitDepend(&ns_html, html);
1237 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1238 nsIDOMNSRange_Release(nsrange);
1239 nsAString_Finish(&ns_html);
1241 if(NS_FAILED(nsres) || !nsnode)
1243 ERR("CreateTextNode failed: %08x\n", nsres);
1244 return E_FAIL;
1247 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1248 nsIDOMNode_Release(nsnode);
1250 return hr;
1253 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1254 BSTR text)
1256 HTMLElement *This = impl_from_IHTMLElement(iface);
1257 nsIDOMNode *nsnode;
1258 nsAString ns_text;
1259 nsresult nsres;
1260 HRESULT hr;
1262 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1264 if(!This->node.doc->nsdoc) {
1265 WARN("NULL nsdoc\n");
1266 return E_UNEXPECTED;
1270 nsAString_InitDepend(&ns_text, text);
1271 nsres = nsIDOMDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1272 nsAString_Finish(&ns_text);
1274 if(NS_FAILED(nsres) || !nsnode)
1276 ERR("CreateTextNode failed: %08x\n", nsres);
1277 return E_FAIL;
1280 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1281 nsIDOMNode_Release(nsnode);
1283 return hr;
1286 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1288 HTMLElement *This = impl_from_IHTMLElement(iface);
1289 FIXME("(%p)->(%p)\n", This, p);
1290 return E_NOTIMPL;
1293 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1295 HTMLElement *This = impl_from_IHTMLElement(iface);
1296 FIXME("(%p)->(%p)\n", This, p);
1297 return E_NOTIMPL;
1300 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1302 HTMLElement *This = impl_from_IHTMLElement(iface);
1304 TRACE("(%p)\n", This);
1306 return call_fire_event(&This->node, EVENTID_CLICK);
1309 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1310 IHTMLFiltersCollection **p)
1312 HTMLElement *This = impl_from_IHTMLElement(iface);
1313 TRACE("(%p)->(%p)\n", This, p);
1315 if(!p)
1316 return E_POINTER;
1318 *p = HTMLFiltersCollection_Create();
1320 return S_OK;
1323 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1325 HTMLElement *This = impl_from_IHTMLElement(iface);
1326 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1327 return E_NOTIMPL;
1330 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1332 HTMLElement *This = impl_from_IHTMLElement(iface);
1333 FIXME("(%p)->(%p)\n", This, p);
1334 return E_NOTIMPL;
1337 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1339 HTMLElement *This = impl_from_IHTMLElement(iface);
1340 FIXME("(%p)->(%p)\n", This, String);
1341 return E_NOTIMPL;
1344 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1346 HTMLElement *This = impl_from_IHTMLElement(iface);
1347 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1348 return E_NOTIMPL;
1351 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1353 HTMLElement *This = impl_from_IHTMLElement(iface);
1354 FIXME("(%p)->(%p)\n", This, p);
1355 return E_NOTIMPL;
1358 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1360 HTMLElement *This = impl_from_IHTMLElement(iface);
1361 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1362 return E_NOTIMPL;
1365 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1367 HTMLElement *This = impl_from_IHTMLElement(iface);
1368 FIXME("(%p)->(%p)\n", This, p);
1369 return E_NOTIMPL;
1372 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1374 HTMLElement *This = impl_from_IHTMLElement(iface);
1375 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1376 return E_NOTIMPL;
1379 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1381 HTMLElement *This = impl_from_IHTMLElement(iface);
1382 FIXME("(%p)->(%p)\n", This, p);
1383 return E_NOTIMPL;
1386 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1388 HTMLElement *This = impl_from_IHTMLElement(iface);
1389 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1390 return E_NOTIMPL;
1393 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1395 HTMLElement *This = impl_from_IHTMLElement(iface);
1396 FIXME("(%p)->(%p)\n", This, p);
1397 return E_NOTIMPL;
1400 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1402 HTMLElement *This = impl_from_IHTMLElement(iface);
1403 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1404 return E_NOTIMPL;
1407 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1409 HTMLElement *This = impl_from_IHTMLElement(iface);
1410 FIXME("(%p)->(%p)\n", This, p);
1411 return E_NOTIMPL;
1414 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1416 HTMLElement *This = impl_from_IHTMLElement(iface);
1417 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1418 return E_NOTIMPL;
1421 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1423 HTMLElement *This = impl_from_IHTMLElement(iface);
1424 FIXME("(%p)->(%p)\n", This, p);
1425 return E_NOTIMPL;
1428 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1430 HTMLElement *This = impl_from_IHTMLElement(iface);
1431 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1432 return E_NOTIMPL;
1435 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1437 HTMLElement *This = impl_from_IHTMLElement(iface);
1438 FIXME("(%p)->(%p)\n", This, p);
1439 return E_NOTIMPL;
1442 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1444 HTMLElement *This = impl_from_IHTMLElement(iface);
1445 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1446 return E_NOTIMPL;
1449 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1451 HTMLElement *This = impl_from_IHTMLElement(iface);
1452 FIXME("(%p)->(%p)\n", This, p);
1453 return E_NOTIMPL;
1456 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1458 HTMLElement *This = impl_from_IHTMLElement(iface);
1459 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1460 return E_NOTIMPL;
1463 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1465 HTMLElement *This = impl_from_IHTMLElement(iface);
1466 FIXME("(%p)->(%p)\n", This, p);
1467 return E_NOTIMPL;
1470 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1472 HTMLElement *This = impl_from_IHTMLElement(iface);
1473 nsIDOMNodeList *nsnode_list;
1474 nsresult nsres;
1476 TRACE("(%p)->(%p)\n", This, p);
1478 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1479 if(NS_FAILED(nsres)) {
1480 ERR("GetChildNodes failed: %08x\n", nsres);
1481 return E_FAIL;
1484 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc,
1485 (IUnknown*)&This->IHTMLElement_iface, nsnode_list);
1487 nsIDOMNodeList_Release(nsnode_list);
1488 return S_OK;
1491 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1493 HTMLElement *This = impl_from_IHTMLElement(iface);
1495 TRACE("(%p)->(%p)\n", This, p);
1497 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1498 return S_OK;
1501 static const IHTMLElementVtbl HTMLElementVtbl = {
1502 HTMLElement_QueryInterface,
1503 HTMLElement_AddRef,
1504 HTMLElement_Release,
1505 HTMLElement_GetTypeInfoCount,
1506 HTMLElement_GetTypeInfo,
1507 HTMLElement_GetIDsOfNames,
1508 HTMLElement_Invoke,
1509 HTMLElement_setAttribute,
1510 HTMLElement_getAttribute,
1511 HTMLElement_removeAttribute,
1512 HTMLElement_put_className,
1513 HTMLElement_get_className,
1514 HTMLElement_put_id,
1515 HTMLElement_get_id,
1516 HTMLElement_get_tagName,
1517 HTMLElement_get_parentElement,
1518 HTMLElement_get_style,
1519 HTMLElement_put_onhelp,
1520 HTMLElement_get_onhelp,
1521 HTMLElement_put_onclick,
1522 HTMLElement_get_onclick,
1523 HTMLElement_put_ondblclick,
1524 HTMLElement_get_ondblclick,
1525 HTMLElement_put_onkeydown,
1526 HTMLElement_get_onkeydown,
1527 HTMLElement_put_onkeyup,
1528 HTMLElement_get_onkeyup,
1529 HTMLElement_put_onkeypress,
1530 HTMLElement_get_onkeypress,
1531 HTMLElement_put_onmouseout,
1532 HTMLElement_get_onmouseout,
1533 HTMLElement_put_onmouseover,
1534 HTMLElement_get_onmouseover,
1535 HTMLElement_put_onmousemove,
1536 HTMLElement_get_onmousemove,
1537 HTMLElement_put_onmousedown,
1538 HTMLElement_get_onmousedown,
1539 HTMLElement_put_onmouseup,
1540 HTMLElement_get_onmouseup,
1541 HTMLElement_get_document,
1542 HTMLElement_put_title,
1543 HTMLElement_get_title,
1544 HTMLElement_put_language,
1545 HTMLElement_get_language,
1546 HTMLElement_put_onselectstart,
1547 HTMLElement_get_onselectstart,
1548 HTMLElement_scrollIntoView,
1549 HTMLElement_contains,
1550 HTMLElement_get_sourceIndex,
1551 HTMLElement_get_recordNumber,
1552 HTMLElement_put_lang,
1553 HTMLElement_get_lang,
1554 HTMLElement_get_offsetLeft,
1555 HTMLElement_get_offsetTop,
1556 HTMLElement_get_offsetWidth,
1557 HTMLElement_get_offsetHeight,
1558 HTMLElement_get_offsetParent,
1559 HTMLElement_put_innerHTML,
1560 HTMLElement_get_innerHTML,
1561 HTMLElement_put_innerText,
1562 HTMLElement_get_innerText,
1563 HTMLElement_put_outerHTML,
1564 HTMLElement_get_outerHTML,
1565 HTMLElement_put_outerText,
1566 HTMLElement_get_outerText,
1567 HTMLElement_insertAdjacentHTML,
1568 HTMLElement_insertAdjacentText,
1569 HTMLElement_get_parentTextEdit,
1570 HTMLElement_get_isTextEdit,
1571 HTMLElement_click,
1572 HTMLElement_get_filters,
1573 HTMLElement_put_ondragstart,
1574 HTMLElement_get_ondragstart,
1575 HTMLElement_toString,
1576 HTMLElement_put_onbeforeupdate,
1577 HTMLElement_get_onbeforeupdate,
1578 HTMLElement_put_onafterupdate,
1579 HTMLElement_get_onafterupdate,
1580 HTMLElement_put_onerrorupdate,
1581 HTMLElement_get_onerrorupdate,
1582 HTMLElement_put_onrowexit,
1583 HTMLElement_get_onrowexit,
1584 HTMLElement_put_onrowenter,
1585 HTMLElement_get_onrowenter,
1586 HTMLElement_put_ondatasetchanged,
1587 HTMLElement_get_ondatasetchanged,
1588 HTMLElement_put_ondataavailable,
1589 HTMLElement_get_ondataavailable,
1590 HTMLElement_put_ondatasetcomplete,
1591 HTMLElement_get_ondatasetcomplete,
1592 HTMLElement_put_onfilterchange,
1593 HTMLElement_get_onfilterchange,
1594 HTMLElement_get_children,
1595 HTMLElement_get_all
1598 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1600 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1603 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1605 return CONTAINING_RECORD(iface, HTMLElement, node);
1608 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1610 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1612 *ppv = NULL;
1614 if(IsEqualGUID(&IID_IUnknown, riid)) {
1615 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1616 *ppv = &This->IHTMLElement_iface;
1617 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1618 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1619 *ppv = &This->IHTMLElement_iface;
1620 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1621 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1622 *ppv = &This->IHTMLElement_iface;
1623 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1624 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1625 *ppv = &This->IHTMLElement2_iface;
1626 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1627 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1628 *ppv = &This->IHTMLElement3_iface;
1629 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1630 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1631 *ppv = &This->IHTMLElement4_iface;
1632 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1633 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1634 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1637 if(*ppv) {
1638 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1639 return S_OK;
1642 return HTMLDOMNode_QI(&This->node, riid, ppv);
1645 void HTMLElement_destructor(HTMLDOMNode *iface)
1647 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1649 ConnectionPointContainer_Destroy(&This->cp_container);
1651 if(This->nselem)
1652 nsIDOMHTMLElement_Release(This->nselem);
1653 if(This->style) {
1654 This->style->elem = NULL;
1655 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1657 if(This->attrs) {
1658 HTMLDOMAttribute *attr;
1660 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1661 attr->elem = NULL;
1663 This->attrs->elem = NULL;
1664 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1667 heap_free(This->filter);
1669 HTMLDOMNode_destructor(&This->node);
1672 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1674 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1675 HTMLElement *new_elem;
1676 HRESULT hres;
1678 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1679 if(FAILED(hres))
1680 return hres;
1682 IHTMLElement_AddRef(&new_elem->IHTMLElement_iface);
1683 *ret = &new_elem->node;
1684 return S_OK;
1687 static const NodeImplVtbl HTMLElementImplVtbl = {
1688 HTMLElement_QI,
1689 HTMLElement_destructor,
1690 HTMLElement_clone,
1691 HTMLElement_get_attr_col
1694 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1696 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1699 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1700 DWORD grfdex, DISPID *pid)
1702 HTMLElement *This = impl_from_DispatchEx(dispex);
1704 if(This->node.vtbl->get_dispid)
1705 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1707 return DISP_E_UNKNOWNNAME;
1710 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1711 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1712 IServiceProvider *caller)
1714 HTMLElement *This = impl_from_DispatchEx(dispex);
1716 if(This->node.vtbl->invoke)
1717 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1718 params, res, ei, caller);
1720 ERR("(%p): element has no invoke method\n", This);
1721 return E_NOTIMPL;
1724 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1726 HTMLElement *This = impl_from_DispatchEx(dispex);
1727 nsIDOMNamedNodeMap *attrs;
1728 nsIDOMNode *node;
1729 nsAString nsstr;
1730 const PRUnichar *str;
1731 BSTR name;
1732 VARIANT value;
1733 unsigned i;
1734 PRUint32 len;
1735 DISPID id;
1736 nsresult nsres;
1737 HRESULT hres;
1739 if(!This->nselem)
1740 return S_FALSE;
1742 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1743 if(NS_FAILED(nsres))
1744 return E_FAIL;
1746 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1747 if(NS_FAILED(nsres)) {
1748 nsIDOMNamedNodeMap_Release(attrs);
1749 return E_FAIL;
1752 nsAString_Init(&nsstr, NULL);
1753 for(i=0; i<len; i++) {
1754 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1755 if(NS_FAILED(nsres))
1756 continue;
1758 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1759 if(NS_FAILED(nsres)) {
1760 nsIDOMNode_Release(node);
1761 continue;
1764 nsAString_GetData(&nsstr, &str);
1765 name = SysAllocString(str);
1766 if(!name) {
1767 nsIDOMNode_Release(node);
1768 continue;
1771 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1772 if(hres != DISP_E_UNKNOWNNAME) {
1773 nsIDOMNode_Release(node);
1774 SysFreeString(name);
1775 continue;
1778 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1779 nsIDOMNode_Release(node);
1780 if(NS_FAILED(nsres)) {
1781 SysFreeString(name);
1782 continue;
1785 nsAString_GetData(&nsstr, &str);
1786 V_VT(&value) = VT_BSTR;
1787 if(*str) {
1788 V_BSTR(&value) = SysAllocString(str);
1789 if(!V_BSTR(&value)) {
1790 SysFreeString(name);
1791 continue;
1793 } else
1794 V_BSTR(&value) = NULL;
1796 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1797 SysFreeString(name);
1798 VariantClear(&value);
1800 nsAString_Finish(&nsstr);
1802 nsIDOMNamedNodeMap_Release(attrs);
1803 return S_OK;
1806 static const tid_t HTMLElement_iface_tids[] = {
1807 HTMLELEMENT_TIDS,
1811 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1812 NULL,
1813 HTMLElement_get_dispid,
1814 HTMLElement_invoke,
1815 HTMLElement_populate_props
1818 static dispex_static_data_t HTMLElement_dispex = {
1819 &HTMLElement_dispex_vtbl,
1820 DispHTMLUnknownElement_tid,
1821 NULL,
1822 HTMLElement_iface_tids
1825 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1827 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1829 HTMLElement2_Init(This);
1830 HTMLElement3_Init(This);
1832 if(dispex_data && !dispex_data->vtbl)
1833 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1834 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1835 dispex_data ? dispex_data : &HTMLElement_dispex);
1837 if(nselem)
1838 nsIDOMHTMLElement_AddRef(nselem);
1839 This->nselem = nselem;
1841 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1843 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1846 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1848 nsIDOMHTMLElement *nselem;
1849 nsAString class_name_str;
1850 const PRUnichar *class_name;
1851 const tag_desc_t *tag;
1852 HTMLElement *elem;
1853 nsresult nsres;
1854 HRESULT hres;
1856 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1857 if(NS_FAILED(nsres))
1858 return E_FAIL;
1860 nsAString_Init(&class_name_str, NULL);
1861 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1863 nsAString_GetData(&class_name_str, &class_name);
1865 tag = get_tag_desc(class_name);
1866 if(tag) {
1867 hres = tag->constructor(doc, nselem, &elem);
1868 }else if(use_generic) {
1869 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1870 }else {
1871 elem = heap_alloc_zero(sizeof(HTMLElement));
1872 if(elem) {
1873 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1874 elem->node.vtbl = &HTMLElementImplVtbl;
1875 hres = S_OK;
1876 }else {
1877 hres = E_OUTOFMEMORY;
1881 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1883 nsIDOMElement_Release(nselem);
1884 nsAString_Finish(&class_name_str);
1885 if(FAILED(hres))
1886 return hres;
1888 *ret = elem;
1889 return S_OK;
1892 /* interface IHTMLFiltersCollection */
1893 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1895 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1897 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1899 if(IsEqualGUID(&IID_IUnknown, riid)) {
1900 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1901 *ppv = &This->IHTMLFiltersCollection_iface;
1902 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1903 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1904 *ppv = &This->IHTMLFiltersCollection_iface;
1905 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1906 return *ppv ? S_OK : E_NOINTERFACE;
1909 if(*ppv) {
1910 IUnknown_AddRef((IUnknown*)*ppv);
1911 return S_OK;
1914 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1915 return E_NOINTERFACE;
1918 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1920 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1921 LONG ref = InterlockedIncrement(&This->ref);
1923 TRACE("(%p) ref=%d\n", This, ref);
1925 return ref;
1928 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1930 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1931 LONG ref = InterlockedDecrement(&This->ref);
1933 TRACE("(%p) ref=%d\n", This, ref);
1935 if(!ref)
1937 heap_free(This);
1940 return ref;
1943 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1945 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1946 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1949 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1950 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1952 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1953 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1956 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1957 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1958 LCID lcid, DISPID *rgDispId)
1960 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1961 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1962 lcid, rgDispId);
1965 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1966 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1967 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1969 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1970 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1971 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1974 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1976 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1978 if(!p)
1979 return E_POINTER;
1981 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1982 *p = 0;
1984 return S_OK;
1987 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1989 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1990 FIXME("(%p)->(%p)\n", This, p);
1991 return E_NOTIMPL;
1994 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
1996 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1997 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
1998 return E_NOTIMPL;
2001 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2002 HTMLFiltersCollection_QueryInterface,
2003 HTMLFiltersCollection_AddRef,
2004 HTMLFiltersCollection_Release,
2005 HTMLFiltersCollection_GetTypeInfoCount,
2006 HTMLFiltersCollection_GetTypeInfo,
2007 HTMLFiltersCollection_GetIDsOfNames,
2008 HTMLFiltersCollection_Invoke,
2009 HTMLFiltersCollection_get_length,
2010 HTMLFiltersCollection_get__newEnum,
2011 HTMLFiltersCollection_item
2014 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2016 WCHAR *ptr;
2017 int idx = 0;
2019 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2020 idx = idx*10 + (*ptr-'0');
2021 if(*ptr)
2022 return DISP_E_UNKNOWNNAME;
2024 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2025 TRACE("ret %x\n", *dispid);
2026 return S_OK;
2029 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2030 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2032 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2034 V_VT(res) = VT_DISPATCH;
2035 V_DISPATCH(res) = NULL;
2037 FIXME("always returning NULL\n");
2039 return S_OK;
2042 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2043 NULL,
2044 HTMLFiltersCollection_get_dispid,
2045 HTMLFiltersCollection_invoke,
2046 NULL
2049 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2050 IHTMLFiltersCollection_tid,
2053 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2054 &HTMLFiltersCollection_dispex_vtbl,
2055 IHTMLFiltersCollection_tid,
2056 NULL,
2057 HTMLFiltersCollection_iface_tids
2060 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2062 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2064 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2065 ret->ref = 1;
2067 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2068 &HTMLFiltersCollection_dispex);
2070 return &ret->IHTMLFiltersCollection_iface;
2073 /* interface IHTMLAttributeCollection */
2074 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2076 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2079 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2081 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2083 *ppv = NULL;
2085 if(IsEqualGUID(&IID_IUnknown, riid)) {
2086 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2087 *ppv = &This->IHTMLAttributeCollection_iface;
2088 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2089 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2090 *ppv = &This->IHTMLAttributeCollection_iface;
2091 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2092 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2093 *ppv = &This->IHTMLAttributeCollection2_iface;
2094 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2095 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2096 *ppv = &This->IHTMLAttributeCollection3_iface;
2097 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2098 return *ppv ? S_OK : E_NOINTERFACE;
2101 if(*ppv) {
2102 IUnknown_AddRef((IUnknown*)*ppv);
2103 return S_OK;
2106 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2107 return E_NOINTERFACE;
2110 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2112 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2113 LONG ref = InterlockedIncrement(&This->ref);
2115 TRACE("(%p) ref=%d\n", This, ref);
2117 return ref;
2120 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2122 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2123 LONG ref = InterlockedDecrement(&This->ref);
2125 TRACE("(%p) ref=%d\n", This, ref);
2127 if(!ref) {
2128 while(!list_empty(&This->attrs)) {
2129 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2131 list_remove(&attr->entry);
2132 attr->elem = NULL;
2133 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2136 heap_free(This);
2139 return ref;
2142 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2144 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2145 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2148 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2149 LCID lcid, ITypeInfo **ppTInfo)
2151 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2152 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2155 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2156 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2158 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2159 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2160 lcid, rgDispId);
2163 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2164 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2165 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2167 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2168 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2169 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2172 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2174 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2175 DISPID id = DISPID_STARTENUM;
2176 LONG len = -1;
2177 HRESULT hres;
2179 FIXME("filter non-enumerable attributes out\n");
2181 while(1) {
2182 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2183 if(FAILED(hres))
2184 return hres;
2185 else if(hres == S_FALSE)
2186 break;
2188 len++;
2189 if(len == *idx)
2190 break;
2193 if(dispid) {
2194 *dispid = id;
2195 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2198 *idx = len+1;
2199 return S_OK;
2202 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2204 HRESULT hres;
2206 if(name[0]>='0' && name[0]<='9') {
2207 WCHAR *end_ptr;
2208 LONG idx;
2210 idx = strtoulW(name, &end_ptr, 10);
2211 if(!*end_ptr) {
2212 hres = get_attr_dispid_by_idx(This, &idx, id);
2213 if(SUCCEEDED(hres))
2214 return hres;
2218 if(!This->elem) {
2219 WARN("NULL elem\n");
2220 return E_UNEXPECTED;
2223 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2224 name, fdexNameCaseInsensitive, id);
2225 return hres;
2228 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2230 HTMLDOMAttribute *iter;
2231 LONG pos = 0;
2232 HRESULT hres;
2234 *attr = NULL;
2235 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2236 if(iter->dispid == id) {
2237 *attr = iter;
2238 break;
2240 pos++;
2243 if(!*attr) {
2244 if(!This->elem) {
2245 WARN("NULL elem\n");
2246 return E_UNEXPECTED;
2249 pos++;
2250 hres = HTMLDOMAttribute_Create(This->elem, id, attr);
2251 if(FAILED(hres))
2252 return hres;
2255 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2256 if(list_pos)
2257 *list_pos = pos;
2258 return S_OK;
2261 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2263 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2264 HRESULT hres;
2266 TRACE("(%p)->(%p)\n", This, p);
2268 *p = -1;
2269 hres = get_attr_dispid_by_idx(This, p, NULL);
2270 return hres;
2273 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2275 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2276 FIXME("(%p)->(%p)\n", This, p);
2277 return E_NOTIMPL;
2280 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2282 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2283 HTMLDOMAttribute *attr;
2284 DISPID id;
2285 HRESULT hres;
2287 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2289 switch(V_VT(name)) {
2290 case VT_I4:
2291 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2292 break;
2293 case VT_BSTR:
2294 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2295 break;
2296 default:
2297 FIXME("unsupported name %s\n", debugstr_variant(name));
2298 hres = E_NOTIMPL;
2300 if(hres == DISP_E_UNKNOWNNAME)
2301 return E_INVALIDARG;
2302 if(FAILED(hres))
2303 return hres;
2305 hres = get_domattr(This, id, NULL, &attr);
2306 if(FAILED(hres))
2307 return hres;
2309 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2310 return S_OK;
2313 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2314 HTMLAttributeCollection_QueryInterface,
2315 HTMLAttributeCollection_AddRef,
2316 HTMLAttributeCollection_Release,
2317 HTMLAttributeCollection_GetTypeInfoCount,
2318 HTMLAttributeCollection_GetTypeInfo,
2319 HTMLAttributeCollection_GetIDsOfNames,
2320 HTMLAttributeCollection_Invoke,
2321 HTMLAttributeCollection_get_length,
2322 HTMLAttributeCollection__newEnum,
2323 HTMLAttributeCollection_item
2326 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2328 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2331 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2333 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2334 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2337 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2339 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2340 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2343 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2345 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2346 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2349 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2351 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2352 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2355 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2356 LCID lcid, ITypeInfo **ppTInfo)
2358 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2359 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2362 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2363 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2365 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2366 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2367 lcid, rgDispId);
2370 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2371 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2372 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2374 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2375 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2376 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2379 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2380 IHTMLDOMAttribute **newretNode)
2382 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2383 HTMLDOMAttribute *attr;
2384 DISPID id;
2385 HRESULT hres;
2387 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2389 hres = get_attr_dispid_by_name(This, bstrName, &id);
2390 if(hres == DISP_E_UNKNOWNNAME) {
2391 *newretNode = NULL;
2392 return S_OK;
2393 } else if(FAILED(hres)) {
2394 return hres;
2397 hres = get_domattr(This, id, NULL, &attr);
2398 if(FAILED(hres))
2399 return hres;
2401 *newretNode = &attr->IHTMLDOMAttribute_iface;
2402 return S_OK;
2405 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2406 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2408 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2409 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2410 return E_NOTIMPL;
2413 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2414 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2416 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2417 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2418 return E_NOTIMPL;
2421 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2422 HTMLAttributeCollection2_QueryInterface,
2423 HTMLAttributeCollection2_AddRef,
2424 HTMLAttributeCollection2_Release,
2425 HTMLAttributeCollection2_GetTypeInfoCount,
2426 HTMLAttributeCollection2_GetTypeInfo,
2427 HTMLAttributeCollection2_GetIDsOfNames,
2428 HTMLAttributeCollection2_Invoke,
2429 HTMLAttributeCollection2_getNamedItem,
2430 HTMLAttributeCollection2_setNamedItem,
2431 HTMLAttributeCollection2_removeNamedItem
2434 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2436 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2439 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2441 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2442 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2445 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2447 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2448 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2451 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2453 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2454 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2457 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2459 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2460 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2463 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2464 LCID lcid, ITypeInfo **ppTInfo)
2466 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2467 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2470 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2471 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2473 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2474 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2475 lcid, rgDispId);
2478 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2479 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2480 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2482 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2483 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2484 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2487 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2488 IHTMLDOMAttribute **ppNodeOut)
2490 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2491 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2494 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2495 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2497 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2498 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2499 return E_NOTIMPL;
2502 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2503 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2505 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2506 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2507 return E_NOTIMPL;
2510 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2512 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2513 HTMLDOMAttribute *attr;
2514 DISPID id;
2515 HRESULT hres;
2517 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2519 hres = get_attr_dispid_by_idx(This, &index, &id);
2520 if(hres == DISP_E_UNKNOWNNAME)
2521 return E_INVALIDARG;
2522 if(FAILED(hres))
2523 return hres;
2525 hres = get_domattr(This, id, NULL, &attr);
2526 if(FAILED(hres))
2527 return hres;
2529 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2530 return S_OK;
2533 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2535 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2536 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2539 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2540 HTMLAttributeCollection3_QueryInterface,
2541 HTMLAttributeCollection3_AddRef,
2542 HTMLAttributeCollection3_Release,
2543 HTMLAttributeCollection3_GetTypeInfoCount,
2544 HTMLAttributeCollection3_GetTypeInfo,
2545 HTMLAttributeCollection3_GetIDsOfNames,
2546 HTMLAttributeCollection3_Invoke,
2547 HTMLAttributeCollection3_getNamedItem,
2548 HTMLAttributeCollection3_setNamedItem,
2549 HTMLAttributeCollection3_removeNamedItem,
2550 HTMLAttributeCollection3_item,
2551 HTMLAttributeCollection3_get_length
2554 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2556 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2559 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2561 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2562 HTMLDOMAttribute *attr;
2563 LONG pos;
2564 HRESULT hres;
2566 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2568 hres = get_attr_dispid_by_name(This, name, dispid);
2569 if(FAILED(hres))
2570 return hres;
2572 hres = get_domattr(This, *dispid, &pos, &attr);
2573 if(FAILED(hres))
2574 return hres;
2575 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2577 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2578 return S_OK;
2581 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2582 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2584 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2586 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2588 switch(flags) {
2589 case DISPATCH_PROPERTYGET: {
2590 HTMLDOMAttribute *iter;
2592 id = id-MSHTML_DISPID_CUSTOM_MIN+1;
2594 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2595 if(!(--id))
2596 break;
2598 if(id)
2599 return E_INVALIDARG;
2601 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2602 V_VT(res) = VT_DISPATCH;
2603 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2604 return S_OK;
2607 default:
2608 FIXME("unimplemented flags %x\n", flags);
2609 return E_NOTIMPL;
2613 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2614 NULL,
2615 HTMLAttributeCollection_get_dispid,
2616 HTMLAttributeCollection_invoke,
2617 NULL
2620 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2621 IHTMLAttributeCollection_tid,
2622 IHTMLAttributeCollection2_tid,
2623 IHTMLAttributeCollection3_tid,
2627 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2628 &HTMLAttributeCollection_dispex_vtbl,
2629 DispHTMLAttributeCollection_tid,
2630 NULL,
2631 HTMLAttributeCollection_iface_tids
2634 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2636 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2638 if(This->attrs) {
2639 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2640 *ac = This->attrs;
2641 return S_OK;
2644 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2645 if(!This->attrs)
2646 return E_OUTOFMEMORY;
2648 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2649 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2650 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2651 This->attrs->ref = 2;
2653 This->attrs->elem = This;
2654 list_init(&This->attrs->attrs);
2655 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2656 &HTMLAttributeCollection_dispex);
2658 *ac = This->attrs;
2659 return S_OK;