Beispiel #1
0
        /// <summary>
        /// Creates a function from the given source.
        /// </summary>
        /// <param name="source">The token iterator.</param>
        /// <returns>The created function.</returns>
        CSSFunction CreateFunction(IEnumerator<CssToken> source)
        {
            var name = ((CssKeywordToken)source.Current).Data;
            var args = new CSSValueList();

            //TODO

            while (source.MoveNext())
            {
                if (source.Current.Type == CssTokenType.RoundBracketClose)
                    break;
            }

            return CSSFunction.Create(name, args);
        }
Beispiel #2
0
        public static Shadow ToShadow(this CSSValueList item)
        {
            if (item.Length < 2)
            {
                return(null);
            }

            var inset  = item[0].Is("inset");
            var offset = inset ? 1 : 0;

            if (inset && item.Length < 3)
            {
                return(null);
            }

            var offsetX = item[offset++].ToLength();
            var offsetY = item[offset++].ToLength();

            if (!offsetX.HasValue || !offsetY.HasValue)
            {
                return(null);
            }

            var blurRadius   = Length.Zero;
            var spreadRadius = Length.Zero;
            var color        = Color.Black;

            if (item.Length > offset)
            {
                var blur = item[offset].ToLength();

                if (blur.HasValue)
                {
                    blurRadius = blur.Value;
                    offset++;
                }
            }

            if (item.Length > offset)
            {
                var spread = item[offset].ToLength();

                if (spread.HasValue)
                {
                    spreadRadius = spread.Value;
                    offset++;
                }
            }

            if (item.Length > offset)
            {
                var col = item[offset].ToColor();

                if (col.HasValue)
                {
                    color = col.Value;
                    offset++;
                }
            }

            if (item.Length > offset)
            {
                return(null);
            }

            return(new Shadow(inset, offsetX.Value, offsetY.Value, blurRadius, spreadRadius, color));
        }
Beispiel #3
0
        internal static Boolean CheckSingleProperty(CSSProperty property, Int32 index, CSSValueList arguments)
        {
            if (index < arguments.Length)
            {
                var argument = arguments[index];
                property.Value = argument;
                return(property.Value == argument);
            }

            return(false);
        }
 internal static CSSFunction Create(String name, CSSValueList arguments)
 {
     //TODO
     return null;
 }
Beispiel #5
0
 internal static CSSFunction Create(String name, CSSValueList arguments)
 {
     //TODO
     return(null);
 }
        /// <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));
        }