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");
200 V_VT(AttributeValue
) = VT_NULL
;
202 nsAString_Init(&attr_str
, strAttributeName
);
203 nsAString_Init(&value_str
, NULL
);
205 nsres
= nsIDOMHTMLElement_GetAttribute(This
->nselem
, &attr_str
, &value_str
);
206 nsAString_Finish(&attr_str
);
208 if(NS_SUCCEEDED(nsres
)) {
209 static const WCHAR wszSRC
[] = {'s','r','c',0};
210 nsAString_GetData(&value_str
, &value
);
211 if(!strcmpiW(strAttributeName
, wszSRC
))
216 hres
= IHTMLDocument2_get_URL(HTMLDOC(This
->node
.doc
), &bstrBaseUrl
);
217 if(SUCCEEDED(hres
)) {
218 hres
= CoInternetCombineUrl(bstrBaseUrl
, value
,
219 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
220 buffer
, sizeof(buffer
)/sizeof(WCHAR
), &len
, 0);
221 SysFreeString(bstrBaseUrl
);
222 if(SUCCEEDED(hres
)) {
223 V_VT(AttributeValue
) = VT_BSTR
;
224 V_BSTR(AttributeValue
) = SysAllocString(buffer
);
225 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
229 V_VT(AttributeValue
) = VT_BSTR
;
230 V_BSTR(AttributeValue
) = SysAllocString(value
);
231 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
234 ERR("GetAttribute failed: %08x\n", nsres
);
238 nsAString_Finish(&value_str
);
243 static HRESULT WINAPI
HTMLElement_removeAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
244 LONG lFlags
, VARIANT_BOOL
*pfSuccess
)
246 HTMLElement
*This
= HTMLELEM_THIS(iface
);
247 FIXME("(%p)->()\n", This
);
251 static HRESULT WINAPI
HTMLElement_put_className(IHTMLElement
*iface
, BSTR v
)
253 HTMLElement
*This
= HTMLELEM_THIS(iface
);
254 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
258 static HRESULT WINAPI
HTMLElement_get_className(IHTMLElement
*iface
, BSTR
*p
)
260 HTMLElement
*This
= HTMLELEM_THIS(iface
);
265 TRACE("(%p)->(%p)\n", This
, p
);
268 FIXME("NULL nselem\n");
272 nsAString_Init(&class_str
, NULL
);
273 nsres
= nsIDOMHTMLElement_GetClassName(This
->nselem
, &class_str
);
275 if(NS_SUCCEEDED(nsres
)) {
276 const PRUnichar
*class;
277 nsAString_GetData(&class_str
, &class);
278 *p
= SysAllocString(class);
280 ERR("GetClassName failed: %08x\n", nsres
);
284 nsAString_Finish(&class_str
);
286 TRACE("className=%s\n", debugstr_w(*p
));
290 static HRESULT WINAPI
HTMLElement_put_id(IHTMLElement
*iface
, BSTR v
)
292 HTMLElement
*This
= HTMLELEM_THIS(iface
);
293 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
297 static HRESULT WINAPI
HTMLElement_get_id(IHTMLElement
*iface
, BSTR
*p
)
299 HTMLElement
*This
= HTMLELEM_THIS(iface
);
300 FIXME("(%p)->(%p)\n", This
, p
);
304 static HRESULT WINAPI
HTMLElement_get_tagName(IHTMLElement
*iface
, BSTR
*p
)
306 HTMLElement
*This
= HTMLELEM_THIS(iface
);
307 const PRUnichar
*tag
;
311 TRACE("(%p)->(%p)\n", This
, p
);
314 static const WCHAR comment_tagW
[] = {'!',0};
316 WARN("NULL nselem, assuming comment\n");
318 *p
= SysAllocString(comment_tagW
);
322 nsAString_Init(&tag_str
, NULL
);
323 nsres
= nsIDOMHTMLElement_GetTagName(This
->nselem
, &tag_str
);
324 if(NS_SUCCEEDED(nsres
)) {
325 nsAString_GetData(&tag_str
, &tag
);
326 *p
= SysAllocString(tag
);
328 ERR("GetTagName failed: %08x\n", nsres
);
331 nsAString_Finish(&tag_str
);
336 static HRESULT WINAPI
HTMLElement_get_parentElement(IHTMLElement
*iface
, IHTMLElement
**p
)
338 HTMLElement
*This
= HTMLELEM_THIS(iface
);
339 FIXME("(%p)->(%p)\n", This
, p
);
343 static HRESULT WINAPI
HTMLElement_get_style(IHTMLElement
*iface
, IHTMLStyle
**p
)
345 HTMLElement
*This
= HTMLELEM_THIS(iface
);
346 nsIDOMElementCSSInlineStyle
*nselemstyle
;
347 nsIDOMCSSStyleDeclaration
*nsstyle
;
350 TRACE("(%p)->(%p)\n", This
, p
);
353 FIXME("NULL nselem\n");
357 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMElementCSSInlineStyle
,
358 (void**)&nselemstyle
);
359 if(NS_FAILED(nsres
)) {
360 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres
);
364 nsres
= nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle
, &nsstyle
);
365 nsIDOMElementCSSInlineStyle_Release(nselemstyle
);
366 if(NS_FAILED(nsres
)) {
367 ERR("GetStyle failed: %08x\n", nsres
);
371 /* FIXME: Store style instead of creating a new instance in each call */
372 *p
= HTMLStyle_Create(nsstyle
);
374 nsIDOMCSSStyleDeclaration_Release(nsstyle
);
378 static HRESULT WINAPI
HTMLElement_put_onhelp(IHTMLElement
*iface
, VARIANT v
)
380 HTMLElement
*This
= HTMLELEM_THIS(iface
);
381 FIXME("(%p)->()\n", This
);
385 static HRESULT WINAPI
HTMLElement_get_onhelp(IHTMLElement
*iface
, VARIANT
*p
)
387 HTMLElement
*This
= HTMLELEM_THIS(iface
);
388 FIXME("(%p)->(%p)\n", This
, p
);
392 static HRESULT WINAPI
HTMLElement_put_onclick(IHTMLElement
*iface
, VARIANT v
)
394 HTMLElement
*This
= HTMLELEM_THIS(iface
);
395 FIXME("(%p)->()\n", This
);
399 static HRESULT WINAPI
HTMLElement_get_onclick(IHTMLElement
*iface
, VARIANT
*p
)
401 HTMLElement
*This
= HTMLELEM_THIS(iface
);
402 FIXME("(%p)->(%p)\n", This
, p
);
406 static HRESULT WINAPI
HTMLElement_put_ondblclick(IHTMLElement
*iface
, VARIANT v
)
408 HTMLElement
*This
= HTMLELEM_THIS(iface
);
409 FIXME("(%p)->()\n", This
);
413 static HRESULT WINAPI
HTMLElement_get_ondblclick(IHTMLElement
*iface
, VARIANT
*p
)
415 HTMLElement
*This
= HTMLELEM_THIS(iface
);
416 FIXME("(%p)->(%p)\n", This
, p
);
420 static HRESULT WINAPI
HTMLElement_put_onkeydown(IHTMLElement
*iface
, VARIANT v
)
422 HTMLElement
*This
= HTMLELEM_THIS(iface
);
423 FIXME("(%p)->()\n", This
);
427 static HRESULT WINAPI
HTMLElement_get_onkeydown(IHTMLElement
*iface
, VARIANT
*p
)
429 HTMLElement
*This
= HTMLELEM_THIS(iface
);
430 FIXME("(%p)->(%p)\n", This
, p
);
434 static HRESULT WINAPI
HTMLElement_put_onkeyup(IHTMLElement
*iface
, VARIANT v
)
436 HTMLElement
*This
= HTMLELEM_THIS(iface
);
437 FIXME("(%p)->()\n", This
);
441 static HRESULT WINAPI
HTMLElement_get_onkeyup(IHTMLElement
*iface
, VARIANT
*p
)
443 HTMLElement
*This
= HTMLELEM_THIS(iface
);
444 FIXME("(%p)->(%p)\n", This
, p
);
448 static HRESULT WINAPI
HTMLElement_put_onkeypress(IHTMLElement
*iface
, VARIANT v
)
450 HTMLElement
*This
= HTMLELEM_THIS(iface
);
451 FIXME("(%p)->()\n", This
);
455 static HRESULT WINAPI
HTMLElement_get_onkeypress(IHTMLElement
*iface
, VARIANT
*p
)
457 HTMLElement
*This
= HTMLELEM_THIS(iface
);
458 FIXME("(%p)->(%p)\n", This
, p
);
462 static HRESULT WINAPI
HTMLElement_put_onmouseout(IHTMLElement
*iface
, VARIANT v
)
464 HTMLElement
*This
= HTMLELEM_THIS(iface
);
465 FIXME("(%p)->()\n", This
);
469 static HRESULT WINAPI
HTMLElement_get_onmouseout(IHTMLElement
*iface
, VARIANT
*p
)
471 HTMLElement
*This
= HTMLELEM_THIS(iface
);
472 FIXME("(%p)->(%p)\n", This
, p
);
476 static HRESULT WINAPI
HTMLElement_put_onmouseover(IHTMLElement
*iface
, VARIANT v
)
478 HTMLElement
*This
= HTMLELEM_THIS(iface
);
479 FIXME("(%p)->()\n", This
);
483 static HRESULT WINAPI
HTMLElement_get_onmouseover(IHTMLElement
*iface
, VARIANT
*p
)
485 HTMLElement
*This
= HTMLELEM_THIS(iface
);
486 FIXME("(%p)->(%p)\n", This
, p
);
490 static HRESULT WINAPI
HTMLElement_put_onmousemove(IHTMLElement
*iface
, VARIANT v
)
492 HTMLElement
*This
= HTMLELEM_THIS(iface
);
493 FIXME("(%p)->()\n", This
);
497 static HRESULT WINAPI
HTMLElement_get_onmousemove(IHTMLElement
*iface
, VARIANT
*p
)
499 HTMLElement
*This
= HTMLELEM_THIS(iface
);
500 FIXME("(%p)->(%p)\n", This
, p
);
504 static HRESULT WINAPI
HTMLElement_put_onmousedown(IHTMLElement
*iface
, VARIANT v
)
506 HTMLElement
*This
= HTMLELEM_THIS(iface
);
507 FIXME("(%p)->()\n", This
);
511 static HRESULT WINAPI
HTMLElement_get_onmousedown(IHTMLElement
*iface
, VARIANT
*p
)
513 HTMLElement
*This
= HTMLELEM_THIS(iface
);
514 FIXME("(%p)->(%p)\n", This
, p
);
518 static HRESULT WINAPI
HTMLElement_put_onmouseup(IHTMLElement
*iface
, VARIANT v
)
520 HTMLElement
*This
= HTMLELEM_THIS(iface
);
521 FIXME("(%p)->()\n", This
);
525 static HRESULT WINAPI
HTMLElement_get_onmouseup(IHTMLElement
*iface
, VARIANT
*p
)
527 HTMLElement
*This
= HTMLELEM_THIS(iface
);
528 FIXME("(%p)->(%p)\n", This
, p
);
532 static HRESULT WINAPI
HTMLElement_get_document(IHTMLElement
*iface
, IDispatch
**p
)
534 HTMLElement
*This
= HTMLELEM_THIS(iface
);
535 FIXME("(%p)->(%p)\n", This
, p
);
539 static HRESULT WINAPI
HTMLElement_put_title(IHTMLElement
*iface
, BSTR v
)
541 HTMLElement
*This
= HTMLELEM_THIS(iface
);
542 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
546 static HRESULT WINAPI
HTMLElement_get_title(IHTMLElement
*iface
, BSTR
*p
)
548 HTMLElement
*This
= HTMLELEM_THIS(iface
);
549 FIXME("(%p)->(%p)\n", This
, p
);
553 static HRESULT WINAPI
HTMLElement_put_language(IHTMLElement
*iface
, BSTR v
)
555 HTMLElement
*This
= HTMLELEM_THIS(iface
);
556 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
560 static HRESULT WINAPI
HTMLElement_get_language(IHTMLElement
*iface
, BSTR
*p
)
562 HTMLElement
*This
= HTMLELEM_THIS(iface
);
563 FIXME("(%p)->(%p)\n", This
, p
);
567 static HRESULT WINAPI
HTMLElement_put_onselectstart(IHTMLElement
*iface
, VARIANT v
)
569 HTMLElement
*This
= HTMLELEM_THIS(iface
);
570 FIXME("(%p)->()\n", This
);
574 static HRESULT WINAPI
HTMLElement_get_onselectstart(IHTMLElement
*iface
, VARIANT
*p
)
576 HTMLElement
*This
= HTMLELEM_THIS(iface
);
577 FIXME("(%p)->(%p)\n", This
, p
);
581 static HRESULT WINAPI
HTMLElement_scrollIntoView(IHTMLElement
*iface
, VARIANT varargStart
)
583 HTMLElement
*This
= HTMLELEM_THIS(iface
);
584 FIXME("(%p)->()\n", This
);
588 static HRESULT WINAPI
HTMLElement_contains(IHTMLElement
*iface
, IHTMLElement
*pChild
,
589 VARIANT_BOOL
*pfResult
)
591 HTMLElement
*This
= HTMLELEM_THIS(iface
);
592 FIXME("(%p)->(%p %p)\n", This
, pChild
, pfResult
);
596 static HRESULT WINAPI
HTMLElement_get_sourceIndex(IHTMLElement
*iface
, long *p
)
598 HTMLElement
*This
= HTMLELEM_THIS(iface
);
599 FIXME("(%p)->(%p)\n", This
, p
);
603 static HRESULT WINAPI
HTMLElement_get_recordNumber(IHTMLElement
*iface
, VARIANT
*p
)
605 HTMLElement
*This
= HTMLELEM_THIS(iface
);
606 FIXME("(%p)->(%p)\n", This
, p
);
610 static HRESULT WINAPI
HTMLElement_put_lang(IHTMLElement
*iface
, BSTR v
)
612 HTMLElement
*This
= HTMLELEM_THIS(iface
);
613 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
617 static HRESULT WINAPI
HTMLElement_get_lang(IHTMLElement
*iface
, BSTR
*p
)
619 HTMLElement
*This
= HTMLELEM_THIS(iface
);
620 FIXME("(%p)->(%p)\n", This
, p
);
624 static HRESULT WINAPI
HTMLElement_get_offsetLeft(IHTMLElement
*iface
, long *p
)
626 HTMLElement
*This
= HTMLELEM_THIS(iface
);
627 FIXME("(%p)->(%p)\n", This
, p
);
631 static HRESULT WINAPI
HTMLElement_get_offsetTop(IHTMLElement
*iface
, long *p
)
633 HTMLElement
*This
= HTMLELEM_THIS(iface
);
634 FIXME("(%p)->(%p)\n", This
, p
);
638 static HRESULT WINAPI
HTMLElement_get_offsetWidth(IHTMLElement
*iface
, long *p
)
640 HTMLElement
*This
= HTMLELEM_THIS(iface
);
641 FIXME("(%p)->(%p)\n", This
, p
);
645 static HRESULT WINAPI
HTMLElement_get_offsetHeight(IHTMLElement
*iface
, long *p
)
647 HTMLElement
*This
= HTMLELEM_THIS(iface
);
648 FIXME("(%p)->(%p)\n", This
, p
);
652 static HRESULT WINAPI
HTMLElement_get_offsetParent(IHTMLElement
*iface
, IHTMLElement
**p
)
654 HTMLElement
*This
= HTMLELEM_THIS(iface
);
655 FIXME("(%p)->(%p)\n", This
, p
);
659 static HRESULT WINAPI
HTMLElement_put_innerHTML(IHTMLElement
*iface
, BSTR v
)
661 HTMLElement
*This
= HTMLELEM_THIS(iface
);
662 nsIDOMNSHTMLElement
*nselem
;
666 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
669 FIXME("NULL nselem\n");
673 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
674 if(NS_FAILED(nsres
)) {
675 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
679 nsAString_Init(&html_str
, v
);
680 nsres
= nsIDOMNSHTMLElement_SetInnerHTML(nselem
, &html_str
);
681 nsAString_Finish(&html_str
);
683 if(NS_FAILED(nsres
)) {
684 FIXME("SetInnerHtml failed %08x\n", nsres
);
691 static HRESULT WINAPI
HTMLElement_get_innerHTML(IHTMLElement
*iface
, BSTR
*p
)
693 HTMLElement
*This
= HTMLELEM_THIS(iface
);
694 FIXME("(%p)->(%p)\n", This
, p
);
698 static HRESULT WINAPI
HTMLElement_put_innerText(IHTMLElement
*iface
, BSTR v
)
700 HTMLElement
*This
= HTMLELEM_THIS(iface
);
701 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
705 static HRESULT WINAPI
HTMLElement_get_innerText(IHTMLElement
*iface
, BSTR
*p
)
707 HTMLElement
*This
= HTMLELEM_THIS(iface
);
708 FIXME("(%p)->(%p)\n", This
, p
);
712 static HRESULT WINAPI
HTMLElement_put_outerHTML(IHTMLElement
*iface
, BSTR v
)
714 HTMLElement
*This
= HTMLELEM_THIS(iface
);
715 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
719 static HRESULT WINAPI
HTMLElement_get_outerHTML(IHTMLElement
*iface
, BSTR
*p
)
721 HTMLElement
*This
= HTMLELEM_THIS(iface
);
722 FIXME("(%p)->(%p)\n", This
, p
);
726 static HRESULT WINAPI
HTMLElement_put_outerText(IHTMLElement
*iface
, BSTR v
)
728 HTMLElement
*This
= HTMLELEM_THIS(iface
);
729 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
733 static HRESULT WINAPI
HTMLElement_get_outerText(IHTMLElement
*iface
, BSTR
*p
)
735 HTMLElement
*This
= HTMLELEM_THIS(iface
);
736 FIXME("(%p)->(%p)\n", This
, p
);
740 static HRESULT
HTMLElement_InsertAdjacentNode(HTMLElement
*This
, BSTR where
, nsIDOMNode
*nsnode
)
742 static const WCHAR wszBeforeBegin
[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
743 static const WCHAR wszAfterBegin
[] = {'a','f','t','e','r','B','e','g','i','n',0};
744 static const WCHAR wszBeforeEnd
[] = {'b','e','f','o','r','e','E','n','d',0};
745 static const WCHAR wszAfterEnd
[] = {'a','f','t','e','r','E','n','d',0};
749 FIXME("NULL nselem\n");
753 if (!strcmpiW(where
, wszBeforeBegin
))
757 nsres
= nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
758 if (!parent
) return E_INVALIDARG
;
759 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
,
760 (nsIDOMNode
*)This
->nselem
, &unused
);
761 if (unused
) nsIDOMNode_Release(unused
);
762 nsIDOMNode_Release(parent
);
764 else if (!strcmpiW(where
, wszAfterBegin
))
767 nsIDOMNode
*first_child
;
768 nsIDOMNode_GetFirstChild(This
->nselem
, &first_child
);
769 nsres
= nsIDOMNode_InsertBefore(This
->nselem
, nsnode
, first_child
, &unused
);
770 if (unused
) nsIDOMNode_Release(unused
);
771 if (first_child
) nsIDOMNode_Release(first_child
);
773 else if (!strcmpiW(where
, wszBeforeEnd
))
776 nsres
= nsIDOMNode_AppendChild(This
->nselem
, nsnode
, &unused
);
777 if (unused
) nsIDOMNode_Release(unused
);
779 else if (!strcmpiW(where
, wszAfterEnd
))
782 nsIDOMNode
*next_sibling
;
784 nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
785 if (!parent
) return E_INVALIDARG
;
787 nsIDOMNode_GetNextSibling(This
->nselem
, &next_sibling
);
790 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
, next_sibling
, &unused
);
791 nsIDOMNode_Release(next_sibling
);
794 nsres
= nsIDOMNode_AppendChild(parent
, nsnode
, &unused
);
795 nsIDOMNode_Release(parent
);
796 if (unused
) nsIDOMNode_Release(unused
);
800 ERR("invalid where: %s\n", debugstr_w(where
));
804 if (NS_FAILED(nsres
))
810 static HRESULT WINAPI
HTMLElement_insertAdjacentHTML(IHTMLElement
*iface
, BSTR where
,
813 HTMLElement
*This
= HTMLELEM_THIS(iface
);
815 nsIDOMDocument
*nsdoc
;
816 nsIDOMDocumentRange
*nsdocrange
;
818 nsIDOMNSRange
*nsrange
;
823 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(html
));
825 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
828 ERR("GetDocument failed: %08x\n", nsres
);
832 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void **)&nsdocrange
);
833 nsIDOMDocument_Release(nsdoc
);
836 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres
);
839 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &range
);
840 nsIDOMDocumentRange_Release(nsdocrange
);
843 ERR("CreateRange failed: %08x\n", nsres
);
847 nsIDOMRange_SetStartBefore(range
, (nsIDOMNode
*)This
->nselem
);
849 nsIDOMRange_QueryInterface(range
, &IID_nsIDOMNSRange
, (void **)&nsrange
);
850 nsIDOMRange_Release(range
);
853 ERR("getting nsIDOMNSRange failed: %08x\n", nsres
);
857 nsAString_Init(&ns_html
, html
);
859 nsres
= nsIDOMNSRange_CreateContextualFragment(nsrange
, &ns_html
, (nsIDOMDocumentFragment
**)&nsnode
);
860 nsIDOMNSRange_Release(nsrange
);
861 nsAString_Finish(&ns_html
);
863 if(NS_FAILED(nsres
) || !nsnode
)
865 ERR("CreateTextNode failed: %08x\n", nsres
);
869 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
870 nsIDOMNode_Release(nsnode
);
875 static HRESULT WINAPI
HTMLElement_insertAdjacentText(IHTMLElement
*iface
, BSTR where
,
878 HTMLElement
*This
= HTMLELEM_THIS(iface
);
880 nsIDOMDocument
*nsdoc
;
885 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(text
));
887 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
888 if(NS_FAILED(nsres
) || !nsdoc
)
890 ERR("GetDocument failed: %08x\n", nsres
);
894 nsAString_Init(&ns_text
, text
);
896 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &ns_text
, (nsIDOMText
**)&nsnode
);
897 nsIDOMDocument_Release(nsdoc
);
898 nsAString_Finish(&ns_text
);
900 if(NS_FAILED(nsres
) || !nsnode
)
902 ERR("CreateTextNode failed: %08x\n", nsres
);
906 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
907 nsIDOMNode_Release(nsnode
);
912 static HRESULT WINAPI
HTMLElement_get_parentTextEdit(IHTMLElement
*iface
, IHTMLElement
**p
)
914 HTMLElement
*This
= HTMLELEM_THIS(iface
);
915 FIXME("(%p)->(%p)\n", This
, p
);
919 static HRESULT WINAPI
HTMLElement_get_isTextEdit(IHTMLElement
*iface
, VARIANT_BOOL
*p
)
921 HTMLElement
*This
= HTMLELEM_THIS(iface
);
922 FIXME("(%p)->(%p)\n", This
, p
);
926 static HRESULT WINAPI
HTMLElement_click(IHTMLElement
*iface
)
928 HTMLElement
*This
= HTMLELEM_THIS(iface
);
929 FIXME("(%p)\n", This
);
933 static HRESULT WINAPI
HTMLElement_get_filters(IHTMLElement
*iface
,
934 IHTMLFiltersCollection
**p
)
936 HTMLElement
*This
= HTMLELEM_THIS(iface
);
937 FIXME("(%p)->(%p)\n", This
, p
);
941 static HRESULT WINAPI
HTMLElement_put_ondragstart(IHTMLElement
*iface
, VARIANT v
)
943 HTMLElement
*This
= HTMLELEM_THIS(iface
);
944 FIXME("(%p)->()\n", This
);
948 static HRESULT WINAPI
HTMLElement_get_ondragstart(IHTMLElement
*iface
, VARIANT
*p
)
950 HTMLElement
*This
= HTMLELEM_THIS(iface
);
951 FIXME("(%p)->(%p)\n", This
, p
);
955 static HRESULT WINAPI
HTMLElement_toString(IHTMLElement
*iface
, BSTR
*String
)
957 HTMLElement
*This
= HTMLELEM_THIS(iface
);
958 FIXME("(%p)->(%p)\n", This
, String
);
962 static HRESULT WINAPI
HTMLElement_put_onbeforeupdate(IHTMLElement
*iface
, VARIANT v
)
964 HTMLElement
*This
= HTMLELEM_THIS(iface
);
965 FIXME("(%p)->()\n", This
);
969 static HRESULT WINAPI
HTMLElement_get_onbeforeupdate(IHTMLElement
*iface
, VARIANT
*p
)
971 HTMLElement
*This
= HTMLELEM_THIS(iface
);
972 FIXME("(%p)->(%p)\n", This
, p
);
976 static HRESULT WINAPI
HTMLElement_put_onafterupdate(IHTMLElement
*iface
, VARIANT v
)
978 HTMLElement
*This
= HTMLELEM_THIS(iface
);
979 FIXME("(%p)->()\n", This
);
983 static HRESULT WINAPI
HTMLElement_get_onafterupdate(IHTMLElement
*iface
, VARIANT
*p
)
985 HTMLElement
*This
= HTMLELEM_THIS(iface
);
986 FIXME("(%p)->(%p)\n", This
, p
);
990 static HRESULT WINAPI
HTMLElement_put_onerrorupdate(IHTMLElement
*iface
, VARIANT v
)
992 HTMLElement
*This
= HTMLELEM_THIS(iface
);
993 FIXME("(%p)->()\n", This
);
997 static HRESULT WINAPI
HTMLElement_get_onerrorupdate(IHTMLElement
*iface
, VARIANT
*p
)
999 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1000 FIXME("(%p)->(%p)\n", This
, p
);
1004 static HRESULT WINAPI
HTMLElement_put_onrowexit(IHTMLElement
*iface
, VARIANT v
)
1006 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1007 FIXME("(%p)->()\n", This
);
1011 static HRESULT WINAPI
HTMLElement_get_onrowexit(IHTMLElement
*iface
, VARIANT
*p
)
1013 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1014 FIXME("(%p)->(%p)\n", This
, p
);
1018 static HRESULT WINAPI
HTMLElement_put_onrowenter(IHTMLElement
*iface
, VARIANT v
)
1020 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1021 FIXME("(%p)->()\n", This
);
1025 static HRESULT WINAPI
HTMLElement_get_onrowenter(IHTMLElement
*iface
, VARIANT
*p
)
1027 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1028 FIXME("(%p)->(%p)\n", This
, p
);
1032 static HRESULT WINAPI
HTMLElement_put_ondatasetchanged(IHTMLElement
*iface
, VARIANT v
)
1034 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1035 FIXME("(%p)->()\n", This
);
1039 static HRESULT WINAPI
HTMLElement_get_ondatasetchanged(IHTMLElement
*iface
, VARIANT
*p
)
1041 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1042 FIXME("(%p)->(%p)\n", This
, p
);
1046 static HRESULT WINAPI
HTMLElement_put_ondataavailable(IHTMLElement
*iface
, VARIANT v
)
1048 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1049 FIXME("(%p)->()\n", This
);
1053 static HRESULT WINAPI
HTMLElement_get_ondataavailable(IHTMLElement
*iface
, VARIANT
*p
)
1055 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1056 FIXME("(%p)->(%p)\n", This
, p
);
1060 static HRESULT WINAPI
HTMLElement_put_ondatasetcomplete(IHTMLElement
*iface
, VARIANT v
)
1062 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1063 FIXME("(%p)->()\n", This
);
1067 static HRESULT WINAPI
HTMLElement_get_ondatasetcomplete(IHTMLElement
*iface
, VARIANT
*p
)
1069 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1070 FIXME("(%p)->(%p)\n", This
, p
);
1074 static HRESULT WINAPI
HTMLElement_put_onfilterchange(IHTMLElement
*iface
, VARIANT v
)
1076 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1077 FIXME("(%p)->()\n", This
);
1081 static HRESULT WINAPI
HTMLElement_get_onfilterchange(IHTMLElement
*iface
, VARIANT
*p
)
1083 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1084 FIXME("(%p)->(%p)\n", This
, p
);
1088 static void create_child_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1090 nsIDOMNodeList
*nsnode_list
;
1092 PRUint32 list_len
= 0, i
;
1095 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1096 if(NS_FAILED(nsres
)) {
1097 ERR("GetChildNodes failed: %08x\n", nsres
);
1101 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1105 buf
->size
= list_len
;
1106 buf
->buf
= heap_alloc(buf
->size
*sizeof(HTMLElement
**));
1108 for(i
=0; i
<list_len
; i
++) {
1109 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1110 if(NS_FAILED(nsres
)) {
1111 ERR("Item failed: %08x\n", nsres
);
1115 if(is_elem_node(iter
))
1116 elem_vector_add(buf
, HTMLELEM_NODE_THIS(get_node(doc
, iter
, TRUE
)));
1120 static HRESULT WINAPI
HTMLElement_get_children(IHTMLElement
*iface
, IDispatch
**p
)
1122 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1123 elem_vector buf
= {NULL
, 0, 0};
1125 TRACE("(%p)->(%p)\n", This
, p
);
1127 create_child_list(This
->node
.doc
, This
, &buf
);
1129 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1133 static void create_all_list(HTMLDocument
*doc
, HTMLDOMNode
*elem
, elem_vector
*buf
)
1135 nsIDOMNodeList
*nsnode_list
;
1137 PRUint32 list_len
= 0, i
;
1140 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
1141 if(NS_FAILED(nsres
)) {
1142 ERR("GetChildNodes failed: %08x\n", nsres
);
1146 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1150 for(i
=0; i
<list_len
; i
++) {
1151 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1152 if(NS_FAILED(nsres
)) {
1153 ERR("Item failed: %08x\n", nsres
);
1157 if(is_elem_node(iter
)) {
1158 HTMLDOMNode
*node
= get_node(doc
, iter
, TRUE
);
1160 elem_vector_add(buf
, HTMLELEM_NODE_THIS(node
));
1161 create_all_list(doc
, node
, buf
);
1166 static HRESULT WINAPI
HTMLElement_get_all(IHTMLElement
*iface
, IDispatch
**p
)
1168 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1169 elem_vector buf
= {NULL
, 0, 8};
1171 TRACE("(%p)->(%p)\n", This
, p
);
1173 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
**));
1175 create_all_list(This
->node
.doc
, &This
->node
, &buf
);
1176 elem_vector_normalize(&buf
);
1178 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1182 #undef HTMLELEM_THIS
1184 static const IHTMLElementVtbl HTMLElementVtbl
= {
1185 HTMLElement_QueryInterface
,
1187 HTMLElement_Release
,
1188 HTMLElement_GetTypeInfoCount
,
1189 HTMLElement_GetTypeInfo
,
1190 HTMLElement_GetIDsOfNames
,
1192 HTMLElement_setAttribute
,
1193 HTMLElement_getAttribute
,
1194 HTMLElement_removeAttribute
,
1195 HTMLElement_put_className
,
1196 HTMLElement_get_className
,
1199 HTMLElement_get_tagName
,
1200 HTMLElement_get_parentElement
,
1201 HTMLElement_get_style
,
1202 HTMLElement_put_onhelp
,
1203 HTMLElement_get_onhelp
,
1204 HTMLElement_put_onclick
,
1205 HTMLElement_get_onclick
,
1206 HTMLElement_put_ondblclick
,
1207 HTMLElement_get_ondblclick
,
1208 HTMLElement_put_onkeydown
,
1209 HTMLElement_get_onkeydown
,
1210 HTMLElement_put_onkeyup
,
1211 HTMLElement_get_onkeyup
,
1212 HTMLElement_put_onkeypress
,
1213 HTMLElement_get_onkeypress
,
1214 HTMLElement_put_onmouseout
,
1215 HTMLElement_get_onmouseout
,
1216 HTMLElement_put_onmouseover
,
1217 HTMLElement_get_onmouseover
,
1218 HTMLElement_put_onmousemove
,
1219 HTMLElement_get_onmousemove
,
1220 HTMLElement_put_onmousedown
,
1221 HTMLElement_get_onmousedown
,
1222 HTMLElement_put_onmouseup
,
1223 HTMLElement_get_onmouseup
,
1224 HTMLElement_get_document
,
1225 HTMLElement_put_title
,
1226 HTMLElement_get_title
,
1227 HTMLElement_put_language
,
1228 HTMLElement_get_language
,
1229 HTMLElement_put_onselectstart
,
1230 HTMLElement_get_onselectstart
,
1231 HTMLElement_scrollIntoView
,
1232 HTMLElement_contains
,
1233 HTMLElement_get_sourceIndex
,
1234 HTMLElement_get_recordNumber
,
1235 HTMLElement_put_lang
,
1236 HTMLElement_get_lang
,
1237 HTMLElement_get_offsetLeft
,
1238 HTMLElement_get_offsetTop
,
1239 HTMLElement_get_offsetWidth
,
1240 HTMLElement_get_offsetHeight
,
1241 HTMLElement_get_offsetParent
,
1242 HTMLElement_put_innerHTML
,
1243 HTMLElement_get_innerHTML
,
1244 HTMLElement_put_innerText
,
1245 HTMLElement_get_innerText
,
1246 HTMLElement_put_outerHTML
,
1247 HTMLElement_get_outerHTML
,
1248 HTMLElement_put_outerText
,
1249 HTMLElement_get_outerText
,
1250 HTMLElement_insertAdjacentHTML
,
1251 HTMLElement_insertAdjacentText
,
1252 HTMLElement_get_parentTextEdit
,
1253 HTMLElement_get_isTextEdit
,
1255 HTMLElement_get_filters
,
1256 HTMLElement_put_ondragstart
,
1257 HTMLElement_get_ondragstart
,
1258 HTMLElement_toString
,
1259 HTMLElement_put_onbeforeupdate
,
1260 HTMLElement_get_onbeforeupdate
,
1261 HTMLElement_put_onafterupdate
,
1262 HTMLElement_get_onafterupdate
,
1263 HTMLElement_put_onerrorupdate
,
1264 HTMLElement_get_onerrorupdate
,
1265 HTMLElement_put_onrowexit
,
1266 HTMLElement_get_onrowexit
,
1267 HTMLElement_put_onrowenter
,
1268 HTMLElement_get_onrowenter
,
1269 HTMLElement_put_ondatasetchanged
,
1270 HTMLElement_get_ondatasetchanged
,
1271 HTMLElement_put_ondataavailable
,
1272 HTMLElement_get_ondataavailable
,
1273 HTMLElement_put_ondatasetcomplete
,
1274 HTMLElement_get_ondatasetcomplete
,
1275 HTMLElement_put_onfilterchange
,
1276 HTMLElement_get_onfilterchange
,
1277 HTMLElement_get_children
,
1281 HRESULT
HTMLElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1283 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1287 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1288 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1289 *ppv
= HTMLELEM(This
);
1290 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1291 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1292 *ppv
= HTMLELEM(This
);
1293 }else if(IsEqualGUID(&IID_IHTMLElement
, riid
)) {
1294 TRACE("(%p)->(IID_IHTMLElement %p)\n", This
, ppv
);
1295 *ppv
= HTMLELEM(This
);
1296 }else if(IsEqualGUID(&IID_IHTMLElement2
, riid
)) {
1297 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This
, ppv
);
1298 *ppv
= HTMLELEM2(This
);
1299 }else if(IsEqualGUID(&IID_IConnectionPointContainer
, riid
)) {
1300 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This
, ppv
);
1301 *ppv
= CONPTCONT(&This
->cp_container
);
1305 IHTMLElement_AddRef(HTMLELEM(This
));
1309 return HTMLDOMNode_QI(&This
->node
, riid
, ppv
);
1312 void HTMLElement_destructor(HTMLDOMNode
*iface
)
1314 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1316 ConnectionPointContainer_Destroy(&This
->cp_container
);
1319 nsIDOMHTMLElement_Release(This
->nselem
);
1321 HTMLDOMNode_destructor(&This
->node
);
1324 static const NodeImplVtbl HTMLElementImplVtbl
= {
1326 HTMLElement_destructor
1329 static const tid_t HTMLElement_iface_tids
[] = {
1336 static dispex_static_data_t HTMLElement_dispex
= {
1338 DispHTMLUnknownElement_tid
,
1340 HTMLElement_iface_tids
1343 void HTMLElement_Init(HTMLElement
*This
)
1345 This
->lpHTMLElementVtbl
= &HTMLElementVtbl
;
1347 ConnectionPointContainer_Init(&This
->cp_container
, (IUnknown
*)HTMLELEM(This
));
1349 HTMLElement2_Init(This
);
1351 if(!This
->node
.dispex
.data
)
1352 init_dispex(&This
->node
.dispex
, (IUnknown
*)HTMLELEM(This
), &HTMLElement_dispex
);
1355 HTMLElement
*HTMLElement_Create(nsIDOMNode
*nsnode
)
1357 nsIDOMHTMLElement
*nselem
;
1358 HTMLElement
*ret
= NULL
;
1359 nsAString class_name_str
;
1360 const PRUnichar
*class_name
;
1363 static const WCHAR wszA
[] = {'A',0};
1364 static const WCHAR wszBODY
[] = {'B','O','D','Y',0};
1365 static const WCHAR wszIMG
[] = {'I','M','G',0};
1366 static const WCHAR wszINPUT
[] = {'I','N','P','U','T',0};
1367 static const WCHAR wszOPTION
[] = {'O','P','T','I','O','N',0};
1368 static const WCHAR wszSCRIPT
[] = {'S','C','R','I','P','T',0};
1369 static const WCHAR wszSELECT
[] = {'S','E','L','E','C','T',0};
1370 static const WCHAR wszTABLE
[] = {'T','A','B','L','E',0};
1371 static const WCHAR wszTEXTAREA
[] = {'T','E','X','T','A','R','E','A',0};
1373 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
1374 if(NS_FAILED(nsres
))
1377 nsAString_Init(&class_name_str
, NULL
);
1378 nsIDOMHTMLElement_GetTagName(nselem
, &class_name_str
);
1380 nsAString_GetData(&class_name_str
, &class_name
);
1382 if(!strcmpW(class_name
, wszA
))
1383 ret
= HTMLAnchorElement_Create(nselem
);
1384 else if(!strcmpW(class_name
, wszBODY
))
1385 ret
= HTMLBodyElement_Create(nselem
);
1386 else if(!strcmpW(class_name
, wszIMG
))
1387 ret
= HTMLImgElement_Create(nselem
);
1388 else if(!strcmpW(class_name
, wszINPUT
))
1389 ret
= HTMLInputElement_Create(nselem
);
1390 else if(!strcmpW(class_name
, wszOPTION
))
1391 ret
= HTMLOptionElement_Create(nselem
);
1392 else if(!strcmpW(class_name
, wszSCRIPT
))
1393 ret
= HTMLScriptElement_Create(nselem
);
1394 else if(!strcmpW(class_name
, wszSELECT
))
1395 ret
= HTMLSelectElement_Create(nselem
);
1396 else if(!strcmpW(class_name
, wszTABLE
))
1397 ret
= HTMLTable_Create(nselem
);
1398 else if(!strcmpW(class_name
, wszTEXTAREA
))
1399 ret
= HTMLTextAreaElement_Create(nselem
);
1402 ret
= heap_alloc_zero(sizeof(HTMLElement
));
1403 HTMLElement_Init(ret
);
1404 ret
->node
.vtbl
= &HTMLElementImplVtbl
;
1407 nsAString_Finish(&class_name_str
);
1409 ret
->nselem
= nselem
;
1416 const IHTMLElementCollectionVtbl
*lpHTMLElementCollectionVtbl
;
1419 HTMLElement
**elems
;
1423 } HTMLElementCollection
;
1425 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1427 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1429 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
1430 REFIID riid
, void **ppv
)
1432 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1436 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1437 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1438 *ppv
= HTMLELEMCOL(This
);
1439 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1440 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1441 *ppv
= HTMLELEMCOL(This
);
1442 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1443 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1444 *ppv
= DISPATCHEX(&This
->dispex
);
1445 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
1446 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This
, ppv
);
1447 *ppv
= HTMLELEMCOL(This
);
1451 IHTMLElementCollection_AddRef(HTMLELEMCOL(This
));
1455 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1456 return E_NOINTERFACE
;
1459 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
1461 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1462 LONG ref
= InterlockedIncrement(&This
->ref
);
1464 TRACE("(%p) ref=%d\n", This
, ref
);
1469 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
1471 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1472 LONG ref
= InterlockedDecrement(&This
->ref
);
1474 TRACE("(%p) ref=%d\n", This
, ref
);
1477 IUnknown_Release(This
->ref_unk
);
1478 heap_free(This
->elems
);
1485 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
1488 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1489 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1493 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
1494 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1496 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1497 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1501 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
1502 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1504 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1505 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1510 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
1511 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1512 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1514 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1515 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1516 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1520 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
1523 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1524 FIXME("(%p)->(%p)\n", This
, String
);
1528 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
1531 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1532 FIXME("(%p)->(%ld)\n", This
, v
);
1536 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
1539 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1541 TRACE("(%p)->(%p)\n", This
, p
);
1547 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
1550 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1551 FIXME("(%p)->(%p)\n", This
, p
);
1555 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
1557 const PRUnichar
*str
;
1558 nsAString nsstr
, nsname
;
1562 static const PRUnichar nameW
[] = {'n','a','m','e',0};
1567 nsAString_Init(&nsstr
, NULL
);
1568 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
1569 nsAString_GetData(&nsstr
, &str
);
1570 if(!strcmpiW(str
, name
)) {
1571 nsAString_Finish(&nsstr
);
1575 nsAString_Init(&nsname
, nameW
);
1576 nsres
= nsIDOMHTMLElement_GetAttribute(elem
->nselem
, &nsname
, &nsstr
);
1577 nsAString_Finish(&nsname
);
1578 if(NS_SUCCEEDED(nsres
)) {
1579 nsAString_GetData(&nsstr
, &str
);
1580 ret
= !strcmpiW(str
, name
);
1583 nsAString_Finish(&nsstr
);
1587 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
1588 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
1590 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1592 TRACE("(%p)->(v(%d) v(%d) %p)\n", This
, V_VT(&name
), V_VT(&index
), pdisp
);
1596 if(V_VT(&name
) == VT_I4
) {
1597 TRACE("name is VT_I4: %d\n", V_I4(&name
));
1600 return E_INVALIDARG
;
1601 if(V_I4(&name
) >= This
->len
)
1604 *pdisp
= (IDispatch
*)This
->elems
[V_I4(&name
)];
1605 IDispatch_AddRef(*pdisp
);
1606 TRACE("Returning pdisp=%p\n", pdisp
);
1610 if(V_VT(&name
) == VT_BSTR
) {
1613 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name
)));
1615 if(V_VT(&index
) == VT_I4
) {
1616 LONG idx
= V_I4(&index
);
1618 TRACE("index = %d\n", idx
);
1621 return E_INVALIDARG
;
1623 for(i
=0; i
<This
->len
; i
++) {
1624 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
1628 if(i
!= This
->len
) {
1629 *pdisp
= (IDispatch
*)HTMLELEM(This
->elems
[i
]);
1630 IDispatch_AddRef(*pdisp
);
1635 elem_vector buf
= {NULL
, 0, 8};
1637 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
1639 for(i
=0; i
<This
->len
; i
++) {
1640 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)))
1641 elem_vector_add(&buf
, This
->elems
[i
]);
1645 elem_vector_normalize(&buf
);
1646 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1649 *pdisp
= (IDispatch
*)HTMLELEM(buf
.buf
[0]);
1650 IDispatch_AddRef(*pdisp
);
1660 FIXME("unsupported arguments\n");
1661 return E_INVALIDARG
;
1664 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
1665 VARIANT tagName
, IDispatch
**pdisp
)
1667 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1670 const PRUnichar
*tag
;
1671 elem_vector buf
= {NULL
, 0, 8};
1673 if(V_VT(&tagName
) != VT_BSTR
) {
1674 WARN("Invalid arg\n");
1675 return DISP_E_MEMBERNOTFOUND
;
1678 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
1680 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
1682 nsAString_Init(&tag_str
, NULL
);
1684 for(i
=0; i
<This
->len
; i
++) {
1685 if(!This
->elems
[i
]->nselem
)
1688 nsIDOMElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
1689 nsAString_GetData(&tag_str
, &tag
);
1691 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1692 V_BSTR(&tagName
), -1) == CSTR_EQUAL
)
1693 elem_vector_add(&buf
, This
->elems
[i
]);
1696 nsAString_Finish(&tag_str
);
1697 elem_vector_normalize(&buf
);
1699 TRACE("fount %d tags\n", buf
.len
);
1701 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1705 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1707 static HRESULT
HTMLElementCollection_get_dispid(IUnknown
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
1709 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1713 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
1714 idx
= idx
*10 + (*ptr
-'0');
1716 if(*ptr
|| idx
>= This
->len
)
1717 return DISP_E_UNKNOWNNAME
;
1719 *dispid
= DISPID_ELEMCOL_0
+ idx
;
1720 TRACE("ret %x\n", *dispid
);
1724 static HRESULT
HTMLElementCollection_invoke(IUnknown
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1725 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1727 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1730 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
1732 idx
= id
- DISPID_ELEMCOL_0
;
1733 if(idx
>= This
->len
)
1734 return DISP_E_UNKNOWNNAME
;
1737 case INVOKE_PROPERTYGET
:
1738 V_VT(res
) = VT_DISPATCH
;
1739 V_DISPATCH(res
) = (IDispatch
*)HTMLELEM(This
->elems
[idx
]);
1740 IHTMLElement_AddRef(HTMLELEM(This
->elems
[idx
]));
1743 FIXME("unimplemented flags %x\n", flags
);
1752 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
1753 HTMLElementCollection_QueryInterface
,
1754 HTMLElementCollection_AddRef
,
1755 HTMLElementCollection_Release
,
1756 HTMLElementCollection_GetTypeInfoCount
,
1757 HTMLElementCollection_GetTypeInfo
,
1758 HTMLElementCollection_GetIDsOfNames
,
1759 HTMLElementCollection_Invoke
,
1760 HTMLElementCollection_toString
,
1761 HTMLElementCollection_put_length
,
1762 HTMLElementCollection_get_length
,
1763 HTMLElementCollection_get__newEnum
,
1764 HTMLElementCollection_item
,
1765 HTMLElementCollection_tags
1768 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl
= {
1769 HTMLElementCollection_get_dispid
,
1770 HTMLElementCollection_invoke
1773 static const tid_t HTMLElementCollection_iface_tids
[] = {
1774 IHTMLElementCollection_tid
,
1777 static dispex_static_data_t HTMLElementCollection_dispex
= {
1778 &HTMLElementColection_dispex_vtbl
,
1779 DispHTMLElementCollection_tid
,
1781 HTMLElementCollection_iface_tids
1784 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
)
1786 elem_vector buf
= {NULL
, 0, 8};
1788 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
**));
1790 elem_vector_add(&buf
, HTMLELEM_NODE_THIS(node
));
1791 create_all_list(node
->doc
, node
, &buf
);
1792 elem_vector_normalize(&buf
);
1794 return HTMLElementCollection_Create((IUnknown
*)HTMLDOMNODE(node
), buf
.buf
, buf
.len
);
1797 static IHTMLElementCollection
*HTMLElementCollection_Create(IUnknown
*ref_unk
,
1798 HTMLElement
**elems
, DWORD len
)
1800 HTMLElementCollection
*ret
= heap_alloc(sizeof(HTMLElementCollection
));
1802 ret
->lpHTMLElementCollectionVtbl
= &HTMLElementCollectionVtbl
;
1807 init_dispex(&ret
->dispex
, (IUnknown
*)HTMLELEMCOL(ret
), &HTMLElementCollection_dispex
);
1809 IUnknown_AddRef(ref_unk
);
1810 ret
->ref_unk
= ref_unk
;
1812 TRACE("ret=%p len=%d\n", ret
, len
);
1814 return HTMLELEMCOL(ret
);