Ejemplo n.º 1
0
        public static void FindMatches(StyleMatchingContext context, List <SelectorMatchRecord> matchedSelectors)
        {
            Debug.Assert(matchedSelectors.Count == 0);

            Debug.Assert(context.currentElement != null, "context.currentElement != null");

            VisualElement element = context.currentElement;

            for (int i = 0; i < context.styleSheetStack.Count; i++)
            {
                StyleSheet          styleSheet = context.styleSheetStack[i];
                SelectorMatchRecord record     = new SelectorMatchRecord(styleSheet, i);

                FastLookup(styleSheet.orderedTypeSelectors, matchedSelectors, context, element.typeName, ref record);
                FastLookup(styleSheet.orderedTypeSelectors, matchedSelectors, context, "*", ref record);

                if (!string.IsNullOrEmpty(element.name))
                {
                    FastLookup(styleSheet.orderedNameSelectors, matchedSelectors, context, element.name, ref record);
                }

                foreach (string @class in element.classList)
                {
                    FastLookup(styleSheet.orderedClassSelectors, matchedSelectors, context, @class, ref record);
                }
            }
        }
Ejemplo n.º 2
0
        public static int Compare(SelectorMatchRecord a, SelectorMatchRecord b)
        {
            int res = a.styleSheetIndexInStack.CompareTo(b.styleSheetIndexInStack);

            if (res == 0)
            {
                res = a.complexSelector.orderInStyleSheet.CompareTo(b.complexSelector.orderInStyleSheet);
            }

            return(res);
        }
Ejemplo n.º 3
0
        static void FastLookup(IDictionary <string, StyleComplexSelector> table, List <SelectorMatchRecord> matchedSelectors, StyleMatchingContext context, string input, ref SelectorMatchRecord record)
        {
            StyleComplexSelector currentComplexSelector;

            if (table.TryGetValue(input, out currentComplexSelector))
            {
                while (currentComplexSelector != null)
                {
                    if (MatchRightToLeft(context.currentElement, currentComplexSelector, context.processResult))
                    {
                        record.complexSelector = currentComplexSelector;
                        matchedSelectors.Add(record);
                    }
                    currentComplexSelector = currentComplexSelector.nextInTable;
                }
            }
        }