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 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
222 *ppv
= &This
->IHTMLElementCollection_iface
;
223 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
224 *ppv
= &This
->IHTMLElementCollection_iface
;
225 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
226 return *ppv
? S_OK
: E_NOINTERFACE
;
229 FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid
));
230 return E_NOINTERFACE
;
233 IHTMLElementCollection_AddRef(&This
->IHTMLElementCollection_iface
);
237 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
239 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
240 LONG ref
= InterlockedIncrement(&This
->ref
);
242 TRACE("(%p) ref=%d\n", This
, ref
);
247 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
249 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
250 LONG ref
= InterlockedDecrement(&This
->ref
);
252 TRACE("(%p) ref=%d\n", This
, ref
);
257 for(i
=0; i
< This
->len
; i
++)
258 node_release(&This
->elems
[i
]->node
);
259 heap_free(This
->elems
);
261 release_dispex(&This
->dispex
);
268 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
271 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
272 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
275 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
276 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
278 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
279 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
282 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
283 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
285 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
286 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
290 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
291 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
292 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
294 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
295 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
296 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
299 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
302 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
303 FIXME("(%p)->(%p)\n", This
, String
);
307 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
310 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
311 FIXME("(%p)->(%d)\n", This
, v
);
315 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
318 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
320 TRACE("(%p)->(%p)\n", This
, p
);
326 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
329 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
330 HTMLElementCollectionEnum
*ret
;
332 TRACE("(%p)->(%p)\n", This
, p
);
334 ret
= heap_alloc(sizeof(*ret
));
336 return E_OUTOFMEMORY
;
338 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLElementCollectionEnumVtbl
;
342 IHTMLElementCollection_AddRef(&This
->IHTMLElementCollection_iface
);
345 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
349 static BOOL
is_elem_id(HTMLElement
*elem
, LPCWSTR name
)
354 hres
= IHTMLElement_get_id(&elem
->IHTMLElement_iface
, &elem_id
);
356 WARN("IHTMLElement_get_id failed: 0x%08x\n", hres
);
360 if(elem_id
&& !strcmpW(elem_id
, name
)) {
361 SysFreeString(elem_id
);
365 SysFreeString(elem_id
);
369 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
371 const PRUnichar
*str
;
376 static const PRUnichar nameW
[] = {'n','a','m','e',0};
381 nsAString_Init(&nsstr
, NULL
);
382 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
383 nsAString_GetData(&nsstr
, &str
);
384 if(!strcmpiW(str
, name
)) {
385 nsAString_Finish(&nsstr
);
389 nsres
= get_elem_attr_value(elem
->nselem
, nameW
, &nsstr
, &str
);
390 if(NS_SUCCEEDED(nsres
)) {
391 ret
= !strcmpiW(str
, name
);
392 nsAString_Finish(&nsstr
);
398 static HRESULT
get_item_idx(HTMLElementCollection
*This
, UINT idx
, IDispatch
**ret
)
400 if(idx
< This
->len
) {
401 *ret
= (IDispatch
*)This
->elems
[idx
];
402 IDispatch_AddRef(*ret
);
408 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
409 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
411 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
414 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
418 switch(V_VT(&name
)) {
422 hres
= get_item_idx(This
, V_I4(&name
), pdisp
);
426 hres
= get_item_idx(This
, V_UINT(&name
), pdisp
);
432 if(V_VT(&index
) == VT_I4
) {
433 LONG idx
= V_I4(&index
);
438 for(i
=0; i
<This
->len
; i
++) {
439 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
444 *pdisp
= (IDispatch
*)&This
->elems
[i
]->IHTMLElement_iface
;
445 IDispatch_AddRef(*pdisp
);
448 elem_vector_t buf
= {NULL
, 0, 8};
450 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
452 for(i
=0; i
<This
->len
; i
++) {
453 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
))) {
454 node_addref(&This
->elems
[i
]->node
);
455 elem_vector_add(&buf
, This
->elems
[i
]);
460 elem_vector_normalize(&buf
);
461 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(buf
.buf
, buf
.len
);
464 /* Already AddRef-ed */
465 *pdisp
= (IDispatch
*)&buf
.buf
[0]->IHTMLElement_iface
;
475 FIXME("Unsupported name %s\n", debugstr_variant(&name
));
480 TRACE("returning %p\n", *pdisp
);
484 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
485 VARIANT tagName
, IDispatch
**pdisp
)
487 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
490 const PRUnichar
*tag
;
491 elem_vector_t buf
= {NULL
, 0, 8};
493 if(V_VT(&tagName
) != VT_BSTR
) {
494 WARN("Invalid arg\n");
495 return DISP_E_MEMBERNOTFOUND
;
498 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
500 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
502 nsAString_Init(&tag_str
, NULL
);
504 for(i
=0; i
<This
->len
; i
++) {
505 if(!This
->elems
[i
]->nselem
)
508 nsIDOMHTMLElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
509 nsAString_GetData(&tag_str
, &tag
);
511 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
512 V_BSTR(&tagName
), -1) == CSTR_EQUAL
) {
513 node_addref(&This
->elems
[i
]->node
);
514 elem_vector_add(&buf
, This
->elems
[i
]);
518 nsAString_Finish(&tag_str
);
519 elem_vector_normalize(&buf
);
521 TRACE("fount %d tags\n", buf
.len
);
523 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(buf
.buf
, buf
.len
);
527 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
528 HTMLElementCollection_QueryInterface
,
529 HTMLElementCollection_AddRef
,
530 HTMLElementCollection_Release
,
531 HTMLElementCollection_GetTypeInfoCount
,
532 HTMLElementCollection_GetTypeInfo
,
533 HTMLElementCollection_GetIDsOfNames
,
534 HTMLElementCollection_Invoke
,
535 HTMLElementCollection_toString
,
536 HTMLElementCollection_put_length
,
537 HTMLElementCollection_get_length
,
538 HTMLElementCollection_get__newEnum
,
539 HTMLElementCollection_item
,
540 HTMLElementCollection_tags
543 static inline HTMLElementCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
545 return CONTAINING_RECORD(iface
, HTMLElementCollection
, dispex
);
548 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
550 static HRESULT
HTMLElementCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
552 HTMLElementCollection
*This
= impl_from_DispatchEx(dispex
);
557 return DISP_E_UNKNOWNNAME
;
559 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
560 idx
= idx
*10 + (*ptr
-'0');
563 /* the name contains alpha characters, so search by name & id */
564 for(idx
= 0; idx
< This
->len
; ++idx
) {
565 if(is_elem_id(This
->elems
[idx
], name
) ||
566 is_elem_name(This
->elems
[idx
], name
))
572 return DISP_E_UNKNOWNNAME
;
574 *dispid
= DISPID_ELEMCOL_0
+ idx
;
575 TRACE("ret %x\n", *dispid
);
579 static HRESULT
HTMLElementCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
580 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
582 HTMLElementCollection
*This
= impl_from_DispatchEx(dispex
);
585 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
587 idx
= id
- DISPID_ELEMCOL_0
;
589 return DISP_E_UNKNOWNNAME
;
592 case DISPATCH_PROPERTYGET
:
593 V_VT(res
) = VT_DISPATCH
;
594 V_DISPATCH(res
) = (IDispatch
*)&This
->elems
[idx
]->IHTMLElement_iface
;
595 IHTMLElement_AddRef(&This
->elems
[idx
]->IHTMLElement_iface
);
598 FIXME("unimplemented flags %x\n", flags
);
605 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl
= {
607 HTMLElementCollection_get_dispid
,
608 HTMLElementCollection_invoke
,
612 static const tid_t HTMLElementCollection_iface_tids
[] = {
613 IHTMLElementCollection_tid
,
617 static dispex_static_data_t HTMLElementCollection_dispex
= {
618 &HTMLElementColection_dispex_vtbl
,
619 DispHTMLElementCollection_tid
,
621 HTMLElementCollection_iface_tids
624 static void create_all_list(HTMLDocumentNode
*doc
, HTMLDOMNode
*elem
, elem_vector_t
*buf
)
626 nsIDOMNodeList
*nsnode_list
;
628 UINT32 list_len
= 0, i
;
632 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
633 if(NS_FAILED(nsres
)) {
634 ERR("GetChildNodes failed: %08x\n", nsres
);
638 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
642 for(i
=0; i
<list_len
; i
++) {
643 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
644 if(NS_FAILED(nsres
)) {
645 ERR("Item failed: %08x\n", nsres
);
649 if(is_elem_node(iter
)) {
652 hres
= get_node(doc
, iter
, TRUE
, &node
);
654 FIXME("get_node failed: %08x\n", hres
);
658 elem_vector_add(buf
, elem_from_HTMLDOMNode(node
));
659 create_all_list(doc
, node
, buf
);
664 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
, BOOL include_root
)
666 elem_vector_t buf
= {NULL
, 0, 8};
668 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
672 elem_vector_add(&buf
, elem_from_HTMLDOMNode(node
));
674 create_all_list(node
->doc
, node
, &buf
);
675 elem_vector_normalize(&buf
);
677 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
680 IHTMLElementCollection
*create_collection_from_nodelist(HTMLDocumentNode
*doc
, nsIDOMNodeList
*nslist
)
682 UINT32 length
= 0, i
;
687 nsIDOMNodeList_GetLength(nslist
, &length
);
694 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
696 for(i
=0; i
<length
; i
++) {
697 nsIDOMNodeList_Item(nslist
, i
, &nsnode
);
698 if(is_elem_node(nsnode
)) {
699 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
702 buf
.buf
[buf
.len
++] = elem_from_HTMLDOMNode(node
);
704 nsIDOMNode_Release(nsnode
);
707 elem_vector_normalize(&buf
);
712 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
715 IHTMLElementCollection
*create_collection_from_htmlcol(HTMLDocumentNode
*doc
, nsIDOMHTMLCollection
*nscol
)
717 UINT32 length
= 0, i
;
722 nsIDOMHTMLCollection_GetLength(nscol
, &length
);
724 buf
.len
= buf
.size
= length
;
728 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
730 for(i
=0; i
<length
; i
++) {
731 nsIDOMHTMLCollection_Item(nscol
, i
, &nsnode
);
732 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
733 nsIDOMNode_Release(nsnode
);
736 buf
.buf
[i
] = elem_from_HTMLDOMNode(node
);
747 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
750 HRESULT
get_elem_source_index(HTMLElement
*elem
, LONG
*ret
)
752 elem_vector_t buf
= {NULL
, 0, 8};
753 nsIDOMNode
*parent_node
, *iter
;
760 iter
= elem
->node
.nsnode
;
761 nsIDOMNode_AddRef(iter
);
763 /* Find document or document fragment parent. */
765 nsres
= nsIDOMNode_GetParentNode(iter
, &parent_node
);
766 nsIDOMNode_Release(iter
);
767 assert(nsres
== NS_OK
);
771 nsres
= nsIDOMNode_GetNodeType(parent_node
, &parent_type
);
772 assert(nsres
== NS_OK
);
774 if(parent_type
!= ELEMENT_NODE
) {
775 if(parent_type
!= DOCUMENT_NODE
&& parent_type
!= DOCUMENT_FRAGMENT_NODE
)
776 FIXME("Unexpected parent_type %d\n", parent_type
);
788 hres
= get_node(elem
->node
.doc
, parent_node
, TRUE
, &node
);
789 nsIDOMNode_Release(parent_node
);
794 /* Create all children collection and find the element in it.
795 * This could be optimized if we ever find the reason. */
796 buf
.buf
= heap_alloc(buf
.size
*sizeof(*buf
.buf
));
798 IHTMLDOMNode_Release(&node
->IHTMLDOMNode_iface
);
799 return E_OUTOFMEMORY
;
802 create_all_list(elem
->node
.doc
, node
, &buf
);
804 for(i
=0; i
< buf
.len
; i
++) {
805 if(buf
.buf
[i
] == elem
)
808 IHTMLDOMNode_Release(&node
->IHTMLDOMNode_iface
);
811 FIXME("The element is not in parent's child list?\n");
819 static IHTMLElementCollection
*HTMLElementCollection_Create(HTMLElement
**elems
, DWORD len
)
821 HTMLElementCollection
*ret
= heap_alloc_zero(sizeof(HTMLElementCollection
));
823 ret
->IHTMLElementCollection_iface
.lpVtbl
= &HTMLElementCollectionVtbl
;
828 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLElementCollection_iface
,
829 &HTMLElementCollection_dispex
);
831 TRACE("ret=%p len=%d\n", ret
, len
);
833 return &ret
->IHTMLElementCollection_iface
;