Exemple #1
0
        /// <summary>
        /// Tries to read and set media constraints for the provided medium.
        /// </summary>
        Boolean TrySetConstraint(CssMedium medium, ref CssToken token)
        {
            if (token.Type != CssTokenType.Ident)
            {
                _tokenizer.JumpToClosedArguments();
                token = _tokenizer.Get();
                return(false);
            }

            var value       = Pool.NewValueBuilder();
            var featureName = token.Data;
            var val         = CssValue.Empty;
            var feature     = _parser.Options.IsToleratingInvalidConstraints ?
                              new UnknownMediaFeature(featureName) : Factory.MediaFeatures.Create(featureName);

            token = _tokenizer.Get();

            if (token.Type == CssTokenType.Colon)
            {
                _tokenizer.State = CssParseMode.Value;
                token            = _tokenizer.Get();

                while (token.Type != CssTokenType.RoundBracketClose || value.IsReady == false)
                {
                    if (token.Type == CssTokenType.Eof)
                    {
                        break;
                    }

                    value.Apply(token);
                    token = _tokenizer.Get();
                }

                _tokenizer.State = CssParseMode.Data;

                val = value.ToPool();
            }
            else if (token.Type == CssTokenType.Eof)
            {
                return(false);
            }

            if (feature != null && feature.TrySetValue(val))
            {
                medium.AddConstraint(feature);
                return(true);
            }

            return(false);
        }