static void GetMathMLAttributeStyleSheet(nsPresContext* aPresContext, nsIStyleSheet** aSheet) { static const char kTitle[] = "Internal MathML/CSS Attribute Style Sheet"; *aSheet = nsnull; // first, look if the attribute stylesheet is already there nsStyleSet *styleSet = aPresContext->StyleSet(); NS_ASSERTION(styleSet, "no style set"); nsAutoString title; for (PRInt32 i = styleSet->SheetCount(nsStyleSet::eAgentSheet) - 1; i >= 0; --i) { nsIStyleSheet *sheet = styleSet->StyleSheetAt(nsStyleSet::eAgentSheet, i); nsCOMPtr<nsICSSStyleSheet> cssSheet(do_QueryInterface(sheet)); if (cssSheet) { cssSheet->GetTitle(title); if (title.Equals(NS_ConvertASCIItoUCS2(kTitle))) { *aSheet = sheet; NS_IF_ADDREF(*aSheet); return; } } } // then, create a new one if it isn't yet there nsCOMPtr<nsIURI> uri; NS_NewURI(getter_AddRefs(uri), "about:internal-mathml-attribute-stylesheet"); if (!uri) return; nsCOMPtr<nsICSSStyleSheet_MOZILLA_1_8_BRANCH> cssSheet = do_CreateInstance(kCSSStyleSheetCID); if (!cssSheet) return; cssSheet->SetURIs18(uri, uri, uri); cssSheet->SetTitle(NS_ConvertASCIItoUCS2(kTitle)); // all done, no further activity from the net involved, so we better do this cssSheet->SetComplete(); nsCOMPtr<nsIDOMCSSStyleSheet> domSheet(do_QueryInterface(cssSheet)); if (domSheet) { PRUint32 index; domSheet->InsertRule(NS_LITERAL_STRING("@namespace url(http://www.w3.org/1998/Math/MathML);"), 0, &index); } // insert the stylesheet into the styleset without notifying observers // XXX Should this be at a different level? styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, cssSheet); *aSheet = cssSheet; NS_ADDREF(*aSheet); }
/* static */ void nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule, CSSParsingEnvironment& aCSSParseEnv) { nsIStyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nsnull; nsRefPtr<nsCSSStyleSheet> cssSheet(do_QueryObject(sheet)); if (!cssSheet) { aCSSParseEnv.mPrincipal = nsnull; return; } nsIDocument* document = sheet->GetOwningDocument(); aCSSParseEnv.mSheetURI = sheet->GetSheetURI(); aCSSParseEnv.mBaseURI = sheet->GetBaseURI(); aCSSParseEnv.mPrincipal = cssSheet->Principal(); aCSSParseEnv.mCSSLoader = document ? document->CSSLoader() : nsnull; }