Exemplo n.º 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 values = value.AsList<CSSPrimitiveValue>();

            if (values != null)
            {
                var times = new List<Time>();

                foreach (var v in values)
                {
                    var time = v.ToTime();

                    if (time == null)
                        return false;

                    times.Add(time.Value);
                }

                _times.Clear();
                _times.AddRange(times);
                return true;
            }

            return false;
        }
Exemplo n.º 2
0
        static SizeMode?Check(CSSValue value)
        {
            var distance = value.ToDistance();

            if (distance != null)
            {
                return new SizeMode {
                           Width = distance
                }
            }
            ;
            else if (value.Is(Keywords.Auto))
            {
                return new SizeMode {
                }
            }
            ;
            else if (value.Is(Keywords.Cover))
            {
                return new SizeMode {
                           IsCovered = true
                }
            }
            ;
            else if (value.Is(Keywords.Contain))
            {
                return new SizeMode {
                           IsContained = true
                }
            }
            ;

            return(null);
        }
Exemplo n.º 3
0
        static ContentMode Evaluate(CSSValue value)
        {
            ContentMode mode = null;

            if (modes.TryGetValue(value, out mode))
            {
                return(mode);
            }

            var primitive = value as CSSPrimitiveValue;

            if (primitive != null)
            {
                switch (primitive.Unit)
                {
                case UnitType.Uri:
                    return(new UrlContentMode(new Url(primitive.ToUri())));

                case UnitType.String:
                    return(new TextContentMode(primitive.GetString()));

                case UnitType.Attr:
                    return(new AttributeContentMode(primitive.GetString()));

                case UnitType.Counter:
                    return(new CounterContentMode((Counter)primitive.Value));
                }
            }

            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 values = value.AsList <CSSPrimitiveValue>();

            if (values != null)
            {
                var fillModes = new List <AnimationDirection>();

                foreach (var item in values)
                {
                    var direction = item.ToDirection();

                    if (direction == null)
                    {
                        return(false);
                    }

                    fillModes.Add(direction.Value);
                }

                _directions.Clear();
                _directions.AddRange(fillModes);
                return(true);
            }

            return(false);
        }
Exemplo n.º 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 length = value.ToLength();

            if (length.HasValue)
            {
                _h = _v = length.Value;
            }
            else if (value is CSSValueList)
            {
                var values = (CSSValueList)value;

                if (values.Length != 2)
                {
                    return(false);
                }

                var h = values[0].ToLength();
                var v = values[1].ToLength();

                if (!h.HasValue || !v.HasValue)
                {
                    return(false);
                }

                _h = h.Value;
                _v = v.Value;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
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 attachments = new List <BackgroundAttachment>();

            for (int i = 0; i < list.Length; i++)
            {
                var attachment = list[i].ToBackgroundAttachment();

                if (attachment == null)
                {
                    return(false);
                }

                attachments.Add(attachment.Value);

                if (++i < list.Length && list[i] != CSSValue.Separator)
                {
                    return(false);
                }
            }

            _attachments = attachments;
            return(true);
        }
Exemplo n.º 7
0
        public static Angle?ToAngle(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Angle> )
            {
                return(((CSSPrimitiveValue <Angle>)value).Value);
            }
            else if (value is CSSValueList)
            {
                var values = (CSSValueList)value;

                if (values.Length == 2 && values[0].Is("to"))
                {
                    if (values[1].Is("bottom"))
                    {
                        return(new Angle(180f, Angle.Unit.Deg));
                    }
                    else if (values[1].Is("right"))
                    {
                        return(new Angle(90f, Angle.Unit.Deg));
                    }
                    else if (values[1].Is("left"))
                    {
                        return(new Angle(270f, Angle.Unit.Deg));
                    }
                    else if (values[1].Is("top"))
                    {
                        return(new Angle(0f, Angle.Unit.Deg));
                    }
                }
            }

            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 values = value.AsList(ToNumber);

            if (values != null)
            {
                var iterations = new List <Int32>();

                foreach (var v in values)
                {
                    var n = v.ToInteger();

                    if (n == null)
                    {
                        return(false);
                    }

                    iterations.Add(n.Value);
                }


                _iterations.Clear();
                _iterations.AddRange(iterations);
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
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()));
        }
