public void ReadListEasingFunction(List <EasingFunction> list, int index)
        {
            list.Clear();
            do
            {
                var value  = m_Values[m_CurrentValueIndex + index];
                var handle = value.handle;
                if (handle.valueType == StyleValueType.Enum)
                {
                    var enumString = value.sheet.ReadEnum(handle);
                    StylePropertyUtil.TryGetEnumIntValue(StyleEnumType.EasingMode, enumString, out var intValue);
                    list.Add(new EasingFunction((EasingMode)intValue));
                    ++index;
                }

                if (index < valueCount)
                {
                    var nextValue = m_Values[m_CurrentValueIndex + index];
                    if (nextValue.handle.valueType == StyleValueType.CommaSeparator)
                    {
                        ++index;
                    }
                }
            }while (index < valueCount);
        }
예제 #2
0
        static int ReadEnum(StyleEnumType enumType, StylePropertyValue value)
        {
            string enumString = null;
            var    handle     = value.handle;

            if (handle.valueType == StyleValueType.Keyword)
            {
                var keyword = value.sheet.ReadKeyword(handle);
                enumString = keyword.ToUssString();
            }
            else
            {
                enumString = value.sheet.ReadEnum(handle);
            }

            StylePropertyUtil.TryGetEnumIntValue(enumType, enumString, out var intValue);
            return(intValue);
        }
예제 #3
0
        public int ReadEnum(StyleEnumType enumType, int index)
        {
            string enumString = null;
            var    value      = m_Values[m_CurrentValueIndex + index];
            var    handle     = value.handle;

            if (handle.valueType == StyleValueType.Keyword)
            {
                var keyword = value.sheet.ReadKeyword(handle);
                enumString = keyword.ToUssString();
            }
            else
            {
                enumString = value.sheet.ReadEnum(handle);
            }

            return(StylePropertyUtil.GetEnumIntValue(enumType, enumString));
        }
예제 #4
0
        public StyleInt ReadStyleEnum(StyleEnumType enumType, int index)
        {
            StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index];
            StyleValueHandle   handle             = stylePropertyValue.handle;
            bool   flag = handle.valueType == StyleValueType.Keyword;
            string value;

            if (flag)
            {
                StyleValueKeyword svk = stylePropertyValue.sheet.ReadKeyword(handle);
                value = svk.ToUssString();
            }
            else
            {
                value = stylePropertyValue.sheet.ReadEnum(handle);
            }
            int enumIntValue = StylePropertyUtil.GetEnumIntValue(enumType, value);

            return(new StyleInt(enumIntValue));
        }
예제 #5
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;
            }
        }