internal void ApplyProperties(StylePropertyReader reader, InheritedStylesData inheritedStylesData)
        {
            while (reader.IsValid())
            {
                var styleProperty = reader.property;
                var propertyID    = reader.propertyID;

                if (reader.IsKeyword(0, StyleValueKeyword.Initial))
                {
                    ApplyInitialStyleValue(reader);
                }
                else if (reader.IsKeyword(0, StyleValueKeyword.Unset) && inheritedStylesData != null)
                {
                    ApplyUnsetStyleValue(reader, inheritedStylesData);
                }
                else
                {
                    switch (propertyID)
                    {
                    case StylePropertyID.Unknown:
                        break;

                    case StylePropertyID.Custom:
                        ApplyCustomStyleProperty(reader);
                        break;

                    case StylePropertyID.BorderColor:
                    case StylePropertyID.BorderRadius:
                    case StylePropertyID.BorderWidth:
                    case StylePropertyID.Flex:
                    case StylePropertyID.Margin:
                    case StylePropertyID.Padding:
                        ApplyShorthandProperty(reader);
                        break;

                    default:
                        ApplyStyleProperty(reader);
                        break;
                    }
                }

                reader.MoveNextProperty();
            }
        }
        private static bool CompileFlexShorthand(StylePropertyReader reader, out StyleFloat grow, out StyleFloat shrink, out StyleLength basis)
        {
            grow   = 0f;
            shrink = 1f;
            basis  = StyleKeyword.Auto;
            bool flag       = false;
            int  valueCount = reader.valueCount;
            bool flag2      = valueCount == 1 && reader.IsValueType(0, StyleValueType.Keyword);

            if (flag2)
            {
                bool flag3 = reader.IsKeyword(0, StyleValueKeyword.None);
                if (flag3)
                {
                    flag   = true;
                    grow   = 0f;
                    shrink = 0f;
                    basis  = StyleKeyword.Auto;
                }
                else
                {
                    bool flag4 = reader.IsKeyword(0, StyleValueKeyword.Auto);
                    if (flag4)
                    {
                        flag   = true;
                        grow   = 1f;
                        shrink = 1f;
                        basis  = StyleKeyword.Auto;
                    }
                }
            }
            else
            {
                bool flag5 = valueCount <= 3;
                if (flag5)
                {
                    flag   = true;
                    grow   = 0f;
                    shrink = 1f;
                    basis  = Length.Percent(0f);
                    bool flag6 = false;
                    bool flag7 = false;
                    int  num   = 0;
                    while (num < valueCount & flag)
                    {
                        StyleValueType valueType = reader.GetValueType(num);
                        bool           flag8     = valueType == StyleValueType.Dimension || valueType == StyleValueType.Keyword;
                        if (flag8)
                        {
                            bool flag9 = flag7;
                            if (flag9)
                            {
                                flag = false;
                                break;
                            }
                            flag7 = true;
                            bool flag10 = valueType == StyleValueType.Keyword;
                            if (flag10)
                            {
                                bool flag11 = reader.IsKeyword(num, StyleValueKeyword.Auto);
                                if (flag11)
                                {
                                    basis = StyleKeyword.Auto;
                                }
                            }
                            else
                            {
                                bool flag12 = valueType == StyleValueType.Dimension;
                                if (flag12)
                                {
                                    basis = reader.ReadStyleLength(num);
                                }
                            }
                            bool flag13 = flag6 && num != valueCount - 1;
                            if (flag13)
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            bool flag14 = valueType == StyleValueType.Float;
                            if (flag14)
                            {
                                StyleFloat styleFloat = reader.ReadStyleFloat(num);
                                bool       flag15     = !flag6;
                                if (flag15)
                                {
                                    flag6 = true;
                                    grow  = styleFloat;
                                }
                                else
                                {
                                    shrink = styleFloat;
                                }
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                        num++;
                    }
                }
            }
            return(flag);
        }
        private static bool CompileFlexShorthand(StylePropertyReader reader, out float grow, out float shrink, out Length basis)
        {
            grow   = 0f;
            shrink = 1f;
            basis  = Length.Auto();

            bool valid      = false;
            var  valueCount = reader.valueCount;

            if (valueCount == 1 && reader.IsValueType(0, StyleValueType.Keyword))
            {
                // Handle none | auto
                if (reader.IsKeyword(0, StyleValueKeyword.None))
                {
                    valid  = true;
                    grow   = 0f;
                    shrink = 0f;
                    basis  = Length.Auto();
                }
                else if (reader.IsKeyword(0, StyleValueKeyword.Auto))
                {
                    valid  = true;
                    grow   = 1f;
                    shrink = 1f;
                    basis  = Length.Auto();
                }
            }
            else if (valueCount <= 3)
            {
                // Handle [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
                valid = true;

                grow   = 0f;
                shrink = 1f;
                basis  = Length.Percent(0);

                bool growFound  = false;
                bool basisFound = false;
                for (int i = 0; i < valueCount && valid; i++)
                {
                    var valueType = reader.GetValueType(i);
                    if (valueType == StyleValueType.Dimension || valueType == StyleValueType.Keyword)
                    {
                        // Basis
                        if (basisFound)
                        {
                            valid = false;
                            break;
                        }

                        basisFound = true;
                        if (valueType == StyleValueType.Keyword)
                        {
                            if (reader.IsKeyword(i, StyleValueKeyword.Auto))
                            {
                                basis = Length.Auto();
                            }
                        }
                        else if (valueType == StyleValueType.Dimension)
                        {
                            basis = reader.ReadLength(i);
                        }

                        if (growFound && i != valueCount - 1)
                        {
                            // If grow is already processed basis must be the last value
                            valid = false;
                        }
                    }
                    else if (valueType == StyleValueType.Float)
                    {
                        var value = reader.ReadFloat(i);
                        if (!growFound)
                        {
                            growFound = true;
                            grow      = value;
                        }
                        else
                        {
                            shrink = value;
                        }
                    }
                    else
                    {
                        valid = false;
                    }
                }
            }

            return(valid);
        }
Beispiel #4
0
        // https://drafts.csswg.org/css-transitions/#transition-shorthand-property
        // [ none | <single-transition-property> ] || <time> || <easing-function> || <time>
        private static void CompileTransition(StylePropertyReader reader, out List <TimeValue> outDelay, out List <TimeValue> outDuration,
                                              out List <StylePropertyName> outProperty, out List <EasingFunction> outTimingFunction)
        {
            s_TransitionDelayList.Clear();
            s_TransitionDurationList.Clear();
            s_TransitionPropertyList.Clear();
            s_TransitionTimingFunctionList.Clear();

            bool isValid         = true;
            bool noneFound       = false;
            var  valueCount      = reader.valueCount;
            int  transitionCount = 0;
            int  i = 0;

            do
            {
                // If none is present and there are more transitions the shorthand is considered invalid
                if (noneFound)
                {
                    isValid = false;
                    break;
                }

                var transitionProperty       = InitialStyle.transitionProperty[0];
                var transitionDuration       = InitialStyle.transitionDuration[0];
                var transitionDelay          = InitialStyle.transitionDelay[0];
                var transitionTimingFunction = InitialStyle.transitionTimingFunction[0];

                bool durationFound       = false;
                bool delayFound          = false;
                bool propertyFound       = false;
                bool timingFunctionFound = false;
                bool commaFound          = false;
                for (; i < valueCount && !commaFound; ++i)
                {
                    var valueType = reader.GetValueType(i);
                    switch (valueType)
                    {
                    case StyleValueType.Keyword:
                        if (reader.IsKeyword(i, StyleValueKeyword.None) && transitionCount == 0)
                        {
                            noneFound          = true;
                            propertyFound      = true;
                            transitionProperty = new StylePropertyName("none");
                        }
                        else
                        {
                            isValid = false;
                        }
                        break;

                    case StyleValueType.Dimension:
                        var time = reader.ReadTimeValue(i);
                        if (!durationFound)
                        {
                            // transition-duration
                            durationFound      = true;
                            transitionDuration = time;
                        }
                        else if (!delayFound)
                        {
                            // transition-delay
                            delayFound      = true;
                            transitionDelay = time;
                        }
                        else
                        {
                            isValid = false;
                        }
                        break;

                    case StyleValueType.Enum:
                        var str = reader.ReadAsString(i);
                        if (!timingFunctionFound && StylePropertyUtil.TryGetEnumIntValue(StyleEnumType.EasingMode, str, out var intValue))
                        {
                            // transition-timing-function
                            timingFunctionFound      = true;
                            transitionTimingFunction = (EasingMode)intValue;
                        }
                        else if (!propertyFound)
                        {
                            // transition-property
                            propertyFound      = true;
                            transitionProperty = new StylePropertyName(str);
                        }
                        else
                        {
                            isValid = false;
                        }
                        break;

                    case StyleValueType.CommaSeparator:
                        commaFound = true;
                        ++transitionCount;
                        break;

                    default:
                        isValid = false;
                        break;
                    }
                }

                s_TransitionDelayList.Add(transitionDelay);
                s_TransitionDurationList.Add(transitionDuration);
                s_TransitionPropertyList.Add(transitionProperty);
                s_TransitionTimingFunctionList.Add(transitionTimingFunction);
            }while (i < valueCount && isValid);

            if (isValid)
            {
                outProperty       = s_TransitionPropertyList;
                outDelay          = s_TransitionDelayList;
                outDuration       = s_TransitionDurationList;
                outTimingFunction = s_TransitionTimingFunctionList;
            }
            else
            {
                outProperty       = InitialStyle.transitionProperty;
                outDelay          = InitialStyle.transitionDelay;
                outDuration       = InitialStyle.transitionDuration;
                outTimingFunction = InitialStyle.transitionTimingFunction;
            }
        }