Пример #1
0
        /// <summary>
        /// Determines if the given value represents a valid state of this property.
        /// </summary>
        /// <param name="value">The state that should be used.</param>
        /// <returns>True if the state is valid, otherwise false.</returns>
        protected override Boolean IsValid(CSSValue value)
        {
            var items           = (value as CSSValueList ?? new CSSValueList(value)).ToList();
            var delays          = new CSSValueList();
            var directions      = new CSSValueList();
            var durations       = new CSSValueList();
            var fillModes       = new CSSValueList();
            var iterationCounts = new CSSValueList();
            var names           = new CSSValueList();
            var timingFunctions = new CSSValueList();
            var playStates      = new CSSValueList();

            foreach (var list in items)
            {
                if (list.Length > 8)
                {
                    return(false);
                }

                if (delays.Length != 0)
                {
                    delays.Add(CSSValue.Separator);
                    durations.Add(CSSValue.Separator);
                    timingFunctions.Add(CSSValue.Separator);
                    iterationCounts.Add(CSSValue.Separator);
                    directions.Add(CSSValue.Separator);
                    fillModes.Add(CSSValue.Separator);
                    names.Add(CSSValue.Separator);
                    playStates.Add(CSSValue.Separator);
                }

                CSSValue delay = null, direction = null, duration = null, fillMode = null,
                         iterationCount = null, name = null, timingFunction = null, playState = null;

                foreach (var item in list)
                {
                    if (!_duration.CanStore(item, ref duration) && !_timingFunction.CanStore(item, ref timingFunction) &&
                        !_delay.CanStore(item, ref delay) && !_iterationCount.CanStore(item, ref iterationCount) &&
                        !_direction.CanStore(item, ref direction) && !_fillMode.CanStore(item, ref fillMode) &&
                        !_playState.CanStore(item, ref playState) && !_name.CanStore(item, ref name))
                    {
                        return(false);
                    }
                }

                delays.Add(delay ?? new CSSPrimitiveValue(Time.Zero));
                durations.Add(duration ?? new CSSPrimitiveValue(Time.Zero));
                timingFunctions.Add(timingFunction ?? new CSSPrimitiveValue(TransitionFunction.Ease));
                iterationCounts.Add(iterationCount ?? new CSSPrimitiveValue(Number.One));
                directions.Add(direction ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.Normal)));
                fillModes.Add(fillMode ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.None)));
                names.Add(name ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.None)));
                playStates.Add(playState ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.Running)));
            }

            return(_name.TrySetValue(names.Reduce()) && _delay.TrySetValue(delays.Reduce()) &&
                   _direction.TrySetValue(directions.Reduce()) && _duration.TrySetValue(durations.Reduce()) &&
                   _fillMode.TrySetValue(fillModes.Reduce()) && _iterationCount.TrySetValue(iterationCounts.Reduce()) &&
                   _timingFunction.TrySetValue(timingFunctions.Reduce()) && _playState.TrySetValue(playStates.Reduce()));
        }
Пример #2
0
        /// <summary>
        /// Determines if the given value represents a valid state of this property.
        /// </summary>
        /// <param name="value">The state that should be used.</param>
        /// <returns>True if the state is valid, otherwise false.</returns>
        protected override Boolean IsValid(CSSValue value)
        {
            var      list = value as CSSValueList ?? new CSSValueList(value);
            var      line = new CSSValueList();
            CSSValue color = null, style = null;

            if (list.Length > 3)
            {
                return(false);
            }

            for (int i = 0; i < list.Length; i++)
            {
                if (_line.CanTake(list[i]))
                {
                    line.Add(list[i]);
                }
                else if (!_color.CanStore(list[i], ref color) && !_style.CanStore(list[i], ref style))
                {
                    return(false);
                }
            }

            return(_line.TrySetValue(line.Reduce()) && _color.TrySetValue(color) && _style.TrySetValue(style));
        }
