Beispiel #1
0
        private bool CheckSimpleSelector(string selector, out StyleSelectorPart[] parts)
        {
            bool result;

            if (!CSSSpec.ParseSelector(selector, out parts))
            {
                this.m_Errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedSelectorFormat, selector);
                result = false;
            }
            else if (parts.Any((StyleSelectorPart p) => p.type == StyleSelectorType.Unknown))
            {
                this.m_Errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedSelectorFormat, selector);
                result = false;
            }
            else if (parts.Any((StyleSelectorPart p) => p.type == StyleSelectorType.RecursivePseudoClass))
            {
                this.m_Errors.AddSemanticError(StyleSheetImportErrorCode.RecursiveSelectorDetected, selector);
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
Beispiel #2
0
        public static int GetSelectorSpecificity(string selector)
        {
            int result = 0;

            StyleSelectorPart[] parts;
            if (CSSSpec.ParseSelector(selector, out parts))
            {
                result = CSSSpec.GetSelectorSpecificity(parts);
            }
            return(result);
        }
        void VisitComplexSelector(ComplexSelector complexSelector)
        {
            int fullSpecificity = CSSSpec.GetSelectorSpecificity(complexSelector.ToString());

            if (fullSpecificity == 0)
            {
                m_Errors.AddInternalError("Failed to calculate selector specificity " + complexSelector);
                return;
            }

            using (m_Builder.BeginComplexSelector(fullSpecificity))
            {
                StyleSelectorRelationship relationShip = StyleSelectorRelationship.None;

                foreach (CombinatorSelector selector in complexSelector)
                {
                    StyleSelectorPart[] parts;

                    string simpleSelector = ExtractSimpleSelector(selector.Selector);

                    if (string.IsNullOrEmpty(simpleSelector))
                    {
                        m_Errors.AddInternalError("Expected simple selector inside complex selector " + simpleSelector);
                        return;
                    }

                    if (CheckSimpleSelector(simpleSelector, out parts))
                    {
                        m_Builder.AddSimpleSelector(parts, relationShip);

                        // Read relation for next element
                        switch (selector.Delimiter)
                        {
                        case Combinator.Child:
                            relationShip = StyleSelectorRelationship.Child;
                            break;

                        case Combinator.Descendent:
                            relationShip = StyleSelectorRelationship.Descendent;
                            break;

                        default:
                            m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidComplexSelectorDelimiter, complexSelector.ToString());
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
Beispiel #4
0
        public static StyleComplexSelector CreateSimpleSelector(string styleName)
        {
            var cs = new StyleComplexSelector();

            StyleSelectorPart[] parts;
            CSSSpec.ParseSelector(styleName, out parts);
            var selector = new StyleSelector();

            selector.parts = parts;
            cs.selectors   = new[] { selector };
            return(cs);
        }
Beispiel #5
0
        private void VisitComplexSelector(ComplexSelector complexSelector)
        {
            int selectorSpecificity = CSSSpec.GetSelectorSpecificity(complexSelector.ToString());

            if (selectorSpecificity == 0)
            {
                this.m_Errors.AddInternalError("Failed to calculate selector specificity " + complexSelector);
            }
            else
            {
                using (this.m_Builder.BeginComplexSelector(selectorSpecificity))
                {
                    StyleSelectorRelationship previousRelationsip = StyleSelectorRelationship.None;
                    foreach (CombinatorSelector current in complexSelector)
                    {
                        string text = this.ExtractSimpleSelector(current.Selector);
                        if (string.IsNullOrEmpty(text))
                        {
                            this.m_Errors.AddInternalError("Expected simple selector inside complex selector " + text);
                            break;
                        }
                        StyleSelectorPart[] parts;
                        if (!this.CheckSimpleSelector(text, out parts))
                        {
                            break;
                        }
                        this.m_Builder.AddSimpleSelector(parts, previousRelationsip);
                        Combinator delimiter = current.Delimiter;
                        if (delimiter != Combinator.Child)
                        {
                            if (delimiter != Combinator.Descendent)
                            {
                                this.m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidComplexSelectorDelimiter, complexSelector.ToString());
                                break;
                            }
                            previousRelationsip = StyleSelectorRelationship.Descendent;
                        }
                        else
                        {
                            previousRelationsip = StyleSelectorRelationship.Child;
                        }
                    }
                }
            }
        }
 bool CheckSimpleSelector(string selector, out StyleSelectorPart[] parts)
 {
     if (!CSSSpec.ParseSelector(selector, out parts))
     {
         m_Errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedSelectorFormat, selector);
         return(false);
     }
     if (parts.Any(p => p.type == StyleSelectorType.Unknown))
     {
         m_Errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedSelectorFormat, selector);
         return(false);
     }
     if (parts.Any(p => p.type == StyleSelectorType.RecursivePseudoClass))
     {
         m_Errors.AddSemanticError(StyleSheetImportErrorCode.RecursiveSelectorDetected, selector);
         return(false);
     }
     return(true);
 }
        void VisitSimpleSelector(string selector)
        {
            StyleSelectorPart[] parts;
            if (CheckSimpleSelector(selector, out parts))
            {
                int specificity = CSSSpec.GetSelectorSpecificity(parts);

                if (specificity == 0)
                {
                    m_Errors.AddInternalError("Failed to calculate selector specificity " + selector);
                    return;
                }

                using (m_Builder.BeginComplexSelector(specificity))
                {
                    m_Builder.AddSimpleSelector(parts, StyleSelectorRelationship.None);
                }
            }
        }