Jacek Caban : mshtml: Store style object in element object.

Alexandre Julliard julliard at winehq.org
Mon Feb 28 11:02:12 CST 2011


Module: wine
Branch: master
Commit: 1745abfa263df7715ccabac5746217f74e5c7f5f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1745abfa263df7715ccabac5746217f74e5c7f5f

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Feb 28 13:13:12 2011 +0100

mshtml: Store style object in element object.

---

 dlls/mshtml/htmlelem.c       |   54 ++++++++++++++++++++++++-----------------
 dlls/mshtml/htmlstyle.c      |   23 +++++++++++-------
 dlls/mshtml/mshtml_private.h |    3 +-
 dlls/mshtml/tests/dom.c      |    7 +++++
 4 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index 712fa66..897a7c5 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -33,6 +33,7 @@
 
 #include "mshtml_private.h"
 #include "htmlevent.h"
+#include "htmlstyle.h"
 
 static const WCHAR aW[]        = {'A',0};
 static const WCHAR bodyW[]     = {'B','O','D','Y',0};
@@ -423,35 +424,42 @@ static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLEl
 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
 {
     HTMLElement *This = impl_from_IHTMLElement(iface);
-    nsIDOMElementCSSInlineStyle *nselemstyle;
-    nsIDOMCSSStyleDeclaration *nsstyle;
-    nsresult nsres;
 
     TRACE("(%p)->(%p)\n", This, p);
 
-    if(!This->nselem) {
-        FIXME("NULL nselem\n");
-        return E_NOTIMPL;
-    }
+    if(!This->style) {
+        nsIDOMElementCSSInlineStyle *nselemstyle;
+        nsIDOMCSSStyleDeclaration *nsstyle;
+        nsresult nsres;
+        HRESULT hres;
 
-    nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
-                                             (void**)&nselemstyle);
-    if(NS_FAILED(nsres)) {
-        ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
-        return E_FAIL;
-    }
+        if(!This->nselem) {
+            FIXME("NULL nselem\n");
+            return E_NOTIMPL;
+        }
 
-    nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
-    nsIDOMElementCSSInlineStyle_Release(nselemstyle);
-    if(NS_FAILED(nsres)) {
-        ERR("GetStyle failed: %08x\n", nsres);
-        return E_FAIL;
-    }
+        nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
+                (void**)&nselemstyle);
+        if(NS_FAILED(nsres)) {
+            ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
+            return E_FAIL;
+        }
 
-    /* FIXME: Store style instead of creating a new instance in each call */
-    *p = HTMLStyle_Create(nsstyle);
+        nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
+        nsIDOMElementCSSInlineStyle_Release(nselemstyle);
+        if(NS_FAILED(nsres)) {
+            ERR("GetStyle failed: %08x\n", nsres);
+            return E_FAIL;
+        }
+
+        hres = HTMLStyle_Create(nsstyle, &This->style);
+        nsIDOMCSSStyleDeclaration_Release(nsstyle);
+        if(FAILED(hres))
+            return hres;
+    }
 
-    nsIDOMCSSStyleDeclaration_Release(nsstyle);
+    *p = &This->style->IHTMLStyle_iface;
+    IHTMLStyle_AddRef(*p);
     return S_OK;
 }
 
@@ -1644,6 +1652,8 @@ void HTMLElement_destructor(HTMLDOMNode *iface)
 
     if(This->nselem)
         nsIDOMHTMLElement_Release(This->nselem);
+    if(This->style)
+        IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
 
     HTMLDOMNode_destructor(&This->node);
 }
diff --git a/dlls/mshtml/htmlstyle.c b/dlls/mshtml/htmlstyle.c
index 5bd69b1..c0074ca 100644
--- a/dlls/mshtml/htmlstyle.c
+++ b/dlls/mshtml/htmlstyle.c
@@ -2902,19 +2902,24 @@ static dispex_static_data_t HTMLStyle_dispex = {
     HTMLStyle_iface_tids
 };
 
-IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration *nsstyle)
+HRESULT HTMLStyle_Create(nsIDOMCSSStyleDeclaration *nsstyle, HTMLStyle **ret)
 {
-    HTMLStyle *ret = heap_alloc_zero(sizeof(HTMLStyle));
+    HTMLStyle *style;
 
-    ret->IHTMLStyle_iface.lpVtbl = &HTMLStyleVtbl;
-    ret->ref = 1;
-    ret->nsstyle = nsstyle;
-    HTMLStyle2_Init(ret);
-    HTMLStyle3_Init(ret);
+    style = heap_alloc_zero(sizeof(HTMLStyle));
+    if(!style)
+        return E_OUTOFMEMORY;
+
+    style->IHTMLStyle_iface.lpVtbl = &HTMLStyleVtbl;
+    style->ref = 1;
+    style->nsstyle = nsstyle;
+    HTMLStyle2_Init(style);
+    HTMLStyle3_Init(style);
 
     nsIDOMCSSStyleDeclaration_AddRef(nsstyle);
 
-    init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLStyle_iface, &HTMLStyle_dispex);
+    init_dispex(&style->dispex, (IUnknown*)&style->IHTMLStyle_iface, &HTMLStyle_dispex);
 
-    return &ret->IHTMLStyle_iface;
+    *ret = style;
+    return S_OK;
 }
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 9bb11fb..0adb344 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -560,6 +560,7 @@ typedef struct {
     IHTMLElement4 IHTMLElement4_iface;
 
     nsIDOMHTMLElement *nselem;
+    HTMLStyle *style;
 } HTMLElement;
 
 #define HTMLELEMENT_TIDS    \
@@ -730,7 +731,7 @@ void set_ready_state(HTMLWindow*,READYSTATE);
 
 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
-IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
+HRESULT HTMLStyle_Create(nsIDOMCSSStyleDeclaration*,HTMLStyle**);
 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
 
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index b23f63c..0ecce41 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -5610,6 +5610,13 @@ static void test_style_filters(IHTMLElement *elem)
     test_style_filter(style, NULL);
     set_style_filter(style, "alpha(opacity=50.00000)");
     set_style_filter(style, "alpha(opacity=100)");
+
+    IHTMLStyle_Release(style);
+
+    hres = IHTMLElement_get_style(elem, &style);
+    ok(hres == S_OK, "get_style failed: %08x\n", hres);
+
+    test_style_filter(style, "alpha(opacity=100)");
     set_style_filter(style, "xxx(a,b,c) alpha(opacity=100)");
     set_style_filter(style, NULL);
 




More information about the wine-cvs mailing list