From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlelem.c | 162 +++++++---------------------------------- 1 file changed, 26 insertions(+), 136 deletions(-)
diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index 354f521697c..e12b032dfb8 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -815,137 +815,45 @@ typedef struct { nsIDOMClientRectList *rect_list; } HTMLRectCollection;
-typedef struct { - IEnumVARIANT IEnumVARIANT_iface; - - LONG ref; - - ULONG iter; - HTMLRectCollection *col; -} HTMLRectCollectionEnum; - -static inline HTMLRectCollectionEnum *HTMLRectCollectionEnum_from_IEnumVARIANT(IEnumVARIANT *iface) -{ - return CONTAINING_RECORD(iface, HTMLRectCollectionEnum, IEnumVARIANT_iface); -} - -static HRESULT WINAPI HTMLRectCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv) -{ - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_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 HTMLRectCollectionEnum_AddRef(IEnumVARIANT *iface) -{ - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_from_IEnumVARIANT(iface); - LONG ref = InterlockedIncrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - return ref; -} - -static ULONG WINAPI HTMLRectCollectionEnum_Release(IEnumVARIANT *iface) +static inline HTMLRectCollection *HTMLRectCollection_from_DispatchEx(DispatchEx *iface) { - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_from_IEnumVARIANT(iface); - LONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - if(!ref) { - IHTMLRectCollection_Release(&This->col->IHTMLRectCollection_iface); - free(This); - } - - return ref; + return CONTAINING_RECORD(iface, HTMLRectCollection, dispex); }
-static HRESULT WINAPI HTMLRectCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched) +static ULONG HTMLRectCollectionEnum_get_length(DispatchEx *dispex) { - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_from_IEnumVARIANT(iface); - VARIANT index; - HRESULT hres; - ULONG num, i; + HTMLRectCollection *col = HTMLRectCollection_from_DispatchEx(dispex); + nsresult nsres; UINT32 len;
- TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched); - - nsIDOMClientRectList_GetLength(This->col->rect_list, &len); - num = min(len - This->iter, celt); - V_VT(&index) = VT_I4; - - for(i = 0; i < num; i++) { - V_I4(&index) = This->iter + i; - hres = IHTMLRectCollection_item(&This->col->IHTMLRectCollection_iface, &index, &rgVar[i]); - if(FAILED(hres)) { - while(i--) - VariantClear(&rgVar[i]); - return hres; - } - } - - This->iter += num; - if(pCeltFetched) - *pCeltFetched = num; - return num == celt ? S_OK : S_FALSE; + nsres = nsIDOMClientRectList_GetLength(col->rect_list, &len); + assert(nsres == NS_OK); + return len; }
-static HRESULT WINAPI HTMLRectCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt) +static HRESULT HTMLRectCollectionEnum_get_item(DispatchEx *dispex, ULONG index, IDispatch **p) { - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_from_IEnumVARIANT(iface); - UINT32 len; - - TRACE("(%p)->(%lu)\n", This, celt); + HTMLRectCollection *col = HTMLRectCollection_from_DispatchEx(dispex); + nsIDOMClientRect *nsrect; + nsresult nsres; + HRESULT hres;
- nsIDOMClientRectList_GetLength(This->col->rect_list, &len); - if(This->iter + celt > len) { - This->iter = len; - return S_FALSE; + nsres = nsIDOMClientRectList_Item(col->rect_list, index, &nsrect); + if(NS_FAILED(nsres)) + return map_nsresult(nsres); + if(!nsrect) { + *p = NULL; + return S_OK; }
- This->iter += celt; - return S_OK; -} - -static HRESULT WINAPI HTMLRectCollectionEnum_Reset(IEnumVARIANT *iface) -{ - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_from_IEnumVARIANT(iface); - - TRACE("(%p)->()\n", This); - - This->iter = 0; - return S_OK; -} - -static HRESULT WINAPI HTMLRectCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum) -{ - HTMLRectCollectionEnum *This = HTMLRectCollectionEnum_from_IEnumVARIANT(iface); - FIXME("(%p)->(%p)\n", This, ppEnum); - return E_NOTIMPL; + hres = create_html_rect(nsrect, &col->dispex, (IHTMLRect**)p); + nsIDOMClientRect_Release(nsrect); + return hres; }
-static const IEnumVARIANTVtbl HTMLRectCollectionEnumVtbl = { - HTMLRectCollectionEnum_QueryInterface, - HTMLRectCollectionEnum_AddRef, - HTMLRectCollectionEnum_Release, - HTMLRectCollectionEnum_Next, - HTMLRectCollectionEnum_Skip, - HTMLRectCollectionEnum_Reset, - HTMLRectCollectionEnum_Clone +static const CollectionEnum_vtbl HTMLRectCollectionEnum_vtbl = { + HTMLRectCollectionEnum_get_length, + HTMLRectCollectionEnum_get_item, };
static inline HTMLRectCollection *impl_from_IHTMLRectCollection(IHTMLRectCollection *iface) @@ -972,23 +880,10 @@ static HRESULT WINAPI HTMLRectCollection_get_length(IHTMLRectCollection *iface, static HRESULT WINAPI HTMLRectCollection_get__newEnum(IHTMLRectCollection *iface, IUnknown **p) { HTMLRectCollection *This = impl_from_IHTMLRectCollection(iface); - HTMLRectCollectionEnum *ret;
TRACE("(%p)->(%p)\n", This, p);
- ret = malloc(sizeof(*ret)); - if(!ret) - return E_OUTOFMEMORY; - - ret->IEnumVARIANT_iface.lpVtbl = &HTMLRectCollectionEnumVtbl; - ret->ref = 1; - ret->iter = 0; - - HTMLRectCollection_AddRef(&This->IHTMLRectCollection_iface); - ret->col = This; - - *p = (IUnknown*)&ret->IEnumVARIANT_iface; - return S_OK; + return CollectionEnum_create(&This->dispex, &HTMLRectCollectionEnum_vtbl, p); }
static HRESULT WINAPI HTMLRectCollection_item(IHTMLRectCollection *iface, VARIANT *index, VARIANT *result) @@ -1037,11 +932,6 @@ static const IHTMLRectCollectionVtbl HTMLRectCollectionVtbl = { HTMLRectCollection_item };
-static inline HTMLRectCollection *HTMLRectCollection_from_DispatchEx(DispatchEx *iface) -{ - return CONTAINING_RECORD(iface, HTMLRectCollection, dispex); -} - static void *HTMLRectCollection_query_interface(DispatchEx *dispex, REFIID riid) { HTMLRectCollection *This = HTMLRectCollection_from_DispatchEx(dispex);