private void GetMatchersFor(List <VisualElement> elements, int idx, int depth, List <RuleMatcher> ruleMatchers) { VisualElement element = elements[idx]; int count = this.m_Matchers.Count; for (int i = 0; i < count; i++) { RuleMatcher item = this.m_Matchers[i]; if (item.depth >= depth && StyleContext.Match(element, ref item)) { StyleSelector[] selectors = item.complexSelector.selectors; int num = item.simpleSelectorIndex + 1; int num2 = selectors.Length; if (num < num2) { RuleMatcher item2 = new RuleMatcher { complexSelector = item.complexSelector, depth = ((selectors[num].previousRelationship != StyleSelectorRelationship.Child) ? 2147483647 : (depth + 1)), simpleSelectorIndex = num, sheet = item.sheet }; this.m_Matchers.Add(item2); } else if (idx == 0) { ruleMatchers.Add(item); } } } }
private void UpdateStyles(VisualElement element, int depth) { if (element.IsDirty(ChangeType.Styles) || element.IsDirty(ChangeType.StylesPath)) { VisualContainer visualContainer = element as VisualContainer; int count = this.m_Matchers.Count; if (visualContainer != null && visualContainer.styleSheets != null) { this.AddMatchersFromSheet(visualContainer.styleSheets); } string fullTypeName = element.fullTypeName; long num = (long)fullTypeName.GetHashCode(); num = (num * 397L ^ (long)this.currentPixelsPerPoint.GetHashCode()); this.m_MatchedRules.Clear(); int count2 = this.m_Matchers.Count; for (int i = 0; i < count2; i++) { RuleMatcher ruleMatcher = this.m_Matchers[i]; if (ruleMatcher.depth >= depth && StyleContext.Match(element, ref ruleMatcher)) { StyleSelector[] selectors = ruleMatcher.complexSelector.selectors; int num2 = ruleMatcher.simpleSelectorIndex + 1; int num3 = selectors.Length; if (num2 < num3) { RuleMatcher item = new RuleMatcher { complexSelector = ruleMatcher.complexSelector, depth = ((selectors[num2].previousRelationship != StyleSelectorRelationship.Child) ? 2147483647 : (depth + 1)), simpleSelectorIndex = num2, sheet = ruleMatcher.sheet }; this.m_Matchers.Add(item); } else { StyleRule rule = ruleMatcher.complexSelector.rule; int specificity = ruleMatcher.complexSelector.specificity; num = (num * 397L ^ (long)rule.GetHashCode()); num = (num * 397L ^ (long)specificity); this.m_MatchedRules.Add(new StyleContext.RuleRef { selector = ruleMatcher.complexSelector, sheet = ruleMatcher.sheet }); } } } VisualElementStyles visualElementStyles; if (StyleContext.s_StyleCache.TryGetValue(num, out visualElementStyles)) { element.SetSharedStyles(visualElementStyles); } else { visualElementStyles = new VisualElementStyles(true); int j = 0; int count3 = this.m_MatchedRules.Count; while (j < count3) { StyleContext.RuleRef ruleRef = this.m_MatchedRules[j]; StylePropertyID[] propertyIDs = StyleSheetCache.GetPropertyIDs(ruleRef.sheet, ruleRef.selector.ruleIndex); visualElementStyles.ApplyRule(ruleRef.sheet, ruleRef.selector.specificity, ruleRef.selector.rule, propertyIDs, this.m_VisualTree.elementPanel.loadResourceFunc); j++; } StyleContext.s_StyleCache[num] = visualElementStyles; element.SetSharedStyles(visualElementStyles); } if (visualContainer != null) { for (int k = 0; k < visualContainer.childrenCount; k++) { VisualElement childAt = visualContainer.GetChildAt(k); this.UpdateStyles(childAt, depth + 1); } } if (this.m_Matchers.Count > count) { this.m_Matchers.RemoveRange(count, this.m_Matchers.Count - count); } } }