From 72fc799d18d67b8a83fb9fdef7cc88221b06e850 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 6 Oct 2008 09:49:00 -0500 Subject: [PATCH] mshtml: Store nsIDOMCSSStyleDeclaration in HTMLCurrentStyle. --- dlls/mshtml/htmlcurstyle.c | 57 +++++++++++++++++++++++++++++++++++++++++--- dlls/mshtml/htmlelem2.c | 2 +- dlls/mshtml/mshtml_private.h | 2 +- dlls/mshtml/nsiface.idl | 35 ++++++++++++++++++++++++++- 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/dlls/mshtml/htmlcurstyle.c b/dlls/mshtml/htmlcurstyle.c index 45680877632..ffce224c08b 100644 --- a/dlls/mshtml/htmlcurstyle.c +++ b/dlls/mshtml/htmlcurstyle.c @@ -37,6 +37,8 @@ typedef struct { const IHTMLCurrentStyleVtbl *lpIHTMLCurrentStyleVtbl; LONG ref; + + nsIDOMCSSStyleDeclaration *nsstyle; } HTMLCurrentStyle; #define HTMLCURSTYLE(x) ((IHTMLCurrentStyle*) &(x)->lpIHTMLCurrentStyleVtbl) @@ -85,8 +87,11 @@ static ULONG WINAPI HTMLCurrentStyle_Release(IHTMLCurrentStyle *iface) TRACE("(%p) ref=%d\n", This, ref); - if(!ref) + if(!ref) { + if(This->nsstyle) + nsIDOMCSSStyleDeclaration_Release(This->nsstyle); heap_free(This); + } return ref; } @@ -875,16 +880,62 @@ static dispex_static_data_t HTMLCurrentStyle_dispex = { HTMLCurrentStyle_iface_tids }; -HRESULT HTMLCurrentStyle_Create(IHTMLCurrentStyle **p) +HRESULT HTMLCurrentStyle_Create(HTMLElement *elem, IHTMLCurrentStyle **p) { + nsIDOMCSSStyleDeclaration *nsstyle; + nsIDOMDocumentView *nsdocview; + nsIDOMAbstractView *nsview; + nsIDOMViewCSS *nsviewcss; + nsIDOMDocument *nsdoc; + nsAString nsempty_str; HTMLCurrentStyle *ret; + nsresult nsres; + + nsres = nsIWebNavigation_GetDocument(elem->node.doc->nscontainer->navigation, &nsdoc); + if(NS_FAILED(nsres)) { + ERR("GetDocument failed: %08x\n", nsres); + return E_FAIL; + } + + nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview); + nsIDOMDocument_Release(nsdoc); + 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) + 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); diff --git a/dlls/mshtml/htmlelem2.c b/dlls/mshtml/htmlelem2.c index 36676c675eb..14650863acb 100644 --- a/dlls/mshtml/htmlelem2.c +++ b/dlls/mshtml/htmlelem2.c @@ -321,7 +321,7 @@ static HRESULT WINAPI HTMLElement2_get_currentStyle(IHTMLElement2 *iface, IHTMLC TRACE("(%p)->(%p)\n", This, p); - return HTMLCurrentStyle_Create(p); + return HTMLCurrentStyle_Create(This, p); } static HRESULT WINAPI HTMLElement2_put_onpropertychange(IHTMLElement2 *iface, VARIANT v) diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 4df7efe1743..626cb8b99f7 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -474,7 +474,7 @@ void HTMLDocument_Window_Init(HTMLDocument*); void HTMLDocument_Service_Init(HTMLDocument*); void HTMLDocument_Hlink_Init(HTMLDocument*); -HRESULT HTMLCurrentStyle_Create(IHTMLCurrentStyle**); +HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**); void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID); void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*); diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl index bedac821595..93e25f11cbe 100644 --- a/dlls/mshtml/nsiface.idl +++ b/dlls/mshtml/nsiface.idl @@ -82,6 +82,7 @@ interface nsIEditorObserver; interface nsIEditActionListener; interface nsIDocumentStateListener; interface nsIDOMCSSStyleSheet; +interface nsIDOMDocumentView; interface IMoniker; @@ -100,7 +101,6 @@ interface nsISupports /* Currently we don't need a full declaration of these interfaces */ typedef nsISupports nsISHistory; typedef nsISupports nsIWidget; -typedef nsISupports nsIDOMAbstractView; typedef nsISupports nsIHttpHeaderVisitor; typedef nsISupports nsIDOMBarProp; typedef nsISupports nsIDOMWindowCollection; @@ -887,6 +887,28 @@ interface nsIDOMDocumentFragment : nsIDOMNode [ object, + uuid(f51ebade-8b1a-11d3-aae7-0010830123b4), + local + /* FROZEN */ +] +interface nsIDOMAbstractView : nsISupports +{ + nsresult GetDocument(nsIDOMDocumentView **aDocument); +} + +[ + object, + uuid(0b9341f3-95d4-4fa4-adcd-e119e0db2889), + local + /* NOT_FROZEN */ +] +interface nsIDOMViewCSS : nsIDOMAbstractView +{ + nsresult GetComputedStyle(nsIDOMElement *elt, const nsAString *pseudoElt, nsIDOMCSSStyleDeclaration **_retval); +} + +[ + object, uuid(a6cf9075-15b3-11d2-932e-00805f8add32), local /* FROZEN */ @@ -1003,6 +1025,17 @@ interface nsIDOMDocumentStyle : nsISupports [ object, + uuid(1acdb2ba-1dd2-11b2-95bc-9542495d2569), + local + /* FROZEN */ +] +interface nsIDOMDocumentView : nsISupports +{ + nsresult GetDefaultView(nsIDOMAbstractView **aDefaultView); +} + +[ + object, uuid(a6cf90ce-15b3-11d2-932e-00805f8add32), local /* FROZEN */ -- 2.11.4.GIT