Jacek Caban : mshtml: Added IHTMLStyleSheet::get_rules implementation.

Alexandre Julliard julliard at winehq.org
Thu Dec 6 08:26:51 CST 2007


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Dec  6 12:22:30 2007 +0100

mshtml: Added IHTMLStyleSheet::get_rules implementation.

---

 dlls/mshtml/htmlstylesheet.c |  159 ++++++++++++++++++++++++++++++++++++++++-
 dlls/mshtml/nsiface.idl      |   28 +++++++-
 dlls/mshtml/tests/dom.c      |   18 +++++
 3 files changed, 199 insertions(+), 6 deletions(-)

diff --git a/dlls/mshtml/htmlstylesheet.c b/dlls/mshtml/htmlstylesheet.c
index bc42ee4..b4c5a87 100644
--- a/dlls/mshtml/htmlstylesheet.c
+++ b/dlls/mshtml/htmlstylesheet.c
@@ -52,8 +52,148 @@ typedef struct {
     nsIDOMStyleSheetList *nslist;
 } HTMLStyleSheetsCollection;
 
-#define HTMLSTYLESHEET(x)      ((IHTMLStyleSheet*)             &(x)->lpHTMLStyleSheetVtbl);
-#define HTMLSTYLESHEETSCOL(x)  ((IHTMLStyleSheetsCollection*)  &(x)->lpHTMLStyleSheetsCollectionVtbl);
+typedef struct {
+    const IHTMLStyleSheetRulesCollectionVtbl *lpHTMLStyleSheetRulesCollectionVtbl;
+
+    LONG ref;
+
+    nsIDOMCSSRuleList *nslist;
+} HTMLStyleSheetRulesCollection;
+
+#define HTMLSTYLESHEET(x)     ((IHTMLStyleSheet*)                &(x)->lpHTMLStyleSheetVtbl);
+#define HTMLSTYLESHEETSCOL(x) ((IHTMLStyleSheetsCollection*)     &(x)->lpHTMLStyleSheetsCollectionVtbl);
+#define HTMLSTYLERULESCOL(x)  ((IHTMLStyleSheetRulesCollection*) &(x)->lpHTMLStyleSheetRulesCollectionVtbl)
+
+#define HTMLSTYLERULESCOL_THIS(iface) \
+    DEFINE_THIS(HTMLStyleSheetRulesCollection, HTMLStyleSheetRulesCollection, iface)
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
+        REFIID riid, void **ppv)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+
+    if(IsEqualGUID(&IID_IUnknown, riid)) {
+        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
+        *ppv = HTMLSTYLERULESCOL(This);
+    }else if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid)) {
+        TRACE("(%p)->(IID_IHTMLStyleSheetRulesCollection %p)\n", This, ppv);
+        *ppv = HTMLSTYLERULESCOL(This);
+    }
+
+    if(*ppv) {
+        IUnknown_AddRef((IUnknown*)*ppv);
+        return S_OK;
+    }
+
+    FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    LONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p) ref=%d\n", This, ref);
+
+    return ref;
+}
+
+static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    LONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p) ref=%d\n", This, ref);
+
+    if(!ref) {
+        if(This->nslist)
+            nsIDOMCSSRuleList_Release(This->nslist);
+        heap_free(This);
+    }
+
+    return ref;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
+        IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    FIXME("(%p)->(%p)\n", This, pctinfo);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
+        UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
+        REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
+          lcid, rgDispId);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
+        DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
+        VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
+          lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
+        long *p)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    FIXME("(%p)->(%p)\n", This, p);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
+        long index, IHTMLStyleSheetRule **ppHTMLStyleSheetRule)
+{
+    HTMLStyleSheetRulesCollection *This = HTMLSTYLERULESCOL_THIS(iface);
+    FIXME("(%p)->(%ld %p)\n", This, index, ppHTMLStyleSheetRule);
+    return E_NOTIMPL;
+}
+
+#undef HTMLSTYLERULECOL_THIS
+
+static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
+    HTMLStyleSheetRulesCollection_QueryInterface,
+    HTMLStyleSheetRulesCollection_AddRef,
+    HTMLStyleSheetRulesCollection_Release,
+    HTMLStyleSheetRulesCollection_GetTypeInfoCount,
+    HTMLStyleSheetRulesCollection_GetTypeInfo,
+    HTMLStyleSheetRulesCollection_GetIDsOfNames,
+    HTMLStyleSheetRulesCollection_Invoke,
+    HTMLStyleSheetRulesCollection_get_length,
+    HTMLStyleSheetRulesCollection_item
+};
+
+static IHTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_Create(nsIDOMCSSRuleList *nslist)
+{
+    HTMLStyleSheetRulesCollection *ret;
+
+    ret = heap_alloc(sizeof(*ret));
+    ret->lpHTMLStyleSheetRulesCollectionVtbl = &HTMLStyleSheetRulesCollectionVtbl;
+    ret->ref = 1;
+    ret->nslist = nslist;
+
+    if(nslist)
+        nsIDOMCSSRuleList_AddRef(nslist);
+
+    return HTMLSTYLERULESCOL(ret);
+}
 
 #define HTMLSTYLESHEETSCOL_THIS(iface) \
     DEFINE_THIS(HTMLStyleSheetsCollection, HTMLStyleSheetsCollection, iface)
