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 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->node.dispex), pctinfo);
109 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
110 LCID lcid, ITypeInfo **ppTInfo)
112 HTMLElement *This = HTMLELEM_THIS(iface);
113 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->node.dispex), iTInfo, lcid, ppTInfo);
116 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
117 LPOLESTR *rgszNames, UINT cNames,
118 LCID lcid, DISPID *rgDispId)
120 HTMLElement *This = HTMLELEM_THIS(iface);
121 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
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 return IDispatchEx_Invoke(DISPATCHEX(&This->node.dispex), dispIdMember, riid, lcid,
130 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
133 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
134 VARIANT AttributeValue, LONG lFlags)
136 HTMLElement *This = HTMLELEM_THIS(iface);
141 VARIANT AttributeValueChanged;
143 WARN("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
146 FIXME("NULL nselem\n");
150 VariantInit(&AttributeValueChanged);
152 hres = VariantChangeType(&AttributeValueChanged, &AttributeValue, 0, VT_BSTR);
154 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue));
158 nsAString_Init(&attr_str, strAttributeName);
159 nsAString_Init(&value_str, V_BSTR(&AttributeValueChanged));
161 TRACE("setting %s to %s\n", debugstr_w(strAttributeName),
162 debugstr_w(V_BSTR(&AttributeValueChanged)));
164 nsres = nsIDOMHTMLElement_SetAttribute(This->nselem, &attr_str, &value_str);
165 nsAString_Finish(&attr_str);
166 nsAString_Finish(&value_str);
168 if(NS_SUCCEEDED(nsres)) {
171 ERR("SetAttribute failed: %08x\n", nsres);
178 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
179 LONG lFlags, VARIANT *AttributeValue)
181 HTMLElement *This = HTMLELEM_THIS(iface);
184 const PRUnichar *value;
188 WARN("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
191 FIXME("NULL nselem\n");
192 V_VT(AttributeValue) = VT_NULL;
196 V_VT(AttributeValue) = VT_NULL;
198 nsAString_Init(&attr_str, strAttributeName);
199 nsAString_Init(&value_str, NULL);
201 nsres = nsIDOMHTMLElement_GetAttribute(This->nselem, &attr_str, &value_str);
202 nsAString_Finish(&attr_str);
204 if(NS_SUCCEEDED(nsres)) {
205 static const WCHAR wszSRC[] = {'s','r','c',0};
206 nsAString_GetData(&value_str, &value);
207 if(!strcmpiW(strAttributeName, wszSRC))
212 hres = IHTMLDocument2_get_URL(HTMLDOC(This->node.doc), &bstrBaseUrl);
213 if(SUCCEEDED(hres)) {
214 hres = CoInternetCombineUrl(bstrBaseUrl, value,
215 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
216 buffer, sizeof(buffer)/sizeof(WCHAR), &len, 0);
217 SysFreeString(bstrBaseUrl);
218 if(SUCCEEDED(hres)) {
219 V_VT(AttributeValue) = VT_BSTR;
220 V_BSTR(AttributeValue) = SysAllocString(buffer);
221 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
225 V_VT(AttributeValue) = VT_BSTR;
226 V_BSTR(AttributeValue) = SysAllocString(value);
227 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
230 ERR("GetAttribute failed: %08x\n", nsres);
234 nsAString_Finish(&value_str);
239 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
240 LONG lFlags, VARIANT_BOOL *pfSuccess)
242 HTMLElement *This = HTMLELEM_THIS(iface);
243 FIXME("(%p)->()\n", This);
247 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
249 HTMLElement *This = HTMLELEM_THIS(iface);
250 nsAString classname_str;
253 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
256 FIXME("NULL nselem\n");
260 nsAString_Init(&classname_str, v);
261 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
262 nsAString_Finish(&classname_str);
264 ERR("SetClassName failed: %08x\n", nsres);
269 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
271 HTMLElement *This = HTMLELEM_THIS(iface);
276 TRACE("(%p)->(%p)\n", This, p);
279 FIXME("NULL nselem\n");
283 nsAString_Init(&class_str, NULL);
284 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
286 if(NS_SUCCEEDED(nsres)) {
287 const PRUnichar *class;
288 nsAString_GetData(&class_str, &class);
289 *p = *class ? SysAllocString(class) : NULL;
291 ERR("GetClassName failed: %08x\n", nsres);
295 nsAString_Finish(&class_str);
297 TRACE("className=%s\n", debugstr_w(*p));
301 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
303 HTMLElement *This = HTMLELEM_THIS(iface);
307 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
310 FIXME("nselem == NULL\n");
314 nsAString_Init(&id_str, v);
315 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
316 nsAString_Finish(&id_str);
318 ERR("SetId failed: %08x\n", nsres);
323 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
325 HTMLElement *This = HTMLELEM_THIS(iface);
330 TRACE("(%p)->(%p)\n", This, p);
337 nsAString_Init(&id_str, NULL);
338 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
339 nsAString_GetData(&id_str, &id);
342 ERR("GetId failed: %08x\n", nsres);
344 *p = SysAllocString(id);
346 nsAString_Finish(&id_str);
350 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
352 HTMLElement *This = HTMLELEM_THIS(iface);
353 const PRUnichar *tag;
357 TRACE("(%p)->(%p)\n", This, p);
360 static const WCHAR comment_tagW[] = {'!',0};
362 WARN("NULL nselem, assuming comment\n");
364 *p = SysAllocString(comment_tagW);
368 nsAString_Init(&tag_str, NULL);
369 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
370 if(NS_SUCCEEDED(nsres)) {
371 nsAString_GetData(&tag_str, &tag);
372 *p = SysAllocString(tag);
374 ERR("GetTagName failed: %08x\n", nsres);
377 nsAString_Finish(&tag_str);
382 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
384 HTMLElement *This = HTMLELEM_THIS(iface);
388 TRACE("(%p)->(%p)\n", This, p);
390 hres = IHTMLDOMNode_get_parentNode(HTMLDOMNODE(&This->node), &node);
394 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
395 IHTMLDOMNode_Release(node);
402 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
404 HTMLElement *This = HTMLELEM_THIS(iface);
405 nsIDOMElementCSSInlineStyle *nselemstyle;
406 nsIDOMCSSStyleDeclaration *nsstyle;
409 TRACE("(%p)->(%p)\n", This, p);
412 FIXME("NULL nselem\n");
416 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
417 (void**)&nselemstyle);
418 if(NS_FAILED(nsres)) {
419 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
423 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
424 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
425 if(NS_FAILED(nsres)) {
426 ERR("GetStyle failed: %08x\n", nsres);
430 /* FIXME: Store style instead of creating a new instance in each call */
431 *p = HTMLStyle_Create(nsstyle);
433 nsIDOMCSSStyleDeclaration_Release(nsstyle);
437 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
439 HTMLElement *This = HTMLELEM_THIS(iface);
440 FIXME("(%p)->()\n", This);
444 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
446 HTMLElement *This = HTMLELEM_THIS(iface);
447 FIXME("(%p)->(%p)\n", This, p);
451 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
453 HTMLElement *This = HTMLELEM_THIS(iface);
455 TRACE("(%p)->()\n", This);
457 return set_node_event(&This->node, EVENTID_CLICK, &v);
460 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
462 HTMLElement *This = HTMLELEM_THIS(iface);
463 FIXME("(%p)->(%p)\n", This, p);
467 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
469 HTMLElement *This = HTMLELEM_THIS(iface);
470 FIXME("(%p)->()\n", This);
474 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
476 HTMLElement *This = HTMLELEM_THIS(iface);
477 FIXME("(%p)->(%p)\n", This, p);
481 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
483 HTMLElement *This = HTMLELEM_THIS(iface);
484 FIXME("(%p)->()\n", This);
488 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
490 HTMLElement *This = HTMLELEM_THIS(iface);
491 FIXME("(%p)->(%p)\n", This, p);
495 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
497 HTMLElement *This = HTMLELEM_THIS(iface);
499 TRACE("(%p)->()\n", This);
501 return set_node_event(&This->node, EVENTID_KEYUP, &v);
504 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
506 HTMLElement *This = HTMLELEM_THIS(iface);
507 FIXME("(%p)->(%p)\n", This, p);
511 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
513 HTMLElement *This = HTMLELEM_THIS(iface);
514 FIXME("(%p)->()\n", This);
518 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
520 HTMLElement *This = HTMLELEM_THIS(iface);
521 FIXME("(%p)->(%p)\n", This, p);
525 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
527 HTMLElement *This = HTMLELEM_THIS(iface);
528 FIXME("(%p)->()\n", This);
532 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
534 HTMLElement *This = HTMLELEM_THIS(iface);
535 FIXME("(%p)->(%p)\n", This, p);
539 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
541 HTMLElement *This = HTMLELEM_THIS(iface);
542 FIXME("(%p)->()\n", This);
546 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
548 HTMLElement *This = HTMLELEM_THIS(iface);
549 FIXME("(%p)->(%p)\n", This, p);
553 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
555 HTMLElement *This = HTMLELEM_THIS(iface);
556 FIXME("(%p)->()\n", This);
560 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
562 HTMLElement *This = HTMLELEM_THIS(iface);
563 FIXME("(%p)->(%p)\n", This, p);
567 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
569 HTMLElement *This = HTMLELEM_THIS(iface);
570 FIXME("(%p)->()\n", This);
574 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
576 HTMLElement *This = HTMLELEM_THIS(iface);
577 FIXME("(%p)->(%p)\n", This, p);
581 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
583 HTMLElement *This = HTMLELEM_THIS(iface);
584 FIXME("(%p)->()\n", This);
588 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
590 HTMLElement *This = HTMLELEM_THIS(iface);
591 FIXME("(%p)->(%p)\n", This, p);
595 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
597 HTMLElement *This = HTMLELEM_THIS(iface);
598 FIXME("(%p)->(%p)\n", This, p);
602 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
604 HTMLElement *This = HTMLELEM_THIS(iface);
608 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
610 nsAString_Init(&title_str, v);
611 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
612 nsAString_Finish(&title_str);
614 ERR("SetTitle failed: %08x\n", nsres);
619 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
621 HTMLElement *This = HTMLELEM_THIS(iface);
625 TRACE("(%p)->(%p)\n", This, p);
627 nsAString_Init(&title_str, NULL);
628 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
629 if(NS_SUCCEEDED(nsres)) {
630 const PRUnichar *title;
632 nsAString_GetData(&title_str, &title);
633 *p = *title ? SysAllocString(title) : NULL;
635 ERR("GetTitle failed: %08x\n", nsres);
642 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
644 HTMLElement *This = HTMLELEM_THIS(iface);
645 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
649 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
651 HTMLElement *This = HTMLELEM_THIS(iface);
652 FIXME("(%p)->(%p)\n", This, p);
656 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
658 HTMLElement *This = HTMLELEM_THIS(iface);
659 FIXME("(%p)->()\n", This);
663 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
665 HTMLElement *This = HTMLELEM_THIS(iface);
666 FIXME("(%p)->(%p)\n", This, p);
670 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
672 HTMLElement *This = HTMLELEM_THIS(iface);
673 FIXME("(%p)->()\n", This);
677 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
678 VARIANT_BOOL *pfResult)
680 HTMLElement *This = HTMLELEM_THIS(iface);
681 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
685 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
687 HTMLElement *This = HTMLELEM_THIS(iface);
688 FIXME("(%p)->(%p)\n", This, p);
692 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
694 HTMLElement *This = HTMLELEM_THIS(iface);
695 FIXME("(%p)->(%p)\n", This, p);
699 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
701 HTMLElement *This = HTMLELEM_THIS(iface);
702 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
706 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
708 HTMLElement *This = HTMLELEM_THIS(iface);
709 FIXME("(%p)->(%p)\n", This, p);
713 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
715 HTMLElement *This = HTMLELEM_THIS(iface);
716 FIXME("(%p)->(%p)\n", This, p);
720 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
722 HTMLElement *This = HTMLELEM_THIS(iface);
723 nsIDOMNSHTMLElement *nselem;
727 TRACE("(%p)->(%p)\n", This, p);
729 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
730 if(NS_FAILED(nsres)) {
731 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
735 nsres = nsIDOMNSHTMLElement_GetOffsetTop(nselem, &top);
736 nsIDOMNSHTMLElement_Release(nselem);
737 if(NS_FAILED(nsres)) {
738 ERR("GetOffsetTop failed: %08x\n", nsres);
746 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
748 HTMLElement *This = HTMLELEM_THIS(iface);
749 FIXME("(%p)->(%p)\n", This, p);
753 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
755 HTMLElement *This = HTMLELEM_THIS(iface);
756 nsIDOMNSHTMLElement *nselem;
760 TRACE("(%p)->(%p)\n", This, p);
762 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
763 if(NS_FAILED(nsres)) {
764 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
768 nsres = nsIDOMNSHTMLElement_GetOffsetHeight(nselem, &offset);
769 nsIDOMNSHTMLElement_Release(nselem);
770 if(NS_FAILED(nsres)) {
771 ERR("GetOffsetHeight failed: %08x\n", nsres);
779 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
781 HTMLElement *This = HTMLELEM_THIS(iface);
782 FIXME("(%p)->(%p)\n", This, p);
786 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
788 HTMLElement *This = HTMLELEM_THIS(iface);
789 nsIDOMNSHTMLElement *nselem;
793 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
796 FIXME("NULL nselem\n");
800 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
801 if(NS_FAILED(nsres)) {
802 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
806 nsAString_Init(&html_str, v);
807 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
808 nsAString_Finish(&html_str);
810 if(NS_FAILED(nsres)) {
811 FIXME("SetInnerHtml failed %08x\n", nsres);
818 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
820 HTMLElement *This = HTMLELEM_THIS(iface);
821 FIXME("(%p)->(%p)\n", This, p);
825 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
827 HTMLElement *This = HTMLELEM_THIS(iface);
828 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
832 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
834 HTMLElement *This = HTMLELEM_THIS(iface);
835 FIXME("(%p)->(%p)\n", This, p);
839 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
841 HTMLElement *This = HTMLELEM_THIS(iface);
842 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
846 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
848 HTMLElement *This = HTMLELEM_THIS(iface);
849 FIXME("(%p)->(%p)\n", This, p);
853 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
855 HTMLElement *This = HTMLELEM_THIS(iface);
856 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
860 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
862 HTMLElement *This = HTMLELEM_THIS(iface);
863 FIXME("(%p)->(%p)\n", This, p);
867 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
869 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
870 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
871 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
872 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
876 FIXME("NULL nselem\n");
880 if (!strcmpiW(where, wszBeforeBegin))
884 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
885 if (!parent) return E_INVALIDARG;
886 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
887 (nsIDOMNode *)This->nselem, &unused);
888 if (unused) nsIDOMNode_Release(unused);
889 nsIDOMNode_Release(parent);
891 else if (!strcmpiW(where, wszAfterBegin))
894 nsIDOMNode *first_child;
895 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
896 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
897 if (unused) nsIDOMNode_Release(unused);
898 if (first_child) nsIDOMNode_Release(first_child);
900 else if (!strcmpiW(where, wszBeforeEnd))
903 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
904 if (unused) nsIDOMNode_Release(unused);
906 else if (!strcmpiW(where, wszAfterEnd))
909 nsIDOMNode *next_sibling;
911 nsIDOMNode_GetParentNode(This->nselem, &parent);
912 if (!parent) return E_INVALIDARG;
914 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
917 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
918 nsIDOMNode_Release(next_sibling);
921 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
922 nsIDOMNode_Release(parent);
923 if (unused) nsIDOMNode_Release(unused);
927 ERR("invalid where: %s\n", debugstr_w(where));
931 if (NS_FAILED(nsres))
937 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
940 HTMLElement *This = HTMLELEM_THIS(iface);
942 nsIDOMDocument *nsdoc;
943 nsIDOMDocumentRange *nsdocrange;
945 nsIDOMNSRange *nsrange;
950 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
952 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
955 ERR("GetDocument failed: %08x\n", nsres);
959 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
960 nsIDOMDocument_Release(nsdoc);
963 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
966 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
967 nsIDOMDocumentRange_Release(nsdocrange);
970 ERR("CreateRange failed: %08x\n", nsres);
974 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
976 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
977 nsIDOMRange_Release(range);
980 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
984 nsAString_Init(&ns_html, html);
986 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
987 nsIDOMNSRange_Release(nsrange);
988 nsAString_Finish(&ns_html);
990 if(NS_FAILED(nsres) || !nsnode)
992 ERR("CreateTextNode failed: %08x\n", nsres);
996 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
997 nsIDOMNode_Release(nsnode);
1002 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1005 HTMLElement *This = HTMLELEM_THIS(iface);
1007 nsIDOMDocument *nsdoc;
1012 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1014 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
1015 if(NS_FAILED(nsres) || !nsdoc)
1017 ERR("GetDocument failed: %08x\n", nsres);
1021 nsAString_Init(&ns_text, text);
1023 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1024 nsIDOMDocument_Release(nsdoc);
1025 nsAString_Finish(&ns_text);
1027 if(NS_FAILED(nsres) || !nsnode)
1029 ERR("CreateTextNode failed: %08x\n", nsres);
1033 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1034 nsIDOMNode_Release(nsnode);
1039 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1041 HTMLElement *This = HTMLELEM_THIS(iface);
1042 FIXME("(%p)->(%p)\n", This, p);
1046 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1048 HTMLElement *This = HTMLELEM_THIS(iface);
1049 FIXME("(%p)->(%p)\n", This, p);
1053 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1055 HTMLElement *This = HTMLELEM_THIS(iface);
1056 FIXME("(%p)\n", This);
1060 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1061 IHTMLFiltersCollection **p)
1063 HTMLElement *This = HTMLELEM_THIS(iface);
1064 FIXME("(%p)->(%p)\n", This, p);
1068 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1070 HTMLElement *This = HTMLELEM_THIS(iface);
1071 FIXME("(%p)->()\n", This);
1075 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1077 HTMLElement *This = HTMLELEM_THIS(iface);
1078 FIXME("(%p)->(%p)\n", This, p);
1082 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1084 HTMLElement *This = HTMLELEM_THIS(iface);
1085 FIXME("(%p)->(%p)\n", This, String);
1089 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1091 HTMLElement *This = HTMLELEM_THIS(iface);
1092 FIXME("(%p)->()\n", This);
1096 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1098 HTMLElement *This = HTMLELEM_THIS(iface);
1099 FIXME("(%p)->(%p)\n", This, p);
1103 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1105 HTMLElement *This = HTMLELEM_THIS(iface);
1106 FIXME("(%p)->()\n", This);
1110 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1112 HTMLElement *This = HTMLELEM_THIS(iface);
1113 FIXME("(%p)->(%p)\n", This, p);
1117 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1119 HTMLElement *This = HTMLELEM_THIS(iface);
1120 FIXME("(%p)->()\n", This);
1124 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1126 HTMLElement *This = HTMLELEM_THIS(iface);
1127 FIXME("(%p)->(%p)\n", This, p);
1131 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1133 HTMLElement *This = HTMLELEM_THIS(iface);
1134 FIXME("(%p)->()\n", This);
1138 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1140 HTMLElement *This = HTMLELEM_THIS(iface);
1141 FIXME("(%p)->(%p)\n", This, p);
1145 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1147 HTMLElement *This = HTMLELEM_THIS(iface);
1148 FIXME("(%p)->()\n", This);
1152 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1154 HTMLElement *This = HTMLELEM_THIS(iface);
1155 FIXME("(%p)->(%p)\n", This, p);
1159 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1161 HTMLElement *This = HTMLELEM_THIS(iface);
1162 FIXME("(%p)->()\n", This);
1166 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1168 HTMLElement *This = HTMLELEM_THIS(iface);
1169 FIXME("(%p)->(%p)\n", This, p);
1173 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1175 HTMLElement *This = HTMLELEM_THIS(iface);
1176 FIXME("(%p)->()\n", This);
1180 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1182 HTMLElement *This = HTMLELEM_THIS(iface);
1183 FIXME("(%p)->(%p)\n", This, p);
1187 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1189 HTMLElement *This = HTMLELEM_THIS(iface);
1190 FIXME("(%p)->()\n", This);
1194 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1196 HTMLElement *This = HTMLELEM_THIS(iface);
1197 FIXME("(%p)->(%p)\n", This, p);
1201 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1203 HTMLElement *This = HTMLELEM_THIS(iface);
1204 FIXME("(%p)->()\n", This);
1208 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1210 HTMLElement *This = HTMLELEM_THIS(iface);
1211 FIXME("(%p)->(%p)\n", This, p);
1215 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1217 nsIDOMNodeList *nsnode_list;
1219 PRUint32 list_len = 0, i;
1222 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1223 if(NS_FAILED(nsres)) {
1224 ERR("GetChildNodes failed: %08x\n", nsres);
1228 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1232 buf->size = list_len;
1233 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1235 for(i=0; i<list_len; i++) {
1236 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1237 if(NS_FAILED(nsres)) {
1238 ERR("Item failed: %08x\n", nsres);
1242 if(is_elem_node(iter))
1243 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1247 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1249 HTMLElement *This = HTMLELEM_THIS(iface);
1250 elem_vector buf = {NULL, 0, 0};
1252 TRACE("(%p)->(%p)\n", This, p);
1254 create_child_list(This->node.doc, This, &buf);
1256 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1260 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1262 nsIDOMNodeList *nsnode_list;
1264 PRUint32 list_len = 0, i;
1267 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1268 if(NS_FAILED(nsres)) {
1269 ERR("GetChildNodes failed: %08x\n", nsres);
1273 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1277 for(i=0; i<list_len; i++) {
1278 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1279 if(NS_FAILED(nsres)) {
1280 ERR("Item failed: %08x\n", nsres);
1284 if(is_elem_node(iter)) {
1285 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1287 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1288 create_all_list(doc, node, buf);
1293 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1295 HTMLElement *This = HTMLELEM_THIS(iface);
1296 elem_vector buf = {NULL, 0, 8};
1298 TRACE("(%p)->(%p)\n", This, p);
1300 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1302 create_all_list(This->node.doc, &This->node, &buf);
1303 elem_vector_normalize(&buf);
1305 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1309 #undef HTMLELEM_THIS
1311 static const IHTMLElementVtbl HTMLElementVtbl = {
1312 HTMLElement_QueryInterface,
1314 HTMLElement_Release,
1315 HTMLElement_GetTypeInfoCount,
1316 HTMLElement_GetTypeInfo,
1317 HTMLElement_GetIDsOfNames,
1319 HTMLElement_setAttribute,
1320 HTMLElement_getAttribute,
1321 HTMLElement_removeAttribute,
1322 HTMLElement_put_className,
1323 HTMLElement_get_className,
1326 HTMLElement_get_tagName,
1327 HTMLElement_get_parentElement,
1328 HTMLElement_get_style,
1329 HTMLElement_put_onhelp,
1330 HTMLElement_get_onhelp,
1331 HTMLElement_put_onclick,
1332 HTMLElement_get_onclick,
1333 HTMLElement_put_ondblclick,
1334 HTMLElement_get_ondblclick,
1335 HTMLElement_put_onkeydown,
1336 HTMLElement_get_onkeydown,
1337 HTMLElement_put_onkeyup,
1338 HTMLElement_get_onkeyup,
1339 HTMLElement_put_onkeypress,
1340 HTMLElement_get_onkeypress,
1341 HTMLElement_put_onmouseout,
1342 HTMLElement_get_onmouseout,
1343 HTMLElement_put_onmouseover,
1344 HTMLElement_get_onmouseover,
1345 HTMLElement_put_onmousemove,
1346 HTMLElement_get_onmousemove,
1347 HTMLElement_put_onmousedown,
1348 HTMLElement_get_onmousedown,
1349 HTMLElement_put_onmouseup,
1350 HTMLElement_get_onmouseup,
1351 HTMLElement_get_document,
1352 HTMLElement_put_title,
1353 HTMLElement_get_title,
1354 HTMLElement_put_language,
1355 HTMLElement_get_language,
1356 HTMLElement_put_onselectstart,
1357 HTMLElement_get_onselectstart,
1358 HTMLElement_scrollIntoView,
1359 HTMLElement_contains,
1360 HTMLElement_get_sourceIndex,
1361 HTMLElement_get_recordNumber,
1362 HTMLElement_put_lang,
1363 HTMLElement_get_lang,
1364 HTMLElement_get_offsetLeft,
1365 HTMLElement_get_offsetTop,
1366 HTMLElement_get_offsetWidth,
1367 HTMLElement_get_offsetHeight,
1368 HTMLElement_get_offsetParent,
1369 HTMLElement_put_innerHTML,
1370 HTMLElement_get_innerHTML,
1371 HTMLElement_put_innerText,
1372 HTMLElement_get_innerText,
1373 HTMLElement_put_outerHTML,
1374 HTMLElement_get_outerHTML,
1375 HTMLElement_put_outerText,
1376 HTMLElement_get_outerText,
1377 HTMLElement_insertAdjacentHTML,
1378 HTMLElement_insertAdjacentText,
1379 HTMLElement_get_parentTextEdit,
1380 HTMLElement_get_isTextEdit,
1382 HTMLElement_get_filters,
1383 HTMLElement_put_ondragstart,
1384 HTMLElement_get_ondragstart,
1385 HTMLElement_toString,
1386 HTMLElement_put_onbeforeupdate,
1387 HTMLElement_get_onbeforeupdate,
1388 HTMLElement_put_onafterupdate,
1389 HTMLElement_get_onafterupdate,
1390 HTMLElement_put_onerrorupdate,
1391 HTMLElement_get_onerrorupdate,
1392 HTMLElement_put_onrowexit,
1393 HTMLElement_get_onrowexit,
1394 HTMLElement_put_onrowenter,
1395 HTMLElement_get_onrowenter,
1396 HTMLElement_put_ondatasetchanged,
1397 HTMLElement_get_ondatasetchanged,
1398 HTMLElement_put_ondataavailable,
1399 HTMLElement_get_ondataavailable,
1400 HTMLElement_put_ondatasetcomplete,
1401 HTMLElement_get_ondatasetcomplete,
1402 HTMLElement_put_onfilterchange,
1403 HTMLElement_get_onfilterchange,
1404 HTMLElement_get_children,
1408 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1410 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1414 if(IsEqualGUID(&IID_IUnknown, riid)) {
1415 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1416 *ppv = HTMLELEM(This);
1417 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1418 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1419 *ppv = HTMLELEM(This);
1420 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1421 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1422 *ppv = HTMLELEM(This);
1423 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1424 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1425 *ppv = HTMLELEM2(This);
1426 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1427 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1428 *ppv = CONPTCONT(&This->cp_container);
1432 IHTMLElement_AddRef(HTMLELEM(This));
1436 return HTMLDOMNode_QI(&This->node, riid, ppv);
1439 void HTMLElement_destructor(HTMLDOMNode *iface)
1441 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1443 ConnectionPointContainer_Destroy(&This->cp_container);
1446 nsIDOMHTMLElement_Release(This->nselem);
1448 HTMLDOMNode_destructor(&This->node);
1451 static const NodeImplVtbl HTMLElementImplVtbl = {
1453 HTMLElement_destructor
1456 static const tid_t HTMLElement_iface_tids[] = {
1464 static dispex_static_data_t HTMLElement_dispex = {
1466 DispHTMLUnknownElement_tid,
1468 HTMLElement_iface_tids
1471 void HTMLElement_Init(HTMLElement *This)
1473 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1475 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1477 HTMLElement2_Init(This);
1479 if(!This->node.dispex.data)
1480 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1483 HTMLElement *HTMLElement_Create(HTMLDocument *doc, nsIDOMNode *nsnode, BOOL use_generic)
1485 nsIDOMHTMLElement *nselem;
1486 HTMLElement *ret = NULL;
1487 nsAString class_name_str;
1488 const PRUnichar *class_name;
1491 static const WCHAR wszA[] = {'A',0};
1492 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1493 static const WCHAR wszIMG[] = {'I','M','G',0};
1494 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1495 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1496 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1497 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1498 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1499 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1501 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1502 if(NS_FAILED(nsres))
1505 nsAString_Init(&class_name_str, NULL);
1506 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1508 nsAString_GetData(&class_name_str, &class_name);
1510 if(!strcmpW(class_name, wszA))
1511 ret = HTMLAnchorElement_Create(nselem);
1512 else if(!strcmpW(class_name, wszBODY))
1513 ret = HTMLBodyElement_Create(nselem);
1514 else if(!strcmpW(class_name, wszIMG))
1515 ret = HTMLImgElement_Create(nselem);
1516 else if(!strcmpW(class_name, wszINPUT))
1517 ret = HTMLInputElement_Create(nselem);
1518 else if(!strcmpW(class_name, wszOPTION))
1519 ret = HTMLOptionElement_Create(nselem);
1520 else if(!strcmpW(class_name, wszSCRIPT))
1521 ret = HTMLScriptElement_Create(nselem);
1522 else if(!strcmpW(class_name, wszSELECT))
1523 ret = HTMLSelectElement_Create(nselem);
1524 else if(!strcmpW(class_name, wszTABLE))
1525 ret = HTMLTable_Create(nselem);
1526 else if(!strcmpW(class_name, wszTEXTAREA))
1527 ret = HTMLTextAreaElement_Create(nselem);
1528 else if(use_generic)
1529 ret = HTMLGenericElement_Create(nselem);
1532 ret = heap_alloc_zero(sizeof(HTMLElement));
1533 HTMLElement_Init(ret);
1534 ret->node.vtbl = &HTMLElementImplVtbl;
1537 TRACE("%s ret %p\n", debugstr_w(class_name), ret);
1539 nsAString_Finish(&class_name_str);
1541 ret->nselem = nselem;
1542 HTMLDOMNode_Init(doc, &ret->node, (nsIDOMNode*)nselem);
1549 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1552 HTMLElement **elems;
1556 } HTMLElementCollection;
1558 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1560 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1562 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1563 REFIID riid, void **ppv)
1565 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1569 if(IsEqualGUID(&IID_IUnknown, riid)) {
1570 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1571 *ppv = HTMLELEMCOL(This);
1572 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1573 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1574 *ppv = HTMLELEMCOL(This);
1575 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1576 return *ppv ? S_OK : E_NOINTERFACE;
1580 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1584 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1585 return E_NOINTERFACE;
1588 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1590 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1591 LONG ref = InterlockedIncrement(&This->ref);
1593 TRACE("(%p) ref=%d\n", This, ref);
1598 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1600 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1601 LONG ref = InterlockedDecrement(&This->ref);
1603 TRACE("(%p) ref=%d\n", This, ref);
1606 IUnknown_Release(This->ref_unk);
1607 heap_free(This->elems);
1614 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1617 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1618 FIXME("(%p)->(%p)\n", This, pctinfo);
1622 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1623 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1625 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1626 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1630 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1631 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1633 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1634 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1639 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1640 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1641 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1643 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1644 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1645 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1649 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1652 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1653 FIXME("(%p)->(%p)\n", This, String);
1657 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1660 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1661 FIXME("(%p)->(%ld)\n", This, v);
1665 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1668 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1670 TRACE("(%p)->(%p)\n", This, p);
1676 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1679 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1680 FIXME("(%p)->(%p)\n", This, p);
1684 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1686 const PRUnichar *str;
1687 nsAString nsstr, nsname;
1691 static const PRUnichar nameW[] = {'n','a','m','e',0};
1696 nsAString_Init(&nsstr, NULL);
1697 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1698 nsAString_GetData(&nsstr, &str);
1699 if(!strcmpiW(str, name)) {
1700 nsAString_Finish(&nsstr);
1704 nsAString_Init(&nsname, nameW);
1705 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1706 nsAString_Finish(&nsname);
1707 if(NS_SUCCEEDED(nsres)) {
1708 nsAString_GetData(&nsstr, &str);
1709 ret = !strcmpiW(str, name);
1712 nsAString_Finish(&nsstr);
1716 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1717 VARIANT name, VARIANT index, IDispatch **pdisp)
1719 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1721 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1725 if(V_VT(&name) == VT_I4) {
1726 TRACE("name is VT_I4: %d\n", V_I4(&name));
1729 return E_INVALIDARG;
1730 if(V_I4(&name) >= This->len)
1733 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1734 IDispatch_AddRef(*pdisp);
1735 TRACE("Returning pdisp=%p\n", pdisp);
1739 if(V_VT(&name) == VT_BSTR) {
1742 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1744 if(V_VT(&index) == VT_I4) {
1745 LONG idx = V_I4(&index);
1747 TRACE("index = %d\n", idx);
1750 return E_INVALIDARG;
1752 for(i=0; i<This->len; i++) {
1753 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1757 if(i != This->len) {
1758 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1759 IDispatch_AddRef(*pdisp);
1764 elem_vector buf = {NULL, 0, 8};
1766 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1768 for(i=0; i<This->len; i++) {
1769 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1770 elem_vector_add(&buf, This->elems[i]);
1774 elem_vector_normalize(&buf);
1775 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1778 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1779 IDispatch_AddRef(*pdisp);
1789 FIXME("unsupported arguments\n");
1790 return E_INVALIDARG;
1793 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1794 VARIANT tagName, IDispatch **pdisp)
1796 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1799 const PRUnichar *tag;
1800 elem_vector buf = {NULL, 0, 8};
1802 if(V_VT(&tagName) != VT_BSTR) {
1803 WARN("Invalid arg\n");
1804 return DISP_E_MEMBERNOTFOUND;
1807 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1809 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1811 nsAString_Init(&tag_str, NULL);
1813 for(i=0; i<This->len; i++) {
1814 if(!This->elems[i]->nselem)
1817 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1818 nsAString_GetData(&tag_str, &tag);
1820 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1821 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1822 elem_vector_add(&buf, This->elems[i]);
1825 nsAString_Finish(&tag_str);
1826 elem_vector_normalize(&buf);
1828 TRACE("fount %d tags\n", buf.len);
1830 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1834 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1836 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1838 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1842 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1843 idx = idx*10 + (*ptr-'0');
1845 if(*ptr || idx >= This->len)
1846 return DISP_E_UNKNOWNNAME;
1848 *dispid = DISPID_ELEMCOL_0 + idx;
1849 TRACE("ret %x\n", *dispid);
1853 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1854 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1856 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1859 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1861 idx = id - DISPID_ELEMCOL_0;
1862 if(idx >= This->len)
1863 return DISP_E_UNKNOWNNAME;
1866 case INVOKE_PROPERTYGET:
1867 V_VT(res) = VT_DISPATCH;
1868 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1869 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1872 FIXME("unimplemented flags %x\n", flags);
1881 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1882 HTMLElementCollection_QueryInterface,
1883 HTMLElementCollection_AddRef,
1884 HTMLElementCollection_Release,
1885 HTMLElementCollection_GetTypeInfoCount,
1886 HTMLElementCollection_GetTypeInfo,
1887 HTMLElementCollection_GetIDsOfNames,
1888 HTMLElementCollection_Invoke,
1889 HTMLElementCollection_toString,
1890 HTMLElementCollection_put_length,
1891 HTMLElementCollection_get_length,
1892 HTMLElementCollection_get__newEnum,
1893 HTMLElementCollection_item,
1894 HTMLElementCollection_tags
1897 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1898 HTMLElementCollection_get_dispid,
1899 HTMLElementCollection_invoke
1902 static const tid_t HTMLElementCollection_iface_tids[] = {
1903 IHTMLElementCollection_tid,
1906 static dispex_static_data_t HTMLElementCollection_dispex = {
1907 &HTMLElementColection_dispex_vtbl,
1908 DispHTMLElementCollection_tid,
1910 HTMLElementCollection_iface_tids
1913 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1915 elem_vector buf = {NULL, 0, 8};
1917 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1919 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1920 create_all_list(node->doc, node, &buf);
1921 elem_vector_normalize(&buf);
1923 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1926 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument *doc, IUnknown *unk, nsIDOMNodeList *nslist)
1928 PRUint32 length = 0, i;
1931 nsIDOMNodeList_GetLength(nslist, &length);
1933 buf.len = buf.size = length;
1937 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1939 for(i=0; i<length; i++) {
1940 nsIDOMNodeList_Item(nslist, i, &nsnode);
1941 buf.buf[i] = HTMLELEM_NODE_THIS(get_node(doc, nsnode, TRUE));
1942 nsIDOMNode_Release(nsnode);
1948 return HTMLElementCollection_Create(unk, buf.buf, buf.len);
1951 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1952 HTMLElement **elems, DWORD len)
1954 HTMLElementCollection *ret = heap_alloc_zero(sizeof(HTMLElementCollection));
1956 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1961 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1963 IUnknown_AddRef(ref_unk);
1964 ret->ref_unk = ref_unk;
1966 TRACE("ret=%p len=%d\n", ret, len);
1968 return HTMLELEMCOL(ret);