NS_IMETHODIMP inCSSValueSearch::SearchSync() { InitSearch(); if (!mDocument) { return NS_OK; } nsCOMPtr<nsIURI> baseURI; nsCOMPtr<nsIDocument> idoc = do_QueryInterface(mDocument); if (idoc) { baseURI = idoc->GetBaseURI(); } nsCOMPtr<nsIDOMStyleSheetList> sheets; nsresult rv = mDocument->GetStyleSheets(getter_AddRefs(sheets)); NS_ENSURE_SUCCESS(rv, NS_OK); 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) SearchStyleSheet(cssSheet, baseURI); } // XXX would be nice to search inline style as well. return NS_OK; }
nsresult inCSSValueSearch::SearchRuleList(nsIDOMCSSRuleList* aRuleList, nsIURI* aBaseURL) { PRUint32 length; aRuleList->GetLength(&length); for (PRUint32 i = 0; i < length; ++i) { nsCOMPtr<nsIDOMCSSRule> rule; aRuleList->Item(i, getter_AddRefs(rule)); PRUint16 type; rule->GetType(&type); switch (type) { case nsIDOMCSSRule::STYLE_RULE: { nsCOMPtr<nsIDOMCSSStyleRule> styleRule = do_QueryInterface(rule); SearchStyleRule(styleRule, aBaseURL); } break; case nsIDOMCSSRule::IMPORT_RULE: { nsCOMPtr<nsIDOMCSSImportRule> importRule = do_QueryInterface(rule); nsCOMPtr<nsIDOMCSSStyleSheet> childSheet; importRule->GetStyleSheet(getter_AddRefs(childSheet)); if (childSheet) SearchStyleSheet(childSheet, aBaseURL); } break; case nsIDOMCSSRule::MEDIA_RULE: { nsCOMPtr<nsIDOMCSSMediaRule> mediaRule = do_QueryInterface(rule); nsCOMPtr<nsIDOMCSSRuleList> childRules; mediaRule->GetCssRules(getter_AddRefs(childRules)); SearchRuleList(childRules, aBaseURL); } break; default: // XXX handle nsIDOMCSSRule::PAGE_RULE if we ever support it break; } } return NS_OK; }
NS_IMETHODIMP inCSSValueSearch::SearchSync() { InitSearch(); nsCOMPtr<nsIURI> baseURL; nsCOMPtr<nsIDOM3Node> dom3Node = do_QueryInterface(mDocument); if (dom3Node) { nsAutoString uri; dom3Node->GetBaseURI(uri); NS_NewURI(getter_AddRefs(baseURL), uri); } nsCOMPtr<nsIDOMDocumentStyle> doc = do_QueryInterface(mDocument); if (doc) { nsCOMPtr<nsIDOMStyleSheetList> sheets; nsresult rv = doc->GetStyleSheets(getter_AddRefs(sheets)); NS_ENSURE_SUCCESS(rv, NS_OK); 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) SearchStyleSheet(cssSheet, baseURL); } } // XXX would be nice to search inline style as well. return NS_OK; }