예제 #1
0
        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;
        }