Hi,

I'm trying to get the collection of CSS rules of certain document.
Following is the source code I try to use to retrieve those rules.


        nsCOMPtr<nsIInterfaceRequestor> requestor;
        this->GetInterfaceRequestor(getter_AddRefs(requestor));
        nsCOMPtr<nsIDOMDocument> document = do_GetInterface(requestor);

        nsCOMPtr<nsIDOMDocumentStyle> doc = do_QueryInterface(document);
        if (doc)
        {
                nsCOMPtr<nsIDOMStyleSheetList> sheets;
                nsresult rv = doc->GetStyleSheets(getter_AddRefs(sheets));

                PRUint32 length;
                sheets->GetLength(&length);
                for (PRUint32 i = 0; i < length; ++i)
                {
                        nsCOMPtr<nsIDOMStyleSheet> sheet;
                        sheets->Item(i, getter_AddRefs(sheet));
                        nsCOMPtr<nsIDOMCSSStyleSheet> cssSheet = 
do_QueryInterface(sheet);

                        if (cssSheet)
                        {
                                nsCOMPtr<nsIDOMCSSRuleList> rules;
                                cssSheet->GetCssRules(getter_AddRefs(rules));

                                if (rules)//this will be false!!!
                                {
                                        PRUint32 rulesLength;
                                        rv = rules->GetLength(&rulesLength);

                                        for (PRUint32 j = 0; j < rulesLength; 
j++)
                                        {
                                                nsCOMPtr<nsIDOMCSSRule> rule;
                                                rules->Item(j, 
getter_AddRefs(rule));

                                                nsAutoString ruleText;
                                                rule->GetCssText(ruleText);
                                        }
                                }
                        }
                }
        }

it doesn't pass the 'if (rules)' condition and I wasn't able to find
out what's wrong. If you were able to help, it would be really great.
Thank you in advance!

Regards,
martin
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to