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());
            }
        }
        private void ApplyToChildren(HtmlNode node, List<HtmlStyle> htmlStyles)
        {
            if (IsValidNode(node))
            {
                ApplyStyle(node, htmlStyles);

                foreach (HtmlNode child in node.GetChildren())
                {
                    ApplyToChildren(child, htmlStyles);
                }
            }
        }
        private void ApplyStyle(CSSelector nextSelector, Specificity specificity, HtmlNode node, List<HtmlStyle> htmlStyles)
		{
			if (nextSelector.IsValidNode(node))
			{
                nextSelector.AddSpecificity(specificity);
				nextSelector.Parse(node, htmlStyles);
			}

			foreach (HtmlNode child in node.GetChildren())
			{
                ApplyStyle(nextSelector.Clone(), specificity, child, htmlStyles);
			}
		}
        internal override void Parse(HtmlNode node, Specificity specificity, List<HtmlStyle> htmlStyles)
		{
			CSSelector nextSelector;
			
			if (context.ParseSelector(this.selectorText, out nextSelector))
			{
				if (nextSelector != null)
				{
					foreach (HtmlNode child in node.GetChildren())
					{
                        CSSelector clone = nextSelector.Clone();
                        ApplyStyle(clone, specificity, child, htmlStyles);
					}
				}
			}
		}
        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 TraverseHtmlNodes(HtmlNode node, StyleSheet styleSheet)
        {
            string style = string.Empty;

            if (string.Compare(node.Tag, HtmlTag.STYLE, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                style = node.InnerHtml == null ? string.Empty : node.InnerHtml.Trim();
            }
            else if (string.Compare(node.Tag, HtmlTag.LINK, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                string relValue = node.ExtractAttributeValue("rel");
                string media = node.ExtractAttributeValue("media");

                if (string.Compare(rel, relValue, StringComparison.InvariantCultureIgnoreCase) == 0 &&
                    (string.IsNullOrEmpty(media) || media.CompareInvariantCultureIgnoreCase("screen")
                    || media.CompareInvariantCultureIgnoreCase("all")))
                {
                    string url = node.ExtractAttributeValue("href");

                    if (!string.IsNullOrEmpty(url))
                    {
                        WebManager web = new WebManager(uriSchema, baseUrl);
                        style = web.ExtractStylesFromLink(url);
                    }
                }
            }

            if (!string.IsNullOrEmpty(style))
            {
                List<CSSElement> styles = new List<CSSElement>();
                List<MediaQuery> mediaQueries = new List<MediaQuery>();

                CSSParser parser = new CSSParser();
                parser.ParseCSS(style, styles, mediaQueries);

                styleSheet.AddRange(styles);
                styleSheet.AddMediaQueryRange(mediaQueries);
            }

            foreach (HtmlNode n in node.GetChildren())
            {
                TraverseHtmlNodes(n, styleSheet);
            }
        }
        internal override void Parse(HtmlNode node, Specificity specificity, List<HtmlStyle> htmlStyles)
        {
            if (node.HasChildren)
            {
                CSSelector nextSelector;
			
				if (context.ParseSelector(this.selectorText, out nextSelector))
				{
					if (nextSelector != null)
					{
						foreach (HtmlNode child in node.GetChildren())
						{
							if (nextSelector.IsValidNode(child))
							{
                                nextSelector.AddSpecificity(specificity);
								nextSelector.Parse(child, htmlStyles);
							}
						}
					}
				}
            }
        }
        private void ApplyToChild(HtmlNode node, List<HtmlStyle> htmlStyles)
        {
            if (node == null)
            {
                return;
            }

            if (!node.HasChildren)
            {
                return;
            }

            if (node.GetChildren().Count < this.position)
            {
                return;
            }

            HtmlNode pNode = GetNodeAtPosition(position, node);

            if (pNode != null)
            {
                ApplyStyle(pNode, htmlStyles);
            }
        }
        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);
            }
        }
Esempio n. 10
0
 void IAttachedSelector.Parse(HtmlNode node, List<HtmlStyle> htmlStyles)
 {
     if (string.IsNullOrEmpty(this.selectorText))
     {
         foreach (HtmlNode child in node.GetChildren())
         {
             ApplyToChildren(child, htmlStyles);
         }
     }
     else
     {
         context.ParseBehavior(this.selectorText, CalculateSpecificity(SelectorType.PseudoClass), node, htmlStyles);
     }
 }
Esempio n. 11
0
        bool IAttachedSelector.IsValidNode(HtmlNode node)
        {
            if (node == null)
            {
                return false;
            }

            return node.GetChildren().Count > 0;
        }