Esempio n. 1
0
 public void add_media_list(media_query_list list)
 {
     if (list != null && !_media_lists.Contains(list))
     {
         _media_lists.Add(list);
     }
 }
Esempio n. 2
0
 public css_selector(css_element_selector right)
 {
     _right       = right;
     _media_query = null;
     _combinator  = css_combinator.descendant;
     _order       = 0;
 }
Esempio n. 3
0
        public void parse_stylesheet(string str, string baseurl, document doc, media_query_list media)
        {
            var text = str;

            // remove comments
            var c_start = text.IndexOf("/*");

            while (c_start != -1)
            {
                var c_end = text.IndexOf("*/", c_start + 2);
                text    = text.Substring(0, c_start) + text.Substring(c_end + 2);
                c_start = text.IndexOf("/*");
            }

            var pos = text.FindFirstNotOf(" \n\r\t");

            while (pos != -1)
            {
                while (pos != -1 && text[pos] == '@')
                {
                    var sPos = pos;
                    pos = text.IndexOfAny(delims1, pos);
                    if (pos != -1 && text[pos] == '{')
                    {
                        pos = html.find_close_bracket(text, pos, '{', '}');
                    }
                    parse_atrule(pos != -1 ? text.Substring(sPos, pos - sPos + 1) : text.Substring(sPos), baseurl, doc, media);
                    if (pos != -1)
                    {
                        pos = text.FindFirstNotOf(" \n\r\t", pos + 1);
                    }
                }
                if (pos == -1)
                {
                    break;
                }
                var style_start = text.IndexOf("{", pos);
                var style_end   = text.IndexOf("}", pos);
                if (style_start != -1 && style_end != -1)
                {
                    var st = new style();
                    st.add(text.Substring(style_start + 1, style_end - style_start - 1), baseurl);
                    parse_selectors(text.Substring(pos, style_start - pos), st, media);
                    if (media != null && doc != null)
                    {
                        doc.add_media_list(media);
                    }
                    pos = style_end + 1;
                }
                else
                {
                    pos = -1;
                }
                if (pos != -1)
                {
                    pos = text.FindFirstNotOf(" \n\r\t", pos);
                }
            }
        }
Esempio n. 4
0
 void parse_atrule(string text, string baseurl, document doc, media_query_list media)
 {
     if (text.StartsWith("@import"))
     {
         var sPos = 7;
         var iStr = text.Substring(sPos);
         if (iStr[iStr.Length - 1] == ';')
         {
             iStr = iStr.Remove(iStr.Length - 1);
         }
         iStr = iStr.Trim();
         var tokens = new List <string>();
         html.split_string(iStr, tokens, " ", "", "(\"");
         if (tokens.Count != 0)
         {
             parse_css_url(tokens.First(), out var url);
             if (string.IsNullOrEmpty(url))
             {
                 url = tokens.First();
             }
             tokens.RemoveAt(0);
             if (doc != null)
             {
                 var doc_cont = doc.container;
                 if (doc_cont != null)
                 {
                     var css_baseurl = baseurl ?? string.Empty;
                     doc_cont.import_css(out var css_text, url, ref css_baseurl);
                     if (!string.IsNullOrEmpty(css_text))
                     {
                         var new_media = media;
                         if (tokens.Count != 0)
                         {
                             var media_str = string.Join(" ", tokens);
                             new_media = media_query_list.create_from_string(media_str, doc);
                             if (new_media == null)
                             {
                                 new_media = media;
                             }
                         }
                         parse_stylesheet(css_text, css_baseurl, doc, new_media);
                     }
                 }
             }
         }
     }
     else if (text.StartsWith("@media"))
     {
         var b1 = text.IndexOf('{');
         var b2 = text.LastIndexOf('}');
         if (b1 != -1)
         {
             var media_type  = text.Substring(6, b1 - 6).Trim();
             var new_media   = media_query_list.create_from_string(media_type, doc);
             var media_style = b2 != -1 ? text.Substring(b1 + 1, b2 - b1 - 1) : text.Substring(b1 + 1);
             parse_stylesheet(media_style, baseurl, doc, new_media);
         }
     }
 }
Esempio n. 5
0
 public css_selector(css_selector val)
 {
     _right       = val._right;
     _left        = val._left;
     _combinator  = val._combinator;
     _specificity = val._specificity;
     _order       = val._order;
     _media_query = val._media_query;
 }
Esempio n. 6
0
        public static media_query_list create_from_string(string str, document doc)
        {
            var tokens = new List <string>();

            html.split_string(str, tokens, ",");
            var list = new media_query_list();

            for (var i = 0; i < tokens.Count; i++)
            {
                var tok   = tokens[i].Trim().ToLowerInvariant();
                var query = media_query.create_from_string(tok, doc);
                if (query != null)
                {
                    list._queries.Add(query);
                }
            }
            return(list._queries.Count != 0 ? list : null);
        }
Esempio n. 7
0
        bool parse_selectors(string txt, style styles, media_query_list media)
        {
            var tokens = new List <string>();

            html.split_string(txt.Trim(), tokens, ",");
            var added_something = false;

            foreach (var tok in tokens)
            {
                var selector = new css_selector(media);
                selector._style = styles;
                if (selector.parse(tok.Trim()))
                {
                    selector.calc_specificity();
                    add_selector(selector);
                    added_something = true;
                }
            }
            return(added_something);
        }
Esempio n. 8
0
 public css_selector(media_query_list media = null)
 {
     _media_query = media;
     _combinator  = css_combinator.descendant;
     _order       = 0;
 }
Esempio n. 9
0
 public media_query_list(media_query_list val)
 {
     _is_used = val._is_used;
     _queries = val._queries;
 }