Exemplo n.º 10
0
        public static Length?ToBorderWidth(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Length> )
            {
                return(((CSSPrimitiveValue <Length>)value).Value);
            }
            else if (value is CSSPrimitiveValue <Number> && ((CSSPrimitiveValue <Number>)value).Value == Number.Zero)
            {
                return(Length.Zero);
            }
            else if (value.Is("thin"))
            {
                return(Length.Thin);
            }
            else if (value.Is("medium"))
            {
                return(Length.Medium);
            }
            else if (value.Is("thick"))
            {
                return(Length.Thick);
            }

            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 list  = value as CSSValueList ?? new CSSValueList(value);
            var clips = new List <BoxModel>();

            for (int i = 0; i < list.Length; i++)
            {
                var clip = list[i].ToBoxModel();

                if (!clip.HasValue)
                {
                    return(false);
                }

                clips.Add(clip.Value);

                if (++i < list.Length && list[i] != CSSValue.Separator)
                {
                    return(false);
                }
            }

            _clips = clips;
            return(true);
        }
Exemplo n.º 12
0
        protected static Boolean ValidatePeriodic(CSSValue v, CSSProperty t, CSSProperty r, CSSProperty b, CSSProperty l)
        {
            var      values = v as CSSValueList ?? new CSSValueList(v);
            CSSValue top    = null;
            CSSValue right  = null;
            CSSValue bottom = null;
            CSSValue left   = null;

            if (values.Length > 4)
            {
                return(false);
            }

            foreach (var value in values)
            {
                if (!t.CanStore(value, ref top) && !r.CanStore(value, ref right) && !b.CanStore(value, ref bottom) && !l.CanStore(value, ref left))
                {
                    return(false);
                }
            }

            right  = right ?? top;
            bottom = bottom ?? top;
            left   = left ?? right;
            return(t.TrySetValue(top) && r.TrySetValue(right) && b.TrySetValue(bottom) && l.TrySetValue(left));
        }
        static IDistance GetMode(CSSValue value, String minIdentifier, String maxIdentifier)
        {
            var calc = value.ToDistance();

            if (calc == null)
            {
                var ident = value.ToIdentifier();

                if (ident != null)
                {
                    if (ident.Equals(minIdentifier, StringComparison.OrdinalIgnoreCase))
                    {
                        calc = Percent.Zero;
                    }
                    else if (ident.Equals(maxIdentifier, StringComparison.OrdinalIgnoreCase))
                    {
                        calc = Percent.Hundred;
                    }
                    else if (ident.Equals(Keywords.Center, StringComparison.OrdinalIgnoreCase))
                    {
                        calc = Percent.Fifty;
                    }
                }
            }

            return(calc);
        }
Exemplo n.º 14
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 values = value.AsList <CSSPrimitiveValue>();

            if (values != null)
            {
                var fillModes = new List <AnimationFillStyle>();

                foreach (var item in values)
                {
                    var mode = item.ToFillMode();

                    if (mode == null)
                    {
                        return(false);
                    }

                    fillModes.Add(mode.Value);
                }

                _fillModes.Clear();
                _fillModes.AddRange(fillModes);
                return(true);
            }

            return(false);
        }
Exemplo n.º 15
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));
        }
        static IDistance GetMode(CSSValue value, String minIdentifier, String maxIdentifier)
        {
            var calc = value.ToDistance();

            if (calc == null && value is CSSPrimitiveValue)
            {
                var primitive = (CSSPrimitiveValue)value;

                if (primitive.Unit == UnitType.Ident)
                {
                    var ident = primitive.GetString();

                    if (ident.Equals(minIdentifier, StringComparison.OrdinalIgnoreCase))
                    {
                        calc = Percent.Zero;
                    }
                    else if (ident.Equals(maxIdentifier, StringComparison.OrdinalIgnoreCase))
                    {
                        calc = Percent.Hundred;
                    }
                    else if (ident.Equals(Keywords.Center, StringComparison.OrdinalIgnoreCase))
                    {
                        calc = Percent.Fifty;
                    }
                }
            }

            return(calc);
        }
Exemplo n.º 17
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 values    = value as CSSValueList ?? new CSSValueList(value);
            var list      = values.ToList();
            var positions = new List <Point>();

            foreach (var entry in list)
            {
                if (entry.Length == 0 || entry.Length > 4)
                {
                    return(false);
                }

                var position = entry.ToPoint();

                if (position == null)
                {
                    return(false);
                }

                positions.Add(position);
            }

            _positions = positions;
            return(true);
        }
        /// <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 values = value.AsList <CSSPrimitiveValue>();

            if (values != null)
            {
                var states = new List <PlayState>();

                foreach (var item in values)
                {
                    if (item.Is(Keywords.Running))
                    {
                        states.Add(PlayState.Running);
                    }
                    else if (item.Is(Keywords.Paused))
                    {
                        states.Add(PlayState.Paused);
                    }
                    else
                    {
                        return(false);
                    }
                }

                _states.Clear();
                _states.AddRange(states);
                return(true);
            }

            return(false);
        }
