Beispiel #1
0
 internal CssStyleSheet(CssParser parser, String url, IElement owner)
 {
     _media = new MediaList(parser);
     _owner = owner;
     _url = url;
     _rules = new CssRuleList(this);
     _parser = parser;
 }
Beispiel #2
0
 /// <summary>
 /// Creates a new CSS import rule
 /// </summary>
 internal CssImportRule(CssParser parser)
     : base(CssRuleType.Import, parser)
 {
     _media = new MediaList(parser);
 }
 /// <summary>
 /// Creates a media list for the given source.
 /// </summary>
 /// <param name="source">The media source.</param>
 /// <param name="options">
 /// The options with the parameters for evaluating the style.
 /// </param>
 /// <returns>The created media list.</returns>
 public IMediaList ParseMedia(String source, StyleOptions options)
 {
     var parser = new CssParser(_options, options.Configuration);
     var media = new MediaList(parser);
     media.MediaText = source;
     return media;
 }
Beispiel #4
0
        /// <summary>
        /// Before any medium has been found for the @media or @import rule.
        /// </summary>
        void FillMediaList(MediaList list, CssTokenType end, ref CssToken token)
        {
            if (token.Type == end)
                return;

            while (token.Type != CssTokenType.Eof)
            {
                var medium = CreateMedium(ref token);

                if (medium != null)
                    list.Add(medium);

                if (token.Type != CssTokenType.Comma)
                    break;

                token = _tokenizer.Get();
            }

            if (token.Type == end && list.Length > 0)
                return;

            list.Clear();
            list.Add(new CssMedium
            {
                IsInverse = true,
                Type = Keywords.All
            });
        }
Beispiel #5
0
        private void FillMediaList(MediaList list, CssTokenType end, ref CssToken token)
        {
            _nodes.Push(list);

            if (token.Type != end)
            {
                while (token.Type != CssTokenType.EndOfFile)
                {
                    var medium = CreateMedium(ref token);

                    if (medium != null)
                    {
                        list.AppendChild(medium);
                    }

                    if (token.Type != CssTokenType.Comma)
                    {
                        break;
                    }

                    token = NextToken();
                    CollectTrivia(ref token);
                }

                if (token.Type != end || list.Length == 0)
                {
                    list.Clear();
                    list.AppendChild(new CssMedium
                    {
                        IsInverse = true,
                        Type = Keywords.All
                    });
                }
            }

            _nodes.Pop();
        }
Beispiel #6
0
 /// <summary>
 /// Creates a new CSS @media rule with a new media list.
 /// </summary>
 internal CssMediaRule(CssParser parser)
     : base(CssRuleType.Media, parser)
 {
     _media = new MediaList(parser);
 }
Beispiel #7
0
 /// <summary>
 /// Imports the media from the given list.
 /// Clears the existing media.
 /// </summary>
 /// <param name="list">The list to import.</param>
 public void Import(MediaList list)
 {
     _media.Clear();
     _media.AddRange(list._media);
 }
Beispiel #8
0
 /// <summary>
 /// Creates a media list for the given source.
 /// </summary>
 /// <param name="source">The media source.</param>
 /// <param name="options">
 /// The options with the parameters for evaluating the style.
 /// </param>
 /// <returns>The created media list.</returns>
 public IMediaList ParseMedia(String source, StyleOptions options)
 {
     var configuration = options.Context.Configuration;
     var parser = new CssParser(_options, configuration);
     var media = new MediaList(parser) { MediaText = source };
     return media;
 }
Beispiel #9
0
 /// <summary>
 /// Creates a new style sheet.
 /// </summary>
 /// <param name="media">The media list to use.</param>
 internal StyleSheet(MediaList media)
 {
     _media = media;
 }
        /// <summary>
        /// Before any medium has been found for the @media or @import rule.
        /// </summary>
        protected void FillMediaList(MediaList list, ref CssToken token)
        {
            if (token.Type != CssTokenType.CurlyBracketOpen)
            {
                while (token.Type != CssTokenType.Eof)
                {
                    var medium = CreateMedium(ref token);

                    if (medium != null)
                        list.Add(medium);

                    if (token.Type != CssTokenType.Comma)
                        break;

                    token = _tokenizer.Get();
                }

                if (token.Type != CssTokenType.CurlyBracketOpen)
                {
                    do
                    {
                        if (token.Type == CssTokenType.Eof || token.Type == CssTokenType.Semicolon)
                            break;

                        token = _tokenizer.Get();
                    }
                    while (token.Type != CssTokenType.CurlyBracketOpen);

                    list.Clear();
                }

                if (list.Length == 0)
                {
                    list.Add(new CssMedium
                    {
                        IsInverse = true,
                        Type = Keywords.All
                    });
                }
            }
        }
Beispiel #11
0
        public void CssMediaListApiWithAppendDeleteAndTextShouldWork()
        {
            var media = new [] { "handheld", "screen", "only screen and (max-device-width: 480px)" };
            var p = new CssParser();
		    var m = new MediaList(p);
            Assert.AreEqual(0, m.Length);

		    m.Add(media[0]);
		    m.Add(media[1]);
		    m.Add(media[2]);

		    m.Remove(media[1]);

            Assert.AreEqual(2, m.Length);
            Assert.AreEqual(media[0], m[0]);
            Assert.AreEqual(media[2], m[1]);
            Assert.AreEqual(String.Concat(media[0], ", ", media[2]), m.MediaText);
        }