CssBorderRadiusProperty
Information can be found on MDN:
https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius
using AngleSharp.Css;
using AngleSharp.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AngleSharp.Dom.Css
{
internal sealed class CssBorderRadiusProperty : CssShorthandProperty
{
private static readonly IValueConverter<Tuple<ICssValue, ICssValue>> Converter = Converters.WithOrder(Converters.LengthOrPercentConverter.Periodic().Atomic().Val()
.Required(), Converters.LengthOrPercentConverter.Periodic().Atomic().Val()
.StartsWithDelimiter()
.Option());
internal CssBorderRadiusProperty(CssStyleDeclaration rule)
: base(PropertyNames.BorderRadius, rule, PropertyFlags.Animatable)
{
}
protected override bool IsValid(ICssValue value)
{
return Converter.TryConvert(value, delegate(Tuple<ICssValue, ICssValue> m) {
Get<CssBorderTopLeftRadiusProperty>().TrySetValue(Extract(m, 0));
Get<CssBorderTopRightRadiusProperty>().TrySetValue(Extract(m, 1));
Get<CssBorderBottomRightRadiusProperty>().TrySetValue(Extract(m, 2));
Get<CssBorderBottomLeftRadiusProperty>().TrySetValue(Extract(m, 3));
});
}
internal override string SerializeValue(IEnumerable<CssProperty> properties)
{
CssBorderTopLeftRadiusProperty cssBorderTopLeftRadiusProperty = properties.OfType<CssBorderTopLeftRadiusProperty>().FirstOrDefault();
CssBorderTopRightRadiusProperty cssBorderTopRightRadiusProperty = properties.OfType<CssBorderTopRightRadiusProperty>().FirstOrDefault();
CssBorderBottomRightRadiusProperty cssBorderBottomRightRadiusProperty = properties.OfType<CssBorderBottomRightRadiusProperty>().FirstOrDefault();
CssBorderBottomLeftRadiusProperty cssBorderBottomLeftRadiusProperty = properties.OfType<CssBorderBottomLeftRadiusProperty>().FirstOrDefault();
if (cssBorderTopLeftRadiusProperty == null || cssBorderTopRightRadiusProperty == null || cssBorderBottomRightRadiusProperty == null || cssBorderBottomLeftRadiusProperty == null)
return string.Empty;
if (!cssBorderTopLeftRadiusProperty.HasValue || !cssBorderTopRightRadiusProperty.HasValue || !cssBorderBottomRightRadiusProperty.HasValue || !cssBorderBottomLeftRadiusProperty.HasValue)
return string.Empty;
return CssShorthandProperty.SerializePeriodic(cssBorderTopLeftRadiusProperty, cssBorderTopRightRadiusProperty, cssBorderBottomRightRadiusProperty, cssBorderBottomLeftRadiusProperty);
}
private static ICssValue Extract(Tuple<ICssValue, ICssValue> src, int index)
{
ICssValue cssValue = src.Item1;
ICssValue cssValue2 = src.Item2;
CssValueList cssValueList = cssValue as CssValueList;
CssValueList cssValueList2 = cssValue2 as CssValueList;
if (cssValueList != null)
cssValue = Find(cssValueList, index);
if (cssValue2 == null)
return cssValue;
CssValueList obj = new CssValueList {
cssValue
};
if (cssValueList2 != null)
cssValue2 = Find(cssValueList2, index);
obj.Add(cssValue2);
return obj;
}
private static ICssValue Find(CssValueList list, int index)
{
if (index < list.Length)
return list[index];
if (index == 3 && 1 < list.Length)
return list[1];
return list[0];
}
}
}