Exemplo n.º 19
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)
        {
            if (value.Is(Keywords.Normal))
            {
                _mode = _normal;
            }
            else if (value.Is(Keywords.None))
            {
                _mode = null;
            }
            else if (value is CSSValueList)
            {
                return(Evaluate((CSSValueList)value));
            }
            else
            {
                var mode = Evaluate(value);

                if (mode == null)
                {
                    return(false);
                }

                _mode = mode;
            }

            return(true);
        }
        /// <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;
            var v1   = value;
            var v2   = value;

            if (list != null)
            {
                if (list.Length != 2)
                {
                    return(false);
                }

                v1 = list[0];
                v2 = list[1];
            }

            var c1 = v1.ToDistance();
            var c2 = v2.ToDistance();

            if (c1 == null || c2 == null)
            {
                return(false);
            }

            _h = c1;
            _v = c2;
            return(true);
        }
Exemplo n.º 21
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 values  = value as CSSValueList ?? new CSSValueList(value);
            var origins = new List <BoxModel>();

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

                if (!origin.HasValue)
                {
                    return(false);
                }

                origins.Add(origin.Value);

                if (++i < values.Length && values[i] != CSSValue.Separator)
                {
                    return(false);
                }
            }

            _origins = origins;
            return(true);
        }
Exemplo n.º 22
0
        public static String ToContent(this CSSValue value)
        {
            if (value is CSSStringValue)
            {
                return(((CSSStringValue)value).Value);
            }

            return(null);
        }
Exemplo n.º 23
0
        public static Time?ToTime(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Time> )
            {
                return(((CSSPrimitiveValue <Time>)value).Value);
            }

            return(null);
        }
Exemplo n.º 24
0
        public static Byte?ToByte(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Number> )
            {
                return((Byte)Math.Min(Math.Max((Int32)((CSSPrimitiveValue <Number>)value).Value, 0), 255));
            }

            return(null);
        }
Exemplo n.º 25
0
        public static Location ToUri(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Location> )
            {
                return(((CSSPrimitiveValue <Location>)value).Value);
            }

            return(null);
        }
Exemplo n.º 26
0
        public static Single?ToNumber(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Number> )
            {
                return((Single)((CSSPrimitiveValue <Number>)value).Value);
            }

            return(null);
        }
Exemplo n.º 27
0
        public static Int32?ToInteger(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Number> )
            {
                return((Int32)((CSSPrimitiveValue <Number>)value).Value);
            }

            return(null);
        }
Exemplo n.º 28
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)
        {
            if (value is CSSValueList)
            {
                return(Evaluate((CSSValueList)value));
            }

            return(Evaluate(new CSSValueList(value)));
        }
Exemplo n.º 29
0
        public static Percent?ToPercent(this CSSValue value)
        {
            if (value is CSSPrimitiveValue <Percent> )
            {
                return(((CSSPrimitiveValue <Percent>)value).Value);
            }

            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)
        {
            if (value is CSSValueList)
            {
                return(SetXY((CSSValueList)value));
            }

            return(SetSingle(value));
        }
Exemplo n.º 31
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 color = value.ToColor();

            if (color.HasValue)
                _color = color.Value;
            else if (value != CSSValue.Inherit)
                return false;

            return true;
        }
Exemplo n.º 32
0
 /// <summary>
 /// Creates a new CSS value list.
 /// </summary>
 /// <param name="item">The first item to add.</param>
 internal CSSValueList(CSSValue item)
     : this()
 {
     _items.Add(item);
 }
Exemplo n.º 33
0
 static Boolean CheckNumber(CSSValue cssValue)
 {
     return (cssValue.CssValueType == CssValueType.PrimitiveValue && ((CSSPrimitiveValue)cssValue).PrimitiveType == CssUnit.Number);
 }
Exemplo n.º 34
0
 public CssRuleViewModel(CSSValue value)
 {
     Init(value);
     name = value.CssText;
 }
Exemplo n.º 35
0
 static Byte ToByte(CSSValue cssValue)
 {
     return ToByte(((CSSPrimitiveValue)cssValue).GetFloatValue(CssUnit.Number));
 }
Exemplo n.º 36
0
 static Single ToSingle(CSSValue cssValue)
 {
     var f = ((CSSPrimitiveValue)cssValue).GetFloatValue(CssUnit.Number);
     return f.HasValue ? f.Value : 0f;
 }