298 lines
9.4 KiB
C#
298 lines
9.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.StyleSheets;
|
|
|
|
namespace UnityEngine.Experimental.UIElements.StyleSheets
|
|
{
|
|
// Token: 0x02000369 RID: 873
|
|
internal class StyleContext
|
|
{
|
|
// Token: 0x06003529 RID: 13609 RVA: 0x00057824 File Offset: 0x00055A24
|
|
public StyleContext(VisualContainer tree)
|
|
{
|
|
this.m_VisualTree = tree;
|
|
this.m_Matchers = new List<RuleMatcher>(0);
|
|
this.m_MatchedRules = new List<StyleContext.RuleRef>(0);
|
|
}
|
|
|
|
// Token: 0x17000C38 RID: 3128
|
|
// (get) Token: 0x0600352A RID: 13610 RVA: 0x0005784C File Offset: 0x00055A4C
|
|
// (set) Token: 0x0600352B RID: 13611 RVA: 0x00057868 File Offset: 0x00055A68
|
|
public float currentPixelsPerPoint { get; set; }
|
|
|
|
// Token: 0x0600352C RID: 13612 RVA: 0x00057874 File Offset: 0x00055A74
|
|
private void AddMatchersFromSheet(IEnumerable<StyleSheet> styleSheets)
|
|
{
|
|
foreach (StyleSheet styleSheet in styleSheets)
|
|
{
|
|
this.PushStyleSheet(styleSheet);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600352D RID: 13613 RVA: 0x000578CC File Offset: 0x00055ACC
|
|
internal void GetMatchersFor(VisualElement element, List<RuleMatcher> ruleMatchers, List<StyleSheet> stylesheets)
|
|
{
|
|
List<VisualElement> list = new List<VisualElement>();
|
|
list.Add(element);
|
|
VisualContainer visualContainer = element as VisualContainer;
|
|
if (visualContainer == null)
|
|
{
|
|
visualContainer = element.parent;
|
|
}
|
|
while (visualContainer != null)
|
|
{
|
|
if (visualContainer.styleSheets != null)
|
|
{
|
|
stylesheets.AddRange(visualContainer.styleSheets);
|
|
this.AddMatchersFromSheet(visualContainer.styleSheets);
|
|
}
|
|
list.Add(visualContainer);
|
|
visualContainer = visualContainer.parent;
|
|
}
|
|
int num = 0;
|
|
for (int i = list.Count - 1; i >= 0; i--)
|
|
{
|
|
this.GetMatchersFor(list, i, num++, ruleMatchers);
|
|
}
|
|
this.m_Matchers.Clear();
|
|
}
|
|
|
|
// Token: 0x0600352E RID: 13614 RVA: 0x00057974 File Offset: 0x00055B74
|
|
private void GetMatchersFor(List<VisualElement> elements, int idx, int depth, List<RuleMatcher> ruleMatchers)
|
|
{
|
|
VisualElement visualElement = elements[idx];
|
|
int count = this.m_Matchers.Count;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
RuleMatcher ruleMatcher = this.m_Matchers[i];
|
|
if (ruleMatcher.depth >= depth && StyleContext.Match(visualElement, ref ruleMatcher))
|
|
{
|
|
StyleSelector[] selectors = ruleMatcher.complexSelector.selectors;
|
|
int num = ruleMatcher.simpleSelectorIndex + 1;
|
|
int num2 = selectors.Length;
|
|
if (num < num2)
|
|
{
|
|
RuleMatcher ruleMatcher2 = new RuleMatcher
|
|
{
|
|
complexSelector = ruleMatcher.complexSelector,
|
|
depth = ((selectors[num].previousRelationship != StyleSelectorRelationship.Child) ? int.MaxValue : (depth + 1)),
|
|
simpleSelectorIndex = num,
|
|
sheet = ruleMatcher.sheet
|
|
};
|
|
this.m_Matchers.Add(ruleMatcher2);
|
|
}
|
|
else if (idx == 0)
|
|
{
|
|
ruleMatchers.Add(ruleMatcher);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600352F RID: 13615 RVA: 0x00057A78 File Offset: 0x00055C78
|
|
private void PushStyleSheet(StyleSheet styleSheetData)
|
|
{
|
|
StyleComplexSelector[] complexSelectors = styleSheetData.complexSelectors;
|
|
int num = this.m_Matchers.Count + complexSelectors.Length;
|
|
this.m_Matchers.Capacity = Math.Max(this.m_Matchers.Capacity, num);
|
|
foreach (StyleComplexSelector styleComplexSelector in complexSelectors)
|
|
{
|
|
this.m_Matchers.Add(new RuleMatcher
|
|
{
|
|
sheet = styleSheetData,
|
|
complexSelector = styleComplexSelector,
|
|
simpleSelectorIndex = 0,
|
|
depth = int.MaxValue
|
|
});
|
|
}
|
|
}
|
|
|
|
// Token: 0x06003530 RID: 13616 RVA: 0x00057B0C File Offset: 0x00055D0C
|
|
public void DirtyStyleSheets()
|
|
{
|
|
StyleContext.PropagateDirtyStyleSheets(this.m_VisualTree);
|
|
}
|
|
|
|
// Token: 0x06003531 RID: 13617 RVA: 0x00057B1C File Offset: 0x00055D1C
|
|
private static void PropagateDirtyStyleSheets(VisualElement e)
|
|
{
|
|
VisualContainer visualContainer = e as VisualContainer;
|
|
if (visualContainer != null)
|
|
{
|
|
if (visualContainer.styleSheets != null)
|
|
{
|
|
visualContainer.LoadStyleSheetsFromPaths();
|
|
}
|
|
foreach (VisualElement visualElement in visualContainer)
|
|
{
|
|
StyleContext.PropagateDirtyStyleSheets(visualElement);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06003532 RID: 13618 RVA: 0x00057B98 File Offset: 0x00055D98
|
|
public void ApplyStyles(VisualContainer subTree)
|
|
{
|
|
Debug.Assert(subTree.panel != null);
|
|
this.UpdateStyles(subTree, 0);
|
|
this.m_Matchers.Clear();
|
|
}
|
|
|
|
// Token: 0x06003533 RID: 13619 RVA: 0x00057BC0 File Offset: 0x00055DC0
|
|
public void ApplyStyles()
|
|
{
|
|
this.ApplyStyles(this.m_VisualTree);
|
|
}
|
|
|
|
// Token: 0x06003534 RID: 13620 RVA: 0x00057BD0 File Offset: 0x00055DD0
|
|
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 ruleMatcher2 = new RuleMatcher
|
|
{
|
|
complexSelector = ruleMatcher.complexSelector,
|
|
depth = ((selectors[num2].previousRelationship != StyleSelectorRelationship.Child) ? int.MaxValue : (depth + 1)),
|
|
simpleSelectorIndex = num2,
|
|
sheet = ruleMatcher.sheet
|
|
};
|
|
this.m_Matchers.Add(ruleMatcher2);
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06003535 RID: 13621 RVA: 0x00057EF0 File Offset: 0x000560F0
|
|
private static bool Match(VisualElement element, ref RuleMatcher matcher)
|
|
{
|
|
bool flag = true;
|
|
StyleSelector styleSelector = matcher.complexSelector.selectors[matcher.simpleSelectorIndex];
|
|
int num = styleSelector.parts.Length;
|
|
int num2 = 0;
|
|
while (num2 < num && flag)
|
|
{
|
|
switch (styleSelector.parts[num2].type)
|
|
{
|
|
case StyleSelectorType.Wildcard:
|
|
break;
|
|
case StyleSelectorType.Type:
|
|
flag = element.typeName == styleSelector.parts[num2].value;
|
|
break;
|
|
case StyleSelectorType.Class:
|
|
flag = element.ClassListContains(styleSelector.parts[num2].value);
|
|
break;
|
|
case StyleSelectorType.PseudoClass:
|
|
{
|
|
int pseudoStates = (int)element.pseudoStates;
|
|
flag = (styleSelector.pseudoStateMask & pseudoStates) == styleSelector.pseudoStateMask;
|
|
flag &= (styleSelector.negatedPseudoStateMask & ~pseudoStates) == styleSelector.negatedPseudoStateMask;
|
|
break;
|
|
}
|
|
case StyleSelectorType.RecursivePseudoClass:
|
|
goto IL_FA;
|
|
case StyleSelectorType.ID:
|
|
flag = element.name == styleSelector.parts[num2].value;
|
|
break;
|
|
default:
|
|
goto IL_FA;
|
|
}
|
|
IL_101:
|
|
num2++;
|
|
continue;
|
|
IL_FA:
|
|
flag = false;
|
|
goto IL_101;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x04000B83 RID: 2947
|
|
private List<RuleMatcher> m_Matchers;
|
|
|
|
// Token: 0x04000B84 RID: 2948
|
|
private List<StyleContext.RuleRef> m_MatchedRules;
|
|
|
|
// Token: 0x04000B85 RID: 2949
|
|
private VisualContainer m_VisualTree;
|
|
|
|
// Token: 0x04000B86 RID: 2950
|
|
private static Dictionary<long, VisualElementStyles> s_StyleCache = new Dictionary<long, VisualElementStyles>();
|
|
|
|
// Token: 0x0200036A RID: 874
|
|
private struct RuleRef
|
|
{
|
|
// Token: 0x04000B87 RID: 2951
|
|
public StyleComplexSelector selector;
|
|
|
|
// Token: 0x04000B88 RID: 2952
|
|
public StyleSheet sheet;
|
|
}
|
|
}
|
|
}
|