CssBorderRadiusProperty
sealed class CssBorderRadiusProperty : CssShorthandProperty, ICssBorderRadiusProperty, ICssProperty, ICssBorderBottomLeftRadiusProperty, ICssBorderBottomRightRadiusProperty, ICssBorderTopLeftRadiusProperty, ICssBorderTopRightRadiusProperty
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;
namespace AngleSharp.Dom.Css
{
internal sealed class CssBorderRadiusProperty : CssShorthandProperty, ICssBorderRadiusProperty, ICssProperty, ICssBorderBottomLeftRadiusProperty, ICssBorderBottomRightRadiusProperty, ICssBorderTopLeftRadiusProperty, ICssBorderTopRightRadiusProperty
{
internal static readonly IValueConverter<Tuple<ICssValue, ICssValue>> Converter = Converters.WithOrder(CssBorderRadiusPartProperty.SingleConverter.Periodic().Atomic().Val()
.Required(), CssBorderRadiusPartProperty.SingleConverter.Periodic().Atomic().Val()
.StartsWithDelimiter()
.Option());
private readonly CssBorderTopLeftRadiusProperty _topLeft;
private readonly CssBorderTopRightRadiusProperty _topRight;
private readonly CssBorderBottomRightRadiusProperty _bottomRight;
private readonly CssBorderBottomLeftRadiusProperty _bottomLeft;
public Length HorizontalBottomLeft => _bottomLeft.HorizontalRadius;
public Length VerticalBottomLeft => _bottomLeft.VerticalRadius;
public Length HorizontalBottomRight => _bottomRight.HorizontalRadius;
public Length VerticalBottomRight => _bottomRight.VerticalRadius;
public Length HorizontalTopLeft => _topLeft.HorizontalRadius;
public Length VerticalTopLeft => _topLeft.VerticalRadius;
public Length HorizontalTopRight => _topRight.HorizontalRadius;
public Length VerticalTopRight => _topRight.VerticalRadius;
internal CssBorderRadiusProperty(CssStyleDeclaration rule)
: base(PropertyNames.BorderRadius, rule, PropertyFlags.Animatable)
{
_topLeft = Get<CssBorderTopLeftRadiusProperty>();
_topRight = Get<CssBorderTopRightRadiusProperty>();
_bottomRight = Get<CssBorderBottomRightRadiusProperty>();
_bottomLeft = Get<CssBorderBottomLeftRadiusProperty>();
}
protected override bool IsValid(ICssValue value)
{
return Converter.TryConvert(value, delegate(Tuple<ICssValue, ICssValue> m) {
_topLeft.TrySetValue(Extract(m, 0));
_topRight.TrySetValue(Extract(m, 1));
_bottomRight.TrySetValue(Extract(m, 2));
_bottomLeft.TrySetValue(Extract(m, 3));
});
}
internal override string SerializeValue(IEnumerable<CssProperty> properties)
{
if (!IsComplete(properties))
return string.Empty;
string text = CssShorthandProperty.SerializePeriodic(_topLeft.HorizontalRadius, _topRight.HorizontalRadius, _bottomRight.HorizontalRadius, _bottomLeft.HorizontalRadius);
if (_topLeft.IsCircle && _topRight.IsCircle && _bottomRight.IsCircle && _bottomLeft.IsCircle)
return text;
string str = CssShorthandProperty.SerializePeriodic(_topLeft.VerticalRadius, _topRight.VerticalRadius, _bottomRight.VerticalRadius, _bottomLeft.VerticalRadius);
return text + " / " + str;
}
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];
}
}
}