Пример #3
0
        /// <summary>
        /// Determines if the given value represents a valid state of this property.
        /// </summary>
        /// <param name="value">The state that should be used.</param>
        /// <returns>True if the state is valid, otherwise false.</returns>
        protected override Boolean IsValid(CSSValue value)
        {
            var items           = (value as CSSValueList ?? new CSSValueList(value)).ToList();
            var delays          = new CSSValueList();
            var durations       = new CSSValueList();
            var timingFunctions = new CSSValueList();
            var properties      = new CSSValueList();

            foreach (var list in items)
            {
                if (list.Length > 8)
                {
                    return(false);
                }

                if (delays.Length != 0)
                {
                    delays.Add(CSSValue.Separator);
                    durations.Add(CSSValue.Separator);
                    timingFunctions.Add(CSSValue.Separator);
                    properties.Add(CSSValue.Separator);
                }

                CSSValue delay = null, duration = null, timingFunction = null, property = null;

                foreach (var item in list)
                {
                    if (!_property.CanStore(item, ref property) && !_duration.CanStore(item, ref duration) &&
                        !_timingFunction.CanStore(item, ref timingFunction) && !_delay.CanStore(item, ref delay))
                    {
                        return(false);
                    }
                }

                delays.Add(delay ?? new CSSPrimitiveValue(Time.Zero));
                durations.Add(duration ?? new CSSPrimitiveValue(Time.Zero));
                timingFunctions.Add(timingFunction ?? new CSSPrimitiveValue(TransitionFunction.Ease));
                properties.Add(property ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.All)));
            }

            return(_property.TrySetValue(properties.Reduce()) && _delay.TrySetValue(delays.Reduce()) &&
                   _duration.TrySetValue(durations.Reduce()) && _timingFunction.TrySetValue(timingFunctions.Reduce()));
        }
        Boolean Evaluate(CSSValueList values)
        {
            CSSValue source = null;
            var      slice  = new CSSValueList();
            var      outset = new CSSValueList();
            var      repeat = new CSSValueList();
            var      width  = new CSSValueList();

            for (var i = 0; i < values.Length; i++)
            {
                var value = values[i];

                if (_source.CanStore(value, ref source))
                {
                    continue;
                }
                else if (repeat.Length == 0 && _repeat.CanTake(value))
                {
                    repeat.Add(value);

                    if (i + 1 < values.Length)
                    {
                        repeat.Add(values[++i]);

                        if (!_repeat.CanTake(repeat))
                        {
                            repeat.Remove(values[i--]);
                        }
                    }

                    continue;
                }
                else if (slice.Length == 0 && _slice.CanTake(value))
                {
                    slice.Add(value);

                    while (i + 1 < values.Length)
                    {
                        slice.Add(values[++i]);

                        if (!_slice.CanTake(slice))
                        {
                            slice.Remove(values[i--]);
                            break;
                        }
                    }

                    continue;
                }
                else if (value == CSSValue.Delimiter)
                {
                    if (++i == values.Length)
                    {
                        return(false);
                    }

                    while (i + 1 < values.Length)
                    {
                        value = values[++i];

                        if (value == CSSValueList.Delimiter)
                        {
                            if (++i == values.Length)
                            {
                                return(false);
                            }

                            while (i + 1 < values.Length)
                            {
                                outset.Add(values[++i]);

                                if (!_outset.CanTake(outset))
                                {
                                    outset.Remove(values[i--]);
                                    break;
                                }
                            }

                            if (outset.Length == 0)
                            {
                                return(false);
                            }

                            break;
                        }

                        width.Add(value);

                        if (!_width.CanTake(width))
                        {
                            width.Remove(values[i--]);
                            break;
                        }
                    }

                    continue;
                }

                return(false);
            }

            return(_width.TrySetValue(width.Reduce()) && _source.TrySetValue(source) &&
                   _outset.TrySetValue(outset.Reduce()) && _repeat.TrySetValue(repeat.Reduce()) &&
                   _slice.TrySetValue(slice.Reduce()));
        }
