Example #1
0
        /// <summary>
        ///  desrialized rule list. ImportRule is at the beginning of file, and should be ignored.
        /// </summary>
        /// <param name="cssText"></param>
        /// <param name="basehref">the base href for import rule. </param>
        /// <returns></returns>
        public static CSSRuleList deserializeRuleList(string cssText, string basehref)
        {
            CSSRuleList rules = new CSSRuleList();

            CSSFileScanner filescanner = new CSSFileScanner(cssText);

            CSSFileScannerResult result = filescanner.ReadNext();

            while (result != null)
            {
                if (result.type == enumCSSRuleType.STYLE_RULE)
                {
                    CSSStyleRule stylerule = deserializeCSSStyleRule(result.cssText);
                    if (stylerule != null)
                    {
                        rules.appendRule(stylerule);
                    }
                }
                else if (result.type == enumCSSRuleType.IMPORT_RULE)
                {
                    CSSImportRule importrule = deserializeCSSImportRule(result.cssText, basehref);
                    if (importrule != null)
                    {
                        rules.appendRule(importrule);
                    }
                }
                else if (result.type == enumCSSRuleType.MEDIA_RULE)
                {
                    CSSMediaRule mediarule = deserializeCSSMediaRule(result.cssText);
                    if (mediarule != null)
                    {
                        rules.appendRule(mediarule);
                    }
                }
                else
                {
                    //TODO: other rules are not implemented now.
                }

                result = filescanner.ReadNext();
            }

            return(rules);
        }
Example #2
0
 private static void addStylesheetRules(CSSStyleSheet stylesheet, CSSRuleList ownerRuleList)
 {
     foreach (var item in stylesheet.cssRules.item)
     {
         if (item.type == enumCSSRuleType.STYLE_RULE)
         {
             ownerRuleList.appendRule(item);
         }
         else if (item.type == enumCSSRuleType.IMPORT_RULE)
         {
             addImportRule((CSSImportRule)item, ownerRuleList);
         }
         else if (item.type == enumCSSRuleType.MEDIA_RULE)
         {
             addMediaRule((CSSMediaRule)item, ownerRuleList);
         }
     }
 }
Example #3
0
        private static void addMediaRule(CSSMediaRule rule, CSSRuleList ownerRuleList)
        {
            bool isMatch = false;

            if (rule.media.item.Count > 0)
            {
                foreach (var subitem in rule.media.item)
                {
                    if (subitem.ToLower().Contains("all"))
                    {
                        isMatch = true;
                    }
                }
            }
            else
            {
                isMatch = true;
            }

            if (isMatch)
            {
                foreach (var item in rule.cssRules.item)
                {
                    if (item.type == enumCSSRuleType.STYLE_RULE)
                    {
                        ownerRuleList.appendRule(item);
                    }
                    else if (item.type == enumCSSRuleType.IMPORT_RULE)
                    {
                        addImportRule((CSSImportRule)item, ownerRuleList);
                    }
                    else if (item.type == enumCSSRuleType.MEDIA_RULE)
                    {
                        addMediaRule((CSSMediaRule)item, ownerRuleList);
                    }
                }
            }
        }