Exemple #1
0
        public void StyleAddTest()
        {
            var style = new style();

            style.add("border: 5px solid red; background-image: value", "base");
            style.add("border: 5px solid red!important; background-image: value", "base");
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        public override void add_style(style st)
        {
            base.add_style(st);
            var content = get_style_property("content", false, "");

            if (!string.IsNullOrEmpty(content))
            {
                var idx = html.value_index(content, types.content_property_string);
                if (idx < 0)
                {
                    var fnc = string.Empty;
                    var i   = 0;
                    while (i < content.Length && i != -1)
                    {
                        if (content[i] == '"')
                        {
                            fnc = string.Empty;
                            i++;
                            var    pos = content.IndexOf('"', i);
                            string txt;
                            if (pos == -1)
                            {
                                txt = content.Substring(i); i = -1;
                            }
                            else
                            {
                                txt = content.Substring(i, pos - i); i = pos + 1;
                            }
                            add_text(txt);
                        }
                        else if (content[i] == '(')
                        {
                            i++;
                            fnc = fnc.Trim().ToLowerInvariant();
                            var    pos = content.IndexOf(')', i);
                            string args;
                            if (pos == -1)
                            {
                                args = content.Substring(i); i = -1;
                            }
                            else
                            {
                                args = content.Substring(i, pos - i); i = pos + 1;
                            }
                            add_function(fnc, args);
                            fnc = string.Empty;
                        }
                        else
                        {
                            fnc += content[i];
                            i++;
                        }
                    }
                }
            }
        }
Exemple #4
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);
        }
Exemple #5
0
        public void StyleAddPropertyTest()
        {
            var style = new style();

            style.add_property("background-image", "value", "base", false);
            style.add_property("border-spacing", "1", null, false);
            style.add_property("border-spacing", "1 2", null, false);
            style.add_property("border", "5px solid red", null, false);
            style.add_property("border-left", "5px solid red", null, false);
            style.add_property("border-right", "5px solid red", null, false);
            style.add_property("border-top", "5px solid red", null, false);
            style.add_property("border-bottom", "5px solid red", null, false);
            style.add_property("border-front", "5px solid red", null, false); //:h3ml
            style.add_property("border-back", "5px solid red", null, false);  //:h3ml
            style.add_property("border-bottom-left-radius", "1", null, false);
            style.add_property("border-bottom-left-radius", "1 2", null, false);
            style.add_property("border-bottom-left-radius", "1 2 3", null, false); //:h3ml
            style.add_property("border-bottom-right-radius", "1", null, false);
            style.add_property("border-bottom-right-radius", "1 2", null, false);
            style.add_property("border-bottom-right-radius", "1 2 3", null, false); //:h3ml
            style.add_property("border-top-right-radius", "1", null, false);
            style.add_property("border-top-right-radius", "1 2", null, false);
            style.add_property("border-top-right-radius", "1 2 3", null, false); //:h3ml
            style.add_property("border-top-left-radius", "1", null, false);
            style.add_property("border-top-left-radius", "1 2", null, false);
            style.add_property("border-top-left-radius", "1 2 3", null, false); //:h3ml
            style.add_property("border-radius", "1", null, false);
            style.add_property("border-radius", "1 2", null, false);
            style.add_property("border-radius", "1 2 3", null, false); //:h3ml
            style.add_property("border-radius-x", "1", null, false);
            style.add_property("border-radius-x", "1 2", null, false);
            style.add_property("border-radius-x", "1 2 3", null, false);
            style.add_property("border-radius-x", "1 2 3 4", null, false);
            style.add_property("border-radius-y", "1", null, false);
            style.add_property("border-radius-y", "1 2", null, false);
            style.add_property("border-radius-y", "1 2 3", null, false);
            style.add_property("border-radius-y", "1 2 3 4", null, false);
            style.add_property("border-radius-z", "1", null, false);       //:h3ml
            style.add_property("border-radius-z", "1 2", null, false);     //:h3ml
            style.add_property("border-radius-z", "1 2 3", null, false);   //:h3ml
            style.add_property("border-radius-z", "1 2 3 4", null, false); //:h3ml
            style.add_property("list-style-image", "value", "base", false);
            style.add_property("background", "url(value)", "base", false);
            style.add_property("background", "repeat", null, false);
            style.add_property("background", "fixed", null, false);
            style.add_property("background", "border-box", null, false);
            style.add_property("background", "border-box border-box", null, false);
            style.add_property("background", "left", null, false);
            style.add_property("background", "1", null, false);
            style.add_property("background", "-1", null, false);
            style.add_property("background", "-1", null, false);
            style.add_property("background", "+1", null, false);
            style.add_property("background", "left 1", null, false);
            style.add_property("background", "red", null, false);
            style.add_property("margin", "1", null, false);
            style.add_property("margin", "1 2", null, false);
            style.add_property("margin", "1 2 3", null, false);
            style.add_property("margin", "1 2 3 4", null, false);
            style.add_property("padding", "1", null, false);
            style.add_property("padding", "1 2", null, false);
            style.add_property("padding", "1 2 3", null, false);
            style.add_property("padding", "1 2 3 4", null, false);
            style.add_property("border-left", "TBD", null, false);
            style.add_property("border-left", "TBD", null, false);
            style.add_property("border-left", "TBD", null, false);
            style.add_property("border-left", "TBD", null, false);
            style.add_property("border-right", "TBD", null, false);
            style.add_property("border-right", "TBD", null, false);
            style.add_property("border-right", "TBD", null, false);
            style.add_property("border-right", "TBD", null, false);
            style.add_property("border-top", "TBD", null, false);
            style.add_property("border-top", "TBD", null, false);
            style.add_property("border-top", "TBD", null, false);
            style.add_property("border-top", "TBD", null, false);
            style.add_property("border-bottom", "TBD", null, false);
            style.add_property("border-bottom", "TBD", null, false);
            style.add_property("border-bottom", "TBD", null, false);
            style.add_property("border-bottom", "TBD", null, false);
            style.add_property("border-front", "TBD", null, false); //:h3ml
            style.add_property("border-front", "TBD", null, false); //:h3ml
            style.add_property("border-front", "TBD", null, false); //:h3ml
            style.add_property("border-front", "TBD", null, false); //:h3ml
            style.add_property("border-back", "TBD", null, false);  //:h3ml
            style.add_property("border-back", "TBD", null, false);  //:h3ml
            style.add_property("border-back", "TBD", null, false);  //:h3ml
            style.add_property("border-back", "TBD", null, false);  //:h3ml
            style.add_property("border-width", "1", null, false);
            style.add_property("border-width", "1 2", null, false);
            style.add_property("border-width", "1 2 3", null, false);
            style.add_property("border-width", "1 2 3 4", null, false);
            style.add_property("border-style", "1", null, false);
            style.add_property("border-style", "1 2", null, false);
            style.add_property("border-style", "1 2 3", null, false);
            style.add_property("border-style", "1 2 3 4", null, false);
            style.add_property("border-color", "1", null, false);
            style.add_property("border-color", "1 2", null, false);
            style.add_property("border-color", "1 2 3", null, false);
            style.add_property("border-color", "1 2 3 4", null, false);
            style.add_property("font", "TBD", null, false);
            style.add_property("font", "TBD", null, false);
            style.add_property("font", "TBD", null, false);
            style.add_property("font", "TBD", null, false);
            style.add_property("unknown", "value", null, false);
        }