Jacek Caban : mshtml: Added IHTMLStyleElement:: media property implementation.

Alexandre Julliard julliard at winehq.org
Fri Dec 17 11:30:47 CST 2010


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Dec 17 03:39:24 2010 +0100

mshtml: Added IHTMLStyleElement::media property implementation.

---

 dlls/mshtml/htmlstyleelem.c |   39 +++++++++++++++++++++++++++---
 dlls/mshtml/nsiface.idl     |   15 ++++++++++++
 dlls/mshtml/tests/dom.c     |   54 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 103 insertions(+), 5 deletions(-)

diff --git a/dlls/mshtml/htmlstyleelem.c b/dlls/mshtml/htmlstyleelem.c
index ee62472..a4cc98e 100644
--- a/dlls/mshtml/htmlstyleelem.c
+++ b/dlls/mshtml/htmlstyleelem.c
@@ -36,6 +36,8 @@ typedef struct {
     HTMLElement element;
 
     const IHTMLStyleElementVtbl *lpIHTMLStyleElementVtbl;
+
+    nsIDOMHTMLStyleElement *nsstyle;
 } HTMLStyleElement;
 
 #define HTMLSTYLE(x)  (&(x)->lpIHTMLStyleElementVtbl)
@@ -180,15 +182,33 @@ static HRESULT WINAPI HTMLStyleElement_get_disabled(IHTMLStyleElement *iface, VA
 static HRESULT WINAPI HTMLStyleElement_put_media(IHTMLStyleElement *iface, BSTR v)
 {
     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
-    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
-    return E_NOTIMPL;
+    nsAString media_str;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(v));
+
+    nsAString_InitDepend(&media_str, v);
+    nsres = nsIDOMHTMLStyleElement_SetMedia(This->nsstyle, &media_str);
+    nsAString_Finish(&media_str);
+    if(NS_FAILED(nsres)) {
+        ERR("SetMedia failed: %08x\n", nsres);
+        return E_FAIL;
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLStyleElement_get_media(IHTMLStyleElement *iface, BSTR *p)
 {
     HTMLStyleElement *This = HTMLSTYLE_THIS(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsAString nsstr;
+    nsresult nsres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    nsAString_Init(&nsstr, NULL);
+    nsres = nsIDOMHTMLStyleElement_GetMedia(This->nsstyle, &nsstr);
+    return return_nsstr(nsres, &nsstr, p);
 }
 
 #undef HTMLSTYLE_THIS
@@ -244,6 +264,9 @@ static void HTMLStyleElement_destructor(HTMLDOMNode *iface)
 {
     HTMLStyleElement *This = HTMLSTYLE_NODE_THIS(iface);
 
+    if(This->nsstyle)
+        nsIDOMHTMLStyleElement_Release(This->nsstyle);
+
     HTMLElement_destructor(&This->element.node);
 }
 
@@ -270,6 +293,7 @@ static dispex_static_data_t HTMLStyleElement_dispex = {
 HRESULT HTMLStyleElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
 {
     HTMLStyleElement *ret;
+    nsresult nsres;
 
     ret = heap_alloc_zero(sizeof(*ret));
     if(!ret)
@@ -278,6 +302,13 @@ HRESULT HTMLStyleElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem
     ret->lpIHTMLStyleElementVtbl = &HTMLStyleElementVtbl;
     ret->element.node.vtbl = &HTMLStyleElementImplVtbl;
 
+    nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLStyleElement, (void**)&ret->nsstyle);
+    if(NS_FAILED(nsres)) {
+        ERR("Could not get nsIDOMHTMLStyleElement iface: %08x\n", nsres);
+        heap_free(ret);
+        return E_FAIL;
+    }
+
     HTMLElement_Init(&ret->element, doc, nselem, &HTMLStyleElement_dispex);
     *elem = &ret->element;
     return S_OK;
diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl
index fc00b25..4248768 100644
--- a/dlls/mshtml/nsiface.idl
+++ b/dlls/mshtml/nsiface.idl
@@ -1704,6 +1704,21 @@ interface nsIDOMHTMLParamElement : nsIDOMHTMLElement
 
 [
     object,
+    uuid(a6cf908d-15b3-11d2-932e-00805f8add32),
+    local
+]
+interface nsIDOMHTMLStyleElement : nsIDOMHTMLElement
+{
+    nsresult GetDisabled(PRBool *aDisabled);
+    nsresult SetDisabled(PRBool aDisabled);
+    nsresult GetMedia(nsAString *aMedia);
+    nsresult SetMedia(const nsAString *aMedia);
+    nsresult GetType(nsAString *aType);
+    nsresult SetType(const nsAString *aType);
+}
+
+[
+    object,
     uuid(94928ab3-8b63-11d3-989d-001083010e9b),
     local
 ]
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index c29f616..536d528 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -40,7 +40,7 @@ static const char range_test_str[] =
 static const char range_test2_str[] =
     "<html><body>abc<hr />123<br /><hr />def</body></html>";
 static const char elem_test_str[] =
-    "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
+    "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
     "<body onload=\"Testing()\">text test<!-- a comment -->"
     "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
     "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
@@ -787,6 +787,17 @@ static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
     return obj;
 }
 
+#define get_style_iface(u) _get_style_iface(__LINE__,u)
+static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
+{
+    IHTMLStyleElement *obj;
+    HRESULT hres;
+
+    hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
+    ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
+    return obj;
+}
+
 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
 {
@@ -2435,6 +2446,40 @@ static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
     _test_elem_tabindex(line, unk, index);
 }
 
+#define test_style_media(s,m) _test_style_media(__LINE__,s,m)
+static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
+{
+    IHTMLStyleElement *style = _get_style_iface(line, unk);
+    BSTR media;
+    HRESULT hres;
+
+    hres = IHTMLStyleElement_get_media(style, &media);
+    ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
+    if(exmedia)
+        ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
+    else
+        ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
+
+    IHTMLStyleElement_Release(style);
+    SysFreeString(media);
+}
+
+#define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
+static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
+{
+    IHTMLStyleElement *style = _get_style_iface(line, unk);
+    BSTR str;
+    HRESULT hres;
+
+    str = a2bstr(media);
+    hres = IHTMLStyleElement_put_media(style, str);
+    ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
+    IHTMLStyleElement_Release(style);
+    SysFreeString(str);
+
+    _test_style_media(line, unk, media);
+}
+
 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
 static void _test_elem_filters(unsigned line, IUnknown *unk)
 {
@@ -6279,6 +6324,13 @@ static void test_elems(IHTMLDocument2 *doc)
         IHTMLElement_Release(elem);
     }
 
+    elem = get_elem_by_id(doc, "styleid", TRUE);
+    if(elem) {
+        test_style_media((IUnknown*)elem, NULL);
+        test_style_put_media((IUnknown*)elem, "screen");
+        IHTMLElement_Release(elem);
+    }
+
     elem = get_doc_elem_by_id(doc, "tbl");
     ok(elem != NULL, "elem == NULL\n");
     if(elem) {




More information about the wine-cvs mailing list