Example #1
0
        // supports_rule
        //   : "@supports" supports_condition group_rule_body
        //   ;
        internal bool ParseSupportsRule(RuleAppendFunc aAppendFunc, object aProcessData)
        {
            bool conditionMet = false;
              var condition = new StringBuilder();

              mScanner.StartRecording();
              bool parsed = ParseSupportsCondition(ref conditionMet);

              if (!parsed) {
            mScanner.StopRecording();
            return false;
              }

              if (!ExpectSymbol('{', true)) {
            { if (!mSuppressErrors) mReporter.ReportUnexpected("PESupportsGroupRuleStart", mToken); };
            mScanner.StopRecording();
            return false;
              }

              UngetToken();
              mScanner.StopRecording(condition);

              // Remove the "{" that would follow the condition.
              if (condition.Length() != 0) {
            condition.Truncate(condition.Length() - 1);
              }

              // Remove spaces from the start and end of the recorded supports condition.
              condition.Trim(" ", true, true, false);

              // Record whether we are in a failing @supports, so that property parse
              // errors don't get reported.
              using (/*var failing = */new nsAutoFailingSupportsRule(this, conditionMet)) {

            GroupRule rule = new CSSSupportsRule(ref conditionMet, condition);
            return ParseGroupRule(rule, aAppendFunc, aProcessData);
              }
        }
Example #2
0
        /**
         * Append the textual representation of |this| to |aBuffer|.
         */
        internal void AppendToString(StringBuilder aBuffer)
        {
            switch (mType) {
            case nsCSSTokenType.Ident:
              nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer);
              break;

            case nsCSSTokenType.AtKeyword:
              aBuffer.Append('@');
              nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer);
              break;

            case nsCSSTokenType.ID:
            case nsCSSTokenType.Hash:
              aBuffer.Append('#');
              nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer);
              break;

            case nsCSSTokenType.Function:
              nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer);
              aBuffer.Append('(');
              break;

            case nsCSSTokenType.URL:
            case nsCSSTokenType.Bad_URL:
              aBuffer.AppendLiteral("url(");
              if (mSymbol != ((PRUnichar)(0))) {
                nsStyleUtil.AppendEscapedCSSString(mIdent, aBuffer, mSymbol);
              } else {
                aBuffer.Append(mIdent);
              }
              if (mType == nsCSSTokenType.URL) {
                aBuffer.Append(((PRUnichar)(')')));
              }
              break;

            case nsCSSTokenType.Number:
              if (mIntegerValid) {
                aBuffer.AppendInt(mInteger, 10);
              } else {
                aBuffer.AppendFloat(mNumber);
              }
              break;

            case nsCSSTokenType.Percentage:
              aBuffer.AppendFloat(mNumber * 100.0f);
              aBuffer.Append(((PRUnichar)('%')));
              break;

            case nsCSSTokenType.Dimension:
              if (mIntegerValid) {
                aBuffer.AppendInt(mInteger, 10);
              } else {
                aBuffer.AppendFloat(mNumber);
              }
              nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer);
              break;

            case nsCSSTokenType.Bad_String:
              nsStyleUtil.AppendEscapedCSSString(mIdent, aBuffer, mSymbol);
              // remove the trailing quote character
              aBuffer.Truncate(aBuffer.Length() - 1);
              break;

            case nsCSSTokenType.String:
              nsStyleUtil.AppendEscapedCSSString(mIdent, aBuffer, mSymbol);
              break;

            case nsCSSTokenType.Symbol:
              aBuffer.Append(mSymbol);
              break;

            case nsCSSTokenType.Whitespace:
              aBuffer.Append(' ');
              break;

            case nsCSSTokenType.HTMLComment:
            case nsCSSTokenType.URange:
              aBuffer.Append(mIdent);
              break;

            case nsCSSTokenType.Includes:
              aBuffer.AppendLiteral("~=");
              break;
            case nsCSSTokenType.Dashmatch:
              aBuffer.AppendLiteral("|=");
              break;
            case nsCSSTokenType.Beginsmatch:
              aBuffer.AppendLiteral("^=");
              break;
            case nsCSSTokenType.Endsmatch:
              aBuffer.AppendLiteral("$=");
              break;
            case nsCSSTokenType.Containsmatch:
              aBuffer.AppendLiteral("*=");
              break;

            default:
              throw new Exception("invalid token type");
              break;
              }
        }