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);
385 FIXME("(%p)->(%p)\n", This, p);
389 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
391 HTMLElement *This = HTMLELEM_THIS(iface);
392 nsIDOMElementCSSInlineStyle *nselemstyle;
393 nsIDOMCSSStyleDeclaration *nsstyle;
396 TRACE("(%p)->(%p)\n", This, p);
399 FIXME("NULL nselem\n");
403 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
404 (void**)&nselemstyle);
405 if(NS_FAILED(nsres)) {
406 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
410 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
411 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
412 if(NS_FAILED(nsres)) {
413 ERR("GetStyle failed: %08x\n", nsres);
417 /* FIXME: Store style instead of creating a new instance in each call */
418 *p = HTMLStyle_Create(nsstyle);
420 nsIDOMCSSStyleDeclaration_Release(nsstyle);
424 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
426 HTMLElement *This = HTMLELEM_THIS(iface);
427 FIXME("(%p)->()\n", This);
431 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
433 HTMLElement *This = HTMLELEM_THIS(iface);
434 FIXME("(%p)->(%p)\n", This, p);
438 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
440 HTMLElement *This = HTMLELEM_THIS(iface);
442 TRACE("(%p)->()\n", This);
444 return set_node_event(&This->node, EVENTID_CLICK, &v);
447 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
449 HTMLElement *This = HTMLELEM_THIS(iface);
450 FIXME("(%p)->(%p)\n", This, p);
454 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
456 HTMLElement *This = HTMLELEM_THIS(iface);
457 FIXME("(%p)->()\n", This);
461 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
463 HTMLElement *This = HTMLELEM_THIS(iface);
464 FIXME("(%p)->(%p)\n", This, p);
468 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
470 HTMLElement *This = HTMLELEM_THIS(iface);
471 FIXME("(%p)->()\n", This);
475 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
477 HTMLElement *This = HTMLELEM_THIS(iface);
478 FIXME("(%p)->(%p)\n", This, p);
482 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
484 HTMLElement *This = HTMLELEM_THIS(iface);
486 TRACE("(%p)->()\n", This);
488 return set_node_event(&This->node, EVENTID_KEYUP, &v);
491 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
493 HTMLElement *This = HTMLELEM_THIS(iface);
494 FIXME("(%p)->(%p)\n", This, p);
498 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
500 HTMLElement *This = HTMLELEM_THIS(iface);
501 FIXME("(%p)->()\n", This);
505 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
507 HTMLElement *This = HTMLELEM_THIS(iface);
508 FIXME("(%p)->(%p)\n", This, p);
512 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
514 HTMLElement *This = HTMLELEM_THIS(iface);
515 FIXME("(%p)->()\n", This);
519 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
521 HTMLElement *This = HTMLELEM_THIS(iface);
522 FIXME("(%p)->(%p)\n", This, p);
526 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
528 HTMLElement *This = HTMLELEM_THIS(iface);
529 FIXME("(%p)->()\n", This);
533 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
535 HTMLElement *This = HTMLELEM_THIS(iface);
536 FIXME("(%p)->(%p)\n", This, p);
540 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
542 HTMLElement *This = HTMLELEM_THIS(iface);
543 FIXME("(%p)->()\n", This);
547 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
549 HTMLElement *This = HTMLELEM_THIS(iface);
550 FIXME("(%p)->(%p)\n", This, p);
554 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
556 HTMLElement *This = HTMLELEM_THIS(iface);
557 FIXME("(%p)->()\n", This);
561 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
563 HTMLElement *This = HTMLELEM_THIS(iface);
564 FIXME("(%p)->(%p)\n", This, p);
568 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
570 HTMLElement *This = HTMLELEM_THIS(iface);
571 FIXME("(%p)->()\n", This);
575 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
577 HTMLElement *This = HTMLELEM_THIS(iface);
578 FIXME("(%p)->(%p)\n", This, p);
582 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
584 HTMLElement *This = HTMLELEM_THIS(iface);
585 FIXME("(%p)->(%p)\n", This, p);
589 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
591 HTMLElement *This = HTMLELEM_THIS(iface);
595 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
597 nsAString_Init(&title_str, v);
598 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
599 nsAString_Finish(&title_str);
601 ERR("SetTitle failed: %08x\n", nsres);
606 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
608 HTMLElement *This = HTMLELEM_THIS(iface);
612 TRACE("(%p)->(%p)\n", This, p);
614 nsAString_Init(&title_str, NULL);
615 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
616 if(NS_SUCCEEDED(nsres)) {
617 const PRUnichar *title;
619 nsAString_GetData(&title_str, &title);
620 *p = *title ? SysAllocString(title) : NULL;
622 ERR("GetTitle failed: %08x\n", nsres);
629 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
631 HTMLElement *This = HTMLELEM_THIS(iface);
632 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
636 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
638 HTMLElement *This = HTMLELEM_THIS(iface);
639 FIXME("(%p)->(%p)\n", This, p);
643 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
645 HTMLElement *This = HTMLELEM_THIS(iface);
646 FIXME("(%p)->()\n", This);
650 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
652 HTMLElement *This = HTMLELEM_THIS(iface);
653 FIXME("(%p)->(%p)\n", This, p);
657 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
659 HTMLElement *This = HTMLELEM_THIS(iface);
660 FIXME("(%p)->()\n", This);
664 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
665 VARIANT_BOOL *pfResult)
667 HTMLElement *This = HTMLELEM_THIS(iface);
668 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
672 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
674 HTMLElement *This = HTMLELEM_THIS(iface);
675 FIXME("(%p)->(%p)\n", This, p);
679 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
681 HTMLElement *This = HTMLELEM_THIS(iface);
682 FIXME("(%p)->(%p)\n", This, p);
686 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
688 HTMLElement *This = HTMLELEM_THIS(iface);
689 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
693 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
695 HTMLElement *This = HTMLELEM_THIS(iface);
696 FIXME("(%p)->(%p)\n", This, p);
700 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
702 HTMLElement *This = HTMLELEM_THIS(iface);
703 FIXME("(%p)->(%p)\n", This, p);
707 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
709 HTMLElement *This = HTMLELEM_THIS(iface);
710 nsIDOMNSHTMLElement *nselem;
714 TRACE("(%p)->(%p)\n", This, p);
716 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
717 if(NS_FAILED(nsres)) {
718 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
722 nsres = nsIDOMNSHTMLElement_GetOffsetTop(nselem, &top);
723 nsIDOMNSHTMLElement_Release(nselem);
724 if(NS_FAILED(nsres)) {
725 ERR("GetOffsetTop failed: %08x\n", nsres);
733 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
735 HTMLElement *This = HTMLELEM_THIS(iface);
736 FIXME("(%p)->(%p)\n", This, p);
740 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
742 HTMLElement *This = HTMLELEM_THIS(iface);
743 nsIDOMNSHTMLElement *nselem;
747 TRACE("(%p)->(%p)\n", This, p);
749 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
750 if(NS_FAILED(nsres)) {
751 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
755 nsres = nsIDOMNSHTMLElement_GetOffsetHeight(nselem, &offset);
756 nsIDOMNSHTMLElement_Release(nselem);
757 if(NS_FAILED(nsres)) {
758 ERR("GetOffsetHeight failed: %08x\n", nsres);
766 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
768 HTMLElement *This = HTMLELEM_THIS(iface);
769 FIXME("(%p)->(%p)\n", This, p);
773 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
775 HTMLElement *This = HTMLELEM_THIS(iface);
776 nsIDOMNSHTMLElement *nselem;
780 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
783 FIXME("NULL nselem\n");
787 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
788 if(NS_FAILED(nsres)) {
789 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
793 nsAString_Init(&html_str, v);
794 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
795 nsAString_Finish(&html_str);
797 if(NS_FAILED(nsres)) {
798 FIXME("SetInnerHtml failed %08x\n", nsres);
805 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
807 HTMLElement *This = HTMLELEM_THIS(iface);
808 FIXME("(%p)->(%p)\n", This, p);
812 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
814 HTMLElement *This = HTMLELEM_THIS(iface);
815 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
819 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
821 HTMLElement *This = HTMLELEM_THIS(iface);
822 FIXME("(%p)->(%p)\n", This, p);
826 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
828 HTMLElement *This = HTMLELEM_THIS(iface);
829 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
833 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
835 HTMLElement *This = HTMLELEM_THIS(iface);
836 FIXME("(%p)->(%p)\n", This, p);
840 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
842 HTMLElement *This = HTMLELEM_THIS(iface);
843 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
847 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
849 HTMLElement *This = HTMLELEM_THIS(iface);
850 FIXME("(%p)->(%p)\n", This, p);
854 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
856 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
857 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
858 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
859 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
863 FIXME("NULL nselem\n");
867 if (!strcmpiW(where, wszBeforeBegin))
871 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
872 if (!parent) return E_INVALIDARG;
873 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
874 (nsIDOMNode *)This->nselem, &unused);
875 if (unused) nsIDOMNode_Release(unused);
876 nsIDOMNode_Release(parent);
878 else if (!strcmpiW(where, wszAfterBegin))
881 nsIDOMNode *first_child;
882 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
883 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
884 if (unused) nsIDOMNode_Release(unused);
885 if (first_child) nsIDOMNode_Release(first_child);
887 else if (!strcmpiW(where, wszBeforeEnd))
890 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
891 if (unused) nsIDOMNode_Release(unused);
893 else if (!strcmpiW(where, wszAfterEnd))
896 nsIDOMNode *next_sibling;
898 nsIDOMNode_GetParentNode(This->nselem, &parent);
899 if (!parent) return E_INVALIDARG;
901 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
904 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
905 nsIDOMNode_Release(next_sibling);
908 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
909 nsIDOMNode_Release(parent);
910 if (unused) nsIDOMNode_Release(unused);
914 ERR("invalid where: %s\n", debugstr_w(where));
918 if (NS_FAILED(nsres))
924 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
927 HTMLElement *This = HTMLELEM_THIS(iface);
929 nsIDOMDocument *nsdoc;
930 nsIDOMDocumentRange *nsdocrange;
932 nsIDOMNSRange *nsrange;
937 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
939 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
942 ERR("GetDocument failed: %08x\n", nsres);
946 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
947 nsIDOMDocument_Release(nsdoc);
950 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
953 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
954 nsIDOMDocumentRange_Release(nsdocrange);
957 ERR("CreateRange failed: %08x\n", nsres);
961 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
963 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
964 nsIDOMRange_Release(range);
967 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
971 nsAString_Init(&ns_html, html);
973 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
974 nsIDOMNSRange_Release(nsrange);
975 nsAString_Finish(&ns_html);
977 if(NS_FAILED(nsres) || !nsnode)
979 ERR("CreateTextNode failed: %08x\n", nsres);
983 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
984 nsIDOMNode_Release(nsnode);
989 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
992 HTMLElement *This = HTMLELEM_THIS(iface);
994 nsIDOMDocument *nsdoc;
999 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1001 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
1002 if(NS_FAILED(nsres) || !nsdoc)
1004 ERR("GetDocument failed: %08x\n", nsres);
1008 nsAString_Init(&ns_text, text);
1010 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1011 nsIDOMDocument_Release(nsdoc);
1012 nsAString_Finish(&ns_text);
1014 if(NS_FAILED(nsres) || !nsnode)
1016 ERR("CreateTextNode failed: %08x\n", nsres);
1020 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1021 nsIDOMNode_Release(nsnode);
1026 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1028 HTMLElement *This = HTMLELEM_THIS(iface);
1029 FIXME("(%p)->(%p)\n", This, p);
1033 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1035 HTMLElement *This = HTMLELEM_THIS(iface);
1036 FIXME("(%p)->(%p)\n", This, p);
1040 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1042 HTMLElement *This = HTMLELEM_THIS(iface);
1043 FIXME("(%p)\n", This);
1047 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1048 IHTMLFiltersCollection **p)
1050 HTMLElement *This = HTMLELEM_THIS(iface);
1051 FIXME("(%p)->(%p)\n", This, p);
1055 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1057 HTMLElement *This = HTMLELEM_THIS(iface);
1058 FIXME("(%p)->()\n", This);
1062 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1064 HTMLElement *This = HTMLELEM_THIS(iface);
1065 FIXME("(%p)->(%p)\n", This, p);
1069 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1071 HTMLElement *This = HTMLELEM_THIS(iface);
1072 FIXME("(%p)->(%p)\n", This, String);
1076 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1078 HTMLElement *This = HTMLELEM_THIS(iface);
1079 FIXME("(%p)->()\n", This);
1083 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1085 HTMLElement *This = HTMLELEM_THIS(iface);
1086 FIXME("(%p)->(%p)\n", This, p);
1090 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1092 HTMLElement *This = HTMLELEM_THIS(iface);
1093 FIXME("(%p)->()\n", This);
1097 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1099 HTMLElement *This = HTMLELEM_THIS(iface);
1100 FIXME("(%p)->(%p)\n", This, p);
1104 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1106 HTMLElement *This = HTMLELEM_THIS(iface);
1107 FIXME("(%p)->()\n", This);
1111 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1113 HTMLElement *This = HTMLELEM_THIS(iface);
1114 FIXME("(%p)->(%p)\n", This, p);
1118 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1120 HTMLElement *This = HTMLELEM_THIS(iface);
1121 FIXME("(%p)->()\n", This);
1125 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1127 HTMLElement *This = HTMLELEM_THIS(iface);
1128 FIXME("(%p)->(%p)\n", This, p);
1132 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1134 HTMLElement *This = HTMLELEM_THIS(iface);
1135 FIXME("(%p)->()\n", This);
1139 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1141 HTMLElement *This = HTMLELEM_THIS(iface);
1142 FIXME("(%p)->(%p)\n", This, p);
1146 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1148 HTMLElement *This = HTMLELEM_THIS(iface);
1149 FIXME("(%p)->()\n", This);
1153 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1155 HTMLElement *This = HTMLELEM_THIS(iface);
1156 FIXME("(%p)->(%p)\n", This, p);
1160 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1162 HTMLElement *This = HTMLELEM_THIS(iface);
1163 FIXME("(%p)->()\n", This);
1167 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1169 HTMLElement *This = HTMLELEM_THIS(iface);
1170 FIXME("(%p)->(%p)\n", This, p);
1174 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1176 HTMLElement *This = HTMLELEM_THIS(iface);
1177 FIXME("(%p)->()\n", This);
1181 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1183 HTMLElement *This = HTMLELEM_THIS(iface);
1184 FIXME("(%p)->(%p)\n", This, p);
1188 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1190 HTMLElement *This = HTMLELEM_THIS(iface);
1191 FIXME("(%p)->()\n", This);
1195 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1197 HTMLElement *This = HTMLELEM_THIS(iface);
1198 FIXME("(%p)->(%p)\n", This, p);
1202 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1204 nsIDOMNodeList *nsnode_list;
1206 PRUint32 list_len = 0, i;
1209 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1210 if(NS_FAILED(nsres)) {
1211 ERR("GetChildNodes failed: %08x\n", nsres);
1215 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1219 buf->size = list_len;
1220 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1222 for(i=0; i<list_len; i++) {
1223 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1224 if(NS_FAILED(nsres)) {
1225 ERR("Item failed: %08x\n", nsres);
1229 if(is_elem_node(iter))
1230 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1234 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1236 HTMLElement *This = HTMLELEM_THIS(iface);
1237 elem_vector buf = {NULL, 0, 0};
1239 TRACE("(%p)->(%p)\n", This, p);
1241 create_child_list(This->node.doc, This, &buf);
1243 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1247 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1249 nsIDOMNodeList *nsnode_list;
1251 PRUint32 list_len = 0, i;
1254 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1255 if(NS_FAILED(nsres)) {
1256 ERR("GetChildNodes failed: %08x\n", nsres);
1260 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1264 for(i=0; i<list_len; i++) {
1265 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1266 if(NS_FAILED(nsres)) {
1267 ERR("Item failed: %08x\n", nsres);
1271 if(is_elem_node(iter)) {
1272 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1274 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1275 create_all_list(doc, node, buf);
1280 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1282 HTMLElement *This = HTMLELEM_THIS(iface);
1283 elem_vector buf = {NULL, 0, 8};
1285 TRACE("(%p)->(%p)\n", This, p);
1287 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1289 create_all_list(This->node.doc, &This->node, &buf);
1290 elem_vector_normalize(&buf);
1292 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1296 #undef HTMLELEM_THIS
1298 static const IHTMLElementVtbl HTMLElementVtbl = {
1299 HTMLElement_QueryInterface,
1301 HTMLElement_Release,
1302 HTMLElement_GetTypeInfoCount,
1303 HTMLElement_GetTypeInfo,
1304 HTMLElement_GetIDsOfNames,
1306 HTMLElement_setAttribute,
1307 HTMLElement_getAttribute,
1308 HTMLElement_removeAttribute,
1309 HTMLElement_put_className,
1310 HTMLElement_get_className,
1313 HTMLElement_get_tagName,
1314 HTMLElement_get_parentElement,
1315 HTMLElement_get_style,
1316 HTMLElement_put_onhelp,
1317 HTMLElement_get_onhelp,
1318 HTMLElement_put_onclick,
1319 HTMLElement_get_onclick,
1320 HTMLElement_put_ondblclick,
1321 HTMLElement_get_ondblclick,
1322 HTMLElement_put_onkeydown,
1323 HTMLElement_get_onkeydown,
1324 HTMLElement_put_onkeyup,
1325 HTMLElement_get_onkeyup,
1326 HTMLElement_put_onkeypress,
1327 HTMLElement_get_onkeypress,
1328 HTMLElement_put_onmouseout,
1329 HTMLElement_get_onmouseout,
1330 HTMLElement_put_onmouseover,
1331 HTMLElement_get_onmouseover,
1332 HTMLElement_put_onmousemove,
1333 HTMLElement_get_onmousemove,
1334 HTMLElement_put_onmousedown,
1335 HTMLElement_get_onmousedown,
1336 HTMLElement_put_onmouseup,
1337 HTMLElement_get_onmouseup,
1338 HTMLElement_get_document,
1339 HTMLElement_put_title,
1340 HTMLElement_get_title,
1341 HTMLElement_put_language,
1342 HTMLElement_get_language,
1343 HTMLElement_put_onselectstart,
1344 HTMLElement_get_onselectstart,
1345 HTMLElement_scrollIntoView,
1346 HTMLElement_contains,
1347 HTMLElement_get_sourceIndex,
1348 HTMLElement_get_recordNumber,
1349 HTMLElement_put_lang,
1350 HTMLElement_get_lang,
1351 HTMLElement_get_offsetLeft,
1352 HTMLElement_get_offsetTop,
1353 HTMLElement_get_offsetWidth,
1354 HTMLElement_get_offsetHeight,
1355 HTMLElement_get_offsetParent,
1356 HTMLElement_put_innerHTML,
1357 HTMLElement_get_innerHTML,
1358 HTMLElement_put_innerText,
1359 HTMLElement_get_innerText,
1360 HTMLElement_put_outerHTML,
1361 HTMLElement_get_outerHTML,
1362 HTMLElement_put_outerText,
1363 HTMLElement_get_outerText,
1364 HTMLElement_insertAdjacentHTML,
1365 HTMLElement_insertAdjacentText,
1366 HTMLElement_get_parentTextEdit,
1367 HTMLElement_get_isTextEdit,
1369 HTMLElement_get_filters,
1370 HTMLElement_put_ondragstart,
1371 HTMLElement_get_ondragstart,
1372 HTMLElement_toString,
1373 HTMLElement_put_onbeforeupdate,
1374 HTMLElement_get_onbeforeupdate,
1375 HTMLElement_put_onafterupdate,
1376 HTMLElement_get_onafterupdate,
1377 HTMLElement_put_onerrorupdate,
1378 HTMLElement_get_onerrorupdate,
1379 HTMLElement_put_onrowexit,
1380 HTMLElement_get_onrowexit,
1381 HTMLElement_put_onrowenter,
1382 HTMLElement_get_onrowenter,
1383 HTMLElement_put_ondatasetchanged,
1384 HTMLElement_get_ondatasetchanged,
1385 HTMLElement_put_ondataavailable,
1386 HTMLElement_get_ondataavailable,
1387 HTMLElement_put_ondatasetcomplete,
1388 HTMLElement_get_ondatasetcomplete,
1389 HTMLElement_put_onfilterchange,
1390 HTMLElement_get_onfilterchange,
1391 HTMLElement_get_children,
1395 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1397 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1401 if(IsEqualGUID(&IID_IUnknown, riid)) {
1402 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1403 *ppv = HTMLELEM(This);
1404 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1405 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1406 *ppv = HTMLELEM(This);
1407 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1408 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1409 *ppv = HTMLELEM(This);
1410 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1411 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1412 *ppv = HTMLELEM2(This);
1413 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1414 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1415 *ppv = CONPTCONT(&This->cp_container);
1419 IHTMLElement_AddRef(HTMLELEM(This));
1423 return HTMLDOMNode_QI(&This->node, riid, ppv);
1426 void HTMLElement_destructor(HTMLDOMNode *iface)
1428 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1430 ConnectionPointContainer_Destroy(&This->cp_container);
1433 nsIDOMHTMLElement_Release(This->nselem);
1435 HTMLDOMNode_destructor(&This->node);
1438 static const NodeImplVtbl HTMLElementImplVtbl = {
1440 HTMLElement_destructor
1443 static const tid_t HTMLElement_iface_tids[] = {
1451 static dispex_static_data_t HTMLElement_dispex = {
1453 DispHTMLUnknownElement_tid,
1455 HTMLElement_iface_tids
1458 void HTMLElement_Init(HTMLElement *This)
1460 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1462 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1464 HTMLElement2_Init(This);
1466 if(!This->node.dispex.data)
1467 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1470 HTMLElement *HTMLElement_Create(HTMLDocument *doc, nsIDOMNode *nsnode, BOOL use_generic)
1472 nsIDOMHTMLElement *nselem;
1473 HTMLElement *ret = NULL;
1474 nsAString class_name_str;
1475 const PRUnichar *class_name;
1478 static const WCHAR wszA[] = {'A',0};
1479 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1480 static const WCHAR wszIMG[] = {'I','M','G',0};
1481 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1482 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1483 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1484 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1485 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1486 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1488 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1489 if(NS_FAILED(nsres))
1492 nsAString_Init(&class_name_str, NULL);
1493 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1495 nsAString_GetData(&class_name_str, &class_name);
1497 if(!strcmpW(class_name, wszA))
1498 ret = HTMLAnchorElement_Create(nselem);
1499 else if(!strcmpW(class_name, wszBODY))
1500 ret = HTMLBodyElement_Create(nselem);
1501 else if(!strcmpW(class_name, wszIMG))
1502 ret = HTMLImgElement_Create(nselem);
1503 else if(!strcmpW(class_name, wszINPUT))
1504 ret = HTMLInputElement_Create(nselem);
1505 else if(!strcmpW(class_name, wszOPTION))
1506 ret = HTMLOptionElement_Create(nselem);
1507 else if(!strcmpW(class_name, wszSCRIPT))
1508 ret = HTMLScriptElement_Create(nselem);
1509 else if(!strcmpW(class_name, wszSELECT))
1510 ret = HTMLSelectElement_Create(nselem);
1511 else if(!strcmpW(class_name, wszTABLE))
1512 ret = HTMLTable_Create(nselem);
1513 else if(!strcmpW(class_name, wszTEXTAREA))
1514 ret = HTMLTextAreaElement_Create(nselem);
1515 else if(use_generic)
1516 ret = HTMLGenericElement_Create(nselem);
1519 ret = heap_alloc_zero(sizeof(HTMLElement));
1520 HTMLElement_Init(ret);
1521 ret->node.vtbl = &HTMLElementImplVtbl;
1524 TRACE("%s ret %p\n", debugstr_w(class_name), ret);
1526 nsAString_Finish(&class_name_str);
1528 ret->nselem = nselem;
1529 HTMLDOMNode_Init(doc, &ret->node, (nsIDOMNode*)nselem);
1536 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1539 HTMLElement **elems;
1543 } HTMLElementCollection;
1545 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1547 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1549 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1550 REFIID riid, void **ppv)
1552 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1556 if(IsEqualGUID(&IID_IUnknown, riid)) {
1557 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1558 *ppv = HTMLELEMCOL(This);
1559 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1560 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1561 *ppv = HTMLELEMCOL(This);
1562 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1563 return *ppv ? S_OK : E_NOINTERFACE;
1567 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1571 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1572 return E_NOINTERFACE;
1575 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1577 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1578 LONG ref = InterlockedIncrement(&This->ref);
1580 TRACE("(%p) ref=%d\n", This, ref);
1585 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1587 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1588 LONG ref = InterlockedDecrement(&This->ref);
1590 TRACE("(%p) ref=%d\n", This, ref);
1593 IUnknown_Release(This->ref_unk);
1594 heap_free(This->elems);
1601 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1604 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1605 FIXME("(%p)->(%p)\n", This, pctinfo);
1609 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1610 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1612 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1613 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1617 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1618 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1620 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1621 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1626 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1627 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1628 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1630 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1631 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1632 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1636 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1639 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1640 FIXME("(%p)->(%p)\n", This, String);
1644 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1647 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1648 FIXME("(%p)->(%ld)\n", This, v);
1652 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1655 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1657 TRACE("(%p)->(%p)\n", This, p);
1663 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1666 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1667 FIXME("(%p)->(%p)\n", This, p);
1671 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1673 const PRUnichar *str;
1674 nsAString nsstr, nsname;
1678 static const PRUnichar nameW[] = {'n','a','m','e',0};
1683 nsAString_Init(&nsstr, NULL);
1684 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1685 nsAString_GetData(&nsstr, &str);
1686 if(!strcmpiW(str, name)) {
1687 nsAString_Finish(&nsstr);
1691 nsAString_Init(&nsname, nameW);
1692 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1693 nsAString_Finish(&nsname);
1694 if(NS_SUCCEEDED(nsres)) {
1695 nsAString_GetData(&nsstr, &str);
1696 ret = !strcmpiW(str, name);
1699 nsAString_Finish(&nsstr);
1703 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1704 VARIANT name, VARIANT index, IDispatch **pdisp)
1706 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1708 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1712 if(V_VT(&name) == VT_I4) {
1713 TRACE("name is VT_I4: %d\n", V_I4(&name));
1716 return E_INVALIDARG;
1717 if(V_I4(&name) >= This->len)
1720 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1721 IDispatch_AddRef(*pdisp);
1722 TRACE("Returning pdisp=%p\n", pdisp);
1726 if(V_VT(&name) == VT_BSTR) {
1729 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1731 if(V_VT(&index) == VT_I4) {
1732 LONG idx = V_I4(&index);
1734 TRACE("index = %d\n", idx);
1737 return E_INVALIDARG;
1739 for(i=0; i<This->len; i++) {
1740 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1744 if(i != This->len) {
1745 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1746 IDispatch_AddRef(*pdisp);
1751 elem_vector buf = {NULL, 0, 8};
1753 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1755 for(i=0; i<This->len; i++) {
1756 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1757 elem_vector_add(&buf, This->elems[i]);
1761 elem_vector_normalize(&buf);
1762 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1765 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1766 IDispatch_AddRef(*pdisp);
1776 FIXME("unsupported arguments\n");
1777 return E_INVALIDARG;
1780 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1781 VARIANT tagName, IDispatch **pdisp)
1783 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1786 const PRUnichar *tag;
1787 elem_vector buf = {NULL, 0, 8};
1789 if(V_VT(&tagName) != VT_BSTR) {
1790 WARN("Invalid arg\n");
1791 return DISP_E_MEMBERNOTFOUND;
1794 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1796 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1798 nsAString_Init(&tag_str, NULL);
1800 for(i=0; i<This->len; i++) {
1801 if(!This->elems[i]->nselem)
1804 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1805 nsAString_GetData(&tag_str, &tag);
1807 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1808 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1809 elem_vector_add(&buf, This->elems[i]);
1812 nsAString_Finish(&tag_str);
1813 elem_vector_normalize(&buf);
1815 TRACE("fount %d tags\n", buf.len);
1817 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1821 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1823 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1825 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1829 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1830 idx = idx*10 + (*ptr-'0');
1832 if(*ptr || idx >= This->len)
1833 return DISP_E_UNKNOWNNAME;
1835 *dispid = DISPID_ELEMCOL_0 + idx;
1836 TRACE("ret %x\n", *dispid);
1840 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1841 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1843 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1846 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1848 idx = id - DISPID_ELEMCOL_0;
1849 if(idx >= This->len)
1850 return DISP_E_UNKNOWNNAME;
1853 case INVOKE_PROPERTYGET:
1854 V_VT(res) = VT_DISPATCH;
1855 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1856 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1859 FIXME("unimplemented flags %x\n", flags);
1868 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1869 HTMLElementCollection_QueryInterface,
1870 HTMLElementCollection_AddRef,
1871 HTMLElementCollection_Release,
1872 HTMLElementCollection_GetTypeInfoCount,
1873 HTMLElementCollection_GetTypeInfo,
1874 HTMLElementCollection_GetIDsOfNames,
1875 HTMLElementCollection_Invoke,
1876 HTMLElementCollection_toString,
1877 HTMLElementCollection_put_length,
1878 HTMLElementCollection_get_length,
1879 HTMLElementCollection_get__newEnum,
1880 HTMLElementCollection_item,
1881 HTMLElementCollection_tags
1884 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1885 HTMLElementCollection_get_dispid,
1886 HTMLElementCollection_invoke
1889 static const tid_t HTMLElementCollection_iface_tids[] = {
1890 IHTMLElementCollection_tid,
1893 static dispex_static_data_t HTMLElementCollection_dispex = {
1894 &HTMLElementColection_dispex_vtbl,
1895 DispHTMLElementCollection_tid,
1897 HTMLElementCollection_iface_tids
1900 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1902 elem_vector buf = {NULL, 0, 8};
1904 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1906 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1907 create_all_list(node->doc, node, &buf);
1908 elem_vector_normalize(&buf);
1910 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1913 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument *doc, IUnknown *unk, nsIDOMNodeList *nslist)
1915 PRUint32 length = 0, i;
1918 nsIDOMNodeList_GetLength(nslist, &length);
1920 buf.len = buf.size = length;
1924 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1926 for(i=0; i<length; i++) {
1927 nsIDOMNodeList_Item(nslist, i, &nsnode);
1928 buf.buf[i] = HTMLELEM_NODE_THIS(get_node(doc, nsnode, TRUE));
1929 nsIDOMNode_Release(nsnode);
1935 return HTMLElementCollection_Create(unk, buf.buf, buf.len);
1938 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1939 HTMLElement **elems, DWORD len)
1941 HTMLElementCollection *ret = heap_alloc_zero(sizeof(HTMLElementCollection));
1943 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1948 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1950 IUnknown_AddRef(ref_unk);
1951 ret->ref_unk = ref_unk;
1953 TRACE("ret=%p len=%d\n", ret, len);
1955 return HTMLELEMCOL(ret);