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 nsAString classname_str;
258 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
261 FIXME("NULL nselem\n");
265 nsAString_Init(&classname_str, v);
266 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
267 nsAString_Finish(&classname_str);
269 ERR("SetClassName failed: %08x\n", nsres);
274 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
276 HTMLElement *This = HTMLELEM_THIS(iface);
281 TRACE("(%p)->(%p)\n", This, p);
284 FIXME("NULL nselem\n");
288 nsAString_Init(&class_str, NULL);
289 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
291 if(NS_SUCCEEDED(nsres)) {
292 const PRUnichar *class;
293 nsAString_GetData(&class_str, &class);
294 *p = *class ? SysAllocString(class) : NULL;
296 ERR("GetClassName failed: %08x\n", nsres);
300 nsAString_Finish(&class_str);
302 TRACE("className=%s\n", debugstr_w(*p));
306 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
308 HTMLElement *This = HTMLELEM_THIS(iface);
312 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
315 FIXME("nselem == NULL\n");
319 nsAString_Init(&id_str, v);
320 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
321 nsAString_Finish(&id_str);
323 ERR("SetId failed: %08x\n", nsres);
328 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
330 HTMLElement *This = HTMLELEM_THIS(iface);
335 TRACE("(%p)->(%p)\n", This, p);
342 nsAString_Init(&id_str, NULL);
343 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
344 nsAString_GetData(&id_str, &id);
347 ERR("GetId failed: %08x\n", nsres);
349 *p = SysAllocString(id);
351 nsAString_Finish(&id_str);
355 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
357 HTMLElement *This = HTMLELEM_THIS(iface);
358 const PRUnichar *tag;
362 TRACE("(%p)->(%p)\n", This, p);
365 static const WCHAR comment_tagW[] = {'!',0};
367 WARN("NULL nselem, assuming comment\n");
369 *p = SysAllocString(comment_tagW);
373 nsAString_Init(&tag_str, NULL);
374 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
375 if(NS_SUCCEEDED(nsres)) {
376 nsAString_GetData(&tag_str, &tag);
377 *p = SysAllocString(tag);
379 ERR("GetTagName failed: %08x\n", nsres);
382 nsAString_Finish(&tag_str);
387 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
389 HTMLElement *This = HTMLELEM_THIS(iface);
390 FIXME("(%p)->(%p)\n", This, p);
394 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
396 HTMLElement *This = HTMLELEM_THIS(iface);
397 nsIDOMElementCSSInlineStyle *nselemstyle;
398 nsIDOMCSSStyleDeclaration *nsstyle;
401 TRACE("(%p)->(%p)\n", This, p);
404 FIXME("NULL nselem\n");
408 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
409 (void**)&nselemstyle);
410 if(NS_FAILED(nsres)) {
411 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
415 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
416 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
417 if(NS_FAILED(nsres)) {
418 ERR("GetStyle failed: %08x\n", nsres);
422 /* FIXME: Store style instead of creating a new instance in each call */
423 *p = HTMLStyle_Create(nsstyle);
425 nsIDOMCSSStyleDeclaration_Release(nsstyle);
429 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
431 HTMLElement *This = HTMLELEM_THIS(iface);
432 FIXME("(%p)->()\n", This);
436 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
438 HTMLElement *This = HTMLELEM_THIS(iface);
439 FIXME("(%p)->(%p)\n", This, p);
443 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
445 HTMLElement *This = HTMLELEM_THIS(iface);
447 TRACE("(%p)->()\n", This);
449 return set_node_event(&This->node, EVENTID_CLICK, &v);
452 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
454 HTMLElement *This = HTMLELEM_THIS(iface);
455 FIXME("(%p)->(%p)\n", This, p);
459 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
461 HTMLElement *This = HTMLELEM_THIS(iface);
462 FIXME("(%p)->()\n", This);
466 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
468 HTMLElement *This = HTMLELEM_THIS(iface);
469 FIXME("(%p)->(%p)\n", This, p);
473 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
475 HTMLElement *This = HTMLELEM_THIS(iface);
476 FIXME("(%p)->()\n", This);
480 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
482 HTMLElement *This = HTMLELEM_THIS(iface);
483 FIXME("(%p)->(%p)\n", This, p);
487 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
489 HTMLElement *This = HTMLELEM_THIS(iface);
491 TRACE("(%p)->()\n", This);
493 return set_node_event(&This->node, EVENTID_KEYUP, &v);
496 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
498 HTMLElement *This = HTMLELEM_THIS(iface);
499 FIXME("(%p)->(%p)\n", This, p);
503 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
505 HTMLElement *This = HTMLELEM_THIS(iface);
506 FIXME("(%p)->()\n", This);
510 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
512 HTMLElement *This = HTMLELEM_THIS(iface);
513 FIXME("(%p)->(%p)\n", This, p);
517 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
519 HTMLElement *This = HTMLELEM_THIS(iface);
520 FIXME("(%p)->()\n", This);
524 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
526 HTMLElement *This = HTMLELEM_THIS(iface);
527 FIXME("(%p)->(%p)\n", This, p);
531 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
533 HTMLElement *This = HTMLELEM_THIS(iface);
534 FIXME("(%p)->()\n", This);
538 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
540 HTMLElement *This = HTMLELEM_THIS(iface);
541 FIXME("(%p)->(%p)\n", This, p);
545 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
547 HTMLElement *This = HTMLELEM_THIS(iface);
548 FIXME("(%p)->()\n", This);
552 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
554 HTMLElement *This = HTMLELEM_THIS(iface);
555 FIXME("(%p)->(%p)\n", This, p);
559 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
561 HTMLElement *This = HTMLELEM_THIS(iface);
562 FIXME("(%p)->()\n", This);
566 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
568 HTMLElement *This = HTMLELEM_THIS(iface);
569 FIXME("(%p)->(%p)\n", This, p);
573 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
575 HTMLElement *This = HTMLELEM_THIS(iface);
576 FIXME("(%p)->()\n", This);
580 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
582 HTMLElement *This = HTMLELEM_THIS(iface);
583 FIXME("(%p)->(%p)\n", This, p);
587 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
589 HTMLElement *This = HTMLELEM_THIS(iface);
590 FIXME("(%p)->(%p)\n", This, p);
594 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
596 HTMLElement *This = HTMLELEM_THIS(iface);
597 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
601 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
603 HTMLElement *This = HTMLELEM_THIS(iface);
604 FIXME("(%p)->(%p)\n", This, p);
608 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
610 HTMLElement *This = HTMLELEM_THIS(iface);
611 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
615 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
617 HTMLElement *This = HTMLELEM_THIS(iface);
618 FIXME("(%p)->(%p)\n", This, p);
622 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
624 HTMLElement *This = HTMLELEM_THIS(iface);
625 FIXME("(%p)->()\n", This);
629 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
631 HTMLElement *This = HTMLELEM_THIS(iface);
632 FIXME("(%p)->(%p)\n", This, p);
636 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
638 HTMLElement *This = HTMLELEM_THIS(iface);
639 FIXME("(%p)->()\n", This);
643 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
644 VARIANT_BOOL *pfResult)
646 HTMLElement *This = HTMLELEM_THIS(iface);
647 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
651 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
653 HTMLElement *This = HTMLELEM_THIS(iface);
654 FIXME("(%p)->(%p)\n", This, p);
658 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
660 HTMLElement *This = HTMLELEM_THIS(iface);
661 FIXME("(%p)->(%p)\n", This, p);
665 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
667 HTMLElement *This = HTMLELEM_THIS(iface);
668 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
672 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
674 HTMLElement *This = HTMLELEM_THIS(iface);
675 FIXME("(%p)->(%p)\n", This, p);
679 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
681 HTMLElement *This = HTMLELEM_THIS(iface);
682 FIXME("(%p)->(%p)\n", This, p);
686 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
688 HTMLElement *This = HTMLELEM_THIS(iface);
689 FIXME("(%p)->(%p)\n", This, p);
693 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
695 HTMLElement *This = HTMLELEM_THIS(iface);
696 FIXME("(%p)->(%p)\n", This, p);
700 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
702 HTMLElement *This = HTMLELEM_THIS(iface);
703 FIXME("(%p)->(%p)\n", This, p);
707 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
709 HTMLElement *This = HTMLELEM_THIS(iface);
710 FIXME("(%p)->(%p)\n", This, p);
714 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
716 HTMLElement *This = HTMLELEM_THIS(iface);
717 nsIDOMNSHTMLElement *nselem;
721 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
724 FIXME("NULL nselem\n");
728 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
729 if(NS_FAILED(nsres)) {
730 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
734 nsAString_Init(&html_str, v);
735 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
736 nsAString_Finish(&html_str);
738 if(NS_FAILED(nsres)) {
739 FIXME("SetInnerHtml failed %08x\n", nsres);
746 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
748 HTMLElement *This = HTMLELEM_THIS(iface);
749 FIXME("(%p)->(%p)\n", This, p);
753 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
755 HTMLElement *This = HTMLELEM_THIS(iface);
756 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
760 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
762 HTMLElement *This = HTMLELEM_THIS(iface);
763 FIXME("(%p)->(%p)\n", This, p);
767 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
769 HTMLElement *This = HTMLELEM_THIS(iface);
770 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
774 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
776 HTMLElement *This = HTMLELEM_THIS(iface);
777 FIXME("(%p)->(%p)\n", This, p);
781 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
783 HTMLElement *This = HTMLELEM_THIS(iface);
784 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
788 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
790 HTMLElement *This = HTMLELEM_THIS(iface);
791 FIXME("(%p)->(%p)\n", This, p);
795 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
797 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
798 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
799 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
800 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
804 FIXME("NULL nselem\n");
808 if (!strcmpiW(where, wszBeforeBegin))
812 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
813 if (!parent) return E_INVALIDARG;
814 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
815 (nsIDOMNode *)This->nselem, &unused);
816 if (unused) nsIDOMNode_Release(unused);
817 nsIDOMNode_Release(parent);
819 else if (!strcmpiW(where, wszAfterBegin))
822 nsIDOMNode *first_child;
823 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
824 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
825 if (unused) nsIDOMNode_Release(unused);
826 if (first_child) nsIDOMNode_Release(first_child);
828 else if (!strcmpiW(where, wszBeforeEnd))
831 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
832 if (unused) nsIDOMNode_Release(unused);
834 else if (!strcmpiW(where, wszAfterEnd))
837 nsIDOMNode *next_sibling;
839 nsIDOMNode_GetParentNode(This->nselem, &parent);
840 if (!parent) return E_INVALIDARG;
842 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
845 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
846 nsIDOMNode_Release(next_sibling);
849 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
850 nsIDOMNode_Release(parent);
851 if (unused) nsIDOMNode_Release(unused);
855 ERR("invalid where: %s\n", debugstr_w(where));
859 if (NS_FAILED(nsres))
865 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
868 HTMLElement *This = HTMLELEM_THIS(iface);
870 nsIDOMDocument *nsdoc;
871 nsIDOMDocumentRange *nsdocrange;
873 nsIDOMNSRange *nsrange;
878 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
880 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
883 ERR("GetDocument failed: %08x\n", nsres);
887 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
888 nsIDOMDocument_Release(nsdoc);
891 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
894 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
895 nsIDOMDocumentRange_Release(nsdocrange);
898 ERR("CreateRange failed: %08x\n", nsres);
902 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
904 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
905 nsIDOMRange_Release(range);
908 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
912 nsAString_Init(&ns_html, html);
914 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
915 nsIDOMNSRange_Release(nsrange);
916 nsAString_Finish(&ns_html);
918 if(NS_FAILED(nsres) || !nsnode)
920 ERR("CreateTextNode failed: %08x\n", nsres);
924 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
925 nsIDOMNode_Release(nsnode);
930 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
933 HTMLElement *This = HTMLELEM_THIS(iface);
935 nsIDOMDocument *nsdoc;
940 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
942 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
943 if(NS_FAILED(nsres) || !nsdoc)
945 ERR("GetDocument failed: %08x\n", nsres);
949 nsAString_Init(&ns_text, text);
951 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
952 nsIDOMDocument_Release(nsdoc);
953 nsAString_Finish(&ns_text);
955 if(NS_FAILED(nsres) || !nsnode)
957 ERR("CreateTextNode failed: %08x\n", nsres);
961 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
962 nsIDOMNode_Release(nsnode);
967 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
969 HTMLElement *This = HTMLELEM_THIS(iface);
970 FIXME("(%p)->(%p)\n", This, p);
974 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
976 HTMLElement *This = HTMLELEM_THIS(iface);
977 FIXME("(%p)->(%p)\n", This, p);
981 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
983 HTMLElement *This = HTMLELEM_THIS(iface);
984 FIXME("(%p)\n", This);
988 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
989 IHTMLFiltersCollection **p)
991 HTMLElement *This = HTMLELEM_THIS(iface);
992 FIXME("(%p)->(%p)\n", This, p);
996 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
998 HTMLElement *This = HTMLELEM_THIS(iface);
999 FIXME("(%p)->()\n", This);
1003 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1005 HTMLElement *This = HTMLELEM_THIS(iface);
1006 FIXME("(%p)->(%p)\n", This, p);
1010 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1012 HTMLElement *This = HTMLELEM_THIS(iface);
1013 FIXME("(%p)->(%p)\n", This, String);
1017 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1019 HTMLElement *This = HTMLELEM_THIS(iface);
1020 FIXME("(%p)->()\n", This);
1024 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1026 HTMLElement *This = HTMLELEM_THIS(iface);
1027 FIXME("(%p)->(%p)\n", This, p);
1031 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1033 HTMLElement *This = HTMLELEM_THIS(iface);
1034 FIXME("(%p)->()\n", This);
1038 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1040 HTMLElement *This = HTMLELEM_THIS(iface);
1041 FIXME("(%p)->(%p)\n", This, p);
1045 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1047 HTMLElement *This = HTMLELEM_THIS(iface);
1048 FIXME("(%p)->()\n", This);
1052 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1054 HTMLElement *This = HTMLELEM_THIS(iface);
1055 FIXME("(%p)->(%p)\n", This, p);
1059 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1061 HTMLElement *This = HTMLELEM_THIS(iface);
1062 FIXME("(%p)->()\n", This);
1066 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1068 HTMLElement *This = HTMLELEM_THIS(iface);
1069 FIXME("(%p)->(%p)\n", This, p);
1073 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1075 HTMLElement *This = HTMLELEM_THIS(iface);
1076 FIXME("(%p)->()\n", This);
1080 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1082 HTMLElement *This = HTMLELEM_THIS(iface);
1083 FIXME("(%p)->(%p)\n", This, p);
1087 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1089 HTMLElement *This = HTMLELEM_THIS(iface);
1090 FIXME("(%p)->()\n", This);
1094 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1096 HTMLElement *This = HTMLELEM_THIS(iface);
1097 FIXME("(%p)->(%p)\n", This, p);
1101 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1103 HTMLElement *This = HTMLELEM_THIS(iface);
1104 FIXME("(%p)->()\n", This);
1108 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1110 HTMLElement *This = HTMLELEM_THIS(iface);
1111 FIXME("(%p)->(%p)\n", This, p);
1115 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1117 HTMLElement *This = HTMLELEM_THIS(iface);
1118 FIXME("(%p)->()\n", This);
1122 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1124 HTMLElement *This = HTMLELEM_THIS(iface);
1125 FIXME("(%p)->(%p)\n", This, p);
1129 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1131 HTMLElement *This = HTMLELEM_THIS(iface);
1132 FIXME("(%p)->()\n", This);
1136 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1138 HTMLElement *This = HTMLELEM_THIS(iface);
1139 FIXME("(%p)->(%p)\n", This, p);
1143 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1145 nsIDOMNodeList *nsnode_list;
1147 PRUint32 list_len = 0, i;
1150 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1151 if(NS_FAILED(nsres)) {
1152 ERR("GetChildNodes failed: %08x\n", nsres);
1156 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1160 buf->size = list_len;
1161 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1163 for(i=0; i<list_len; i++) {
1164 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1165 if(NS_FAILED(nsres)) {
1166 ERR("Item failed: %08x\n", nsres);
1170 if(is_elem_node(iter))
1171 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1175 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1177 HTMLElement *This = HTMLELEM_THIS(iface);
1178 elem_vector buf = {NULL, 0, 0};
1180 TRACE("(%p)->(%p)\n", This, p);
1182 create_child_list(This->node.doc, This, &buf);
1184 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1188 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1190 nsIDOMNodeList *nsnode_list;
1192 PRUint32 list_len = 0, i;
1195 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1196 if(NS_FAILED(nsres)) {
1197 ERR("GetChildNodes failed: %08x\n", nsres);
1201 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1205 for(i=0; i<list_len; i++) {
1206 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1207 if(NS_FAILED(nsres)) {
1208 ERR("Item failed: %08x\n", nsres);
1212 if(is_elem_node(iter)) {
1213 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1215 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1216 create_all_list(doc, node, buf);
1221 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1223 HTMLElement *This = HTMLELEM_THIS(iface);
1224 elem_vector buf = {NULL, 0, 8};
1226 TRACE("(%p)->(%p)\n", This, p);
1228 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1230 create_all_list(This->node.doc, &This->node, &buf);
1231 elem_vector_normalize(&buf);
1233 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1237 #undef HTMLELEM_THIS
1239 static const IHTMLElementVtbl HTMLElementVtbl = {
1240 HTMLElement_QueryInterface,
1242 HTMLElement_Release,
1243 HTMLElement_GetTypeInfoCount,
1244 HTMLElement_GetTypeInfo,
1245 HTMLElement_GetIDsOfNames,
1247 HTMLElement_setAttribute,
1248 HTMLElement_getAttribute,
1249 HTMLElement_removeAttribute,
1250 HTMLElement_put_className,
1251 HTMLElement_get_className,
1254 HTMLElement_get_tagName,
1255 HTMLElement_get_parentElement,
1256 HTMLElement_get_style,
1257 HTMLElement_put_onhelp,
1258 HTMLElement_get_onhelp,
1259 HTMLElement_put_onclick,
1260 HTMLElement_get_onclick,
1261 HTMLElement_put_ondblclick,
1262 HTMLElement_get_ondblclick,
1263 HTMLElement_put_onkeydown,
1264 HTMLElement_get_onkeydown,
1265 HTMLElement_put_onkeyup,
1266 HTMLElement_get_onkeyup,
1267 HTMLElement_put_onkeypress,
1268 HTMLElement_get_onkeypress,
1269 HTMLElement_put_onmouseout,
1270 HTMLElement_get_onmouseout,
1271 HTMLElement_put_onmouseover,
1272 HTMLElement_get_onmouseover,
1273 HTMLElement_put_onmousemove,
1274 HTMLElement_get_onmousemove,
1275 HTMLElement_put_onmousedown,
1276 HTMLElement_get_onmousedown,
1277 HTMLElement_put_onmouseup,
1278 HTMLElement_get_onmouseup,
1279 HTMLElement_get_document,
1280 HTMLElement_put_title,
1281 HTMLElement_get_title,
1282 HTMLElement_put_language,
1283 HTMLElement_get_language,
1284 HTMLElement_put_onselectstart,
1285 HTMLElement_get_onselectstart,
1286 HTMLElement_scrollIntoView,
1287 HTMLElement_contains,
1288 HTMLElement_get_sourceIndex,
1289 HTMLElement_get_recordNumber,
1290 HTMLElement_put_lang,
1291 HTMLElement_get_lang,
1292 HTMLElement_get_offsetLeft,
1293 HTMLElement_get_offsetTop,
1294 HTMLElement_get_offsetWidth,
1295 HTMLElement_get_offsetHeight,
1296 HTMLElement_get_offsetParent,
1297 HTMLElement_put_innerHTML,
1298 HTMLElement_get_innerHTML,
1299 HTMLElement_put_innerText,
1300 HTMLElement_get_innerText,
1301 HTMLElement_put_outerHTML,
1302 HTMLElement_get_outerHTML,
1303 HTMLElement_put_outerText,
1304 HTMLElement_get_outerText,
1305 HTMLElement_insertAdjacentHTML,
1306 HTMLElement_insertAdjacentText,
1307 HTMLElement_get_parentTextEdit,
1308 HTMLElement_get_isTextEdit,
1310 HTMLElement_get_filters,
1311 HTMLElement_put_ondragstart,
1312 HTMLElement_get_ondragstart,
1313 HTMLElement_toString,
1314 HTMLElement_put_onbeforeupdate,
1315 HTMLElement_get_onbeforeupdate,
1316 HTMLElement_put_onafterupdate,
1317 HTMLElement_get_onafterupdate,
1318 HTMLElement_put_onerrorupdate,
1319 HTMLElement_get_onerrorupdate,
1320 HTMLElement_put_onrowexit,
1321 HTMLElement_get_onrowexit,
1322 HTMLElement_put_onrowenter,
1323 HTMLElement_get_onrowenter,
1324 HTMLElement_put_ondatasetchanged,
1325 HTMLElement_get_ondatasetchanged,
1326 HTMLElement_put_ondataavailable,
1327 HTMLElement_get_ondataavailable,
1328 HTMLElement_put_ondatasetcomplete,
1329 HTMLElement_get_ondatasetcomplete,
1330 HTMLElement_put_onfilterchange,
1331 HTMLElement_get_onfilterchange,
1332 HTMLElement_get_children,
1336 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1338 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1342 if(IsEqualGUID(&IID_IUnknown, riid)) {
1343 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1344 *ppv = HTMLELEM(This);
1345 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1346 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1347 *ppv = HTMLELEM(This);
1348 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1349 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1350 *ppv = HTMLELEM(This);
1351 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1352 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1353 *ppv = HTMLELEM2(This);
1354 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1355 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1356 *ppv = CONPTCONT(&This->cp_container);
1360 IHTMLElement_AddRef(HTMLELEM(This));
1364 return HTMLDOMNode_QI(&This->node, riid, ppv);
1367 void HTMLElement_destructor(HTMLDOMNode *iface)
1369 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1371 ConnectionPointContainer_Destroy(&This->cp_container);
1374 nsIDOMHTMLElement_Release(This->nselem);
1376 HTMLDOMNode_destructor(&This->node);
1379 static const NodeImplVtbl HTMLElementImplVtbl = {
1381 HTMLElement_destructor
1384 static const tid_t HTMLElement_iface_tids[] = {
1391 static dispex_static_data_t HTMLElement_dispex = {
1393 DispHTMLUnknownElement_tid,
1395 HTMLElement_iface_tids
1398 void HTMLElement_Init(HTMLElement *This)
1400 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1402 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1404 HTMLElement2_Init(This);
1406 if(!This->node.dispex.data)
1407 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1410 HTMLElement *HTMLElement_Create(HTMLDocument *doc, nsIDOMNode *nsnode, BOOL use_generic)
1412 nsIDOMHTMLElement *nselem;
1413 HTMLElement *ret = NULL;
1414 nsAString class_name_str;
1415 const PRUnichar *class_name;
1418 static const WCHAR wszA[] = {'A',0};
1419 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1420 static const WCHAR wszIMG[] = {'I','M','G',0};
1421 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1422 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1423 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1424 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1425 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1426 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1428 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1429 if(NS_FAILED(nsres))
1432 nsAString_Init(&class_name_str, NULL);
1433 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1435 nsAString_GetData(&class_name_str, &class_name);
1437 if(!strcmpW(class_name, wszA))
1438 ret = HTMLAnchorElement_Create(nselem);
1439 else if(!strcmpW(class_name, wszBODY))
1440 ret = HTMLBodyElement_Create(nselem);
1441 else if(!strcmpW(class_name, wszIMG))
1442 ret = HTMLImgElement_Create(nselem);
1443 else if(!strcmpW(class_name, wszINPUT))
1444 ret = HTMLInputElement_Create(nselem);
1445 else if(!strcmpW(class_name, wszOPTION))
1446 ret = HTMLOptionElement_Create(nselem);
1447 else if(!strcmpW(class_name, wszSCRIPT))
1448 ret = HTMLScriptElement_Create(nselem);
1449 else if(!strcmpW(class_name, wszSELECT))
1450 ret = HTMLSelectElement_Create(nselem);
1451 else if(!strcmpW(class_name, wszTABLE))
1452 ret = HTMLTable_Create(nselem);
1453 else if(!strcmpW(class_name, wszTEXTAREA))
1454 ret = HTMLTextAreaElement_Create(nselem);
1455 else if(use_generic)
1456 ret = HTMLGenericElement_Create(nselem);
1459 ret = heap_alloc_zero(sizeof(HTMLElement));
1460 HTMLElement_Init(ret);
1461 ret->node.vtbl = &HTMLElementImplVtbl;
1464 TRACE("%s ret %p\n", debugstr_w(class_name), ret);
1466 nsAString_Finish(&class_name_str);
1468 ret->nselem = nselem;
1469 HTMLDOMNode_Init(doc, &ret->node, (nsIDOMNode*)nselem);
1476 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1479 HTMLElement **elems;
1483 } HTMLElementCollection;
1485 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1487 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1489 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1490 REFIID riid, void **ppv)
1492 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1496 if(IsEqualGUID(&IID_IUnknown, riid)) {
1497 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1498 *ppv = HTMLELEMCOL(This);
1499 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1500 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1501 *ppv = HTMLELEMCOL(This);
1502 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1503 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1504 *ppv = DISPATCHEX(&This->dispex);
1505 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1506 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1507 *ppv = HTMLELEMCOL(This);
1511 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1515 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1516 return E_NOINTERFACE;
1519 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1521 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1522 LONG ref = InterlockedIncrement(&This->ref);
1524 TRACE("(%p) ref=%d\n", This, ref);
1529 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1531 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1532 LONG ref = InterlockedDecrement(&This->ref);
1534 TRACE("(%p) ref=%d\n", This, ref);
1537 IUnknown_Release(This->ref_unk);
1538 heap_free(This->elems);
1545 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1548 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1549 FIXME("(%p)->(%p)\n", This, pctinfo);
1553 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1554 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1556 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1557 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1561 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1562 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1564 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1565 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1570 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1571 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1572 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1574 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1575 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1576 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1580 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1583 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1584 FIXME("(%p)->(%p)\n", This, String);
1588 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1591 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1592 FIXME("(%p)->(%ld)\n", This, v);
1596 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1599 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1601 TRACE("(%p)->(%p)\n", This, p);
1607 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1610 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1611 FIXME("(%p)->(%p)\n", This, p);
1615 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1617 const PRUnichar *str;
1618 nsAString nsstr, nsname;
1622 static const PRUnichar nameW[] = {'n','a','m','e',0};
1627 nsAString_Init(&nsstr, NULL);
1628 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1629 nsAString_GetData(&nsstr, &str);
1630 if(!strcmpiW(str, name)) {
1631 nsAString_Finish(&nsstr);
1635 nsAString_Init(&nsname, nameW);
1636 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1637 nsAString_Finish(&nsname);
1638 if(NS_SUCCEEDED(nsres)) {
1639 nsAString_GetData(&nsstr, &str);
1640 ret = !strcmpiW(str, name);
1643 nsAString_Finish(&nsstr);
1647 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1648 VARIANT name, VARIANT index, IDispatch **pdisp)
1650 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1652 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1656 if(V_VT(&name) == VT_I4) {
1657 TRACE("name is VT_I4: %d\n", V_I4(&name));
1660 return E_INVALIDARG;
1661 if(V_I4(&name) >= This->len)
1664 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1665 IDispatch_AddRef(*pdisp);
1666 TRACE("Returning pdisp=%p\n", pdisp);
1670 if(V_VT(&name) == VT_BSTR) {
1673 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1675 if(V_VT(&index) == VT_I4) {
1676 LONG idx = V_I4(&index);
1678 TRACE("index = %d\n", idx);
1681 return E_INVALIDARG;
1683 for(i=0; i<This->len; i++) {
1684 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1688 if(i != This->len) {
1689 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1690 IDispatch_AddRef(*pdisp);
1695 elem_vector buf = {NULL, 0, 8};
1697 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1699 for(i=0; i<This->len; i++) {
1700 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1701 elem_vector_add(&buf, This->elems[i]);
1705 elem_vector_normalize(&buf);
1706 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1709 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1710 IDispatch_AddRef(*pdisp);
1720 FIXME("unsupported arguments\n");
1721 return E_INVALIDARG;
1724 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1725 VARIANT tagName, IDispatch **pdisp)
1727 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1730 const PRUnichar *tag;
1731 elem_vector buf = {NULL, 0, 8};
1733 if(V_VT(&tagName) != VT_BSTR) {
1734 WARN("Invalid arg\n");
1735 return DISP_E_MEMBERNOTFOUND;
1738 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1740 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1742 nsAString_Init(&tag_str, NULL);
1744 for(i=0; i<This->len; i++) {
1745 if(!This->elems[i]->nselem)
1748 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1749 nsAString_GetData(&tag_str, &tag);
1751 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1752 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1753 elem_vector_add(&buf, This->elems[i]);
1756 nsAString_Finish(&tag_str);
1757 elem_vector_normalize(&buf);
1759 TRACE("fount %d tags\n", buf.len);
1761 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1765 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1767 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1769 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1773 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1774 idx = idx*10 + (*ptr-'0');
1776 if(*ptr || idx >= This->len)
1777 return DISP_E_UNKNOWNNAME;
1779 *dispid = DISPID_ELEMCOL_0 + idx;
1780 TRACE("ret %x\n", *dispid);
1784 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1785 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1787 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1790 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1792 idx = id - DISPID_ELEMCOL_0;
1793 if(idx >= This->len)
1794 return DISP_E_UNKNOWNNAME;
1797 case INVOKE_PROPERTYGET:
1798 V_VT(res) = VT_DISPATCH;
1799 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1800 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1803 FIXME("unimplemented flags %x\n", flags);
1812 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1813 HTMLElementCollection_QueryInterface,
1814 HTMLElementCollection_AddRef,
1815 HTMLElementCollection_Release,
1816 HTMLElementCollection_GetTypeInfoCount,
1817 HTMLElementCollection_GetTypeInfo,
1818 HTMLElementCollection_GetIDsOfNames,
1819 HTMLElementCollection_Invoke,
1820 HTMLElementCollection_toString,
1821 HTMLElementCollection_put_length,
1822 HTMLElementCollection_get_length,
1823 HTMLElementCollection_get__newEnum,
1824 HTMLElementCollection_item,
1825 HTMLElementCollection_tags
1828 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1829 HTMLElementCollection_get_dispid,
1830 HTMLElementCollection_invoke
1833 static const tid_t HTMLElementCollection_iface_tids[] = {
1834 IHTMLElementCollection_tid,
1837 static dispex_static_data_t HTMLElementCollection_dispex = {
1838 &HTMLElementColection_dispex_vtbl,
1839 DispHTMLElementCollection_tid,
1841 HTMLElementCollection_iface_tids
1844 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1846 elem_vector buf = {NULL, 0, 8};
1848 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1850 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1851 create_all_list(node->doc, node, &buf);
1852 elem_vector_normalize(&buf);
1854 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1857 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1858 HTMLElement **elems, DWORD len)
1860 HTMLElementCollection *ret = heap_alloc_zero(sizeof(HTMLElementCollection));
1862 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1867 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1869 IUnknown_AddRef(ref_unk);
1870 ret->ref_unk = ref_unk;
1872 TRACE("ret=%p len=%d\n", ret, len);
1874 return HTMLELEMCOL(ret);