コード例 #1
0
        public static int Compare(SelectorMatchRecord a, SelectorMatchRecord b)
        {
            if (a.sheet.isUnityStyleSheet != b.sheet.isUnityStyleSheet)
            {
                return(a.sheet.isUnityStyleSheet ? -1 : 1);
            }

            int res = 0;

            // Unity style sheet are sorted by specificity because they are applied with a negative specificity
            if (a.sheet.isUnityStyleSheet)
            {
                res = a.complexSelector.specificity.CompareTo(b.complexSelector.specificity);
            }

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

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

            return(res);
        }
コード例 #2
0
        public static int Compare(SelectorMatchRecord a, SelectorMatchRecord b)
        {
            bool flag = a.sheet.isUnityStyleSheet != b.sheet.isUnityStyleSheet;
            int  result;

            if (flag)
            {
                result = (a.sheet.isUnityStyleSheet ? -1 : 1);
            }
            else
            {
                int  num   = a.complexSelector.specificity.CompareTo(b.complexSelector.specificity);
                bool flag2 = num == 0;
                if (flag2)
                {
                    num = a.styleSheetIndexInStack.CompareTo(b.styleSheetIndexInStack);
                }
                bool flag3 = num == 0;
                if (flag3)
                {
                    num = a.complexSelector.orderInStyleSheet.CompareTo(b.complexSelector.orderInStyleSheet);
                }
                result = num;
            }
            return(result);
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
0
        public static void FindMatches(StyleMatchingContext context, List <SelectorMatchRecord> matchedSelectors, int parentSheetIndex)
        {
            Debug.Assert(matchedSelectors.Count == 0);

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

            var toggleRoot           = false;
            var processedStyleSheets = HashSetPool <StyleSheet> .Get();

            try
            {
                var element = context.currentElement;
                for (var i = context.styleSheetCount - 1; i >= 0; --i)
                {
                    var styleSheet = context.GetStyleSheetAt(i);
                    if (!processedStyleSheets.Add(styleSheet))
                    {
                        continue;
                    }

                    // If the sheet is added on the element consider it as :root
                    if (i > parentSheetIndex)
                    {
                        element.pseudoStates |= PseudoStates.Root;
                        toggleRoot            = true;
                    }
                    else
                    {
                        element.pseudoStates &= ~PseudoStates.Root;
                    }

                    var 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.GetClassesForIteration())
                    {
                        FastLookup(styleSheet.orderedClassSelectors, matchedSelectors, context, @class, ref record);
                    }
                }

                if (toggleRoot)
                {
                    element.pseudoStates &= ~PseudoStates.Root;
                }
            }
            finally
            {
                HashSetPool <StyleSheet> .Release(processedStyleSheets);
            }
        }
コード例 #5
0
        public static int Compare(SelectorMatchRecord a, SelectorMatchRecord b)
        {
            if (a.sheet.isUnityStyleSheet != b.sheet.isUnityStyleSheet)
            {
                return(a.sheet.isUnityStyleSheet ? -1 : 1);
            }

            int res = a.complexSelector.specificity.CompareTo(b.complexSelector.specificity);

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

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

            return(res);
        }
コード例 #6
0
        public static void FindMatches(StyleMatchingContext context, List <SelectorMatchRecord> matchedSelectors, int parentSheetIndex)
        {
            Debug.Assert(matchedSelectors.Count == 0);

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

            VisualElement element     = context.currentElement;
            bool          toggledRoot = false;

            for (int i = 0; i < context.styleSheetStack.Count; i++)
            {
                // If the sheet is added on the element consider it as :root
                if (!toggledRoot && i > parentSheetIndex)
                {
                    element.pseudoStates |= PseudoStates.Root;
                    toggledRoot           = true;
                }

                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.GetClassesForIteration())
                {
                    FastLookup(styleSheet.orderedClassSelectors, matchedSelectors, context, @class, ref record);
                }
            }

            if (toggledRoot)
            {
                element.pseudoStates &= ~PseudoStates.Root;
            }
        }
コード例 #7
0
        public static void FindMatches(StyleMatchingContext context, List <SelectorMatchRecord> matchedSelectors)
        {
            Debug.Assert(matchedSelectors.Count == 0);
            Debug.Assert(context.currentElement != null, "context.currentElement != null");
            VisualElement currentElement = context.currentElement;

            for (int i = 0; i < context.styleSheetStack.Count; i++)
            {
                StyleSheet          styleSheet          = context.styleSheetStack[i];
                SelectorMatchRecord selectorMatchRecord = new SelectorMatchRecord(styleSheet, i);
                StyleSelectorHelper.FastLookup(styleSheet.orderedTypeSelectors, matchedSelectors, context, currentElement.typeName, ref selectorMatchRecord);
                StyleSelectorHelper.FastLookup(styleSheet.orderedTypeSelectors, matchedSelectors, context, "*", ref selectorMatchRecord);
                bool flag = !string.IsNullOrEmpty(currentElement.name);
                if (flag)
                {
                    StyleSelectorHelper.FastLookup(styleSheet.orderedNameSelectors, matchedSelectors, context, currentElement.name, ref selectorMatchRecord);
                }
                foreach (string current in currentElement.GetClassesForIteration())
                {
                    StyleSelectorHelper.FastLookup(styleSheet.orderedClassSelectors, matchedSelectors, context, current, ref selectorMatchRecord);
                }
            }
        }
コード例 #8
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;
                }
            }
        }
コード例 #9
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)
                {
                    bool isCandidate        = true;
                    bool isMatchRightToLeft = false;

                    if (!currentComplexSelector.isSimple)
                    {
                        isCandidate = context.ancestorFilter.IsCandidate(currentComplexSelector);
                    }

                    if (isCandidate || s_VerifyBloomIntegrity)
                    {
                        isMatchRightToLeft = MatchRightToLeft(context.currentElement, currentComplexSelector, context.processResult);
                    }

                    // This verifies that the Bloom filter never rejects a valid complex selector.
                    if (s_VerifyBloomIntegrity)
                    {
                        Assert.IsTrue(isCandidate || !isMatchRightToLeft, "The Bloom filter returned a false negative match.");
                    }

                    if (isMatchRightToLeft)
                    {
                        record.complexSelector = currentComplexSelector;
                        matchedSelectors.Add(record);
                    }

                    currentComplexSelector = currentComplexSelector.nextInTable;
                }
            }
        }
コード例 #10
0
        private static void FastLookup(IDictionary <string, StyleComplexSelector> table, List <SelectorMatchRecord> matchedSelectors, StyleMatchingContext context, string input, ref SelectorMatchRecord record)
        {
            StyleComplexSelector nextInTable;
            bool flag = table.TryGetValue(input, out nextInTable);

            if (flag)
            {
                while (nextInTable != null)
                {
                    bool flag2 = StyleSelectorHelper.MatchRightToLeft(context.currentElement, nextInTable, context.processResult);
                    if (flag2)
                    {
                        record.complexSelector = nextInTable;
                        matchedSelectors.Add(record);
                    }
                    nextInTable = nextInTable.nextInTable;
                }
            }
        }