예제 #1
0
        /// <summary>
        /// Computes the cascaded style, i.e. resolves the cascade by ordering after specifity.
        /// Two rules with the same specifity are ordered according to their appearance. The more
        /// recent declaration wins. Inheritance is not taken into account.
        /// </summary>
        /// <param name="styleCollection">The style rules to apply.</param>
        /// <param name="element">The element to compute the cascade for.</param>
        /// <returns>Returns the cascaded read-only style declaration.</returns>
        public static CssStyleDeclaration ComputeCascadedStyle(this StyleCollection styleCollection, IElement element)
        {
            var style = new CssStyleDeclaration();
            var rules = styleCollection.SortBySpecifity(element);

            foreach (var rule in rules)
            {
                style.SetDeclarations(rule.Style);
            }

            return(new CssStyleDeclaration(style.Declarations));
        }
예제 #2
0
        /// <summary>
        /// Computes the cascaded style, i.e. resolves the cascade by ordering after specifity.
        /// Two rules with the same specifity are ordered according to their appearance. The more
        /// recent declaration wins. Inheritance is not taken into account.
        /// </summary>
        /// <param name="styleCollection">The style rules to apply.</param>
        /// <param name="element">The element to compute the cascade for.</param>
        /// <returns>Returns the cascaded read-only style declaration.</returns>
        public static CssStyleDeclaration ComputeCascadedStyle(this StyleCollection styleCollection, IElement element)
        {
            var computedStyle = new CssStyleDeclaration();
            var rules         = styleCollection.SortBySpecifity(element);

            foreach (var rule in rules)
            {
                var inlineStyle = rule.Style;
                computedStyle.SetDeclarations(inlineStyle.Declarations);
            }

            if (element is IHtmlElement)
            {
                var htmlElement = (IHtmlElement)element;
                if (htmlElement.Style != null)
                {
                    var declarations = htmlElement.Style.OfType <CssProperty>();
                    computedStyle.SetDeclarations(declarations);
                }
            }

            return(computedStyle);
        }