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; } } } }
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); } } }