Skip to content

Commit e8dab26

Browse files
committed
Refactored value model names
1 parent 64df5cf commit e8dab26

File tree

93 files changed

+1548
-561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1548
-561
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released on tbd.
44

55
- Updated to use AngleSharp 1.0 (#150)
66
- Updated media parsing to media L4 spec (#133)
7+
- Updated naming of CSS values (e.g., `Color` to `CssColorValue`)
78
- Fixed issue when updating shorthands with invalid values (#129)
89
- Fixed issue with appended EOF character in `CssText` (#123)
910
- Fixed missing semicolon in `@page` rule (#135)
@@ -15,6 +16,7 @@ Released on tbd.
1516
- Fixed `GetInnerText` multi-line / text node behavior (#155) @Seyden
1617
- Fixed computation of relative (`em`) values to absolute (`px`) for `Length` (#136)
1718
- Added further compactification of CSS tuples (#89, #93)
19+
- Added new value types `CssPercentageValue`, `CssNumberValue`, and `CssIntegerValue`
1820
- Added support for CSS nesting in style rules (#148)
1921
- Added resolution of CSS variable names (#62)
2022
- Added support for 8-digit hex color codes (#132)

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ AngleSharp.Css contains code written by (in order of first pull request / commit
1717
* [Fraaankes](https://github.com/Fraaankes)
1818
* [Eric Mutta](https://github.com/ericmutta)
1919
* [Seyden](https://github.com/Seyden)
20+
* [Dave Dunkin](https://github.com/ddunkin)
2021

2122
Without these awesome people AngleSharp.Css could not exist. Thanks to everyone for your contributions! :beers:
2223

src/AngleSharp.Css.Tests/Values/Gradient.cs

Lines changed: 64 additions & 64 deletions
Large diffs are not rendered by default.

src/AngleSharp.Css.Tests/Values/UnitConversion.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ public void LengthToVminCorrectValue()
204204
public void AngleParseCorrectDegValue()
205205
{
206206
var s = "1.35e2deg";
207-
var v = default(Angle);
208-
var r = Angle.TryParse(s, out v);
207+
var v = default(CssAngleValue);
208+
var r = CssAngleValue.TryParse(s, out v);
209209
Assert.IsTrue(r);
210210
Assert.AreEqual(135f, v.Value);
211-
Assert.AreEqual(Angle.Unit.Deg, v.Type);
211+
Assert.AreEqual(CssAngleValue.Unit.Deg, v.Type);
212212
}
213213

214214
[Test]
@@ -248,8 +248,8 @@ public void TimeParseCorrectSecondsValue()
248248
public void AngleParseIncorrectValue()
249249
{
250250
var s = "123.deg";
251-
var v = default(Angle);
252-
var r = Angle.TryParse(s, out v);
251+
var v = default(CssAngleValue);
252+
var r = CssAngleValue.TryParse(s, out v);
253253
Assert.IsFalse(r);
254254
}
255255
}

src/AngleSharp.Css/Constants/Map.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ static class Map
2626
/// <summary>
2727
/// Contains the string-Angle mapping for linear-gradients.s
2828
/// </summary>
29-
public static readonly Dictionary<String, Angle> GradientAngles = new(StringComparer.OrdinalIgnoreCase)
30-
{
31-
{ CssKeywords.Left, new Angle(270.0, Angle.Unit.Deg) },
32-
{ CssKeywords.Top, new Angle(0.0, Angle.Unit.Deg) },
33-
{ CssKeywords.Right, new Angle(90.0, Angle.Unit.Deg) },
34-
{ CssKeywords.Bottom, new Angle(180.0, Angle.Unit.Deg) },
35-
{ CssKeywords.LeftTop, new Angle(315.0, Angle.Unit.Deg) },
36-
{ CssKeywords.LeftBottom, new Angle(225.0, Angle.Unit.Deg) },
37-
{ CssKeywords.RightTop, new Angle(45.0, Angle.Unit.Deg) },
38-
{ CssKeywords.RightBottom, new Angle(135.0, Angle.Unit.Deg) },
29+
public static readonly Dictionary<String, CssAngleValue> GradientAngles = new(StringComparer.OrdinalIgnoreCase)
30+
{
31+
{ CssKeywords.Left, new CssAngleValue(270.0, CssAngleValue.Unit.Deg) },
32+
{ CssKeywords.Top, new CssAngleValue(0.0, CssAngleValue.Unit.Deg) },
33+
{ CssKeywords.Right, new CssAngleValue(90.0, CssAngleValue.Unit.Deg) },
34+
{ CssKeywords.Bottom, new CssAngleValue(180.0, CssAngleValue.Unit.Deg) },
35+
{ CssKeywords.LeftTop, new CssAngleValue(315.0, CssAngleValue.Unit.Deg) },
36+
{ CssKeywords.LeftBottom, new CssAngleValue(225.0, CssAngleValue.Unit.Deg) },
37+
{ CssKeywords.RightTop, new CssAngleValue(45.0, CssAngleValue.Unit.Deg) },
38+
{ CssKeywords.RightBottom, new CssAngleValue(135.0, CssAngleValue.Unit.Deg) },
3939
};
4040

4141
/// <summary>

src/AngleSharp.Css/Declarations/ContentDeclaration.cs

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public ICssValue Convert(StringSource source)
108108
return null;
109109
}
110110

111-
private sealed class ContentValue : ICssValue
111+
private sealed class ContentValue : ICssValue, IEquatable<ContentValue>
112112
{
113-
private ICssValue[] _modes;
113+
private readonly ICssValue[] _modes;
114114

115115
public ContentValue(ICssValue[] modes)
116116
{
@@ -124,6 +124,30 @@ public ICssValue Compute(ICssComputeContext context)
124124
var modes = _modes.Select(mode => mode.Compute(context)).ToArray();
125125
return new ContentValue(modes);
126126
}
127+
public Boolean Equals(ContentValue other)
128+
{
129+
var l = _modes.Length;
130+
131+
if (l == other._modes.Length)
132+
{
133+
for (var i = 0; i < l; i++)
134+
{
135+
var a = _modes[i];
136+
var b = other._modes[i];
137+
138+
if (!a.Equals(b))
139+
{
140+
return false;
141+
}
142+
}
143+
144+
return true;
145+
}
146+
147+
return false;
148+
}
149+
150+
Boolean IEquatable<ICssValue>.Equals(ICssValue other) => other is ContentValue value && Equals(value);
127151
}
128152

129153
private abstract class ContentMode : ICssValue
@@ -134,10 +158,9 @@ private abstract class ContentMode : ICssValue
134158

135159
public abstract String GetCssText();
136160

137-
ICssValue ICssValue.Compute(ICssComputeContext context)
138-
{
139-
return this;
140-
}
161+
ICssValue ICssValue.Compute(ICssComputeContext context) => this;
162+
163+
public virtual Boolean Equals(ICssValue other) => Object.ReferenceEquals(this, other);
141164
}
142165

143166
/// <summary>
@@ -209,6 +232,16 @@ public TextContentMode(String text)
209232
public override String GetCssText() => _text.CssString();
210233

211234
public override String Stringify(IElement element) => _text;
235+
236+
public override Boolean Equals(ICssValue other)
237+
{
238+
if (other is TextContentMode o)
239+
{
240+
return _text.Equals(o._text);
241+
}
242+
243+
return false;
244+
}
212245
}
213246

214247
/// <summary>
@@ -228,6 +261,16 @@ public CounterContentMode(CssCounterDefinitionValue counter)
228261
public override String GetCssText() => _counter.CssText;
229262

230263
public override String Stringify(IElement element) => String.Empty;
264+
265+
public override Boolean Equals(ICssValue other)
266+
{
267+
if (other is CounterContentMode o)
268+
{
269+
return _counter.Equals(o._counter);
270+
}
271+
272+
return false;
273+
}
231274
}
232275

233276
/// <summary>
@@ -246,6 +289,16 @@ public AttributeContentMode(String attribute)
246289
public override String GetCssText() => FunctionNames.Attr.CssFunction(_attribute);
247290

248291
public override String Stringify(IElement element) => element.GetAttribute(_attribute) ?? String.Empty;
292+
293+
public override Boolean Equals(ICssValue other)
294+
{
295+
if (other is AttributeContentMode o)
296+
{
297+
return _attribute.Equals(o._attribute);
298+
}
299+
300+
return false;
301+
}
249302
}
250303

251304
/// <summary>
@@ -265,6 +318,16 @@ public UrlContentMode(CssUrlValue url)
265318
public override String GetCssText() => _url.CssText;
266319

267320
public override String Stringify(IElement element) => String.Empty;
321+
322+
public override Boolean Equals(ICssValue other)
323+
{
324+
if (other is UrlContentMode o)
325+
{
326+
return _url.Equals(o._url);
327+
}
328+
329+
return false;
330+
}
268331
}
269332
}
270333
}

src/AngleSharp.Css/Declarations/CursorDeclaration.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ sealed class CursorValueConverter : IValueConverter
2121
{
2222
public ICssValue Convert(StringSource source)
2323
{
24-
var cursor = default(ICssValue);
2524
var definitions = new List<ICssValue>();
2625

2726
while (!source.IsDone)
2827
{
2928
var imageSource = source.ParseImageSource();
30-
var c = source.SkipSpacesAndComments();
29+
source.SkipSpacesAndComments();
3130

3231
if (imageSource != null)
3332
{
3433
var x = source.ParseNumber();
35-
c = source.SkipSpacesAndComments();
34+
source.SkipSpacesAndComments();
3635
var y = source.ParseNumber();
37-
c = source.SkipSpacesAndComments();
36+
var c = source.SkipSpacesAndComments();
3837

3938
if (x.HasValue != y.HasValue || c != Symbols.Comma)
4039
break;
@@ -44,16 +43,14 @@ public ICssValue Convert(StringSource source)
4443

4544
if (x.HasValue)
4645
{
47-
var xp = new CssLengthValue(x.Value, CssLengthValue.Unit.None);
48-
var yp = new CssLengthValue(y.Value, CssLengthValue.Unit.None);
49-
position = new CssPoint2D(xp, yp);
46+
position = new CssPoint2D(x, y);
5047
}
5148

5249
definitions.Add(new CssCustomCursorValue(imageSource, position));
5350
}
5451
else
5552
{
56-
cursor = source.ParseConstant(Map.SystemCursors);
53+
var cursor = source.ParseConstant(Map.SystemCursors);
5754

5855
if (cursor != null)
5956
{

src/AngleSharp.Css/Dom/ICssValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace AngleSharp.Css.Dom
22
{
3-
using System;
43
using AngleSharp.Css.Values;
4+
using System;
55

66
/// <summary>
77
/// Represents a value of a CSS property.
88
/// </summary>
9-
public interface ICssValue
9+
public interface ICssValue : IEquatable<ICssValue>
1010
{
1111
/// <summary>
1212
/// The text representation of the value.

0 commit comments

Comments
 (0)