CssBorderWidthProperty
More information available at:
https://developer.mozilla.org/en-US/docs/Web/CSS/border-width
using AngleSharp.Css;
using AngleSharp.Extensions;
using System;
using System.Collections.Generic;
namespace AngleSharp.Dom.Css
{
internal sealed class CssBorderWidthProperty : CssShorthandProperty, ICssBorderWidthsProperty, ICssProperty
{
internal static readonly IValueConverter<Tuple<ICssValue, ICssValue, ICssValue, ICssValue>> Converter = CssBorderPartWidthProperty.Converter.Val().Periodic();
private readonly CssBorderTopWidthProperty _top;
private readonly CssBorderRightWidthProperty _right;
private readonly CssBorderBottomWidthProperty _bottom;
private readonly CssBorderLeftWidthProperty _left;
public Length Top => _top.Width;
public Length Right => _right.Width;
public Length Bottom => _bottom.Width;
public Length Left => _left.Width;
internal CssBorderWidthProperty(CssStyleDeclaration rule)
: base(PropertyNames.BorderWidth, rule, PropertyFlags.Animatable)
{
_top = Get<CssBorderTopWidthProperty>();
_right = Get<CssBorderRightWidthProperty>();
_bottom = Get<CssBorderBottomWidthProperty>();
_left = Get<CssBorderLeftWidthProperty>();
}
protected override bool IsValid(ICssValue value)
{
return Converter.TryConvert(value, delegate(Tuple<ICssValue, ICssValue, ICssValue, ICssValue> m) {
_top.TrySetValue(m.Item1);
_right.TrySetValue(m.Item2);
_bottom.TrySetValue(m.Item3);
_left.TrySetValue(m.Item4);
});
}
internal override string SerializeValue(IEnumerable<CssProperty> properties)
{
if (!IsComplete(properties))
return string.Empty;
return CssShorthandProperty.SerializePeriodic(_top, _right, _bottom, _left);
}
}
}