Ejemplo n.º 1
0
        /// <summary>
        /// Computes the declarations for the given element in the specified window.
        /// </summary>
        /// <param name="window">The context of the element.</param>
        /// <param name="element">The element that is questioned.</param>
        /// <returns>The style declaration containing all the declarations.</returns>
        public static CSSStyleDeclaration ComputeDeclarations(this IWindow window, IElement element)
        {
            var bag = new CssPropertyBag();

            foreach (var stylesheet in window.Document.StyleSheets)
            {
                var sheet = stylesheet as CSSStyleSheet;

                if (sheet != null && !stylesheet.IsDisabled && stylesheet.Media.Validate(window))
                {
                    var rules = (CSSRuleList)sheet.Rules;
                    rules.ComputeStyle(bag, window, element);
                }
            }

            var htmlElement = element as HTMLElement;

            if (htmlElement != null)
            {
                bag.ExtendWith(htmlElement.Style, Priority.Inline);
            }

            bag.InheritFrom(element, window);
            return(new CSSStyleDeclaration(bag));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Extends the given bag with the set properties of the specified
 /// styling declaration.
 /// </summary>
 /// <param name="bag">The bag to modify.</param>
 /// <param name="styling">The styling properties to use.</param>
 /// <param name="priority">Sets the priority of the new properties.</param>
 public static void ExtendWith(this CssPropertyBag bag, CSSStyleDeclaration styling, Priority priority)
 {
     foreach (var property in styling.Declarations)
     {
         bag.TryUpdate(property, priority);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Inherits the unspecified properties from the element's parents.
        /// </summary>
        /// <param name="bag">The bag to modify.</param>
        /// <param name="element">The element that has unresolved properties.</param>
        /// <param name="window">The associated window object.</param>
        public static void InheritFrom(this CssPropertyBag bag, IElement element, IWindow window)
        {
            var parent = element.ParentElement;

            if (parent != null)
            {
                var styling = window.ComputeDeclarations(parent);

                foreach (var property in styling.Declarations)
                {
                    var styleProperty = bag[property.Name];

                    if (styleProperty == null || styleProperty.IsInherited)
                    {
                        bag.TryUpdate(property);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 internal override void ComputeStyle(CssPropertyBag style, IWindow window, IElement element)
 {
     foreach (var rule in _rules.List)
         rule.ComputeStyle(style, window, element);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Computes the style for the given element within the specified window
 /// context. Writes the properties into the specified style declaration.
 /// </summary>
 /// <param name="style">The declaration that is used.</param>
 /// <param name="window">The given window context.</param>
 /// <param name="element">The element that is computed.</param>
 internal virtual void ComputeStyle(CssPropertyBag style, IWindow window, IElement element)
 {
     //By default nothing gets computed.
 }