Example #1
0
 public void Init(StyleProperty property, StyleSheet sheet, StyleValueHandle[] handles)
 {
     m_ResolvedValues.Clear();
     m_Sheet    = sheet;
     m_Property = property;
     m_Handles  = handles;
 }
Example #2
0
        public void Init(StyleProperty property, StyleSheet sheet, StyleValueHandle[] handles)
        {
            m_ResolvedValues.Clear();
            m_ContextStack.Clear();

            m_Property = property;
            PushContext(sheet, handles);
        }
Example #3
0
        public Result ResolveVarFunction(StyleProperty property, StyleSheet sheet, StyleValueHandle[] handles, ref int index,
                                         List <StylePropertyValue> resolvedValues)
        {
            m_ResolvedValues = resolvedValues;
            m_ResolvedVarStack.Clear();
            m_CurrentProperty      = property;
            m_ValidationExpression = null;

            if (!property.isCustomProperty)
            {
                string syntax;
                if (!StylePropertyCache.TryGetSyntax(property.name, out syntax))
                {
                    Debug.LogAssertion($"Unknown style property {m_CurrentProperty.name}");
                    return(Result.Invalid);
                }

                m_ValidationExpression = s_SyntaxParser.Parse(syntax);
            }

            int    argc;
            string varName;

            ParseVarFunction(sheet, handles, ref index, out argc, out varName);

            var result = ResolveVariable(varName);

            if (result != Result.Valid)
            {
                // var() fallback
                if (result == Result.NotFound && argc > 1 && !m_CurrentProperty.isCustomProperty)
                {
                    var h = handles[++index];
                    Debug.Assert(h.valueType == StyleValueType.FunctionSeparator, $"Unexpected value type {h.valueType} in var function");
                    if (h.valueType == StyleValueType.FunctionSeparator && index + 1 < handles.Length)
                    {
                        ++index;
                        result = ResolveFallback(sheet, handles, ref index);
                    }
                }
            }

            return(result);
        }
