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
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 static HRESULT HTMLElementCollection_Create(IUnknown*,HTMLElement**,DWORD,IDispatch**);
49 static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
51 if(buf->len == buf->size) {
53 buf->buf = mshtml_realloc(buf->buf, buf->size*sizeof(HTMLElement**));
56 buf->buf[buf->len++] = elem;
59 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
61 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
62 REFIID riid, void **ppv)
64 HTMLElement *This = HTMLELEM_THIS(iface);
68 return IUnknown_QueryInterface(This->impl, riid, ppv);
70 hres = HTMLElement_QI(This, riid, ppv);
72 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
77 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
79 HTMLElement *This = HTMLELEM_THIS(iface);
82 return IUnknown_AddRef(This->impl);
84 TRACE("(%p)\n", This);
85 return IHTMLDocument2_AddRef(HTMLDOC(This->node->doc));
88 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
90 HTMLElement *This = HTMLELEM_THIS(iface);
93 return IUnknown_Release(This->impl);
95 TRACE("(%p)\n", This);
96 return IHTMLDocument2_Release(HTMLDOC(This->node->doc));
99 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
101 HTMLElement *This = HTMLELEM_THIS(iface);
102 FIXME("(%p)->(%p)\n", This, pctinfo);
106 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
107 LCID lcid, ITypeInfo **ppTInfo)
109 HTMLElement *This = HTMLELEM_THIS(iface);
110 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
114 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
115 LPOLESTR *rgszNames, UINT cNames,
116 LCID lcid, DISPID *rgDispId)
118 HTMLElement *This = HTMLELEM_THIS(iface);
119 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
124 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
125 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
126 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
128 HTMLElement *This = HTMLELEM_THIS(iface);
129 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
130 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
134 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
135 VARIANT AttributeValue, LONG lFlags)
137 HTMLElement *This = HTMLELEM_THIS(iface);
142 VARIANT AttributeValueChanged;
144 WARN("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
146 VariantInit(&AttributeValueChanged);
148 hres = VariantChangeType(&AttributeValueChanged, &AttributeValue, 0, VT_BSTR);
150 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue));
154 nsAString_Init(&attr_str, strAttributeName);
155 nsAString_Init(&value_str, V_BSTR(&AttributeValueChanged));
157 TRACE("setting %s to %s\n", debugstr_w(strAttributeName),
158 debugstr_w(V_BSTR(&AttributeValueChanged)));
160 nsres = nsIDOMHTMLElement_SetAttribute(This->nselem, &attr_str, &value_str);
161 nsAString_Finish(&attr_str);
162 nsAString_Finish(&value_str);
164 if(NS_SUCCEEDED(nsres)) {
167 ERR("SetAttribute failed: %08x\n", nsres);
174 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
175 LONG lFlags, VARIANT *AttributeValue)
177 HTMLElement *This = HTMLELEM_THIS(iface);
180 const PRUnichar *value;
184 WARN("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
186 VariantInit(AttributeValue);
188 nsAString_Init(&attr_str, strAttributeName);
189 nsAString_Init(&value_str, NULL);
191 nsres = nsIDOMHTMLElement_GetAttribute(This->nselem, &attr_str, &value_str);
192 nsAString_Finish(&attr_str);
194 if(NS_SUCCEEDED(nsres)) {
195 static const WCHAR wszSRC[] = {'s','r','c',0};
196 nsAString_GetData(&value_str, &value, NULL);
197 if(!strcmpiW(strAttributeName, wszSRC))
202 hres = IHTMLDocument2_get_URL(HTMLDOC(This->node->doc), &bstrBaseUrl);
203 if(SUCCEEDED(hres)) {
204 hres = CoInternetCombineUrl(bstrBaseUrl, value,
205 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
206 buffer, sizeof(buffer)/sizeof(WCHAR), &len, 0);
207 SysFreeString(bstrBaseUrl);
208 if(SUCCEEDED(hres)) {
209 V_VT(AttributeValue) = VT_BSTR;
210 V_BSTR(AttributeValue) = SysAllocString(buffer);
211 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
215 V_VT(AttributeValue) = VT_BSTR;
216 V_BSTR(AttributeValue) = SysAllocString(value);
217 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
220 ERR("GetAttribute failed: %08x\n", nsres);
224 nsAString_Finish(&value_str);
229 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
230 LONG lFlags, VARIANT_BOOL *pfSuccess)
232 HTMLElement *This = HTMLELEM_THIS(iface);
233 FIXME("(%p)->()\n", This);
237 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
239 HTMLElement *This = HTMLELEM_THIS(iface);
240 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
244 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
246 HTMLElement *This = HTMLELEM_THIS(iface);
251 TRACE("(%p)->(%p)\n", This, p);
253 nsAString_Init(&class_str, NULL);
254 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
256 if(NS_SUCCEEDED(nsres)) {
257 const PRUnichar *class;
258 nsAString_GetData(&class_str, &class, NULL);
259 *p = SysAllocString(class);
261 ERR("GetClassName failed: %08x\n", nsres);
265 nsAString_Finish(&class_str);
267 TRACE("className=%s\n", debugstr_w(*p));
271 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
273 HTMLElement *This = HTMLELEM_THIS(iface);
274 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
278 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
280 HTMLElement *This = HTMLELEM_THIS(iface);
281 FIXME("(%p)->(%p)\n", This, p);
285 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
287 HTMLElement *This = HTMLELEM_THIS(iface);
288 FIXME("(%p)->(%p)\n", This, p);
292 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
294 HTMLElement *This = HTMLELEM_THIS(iface);
295 FIXME("(%p)->(%p)\n", This, p);
299 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
301 HTMLElement *This = HTMLELEM_THIS(iface);
302 nsIDOMElementCSSInlineStyle *nselemstyle;
303 nsIDOMCSSStyleDeclaration *nsstyle;
306 TRACE("(%p)->(%p)\n", This, p);
308 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
309 (void**)&nselemstyle);
310 if(NS_FAILED(nsres)) {
311 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
315 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
316 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
317 if(NS_FAILED(nsres)) {
318 ERR("GetStyle failed: %08x\n", nsres);
322 /* FIXME: Store style instead of creating a new instance in each call */
323 *p = HTMLStyle_Create(nsstyle);
325 nsIDOMCSSStyleDeclaration_Release(nsstyle);
329 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
331 HTMLElement *This = HTMLELEM_THIS(iface);
332 FIXME("(%p)->()\n", This);
336 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
338 HTMLElement *This = HTMLELEM_THIS(iface);
339 FIXME("(%p)->(%p)\n", This, p);
343 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
345 HTMLElement *This = HTMLELEM_THIS(iface);
346 FIXME("(%p)->()\n", This);
350 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
352 HTMLElement *This = HTMLELEM_THIS(iface);
353 FIXME("(%p)->(%p)\n", This, p);
357 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
359 HTMLElement *This = HTMLELEM_THIS(iface);
360 FIXME("(%p)->()\n", This);
364 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
366 HTMLElement *This = HTMLELEM_THIS(iface);
367 FIXME("(%p)->(%p)\n", This, p);
371 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
373 HTMLElement *This = HTMLELEM_THIS(iface);
374 FIXME("(%p)->()\n", This);
378 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
380 HTMLElement *This = HTMLELEM_THIS(iface);
381 FIXME("(%p)->(%p)\n", This, p);
385 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
387 HTMLElement *This = HTMLELEM_THIS(iface);
388 FIXME("(%p)->()\n", This);
392 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
394 HTMLElement *This = HTMLELEM_THIS(iface);
395 FIXME("(%p)->(%p)\n", This, p);
399 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
401 HTMLElement *This = HTMLELEM_THIS(iface);
402 FIXME("(%p)->()\n", This);
406 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
408 HTMLElement *This = HTMLELEM_THIS(iface);
409 FIXME("(%p)->(%p)\n", This, p);
413 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
415 HTMLElement *This = HTMLELEM_THIS(iface);
416 FIXME("(%p)->()\n", This);
420 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
422 HTMLElement *This = HTMLELEM_THIS(iface);
423 FIXME("(%p)->(%p)\n", This, p);
427 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
429 HTMLElement *This = HTMLELEM_THIS(iface);
430 FIXME("(%p)->()\n", This);
434 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
436 HTMLElement *This = HTMLELEM_THIS(iface);
437 FIXME("(%p)->(%p)\n", This, p);
441 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
443 HTMLElement *This = HTMLELEM_THIS(iface);
444 FIXME("(%p)->()\n", This);
448 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
450 HTMLElement *This = HTMLELEM_THIS(iface);
451 FIXME("(%p)->(%p)\n", This, p);
455 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
457 HTMLElement *This = HTMLELEM_THIS(iface);
458 FIXME("(%p)->()\n", This);
462 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
464 HTMLElement *This = HTMLELEM_THIS(iface);
465 FIXME("(%p)->(%p)\n", This, p);
469 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
471 HTMLElement *This = HTMLELEM_THIS(iface);
472 FIXME("(%p)->()\n", This);
476 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
478 HTMLElement *This = HTMLELEM_THIS(iface);
479 FIXME("(%p)->(%p)\n", This, p);
483 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
485 HTMLElement *This = HTMLELEM_THIS(iface);
486 FIXME("(%p)->(%p)\n", This, p);
490 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
492 HTMLElement *This = HTMLELEM_THIS(iface);
493 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
497 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
499 HTMLElement *This = HTMLELEM_THIS(iface);
500 FIXME("(%p)->(%p)\n", This, p);
504 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
506 HTMLElement *This = HTMLELEM_THIS(iface);
507 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
511 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
513 HTMLElement *This = HTMLELEM_THIS(iface);
514 FIXME("(%p)->(%p)\n", This, p);
518 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
520 HTMLElement *This = HTMLELEM_THIS(iface);
521 FIXME("(%p)->()\n", This);
525 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
527 HTMLElement *This = HTMLELEM_THIS(iface);
528 FIXME("(%p)->(%p)\n", This, p);
532 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
534 HTMLElement *This = HTMLELEM_THIS(iface);
535 FIXME("(%p)->()\n", This);
539 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
540 VARIANT_BOOL *pfResult)
542 HTMLElement *This = HTMLELEM_THIS(iface);
543 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
547 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
549 HTMLElement *This = HTMLELEM_THIS(iface);
550 FIXME("(%p)->(%p)\n", This, p);
554 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
556 HTMLElement *This = HTMLELEM_THIS(iface);
557 FIXME("(%p)->(%p)\n", This, p);
561 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
563 HTMLElement *This = HTMLELEM_THIS(iface);
564 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
568 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
570 HTMLElement *This = HTMLELEM_THIS(iface);
571 FIXME("(%p)->(%p)\n", This, p);
575 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
577 HTMLElement *This = HTMLELEM_THIS(iface);
578 FIXME("(%p)->(%p)\n", This, p);
582 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
584 HTMLElement *This = HTMLELEM_THIS(iface);
585 FIXME("(%p)->(%p)\n", This, p);
589 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
591 HTMLElement *This = HTMLELEM_THIS(iface);
592 FIXME("(%p)->(%p)\n", This, p);
596 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
598 HTMLElement *This = HTMLELEM_THIS(iface);
599 FIXME("(%p)->(%p)\n", This, p);
603 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
605 HTMLElement *This = HTMLELEM_THIS(iface);
606 FIXME("(%p)->(%p)\n", This, p);
610 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
612 HTMLElement *This = HTMLELEM_THIS(iface);
613 nsIDOMNSHTMLElement *nselem;
617 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
619 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
620 if(NS_FAILED(nsres)) {
621 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
625 nsAString_Init(&html_str, v);
626 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
627 nsAString_Finish(&html_str);
629 if(NS_FAILED(nsres)) {
630 FIXME("SetInnerHtml failed %08x\n", nsres);
637 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
639 HTMLElement *This = HTMLELEM_THIS(iface);
640 FIXME("(%p)->(%p)\n", This, p);
644 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
646 HTMLElement *This = HTMLELEM_THIS(iface);
647 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
651 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
653 HTMLElement *This = HTMLELEM_THIS(iface);
654 FIXME("(%p)->(%p)\n", This, p);
658 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
660 HTMLElement *This = HTMLELEM_THIS(iface);
661 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
665 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
667 HTMLElement *This = HTMLELEM_THIS(iface);
668 FIXME("(%p)->(%p)\n", This, p);
672 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
674 HTMLElement *This = HTMLELEM_THIS(iface);
675 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
679 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
681 HTMLElement *This = HTMLELEM_THIS(iface);
682 FIXME("(%p)->(%p)\n", This, p);
686 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
688 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
689 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
690 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
691 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
694 if (!strcmpiW(where, wszBeforeBegin))
698 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
699 if (!parent) return E_INVALIDARG;
700 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
701 (nsIDOMNode *)This->nselem, &unused);
702 if (unused) nsIDOMNode_Release(unused);
703 nsIDOMNode_Release(parent);
705 else if (!strcmpiW(where, wszAfterBegin))
708 nsIDOMNode *first_child;
709 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
710 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
711 if (unused) nsIDOMNode_Release(unused);
712 if (first_child) nsIDOMNode_Release(first_child);
714 else if (!strcmpiW(where, wszBeforeEnd))
717 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
718 if (unused) nsIDOMNode_Release(unused);
720 else if (!strcmpiW(where, wszAfterEnd))
723 nsIDOMNode *next_sibling;
725 nsIDOMNode_GetParentNode(This->nselem, &parent);
726 if (!parent) return E_INVALIDARG;
728 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
731 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
732 nsIDOMNode_Release(next_sibling);
735 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
736 nsIDOMNode_Release(parent);
737 if (unused) nsIDOMNode_Release(unused);
741 ERR("invalid where: %s\n", debugstr_w(where));
745 if (NS_FAILED(nsres))
751 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
754 HTMLElement *This = HTMLELEM_THIS(iface);
756 nsIDOMDocument *nsdoc;
757 nsIDOMDocumentRange *nsdocrange;
759 nsIDOMNSRange *nsrange;
764 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
766 nsres = nsIWebNavigation_GetDocument(This->node->doc->nscontainer->navigation, &nsdoc);
769 ERR("GetDocument failed: %08x\n", nsres);
773 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
774 nsIDOMDocument_Release(nsdoc);
777 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
780 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
781 nsIDOMDocumentRange_Release(nsdocrange);
784 ERR("CreateRange failed: %08x\n", nsres);
788 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
790 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
791 nsIDOMRange_Release(range);
794 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
798 nsAString_Init(&ns_html, html);
800 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
801 nsIDOMNSRange_Release(nsrange);
802 nsAString_Finish(&ns_html);
804 if(NS_FAILED(nsres) || !nsnode)
806 ERR("CreateTextNode failed: %08x\n", nsres);
810 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
811 nsIDOMNode_Release(nsnode);
816 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
819 HTMLElement *This = HTMLELEM_THIS(iface);
821 nsIDOMDocument *nsdoc;
826 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
828 nsres = nsIWebNavigation_GetDocument(This->node->doc->nscontainer->navigation, &nsdoc);
829 if(NS_FAILED(nsres) || !nsdoc)
831 ERR("GetDocument failed: %08x\n", nsres);
835 nsAString_Init(&ns_text, text);
837 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
838 nsIDOMDocument_Release(nsdoc);
839 nsAString_Finish(&ns_text);
841 if(NS_FAILED(nsres) || !nsnode)
843 ERR("CreateTextNode failed: %08x\n", nsres);
847 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
848 nsIDOMNode_Release(nsnode);
853 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
855 HTMLElement *This = HTMLELEM_THIS(iface);
856 FIXME("(%p)->(%p)\n", This, p);
860 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
862 HTMLElement *This = HTMLELEM_THIS(iface);
863 FIXME("(%p)->(%p)\n", This, p);
867 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
869 HTMLElement *This = HTMLELEM_THIS(iface);
870 FIXME("(%p)\n", This);
874 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
875 IHTMLFiltersCollection **p)
877 HTMLElement *This = HTMLELEM_THIS(iface);
878 FIXME("(%p)->(%p)\n", This, p);
882 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
884 HTMLElement *This = HTMLELEM_THIS(iface);
885 FIXME("(%p)->()\n", This);
889 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
891 HTMLElement *This = HTMLELEM_THIS(iface);
892 FIXME("(%p)->(%p)\n", This, p);
896 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
898 HTMLElement *This = HTMLELEM_THIS(iface);
899 FIXME("(%p)->(%p)\n", This, String);
903 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
905 HTMLElement *This = HTMLELEM_THIS(iface);
906 FIXME("(%p)->()\n", This);
910 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
912 HTMLElement *This = HTMLELEM_THIS(iface);
913 FIXME("(%p)->(%p)\n", This, p);
917 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
919 HTMLElement *This = HTMLELEM_THIS(iface);
920 FIXME("(%p)->()\n", This);
924 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
926 HTMLElement *This = HTMLELEM_THIS(iface);
927 FIXME("(%p)->(%p)\n", This, p);
931 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
933 HTMLElement *This = HTMLELEM_THIS(iface);
934 FIXME("(%p)->()\n", This);
938 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
940 HTMLElement *This = HTMLELEM_THIS(iface);
941 FIXME("(%p)->(%p)\n", This, p);
945 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
947 HTMLElement *This = HTMLELEM_THIS(iface);
948 FIXME("(%p)->()\n", This);
952 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
954 HTMLElement *This = HTMLELEM_THIS(iface);
955 FIXME("(%p)->(%p)\n", This, p);
959 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
961 HTMLElement *This = HTMLELEM_THIS(iface);
962 FIXME("(%p)->()\n", This);
966 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
968 HTMLElement *This = HTMLELEM_THIS(iface);
969 FIXME("(%p)->(%p)\n", This, p);
973 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
975 HTMLElement *This = HTMLELEM_THIS(iface);
976 FIXME("(%p)->()\n", This);
980 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
982 HTMLElement *This = HTMLELEM_THIS(iface);
983 FIXME("(%p)->(%p)\n", This, p);
987 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
989 HTMLElement *This = HTMLELEM_THIS(iface);
990 FIXME("(%p)->()\n", This);
994 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
996 HTMLElement *This = HTMLELEM_THIS(iface);
997 FIXME("(%p)->(%p)\n", This, p);
1001 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1003 HTMLElement *This = HTMLELEM_THIS(iface);
1004 FIXME("(%p)->()\n", This);
1008 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1010 HTMLElement *This = HTMLELEM_THIS(iface);
1011 FIXME("(%p)->(%p)\n", This, p);
1015 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1017 HTMLElement *This = HTMLELEM_THIS(iface);
1018 FIXME("(%p)->()\n", This);
1022 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1024 HTMLElement *This = HTMLELEM_THIS(iface);
1025 FIXME("(%p)->(%p)\n", This, p);
1029 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1031 nsIDOMNodeList *nsnode_list;
1033 PRUint32 list_len = 0, i;
1037 nsres = nsIDOMNode_GetChildNodes(elem->node->nsnode, &nsnode_list);
1038 if(NS_FAILED(nsres)) {
1039 ERR("GetChildNodes failed: %08x\n", nsres);
1043 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1047 buf->size = list_len;
1048 buf->buf = mshtml_alloc(buf->size*sizeof(HTMLElement**));
1050 for(i=0; i<list_len; i++) {
1051 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1052 if(NS_FAILED(nsres)) {
1053 ERR("Item failed: %08x\n", nsres);
1057 node = get_node(doc, iter);
1058 if(node->node_type != NT_HTMLELEM)
1061 elem_vector_add(buf, (HTMLElement*)node->impl.elem);
1065 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1067 HTMLElement *This = HTMLELEM_THIS(iface);
1068 elem_vector buf = {NULL, 0, 0};
1070 TRACE("(%p)->(%p)\n", This, p);
1072 create_child_list(This->node->doc, This, &buf);
1074 return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p);
1077 static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1079 nsIDOMNodeList *nsnode_list;
1081 PRUint32 list_len = 0, i;
1085 nsres = nsIDOMNode_GetChildNodes(elem->node->nsnode, &nsnode_list);
1086 if(NS_FAILED(nsres)) {
1087 ERR("GetChildNodes failed: %08x\n", nsres);
1091 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1095 for(i=0; i<list_len; i++) {
1096 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1097 if(NS_FAILED(nsres)) {
1098 ERR("Item failed: %08x\n", nsres);
1102 node = get_node(doc, iter);
1103 if(node->node_type != NT_HTMLELEM)
1106 elem_vector_add(buf, (HTMLElement*)node->impl.elem);
1107 create_all_list(doc, (HTMLElement*)node->impl.elem, buf);
1111 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1113 HTMLElement *This = HTMLELEM_THIS(iface);
1114 elem_vector buf = {NULL, 0, 8};
1116 TRACE("(%p)->(%p)\n", This, p);
1118 buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement**));
1120 create_all_list(This->node->doc, This, &buf);
1123 mshtml_free(buf.buf);
1125 }else if(buf.size > buf.len) {
1126 buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement**));
1129 return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p);
1132 static void HTMLElement_destructor(IUnknown *iface)
1134 HTMLElement *This = HTMLELEM_THIS(iface);
1136 if(This->destructor)
1137 This->destructor(This->impl);
1140 nsIDOMHTMLElement_Release(This->nselem);
1145 #undef HTMLELEM_THIS
1147 static const IHTMLElementVtbl HTMLElementVtbl = {
1148 HTMLElement_QueryInterface,
1150 HTMLElement_Release,
1151 HTMLElement_GetTypeInfoCount,
1152 HTMLElement_GetTypeInfo,
1153 HTMLElement_GetIDsOfNames,
1155 HTMLElement_setAttribute,
1156 HTMLElement_getAttribute,
1157 HTMLElement_removeAttribute,
1158 HTMLElement_put_className,
1159 HTMLElement_get_className,
1162 HTMLElement_get_tagName,
1163 HTMLElement_get_parentElement,
1164 HTMLElement_get_style,
1165 HTMLElement_put_onhelp,
1166 HTMLElement_get_onhelp,
1167 HTMLElement_put_onclick,
1168 HTMLElement_get_onclick,
1169 HTMLElement_put_ondblclick,
1170 HTMLElement_get_ondblclick,
1171 HTMLElement_put_onkeydown,
1172 HTMLElement_get_onkeydown,
1173 HTMLElement_put_onkeyup,
1174 HTMLElement_get_onkeyup,
1175 HTMLElement_put_onkeypress,
1176 HTMLElement_get_onkeypress,
1177 HTMLElement_put_onmouseout,
1178 HTMLElement_get_onmouseout,
1179 HTMLElement_put_onmouseover,
1180 HTMLElement_get_onmouseover,
1181 HTMLElement_put_onmousemove,
1182 HTMLElement_get_onmousemove,
1183 HTMLElement_put_onmousedown,
1184 HTMLElement_get_onmousedown,
1185 HTMLElement_put_onmouseup,
1186 HTMLElement_get_onmouseup,
1187 HTMLElement_get_document,
1188 HTMLElement_put_title,
1189 HTMLElement_get_title,
1190 HTMLElement_put_language,
1191 HTMLElement_get_language,
1192 HTMLElement_put_onselectstart,
1193 HTMLElement_get_onselectstart,
1194 HTMLElement_scrollIntoView,
1195 HTMLElement_contains,
1196 HTMLElement_get_sourceIndex,
1197 HTMLElement_get_recordNumber,
1198 HTMLElement_put_lang,
1199 HTMLElement_get_lang,
1200 HTMLElement_get_offsetLeft,
1201 HTMLElement_get_offsetTop,
1202 HTMLElement_get_offsetWidth,
1203 HTMLElement_get_offsetHeight,
1204 HTMLElement_get_offsetParent,
1205 HTMLElement_put_innerHTML,
1206 HTMLElement_get_innerHTML,
1207 HTMLElement_put_innerText,
1208 HTMLElement_get_innerText,
1209 HTMLElement_put_outerHTML,
1210 HTMLElement_get_outerHTML,
1211 HTMLElement_put_outerText,
1212 HTMLElement_get_outerText,
1213 HTMLElement_insertAdjacentHTML,
1214 HTMLElement_insertAdjacentText,
1215 HTMLElement_get_parentTextEdit,
1216 HTMLElement_get_isTextEdit,
1218 HTMLElement_get_filters,
1219 HTMLElement_put_ondragstart,
1220 HTMLElement_get_ondragstart,
1221 HTMLElement_toString,
1222 HTMLElement_put_onbeforeupdate,
1223 HTMLElement_get_onbeforeupdate,
1224 HTMLElement_put_onafterupdate,
1225 HTMLElement_get_onafterupdate,
1226 HTMLElement_put_onerrorupdate,
1227 HTMLElement_get_onerrorupdate,
1228 HTMLElement_put_onrowexit,
1229 HTMLElement_get_onrowexit,
1230 HTMLElement_put_onrowenter,
1231 HTMLElement_get_onrowenter,
1232 HTMLElement_put_ondatasetchanged,
1233 HTMLElement_get_ondatasetchanged,
1234 HTMLElement_put_ondataavailable,
1235 HTMLElement_get_ondataavailable,
1236 HTMLElement_put_ondatasetcomplete,
1237 HTMLElement_get_ondatasetcomplete,
1238 HTMLElement_put_onfilterchange,
1239 HTMLElement_get_onfilterchange,
1240 HTMLElement_get_children,
1244 HRESULT HTMLElement_QI(HTMLElement *This, REFIID riid, void **ppv)
1248 if(IsEqualGUID(&IID_IUnknown, riid)) {
1249 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1250 *ppv = HTMLELEM(This);
1251 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1252 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1253 *ppv = HTMLELEM(This);
1254 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1255 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1256 *ppv = HTMLELEM(This);
1257 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1258 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1259 *ppv = HTMLELEM2(This);
1263 IHTMLElement_AddRef(HTMLELEM(This));
1267 return HTMLDOMNode_QI(This->node, riid, ppv);
1270 void HTMLElement_Create(HTMLDOMNode *node)
1273 nsAString class_name_str;
1274 const PRUnichar *class_name;
1277 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1278 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1279 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1280 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1282 ret = mshtml_alloc(sizeof(HTMLElement));
1283 ret->lpHTMLElementVtbl = &HTMLElementVtbl;
1286 ret->destructor = NULL;
1288 node->node_type = NT_HTMLELEM;
1289 node->impl.elem = HTMLELEM(ret);
1290 node->destructor = HTMLElement_destructor;
1292 HTMLElement2_Init(ret);
1294 nsres = nsIDOMNode_QueryInterface(node->nsnode, &IID_nsIDOMHTMLElement, (void**)&ret->nselem);
1295 if(NS_FAILED(nsres))
1298 nsAString_Init(&class_name_str, NULL);
1299 nsIDOMHTMLElement_GetTagName(ret->nselem, &class_name_str);
1301 nsAString_GetData(&class_name_str, &class_name, NULL);
1303 if(!strcmpW(class_name, wszBODY))
1304 HTMLBodyElement_Create(ret);
1305 else if(!strcmpW(class_name, wszINPUT))
1306 HTMLInputElement_Create(ret);
1307 else if(!strcmpW(class_name, wszSELECT))
1308 HTMLSelectElement_Create(ret);
1309 else if(!strcmpW(class_name, wszTEXTAREA))
1310 HTMLTextAreaElement_Create(ret);
1312 nsAString_Finish(&class_name_str);
1316 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1319 HTMLElement **elems;
1323 } HTMLElementCollection;
1325 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1327 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1329 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1330 REFIID riid, void **ppv)
1332 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1336 if(IsEqualGUID(&IID_IUnknown, riid)) {
1337 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1338 *ppv = HTMLELEMCOL(This);
1339 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1340 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1341 *ppv = HTMLELEMCOL(This);
1342 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1343 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1344 *ppv = HTMLELEMCOL(This);
1348 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1352 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1353 return E_NOINTERFACE;
1356 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1358 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1359 LONG ref = InterlockedIncrement(&This->ref);
1361 TRACE("(%p) ref=%d\n", This, ref);
1366 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1368 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1369 LONG ref = InterlockedDecrement(&This->ref);
1371 TRACE("(%p) ref=%d\n", This, ref);
1374 IUnknown_Release(This->ref_unk);
1375 mshtml_free(This->elems);
1382 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1385 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1386 FIXME("(%p)->(%p)\n", This, pctinfo);
1390 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1391 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1393 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1394 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1398 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1399 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1401 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1402 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1407 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1408 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1409 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1411 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1412 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1413 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1417 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1420 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1421 FIXME("(%p)->(%p)\n", This, String);
1425 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1428 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1429 FIXME("(%p)->(%ld)\n", This, v);
1433 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1436 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1438 TRACE("(%p)->(%p)\n", This, p);
1444 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1447 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1448 FIXME("(%p)->(%p)\n", This, p);
1452 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1453 VARIANT name, VARIANT index, IDispatch **pdisp)
1455 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1457 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1459 if(V_VT(&name) == VT_I4) {
1460 TRACE("name is VT_I4: %d\n", V_I4(&name));
1461 if(V_I4(&name) < 0 || V_I4(&name) >= This->len) {
1462 ERR("Invalid name! name=%d\n", V_I4(&name));
1463 return E_INVALIDARG;
1466 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1467 IDispatch_AddRef(*pdisp);
1468 TRACE("Returning pdisp=%p\n", pdisp);
1472 if(V_VT(&name) == VT_BSTR) {
1475 const PRUnichar *tag;
1476 elem_vector buf = {NULL, 0, 8};
1478 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1480 nsAString_Init(&tag_str, NULL);
1481 buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement*));
1483 for(i=0; i<This->len; i++) {
1484 if(!This->elems[i]->nselem) continue;
1486 nsIDOMHTMLElement_GetId(This->elems[i]->nselem, &tag_str);
1487 nsAString_GetData(&tag_str, &tag, NULL);
1489 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1490 V_BSTR(&name), -1) == CSTR_EQUAL) {
1491 TRACE("Found name. elem=%d\n", i);
1492 if (V_VT(&index) == VT_I4)
1493 if (buf.len == V_I4(&index)) {
1494 nsAString_Finish(&tag_str);
1495 mshtml_free(buf.buf);
1497 *pdisp = (IDispatch*)This->elems[i];
1498 TRACE("Returning element %d pdisp=%p\n", i, pdisp);
1499 IDispatch_AddRef(*pdisp);
1502 elem_vector_add(&buf, This->elems[i]);
1505 nsAString_Finish(&tag_str);
1506 if (V_VT(&index) == VT_I4) {
1507 mshtml_free(buf.buf);
1509 ERR("Invalid index. index=%d >= buf.len=%d\n",V_I4(&index), buf.len);
1510 return E_INVALIDARG;
1513 mshtml_free(buf.buf);
1515 } else if(buf.size > buf.len) {
1516 buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement*));
1518 TRACE("Returning %d element(s).\n", buf.len);
1519 return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp);
1522 FIXME("unsupported arguments\n");
1523 return E_INVALIDARG;
1526 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1527 VARIANT tagName, IDispatch **pdisp)
1529 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1532 const PRUnichar *tag;
1533 elem_vector buf = {NULL, 0, 8};
1535 if(V_VT(&tagName) != VT_BSTR) {
1536 WARN("Invalid arg\n");
1537 return DISP_E_MEMBERNOTFOUND;
1540 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1542 buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement*));
1544 nsAString_Init(&tag_str, NULL);
1546 for(i=0; i<This->len; i++) {
1547 if(!This->elems[i]->nselem)
1550 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1551 nsAString_GetData(&tag_str, &tag, NULL);
1553 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1554 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1555 elem_vector_add(&buf, This->elems[i]);
1558 nsAString_Finish(&tag_str);
1560 TRACE("fount %d tags\n", buf.len);
1563 mshtml_free(buf.buf);
1565 }else if(buf.size > buf.len) {
1566 buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement*));
1569 return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp);
1574 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1575 HTMLElementCollection_QueryInterface,
1576 HTMLElementCollection_AddRef,
1577 HTMLElementCollection_Release,
1578 HTMLElementCollection_GetTypeInfoCount,
1579 HTMLElementCollection_GetTypeInfo,
1580 HTMLElementCollection_GetIDsOfNames,
1581 HTMLElementCollection_Invoke,
1582 HTMLElementCollection_toString,
1583 HTMLElementCollection_put_length,
1584 HTMLElementCollection_get_length,
1585 HTMLElementCollection_get__newEnum,
1586 HTMLElementCollection_item,
1587 HTMLElementCollection_tags
1590 static HRESULT HTMLElementCollection_Create(IUnknown *ref_unk, HTMLElement **elems, DWORD len,
1593 HTMLElementCollection *ret = mshtml_alloc(sizeof(HTMLElementCollection));
1595 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1600 IUnknown_AddRef(ref_unk);
1601 ret->ref_unk = ref_unk;
1603 TRACE("ret=%p len=%d\n", ret, len);
1605 *p = (IDispatch*)ret;