internal void LoadChildSheet(CssStyleSheet aParentSheet, Uri aUrl, nsMediaList aMedia, CssImportRule aRule) { }
internal CssImportRule(nsMediaList aMedia, string aUrlSpec) { mMedia = aMedia; mUrlSpec = aUrlSpec; }
// Parse a CSS2 media rule: "@media medium [, medium] { ... }" internal bool ParseMediaRule(RuleAppendFunc aAppendFunc, object aData) { nsMediaList media = new nsMediaList(); if (GatherMedia(media, true)) { // XXXbz this could use better error reporting throughout the method MediaRule rule = new MediaRule(); // Append first, so when we do SetMedia() the rule // knows what its stylesheet is. if (ParseGroupRule(rule, aAppendFunc, aData)) { rule.SetMedia(media); return true; } } return false; }
internal void ProcessImport(string aURLSpec, nsMediaList aMedia, RuleAppendFunc aAppendFunc, object aData) { ImportRule rule = new ImportRule(aMedia, aURLSpec); aAppendFunc(rule, aData); // Diagnose bad URIs even if we don't have a child loader. Uri url; // Charset will be deduced from mBaseURI, which is more or less correct. nsresult rv = CommonUtil.NS_NewURI(out url, aURLSpec, null, mBaseURI); if (rv.Failed()) { if (rv == nsresult.ERROR_MALFORMED_URI) { // import url is bad { if (!mSuppressErrors) mReporter.ReportUnexpected("PEImportBadURI", aURLSpec); }; mReporter.OutputError(); } return; } if (mChildLoader != null) { mChildLoader.LoadChildSheet(mSheet, url, aMedia, rule); } }
internal nsresult ParseMediaList(string aBuffer, Uri aURI, // for error reporting uint32_t aLineNumber, // for error reporting nsMediaList aMediaList, bool aHTMLMode) { // XXX Are there cases where the caller wants to keep what it already // has in case of parser error? If GatherMedia ever changes to return // a value other than true, we probably should avoid modifying aMediaList. aMediaList.Clear(); // fake base URI since media lists don't have URIs in them var scanner = new nsCSSScanner(aBuffer, aLineNumber); var reporter = new ErrorReporter(scanner, mSheet, mChildLoader, aURI); InitScanner(scanner, reporter, aURI, aURI, null); mHTMLMediaMode = aHTMLMode; // XXXldb We need to make the scanner not skip CSS comments! (Or // should we?) // For aHTMLMode, we used to follow the parsing rules in // http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-media-descriptors // which wouldn't work for media queries since they remove all but the // first word. However, they're changed in // http://www.whatwg.org/specs/web-apps/current-work/multipage/section-document.html#media2 // (as of 2008-05-29) which says that the media attribute just points // to a media query. (The main substative difference is the relative // precedence of commas and paretheses.) bool parsedOK = GatherMedia(aMediaList, false); Debug.Assert(parsedOK, "GatherMedia returned false; we probably want to avoid trashing aMediaList"); mReporter.ClearError(); ReleaseScanner(); mHTMLMediaMode = false; return nsresult.OK; }
// Returns false only when there is a low-level error in the scanner // (out-of-memory). internal bool GatherMedia(nsMediaList aMedia, bool aInAtRule) { for (;;) { nsMediaQuery query = null; bool hitStop = false; if (!ParseMediaQuery(aInAtRule, ref query, ref hitStop)) { Debug.Assert(!hitStop, "should return true when hit stop"); mReporter.OutputError(); if (query != null) { query.SetHadUnknownExpression(); } if (aInAtRule) { char[] stopChars = { ',', '{', ';', '}', '\0' }; SkipUntilOneOf(stopChars); } else { SkipUntil(','); } // Rely on SkipUntilOneOf leaving mToken around as the last token read. if (mToken.mType == nsCSSTokenType.Symbol && aInAtRule && (mToken.mSymbol == '{' || mToken.mSymbol == ';' || mToken.mSymbol == '}')) { UngetToken(); hitStop = true; } } if (query != null) { aMedia.AppendQuery(query); } if (hitStop) { break; } } return true; }
// Parse a CSS2 import rule: "@import STRING | URL [medium [, medium]]" internal bool ParseImportRule(RuleAppendFunc aAppendFunc, object aData) { nsMediaList media = new nsMediaList(); string url = ""; if (!ParseURLOrString(ref url)) { { if (!mSuppressErrors) mReporter.ReportUnexpected("PEImportNotURI", mToken); }; return false; } if (!ExpectSymbol(';', true)) { if (!GatherMedia(media, true) || !ExpectSymbol(';', true)) { { if (!mSuppressErrors) mReporter.ReportUnexpected("PEImportUnexpected", mToken); }; // don't advance section, simply ignore invalid @import return false; } // Safe to assert this, since we ensured that there is something // other than the ';' coming after the @import's url() token. Debug.Assert(media.Count() != 0, "media list must be nonempty"); } ProcessImport(url, media, aAppendFunc, aData); return true; }
internal void SetMedia(nsMediaList aMedia) { mMedia = aMedia; }