Skip to content

Commit 1033292

Browse files
committed
Optimized border parsing
1 parent 062d85e commit 1033292

21 files changed

+72
-125
lines changed

src/AngleSharp.Css.Tests/Declarations/CssBorderProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void CssBorderStyleWavyIllegal()
249249
{
250250
var snippet = "border-style: wavy";
251251
var property = ParseDeclaration(snippet);
252-
Assert.IsNull(property);
252+
Assert.IsFalse(property.HasValue);
253253
}
254254

255255
[Test]
@@ -437,7 +437,7 @@ public void CssBorderWidthZerosIllegal()
437437
{
438438
var snippet = "border-width: 0 0 0 0 0";
439439
var property = ParseDeclaration(snippet);
440-
Assert.IsNull(property);
440+
Assert.IsFalse(property.HasValue);
441441
}
442442

443443
[Test]

src/AngleSharp.Css.Tests/Styling/CssSheet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public void CssFontWithSlashAndContent()
573573
public void CssBackgroundWebkitGradientIsInvalid()
574574
{
575575
var background = ParseDeclaration("background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #FFA84C), color-stop(100%, #FF7B0D))");
576-
Assert.IsNull(background);
576+
Assert.IsFalse(background.HasValue);
577577
}
578578

579579
[Test]

src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public void RemovingPropertiesShouldNotYieldEmptyStyle_Issue14()
431431
[Test]
432432
public void RecombinationWorksWithBorder_Issue16()
433433
{
434-
var expected = "<button style=\"pointer-events: auto; border-width: 1px; border-style: solid; border-color: rgba(0, 0, 0, 1)\"></button>";
434+
var expected = "<button style=\"pointer-events: auto; border: 1px solid rgba(0, 0, 0, 1)\"></button>";
435435
var document = ParseDocument("");
436436
var element = document.CreateElement("button");
437437
element.GetStyle().SetPointerEvents("auto");

src/AngleSharp.Css/Declarations/BorderBottomColorDeclaration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static class BorderBottomColorDeclaration
1010

1111
public static String[] Shorthands = new[]
1212
{
13+
PropertyNames.Border,
1314
PropertyNames.BorderColor,
1415
PropertyNames.BorderBottom,
1516
};

src/AngleSharp.Css/Declarations/BorderBottomStyleDeclaration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static class BorderBottomStyleDeclaration
1010

1111
public static String[] Shorthands = new[]
1212
{
13+
PropertyNames.Border,
1314
PropertyNames.BorderStyle,
1415
PropertyNames.BorderBottom,
1516
};

src/AngleSharp.Css/Declarations/BorderBottomWidthDeclaration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static class BorderBottomWidthDeclaration
1010

1111
public static String[] Shorthands = new[]
1212
{
13+
PropertyNames.Border,
1314
PropertyNames.BorderWidth,
1415
PropertyNames.BorderBottom,
1516
};
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
namespace AngleSharp.Css.Declarations
22
{
3-
using AngleSharp.Css.Converters;
43
using AngleSharp.Css.Dom;
5-
using AngleSharp.Css.Values;
6-
using AngleSharp.Text;
74
using System;
8-
using System.Linq;
95
using static ValueConverters;
106

117
static class BorderColorDeclaration
@@ -17,7 +13,7 @@ static class BorderColorDeclaration
1713
PropertyNames.Border,
1814
};
1915

20-
public static IValueConverter Converter = new BorderColorAggregator();
16+
public static IValueConverter Converter = AggregatePeriodic(CurrentColorConverter);
2117

2218
public static ICssValue InitialValue = null;
2319

@@ -30,32 +26,5 @@ static class BorderColorDeclaration
3026
PropertyNames.BorderBottomColor,
3127
PropertyNames.BorderLeftColor,
3228
};
33-
34-
sealed class BorderColorAggregator : IValueAggregator, IValueConverter
35-
{
36-
private static readonly IValueConverter converter = CurrentColorConverter.Periodic();
37-
38-
public ICssValue Convert(StringSource source) => converter.Convert(source);
39-
40-
public ICssValue Merge(ICssValue[] values)
41-
{
42-
if (values[0] != null)
43-
{
44-
return new CssPeriodicValue(values);
45-
}
46-
47-
return null;
48-
}
49-
50-
public ICssValue[] Split(ICssValue value)
51-
{
52-
if (value is CssPeriodicValue periodic)
53-
{
54-
return periodic.ToArray();
55-
}
56-
57-
return null;
58-
}
59-
}
6029
}
6130
}

src/AngleSharp.Css/Declarations/BorderDeclaration.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,7 @@ sealed class BorderAggregator : IValueAggregator, IValueConverter
4141

4242
public ICssValue Convert(StringSource source) => converter.Convert(source);
4343

44-
public ICssValue Merge(ICssValue[] values)
45-
{
46-
if (values.Length == 3)
47-
{
48-
return new CssTupleValue(values);
49-
}
50-
51-
return null;
52-
}
44+
public ICssValue Merge(ICssValue[] values) => new CssTupleValue(values);
5345

5446
public ICssValue[] Split(ICssValue value)
5547
{

src/AngleSharp.Css/Declarations/BorderLeftColorDeclaration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static class BorderLeftColorDeclaration
1010

1111
public static String[] Shorthands = new[]
1212
{
13+
PropertyNames.Border,
1314
PropertyNames.BorderColor,
1415
PropertyNames.BorderLeft,
1516
};

src/AngleSharp.Css/Declarations/BorderLeftStyleDeclaration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static class BorderLeftStyleDeclaration
1010

1111
public static String[] Shorthands = new[]
1212
{
13+
PropertyNames.Border,
1314
PropertyNames.BorderStyle,
1415
PropertyNames.BorderLeft,
1516
};

0 commit comments

Comments
 (0)