Esempio n. 1
0
        public void ApplyCssText(string cssText)
        {
            if (!string.IsNullOrEmpty(cssText))
            {
                var stylesheet = CSSParser.ParseCSSStyleSheet(cssText, string.Empty, true);

                this.ApplyCssRules(stylesheet.cssRules, string.Empty);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// parse and download the stylesheets and make them available at StyleSheets.
        /// </summary>
        public void ParseStyleSheet()
        {
            HTMLCollection styletags = this.getElementsByTagName("link, style");

            HTMLCollection availablesheets = new HTMLCollection();

            foreach (var item in styletags.item)
            {
                if (item.tagName == "style")
                {
                    availablesheets.Add(item);
                }

                else if (item.hasAttribute("type"))
                {
                    if (item.getAttribute("type").ToLower().Contains("css"))
                    {
                        availablesheets.Add(item);
                    }
                }
                else if (item.hasAttribute("rel"))
                {
                    if (item.getAttribute("rel").ToLower().Contains("stylesheet"))
                    {
                        availablesheets.Add(item);
                    }
                }
            }

            foreach (var item in availablesheets.item)
            {
                if (item.tagName == "link")
                {
                    string href = item.getAttribute("href");

                    if (string.IsNullOrEmpty(href))
                    {
                        continue;
                    }

                    string absoluteUrl = PathHelper.combine(this.getBaseUrl(), href);

                    string cssText = Loader.LoadCss(absoluteUrl);

                    if (string.IsNullOrEmpty(cssText))
                    {
                        continue;
                    }

                    CSSStyleSheet newStyleSheet = CSSParser.ParseCSSStyleSheet(cssText, absoluteUrl, true);
                    newStyleSheet.ownerNode = item;

                    if (newStyleSheet != null)
                    {
                        newStyleSheet.ownerNode = item;

                        string media = item.getAttribute("media");
                        if (!string.IsNullOrEmpty(media))
                        {
                            string[] medialist = media.Split(',');
                            foreach (var mediaitem in medialist)
                            {
                                newStyleSheet.Medialist.appendMedium(mediaitem);
                            }
                        }
                        this.StyleSheets.appendStyleSheet(newStyleSheet);
                    }
                }

                else if (item.tagName == "style")
                {
                    string cssText = item.InnerHtml;

                    CSSStyleSheet newStyleSheet = CSSParser.ParseCSSStyleSheet(cssText, this.getBaseUrl(), true);

                    newStyleSheet.ownerNode = item;

                    string media = item.getAttribute("media");
                    if (!string.IsNullOrEmpty(media))
                    {
                        string[] medialist = media.Split(',');
                        foreach (var mediaitem in medialist)
                        {
                            newStyleSheet.Medialist.appendMedium(mediaitem);
                        }
                    }
                    this.StyleSheets.appendStyleSheet(newStyleSheet);
                }
            }

            hasParseCSS = true;
        }