From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlform.c | 156 ++++------------------------------------- 1 file changed, 14 insertions(+), 142 deletions(-)
diff --git a/dlls/mshtml/htmlform.c b/dlls/mshtml/htmlform.c index 29986158ca7..1007d27269d 100644 --- a/dlls/mshtml/htmlform.c +++ b/dlls/mshtml/htmlform.c @@ -42,15 +42,6 @@ struct HTMLFormElement { nsIDOMHTMLFormElement *nsform; };
-typedef struct { - IEnumVARIANT IEnumVARIANT_iface; - - LONG ref; - - ULONG iter; - HTMLFormElement *elem; -} HTMLFormElementEnum; - HRESULT return_nsform(nsresult nsres, nsIDOMHTMLFormElement *form, IHTMLFormElement **p) { nsIDOMNode *form_node; @@ -118,133 +109,32 @@ static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret) return S_OK; }
-static inline HTMLFormElementEnum *impl_from_IEnumVARIANT(IEnumVARIANT *iface) -{ - return CONTAINING_RECORD(iface, HTMLFormElementEnum, IEnumVARIANT_iface); -} - -static HRESULT WINAPI HTMLFormElementEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv) -{ - HTMLFormElementEnum *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 HTMLFormElementEnum_AddRef(IEnumVARIANT *iface) -{ - HTMLFormElementEnum *This = impl_from_IEnumVARIANT(iface); - LONG ref = InterlockedIncrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - return ref; -} - -static ULONG WINAPI HTMLFormElementEnum_Release(IEnumVARIANT *iface) -{ - HTMLFormElementEnum *This = impl_from_IEnumVARIANT(iface); - LONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - if(!ref) { - IHTMLFormElement_Release(&This->elem->IHTMLFormElement_iface); - free(This); - } - - return ref; -} - -static HRESULT WINAPI HTMLFormElementEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched) +static inline HTMLFormElement *impl_from_DispatchEx(DispatchEx *iface) { - HTMLFormElementEnum *This = impl_from_IEnumVARIANT(iface); - nsresult nsres; - HRESULT hres; - ULONG num, i; - LONG len; - - TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched); - - nsres = nsIDOMHTMLFormElement_GetLength(This->elem->nsform, &len); - if(NS_FAILED(nsres)) - return E_FAIL; - num = min(len - This->iter, celt); - - for(i = 0; i < num; i++) { - hres = htmlform_item(This->elem, This->iter + i, &V_DISPATCH(&rgVar[i])); - if(FAILED(hres)) { - while(i--) - VariantClear(&rgVar[i]); - return hres; - } - V_VT(&rgVar[i]) = VT_DISPATCH; - } - - This->iter += num; - if(pCeltFetched) - *pCeltFetched = num; - return num == celt ? S_OK : S_FALSE; + return CONTAINING_RECORD(iface, HTMLFormElement, element.node.event_target.dispex); }
-static HRESULT WINAPI HTMLFormElementEnum_Skip(IEnumVARIANT *iface, ULONG celt) +static ULONG HTMLFormElementEnum_get_length(DispatchEx *dispex) { - HTMLFormElementEnum *This = impl_from_IEnumVARIANT(iface); + HTMLFormElement *elem = impl_from_DispatchEx(dispex); nsresult nsres; LONG len;
- TRACE("(%p)->(%lu)\n", This, celt); - - nsres = nsIDOMHTMLFormElement_GetLength(This->elem->nsform, &len); - if(NS_FAILED(nsres)) - return E_FAIL; - - if(This->iter + celt > len) { - This->iter = len; - return S_FALSE; - } - - This->iter += celt; - return S_OK; + nsres = nsIDOMHTMLFormElement_GetLength(elem->nsform, &len); + assert(nsres == NS_OK); + return len; }
-static HRESULT WINAPI HTMLFormElementEnum_Reset(IEnumVARIANT *iface) +static HRESULT HTMLFormElementEnum_get_item(DispatchEx *dispex, ULONG index, IDispatch **p) { - HTMLFormElementEnum *This = impl_from_IEnumVARIANT(iface); - - TRACE("(%p)->()\n", This); + HTMLFormElement *elem = impl_from_DispatchEx(dispex);
- This->iter = 0; - return S_OK; -} - -static HRESULT WINAPI HTMLFormElementEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum) -{ - HTMLFormElementEnum *This = impl_from_IEnumVARIANT(iface); - FIXME("(%p)->(%p)\n", This, ppEnum); - return E_NOTIMPL; + return htmlform_item(elem, index, p); }
-static const IEnumVARIANTVtbl HTMLFormElementEnumVtbl = { - HTMLFormElementEnum_QueryInterface, - HTMLFormElementEnum_AddRef, - HTMLFormElementEnum_Release, - HTMLFormElementEnum_Next, - HTMLFormElementEnum_Skip, - HTMLFormElementEnum_Reset, - HTMLFormElementEnum_Clone +static const CollectionEnum_vtbl HTMLFormElementEnum_vtbl = { + HTMLFormElementEnum_get_length, + HTMLFormElementEnum_get_item, };
static inline HTMLFormElement *impl_from_IHTMLFormElement(IHTMLFormElement *iface) @@ -633,23 +523,10 @@ static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG * static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p) { HTMLFormElement *This = impl_from_IHTMLFormElement(iface); - HTMLFormElementEnum *ret;
TRACE("(%p)->(%p)\n", This, p);
- ret = malloc(sizeof(*ret)); - if(!ret) - return E_OUTOFMEMORY; - - ret->IEnumVARIANT_iface.lpVtbl = &HTMLFormElementEnumVtbl; - ret->ref = 1; - ret->iter = 0; - - HTMLFormElement_AddRef(&This->IHTMLFormElement_iface); - ret->elem = This; - - *p = (IUnknown*)&ret->IEnumVARIANT_iface; - return S_OK; + return CollectionEnum_create(&This->element.node.event_target.dispex, &HTMLFormElementEnum_vtbl, p); }
static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name, @@ -718,11 +595,6 @@ static const IHTMLFormElementVtbl HTMLFormElementVtbl = { HTMLFormElement_tags };
-static inline HTMLFormElement *impl_from_DispatchEx(DispatchEx *iface) -{ - return CONTAINING_RECORD(iface, HTMLFormElement, element.node.event_target.dispex); -} - static void *HTMLFormElement_query_interface(DispatchEx *dispex, REFIID riid) { HTMLFormElement *This = impl_from_DispatchEx(dispex);