internal bool StyleContains(HtmlStyle parentStyle, HtmlStyle childStyle)
        {
            foreach (string[] array in tags)
            {
                if (HtmlStringComparer.Contains(array, parentStyle.Name) && HtmlStringComparer.Contains(array, childStyle.Name))
                {
                    return true;
                }
            }

            return false;
        }
        internal bool InheritStyle(HtmlStyle parentStyle, HtmlNode child)
        {
            foreach (CSSProperty property in properties)
            {
                if (property.AppendStyle(parentStyle, child))
                {
                    return true;
                }
            }

            return false;
        }
        internal override bool AppendStyle(HtmlStyle parentStyle, HtmlNode child)
        {
            if (parentStyle == null || child == null)
            {
                return false;
            }

            if (parentStyle.Name.CompareInvariantCultureIgnoreCase(backgroundColor) ||
                parentStyle.Name.CompareInvariantCultureIgnoreCase(background))
            {
                HtmlStyle style;

                if (!child.HasStyle(backgroundColor) && !child.HasStyle(background))
                {
                    //child.HtmlStyles.Add(new HtmlStyle(parentStyle.Name, parentStyle.Value, false));
                    child.UpdateInheritedStyles(parentStyle);
                }
                else if ((child.TryGetStyle(background, out style) || child.TryGetStyle(backgroundColor, out style)) &&
                    style.Value.CompareInvariantCultureIgnoreCase(transparent))
                {
                    string styleValue = parentStyle.Value;
                    
                    if (parentStyle.Name.CompareInvariantCultureIgnoreCase(background) &&
                        style.Name.CompareInvariantCultureIgnoreCase(backgroundColor))
                    {
                        int index = styleValue.IndexOf(' ');

                        if (index != -1)
                        {
                            styleValue = styleValue.Remove(index);
                        }
                    }
                    
                    style.ModifyStyle(styleValue);
                }

                return true;
            }

            return false;
        }
        internal void OverWrite(HtmlStyle htmlStyle)
        {
            CSSPropertyParser propertyParser = new CSSPropertyParser();

            //if (string.Compare(name, htmlStyle.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
            if (propertyParser.StyleContains(this, htmlStyle))
            {
                if (!important && htmlStyle.Important)
                {
                    name = htmlStyle.Name;
                    value = htmlStyle.Value;
                    important = htmlStyle.Important;
                    specificity = htmlStyle.Specificity;
                }
                else if (htmlStyle.Specificity >= specificity && (!important || (important && htmlStyle.Important)))
                {
                    name = htmlStyle.Name;
                    value = htmlStyle.Value;
                }
            }
        }
        internal void UpdateInheritedStyles(HtmlStyle style)
        {
            CSSPropertyParser propertyParser = new CSSPropertyParser();

            foreach (HtmlStyle inheritedStyle in inheritedHtmlStyles)
            {
                if (propertyParser.StyleContains(style, inheritedStyle))
                {
                    inheritedStyle.ModifyStyle(style.Value);
                    return;
                }
            }

            //If style found in the inheritedStyles, control will return without hit this statment.
            inheritedHtmlStyles.Add(style.Clone());
        }
        internal bool TryGetInheritedStyle(string styleName, out HtmlStyle htmlStyle)
        {
            htmlStyle = null;

            if (inheritedHtmlStyles == null || inheritedHtmlStyles.Count == 0)
            {
                return false;
            }

            foreach (HtmlStyle style in inheritedHtmlStyles)
            {
                if (string.Compare(styleName, style.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    htmlStyle = style;
                    return true;
                }
            }

            return false;
        }
        internal bool TryGetStyle(string styleName, out HtmlStyle htmlStyle)
        {
            htmlStyle = null;

            foreach (HtmlStyle style in htmlStyles)
            {
                if (string.Compare(styleName, style.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    htmlStyle = style;
                    return true;
                }
            }

            return false;
        }
        internal override bool AppendStyle(HtmlStyle parentStyle, HtmlNode child)
        {
            if (parentStyle == null || child == null)
            {
                return false;
            }

            if (parentStyle.Name.CompareInvariantCultureIgnoreCase(fontFamily))
            {
                ProcessFontFamily(parentStyle, child);
                return true;
            }
            else if (parentStyle.Name.CompareInvariantCultureIgnoreCase(font))
            {
                ProcessFont(parentStyle, child);
                return true;
            }

            return false;
        }
 private void ProcessFontFamily(HtmlStyle parentStyle, HtmlNode child)
 {
     if (!child.HasStyle(fontFamily) && !child.HasStyle(font))
     {
         child.UpdateInheritedStyles(parentStyle);
     }
 }
        private void ProcessFont(HtmlStyle parentStyle, HtmlNode child)
        {
            Dictionary<string, string> parentStyles = new Dictionary<string, string>();
            KeyValuePair<Stack<string>, Stack<string>> styleStack =
                new KeyValuePair<Stack<string>, Stack<string>>(new Stack<string>(), new Stack<string>());

            if (ProcessFontStyle(parentStyle.Value, parentStyles, styleStack) && parentStyles.Count > 0)
            {
                foreach (var style in parentStyles)
                {
                    if (!child.HasStyle(style.Key))
                    {
                        child.UpdateInheritedStyles(new HtmlStyle(style.Key, style.Value, false));
                    }
                }
            }
        }
 internal abstract bool AppendStyle(HtmlStyle parentStyle, HtmlNode child);