primitive selector expression
Inheritance: CssElementSelector
Beispiel #1
0
        public void AddSelector(CssSimpleElementSelector primExpr)
        {
#if DEBUG
            if (primExpr == null)
            {
            }
#endif
            if (_elementSelector == null)
            {
                _elementSelector = primExpr;
            }
            else
            {
                CssCompundElementSelector combinatorExpr = _elementSelector as CssCompundElementSelector;
                if (combinatorExpr != null)
                {
                    combinatorExpr.RightSelector = primExpr;
                }
                else
                {
                    CssSimpleElementSelector currentPrimExpr = _elementSelector as CssSimpleElementSelector;
                    if (currentPrimExpr != null)
                    {
                        combinatorExpr = new CssCompundElementSelector(CssCombinatorOperator.Descendant);
                        combinatorExpr.LeftSelector  = _elementSelector;
                        combinatorExpr.RightSelector = primExpr;
                        _elementSelector             = combinatorExpr;
                    }
                    else
                    {
                    }
                }
            }
        }
        public static bool IsCompatible(CssSimpleElementSelector sel1, CssSimpleElementSelector sel2)
        {
            //walk top of both

            var parOrSelf1 = GetTopParentOrSelf(sel1);
            var parOrSelf2 = GetTopParentOrSelf(sel2);

            return(parOrSelf1.IsSameNameAndType(parOrSelf2));
        }
        static CssElementSelector GetTopParentOrSelf(CssSimpleElementSelector selector)
        {
            var parent = selector.Parent;

            if (parent == null)
            {
                return(selector);
            }
            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            return(parent);
        }
        public override bool IsSameNameAndType(CssElementSelector anotherSelector)
        {
            if (anotherSelector == null)
            {
                return(false);
            }
            if (anotherSelector == this)
            {
                return(true);
            }
            //------------------------------
            CssSimpleElementSelector another = anotherSelector as CssSimpleElementSelector;

            return(another != null && (another.Name == this.Name) &&
                   (another.selectorType == this.selectorType));
        }
 static CssElementSelector GetTopParentOrSelf(CssSimpleElementSelector selector)
 {
     var parent = selector.Parent;
     if (parent == null)
     {
         return selector;
     }
     while (parent.Parent != null)
     {
         parent = parent.Parent;
     }
     return parent;
 }
        public static bool IsCompatible(CssSimpleElementSelector sel1, CssSimpleElementSelector sel2)
        {
            //walk top of both

            var parOrSelf1 = GetTopParentOrSelf(sel1);
            var parOrSelf2 = GetTopParentOrSelf(sel2);
            return parOrSelf1.IsSameNameAndType(parOrSelf2);

        }
Beispiel #7
0
        public void AddSelector(CssSimpleElementSelector primExpr)
        {
#if DEBUG
            if (primExpr == null)
            {

            }
#endif
            if (elementSelector == null)
            {
                elementSelector = primExpr;
            }
            else
            {
                CssCompundElementSelector combinatorExpr = this.elementSelector as CssCompundElementSelector;
                if (combinatorExpr != null)
                {
                    combinatorExpr.RightSelector = primExpr;
                }
                else
                {
                    CssSimpleElementSelector currentPrimExpr = this.elementSelector as CssSimpleElementSelector;
                    if (currentPrimExpr != null)
                    {
                        combinatorExpr = new CssCompundElementSelector(CssCombinatorOperator.Descendant);
                        combinatorExpr.LeftSelector = this.elementSelector;
                        combinatorExpr.RightSelector = primExpr;
                        this.elementSelector = combinatorExpr;
                    }
                    else
                    {
                    }
                }
            }
        }