Skip to content

Commit 20e091d

Browse files
committed
Improved background serialization
1 parent 0ee93d6 commit 20e091d

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static class BackgroundDeclaration
3030
PropertyNames.BackgroundColor,
3131
};
3232

33-
sealed class BackgroundValueConverter : IValueConverter
33+
sealed class BackgroundAggregator : IValueAggregator, IValueConverter
3434
{
3535
public ICssValue Convert(StringSource source)
3636
{
@@ -113,7 +113,7 @@ public ICssValue Convert(StringSource source)
113113
}
114114
}
115115
while (pos != source.Index);
116-
116+
117117
layers.Add(new CssBackgroundLayerValue(
118118
image,
119119
position,
@@ -126,13 +126,6 @@ public ICssValue Convert(StringSource source)
126126

127127
return new CssBackgroundValue(new CssListValue(layers.OfType<ICssValue>().ToArray()), color);
128128
}
129-
}
130-
131-
sealed class BackgroundAggregator : IValueAggregator, IValueConverter
132-
{
133-
private static readonly IValueConverter converter = new BackgroundValueConverter();
134-
135-
public ICssValue Convert(StringSource source) => converter.Convert(source);
136129

137130
public ICssValue Merge(ICssValue[] values)
138131
{
@@ -144,7 +137,6 @@ public ICssValue Merge(ICssValue[] values)
144137
var origin = GetList(values[5]);
145138
var clip = GetList(values[6]);
146139
var color = values[7];
147-
148140
var layers = CreateLayers(image, attachment, clip, position, origin, repeat, size);
149141

150142
if (color != null || layers != null)

src/AngleSharp.Css/Declarations/BackgroundPositionDeclaration.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public ICssValue Merge(ICssValue[] values)
5252

5353
return new CssListValue(points);
5454
}
55-
else if (values[0] is CssInitialValue && values[1] is CssInitialValue)
56-
{
57-
return new CssInitialValue(InitialValues.BackgroundPositionDecl);
58-
}
5955

6056
return null;
6157
}
@@ -73,14 +69,6 @@ public ICssValue[] Split(ICssValue value)
7369
new CssListValue(y),
7470
};
7571
}
76-
else if (value is CssInitialValue)
77-
{
78-
return new ICssValue[]
79-
{
80-
new CssInitialValue(InitialValues.BackgroundPositionXDecl),
81-
new CssInitialValue(InitialValues.BackgroundPositionYDecl),
82-
};
83-
}
8472

8573
return null;
8674
}

src/AngleSharp.Css/Declarations/BackgroundRepeatDeclaration.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public ICssValue Merge(ICssValue[] values)
5252

5353
return new CssListValue(repeats);
5454
}
55-
else if (values[0] is CssInitialValue && values[1] is CssInitialValue)
56-
{
57-
return new CssInitialValue(InitialValues.BackgroundRepeatDecl);
58-
}
5955

6056
return null;
6157
}
@@ -73,14 +69,6 @@ public ICssValue[] Split(ICssValue value)
7369
new CssListValue(v),
7470
};
7571
}
76-
else if (value is CssInitialValue)
77-
{
78-
return new ICssValue[]
79-
{
80-
new CssInitialValue(InitialValues.BackgroundRepeatHorizontalDecl),
81-
new CssInitialValue(InitialValues.BackgroundRepeatVerticalDecl),
82-
};
83-
}
8472

8573
return null;
8674
}

src/AngleSharp.Css/Extensions/DeclarationInfoExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ public static ICssValue[] Seperate(this DeclarationInfo info, IDeclarationFactor
4747
if (value is ICssRawValue || value is CssChildValue)
4848
{
4949
var child = new CssChildValue(value);
50-
return Enumerable.Repeat(child, longhands.Length).ToArray();
50+
return Enumerable
51+
.Repeat(child, longhands.Length)
52+
.ToArray();
5153
}
5254
else if (value is CssInitialValue)
5355
{
54-
return longhands.Select(name => factory.Create(name)?.InitialValue).ToArray();
56+
return longhands
57+
.Select(name => new CssInitialValue(factory.Create(name)?.InitialValue))
58+
.OfType<ICssValue>()
59+
.ToArray();
5560
}
5661

5762
return info.Aggregator?.Split(value);

0 commit comments

Comments
 (0)