예제 #1
0
        /// <summary>
        /// Specific version optimized for a read-only Html document
        /// </summary>
        public ICssStyleDeclaration GetComputedStyleInReadOnlyDocument(IElement element, String pseudo = null)
        {
            if (styleRulesCache == null)
            {
                styleRulesCache = this.GetStyleCollection();
                styleRulesCache.FreezeForReuse();
            }

            var pseudoElement = PseudoElement.Create(element, pseudo);

            if (pseudoElement != null)
            {
                element = pseudoElement;
            }

            var computedStyle = new CssStyleDeclaration();

            var elementStyle = this.ComputeCascadedStyleInReadOnlyDocument(styleRulesCache, element);

            computedStyle.SetDeclarations(elementStyle.Declarations);

            var ancestorElements = element.GetAncestors().OfType <IElement>();

            foreach (var ancestorElement in ancestorElements)
            {
                var ancestorStyle = ComputeCascadedStyleInReadOnlyDocument(styleRulesCache, ancestorElement);
                computedStyle.UpdateDeclarations(ancestorStyle.Declarations);
            }

            return(computedStyle);
        }
예제 #2
0
 /// <summary>
 /// Creates a pseudo element for the current element.
 /// </summary>
 /// <param name="pseudoElement">
 /// The element to create (e.g. ::after).
 /// </param>
 /// <returns>The created element or null, if not possible.</returns>
 public IPseudoElement Pseudo(String pseudoElement)
 {
     return(PseudoElement.Create(this, pseudoElement));
 }