@@ -468,8 +608,19 @@ static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
                                                IHTMLStyleSheetRulesCollection **p)
 {
     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsIDOMCSSRuleList *nslist = NULL;
+    nsresult nsres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    /* Gecko has buggy security checks and GetCssRules will fail. We have a correct
+     * implementation and it will work when the bug will be fixed in Gecko. */
+    nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
+    if(NS_FAILED(nsres))
+        WARN("GetCssRules failed: %08x\n", nsres);
+
+    *p = HTMLStyleSheetRulesCollection_Create(nslist);
+    return S_OK;
 }
 
 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl
index 8f2876c..26258ee 100644
--- a/dlls/mshtml/nsiface.idl
+++ b/dlls/mshtml/nsiface.idl
@@ -81,6 +81,7 @@ interface nsIOutputStream;
 interface nsIEditorObserver;
 interface nsIEditActionListener;
 interface nsIDocumentStateListener;
+interface nsIDOMCSSStyleSheet;
 
 interface IMoniker;
 
@@ -116,7 +117,6 @@ typedef nsISupports nsIDOMHTMLOptionsCollection;
 typedef nsISupports nsIDOMHTMLCollection;
 typedef nsISupports nsIWebProgressListener;
 typedef nsISupports nsIDOMCSSValue;
-typedef nsISupports nsIDOMCSSRule;
 typedef nsISupports nsIPrintSession;
 typedef nsISupports nsIControllerCommandTable;
 typedef nsISupports nsIPrincipal;
@@ -124,7 +124,6 @@ typedef nsISupports nsIAtom;
 typedef nsISupports nsISupportsArray;
 typedef nsISupports nsIContentFilter;
 typedef nsISupports nsIDOMMediaList;
-typedef nsISupports nsIDOMCSSRuleList;
 
 [
     object,
@@ -553,6 +552,20 @@ interface nsIUploadChannel : nsISupports
 
 [
     object,
+    uuid(a6cf90c1-15b3-11d2-932e-00805f8add32)
+    /* FROZEN */
+]
+interface nsIDOMCSSRule : nsISupports
+{
+    nsresult GetType(PRUint16 *aType);
+    nsresult GetCssText(nsAString *aCssText);
+    nsresult SetCssText(const nsAString *aCssText);
+    nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet **aParentStyleSheet);
+    nsresult GetParentRule(nsIDOMCSSRule **aParentRule);
+}
+
+[
+    object,
     uuid(a6cf90be-15b3-11d2-932e-00805f8add32)
     /* FROZEN */
 ]
@@ -573,6 +586,17 @@ interface nsIDOMCSSStyleDeclaration : nsISupports
 
 [
     object,
+    uuid(a6cf90c0-15b3-11d2-932e-00805f8add32)
+    /* FROZEN */
+]
+interface nsIDOMCSSRuleList : nsISupports
+{
+    nsresult GetLength(PRUint32 *aLength);
+    nsresult Item(PRUint32 index, nsIDOMCSSRule **_retval);
+}
+
+[
+    object,
     uuid(a6cf9080-15b3-11d2-932e-00805f8add32)
     /* FROZEN */
 ]
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index f1511de..5debead 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -1084,6 +1084,23 @@ static void test_defaults(IHTMLDocument2 *doc)
     test_default_selection(doc);
 }
 
+static void test_stylesheet(IDispatch *disp)
+{
+    IHTMLStyleSheetRulesCollection *col = NULL;
+    IHTMLStyleSheet *stylesheet;
+    HRESULT hres;
+
+    hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
+    ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
+
+    hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
+    ok(hres == S_OK, "get_rules failed: %08x\n", hres);
+    ok(col != NULL, "col == NULL\n");
+
+    IHTMLStyleSheetRulesCollection_Release(col);
+    IHTMLStyleSheet_Release(stylesheet);
+}
+
 static void test_stylesheets(IHTMLDocument2 *doc)
 {
     IHTMLStyleSheetsCollection *col = NULL;
@@ -1107,6 +1124,7 @@ static void test_stylesheets(IHTMLDocument2 *doc)
     ok(hres == S_OK, "item failed: %08x\n", hres);
     ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
+    test_stylesheet(V_DISPATCH(&res));
     VariantClear(&res);
 
     V_VT(&res) = VT_I4;




More information about the wine-cvs mailing list