Boolean CheckList(CSSValueList list)
        {
            var entries = new List<KeyValuePair<String, Int32>>();

            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] is CSSIdentifierValue == false)
                    return false;

                var ident = ((CSSIdentifierValue)list[i]).Value;
                var num = 0;

                if (i + 1 < list.Length)
                {
                    var number = list[i + 1].ToInteger();

                    if (number.HasValue)
                    {
                        i++;
                        num = number.Value;
                    }
                }

                entries.Add(new KeyValuePair<String, Int32>(ident, num));
            }

            _resets.Clear();

            foreach (var entry in entries)
                _resets[entry.Key] = entry.Value;

            return true;
        }
        Boolean Evaluate(CSSValueList values)
        {
            if (values.Length > 4)
                return false;

            var top = ToMode(values[0]);
            var right = ToMode(values[1]);
            var bottom = top;
            var left = right;

            if (top == null || right == null)
                return false;

            if (values.Length > 2)
            {
                bottom = ToMode(values[2]);

                if (bottom == null)
                    return false;

                if (values.Length > 3)
                {
                    left = ToMode(values[3]);

                    if (left == null)
                        return false;
                }
            }

            _left = left;
            _right = right;
            _bottom = bottom;
            _top = top;
            return true;
        }
예제 #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)
        {
            if (value == CSSValue.Inherit)
                return true;

            var list = value as CSSValueList;

            if (list == null)
                list = new CSSValueList(value);

            var index = 0;
            var startGroup = new List<CSSProperty>(3);
            var style = new CSSOutlineStyleProperty();
            var width = new CSSOutlineWidthProperty();
            var color = new CSSOutlineColorProperty();
            startGroup.Add(style);
            startGroup.Add(width);
            startGroup.Add(color);

            while (true)
            {
                var length = startGroup.Count;

                for (int i = 0; i < length; i++)
                {
                    if (CheckSingleProperty(startGroup[i], index, list))
                    {
                        startGroup.RemoveAt(i);
                        index++;
                        break;
                    }
                }

                if (length == startGroup.Count)
                    break;
            }

            if (index == list.Length)
            {
                _style = style;
                _width = width;
                _color = color;
                return true;
            }

            return false;
        }
        Boolean CheckList(CSSValueList values)
        {
            var sizes = new List<SizeMode>();
            var list = values.ToList();

            foreach (var entry in list)
            {
                while (entry.Length == 0 || entry.Length > 2)
                    return false;

                var size = entry.Length == 1 ? Check(entry[0]) : Check(entry[0], entry[1]);

                if (size == null)
                    return false;

                sizes.Add(size);
            }

            _sizes = sizes;
            return true;
        }
        Boolean SetXY(CSSValueList list)
        {
            if (list.Length == 2)
            {
                var x = GetMode(list[0], "left", "right");
                var y = GetMode(list[1], "top", "bottom");

                if (y == null || x == null)
                {
                    x = GetMode(list[1], "left", "right");
                    y = GetMode(list[0], "top", "bottom");
                }

                if (x != null && y != null)
                {
                    _x = x;
                    _y = y;
                    return true;
                }
            }

            return false;
        }
예제 #6
0
        Boolean Evaluate(CSSValueList values)
        {
            var items = new List<ContentMode>();

            foreach (var value in values)
            {
                var item = Evaluate(value);

                if (item == null)
                    return false;

                items.Add(item);
            }

            if (items.Count == 0)
                return false;
            else if (items.Count == 1)
                _mode = items[0];
            else
                _mode = new MultiContentMode(items);

            return true;
        }