Пример #5
0
        /// <summary>
        /// Determines if the given value represents a valid state of this property.
        /// </summary>
        /// <param name="value">The state that should be used.</param>
        /// <returns>True if the state is valid, otherwise false.</returns>
        protected override Boolean IsValid(CSSValue value)
        {
            var      items       = (value as CSSValueList ?? new CSSValueList(value)).ToList();
            var      images      = new CSSValueList();
            var      positions   = new CSSValueList();
            var      sizes       = new CSSValueList();
            var      repeats     = new CSSValueList();
            var      attachments = new CSSValueList();
            var      origins     = new CSSValueList();
            var      clips       = new CSSValueList();
            CSSValue color       = null;

            foreach (var list in items)
            {
                CSSValue image = null, position = null, size = null, repeat = null,
                         attachment = null, origin = null, clip = null;

                if (color != null)
                {
                    return(false);
                }

                if (images.Length > 0)
                {
                    images.Add(CSSValue.Separator);
                    positions.Add(CSSValue.Separator);
                    sizes.Add(CSSValue.Separator);
                    repeats.Add(CSSValue.Separator);
                    attachments.Add(CSSValue.Separator);
                    origins.Add(CSSValue.Separator);
                    clips.Add(CSSValue.Separator);
                }

                for (int j = 0; j < list.Length; j++)
                {
                    var item = list[j];

                    if (_position.CanStore(item, ref position))
                    {
                        if (j + 1 == list.Length)
                        {
                            continue;
                        }

                        var pack = new CSSValueList();
                        pack.Add(position);
                        pack.Add(list[j + 1]);

                        if (_position.CanTake(pack))
                        {
                            positions.Add(position);
                            position = list[++j];
                        }

                        if (j + 1 < list.Length && list[j + 1] == CSSValue.Delimiter)
                        {
                            j += 2;

                            if (j < list.Length && _size.CanStore(list[j], ref size))
                            {
                                if (j + 1 == list.Length)
                                {
                                    continue;
                                }

                                pack = new CSSValueList();
                                pack.Add(size);
                                pack.Add(list[j + 1]);

                                if (_size.CanTake(pack))
                                {
                                    sizes.Add(size);
                                    size = list[++j];
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    else if (_repeat.CanStore(item, ref repeat))
                    {
                        if (j + 1 == list.Length)
                        {
                            continue;
                        }

                        var pack = new CSSValueList();
                        pack.Add(repeat);
                        pack.Add(list[j + 1]);

                        if (_repeat.CanTake(pack))
                        {
                            repeats.Add(repeat);
                            repeat = list[++j];
                        }
                    }
                    else if (!_image.CanStore(item, ref image) && !_attachment.CanStore(item, ref attachment) &&
                             !_origin.CanStore(item, ref origin) && !_clip.CanStore(item, ref clip) && !_color.CanStore(item, ref color))
                    {
                        return(false);
                    }
                }

                images.Add(image ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.None)));
                positions.Add(position ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.Center)));
                sizes.Add(size ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.Auto)));
                repeats.Add(repeat ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.Repeat)));
                attachments.Add(attachment ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.Scroll)));
                origins.Add(origin ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.BorderBox)));
                clips.Add(clip ?? new CSSPrimitiveValue(new CssIdentifier(Keywords.BorderBox)));
            }

            return(_image.TrySetValue(images.Reduce()) && _position.TrySetValue(positions.Reduce()) &&
                   _repeat.TrySetValue(repeats.Reduce()) && _attachment.TrySetValue(attachments.Reduce()) &&
                   _origin.TrySetValue(origins.Reduce()) && _size.TrySetValue(sizes.Reduce()) &&
                   _clip.TrySetValue(clips) && _color.TrySetValue(color));
        }