From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlnode.c | 167 +++++------------------------------------ 1 file changed, 20 insertions(+), 147 deletions(-)
diff --git a/dlls/mshtml/htmlnode.c b/dlls/mshtml/htmlnode.c index 0d9a5259935..846bf1382a5 100644 --- a/dlls/mshtml/htmlnode.c +++ b/dlls/mshtml/htmlnode.c @@ -43,153 +43,44 @@ typedef struct { nsIDOMNodeList *nslist; } HTMLDOMChildrenCollection;
-typedef struct { - IEnumVARIANT IEnumVARIANT_iface; - - LONG ref; - - ULONG iter; - HTMLDOMChildrenCollection *col; -} HTMLDOMChildrenCollectionEnum; - -static inline HTMLDOMChildrenCollectionEnum *impl_from_IEnumVARIANT(IEnumVARIANT *iface) -{ - return CONTAINING_RECORD(iface, HTMLDOMChildrenCollectionEnum, IEnumVARIANT_iface); -} - -static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv) -{ - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - - TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv); - - if(IsEqualGUID(riid, &IID_IUnknown)) { - *ppv = &This->IEnumVARIANT_iface; - }else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) { - *ppv = &This->IEnumVARIANT_iface; - }else { - FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv); - *ppv = NULL; - return E_NOINTERFACE; - } - - IUnknown_AddRef((IUnknown*)*ppv); - return S_OK; -} - -static ULONG WINAPI HTMLDOMChildrenCollectionEnum_AddRef(IEnumVARIANT *iface) -{ - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - LONG ref = InterlockedIncrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - return ref; -} - -static ULONG WINAPI HTMLDOMChildrenCollectionEnum_Release(IEnumVARIANT *iface) +static inline HTMLDOMChildrenCollection *impl_from_DispatchEx(DispatchEx *iface) { - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - LONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - if(!ref) { - IHTMLDOMChildrenCollection_Release(&This->col->IHTMLDOMChildrenCollection_iface); - free(This); - } - - return ref; + return CONTAINING_RECORD(iface, HTMLDOMChildrenCollection, dispex); }
-static ULONG get_enum_len(HTMLDOMChildrenCollectionEnum *This) +static ULONG HTMLDOMChildrenCollectionEnum_get_length(DispatchEx *dispex) { - UINT32 len; + HTMLDOMChildrenCollection *col = impl_from_DispatchEx(dispex); nsresult nsres; + UINT32 len;
- nsres = nsIDOMNodeList_GetLength(This->col->nslist, &len); + nsres = nsIDOMNodeList_GetLength(col->nslist, &len); assert(nsres == NS_OK); return len; }
-static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched) +static HRESULT HTMLDOMChildrenCollectionEnum_get_item(DispatchEx *dispex, ULONG index, IDispatch **p) { - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - ULONG fetched = 0, len; + HTMLDOMChildrenCollection *col = impl_from_DispatchEx(dispex); nsIDOMNode *nsnode; HTMLDOMNode *node; nsresult nsres; HRESULT hres;
- TRACE("(%p)->(%ld %p %p)\n", This, celt, rgVar, pCeltFetched); - - len = get_enum_len(This); - - while(This->iter+fetched < len && fetched < celt) { - nsres = nsIDOMNodeList_Item(This->col->nslist, This->iter+fetched, &nsnode); - assert(nsres == NS_OK); - - hres = get_node(nsnode, TRUE, &node); - nsIDOMNode_Release(nsnode); - if(FAILED(hres)) { - while(fetched--) - VariantClear(rgVar+fetched); - return hres; - } - - V_VT(rgVar+fetched) = VT_DISPATCH; - V_DISPATCH(rgVar+fetched) = (IDispatch*)&node->IHTMLDOMNode_iface; - fetched++; - } - - This->iter += fetched; - if(pCeltFetched) - *pCeltFetched = fetched; - return fetched == celt ? S_OK : S_FALSE; -} - -static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt) -{ - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - ULONG len; - - TRACE("(%p)->(%ld)\n", This, celt); - - len = get_enum_len(This); - if(This->iter + celt > len) { - This->iter = len; - return S_FALSE; - } - - This->iter += celt; - return S_OK; -} - -static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_Reset(IEnumVARIANT *iface) -{ - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - - TRACE("(%p)->()\n", This); - - This->iter = 0; - return S_OK; -} + nsres = nsIDOMNodeList_Item(col->nslist, index, &nsnode); + if(NS_FAILED(nsres)) + return map_nsresult(nsres);
-static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum) -{ - HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface); - FIXME("(%p)->(%p)\n", This, ppEnum); - return E_NOTIMPL; + hres = get_node(nsnode, TRUE, &node); + nsIDOMNode_Release(nsnode); + if(SUCCEEDED(hres)) + *p = (IDispatch*)&node->IHTMLDOMNode_iface; + return hres; }
-static const IEnumVARIANTVtbl HTMLDOMChildrenCollectionEnumVtbl = { - HTMLDOMChildrenCollectionEnum_QueryInterface, - HTMLDOMChildrenCollectionEnum_AddRef, - HTMLDOMChildrenCollectionEnum_Release, - HTMLDOMChildrenCollectionEnum_Next, - HTMLDOMChildrenCollectionEnum_Skip, - HTMLDOMChildrenCollectionEnum_Reset, - HTMLDOMChildrenCollectionEnum_Clone +static const CollectionEnum_vtbl HTMLDOMChildrenCollectionEnum_vtbl = { + HTMLDOMChildrenCollectionEnum_get_length, + HTMLDOMChildrenCollectionEnum_get_item, };
static inline HTMLDOMChildrenCollection *impl_from_IHTMLDOMChildrenCollection(IHTMLDOMChildrenCollection *iface) @@ -215,23 +106,10 @@ static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenColle static HRESULT WINAPI HTMLDOMChildrenCollection_get__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p) { HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface); - HTMLDOMChildrenCollectionEnum *ret;
TRACE("(%p)->(%p)\n", This, p);
- ret = malloc(sizeof(*ret)); - if(!ret) - return E_OUTOFMEMORY; - - ret->IEnumVARIANT_iface.lpVtbl = &HTMLDOMChildrenCollectionEnumVtbl; - ret->ref = 1; - ret->iter = 0; - - IHTMLDOMChildrenCollection_AddRef(&This->IHTMLDOMChildrenCollection_iface); - ret->col = This; - - *p = (IUnknown*)&ret->IEnumVARIANT_iface; - return S_OK; + return CollectionEnum_create(&This->dispex, &HTMLDOMChildrenCollectionEnum_vtbl, p); }
static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, LONG index, IDispatch **ppItem) @@ -282,11 +160,6 @@ static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = { HTMLDOMChildrenCollection_item };
-static inline HTMLDOMChildrenCollection *impl_from_DispatchEx(DispatchEx *iface) -{ - return CONTAINING_RECORD(iface, HTMLDOMChildrenCollection, dispex); -} - static void *HTMLDOMChildrenCollection_query_interface(DispatchEx *dispex, REFIID riid) { HTMLDOMChildrenCollection *This = impl_from_DispatchEx(dispex);