From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlstylesheet.c | 162 ++++++----------------------------- 1 file changed, 25 insertions(+), 137 deletions(-)
diff --git a/dlls/mshtml/htmlstylesheet.c b/dlls/mshtml/htmlstylesheet.c index fb9d71f894f..ff422156836 100644 --- a/dlls/mshtml/htmlstylesheet.c +++ b/dlls/mshtml/htmlstylesheet.c @@ -47,15 +47,6 @@ struct HTMLStyleSheetsCollection { nsIDOMStyleSheetList *nslist; };
-typedef struct { - IEnumVARIANT IEnumVARIANT_iface; - - LONG ref; - - ULONG iter; - HTMLStyleSheetsCollection *col; -} HTMLStyleSheetsCollectionEnum; - struct HTMLStyleSheetRulesCollection { DispatchEx dispex; IHTMLStyleSheetRulesCollection IHTMLStyleSheetRulesCollection_iface; @@ -399,128 +390,43 @@ static HRESULT create_style_sheet_rules_collection(nsIDOMCSSRuleList *nslist, Di return S_OK; }
-static inline HTMLStyleSheetsCollectionEnum *HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(IEnumVARIANT *iface) -{ - return CONTAINING_RECORD(iface, HTMLStyleSheetsCollectionEnum, IEnumVARIANT_iface); -} - -static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv) -{ - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_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 HTMLStyleSheetsCollectionEnum_AddRef(IEnumVARIANT *iface) -{ - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface); - LONG ref = InterlockedIncrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - return ref; -} - -static ULONG WINAPI HTMLStyleSheetsCollectionEnum_Release(IEnumVARIANT *iface) -{ - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface); - LONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p) ref=%ld\n", This, ref); - - if(!ref) { - IHTMLStyleSheetsCollection_Release(&This->col->IHTMLStyleSheetsCollection_iface); - free(This); - } - - return ref; -} - -static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched) +static inline HTMLStyleSheetsCollection *HTMLStyleSheetsCollection_from_DispatchEx(DispatchEx *iface) { - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface); - VARIANT index; - HRESULT hres; - ULONG num, i; - UINT32 len; - - TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched); - - nsIDOMStyleSheetList_GetLength(This->col->nslist, &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 = IHTMLStyleSheetsCollection_item(&This->col->IHTMLStyleSheetsCollection_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; + return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, dispex); }
-static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt) +static ULONG HTMLStyleSheetsCollectionEnum_get_length(DispatchEx *dispex) { - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface); + HTMLStyleSheetsCollection *col = HTMLStyleSheetsCollection_from_DispatchEx(dispex); + nsresult nsres; UINT32 len;
- TRACE("(%p)->(%lu)\n", This, celt); - - nsIDOMStyleSheetList_GetLength(This->col->nslist, &len); - if(This->iter + celt > len) { - This->iter = len; - return S_FALSE; - } - - This->iter += celt; - return S_OK; + nsres = nsIDOMStyleSheetList_GetLength(col->nslist, &len); + assert(nsres == NS_OK); + return len; }
-static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Reset(IEnumVARIANT *iface) +static HRESULT HTMLStyleSheetsCollectionEnum_get_item(DispatchEx *dispex, ULONG index, IDispatch **p) { - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface); - - TRACE("(%p)->()\n", This); + HTMLStyleSheetsCollection *col = HTMLStyleSheetsCollection_from_DispatchEx(dispex); + nsIDOMStyleSheet *nsstylesheet; + nsresult nsres; + HRESULT hres;
- This->iter = 0; - return S_OK; -} + nsres = nsIDOMStyleSheetList_Item(col->nslist, index, &nsstylesheet); + if(NS_FAILED(nsres)) + return map_nsresult(nsres); + if(!nsstylesheet) + return E_INVALIDARG;
-static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum) -{ - HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface); - FIXME("(%p)->(%p)\n", This, ppEnum); - return E_NOTIMPL; + hres = create_style_sheet(nsstylesheet, &col->dispex, (IHTMLStyleSheet**)p); + nsIDOMStyleSheet_Release(nsstylesheet); + return hres; }
-static const IEnumVARIANTVtbl HTMLStyleSheetsCollectionEnumVtbl = { - HTMLStyleSheetsCollectionEnum_QueryInterface, - HTMLStyleSheetsCollectionEnum_AddRef, - HTMLStyleSheetsCollectionEnum_Release, - HTMLStyleSheetsCollectionEnum_Next, - HTMLStyleSheetsCollectionEnum_Skip, - HTMLStyleSheetsCollectionEnum_Reset, - HTMLStyleSheetsCollectionEnum_Clone +static const CollectionEnum_vtbl HTMLStyleSheetsCollectionEnum_vtbl = { + HTMLStyleSheetsCollectionEnum_get_length, + HTMLStyleSheetsCollectionEnum_get_item, };
static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface) @@ -550,23 +456,10 @@ static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCol IUnknown **p) { HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface); - HTMLStyleSheetsCollectionEnum *ret;
TRACE("(%p)->(%p)\n", This, p);
- ret = malloc(sizeof(*ret)); - if(!ret) - return E_OUTOFMEMORY; - - ret->IEnumVARIANT_iface.lpVtbl = &HTMLStyleSheetsCollectionEnumVtbl; - ret->ref = 1; - ret->iter = 0; - - HTMLStyleSheetsCollection_AddRef(&This->IHTMLStyleSheetsCollection_iface); - ret->col = This; - - *p = (IUnknown*)&ret->IEnumVARIANT_iface; - return S_OK; + return CollectionEnum_create(&This->dispex, &HTMLStyleSheetsCollectionEnum_vtbl, p); }
static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface, @@ -626,11 +519,6 @@ static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = { HTMLStyleSheetsCollection_item };
-static inline HTMLStyleSheetsCollection *HTMLStyleSheetsCollection_from_DispatchEx(DispatchEx *iface) -{ - return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, dispex); -} - static void *HTMLStyleSheetsCollection_query_interface(DispatchEx *dispex, REFIID riid) { HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);