private void ApplyStyle(CSSelector nextSelector, Specificity specificity, HtmlNode node, List<HtmlStyle> htmlStyles)
        {
            if (node.Next != null)
            {
            	if (nextSelector.IsValidNode(node.GetNext()))
                {
                    nextSelector.AddSpecificity(specificity);
            		nextSelector.Parse(node.GetNext(), htmlStyles);
                }

                ApplyStyle(nextSelector, specificity, node.GetNext(), htmlStyles);
            }
        }
        internal override void Parse(HtmlNode node, Specificity specificity, List<HtmlStyle> htmlStyles)
        {
            if (node.Next != null)
            {
            	HtmlNode temp = node.GetNext();

                //Empty text nodes can be avoid. This loop will skip those.
                while (temp != null && temp.Tag == HtmlTag.TEXT)
                {
                	temp = temp.GetNext();
                }

                if (temp != null)
                {
                    CSSelector nextSelector;
			
					if (context.ParseSelector(this.selectorText, out nextSelector))
					{
						if (nextSelector != null && nextSelector.IsValidNode(temp))
						{
                            nextSelector.AddSpecificity(specificity);
							nextSelector.Parse(temp, htmlStyles);
						}
					}
                }
            }
        }
Пример #3
0
        private void InterpretStyles(HtmlNode htmlNode)
        {
            string style;

            if (!HtmlStyle.IsNonStyleElement(htmlNode.Tag))
            {
                if (htmlNode.Attributes.TryGetValue("style", out style))
                {
                    CSSParser cssParser = new CSSParser();
                    htmlNode.AddStyles(cssParser.ParseRules(style, SelectorType.Inline));
                }

                Parse(htmlNode);
            }

            foreach (HtmlNode node in htmlNode.GetChildren())
            {
                InterpretStyles(node);
            }

            //This loop only needs when the parent is null. If parent is not null, it will loop through all the 
            //child elements thus next nodes processed without this loop.
            if (htmlNode.Parent == null && htmlNode.Next != null)
            {
                InterpretStyles(htmlNode.GetNext());
            }
        }
        internal void ParseStyle(HtmlNode node)
        {
            foreach (CSSProperty property in properties)
            {
                property.ParseStyle(node);
            }

            foreach (HtmlNode child in node.GetChildren())
            {
                ParseStyle(child);
            }

            if (node.Parent == null && node.Next != null)
            {
                ParseStyle(node.GetNext());
            }
        }
        private void ApplyToChildren(HtmlNode node, HtmlNode parent)
        {
            if (node == null)
            {
                return;
            }

            if (parent != null)
            {
                node.ImportInheritedStyles(parent.InheritedHtmlStyles);

                AppendStyles(node, parent);

                UpdateCurrentNodeInheritedStyles(node);

                InheritFromParent(node, parent);
            }

            foreach (HtmlNode child in node.GetChildren())
            {
                ApplyToChildren(child, node);
            }

            if (node.Parent == null && node.Next != null)
            {
                ApplyToChildren(node.GetNext(), parent);
            }
        }
Пример #6
0
        internal StyleSheet TrackCSS(HtmlNode node)
        {
            StyleSheet styleSheet = new StyleSheet(new SelectorContext());

            TraverseHtmlNodes(node, styleSheet);

            HtmlNode nextNode = node.GetNext();

            while (nextNode != null)
            {
                TraverseHtmlNodes(nextNode, styleSheet);
                nextNode = nextNode.GetNext();
            }

            return styleSheet;
        }