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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown*,HTMLElement**,DWORD);
46 static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
48 if(buf->len == buf->size) {
50 buf->buf = heap_realloc(buf->buf, buf->size*sizeof(HTMLElement**));
53 buf->buf[buf->len++] = elem;
56 static void elem_vector_normalize(elem_vector *buf)
61 }else if(buf->size > buf->len) {
62 buf->buf = heap_realloc(buf->buf, buf->len*sizeof(HTMLElement**));
68 static BOOL is_elem_node(nsIDOMNode *node)
72 nsIDOMNode_GetNodeType(node, &type);
74 return type == ELEMENT_NODE || type == COMMENT_NODE;
77 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
79 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
81 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
82 REFIID riid, void **ppv)
84 HTMLElement *This = HTMLELEM_THIS(iface);
86 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->node), riid, ppv);
89 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
91 HTMLElement *This = HTMLELEM_THIS(iface);
93 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->node));
96 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
98 HTMLElement *This = HTMLELEM_THIS(iface);
100 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->node));
103 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
105 HTMLElement *This = HTMLELEM_THIS(iface);
106 FIXME("(%p)->(%p)\n", This, pctinfo);
110 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
111 LCID lcid, ITypeInfo **ppTInfo)
113 HTMLElement *This = HTMLELEM_THIS(iface);
114 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
118 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
119 LPOLESTR *rgszNames, UINT cNames,
120 LCID lcid, DISPID *rgDispId)
122 HTMLElement *This = HTMLELEM_THIS(iface);
123 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
128 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
129 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
130 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
132 HTMLElement *This = HTMLELEM_THIS(iface);
133 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
134 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
138 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
139 VARIANT AttributeValue, LONG lFlags)
141 HTMLElement *This = HTMLELEM_THIS(iface);
146 VARIANT AttributeValueChanged;
148 WARN("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
151 FIXME("NULL nselem\n");
155 VariantInit(&AttributeValueChanged);
157 hres = VariantChangeType(&AttributeValueChanged, &AttributeValue, 0, VT_BSTR);
159 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue));
163 nsAString_Init(&attr_str, strAttributeName);
164 nsAString_Init(&value_str, V_BSTR(&AttributeValueChanged));
166 TRACE("setting %s to %s\n", debugstr_w(strAttributeName),
167 debugstr_w(V_BSTR(&AttributeValueChanged)));
169 nsres = nsIDOMHTMLElement_SetAttribute(This->nselem, &attr_str, &value_str);
170 nsAString_Finish(&attr_str);
171 nsAString_Finish(&value_str);
173 if(NS_SUCCEEDED(nsres)) {
176 ERR("SetAttribute failed: %08x\n", nsres);
183 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
184 LONG lFlags, VARIANT *AttributeValue)
186 HTMLElement *This = HTMLELEM_THIS(iface);
189 const PRUnichar *value;
193 WARN("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
196 FIXME("NULL nselem\n");
197 V_VT(AttributeValue) = VT_NULL;
201 V_VT(AttributeValue) = VT_NULL;
203 nsAString_Init(&attr_str, strAttributeName);
204 nsAString_Init(&value_str, NULL);
206 nsres = nsIDOMHTMLElement_GetAttribute(This->nselem, &attr_str, &value_str);
207 nsAString_Finish(&attr_str);
209 if(NS_SUCCEEDED(nsres)) {
210 static const WCHAR wszSRC[] = {'s','r','c',0};
211 nsAString_GetData(&value_str, &value);
212 if(!strcmpiW(strAttributeName, wszSRC))
217 hres = IHTMLDocument2_get_URL(HTMLDOC(This->node.doc), &bstrBaseUrl);
218 if(SUCCEEDED(hres)) {
219 hres = CoInternetCombineUrl(bstrBaseUrl, value,
220 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
221 buffer, sizeof(buffer)/sizeof(WCHAR), &len, 0);
222 SysFreeString(bstrBaseUrl);
223 if(SUCCEEDED(hres)) {
224 V_VT(AttributeValue) = VT_BSTR;
225 V_BSTR(AttributeValue) = SysAllocString(buffer);
226 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
230 V_VT(AttributeValue) = VT_BSTR;
231 V_BSTR(AttributeValue) = SysAllocString(value);
232 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
235 ERR("GetAttribute failed: %08x\n", nsres);
239 nsAString_Finish(&value_str);
244 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
245 LONG lFlags, VARIANT_BOOL *pfSuccess)
247 HTMLElement *This = HTMLELEM_THIS(iface);
248 FIXME("(%p)->()\n", This);
252 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
254 HTMLElement *This = HTMLELEM_THIS(iface);
255 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
259 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
261 HTMLElement *This = HTMLELEM_THIS(iface);
266 TRACE("(%p)->(%p)\n", This, p);
269 FIXME("NULL nselem\n");
273 nsAString_Init(&class_str, NULL);
274 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
276 if(NS_SUCCEEDED(nsres)) {
277 const PRUnichar *class;
278 nsAString_GetData(&class_str, &class);
279 *p = SysAllocString(class);
281 ERR("GetClassName failed: %08x\n", nsres);
285 nsAString_Finish(&class_str);
287 TRACE("className=%s\n", debugstr_w(*p));
291 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
293 HTMLElement *This = HTMLELEM_THIS(iface);
297 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
300 FIXME("nselem == NULL\n");
304 nsAString_Init(&id_str, v);
305 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
306 nsAString_Finish(&id_str);
308 ERR("SetId failed: %08x\n", nsres);
313 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
315 HTMLElement *This = HTMLELEM_THIS(iface);
320 TRACE("(%p)->(%p)\n", This, p);
327 nsAString_Init(&id_str, NULL);
328 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
329 nsAString_GetData(&id_str, &id);
332 ERR("GetId failed: %08x\n", nsres);
334 *p = SysAllocString(id);
336 nsAString_Finish(&id_str);
340 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
342 HTMLElement *This = HTMLELEM_THIS(iface);
343 const PRUnichar *tag;
347 TRACE("(%p)->(%p)\n", This, p);
350 static const WCHAR comment_tagW[] = {'!',0};
352 WARN("NULL nselem, assuming comment\n");
354 *p = SysAllocString(comment_tagW);
358 nsAString_Init(&tag_str, NULL);
359 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
360 if(NS_SUCCEEDED(nsres)) {
361 nsAString_GetData(&tag_str, &tag);
362 *p = SysAllocString(tag);
364 ERR("GetTagName failed: %08x\n", nsres);
367 nsAString_Finish(&tag_str);
372 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
374 HTMLElement *This = HTMLELEM_THIS(iface);
375 FIXME("(%p)->(%p)\n", This, p);
379 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
381 HTMLElement *This = HTMLELEM_THIS(iface);
382 nsIDOMElementCSSInlineStyle *nselemstyle;
383 nsIDOMCSSStyleDeclaration *nsstyle;
386 TRACE("(%p)->(%p)\n", This, p);
389 FIXME("NULL nselem\n");
393 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
394 (void**)&nselemstyle);
395 if(NS_FAILED(nsres)) {
396 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
400 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
401 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
402 if(NS_FAILED(nsres)) {
403 ERR("GetStyle failed: %08x\n", nsres);
407 /* FIXME: Store style instead of creating a new instance in each call */
408 *p = HTMLStyle_Create(nsstyle);
410 nsIDOMCSSStyleDeclaration_Release(nsstyle);
414 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
416 HTMLElement *This = HTMLELEM_THIS(iface);
417 FIXME("(%p)->()\n", This);
421 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
423 HTMLElement *This = HTMLELEM_THIS(iface);
424 FIXME("(%p)->(%p)\n", This, p);
428 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
430 HTMLElement *This = HTMLELEM_THIS(iface);
431 FIXME("(%p)->()\n", This);
435 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
437 HTMLElement *This = HTMLELEM_THIS(iface);
438 FIXME("(%p)->(%p)\n", This, p);
442 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
444 HTMLElement *This = HTMLELEM_THIS(iface);
445 FIXME("(%p)->()\n", This);
449 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
451 HTMLElement *This = HTMLELEM_THIS(iface);
452 FIXME("(%p)->(%p)\n", This, p);
456 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
458 HTMLElement *This = HTMLELEM_THIS(iface);
459 FIXME("(%p)->()\n", This);
463 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
465 HTMLElement *This = HTMLELEM_THIS(iface);
466 FIXME("(%p)->(%p)\n", This, p);
470 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
472 HTMLElement *This = HTMLELEM_THIS(iface);
473 FIXME("(%p)->()\n", This);
477 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
479 HTMLElement *This = HTMLELEM_THIS(iface);
480 FIXME("(%p)->(%p)\n", This, p);
484 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
486 HTMLElement *This = HTMLELEM_THIS(iface);
487 FIXME("(%p)->()\n", This);
491 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
493 HTMLElement *This = HTMLELEM_THIS(iface);
494 FIXME("(%p)->(%p)\n", This, p);
498 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
500 HTMLElement *This = HTMLELEM_THIS(iface);
501 FIXME("(%p)->()\n", This);
505 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
507 HTMLElement *This = HTMLELEM_THIS(iface);
508 FIXME("(%p)->(%p)\n", This, p);
512 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
514 HTMLElement *This = HTMLELEM_THIS(iface);
515 FIXME("(%p)->()\n", This);
519 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
521 HTMLElement *This = HTMLELEM_THIS(iface);
522 FIXME("(%p)->(%p)\n", This, p);
526 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
528 HTMLElement *This = HTMLELEM_THIS(iface);
529 FIXME("(%p)->()\n", This);
533 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
535 HTMLElement *This = HTMLELEM_THIS(iface);
536 FIXME("(%p)->(%p)\n", This, p);
540 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
542 HTMLElement *This = HTMLELEM_THIS(iface);
543 FIXME("(%p)->()\n", This);
547 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
549 HTMLElement *This = HTMLELEM_THIS(iface);
550 FIXME("(%p)->(%p)\n", This, p);
554 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
556 HTMLElement *This = HTMLELEM_THIS(iface);
557 FIXME("(%p)->()\n", This);
561 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
563 HTMLElement *This = HTMLELEM_THIS(iface);
564 FIXME("(%p)->(%p)\n", This, p);
568 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
570 HTMLElement *This = HTMLELEM_THIS(iface);
571 FIXME("(%p)->(%p)\n", This, p);
575 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
577 HTMLElement *This = HTMLELEM_THIS(iface);
578 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
582 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
584 HTMLElement *This = HTMLELEM_THIS(iface);
585 FIXME("(%p)->(%p)\n", This, p);
589 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
591 HTMLElement *This = HTMLELEM_THIS(iface);
592 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
596 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
598 HTMLElement *This = HTMLELEM_THIS(iface);
599 FIXME("(%p)->(%p)\n", This, p);
603 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
605 HTMLElement *This = HTMLELEM_THIS(iface);
606 FIXME("(%p)->()\n", This);
610 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
612 HTMLElement *This = HTMLELEM_THIS(iface);
613 FIXME("(%p)->(%p)\n", This, p);
617 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
619 HTMLElement *This = HTMLELEM_THIS(iface);
620 FIXME("(%p)->()\n", This);
624 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
625 VARIANT_BOOL *pfResult)
627 HTMLElement *This = HTMLELEM_THIS(iface);
628 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
632 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
634 HTMLElement *This = HTMLELEM_THIS(iface);
635 FIXME("(%p)->(%p)\n", This, p);
639 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
641 HTMLElement *This = HTMLELEM_THIS(iface);
642 FIXME("(%p)->(%p)\n", This, p);
646 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
648 HTMLElement *This = HTMLELEM_THIS(iface);
649 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
653 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
655 HTMLElement *This = HTMLELEM_THIS(iface);
656 FIXME("(%p)->(%p)\n", This, p);
660 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
662 HTMLElement *This = HTMLELEM_THIS(iface);
663 FIXME("(%p)->(%p)\n", This, p);
667 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
669 HTMLElement *This = HTMLELEM_THIS(iface);
670 FIXME("(%p)->(%p)\n", This, p);
674 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
676 HTMLElement *This = HTMLELEM_THIS(iface);
677 FIXME("(%p)->(%p)\n", This, p);
681 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
683 HTMLElement *This = HTMLELEM_THIS(iface);
684 FIXME("(%p)->(%p)\n", This, p);
688 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
690 HTMLElement *This = HTMLELEM_THIS(iface);
691 FIXME("(%p)->(%p)\n", This, p);
695 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
697 HTMLElement *This = HTMLELEM_THIS(iface);
698 nsIDOMNSHTMLElement *nselem;
702 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
705 FIXME("NULL nselem\n");
709 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
710 if(NS_FAILED(nsres)) {
711 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
715 nsAString_Init(&html_str, v);
716 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
717 nsAString_Finish(&html_str);
719 if(NS_FAILED(nsres)) {
720 FIXME("SetInnerHtml failed %08x\n", nsres);
727 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
729 HTMLElement *This = HTMLELEM_THIS(iface);
730 FIXME("(%p)->(%p)\n", This, p);
734 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
736 HTMLElement *This = HTMLELEM_THIS(iface);
737 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
741 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
743 HTMLElement *This = HTMLELEM_THIS(iface);
744 FIXME("(%p)->(%p)\n", This, p);
748 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
750 HTMLElement *This = HTMLELEM_THIS(iface);
751 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
755 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
757 HTMLElement *This = HTMLELEM_THIS(iface);
758 FIXME("(%p)->(%p)\n", This, p);
762 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
764 HTMLElement *This = HTMLELEM_THIS(iface);
765 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
769 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
771 HTMLElement *This = HTMLELEM_THIS(iface);
772 FIXME("(%p)->(%p)\n", This, p);
776 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
778 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
779 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
780 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
781 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
785 FIXME("NULL nselem\n");
789 if (!strcmpiW(where, wszBeforeBegin))
793 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
794 if (!parent) return E_INVALIDARG;
795 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
796 (nsIDOMNode *)This->nselem, &unused);
797 if (unused) nsIDOMNode_Release(unused);
798 nsIDOMNode_Release(parent);
800 else if (!strcmpiW(where, wszAfterBegin))
803 nsIDOMNode *first_child;
804 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
805 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
806 if (unused) nsIDOMNode_Release(unused);
807 if (first_child) nsIDOMNode_Release(first_child);
809 else if (!strcmpiW(where, wszBeforeEnd))
812 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
813 if (unused) nsIDOMNode_Release(unused);
815 else if (!strcmpiW(where, wszAfterEnd))
818 nsIDOMNode *next_sibling;
820 nsIDOMNode_GetParentNode(This->nselem, &parent);
821 if (!parent) return E_INVALIDARG;
823 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
826 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
827 nsIDOMNode_Release(next_sibling);
830 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
831 nsIDOMNode_Release(parent);
832 if (unused) nsIDOMNode_Release(unused);
836 ERR("invalid where: %s\n", debugstr_w(where));
840 if (NS_FAILED(nsres))
846 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
849 HTMLElement *This = HTMLELEM_THIS(iface);
851 nsIDOMDocument *nsdoc;
852 nsIDOMDocumentRange *nsdocrange;
854 nsIDOMNSRange *nsrange;
859 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
861 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
864 ERR("GetDocument failed: %08x\n", nsres);
868 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
869 nsIDOMDocument_Release(nsdoc);
872 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
875 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
876 nsIDOMDocumentRange_Release(nsdocrange);
879 ERR("CreateRange failed: %08x\n", nsres);
883 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
885 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
886 nsIDOMRange_Release(range);
889 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
893 nsAString_Init(&ns_html, html);
895 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
896 nsIDOMNSRange_Release(nsrange);
897 nsAString_Finish(&ns_html);
899 if(NS_FAILED(nsres) || !nsnode)
901 ERR("CreateTextNode failed: %08x\n", nsres);
905 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
906 nsIDOMNode_Release(nsnode);
911 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
914 HTMLElement *This = HTMLELEM_THIS(iface);
916 nsIDOMDocument *nsdoc;
921 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
923 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
924 if(NS_FAILED(nsres) || !nsdoc)
926 ERR("GetDocument failed: %08x\n", nsres);
930 nsAString_Init(&ns_text, text);
932 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
933 nsIDOMDocument_Release(nsdoc);
934 nsAString_Finish(&ns_text);
936 if(NS_FAILED(nsres) || !nsnode)
938 ERR("CreateTextNode failed: %08x\n", nsres);
942 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
943 nsIDOMNode_Release(nsnode);
948 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
950 HTMLElement *This = HTMLELEM_THIS(iface);
951 FIXME("(%p)->(%p)\n", This, p);
955 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
957 HTMLElement *This = HTMLELEM_THIS(iface);
958 FIXME("(%p)->(%p)\n", This, p);
962 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
964 HTMLElement *This = HTMLELEM_THIS(iface);
965 FIXME("(%p)\n", This);
969 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
970 IHTMLFiltersCollection **p)
972 HTMLElement *This = HTMLELEM_THIS(iface);
973 FIXME("(%p)->(%p)\n", This, p);
977 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
979 HTMLElement *This = HTMLELEM_THIS(iface);
980 FIXME("(%p)->()\n", This);
984 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
986 HTMLElement *This = HTMLELEM_THIS(iface);
987 FIXME("(%p)->(%p)\n", This, p);
991 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
993 HTMLElement *This = HTMLELEM_THIS(iface);
994 FIXME("(%p)->(%p)\n", This, String);
998 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1000 HTMLElement *This = HTMLELEM_THIS(iface);
1001 FIXME("(%p)->()\n", This);
1005 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1007 HTMLElement *This = HTMLELEM_THIS(iface);
1008 FIXME("(%p)->(%p)\n", This, p);
1012 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1014 HTMLElement *This = HTMLELEM_THIS(iface);
1015 FIXME("(%p)->()\n", This);
1019 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1021 HTMLElement *This = HTMLELEM_THIS(iface);
1022 FIXME("(%p)->(%p)\n", This, p);
1026 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1028 HTMLElement *This = HTMLELEM_THIS(iface);
1029 FIXME("(%p)->()\n", This);
1033 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1035 HTMLElement *This = HTMLELEM_THIS(iface);
1036 FIXME("(%p)->(%p)\n", This, p);
1040 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1042 HTMLElement *This = HTMLELEM_THIS(iface);
1043 FIXME("(%p)->()\n", This);
1047 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1049 HTMLElement *This = HTMLELEM_THIS(iface);
1050 FIXME("(%p)->(%p)\n", This, p);
1054 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1056 HTMLElement *This = HTMLELEM_THIS(iface);
1057 FIXME("(%p)->()\n", This);
1061 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1063 HTMLElement *This = HTMLELEM_THIS(iface);
1064 FIXME("(%p)->(%p)\n", This, p);
1068 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1070 HTMLElement *This = HTMLELEM_THIS(iface);
1071 FIXME("(%p)->()\n", This);
1075 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1077 HTMLElement *This = HTMLELEM_THIS(iface);
1078 FIXME("(%p)->(%p)\n", This, p);
1082 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1084 HTMLElement *This = HTMLELEM_THIS(iface);
1085 FIXME("(%p)->()\n", This);
1089 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1091 HTMLElement *This = HTMLELEM_THIS(iface);
1092 FIXME("(%p)->(%p)\n", This, p);
1096 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1098 HTMLElement *This = HTMLELEM_THIS(iface);
1099 FIXME("(%p)->()\n", This);
1103 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1105 HTMLElement *This = HTMLELEM_THIS(iface);
1106 FIXME("(%p)->(%p)\n", This, p);
1110 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1112 HTMLElement *This = HTMLELEM_THIS(iface);
1113 FIXME("(%p)->()\n", This);
1117 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1119 HTMLElement *This = HTMLELEM_THIS(iface);
1120 FIXME("(%p)->(%p)\n", This, p);
1124 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1126 nsIDOMNodeList *nsnode_list;
1128 PRUint32 list_len = 0, i;
1131 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1132 if(NS_FAILED(nsres)) {
1133 ERR("GetChildNodes failed: %08x\n", nsres);
1137 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1141 buf->size = list_len;
1142 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1144 for(i=0; i<list_len; i++) {
1145 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1146 if(NS_FAILED(nsres)) {
1147 ERR("Item failed: %08x\n", nsres);
1151 if(is_elem_node(iter))
1152 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1156 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1158 HTMLElement *This = HTMLELEM_THIS(iface);
1159 elem_vector buf = {NULL, 0, 0};
1161 TRACE("(%p)->(%p)\n", This, p);
1163 create_child_list(This->node.doc, This, &buf);
1165 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1169 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1171 nsIDOMNodeList *nsnode_list;
1173 PRUint32 list_len = 0, i;
1176 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1177 if(NS_FAILED(nsres)) {
1178 ERR("GetChildNodes failed: %08x\n", nsres);
1182 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1186 for(i=0; i<list_len; i++) {
1187 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1188 if(NS_FAILED(nsres)) {
1189 ERR("Item failed: %08x\n", nsres);
1193 if(is_elem_node(iter)) {
1194 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1196 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1197 create_all_list(doc, node, buf);
1202 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1204 HTMLElement *This = HTMLELEM_THIS(iface);
1205 elem_vector buf = {NULL, 0, 8};
1207 TRACE("(%p)->(%p)\n", This, p);
1209 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1211 create_all_list(This->node.doc, &This->node, &buf);
1212 elem_vector_normalize(&buf);
1214 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1218 #undef HTMLELEM_THIS
1220 static const IHTMLElementVtbl HTMLElementVtbl = {
1221 HTMLElement_QueryInterface,
1223 HTMLElement_Release,
1224 HTMLElement_GetTypeInfoCount,
1225 HTMLElement_GetTypeInfo,
1226 HTMLElement_GetIDsOfNames,
1228 HTMLElement_setAttribute,
1229 HTMLElement_getAttribute,
1230 HTMLElement_removeAttribute,
1231 HTMLElement_put_className,
1232 HTMLElement_get_className,
1235 HTMLElement_get_tagName,
1236 HTMLElement_get_parentElement,
1237 HTMLElement_get_style,
1238 HTMLElement_put_onhelp,
1239 HTMLElement_get_onhelp,
1240 HTMLElement_put_onclick,
1241 HTMLElement_get_onclick,
1242 HTMLElement_put_ondblclick,
1243 HTMLElement_get_ondblclick,
1244 HTMLElement_put_onkeydown,
1245 HTMLElement_get_onkeydown,
1246 HTMLElement_put_onkeyup,
1247 HTMLElement_get_onkeyup,
1248 HTMLElement_put_onkeypress,
1249 HTMLElement_get_onkeypress,
1250 HTMLElement_put_onmouseout,
1251 HTMLElement_get_onmouseout,
1252 HTMLElement_put_onmouseover,
1253 HTMLElement_get_onmouseover,
1254 HTMLElement_put_onmousemove,
1255 HTMLElement_get_onmousemove,
1256 HTMLElement_put_onmousedown,
1257 HTMLElement_get_onmousedown,
1258 HTMLElement_put_onmouseup,
1259 HTMLElement_get_onmouseup,
1260 HTMLElement_get_document,
1261 HTMLElement_put_title,
1262 HTMLElement_get_title,
1263 HTMLElement_put_language,
1264 HTMLElement_get_language,
1265 HTMLElement_put_onselectstart,
1266 HTMLElement_get_onselectstart,
1267 HTMLElement_scrollIntoView,
1268 HTMLElement_contains,
1269 HTMLElement_get_sourceIndex,
1270 HTMLElement_get_recordNumber,
1271 HTMLElement_put_lang,
1272 HTMLElement_get_lang,
1273 HTMLElement_get_offsetLeft,
1274 HTMLElement_get_offsetTop,
1275 HTMLElement_get_offsetWidth,
1276 HTMLElement_get_offsetHeight,
1277 HTMLElement_get_offsetParent,
1278 HTMLElement_put_innerHTML,
1279 HTMLElement_get_innerHTML,
1280 HTMLElement_put_innerText,
1281 HTMLElement_get_innerText,
1282 HTMLElement_put_outerHTML,
1283 HTMLElement_get_outerHTML,
1284 HTMLElement_put_outerText,
1285 HTMLElement_get_outerText,
1286 HTMLElement_insertAdjacentHTML,
1287 HTMLElement_insertAdjacentText,
1288 HTMLElement_get_parentTextEdit,
1289 HTMLElement_get_isTextEdit,
1291 HTMLElement_get_filters,
1292 HTMLElement_put_ondragstart,
1293 HTMLElement_get_ondragstart,
1294 HTMLElement_toString,
1295 HTMLElement_put_onbeforeupdate,
1296 HTMLElement_get_onbeforeupdate,
1297 HTMLElement_put_onafterupdate,
1298 HTMLElement_get_onafterupdate,
1299 HTMLElement_put_onerrorupdate,
1300 HTMLElement_get_onerrorupdate,
1301 HTMLElement_put_onrowexit,
1302 HTMLElement_get_onrowexit,
1303 HTMLElement_put_onrowenter,
1304 HTMLElement_get_onrowenter,
1305 HTMLElement_put_ondatasetchanged,
1306 HTMLElement_get_ondatasetchanged,
1307 HTMLElement_put_ondataavailable,
1308 HTMLElement_get_ondataavailable,
1309 HTMLElement_put_ondatasetcomplete,
1310 HTMLElement_get_ondatasetcomplete,
1311 HTMLElement_put_onfilterchange,
1312 HTMLElement_get_onfilterchange,
1313 HTMLElement_get_children,
1317 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1319 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1323 if(IsEqualGUID(&IID_IUnknown, riid)) {
1324 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1325 *ppv = HTMLELEM(This);
1326 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1327 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1328 *ppv = HTMLELEM(This);
1329 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1330 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1331 *ppv = HTMLELEM(This);
1332 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1333 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1334 *ppv = HTMLELEM2(This);
1335 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1336 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1337 *ppv = CONPTCONT(&This->cp_container);
1341 IHTMLElement_AddRef(HTMLELEM(This));
1345 return HTMLDOMNode_QI(&This->node, riid, ppv);
1348 void HTMLElement_destructor(HTMLDOMNode *iface)
1350 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1352 ConnectionPointContainer_Destroy(&This->cp_container);
1355 nsIDOMHTMLElement_Release(This->nselem);
1357 HTMLDOMNode_destructor(&This->node);
1360 static const NodeImplVtbl HTMLElementImplVtbl = {
1362 HTMLElement_destructor
1365 static const tid_t HTMLElement_iface_tids[] = {
1372 static dispex_static_data_t HTMLElement_dispex = {
1374 DispHTMLUnknownElement_tid,
1376 HTMLElement_iface_tids
1379 void HTMLElement_Init(HTMLElement *This)
1381 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1383 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1385 HTMLElement2_Init(This);
1387 if(!This->node.dispex.data)
1388 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1391 HTMLElement *HTMLElement_Create(nsIDOMNode *nsnode)
1393 nsIDOMHTMLElement *nselem;
1394 HTMLElement *ret = NULL;
1395 nsAString class_name_str;
1396 const PRUnichar *class_name;
1399 static const WCHAR wszA[] = {'A',0};
1400 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1401 static const WCHAR wszIMG[] = {'I','M','G',0};
1402 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1403 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1404 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1405 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1406 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1407 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1409 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1410 if(NS_FAILED(nsres))
1413 nsAString_Init(&class_name_str, NULL);
1414 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1416 nsAString_GetData(&class_name_str, &class_name);
1418 if(!strcmpW(class_name, wszA))
1419 ret = HTMLAnchorElement_Create(nselem);
1420 else if(!strcmpW(class_name, wszBODY))
1421 ret = HTMLBodyElement_Create(nselem);
1422 else if(!strcmpW(class_name, wszIMG))
1423 ret = HTMLImgElement_Create(nselem);
1424 else if(!strcmpW(class_name, wszINPUT))
1425 ret = HTMLInputElement_Create(nselem);
1426 else if(!strcmpW(class_name, wszOPTION))
1427 ret = HTMLOptionElement_Create(nselem);
1428 else if(!strcmpW(class_name, wszSCRIPT))
1429 ret = HTMLScriptElement_Create(nselem);
1430 else if(!strcmpW(class_name, wszSELECT))
1431 ret = HTMLSelectElement_Create(nselem);
1432 else if(!strcmpW(class_name, wszTABLE))
1433 ret = HTMLTable_Create(nselem);
1434 else if(!strcmpW(class_name, wszTEXTAREA))
1435 ret = HTMLTextAreaElement_Create(nselem);
1438 ret = heap_alloc_zero(sizeof(HTMLElement));
1439 HTMLElement_Init(ret);
1440 ret->node.vtbl = &HTMLElementImplVtbl;
1443 nsAString_Finish(&class_name_str);
1445 ret->nselem = nselem;
1452 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1455 HTMLElement **elems;
1459 } HTMLElementCollection;
1461 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1463 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1465 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1466 REFIID riid, void **ppv)
1468 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1472 if(IsEqualGUID(&IID_IUnknown, riid)) {
1473 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1474 *ppv = HTMLELEMCOL(This);
1475 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1476 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1477 *ppv = HTMLELEMCOL(This);
1478 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1479 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1480 *ppv = DISPATCHEX(&This->dispex);
1481 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1482 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1483 *ppv = HTMLELEMCOL(This);
1487 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1491 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1492 return E_NOINTERFACE;
1495 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1497 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1498 LONG ref = InterlockedIncrement(&This->ref);
1500 TRACE("(%p) ref=%d\n", This, ref);
1505 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1507 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1508 LONG ref = InterlockedDecrement(&This->ref);
1510 TRACE("(%p) ref=%d\n", This, ref);
1513 IUnknown_Release(This->ref_unk);
1514 heap_free(This->elems);
1521 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1524 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1525 FIXME("(%p)->(%p)\n", This, pctinfo);
1529 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1530 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1532 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1533 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1537 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1538 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1540 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1541 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1546 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1547 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1548 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1550 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1551 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1552 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1556 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1559 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1560 FIXME("(%p)->(%p)\n", This, String);
1564 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1567 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1568 FIXME("(%p)->(%ld)\n", This, v);
1572 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1575 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1577 TRACE("(%p)->(%p)\n", This, p);
1583 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1586 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1587 FIXME("(%p)->(%p)\n", This, p);
1591 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1593 const PRUnichar *str;
1594 nsAString nsstr, nsname;
1598 static const PRUnichar nameW[] = {'n','a','m','e',0};
1603 nsAString_Init(&nsstr, NULL);
1604 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1605 nsAString_GetData(&nsstr, &str);
1606 if(!strcmpiW(str, name)) {
1607 nsAString_Finish(&nsstr);
1611 nsAString_Init(&nsname, nameW);
1612 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1613 nsAString_Finish(&nsname);
1614 if(NS_SUCCEEDED(nsres)) {
1615 nsAString_GetData(&nsstr, &str);
1616 ret = !strcmpiW(str, name);
1619 nsAString_Finish(&nsstr);
1623 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1624 VARIANT name, VARIANT index, IDispatch **pdisp)
1626 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1628 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1632 if(V_VT(&name) == VT_I4) {
1633 TRACE("name is VT_I4: %d\n", V_I4(&name));
1636 return E_INVALIDARG;
1637 if(V_I4(&name) >= This->len)
1640 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1641 IDispatch_AddRef(*pdisp);
1642 TRACE("Returning pdisp=%p\n", pdisp);
1646 if(V_VT(&name) == VT_BSTR) {
1649 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1651 if(V_VT(&index) == VT_I4) {
1652 LONG idx = V_I4(&index);
1654 TRACE("index = %d\n", idx);
1657 return E_INVALIDARG;
1659 for(i=0; i<This->len; i++) {
1660 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1664 if(i != This->len) {
1665 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1666 IDispatch_AddRef(*pdisp);
1671 elem_vector buf = {NULL, 0, 8};
1673 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1675 for(i=0; i<This->len; i++) {
1676 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1677 elem_vector_add(&buf, This->elems[i]);
1681 elem_vector_normalize(&buf);
1682 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1685 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1686 IDispatch_AddRef(*pdisp);
1696 FIXME("unsupported arguments\n");
1697 return E_INVALIDARG;
1700 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1701 VARIANT tagName, IDispatch **pdisp)
1703 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1706 const PRUnichar *tag;
1707 elem_vector buf = {NULL, 0, 8};
1709 if(V_VT(&tagName) != VT_BSTR) {
1710 WARN("Invalid arg\n");
1711 return DISP_E_MEMBERNOTFOUND;
1714 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1716 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1718 nsAString_Init(&tag_str, NULL);
1720 for(i=0; i<This->len; i++) {
1721 if(!This->elems[i]->nselem)
1724 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1725 nsAString_GetData(&tag_str, &tag);
1727 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1728 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1729 elem_vector_add(&buf, This->elems[i]);
1732 nsAString_Finish(&tag_str);
1733 elem_vector_normalize(&buf);
1735 TRACE("fount %d tags\n", buf.len);
1737 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1741 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1743 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1745 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1749 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1750 idx = idx*10 + (*ptr-'0');
1752 if(*ptr || idx >= This->len)
1753 return DISP_E_UNKNOWNNAME;
1755 *dispid = DISPID_ELEMCOL_0 + idx;
1756 TRACE("ret %x\n", *dispid);
1760 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1761 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1763 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1766 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1768 idx = id - DISPID_ELEMCOL_0;
1769 if(idx >= This->len)
1770 return DISP_E_UNKNOWNNAME;
1773 case INVOKE_PROPERTYGET:
1774 V_VT(res) = VT_DISPATCH;
1775 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1776 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1779 FIXME("unimplemented flags %x\n", flags);
1788 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1789 HTMLElementCollection_QueryInterface,
1790 HTMLElementCollection_AddRef,
1791 HTMLElementCollection_Release,
1792 HTMLElementCollection_GetTypeInfoCount,
1793 HTMLElementCollection_GetTypeInfo,
1794 HTMLElementCollection_GetIDsOfNames,
1795 HTMLElementCollection_Invoke,
1796 HTMLElementCollection_toString,
1797 HTMLElementCollection_put_length,
1798 HTMLElementCollection_get_length,
1799 HTMLElementCollection_get__newEnum,
1800 HTMLElementCollection_item,
1801 HTMLElementCollection_tags
1804 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1805 HTMLElementCollection_get_dispid,
1806 HTMLElementCollection_invoke
1809 static const tid_t HTMLElementCollection_iface_tids[] = {
1810 IHTMLElementCollection_tid,
1813 static dispex_static_data_t HTMLElementCollection_dispex = {
1814 &HTMLElementColection_dispex_vtbl,
1815 DispHTMLElementCollection_tid,
1817 HTMLElementCollection_iface_tids
1820 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1822 elem_vector buf = {NULL, 0, 8};
1824 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1826 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1827 create_all_list(node->doc, node, &buf);
1828 elem_vector_normalize(&buf);
1830 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1833 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1834 HTMLElement **elems, DWORD len)
1836 HTMLElementCollection *ret = heap_alloc_zero(sizeof(HTMLElementCollection));
1838 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1843 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1845 IUnknown_AddRef(ref_unk);
1846 ret->ref_unk = ref_unk;
1848 TRACE("ret=%p len=%d\n", ret, len);
1850 return HTMLELEMCOL(ret);