HRESULT HTMLCurrentStyle_Create(HTMLElement *elem, IHTMLCurrentStyle **p) { nsIDOMCSSStyleDeclaration *nsstyle; nsIDOMDocumentView *nsdocview; nsIDOMAbstractView *nsview; nsIDOMViewCSS *nsviewcss; nsAString nsempty_str; HTMLCurrentStyle *ret; nsresult nsres; if(!elem->node.doc->nsdoc) { WARN("NULL nsdoc\n"); return E_UNEXPECTED; } nsres = nsIDOMHTMLDocument_QueryInterface(elem->node.doc->nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview); if(NS_FAILED(nsres)) { ERR("Could not get nsIDOMDocumentView: %08x\n", nsres); return E_FAIL; } nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview); nsIDOMDocumentView_Release(nsdocview); if(NS_FAILED(nsres)) { ERR("GetDefaultView failed: %08x\n", nsres); return E_FAIL; } nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMViewCSS, (void**)&nsviewcss); nsIDOMAbstractView_Release(nsview); if(NS_FAILED(nsres)) { ERR("Could not get nsIDOMViewCSS: %08x\n", nsres); return E_FAIL; } nsAString_Init(&nsempty_str, NULL); nsres = nsIDOMViewCSS_GetComputedStyle(nsviewcss, (nsIDOMElement*)elem->nselem, &nsempty_str, &nsstyle); nsIDOMViewCSS_Release(nsviewcss); nsAString_Finish(&nsempty_str); if(NS_FAILED(nsres)) { ERR("GetComputedStyle failed: %08x\n", nsres); return E_FAIL; } ret = heap_alloc_zero(sizeof(HTMLCurrentStyle)); if(!ret) { nsIDOMCSSStyleDeclaration_Release(nsstyle); return E_OUTOFMEMORY; } ret->lpIHTMLCurrentStyleVtbl = &HTMLCurrentStyleVtbl; ret->ref = 1; ret->nsstyle = nsstyle; init_dispex(&ret->dispex, (IUnknown*)HTMLCURSTYLE(ret), &HTMLCurrentStyle_dispex); *p = HTMLCURSTYLE(ret); return S_OK; }
HRESULT HTMLCurrentStyle_Create(HTMLElement *elem, IHTMLCurrentStyle **p) { nsIDOMCSSStyleDeclaration *nsstyle; mozIDOMWindowProxy *nsview; nsIDOMWindow *nswindow; nsAString nsempty_str; HTMLCurrentStyle *ret; nsresult nsres; if(!elem->node.doc->nsdoc) { WARN("NULL nsdoc\n"); return E_UNEXPECTED; } nsres = nsIDOMHTMLDocument_GetDefaultView(elem->node.doc->nsdoc, &nsview); if(NS_FAILED(nsres)) { ERR("GetDefaultView failed: %08x\n", nsres); return E_FAIL; } nsres = mozIDOMWindowProxy_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow); mozIDOMWindowProxy_Release(nsview); assert(nsres == NS_OK); nsAString_Init(&nsempty_str, NULL); nsres = nsIDOMWindow_GetComputedStyle(nswindow, (nsIDOMElement*)elem->nselem, &nsempty_str, &nsstyle); nsAString_Finish(&nsempty_str); nsIDOMWindow_Release(nswindow); if(NS_FAILED(nsres)) { ERR("GetComputedStyle failed: %08x\n", nsres); return E_FAIL; } if(!nsstyle) { ERR("GetComputedStyle returned NULL nsstyle\n"); return E_FAIL; } ret = heap_alloc_zero(sizeof(HTMLCurrentStyle)); if(!ret) { nsIDOMCSSStyleDeclaration_Release(nsstyle); return E_OUTOFMEMORY; } ret->IHTMLCurrentStyle_iface.lpVtbl = &HTMLCurrentStyleVtbl; ret->IHTMLCurrentStyle2_iface.lpVtbl = &HTMLCurrentStyle2Vtbl; ret->IHTMLCurrentStyle3_iface.lpVtbl = &HTMLCurrentStyle3Vtbl; ret->IHTMLCurrentStyle4_iface.lpVtbl = &HTMLCurrentStyle4Vtbl; ret->ref = 1; ret->nsstyle = nsstyle; init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLCurrentStyle_iface, &HTMLCurrentStyle_dispex); IHTMLElement_AddRef(&elem->IHTMLElement_iface); ret->elem = elem; *p = &ret->IHTMLCurrentStyle_iface; return S_OK; }
static ULONG WINAPI HTMLCurrentStyle_Release(IHTMLCurrentStyle *iface) { HTMLCurrentStyle *This = HTMLCURSTYLE_THIS(iface); LONG ref = InterlockedDecrement(&This->ref); TRACE("(%p) ref=%d\n", This, ref); if(!ref) { if(This->nsstyle) nsIDOMCSSStyleDeclaration_Release(This->nsstyle); release_dispex(&This->dispex); heap_free(This); } return ref; }