コード例 #1
0
 private static List <MatchedRule> MatchingRules(Dom.ElementData elem, Css.Stylesheet stylesheet)
 {
     return(stylesheet.Rules
            .Select(rule => MatchRule(elem, rule))
            .Where(rule => rule != null)
            .ToList());
 }
コード例 #2
0
        public static StyledNode StyleTree(Dom.Node root, Css.Stylesheet stylesheet)
        {
            var specifiedValues = new Dictionary <string, Css.Value>();

            switch (root.NodeType)
            {
            case Dom.ElementData elem:
                specifiedValues = GetSpecifiedValues(elem, stylesheet);
                break;
            }

            var children = root.Children.Select(child => StyleTree(child, stylesheet)).ToList();

            return(new StyledNode(root, specifiedValues, children));
        }
コード例 #3
0
        private static Dictionary <string, Css.Value> GetSpecifiedValues(Dom.ElementData elem, Css.Stylesheet stylesheet)
        {
            var values = new Dictionary <string, Css.Value>();
            var rules  = MatchingRules(elem, stylesheet)
                         .OrderBy(rule => rule.Specificity.Calc())
                         .Select(r => r.Rule);

            foreach (var rule in rules)
            {
                foreach (var declaration in rule.Declarations)
                {
                    values[declaration.Name] = declaration.Value;
                }
            }

            return(values);
        }