示例#1
0
        /// <summary>
        /// apply css rules to current document.
        /// </summary>
        /// <param name="dom"></param>
        /// <param name="rulelist"></param>
        /// <param name="mediadeviceInfo"></param>
        public void ApplyCssRules(CSS.CSSRuleList rulelist, string mediadeviceInfo)
        {
            if (rulelist == null)
            {
                return;
            }

            foreach (var item in rulelist.item)
            {
                if (item.type == CSS.enumCSSRuleType.STYLE_RULE)
                {
                    CSS.CSSStyleRule stylerule = item as CSS.CSSStyleRule;

                    foreach (var elemntitem in this.Select(stylerule.selectorText).item)
                    {
                        elemntitem.StyleRules.Add(stylerule);
                    }
                }
                else if (item.type == CSS.enumCSSRuleType.MEDIA_RULE)
                {
                    CSS.CSSMediaRule mediarule = item as CSS.CSSMediaRule;

                    if (string.IsNullOrEmpty(mediadeviceInfo))
                    {
                        ApplyCssRules(mediarule.cssRules, string.Empty);
                    }
                    else
                    {
                        if (MediaQuery.isMatch(mediarule.media, mediadeviceInfo))
                        {
                            ApplyCssRules(mediarule.cssRules, string.Empty);
                        }
                    }
                }
                else if (item.type == enumCSSRuleType.IMPORT_RULE)
                {
                    CSS.CSSImportRule importrule = item as CSS.CSSImportRule;

                    if (importrule.stylesheet != null && importrule.stylesheet.cssRules != null)
                    {
                        if (MediaQuery.isMatch(importrule.media, mediadeviceInfo))
                        {
                            ApplyCssRules(importrule.stylesheet.cssRules, mediadeviceInfo);
                        }
                    }
                }
            }
        }