Exemple #1
0
        public void ResolveStyle(bool recursive = false)
        {
            markedStyleResolve          = false;
            markedStyleResolveRecursive = false;

            var inheritedChanges = ComputedStyle.HasInheritedChanges;


            var inlineStyles  = RuleHelpers.GetRuleDic(Style);
            var inlineLayouts = RuleHelpers.GetLayoutDic(Style);

            if (inlineLayouts != null)
            {
                foreach (var l in inlineLayouts)
                {
                    inlineStyles[l.prop.name] = l.value;
                }
            }

            List <RuleTreeNode <StyleData> > matchingRules;

            if (Tag == "_before")
            {
                matchingRules = Parent.BeforeRules;
            }
            else if (Tag == "_after")
            {
                matchingRules = Parent.AfterRules;
            }
            else
            {
                matchingRules = Context.StyleTree.GetMatchingRules(this).ToList();
            }

            var importantIndex = Math.Max(0, matchingRules.FindIndex(x => x.Specifity <= RuleHelpers.ImportantSpecifity));
            var cssStyles      = new List <Dictionary <string, object> > {
            };

            for (int i = 0; i < importantIndex; i++)
            {
                cssStyles.AddRange(matchingRules[i].Data?.Rules);
            }
            cssStyles.Add(inlineStyles);
            for (int i = importantIndex; i < matchingRules.Count; i++)
            {
                cssStyles.AddRange(matchingRules[i].Data?.Rules);
            }

            ComputedStyle.CssStyles = cssStyles;
            ApplyStyles();
            ApplyLayoutStyles();
            ComputedStyle.MarkChangesSeen();


            if (inheritedChanges || recursive)
            {
                BeforeRules = Context.StyleTree.GetMatchingBefore(this).ToList();
                //if (BeforeRules.Count > 0) AddBefore();
                //else RemoveBefore();
                BeforePseudo?.ResolveStyle();

                foreach (var child in Children)
                {
                    child.ResolveStyle(true);
                }

                AfterRules = Context.StyleTree.GetMatchingAfter(this).ToList();
                //if (AfterRules.Count > 0) AddAfter();
                //else RemoveAfter();
                AfterPseudo?.ResolveStyle();
            }
        }