Пример #1
0
 public bool TransferFromBlock(nsCSSExpandedDataBlock aFromBlock, CssProperty aPropID,
     bool aIsImportant, bool aOverrideImportant, bool aMustCallValueAppended, CssDeclaration aDeclaration)
 {
     if (!nsCSSProps.IsShorthand(aPropID))
         return DoTransferFromBlock(aFromBlock, aPropID, aIsImportant, aOverrideImportant, aMustCallValueAppended, aDeclaration);
     bool changed = false;
     foreach (CssProperty p in nsCSSProps.SubpropertyEntryFor(aPropID, true))
         changed |= DoTransferFromBlock(aFromBlock, p, aIsImportant, aOverrideImportant, aMustCallValueAppended, aDeclaration);
     return changed;
 }
Пример #2
0
 internal CssStyleRule(CssSelectorGroup aSelector, CssDeclaration aDeclaration)
 {
     mSelector = aSelector;
     mDeclaration = aDeclaration;
 }
Пример #3
0
 internal CssPageRule(CssDeclaration aDeclaration)
 {
     mDeclaration = aDeclaration;
 }
Пример #4
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;
        }
Пример #5
0
        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;
        }
Пример #6
0
        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;
        }
Пример #7
0
        //----------------------------------------------------------------------
        internal bool ParseDeclaration(Declaration aDeclaration,
                                        nsParseDeclaration aFlags,
                                        bool aMustCallValueAppended,
                                        ref bool aChanged,
                                        nsCSSContextType aContext = nsCSSContextType.General)
        {
            if (!(aContext == nsCSSContextType.General ||
                          aContext == nsCSSContextType.Page)) throw new ArgumentException("Must be page or general context");
              bool checkForBraces = (aFlags & nsParseDeclaration.InBraces) != 0;

              mTempData.AssertInitialState();

              // Get property name
              nsCSSToken tk = mToken;
              string propertyName;
              for (;;) {
            if (!GetToken(true)) {
              if (checkForBraces) {
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclEndEOF"); };
              }
              return false;
            }
            if (nsCSSTokenType.Ident == tk.mType) {
              propertyName = tk.mIdentStr;
              // grab the ident before the ExpectSymbol trashes the token
              if (!ExpectSymbol(':', true)) {
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEParseDeclarationNoColon", mToken); };
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclDropped"); };
                mReporter.OutputError();
                return false;
              }
              break;
            }
            if (tk.IsSymbol(';')) {
              // dangling semicolons are skipped
              continue;
            }

            if (!tk.IsSymbol('}')) {
              { if (!mSuppressErrors) mReporter.ReportUnexpected("PEParseDeclarationDeclExpected", mToken); };
              { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclSkipped"); };
              mReporter.OutputError();
            }
            // Not a declaration...
            UngetToken();
            return false;
              }

              // Don't report property parse errors if we're inside a failing @supports
              // rule.
              using (/*var suppressErrors = */new nsAutoSuppressErrors(this, mInFailingSupportsRule)) {

            // Map property name to its ID and then parse the property
            nsCSSProperty propID = nsCSSProps.LookupProperty(propertyName,
                                                              nsCSSProps.EnabledState.Enabled);
            if (nsCSSProperty.Unknown == propID ||
               (aContext == nsCSSContextType.Page &&
                !nsCSSProps.PropHasFlags(propID, nsCSSProps.APPLIES_TO_PAGE_RULE))) { // unknown property
              if (!NonMozillaVendorIdentifier(propertyName)) {
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEUnknownProperty", propertyName); };
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclDropped"); };
                mReporter.OutputError();
              }

              return false;
            }
            if (! ParseProperty(propID)) {
              // XXX Much better to put stuff in the value parsers instead...
              { if (!mSuppressErrors) mReporter.ReportUnexpected("PEValueParsingError", propertyName); };
              { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclDropped"); };
              mReporter.OutputError();
              mTempData.ClearProperty(propID);
              mTempData.AssertInitialState();
              return false;
            }
            mReporter.ClearError();

            // Look for "!important".
            PriorityParsingStatus status;
            if ((aFlags & nsParseDeclaration.AllowImportant) != 0) {
              status = ParsePriority();
            }
            else {
              status = PriorityParsingStatus.None;
            }

            // Look for a semicolon or close brace.
            if (status != PriorityParsingStatus.Error) {
              if (!GetToken(true)) {
                // EOF is always ok
              } else if (mToken.IsSymbol(';')) {
                // semicolon is always ok
              } else if (mToken.IsSymbol('}')) {
                // brace is ok if checkForBraces, but don't eat it
                UngetToken();
                if (!checkForBraces) {
                  status = PriorityParsingStatus.Error;
                }
              } else {
                UngetToken();
                status = PriorityParsingStatus.Error;
              }
            }

            if (status == PriorityParsingStatus.Error) {
              if (checkForBraces) {
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEBadDeclOrRuleEnd2", mToken); };
              } else {
                { if (!mSuppressErrors) mReporter.ReportUnexpected("PEBadDeclEnd", mToken); };
              }
              { if (!mSuppressErrors) mReporter.ReportUnexpected("PEDeclDropped"); };
              mReporter.OutputError();
              mTempData.ClearProperty(propID);
              mTempData.AssertInitialState();
              return false;
            }

            aChanged |= mData.TransferFromBlock(mTempData, propID,
                                                 status == PriorityParsingStatus.Important,
                                                 false, aMustCallValueAppended,
                                                 aDeclaration);
            return true;
              }
        }
Пример #8
0
        private bool DoTransferFromBlock(nsCSSExpandedDataBlock aFromBlock, CssProperty aPropID,
                                         bool aIsImportant, bool aOverrideImportant, bool aMustCallValueAppended, CssDeclaration aDeclaration)
        {
            bool changed = false;

            if (aIsImportant)
            {
                if (!mPropertiesImportant.HasProperty(aPropID))
                {
                    changed = true;
                }
                mPropertiesImportant.AddProperty(aPropID);
            }
            else
            {
                if (mPropertiesImportant.HasProperty(aPropID))
                {
                    if (!aOverrideImportant)
                    {
                        aFromBlock.ClearLonghandProperty(aPropID);
                        return(false);
                    }
                    changed = true;
                    mPropertiesImportant.RemoveProperty(aPropID);
                }
            }

            if (aMustCallValueAppended || !mPropertiesSet.HasProperty(aPropID))
            {
                aDeclaration.ValueAppended(aPropID);
            }

            mPropertiesSet.AddProperty(aPropID);
            aFromBlock.mPropertiesSet.RemoveProperty(aPropID);
            changed |= MoveValue(ref aFromBlock.mValues[(int)aPropID], ref mValues[(int)aPropID]);

            return(changed);
        }
Пример #9
0
        public bool TransferFromBlock(nsCSSExpandedDataBlock aFromBlock, CssProperty aPropID,
                                      bool aIsImportant, bool aOverrideImportant, bool aMustCallValueAppended, CssDeclaration aDeclaration)
        {
            if (!nsCSSProps.IsShorthand(aPropID))
            {
                return(DoTransferFromBlock(aFromBlock, aPropID, aIsImportant, aOverrideImportant, aMustCallValueAppended, aDeclaration));
            }
            bool changed = false;

            foreach (CssProperty p in nsCSSProps.SubpropertyEntryFor(aPropID, true))
            {
                changed |= DoTransferFromBlock(aFromBlock, p, aIsImportant, aOverrideImportant, aMustCallValueAppended, aDeclaration);
            }
            return(changed);
        }
Пример #10
0
 internal CssKeyframeRule(List<float> aKeys, CssDeclaration aDeclaration)
 {
     mKeys = aKeys;
     mDeclaration = aDeclaration;
 }
Пример #11
0
        private bool DoTransferFromBlock(nsCSSExpandedDataBlock aFromBlock, CssProperty aPropID,
            bool aIsImportant, bool aOverrideImportant, bool aMustCallValueAppended, CssDeclaration aDeclaration)
        {
            bool changed = false;
            if (aIsImportant) {
                if (!mPropertiesImportant.HasProperty(aPropID))
                    changed = true;
                mPropertiesImportant.AddProperty(aPropID);
            }
            else {
                if (mPropertiesImportant.HasProperty(aPropID)) {
                    if (!aOverrideImportant) {
                        aFromBlock.ClearLonghandProperty(aPropID);
                        return false;
                    }
                    changed = true;
                    mPropertiesImportant.RemoveProperty(aPropID);
                }
            }

            if (aMustCallValueAppended || !mPropertiesSet.HasProperty(aPropID)) {
                aDeclaration.ValueAppended(aPropID);
            }

            mPropertiesSet.AddProperty(aPropID);
            aFromBlock.mPropertiesSet.RemoveProperty(aPropID);
            changed |= MoveValue(ref aFromBlock.mValues[(int)aPropID], ref mValues[(int)aPropID]);

            return changed;
        }
Пример #12
0
 internal CssKeyframeRule(List <float> aKeys, CssDeclaration aDeclaration)
 {
     mKeys        = aKeys;
     mDeclaration = aDeclaration;
 }
Пример #13
0
 internal CssPageRule(CssDeclaration aDeclaration)
 {
     mDeclaration = aDeclaration;
 }
Пример #14
0
 internal CssStyleRule(CssSelectorGroup aSelector, CssDeclaration aDeclaration)
 {
     mSelector    = aSelector;
     mDeclaration = aDeclaration;
 }