private LastChildSelector(ISelectorContext context, string selectorText, Specificity specificity)
 {
     this.context = context;
     regex = new Regex("^(:last-child)|(:last-of-type)");
     this.selectorText = selectorText;
     this.specificity = specificity;
 }
Ejemplo n.º 2
0
        public static Specificity operator +(Specificity specificity, SelectorType type)
        {
            Specificity newSpecificity = new Specificity(specificity.inline, specificity.id, specificity.classes, specificity.elements);
            newSpecificity.SetSpecificity(type);

            return newSpecificity;
        }
 private FirstChildSelector(ISelectorContext context, string selectorText, Specificity specificity)
 {
     this.context = context;
     regex = new Regex("^:first-child");
     this.selectorText = selectorText;
     this.specificity = specificity;
 }
        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);
						}
					}
                }
            }
        }
 private AttributeSelector(ISelectorContext context, AttributeElements element, Specificity specificity)
 {
     this.context = context;
     this.element = element;
     this.specificity = specificity;
     isValid = new Regex("^\\[([a-zA-Z]+[0-9]*)+([~|^$*]?=+[\"']?([a-zA-Z]+[0-9]*)+[\"']?)*\\]");
     spliter = new Regex(@"\w+|[~|^$*]|=");
 }
 private NthChildSelector(ISelectorContext context, string selectorText, int position, Specificity specificity)
 {
     this.context = context;
     regex = new Regex("^:nth-child\\(\\d+\\)");
     this.selectorText = selectorText;
     this.position = position;
     this.specificity = specificity;
 }
 private IdentitySelector(ISelectorContext context, string currentSelector, string selectorText, Specificity specificity)
 {
     this.context = context;
     regex = new Regex("^#[-_]*([a-zA-Z]+[0-9_-]*)+");
     this.currentSelector = currentSelector;
     this.selectorText = selectorText;
     this.specificity = specificity;
 }
Ejemplo n.º 8
0
 private NotSelector(ISelectorContext context, string selectorText, string currentSelector, Specificity specificity)
 {
     this.context = context;
     regex = new Regex("^:not\\([a-zA-Z]+[0-9]*\\)");
     elementName = new Regex("\\([a-zA-Z]+[0-9]*\\)");
     this.selectorText = selectorText;
     this.currentSelector = currentSelector;
     this.specificity = specificity;
 }
        internal override void Parse(HtmlNode node, Specificity specificity, List<HtmlStyle> htmlStyles)
        {
            CSSelector nextSelector;
			
			if (context.ParseSelector(this.selectorText, out nextSelector))
			{
				if (nextSelector != null)
				{
                    ApplyStyle(nextSelector, specificity, node, 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);
			}
		}
        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);
            }
        }
        private ElementSelector(ISelectorContext context, string currentSelector, string selectorText, Specificity specificity)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.context = context;
            regex = new Regex(@"^([a-zA-Z]+[0-9]*)+");
            this.currentSelector = currentSelector;
            this.selectorText = selectorText;
            this.specificity = specificity;

            FillSpecialTags();
        }
        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 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);
							}
						}
					}
				}
            }
        }
Ejemplo n.º 15
0
 protected Specificity CalculateSpecificity(SelectorType type)
 {
     return this.specificity += type;
 }
Ejemplo n.º 16
0
        internal void CopyHtmlStyles(List<HtmlStyle> newStyles, Specificity specificity)
        {
            CSSPropertyParser propertyParser = new CSSPropertyParser();

            foreach (HtmlStyle newStyle in newStyles)
            {
                bool found = false;

                newStyle.Specificity = specificity;

                foreach (HtmlStyle style in htmlStyles)
                {
                    if (propertyParser.StyleContains(newStyle, style))
                    {
                        found = true;
                        style.OverWrite(newStyle);
                    }
                }

                if (!found)
                {
                    htmlStyles.Add(newStyle.Clone());
                }
            }
        }
Ejemplo n.º 17
0
        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;
                }
            }
        }
Ejemplo n.º 18
0
 internal HtmlStyle(string name, string value, bool important, Specificity specificity)
     : this(name, value, important)
 {
     this.specificity = specificity;
 }
Ejemplo n.º 19
0
 private GlobalSelector(ISelectorContext context, string selectorText, Specificity specificity)
 {
     this.context = context;
     this.selectorText = selectorText;
     this.specificity = specificity;
 }
Ejemplo n.º 20
0
 //This is method is public because it can serve as the IAttachedSelector.AddSpecificity
 public void AddSpecificity(Specificity specificity)
 {
     this.specificity = specificity;
 }
        public bool ParseBehavior(string selectorText, Specificity specificity, HtmlNode node, List<HtmlStyle> htmlStyles)
        {
            bool foundBehavior = false;

            foreach (CSSBehavior behavior in CSSBehaviors)
            {
                if (behavior.IsValidBehavior(selectorText))
                {
                    foundBehavior = true;

                    behavior.Parse(node, specificity, htmlStyles);

                    break;
                }
            }

            return foundBehavior;
        }
        public bool ParseSelectorOrBehavior(string selectorText, Specificity specificity, HtmlNode node, List<HtmlStyle> htmlStyles)
        {
            bool found = false;

            foreach (IAttachedSelector selector in attachedSelectors)
            {
                if (selector.Prepare(selectorText))
                {
                    if (selector.IsValidNode(node))
                    {
                        found = true;
                        selector.AddSpecificity(specificity);
                        selector.Parse(node, htmlStyles);
                    }

                    break;
                }
            }

            if (!found)
            {
                found = ParseBehavior(selectorText, specificity, node, htmlStyles);
            }

            return found;
        }
Ejemplo n.º 23
0
 internal abstract void Parse(HtmlNode node, Specificity specificity, List<HtmlStyle> htmlStyles);