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
19 #include "mshtml_private.h"
23 IHTMLElementCollection IHTMLElementCollection_iface
;
29 } HTMLElementCollection
;
32 IEnumVARIANT IEnumVARIANT_iface
;
37 HTMLElementCollection
*col
;
38 } HTMLElementCollectionEnum
;
46 /* FIXME: Handle it better way */
47 static inline HTMLElement
*elem_from_HTMLDOMNode(HTMLDOMNode
*iface
)
49 return CONTAINING_RECORD(iface
, HTMLElement
, node
);
52 static IHTMLElementCollection
*HTMLElementCollection_Create(HTMLElement
**elems
, DWORD len
);
54 static void elem_vector_add(elem_vector_t
*buf
, HTMLElement
*elem
)
56 if(buf
->len
== buf
->size
) {
58 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
*sizeof(HTMLElement
*));
61 buf
->buf
[buf
->len
++] = elem
;
64 static void elem_vector_normalize(elem_vector_t
*buf
)
69 }else if(buf
->size
> buf
->len
) {
70 buf
->buf
= heap_realloc(buf
->buf
, buf
->len
*sizeof(HTMLElement
*));
76 static inline BOOL
is_elem_node(nsIDOMNode
*node
)
80 nsIDOMNode_GetNodeType(node
, &type
);
82 return type
== ELEMENT_NODE
|| type
== COMMENT_NODE
;
85 static inline HTMLElementCollectionEnum
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
87 return CONTAINING_RECORD(iface
, HTMLElementCollectionEnum
, IEnumVARIANT_iface
);
90 static HRESULT WINAPI
HTMLElementCollectionEnum_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
92 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
94 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
96 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
97 *ppv
= &This
->IEnumVARIANT_iface
;
98 }else if(IsEqualGUID(riid
, &IID_IEnumVARIANT
)) {
99 *ppv
= &This
->IEnumVARIANT_iface
;
101 FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid
));
103 return E_NOINTERFACE
;
106 IUnknown_AddRef((IUnknown
*)*ppv
);
110 static ULONG WINAPI
HTMLElementCollectionEnum_AddRef(IEnumVARIANT
*iface
)
112 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
113 LONG ref
= InterlockedIncrement(&This
->ref
);
115 TRACE("(%p) ref=%d\n", This
, ref
);
120 static ULONG WINAPI
HTMLElementCollectionEnum_Release(IEnumVARIANT
*iface
)
122 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
123 LONG ref
= InterlockedDecrement(&This
->ref
);
125 TRACE("(%p) ref=%d\n", This
, ref
);
128 IHTMLElementCollection_Release(&This
->col
->IHTMLElementCollection_iface
);
135 static HRESULT WINAPI
HTMLElementCollectionEnum_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
137 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
140 TRACE("(%p)->(%d %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
142 while(This
->iter
+fetched
< This
->col
->len
&& fetched
< celt
) {
143 V_VT(rgVar
+fetched
) = VT_DISPATCH
;
144 V_DISPATCH(rgVar
+fetched
) = (IDispatch
*)&This
->col
->elems
[This
->iter
+fetched
]->IHTMLElement_iface
;
145 IDispatch_AddRef(V_DISPATCH(rgVar
+fetched
));
149 This
->iter
+= fetched
;
151 *pCeltFetched
= fetched
;
152 return fetched
== celt
? S_OK
: S_FALSE
;
155 static HRESULT WINAPI
HTMLElementCollectionEnum_Skip(IEnumVARIANT
*iface
, ULONG celt
)
157 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
159 TRACE("(%p)->(%d)\n", This
, celt
);
161 if(This
->iter
+ celt
> This
->col
->len
) {
162 This
->iter
= This
->col
->len
;
170 static HRESULT WINAPI
HTMLElementCollectionEnum_Reset(IEnumVARIANT
*iface
)
172 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
174 TRACE("(%p)->()\n", This
);
180 static HRESULT WINAPI
HTMLElementCollectionEnum_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
182 HTMLElementCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
183 FIXME("(%p)->(%p)\n", This
, ppEnum
);
187 static const IEnumVARIANTVtbl HTMLElementCollectionEnumVtbl
= {
188 HTMLElementCollectionEnum_QueryInterface
,
189 HTMLElementCollectionEnum_AddRef
,
190 HTMLElementCollectionEnum_Release
,
191 HTMLElementCollectionEnum_Next
,
192 HTMLElementCollectionEnum_Skip
,
193 HTMLElementCollectionEnum_Reset
,
194 HTMLElementCollectionEnum_Clone
197 static inline HTMLElementCollection
*impl_from_IHTMLElementCollection(IHTMLElementCollection
*iface
)
199 return CONTAINING_RECORD(iface
, HTMLElementCollection
, IHTMLElementCollection_iface
);
202 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
203 REFIID riid
, void **ppv
)
205 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
207 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
208 *ppv
= &This
->IHTMLElementCollection_iface
;
209 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
210 *ppv
= &This
->IHTMLElementCollection_iface
;
211 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
212 return *ppv
? S_OK
: E_NOINTERFACE
;
215 FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid
));
216 return E_NOINTERFACE
;
219 IHTMLElementCollection_AddRef(&This
->IHTMLElementCollection_iface
);
223 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
225 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
226 LONG ref
= InterlockedIncrement(&This
->ref
);
228 TRACE("(%p) ref=%d\n", This
, ref
);
233 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
235 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
236 LONG ref
= InterlockedDecrement(&This
->ref
);
238 TRACE("(%p) ref=%d\n", This
, ref
);
243 for(i
=0; i
< This
->len
; i
++)
244 node_release(&This
->elems
[i
]->node
);
245 heap_free(This
->elems
);
247 release_dispex(&This
->dispex
);
254 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
257 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
258 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
261 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
262 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
264 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
265 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
268 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
269 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
271 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
272 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
276 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
277 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
278 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
280 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
281 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
282 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
285 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
288 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
289 FIXME("(%p)->(%p)\n", This
, String
);
293 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
296 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
297 FIXME("(%p)->(%d)\n", This
, v
);
301 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
304 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
306 TRACE("(%p)->(%p)\n", This
, p
);
312 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
315 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
316 HTMLElementCollectionEnum
*ret
;
318 TRACE("(%p)->(%p)\n", This
, p
);
320 ret
= heap_alloc(sizeof(*ret
));
322 return E_OUTOFMEMORY
;
324 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLElementCollectionEnumVtbl
;
328 IHTMLElementCollection_AddRef(&This
->IHTMLElementCollection_iface
);
331 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
335 static BOOL
is_elem_id(HTMLElement
*elem
, LPCWSTR name
)
340 hres
= IHTMLElement_get_id(&elem
->IHTMLElement_iface
, &elem_id
);
342 WARN("IHTMLElement_get_id failed: 0x%08x\n", hres
);
346 if(elem_id
&& !strcmpW(elem_id
, name
)) {
347 SysFreeString(elem_id
);
351 SysFreeString(elem_id
);
355 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
357 const PRUnichar
*str
;
362 static const PRUnichar nameW
[] = {'n','a','m','e',0};
367 nsAString_Init(&nsstr
, NULL
);
368 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
369 nsAString_GetData(&nsstr
, &str
);
370 if(!strcmpiW(str
, name
)) {
371 nsAString_Finish(&nsstr
);
375 nsres
= get_elem_attr_value(elem
->nselem
, nameW
, &nsstr
, &str
);
376 if(NS_SUCCEEDED(nsres
)) {
377 ret
= !strcmpiW(str
, name
);
378 nsAString_Finish(&nsstr
);
384 static HRESULT
get_item_idx(HTMLElementCollection
*This
, UINT idx
, IDispatch
**ret
)
386 if(idx
< This
->len
) {
387 *ret
= (IDispatch
*)This
->elems
[idx
];
388 IDispatch_AddRef(*ret
);
394 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
395 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
397 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
400 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
404 switch(V_VT(&name
)) {
408 hres
= get_item_idx(This
, V_I4(&name
), pdisp
);
412 hres
= get_item_idx(This
, V_UINT(&name
), pdisp
);
418 if(V_VT(&index
) == VT_I4
) {
419 LONG idx
= V_I4(&index
);
424 for(i
=0; i
<This
->len
; i
++) {
425 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
430 *pdisp
= (IDispatch
*)&This
->elems
[i
]->IHTMLElement_iface
;
431 IDispatch_AddRef(*pdisp
);
434 elem_vector_t buf
= {NULL
, 0, 8};
436 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
438 for(i
=0; i
<This
->len
; i
++) {
439 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
))) {
440 node_addref(&This
->elems
[i
]->node
);
441 elem_vector_add(&buf
, This
->elems
[i
]);
446 elem_vector_normalize(&buf
);
447 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(buf
.buf
, buf
.len
);
450 /* Already AddRef-ed */
451 *pdisp
= (IDispatch
*)&buf
.buf
[0]->IHTMLElement_iface
;
461 FIXME("Unsupported name %s\n", debugstr_variant(&name
));
466 TRACE("returning %p\n", *pdisp
);
470 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
471 VARIANT tagName
, IDispatch
**pdisp
)
473 HTMLElementCollection
*This
= impl_from_IHTMLElementCollection(iface
);
476 const PRUnichar
*tag
;
477 elem_vector_t buf
= {NULL
, 0, 8};
479 if(V_VT(&tagName
) != VT_BSTR
) {
480 WARN("Invalid arg\n");
481 return DISP_E_MEMBERNOTFOUND
;
484 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
486 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
488 nsAString_Init(&tag_str
, NULL
);
490 for(i
=0; i
<This
->len
; i
++) {
491 if(!This
->elems
[i
]->nselem
)
494 nsIDOMHTMLElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
495 nsAString_GetData(&tag_str
, &tag
);
497 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
498 V_BSTR(&tagName
), -1) == CSTR_EQUAL
) {
499 node_addref(&This
->elems
[i
]->node
);
500 elem_vector_add(&buf
, This
->elems
[i
]);
504 nsAString_Finish(&tag_str
);
505 elem_vector_normalize(&buf
);
507 TRACE("fount %d tags\n", buf
.len
);
509 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(buf
.buf
, buf
.len
);
513 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
514 HTMLElementCollection_QueryInterface
,
515 HTMLElementCollection_AddRef
,
516 HTMLElementCollection_Release
,
517 HTMLElementCollection_GetTypeInfoCount
,
518 HTMLElementCollection_GetTypeInfo
,
519 HTMLElementCollection_GetIDsOfNames
,
520 HTMLElementCollection_Invoke
,
521 HTMLElementCollection_toString
,
522 HTMLElementCollection_put_length
,
523 HTMLElementCollection_get_length
,
524 HTMLElementCollection_get__newEnum
,
525 HTMLElementCollection_item
,
526 HTMLElementCollection_tags
529 static inline HTMLElementCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
531 return CONTAINING_RECORD(iface
, HTMLElementCollection
, dispex
);
534 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
536 static HRESULT
HTMLElementCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
538 HTMLElementCollection
*This
= impl_from_DispatchEx(dispex
);
543 return DISP_E_UNKNOWNNAME
;
545 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
546 idx
= idx
*10 + (*ptr
-'0');
549 /* the name contains alpha characters, so search by name & id */
550 for(idx
= 0; idx
< This
->len
; ++idx
) {
551 if(is_elem_id(This
->elems
[idx
], name
) ||
552 is_elem_name(This
->elems
[idx
], name
))
558 return DISP_E_UNKNOWNNAME
;
560 *dispid
= DISPID_ELEMCOL_0
+ idx
;
561 TRACE("ret %x\n", *dispid
);
565 static HRESULT
HTMLElementCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
566 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
568 HTMLElementCollection
*This
= impl_from_DispatchEx(dispex
);
571 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
573 idx
= id
- DISPID_ELEMCOL_0
;
575 return DISP_E_UNKNOWNNAME
;
578 case DISPATCH_PROPERTYGET
:
579 V_VT(res
) = VT_DISPATCH
;
580 V_DISPATCH(res
) = (IDispatch
*)&This
->elems
[idx
]->IHTMLElement_iface
;
581 IHTMLElement_AddRef(&This
->elems
[idx
]->IHTMLElement_iface
);
584 FIXME("unimplemented flags %x\n", flags
);
591 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl
= {
593 HTMLElementCollection_get_dispid
,
594 HTMLElementCollection_invoke
,
598 static const tid_t HTMLElementCollection_iface_tids
[] = {
599 IHTMLElementCollection_tid
,
603 static dispex_static_data_t HTMLElementCollection_dispex
= {
604 &HTMLElementColection_dispex_vtbl
,
605 DispHTMLElementCollection_tid
,
607 HTMLElementCollection_iface_tids
610 static void create_all_list(HTMLDocumentNode
*doc
, HTMLDOMNode
*elem
, elem_vector_t
*buf
)
612 nsIDOMNodeList
*nsnode_list
;
614 UINT32 list_len
= 0, i
;
618 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
619 if(NS_FAILED(nsres
)) {
620 ERR("GetChildNodes failed: %08x\n", nsres
);
624 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
628 for(i
=0; i
<list_len
; i
++) {
629 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
630 if(NS_FAILED(nsres
)) {
631 ERR("Item failed: %08x\n", nsres
);
635 if(is_elem_node(iter
)) {
638 hres
= get_node(doc
, iter
, TRUE
, &node
);
640 FIXME("get_node failed: %08x\n", hres
);
644 elem_vector_add(buf
, elem_from_HTMLDOMNode(node
));
645 create_all_list(doc
, node
, buf
);
650 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
, BOOL include_root
)
652 elem_vector_t buf
= {NULL
, 0, 8};
654 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
658 elem_vector_add(&buf
, elem_from_HTMLDOMNode(node
));
660 create_all_list(node
->doc
, node
, &buf
);
661 elem_vector_normalize(&buf
);
663 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
666 IHTMLElementCollection
*create_collection_from_nodelist(HTMLDocumentNode
*doc
, nsIDOMNodeList
*nslist
)
668 UINT32 length
= 0, i
;
673 nsIDOMNodeList_GetLength(nslist
, &length
);
680 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
682 for(i
=0; i
<length
; i
++) {
683 nsIDOMNodeList_Item(nslist
, i
, &nsnode
);
684 if(is_elem_node(nsnode
)) {
685 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
688 buf
.buf
[buf
.len
++] = elem_from_HTMLDOMNode(node
);
690 nsIDOMNode_Release(nsnode
);
693 elem_vector_normalize(&buf
);
698 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
701 IHTMLElementCollection
*create_collection_from_htmlcol(HTMLDocumentNode
*doc
, nsIDOMHTMLCollection
*nscol
)
703 UINT32 length
= 0, i
;
708 nsIDOMHTMLCollection_GetLength(nscol
, &length
);
710 buf
.len
= buf
.size
= length
;
714 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
716 for(i
=0; i
<length
; i
++) {
717 nsIDOMHTMLCollection_Item(nscol
, i
, &nsnode
);
718 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
719 nsIDOMNode_Release(nsnode
);
722 buf
.buf
[i
] = elem_from_HTMLDOMNode(node
);
733 return HTMLElementCollection_Create(buf
.buf
, buf
.len
);
736 HRESULT
get_elem_source_index(HTMLElement
*elem
, LONG
*ret
)
738 elem_vector_t buf
= {NULL
, 0, 8};
739 nsIDOMNode
*parent_node
, *iter
;
746 iter
= elem
->node
.nsnode
;
747 nsIDOMNode_AddRef(iter
);
749 /* Find document or document fragment parent. */
751 nsres
= nsIDOMNode_GetParentNode(iter
, &parent_node
);
752 nsIDOMNode_Release(iter
);
753 assert(nsres
== NS_OK
);
757 nsres
= nsIDOMNode_GetNodeType(parent_node
, &parent_type
);
758 assert(nsres
== NS_OK
);
760 if(parent_type
!= ELEMENT_NODE
) {
761 if(parent_type
!= DOCUMENT_NODE
&& parent_type
!= DOCUMENT_FRAGMENT_NODE
)
762 FIXME("Unexpected parent_type %d\n", parent_type
);
774 hres
= get_node(elem
->node
.doc
, parent_node
, TRUE
, &node
);
775 nsIDOMNode_Release(parent_node
);
780 /* Create all children collection and find the element in it.
781 * This could be optimized if we ever find the reason. */
782 buf
.buf
= heap_alloc(buf
.size
*sizeof(*buf
.buf
));
784 IHTMLDOMNode_Release(&node
->IHTMLDOMNode_iface
);
785 return E_OUTOFMEMORY
;
788 create_all_list(elem
->node
.doc
, node
, &buf
);
790 for(i
=0; i
< buf
.len
; i
++) {
791 if(buf
.buf
[i
] == elem
)
794 IHTMLDOMNode_Release(&node
->IHTMLDOMNode_iface
);
797 FIXME("The element is not in parent's child list?\n");
805 static IHTMLElementCollection
*HTMLElementCollection_Create(HTMLElement
**elems
, DWORD len
)
807 HTMLElementCollection
*ret
= heap_alloc_zero(sizeof(HTMLElementCollection
));
809 ret
->IHTMLElementCollection_iface
.lpVtbl
= &HTMLElementCollectionVtbl
;
814 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLElementCollection_iface
,
815 &HTMLElementCollection_dispex
);
817 TRACE("ret=%p len=%d\n", ret
, len
);
819 return &ret
->IHTMLElementCollection_iface
;