CssBorderImageProperty
More information available at:
https://developer.mozilla.org/en-US/docs/Web/CSS/border-image
using AngleSharp.Css;
using AngleSharp.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AngleSharp.Dom.Css
{
internal sealed class CssBorderImageProperty : CssShorthandProperty
{
private static readonly IValueConverter<Tuple<CssValue, Tuple<CssValue, CssValue, CssValue>, CssValue>> Converter = Converters.WithAny(Converters.OptionalImageSourceConverter.Val().Option(), Converters.WithOrder(CssBorderImageSliceProperty.Converter.Val().Option(), CssBorderImageWidthProperty.Converter.Val().StartsWithDelimiter().Option(), CssBorderImageOutsetProperty.Converter.Val().StartsWithDelimiter().Option()), CssBorderImageRepeatProperty.Converter.Val().Option());
internal CssBorderImageProperty(CssStyleDeclaration rule)
: base(PropertyNames.BorderImage, rule, PropertyFlags.None)
{
}
protected override bool IsValid(CssValue value)
{
return Converter.TryConvert(value, delegate(Tuple<CssValue, Tuple<CssValue, CssValue, CssValue>, CssValue> m) {
Get<CssBorderImageSourceProperty>().TrySetValue(m.Item1);
Get<CssBorderImageSliceProperty>().TrySetValue(m.Item2.Item1);
Get<CssBorderImageWidthProperty>().TrySetValue(m.Item2.Item2);
Get<CssBorderImageOutsetProperty>().TrySetValue(m.Item2.Item3);
Get<CssBorderImageRepeatProperty>().TrySetValue(m.Item3);
});
}
internal override string SerializeValue(IEnumerable<CssProperty> properties)
{
CssBorderImageSourceProperty cssBorderImageSourceProperty = properties.OfType<CssBorderImageSourceProperty>().FirstOrDefault();
CssBorderImageSliceProperty cssBorderImageSliceProperty = properties.OfType<CssBorderImageSliceProperty>().FirstOrDefault();
CssBorderImageWidthProperty cssBorderImageWidthProperty = properties.OfType<CssBorderImageWidthProperty>().FirstOrDefault();
CssBorderImageOutsetProperty cssBorderImageOutsetProperty = properties.OfType<CssBorderImageOutsetProperty>().FirstOrDefault();
CssBorderImageRepeatProperty cssBorderImageRepeatProperty = properties.OfType<CssBorderImageRepeatProperty>().FirstOrDefault();
if (cssBorderImageSourceProperty == null || cssBorderImageSliceProperty == null || cssBorderImageWidthProperty == null || cssBorderImageOutsetProperty == null || cssBorderImageRepeatProperty == null)
return string.Empty;
List<string> list = new List<string>();
list.Add(cssBorderImageSourceProperty.SerializeValue());
if (cssBorderImageSliceProperty.HasValue)
list.Add(cssBorderImageSliceProperty.SerializeValue());
if (cssBorderImageWidthProperty.HasValue || cssBorderImageOutsetProperty.HasValue) {
list.Add("/");
if (cssBorderImageWidthProperty.HasValue)
list.Add(cssBorderImageWidthProperty.SerializeValue());
if (cssBorderImageOutsetProperty.HasValue) {
list.Add("/");
list.Add(cssBorderImageOutsetProperty.SerializeValue());
}
}
if (cssBorderImageRepeatProperty.HasValue)
list.Add(cssBorderImageRepeatProperty.SerializeValue());
return string.Format(" ", new object[1] {
list
});
}
}
}