예제 #7
0
        Boolean Evaluate(CSSValueList values)
        {
            var modes = new List<CursorMode>();
            var entries = values.ToList();
            var acceptMore = true;

            foreach (var entry in entries)
            {
                if (!acceptMore || entry.Length == 0)
                    return false;

                if (entry.Length == 1)
                {
                    var item = Evaluate(entry[0]);

                    if (item == null)
                        return false;

                    acceptMore = item is CustomCursorMode;
                    modes.Add(item);
                }
                else if(entry.Length == 3)
                {
                    var location = entry[0].ToUri();
                    var x = entry[1].ToNumber();
                    var y = entry[2].ToNumber();

                    if (location == null || !x.HasValue || !y.HasValue)
                        return false;

                    modes.Add(new CustomCursorMode(location, x, y));
                }
                else
                    return false;
            }

            if (modes.Count == 1)
                _mode = modes[0];
            else if (modes.Count == 0)
                return false;

            _mode = new MultiCursorMode(modes);
            return true;
        }
        static Boolean Check(CSSValueList values, ref Position position)
        {
            var index      = 0;
            var shift      = CSSCalcValue.Zero;
            var horizontal = CSSCalcValue.Center;
            var vertical   = CSSCalcValue.Center;
            var value      = values[index];

            if (value.Is("left"))
            {
                horizontal = CSSCalcValue.Zero;
                shift      = values[index + 1].AsCalc();
            }
            else if (value.Is("right"))
            {
                horizontal = CSSCalcValue.Full;
                shift      = values[index + 1].AsCalc();
            }
            else if (!value.Is("center"))
            {
                return(false);
            }

            if (shift != null && shift != CSSCalcValue.Zero)
            {
                index++;
                horizontal = horizontal.Add(shift);
                shift      = CSSCalcValue.Zero;
            }

            value = values[++index];

            if (value.Is("top"))
            {
                vertical = CSSCalcValue.Zero;

                if (index + 1 < values.Length)
                {
                    shift = values[index + 1].AsCalc();
                }
            }
            else if (value.Is("bottom"))
            {
                vertical = CSSCalcValue.Full;

                if (index + 1 < values.Length)
                {
                    shift = values[index + 1].AsCalc();
                }
            }
            else if (!value.Is("center"))
            {
                return(false);
            }

            if (shift == null)
            {
                return(false);
            }
            else if (shift != CSSCalcValue.Zero)
            {
                vertical = vertical.Add(shift);
            }

            position.X = horizontal;
            position.Y = vertical;
            return(true);
        }
        Boolean Check(CSSValueList arguments)
        {
            var count = arguments.Length;
            var splitIndex = arguments.Length;

            for (var i = 0; i < splitIndex; i++)
                if (arguments[i] == CSSValue.Delimiter)
                    splitIndex = i;

            if (count - 1 > splitIndex + 4 || splitIndex > 4 || splitIndex == count - 1 || splitIndex == 0)
                return false;

            var values = new CSSCalcValue[4];

            for (int i = 0; i < splitIndex; i++)
            {
                values[i] = arguments[i].AsCalc();

                for (int j = 2 * i + 1; j < 4; j += i + 1)
                    values[j] = values[i];

                if (values[i] == null)
                    return false;
            }

            _topLeftHorizontal = values[0];
            _topRightHorizontal = values[1];
            _bottomRightHorizontal = values[2];
            _bottomLeftHorizontal = values[3];

            if (splitIndex != count)
            {
                splitIndex++;
                count -= splitIndex;

                for (int i = 0; i < count; i++)
                {
                    values[i] = arguments[i + splitIndex].AsCalc();

                    for (int j = 2 * i + 1; j < 4; j += i + 1)
                        values[j] = values[i];

                    if (values[i] == null)
                        return false;
                }
            }

            _topLeftVertical = values[0];
            _topRightVertical = values[1];
            _bottomRightVertical = values[2];
            _bottomLeftVertical = values[3];

            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)
        {
            if (value != CSSValue.Inherit)
            {
                var values = value as CSSValueList ?? new CSSValueList(value);
                var image = new CSSValueList();
                var position = new CSSValueList();
                var size = new CSSValueList();
                var repeat = new CSSValueList();
                var attachment = new CSSValueList();
                var origin = new CSSValueList();
                var clip = new CSSValueList();
                var color = new CSSPrimitiveValue<Color>(Color.Transparent);
                var list = values.ToList();

                for (int i = 0; i < list.Count; i++)
                {
                    var entry = list[i];
                    var hasImage = false;
                    var hasPosition = false;
                    var hasRepeat = false;
                    var hasAttachment = false;
                    var hasBox = false;
                    var hasColor = i + 1 != list.Count;

                    for (int j = 0; j < entry.Length; j++)
                    {
                        if (!hasPosition && (entry[j].IsOneOf("top", "left", "center", "bottom", "right") || entry[j].AsCalc() != null))
                        {
                            hasPosition = true;
                            position.Add(entry[j]);

                            while (j + 1 < entry.Length && (entry[j + 1].IsOneOf("top", "left", "center", "bottom", "right") || entry[j + 1].AsCalc() != null))
                                position.Add(entry[++j]);

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

                                if (j < entry.Length && (entry[j].IsOneOf("auto", "contain", "cover") || entry[j].AsCalc() != null))
                                {
                                    size.Add(entry[j]);

                                    if (j + 1 < entry.Length && (entry[j + 1].Is("auto") || entry[j + 1].AsCalc() != null))
                                        size.Add(entry[++j]);
                                }
                                else
                                    return false;
                            }
                            else
                                size.Add(new CSSIdentifierValue("auto"));

                            continue;
                        }

                        if (!hasImage && entry[j].AsImage() != null)
                        {
                            hasImage = true;
                            image.Add(entry[j]);
                        }
                        else if (!hasRepeat && entry[j].IsOneOf("repeat-x", "repeat-y", "repeat", "space", "round", "no-repeat"))
                        {
                            hasRepeat = true;
                            repeat.Add(entry[j]);

                            if (j + 1 < entry.Length && entry[j + 1].IsOneOf("repeat", "space", "round", "no-repeat"))
                                repeat.Add(entry[++j]);
                        }
                        else if (!hasAttachment && entry[j].IsOneOf("local", "fixed", "scroll"))
                        {
                            hasAttachment = true;
                            attachment.Add(entry[j]);
                        }
                        else if (!hasBox && entry[j].ToBoxModel().HasValue)
                        {
                            hasBox = true;
                            origin.Add(entry[j]);

                            if (j + 1 < entry.Length && entry[j + 1].ToBoxModel().HasValue)
                                clip.Add(entry[++j]);
                            else
                                clip.Add(new CSSIdentifierValue("border-box"));
                        }
                        else
                        {
                            if (hasColor)
                                return false;

                            hasColor = true;
                            color = entry[j].AsColor();

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

                    if (!hasImage)
                        image.Add(new CSSIdentifierValue("none"));

                    if (!hasPosition)
                    {
                        position.Add(new CSSIdentifierValue("center"));
                        size.Add(new CSSIdentifierValue("auto"));
                    }

                    if (!hasRepeat)
                        repeat.Add(new CSSIdentifierValue("repeat"));

                    if (!hasAttachment)
                        attachment.Add(new CSSIdentifierValue("scroll"));

                    if (!hasBox)
                    {
                        origin.Add(new CSSIdentifierValue("border-box"));
                        clip.Add(new CSSIdentifierValue("border-box"));
                    }

                    if (i + 1 < list.Count)
                    {
                        image.Add(CSSValue.Separator);
                        position.Add(CSSValue.Separator);
                        size.Add(CSSValue.Separator);
                        repeat.Add(CSSValue.Separator);
                        attachment.Add(CSSValue.Separator);
                        origin.Add(CSSValue.Separator);
                        clip.Add(CSSValue.Separator);
                    }
                }

                _image.Value = image;
                _position.Value = position;
                _repeat.Value = repeat;
                _attachment.Value = attachment;
                _origin.Value = origin;
                _size.Value = size;
                _clip.Value = clip;
                _color.Value = color;
            }

            return true;
        }
예제 #11
0
        protected override Boolean IsValid(CSSValue value)
        {
            if (value != CSSValue.Inherit)
            {
                var values     = value as CSSValueList ?? new CSSValueList(value);
                var image      = new CSSValueList();
                var position   = new CSSValueList();
                var size       = new CSSValueList();
                var repeat     = new CSSValueList();
                var attachment = new CSSValueList();
                var origin     = new CSSValueList();
                var clip       = new CSSValueList();
                var color      = new CSSPrimitiveValue <Color>(AngleSharp.DOM.Color.Transparent);
                var list       = values.ToList();

                for (int i = 0; i < list.Count; i++)
                {
                    var entry         = list[i];
                    var hasImage      = false;
                    var hasPosition   = false;
                    var hasRepeat     = false;
                    var hasAttachment = false;
                    var hasBox        = false;
                    var hasColor      = i + 1 != list.Count;

                    for (int j = 0; j < entry.Length; j++)
                    {
                        if (!hasPosition && (entry[j].IsOneOf("top", "left", "center", "bottom", "right") || entry[j].AsCalc() != null))
                        {
                            hasPosition = true;
                            position.Add(entry[j]);

                            while (j + 1 < entry.Length && (entry[j + 1].IsOneOf("top", "left", "center", "bottom", "right") || entry[j + 1].AsCalc() != null))
                            {
                                position.Add(entry[++j]);
                            }

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

                                if (j < entry.Length && (entry[j].IsOneOf("auto", "contain", "cover") || entry[j].AsCalc() != null))
                                {
                                    size.Add(entry[j]);

                                    if (j + 1 < entry.Length && (entry[j + 1].Is("auto") || entry[j + 1].AsCalc() != null))
                                    {
                                        size.Add(entry[++j]);
                                    }
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                size.Add(new CSSIdentifierValue("auto"));
                            }

                            continue;
                        }

                        if (!hasImage && entry[j].AsImage() != null)
                        {
                            hasImage = true;
                            image.Add(entry[j]);
                        }
                        else if (!hasRepeat && entry[j].IsOneOf("repeat-x", "repeat-y", "repeat", "space", "round", "no-repeat"))
                        {
                            hasRepeat = true;
                            repeat.Add(entry[j]);

                            if (j + 1 < entry.Length && entry[j + 1].IsOneOf("repeat", "space", "round", "no-repeat"))
                            {
                                repeat.Add(entry[++j]);
                            }
                        }
                        else if (!hasAttachment && entry[j].IsOneOf("local", "fixed", "scroll"))
                        {
                            hasAttachment = true;
                            attachment.Add(entry[j]);
                        }
                        else if (!hasBox && entry[j].ToBoxModel().HasValue)
                        {
                            hasBox = true;
                            origin.Add(entry[j]);

                            if (j + 1 < entry.Length && entry[j + 1].ToBoxModel().HasValue)
                            {
                                clip.Add(entry[++j]);
                            }
                            else
                            {
                                clip.Add(new CSSIdentifierValue("border-box"));
                            }
                        }
                        else
                        {
                            if (hasColor)
                            {
                                return(false);
                            }

                            hasColor = true;
                            color    = entry[j].AsColor();

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

                    if (!hasImage)
                    {
                        image.Add(new CSSIdentifierValue("none"));
                    }

                    if (!hasPosition)
                    {
                        position.Add(new CSSIdentifierValue("center"));
                        size.Add(new CSSIdentifierValue("auto"));
                    }

                    if (!hasRepeat)
                    {
                        repeat.Add(new CSSIdentifierValue("repeat"));
                    }

                    if (!hasAttachment)
                    {
                        attachment.Add(new CSSIdentifierValue("scroll"));
                    }

                    if (!hasBox)
                    {
                        origin.Add(new CSSIdentifierValue("border-box"));
                        clip.Add(new CSSIdentifierValue("border-box"));
                    }

                    if (i + 1 < list.Count)
                    {
                        image.Add(CSSValue.Separator);
                        position.Add(CSSValue.Separator);
                        size.Add(CSSValue.Separator);
                        repeat.Add(CSSValue.Separator);
                        attachment.Add(CSSValue.Separator);
                        origin.Add(CSSValue.Separator);
                        clip.Add(CSSValue.Separator);
                    }
                }

                _image.Value      = image;
                _position.Value   = position;
                _repeat.Value     = repeat;
                _attachment.Value = attachment;
                _origin.Value     = origin;
                _size.Value       = size;
                _clip.Value       = clip;
                _color.Value      = color;
            }

            return(true);
        }
예제 #12
0
        Boolean Check(CSSValueList arguments)
        {
            var count = arguments.Length;

            if (count > 4)
                return false;

            var values = new CSSValue[4];

            for (int i = 0; i < count; i++)
                for (int j = i; j < 4; j += i + 1)
                    values[j] = arguments[i];

            return Check(values);
        }
        Boolean SetXYZ(CSSValueList list)
        {
            var z = CSSCalcValue.Zero;

            if (list.Length == 3)
            {
                if (!list[2].ToLength().HasValue)
                    return false;

                z = list[2].AsCalc();
            }

            if (z != CSSCalcValue.Zero || list.Length == 2)
            {
                var x = GetMode(list[0], "left", "right");
                var y = GetMode(list[1], "top", "bottom");

                if (y == null || x == null)
                {
                    x = GetMode(list[1], "left", "right");
                    y = GetMode(list[0], "top", "bottom");
                }

                if (x != null && y != null)
                {
                    _x = x;
                    _y = y;
                    _z = z;
                    return true;
                }
            }

            return false;
        }