internal nsresult ParseDeclarations(string aBuffer, Uri aSheetURI, Uri aBaseURI, nsIPrincipal aSheetPrincipal, Declaration aDeclaration, ref bool aChanged) { aChanged = false; if (aSheetPrincipal == null) throw new ArgumentException("Must have principal here!"); var scanner = new nsCSSScanner(aBuffer, 0); var reporter = new ErrorReporter(scanner, mSheet, mChildLoader, aSheetURI); InitScanner(scanner, reporter, aSheetURI, aBaseURI, aSheetPrincipal); mSection = nsCSSSection.General; mData.AssertInitialState(); aDeclaration.ClearData(); // We could check if it was already empty, but... aChanged = true; for (;;) { // If we cleared the old decl, then we want to be calling // ValueAppended as we parse. if (!ParseDeclaration(aDeclaration, nsParseDeclaration.AllowImportant, true, ref aChanged)) { if (!SkipDeclaration(false)) { break; } } } aDeclaration.CompressFrom(mData); ReleaseScanner(); return nsresult.OK; }
internal nsresult ParseProperty(nsCSSProperty aPropID, string aPropValue, Uri aSheetURI, Uri aBaseURI, nsIPrincipal aSheetPrincipal, Declaration aDeclaration, ref bool aChanged, bool aIsImportant, bool aIsSVGMode) { if (aSheetPrincipal == null) throw new ArgumentException("Must have principal here!"); if (aBaseURI == null) throw new ArgumentException("need base URI"); if (aDeclaration == null) throw new ArgumentException("Need declaration to parse into!"); mData.AssertInitialState(); mTempData.AssertInitialState(); aDeclaration.AssertMutable(); var scanner = new nsCSSScanner(aPropValue, 0); var reporter = new ErrorReporter(scanner, mSheet, mChildLoader, aSheetURI); InitScanner(scanner, reporter, aSheetURI, aBaseURI, aSheetPrincipal); mSection = nsCSSSection.General; scanner.SetSVGMode(aIsSVGMode); aChanged = false; // Check for unknown or preffed off properties if (nsCSSProperty.Unknown == aPropID || !nsCSSProps.IsEnabled(aPropID)) { string propName = nsCSSProps.GetStringValue(aPropID); { if (!mSuppressErrors) mReporter.ReportUnexpected("PEUnknownProperty", propName); }; { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclDropped"); }; mReporter.OutputError(); ReleaseScanner(); return nsresult.OK; } bool parsedOK = ParseProperty(aPropID); // We should now be at EOF if (parsedOK && GetToken(true)) { { if (!mSuppressErrors) mReporter.ReportUnexpected("PEExpectEndValue", mToken); }; parsedOK = false; } if (!parsedOK) { string propName = nsCSSProps.GetStringValue(aPropID); { if (!mSuppressErrors) mReporter.ReportUnexpected("PEValueParsingError", propName); }; { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclDropped"); }; mReporter.OutputError(); mTempData.ClearProperty(aPropID); } else { // We know we don't need to force a ValueAppended call for the new // value. So if we are not processing a shorthand, and there's // already a value for this property in the declaration at the // same importance level, then we can just copy our parsed value // directly into the declaration without going through the whole // expand/compress thing. if (!aDeclaration.TryReplaceValue(aPropID, aIsImportant, mTempData, ref aChanged)) { // Do it the slow way aDeclaration.ExpandTo(mData); aChanged = mData.TransferFromBlock(mTempData, aPropID, aIsImportant, true, false, aDeclaration); aDeclaration.CompressFrom(mData); } mReporter.ClearError(); } mTempData.AssertInitialState(); ReleaseScanner(); return nsresult.OK; }
internal Declaration ParseDeclarationBlock(nsParseDeclaration aFlags, nsCSSContextType aContext = nsCSSContextType.General) { bool checkForBraces = (aFlags & nsParseDeclaration.InBraces) != 0; if (checkForBraces) { if (!ExpectSymbol('{', true)) { { if (!mSuppressErrors) mReporter.ReportUnexpected("PEBadDeclBlockStart", mToken); }; mReporter.OutputError(); return null; } } Declaration declaration = new Declaration(); mData.AssertInitialState(); if (declaration != null) { for (;;) { bool changed = false; if (!ParseDeclaration(declaration, aFlags, true, ref changed, aContext)) { if (!SkipDeclaration(checkForBraces)) { break; } if (checkForBraces) { if (ExpectSymbol('}', true)) { break; } } // Since the skipped declaration didn't end the block we parse // the next declaration. } } declaration.CompressFrom(mData); } return declaration; }