CssBorderProperty
sealed class CssBorderProperty : CssShorthandProperty, ICssBorderProperty, ICssProperty, ICssBorderWidthProperty, ICssBorderStyleProperty, ICssBorderColorProperty
More information available at:
https://developer.mozilla.org/en-US/docs/Web/CSS/border
using AngleSharp.Css;
using AngleSharp.Extensions;
using System;
using System.Collections.Generic;
namespace AngleSharp.Dom.Css
{
internal sealed class CssBorderProperty : CssShorthandProperty, ICssBorderProperty, ICssProperty, ICssBorderWidthProperty, ICssBorderStyleProperty, ICssBorderColorProperty
{
internal static readonly IValueConverter<Tuple<ICssValue, ICssValue, ICssValue>> Converter = Converters.WithAny(CssBorderPartWidthProperty.Converter.Val().Option(CssValue.Initial), CssBorderPartStyleProperty.Converter.Val().Option(CssValue.Initial), CssBorderPartColorProperty.Converter.Val().Option(CssValue.Initial));
private readonly CssBorderTopColorProperty _topColor;
private readonly CssBorderTopStyleProperty _topStyle;
private readonly CssBorderTopWidthProperty _topWidth;
private readonly CssBorderRightColorProperty _rightColor;
private readonly CssBorderRightStyleProperty _rightStyle;
private readonly CssBorderRightWidthProperty _rightWidth;
private readonly CssBorderBottomColorProperty _bottomColor;
private readonly CssBorderBottomStyleProperty _bottomStyle;
private readonly CssBorderBottomWidthProperty _bottomWidth;
private readonly CssBorderLeftColorProperty _leftColor;
private readonly CssBorderLeftStyleProperty _leftStyle;
private readonly CssBorderLeftWidthProperty _leftWidth;
public Length Width => _leftWidth.Width;
public Color Color => _leftColor.Color;
public LineStyle Style => _leftStyle.Style;
internal CssBorderProperty(CssStyleDeclaration rule)
: base(PropertyNames.Border, rule, PropertyFlags.Animatable)
{
_topColor = Get<CssBorderTopColorProperty>();
_topStyle = Get<CssBorderTopStyleProperty>();
_topWidth = Get<CssBorderTopWidthProperty>();
_rightColor = Get<CssBorderRightColorProperty>();
_rightStyle = Get<CssBorderRightStyleProperty>();
_rightWidth = Get<CssBorderRightWidthProperty>();
_bottomColor = Get<CssBorderBottomColorProperty>();
_bottomStyle = Get<CssBorderBottomStyleProperty>();
_bottomWidth = Get<CssBorderBottomWidthProperty>();
_leftColor = Get<CssBorderLeftColorProperty>();
_leftStyle = Get<CssBorderLeftStyleProperty>();
_leftWidth = Get<CssBorderLeftWidthProperty>();
}
protected override bool IsValid(ICssValue value)
{
return Converter.TryConvert(value, delegate(Tuple<ICssValue, ICssValue, ICssValue> m) {
_topWidth.TrySetValue(m.Item1);
_topStyle.TrySetValue(m.Item2);
_topColor.TrySetValue(m.Item3);
_leftWidth.TrySetValue(m.Item1);
_leftStyle.TrySetValue(m.Item2);
_leftColor.TrySetValue(m.Item3);
_rightWidth.TrySetValue(m.Item1);
_rightStyle.TrySetValue(m.Item2);
_rightColor.TrySetValue(m.Item3);
_bottomWidth.TrySetValue(m.Item1);
_bottomStyle.TrySetValue(m.Item2);
_bottomColor.TrySetValue(m.Item3);
});
}
internal override string SerializeValue(IEnumerable<CssProperty> properties)
{
if (!IsComplete(properties))
return string.Empty;
List<string> list = new List<string>();
string text = _leftWidth.SerializeValue();
string text2 = _leftStyle.SerializeValue();
string text3 = _leftColor.SerializeValue();
if (text == _topWidth.SerializeValue() && text == _bottomWidth.SerializeValue() && text == _rightWidth.SerializeValue())
list.Add(text);
if (text2 == _topWidth.SerializeValue() && text2 == _bottomWidth.SerializeValue() && text2 == _rightWidth.SerializeValue())
list.Add(text2);
if (text3 == _topWidth.SerializeValue() && text3 == _bottomWidth.SerializeValue() && text3 == _rightWidth.SerializeValue())
list.Add(text3);
return string.Join(" ", list);
}
}
}