Example #4
0
        private void SetupReferences()
        {
            bool flag = this.complexSelectors == null || this.rules == null;

            if (!flag)
            {
                StyleRule[] rules = this.rules;
                for (int i = 0; i < rules.Length; i++)
                {
                    StyleRule       styleRule  = rules[i];
                    StyleProperty[] properties = styleRule.properties;
                    for (int j = 0; j < properties.Length; j++)
                    {
                        StyleProperty styleProperty = properties[j];
                        bool          flag2         = StyleSheet.CustomStartsWith(styleProperty.name, StyleSheet.kCustomPropertyMarker);
                        if (flag2)
                        {
                            styleRule.customPropertiesCount++;
                            styleProperty.isCustomProperty = true;
                        }
                        StyleValueHandle[] values = styleProperty.values;
                        for (int k = 0; k < values.Length; k++)
                        {
                            StyleValueHandle handle = values[k];
                            bool             flag3  = handle.IsVarFunction();
                            if (flag3)
                            {
                                styleProperty.requireVariableResolve = true;
                                break;
                            }
                        }
                    }
                }
                int l   = 0;
                int num = this.complexSelectors.Length;
                while (l < num)
                {
                    this.complexSelectors[l].CachePseudoStateMasks();
                    l++;
                }
                this.orderedClassSelectors = new Dictionary <string, StyleComplexSelector>(StringComparer.Ordinal);
                this.orderedNameSelectors  = new Dictionary <string, StyleComplexSelector>(StringComparer.Ordinal);
                this.orderedTypeSelectors  = new Dictionary <string, StyleComplexSelector>(StringComparer.Ordinal);
                int m = 0;
                while (m < this.complexSelectors.Length)
                {
                    StyleComplexSelector styleComplexSelector = this.complexSelectors[m];
                    bool flag4 = styleComplexSelector.ruleIndex < this.rules.Length;
                    if (flag4)
                    {
                        styleComplexSelector.rule = this.rules[styleComplexSelector.ruleIndex];
                    }
                    styleComplexSelector.orderInStyleSheet = m;
                    StyleSelector     styleSelector     = styleComplexSelector.selectors[styleComplexSelector.selectors.Length - 1];
                    StyleSelectorPart styleSelectorPart = styleSelector.parts[0];
                    string            key = styleSelectorPart.value;
                    Dictionary <string, StyleComplexSelector> dictionary = null;
                    switch (styleSelectorPart.type)
                    {
                    case StyleSelectorType.Wildcard:
                    case StyleSelectorType.Type:
                        key        = (styleSelectorPart.value ?? "*");
                        dictionary = this.orderedTypeSelectors;
                        break;

                    case StyleSelectorType.Class:
                        dictionary = this.orderedClassSelectors;
                        break;

                    case StyleSelectorType.PseudoClass:
                        key        = "*";
                        dictionary = this.orderedTypeSelectors;
                        break;

                    case StyleSelectorType.RecursivePseudoClass:
                        goto IL_22B;

                    case StyleSelectorType.ID:
                        dictionary = this.orderedNameSelectors;
                        break;

                    default:
                        goto IL_22B;
                    }
IL_249:
                    bool flag5 = dictionary != null;
                    if (flag5)
                    {
                        StyleComplexSelector nextInTable;
                        bool flag6 = dictionary.TryGetValue(key, out nextInTable);
                        if (flag6)
                        {
                            styleComplexSelector.nextInTable = nextInTable;
                        }
                        dictionary[key] = styleComplexSelector;
                    }
                    m++;
                    continue;
IL_22B:
                    Debug.LogError(string.Format("Invalid first part type {0}", styleSelectorPart.type));
                    goto IL_249;
                }
            }
        }
        public static void FindSpecifiedStyles(ComputedStyle computedStyle, IEnumerable <SelectorMatchRecord> matchRecords, Dictionary <StylePropertyId, int> result)
        {
            result.Clear();
            bool flag = computedStyle == null;

            if (!flag)
            {
                foreach (SelectorMatchRecord current in matchRecords)
                {
                    int  value             = current.complexSelector.specificity;
                    bool isUnityStyleSheet = current.sheet.isUnityStyleSheet;
                    if (isUnityStyleSheet)
                    {
                        value = -1;
                    }
                    StyleProperty[] properties = current.complexSelector.rule.properties;
                    StyleProperty[] array      = properties;
                    for (int i = 0; i < array.Length; i++)
                    {
                        StyleProperty   styleProperty = array[i];
                        StylePropertyId stylePropertyId;
                        bool            flag2 = StylePropertyUtil.s_NameToId.TryGetValue(styleProperty.name, out stylePropertyId);
                        if (flag2)
                        {
                            bool flag3 = StyleDebug.IsShorthandProperty(stylePropertyId);
                            if (flag3)
                            {
                                string[] longhandPropertyNames = StyleDebug.GetLonghandPropertyNames(stylePropertyId);
                                string[] array2 = longhandPropertyNames;
                                for (int j = 0; j < array2.Length; j++)
                                {
                                    string          name = array2[j];
                                    StylePropertyId stylePropertyIdFromName = StyleDebug.GetStylePropertyIdFromName(name);
                                    result[stylePropertyIdFromName] = value;
                                }
                            }
                            else
                            {
                                result[stylePropertyId] = value;
                            }
                        }
                    }
                }
                StylePropertyId[] inheritedProperties = StyleDebug.GetInheritedProperties();
                StylePropertyId[] array3 = inheritedProperties;
                for (int k = 0; k < array3.Length; k++)
                {
                    StylePropertyId stylePropertyId2 = array3[k];
                    bool            flag4            = result.ContainsKey(stylePropertyId2);
                    if (!flag4)
                    {
                        object computedStyleValue  = StyleDebug.GetComputedStyleValue(computedStyle, stylePropertyId2);
                        object computedStyleValue2 = StyleDebug.GetComputedStyleValue(InitialStyle.Get(), stylePropertyId2);
                        bool   flag5 = !computedStyleValue.Equals(computedStyleValue2);
                        if (flag5)
                        {
                            result[stylePropertyId2] = 2147483646;
                        }
                    }
                }
            }
        }