2 * Copyright 2006-2008 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
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 IHTMLElementCollection IHTMLElementCollection_iface
;
43 } HTMLElementCollection
;
46 IEnumVARIANT IEnumVARIANT_iface
;
51 HTMLElementCollection
*col
;
52 } HTMLElementCollectionEnum
;
60 /* FIXME: Handle it better way */
61 static inline HTMLElement
*elem_from_HTMLDOMNode(HTMLDOMNode
*iface
)
63 return CONTAINING_RECORD(iface
, HTMLElement
, node
);
66 static IHTMLElementCollection
*HTMLElementCollection_Create(HTMLElement
**elems
, DWORD len
);
68 static void elem_vector_add(elem_vector_t
*buf
, HTMLElement
*elem
)
70 if(buf
->len
== buf
->size
) {
72 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
*sizeof(HTMLElement
*));
75 buf
->buf
[buf
->len
++] = elem
;
78 static void elem_vector_normalize(elem_vector_t
*buf
)
83 }else if(buf
->size
> buf
->len
) {
84 buf
->buf
= heap_realloc(buf
->buf
, buf
->len
*sizeof(HTMLElement
*));
90 static inline BOOL
is_elem_node(nsIDOMNode
*node
)
94 nsIDOMNode_GetNodeType(node
, &type
);
96 return type
== ELEMENT_NODE
|| type
== COMMENT_NODE
;
99 static inline HTMLElementCollectionEnum
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
101 return CONTAINING_RECORD(iface
, HTMLElementCollectionEnum
, IEnumVARIANT_iface
);
104 static HRESULT WINAPI
HTMLElementCollectionEnum_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
106 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
108 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
110 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
111 *ppv
= &This
->IEnumVARIANT_iface
;
112 }else if(IsEqualGUID(riid
, &IID_IEnumVARIANT
)) {
113 *ppv
= &This
->IEnumVARIANT_iface
;
115 FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid
));
117 return E_NOINTERFACE
;
120 IUnknown_AddRef((IUnknown
*)*ppv
);
124 static ULONG WINAPI
HTMLElementCollectionEnum_AddRef(IEnumVARIANT
*iface
)
126 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
127 LONG ref
= InterlockedIncrement(&This
->ref
);
129 TRACE("(%p) ref=%d\n", This
, ref
);
134 static ULONG WINAPI
HTMLElementCollectionEnum_Release(IEnumVARIANT
*iface
)
136 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
137 LONG ref
= InterlockedDecrement(&This
->ref
);
139 TRACE("(%p) ref=%d\n", This
, ref
);
142 IHTMLElementCollection_Release(&This
->col
->IHTMLElementCollection_iface
);
149 static HRESULT WINAPI
HTMLElementCollectionEnum_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
151 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
154 TRACE("(%p)->(%d %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
156 while(This
->iter
+fetched
< This
->col
->len
&& fetched
< celt
) {
157 V_VT(rgVar
+fetched
) = VT_DISPATCH
;
158 V_DISPATCH(rgVar
+fetched
) = (IDispatch
*)&This
->col
->elems
[This
->iter
+fetched
]->IHTMLElement_iface
;
159 IDispatch_AddRef(V_DISPATCH(rgVar
+fetched
));
163 This
->iter
+= fetched
;
165 *pCeltFetched
= fetched
;
166 return fetched
== celt
? S_OK
: S_FALSE
;
169 static HRESULT WINAPI
HTMLElementCollectionEnum_Skip(IEnumVARIANT
*iface
, ULONG celt
)
171 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
173 TRACE("(%p)->(%d)\n", This
, celt
);
175 if(This
->iter
+ celt
> This
->col
->len
) {
176 This
->iter
= This
->col
->len
;
184 static HRESULT WINAPI
HTMLElementCollectionEnum_Reset(IEnumVARIANT
*iface
)
186 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
188 TRACE("(%p)->()\n", This
);
194 static HRESULT WINAPI
HTMLElementCollectionEnum_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
196 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
197 FIXME("(%p)->(%p)\n", This
, ppEnum
);
201 static const IEnumVARIANTVtbl HTMLElementCollectionEnumVtbl
= {
202 HTMLElementCollectionEnum_QueryInterface
,
203 HTMLElementCollectionEnum_AddRef
,
204 HTMLElementCollectionEnum_Release
,
205 HTMLElementCollectionEnum_Next
,
206 HTMLElementCollectionEnum_Skip
,
207 HTMLElementCollectionEnum_Reset
,
208 HTMLElementCollectionEnum_Clone
211 static inline HTMLElementCollection
*impl_from_IHTMLElementCollection(IHTMLElementCollection
*iface
)
213 return CONTAINING_RECORD(iface
, HTMLElementCollection
, IHTMLElementCollection_iface
);
216 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
217 REFIID riid
, void **ppv
)
219 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
221 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
223 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
224 *ppv
= &This
->IHTMLElementCollection_iface
;
225 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
226 *ppv
= &This
->IHTMLElementCollection_iface
;
227 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
228 return *ppv
? S_OK
: E_NOINTERFACE
;
231 FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid
));
232 return E_NOINTERFACE
;
235 IHTMLElementCollection_AddRef(&This
->IHTMLElementCollection_iface
);
239 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
241 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
242 LONG ref
= InterlockedIncrement(&This
->ref
);
244 TRACE("(%p) ref=%d\n", This
, ref
);
249 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
251 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
252 LONG ref
= InterlockedDecrement(&This
->ref
);
254 TRACE("(%p) ref=%d\n", This
, ref
);
259 for(i
=0; i
< This
->len
; i
++)
260 node_release(&This
->elems
[i
]->node
);
261 heap_free(This
->elems
);
263 release_dispex(&This
->dispex
);
270 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
273 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
274 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
277 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
278 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
280 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
281 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
284 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
285 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
287 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
288 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
292 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
293 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
294 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
296 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
297 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
298 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
301 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
304 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
305 FIXME("(%p)->(%p)\n", This
, String
);
309 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
312 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
313 FIXME("(%p)->(%d)\n", This
, v
);
317 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
320 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
322 TRACE("(%p)->(%p)\n", This
, p
);
328 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
331 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
332 HTMLElementCollectionEnum
*ret
;
334 TRACE("(%p)->(%p)\n", This
, p
);
336 ret
= heap_alloc(sizeof(*ret
));
338 return E_OUTOFMEMORY
;
340 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLElementCollectionEnumVtbl
;
344 IHTMLElementCollection_AddRef(&This
->IHTMLElementCollection_iface
);
347 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
351 static BOOL
is_elem_id(HTMLElement
*elem
, LPCWSTR name
)
356 hres
= IHTMLElement_get_id(&elem
->IHTMLElement_iface
, &elem_id
);
358 WARN("IHTMLElement_get_id failed: 0x%08x\n", hres
);
362 if(elem_id
&& !strcmpW(elem_id
, name
)) {
363 SysFreeString(elem_id
);
367 SysFreeString(elem_id
);
371 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
373 const PRUnichar
*str
;
378 static const PRUnichar nameW
[] = {'n','a','m','e',0};
383 nsAString_Init(&nsstr
, NULL
);
384 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
385 nsAString_GetData(&nsstr
, &str
);
386 if(!strcmpiW(str
, name
)) {
387 nsAString_Finish(&nsstr
);
391 nsres
= get_elem_attr_value(elem
->nselem
, nameW
, &nsstr
, &str
);
392 if(NS_SUCCEEDED(nsres
)) {
393 ret
= !strcmpiW(str
, name
);
394 nsAString_Finish(&nsstr
);
400 static HRESULT
get_item_idx(HTMLElementCollection
*This
, UINT idx
, IDispatch
**ret
)
402 if(idx
< This
->len
) {
403 *ret
= (IDispatch
*)&This
->elems
[idx
]->node
.event_target
.dispex
.IDispatchEx_iface
;
404 IDispatch_AddRef(*ret
);
410 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
411 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
413 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
416 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
420 switch(V_VT(&name
)) {
425 hres
= get_item_idx(This
, V_I4(&name
), pdisp
);
430 hres
= get_item_idx(This
, V_UINT(&name
), pdisp
);
436 if(V_VT(&index
) == VT_I4
) {
437 LONG idx
= V_I4(&index
);
442 for(i
=0; i
<This
->len
; i
++) {
443 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
448 *pdisp
= (IDispatch
*)&This
->elems
[i
]->IHTMLElement_iface
;
449 IDispatch_AddRef(*pdisp
);
452 elem_vector_t buf
= {NULL
, 0, 8};
454 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
456 for(i
=0; i
<This
->len
; i
++) {
457 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
))) {
458 node_addref(&This
->elems
[i
]->node
);
459 elem_vector_add(&buf
, This
->elems
[i
]);
464 elem_vector_normalize(&buf
);
465 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(buf
.buf
, buf
.len
);
468 /* Already AddRef-ed */
469 *pdisp
= (IDispatch
*)&buf
.buf
[0]->IHTMLElement_iface
;
479 FIXME("Unsupported name %s\n", debugstr_variant(&name
));
484 TRACE("returning %p\n", *pdisp
);
488 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
489 VARIANT tagName
, IDispatch
**pdisp
)
491 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
494 const PRUnichar
*tag
;
495 elem_vector_t buf
= {NULL
, 0, 8};
497 if(V_VT(&tagName
) != VT_BSTR
) {
498 WARN("Invalid arg\n");
499 return DISP_E_MEMBERNOTFOUND
;
502 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
504 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
506 nsAString_Init(&tag_str
, NULL
);
508 for(i
=0; i
<This
->len
; i
++) {
509 if(!This
->elems
[i
]->nselem
)
512 nsIDOMHTMLElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
513 nsAString_GetData(&tag_str
, &tag
);
515 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
516 V_BSTR(&tagName
), -1) == CSTR_EQUAL
) {
517 node_addref(&This
->elems
[i
]->node
);
518 elem_vector_add(&buf
, This
->elems
[i
]);
522 nsAString_Finish(&tag_str
);
523 elem_vector_normalize(&buf
);
525 TRACE("fount %d tags\n", buf
.len
);
527 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(buf
.buf
, buf
.len
);
531 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
532 HTMLElementCollection_QueryInterface
,
533 HTMLElementCollection_AddRef
,
534 HTMLElementCollection_Release
,
535 HTMLElementCollection_GetTypeInfoCount
,
536 HTMLElementCollection_GetTypeInfo
,
537 HTMLElementCollection_GetIDsOfNames
,
538 HTMLElementCollection_Invoke
,
539 HTMLElementCollection_toString
,
540 HTMLElementCollection_put_length
,
541 HTMLElementCollection_get_length
,
542 HTMLElementCollection_get__newEnum
,
543 HTMLElementCollection_item
,
544 HTMLElementCollection_tags
547 static inline HTMLElementCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
549 return CONTAINING_RECORD(iface
, HTMLElementCollection
, dispex
);
552 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
554 static HRESULT
HTMLElementCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
556 HTMLElementCollection
*This
= impl_from_DispatchEx(dispex
);
561 return DISP_E_UNKNOWNNAME
;
563 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
564 idx
= idx
*10 + (*ptr
-'0');
567 /* the name contains alpha characters, so search by name & id */
568 for(idx
= 0; idx
< This
->len
; ++idx
) {
569 if(is_elem_id(This
->elems
[idx
], name
) ||
570 is_elem_name(This
->elems
[idx
], name
))
576 return DISP_E_UNKNOWNNAME
;
578 *dispid
= DISPID_ELEMCOL_0
+ idx
;
579 TRACE("ret %x\n", *dispid
);
583 static HRESULT
HTMLElementCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
584 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
586 HTMLElementCollection
*This
= impl_from_DispatchEx(dispex
);
589 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
591 idx
= id
- DISPID_ELEMCOL_0
;
593 return DISP_E_UNKNOWNNAME
;
596 case DISPATCH_PROPERTYGET
:
597 V_VT(res
) = VT_DISPATCH
;
598 V_DISPATCH(res
) = (IDispatch
*)&This
->elems
[idx
]->IHTMLElement_iface
;
599 IHTMLElement_AddRef(&This
->elems
[idx
]->IHTMLElement_iface
);
602 FIXME("unimplemented flags %x\n", flags
);
609 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl
= {
611 HTMLElementCollection_get_dispid
,
612 HTMLElementCollection_invoke
,
616 static const tid_t HTMLElementCollection_iface_tids
[] = {
617 IHTMLElementCollection_tid
,
621 static dispex_static_data_t HTMLElementCollection_dispex
= {
622 &HTMLElementColection_dispex_vtbl
,
623 DispHTMLElementCollection_tid
,
624 HTMLElementCollection_iface_tids
627 static void create_all_list(HTMLDocumentNode
*doc
, HTMLDOMNode
*elem
, elem_vector_t
*buf
)
629 nsIDOMNodeList
*nsnode_list
;
631 UINT32 list_len
= 0, i
;
635 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
636 if(NS_FAILED(nsres
)) {
637 ERR("GetChildNodes failed: %08x\n", nsres
);
641 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
645 for(i
=0; i
<list_len
; i
++) {
646 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
647 if(NS_FAILED(nsres
)) {
648 ERR("Item failed: %08x\n", nsres
);
652 if(is_elem_node(iter
)) {
655 hres
= get_node(doc
, iter
, TRUE
, &node
);
657 FIXME("get_node failed: %08x\n", hres
);
661 elem_vector_add(buf
, elem_from_HTMLDOMNode(node
));
662 create_all_list(doc
, node
, buf
);
667 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
, BOOL include_root
)
669 elem_vector_t buf
= {NULL
, 0, 8};
671 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
675 elem_vector_add(&buf
, elem_from_HTMLDOMNode(node
));
677 create_all_list(node
->doc
, node
, &buf
);
678 elem_vector_normalize(&buf
);
680 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
683 IHTMLElementCollection
*create_collection_from_nodelist(HTMLDocumentNode
*doc
, nsIDOMNodeList
*nslist
)
685 UINT32 length
= 0, i
;
690 nsIDOMNodeList_GetLength(nslist
, &length
);
697 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
699 for(i
=0; i
<length
; i
++) {
700 nsIDOMNodeList_Item(nslist
, i
, &nsnode
);
701 if(is_elem_node(nsnode
)) {
702 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
705 buf
.buf
[buf
.len
++] = elem_from_HTMLDOMNode(node
);
707 nsIDOMNode_Release(nsnode
);
710 elem_vector_normalize(&buf
);
715 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
718 IHTMLElementCollection
*create_collection_from_htmlcol(HTMLDocumentNode
*doc
, nsIDOMHTMLCollection
*nscol
)
720 UINT32 length
= 0, i
;
726 nsIDOMHTMLCollection_GetLength(nscol
, &length
);
728 buf
.len
= buf
.size
= length
;
732 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
734 for(i
=0; i
<length
; i
++) {
735 nsIDOMHTMLCollection_Item(nscol
, i
, &nsnode
);
736 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
737 nsIDOMNode_Release(nsnode
);
740 buf
.buf
[i
] = elem_from_HTMLDOMNode(node
);
751 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
754 HRESULT
get_elem_source_index(HTMLElement
*elem
, LONG
*ret
)
756 elem_vector_t buf
= {NULL
, 0, 8};
757 nsIDOMNode
*parent_node
, *iter
;
764 iter
= elem
->node
.nsnode
;
765 nsIDOMNode_AddRef(iter
);
767 /* Find document or document fragment parent. */
769 nsres
= nsIDOMNode_GetParentNode(iter
, &parent_node
);
770 nsIDOMNode_Release(iter
);
771 assert(nsres
== NS_OK
);
775 nsres
= nsIDOMNode_GetNodeType(parent_node
, &parent_type
);
776 assert(nsres
== NS_OK
);
778 if(parent_type
!= ELEMENT_NODE
) {
779 if(parent_type
!= DOCUMENT_NODE
&& parent_type
!= DOCUMENT_FRAGMENT_NODE
)
780 FIXME("Unexpected parent_type %d\n", parent_type
);
792 hres
= get_node(elem
->node
.doc
, parent_node
, TRUE
, &node
);
793 nsIDOMNode_Release(parent_node
);
798 /* Create all children collection and find the element in it.
799 * This could be optimized if we ever find the reason. */
800 buf
.buf
= heap_alloc(buf
.size
*sizeof(*buf
.buf
));
802 IHTMLDOMNode_Release(&node
->IHTMLDOMNode_iface
);
803 return E_OUTOFMEMORY
;
806 create_all_list(elem
->node
.doc
, node
, &buf
);
808 for(i
=0; i
< buf
.len
; i
++) {
809 if(buf
.buf
[i
] == elem
)
812 IHTMLDOMNode_Release(&node
->IHTMLDOMNode_iface
);
815 FIXME("The element is not in parent's child list?\n");
823 static IHTMLElementCollection
*HTMLElementCollection_Create(HTMLElement
**elems
, DWORD len
)
825 HTMLElementCollection
*ret
= heap_alloc_zero(sizeof(HTMLElementCollection
));
830 ret
->IHTMLElementCollection_iface
.lpVtbl
= &HTMLElementCollectionVtbl
;
835 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLElementCollection_iface
,
836 &HTMLElementCollection_dispex
);
838 TRACE("ret=%p len=%d\n", ret
, len
);
840 return &ret
->IHTMLElementCollection_iface
;