Skip to content

Commit 39544e9

Browse files
committed
Added resize declaration #61
1 parent 375f899 commit 39544e9

File tree

9 files changed

+164
-0
lines changed

9 files changed

+164
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace AngleSharp.Css.Tests.Declarations
2+
{
3+
using NUnit.Framework;
4+
using static CssConstructionFunctions;
5+
6+
[TestFixture]
7+
public class CssResizePropertyTests
8+
{
9+
[Test]
10+
public void CssResizeNoneLegal()
11+
{
12+
var snippet = "resize: none";
13+
var property = ParseDeclaration(snippet);
14+
Assert.AreEqual("resize", property.Name);
15+
Assert.IsFalse(property.IsImportant);
16+
Assert.IsFalse(property.IsAnimatable);
17+
Assert.IsFalse(property.IsInherited);
18+
Assert.IsTrue(property.HasValue);
19+
Assert.AreEqual("none", property.Value);
20+
}
21+
22+
[Test]
23+
public void CssResizeScaledownIllegal()
24+
{
25+
var snippet = "resize: scaledown";
26+
var property = ParseDeclaration(snippet);
27+
Assert.AreEqual("resize", property.Name);
28+
Assert.IsFalse(property.IsImportant);
29+
Assert.IsFalse(property.IsAnimatable);
30+
Assert.IsFalse(property.IsInherited);
31+
Assert.IsFalse(property.HasValue);
32+
}
33+
34+
[Test]
35+
public void CssResizeBothLegal()
36+
{
37+
var snippet = "resize : both";
38+
var property = ParseDeclaration(snippet);
39+
Assert.AreEqual("resize", property.Name);
40+
Assert.IsFalse(property.IsImportant);
41+
Assert.IsFalse(property.IsAnimatable);
42+
Assert.IsFalse(property.IsInherited);
43+
Assert.IsTrue(property.HasValue);
44+
Assert.AreEqual("both", property.Value);
45+
}
46+
47+
[Test]
48+
public void CssResizeHorizontalLegal()
49+
{
50+
var snippet = "resize : horizontal";
51+
var property = ParseDeclaration(snippet);
52+
Assert.AreEqual("resize", property.Name);
53+
Assert.IsFalse(property.IsImportant);
54+
Assert.IsFalse(property.IsAnimatable);
55+
Assert.IsFalse(property.IsInherited);
56+
Assert.IsTrue(property.HasValue);
57+
Assert.AreEqual("horizontal", property.Value);
58+
}
59+
60+
[Test]
61+
public void CssResizeVerticalLegal()
62+
{
63+
var snippet = "resize : vertical";
64+
var property = ParseDeclaration(snippet);
65+
Assert.AreEqual("resize", property.Name);
66+
Assert.IsFalse(property.IsImportant);
67+
Assert.IsFalse(property.IsAnimatable);
68+
Assert.IsFalse(property.IsInherited);
69+
Assert.IsTrue(property.HasValue);
70+
Assert.AreEqual("vertical", property.Value);
71+
}
72+
}
73+
}

src/AngleSharp.Css/Constants/CssKeywords.cs

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public static class CssKeywords
1212
/// </summary>
1313
public static readonly String Distribute = "distribute";
1414

15+
/// <summary>
16+
/// The horizontal keyword.
17+
/// </summary>
18+
public static readonly String Horizontal = "horizontal";
19+
20+
/// <summary>
21+
/// The vertical keyword.
22+
/// </summary>
23+
public static readonly String Vertical = "vertical";
24+
1525
/// <summary>
1626
/// The clip keyword.
1727
/// </summary>

src/AngleSharp.Css/Constants/InitialValues.cs

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ static class InitialValues
161161
public static readonly ICssValue RubyPositionDecl = new Constant<RubyPosition>(CssKeywords.Over, RubyPosition.Over);
162162
public static readonly ICssValue RubyOverhangDecl = new Constant<RubyOverhangMode>(CssKeywords.None, RubyOverhangMode.None);
163163
public static readonly ICssValue RubyAlignDecl = new Constant<RubyAlignment>(CssKeywords.SpaceAround, RubyAlignment.SpaceAround);
164+
public static readonly ICssValue ResizeDecl = new Constant<ResizeMode>(CssKeywords.None, ResizeMode.None);
164165
public static readonly ICssValue QuotesDecl = new Quote("«", "»");
165166
public static readonly ICssValue PointerEventsDecl = new Constant<PointerEvent>(CssKeywords.Auto, PointerEvent.Auto);
166167
public static readonly ICssValue ContentDecl = new Constant<Object>(CssKeywords.Normal, null);

src/AngleSharp.Css/Constants/Map.cs

+13
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,19 @@ static class Map
722722
{ CssKeywords.BreakWord, OverflowWrap.BreakWord },
723723
};
724724

725+
/// <summary>
726+
/// Contains the string-ResizeMode mapping.
727+
/// </summary>
728+
public static readonly Dictionary<String, ResizeMode> ResizeModes = new Dictionary<String, ResizeMode>(StringComparer.OrdinalIgnoreCase)
729+
{
730+
{ CssKeywords.None, ResizeMode.None },
731+
{ CssKeywords.Both, ResizeMode.Both },
732+
{ CssKeywords.Horizontal, ResizeMode.Horizontal },
733+
{ CssKeywords.Vertical, ResizeMode.Vertical },
734+
{ CssKeywords.Block, ResizeMode.Block },
735+
{ CssKeywords.Inline, ResizeMode.Inline },
736+
};
737+
725738
/// <summary>
726739
/// Contains the string-RubyAlignment mapping.
727740
/// </summary>

src/AngleSharp.Css/Constants/PropertyNames.cs

+5
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,11 @@ public static class PropertyNames
987987
/// </summary>
988988
public static readonly String Quotes = "quotes";
989989

990+
/// <summary>
991+
/// The resize declaration.
992+
/// </summary>
993+
public static readonly String Resize = "resize";
994+
990995
/// <summary>
991996
/// The right declaration.
992997
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace AngleSharp.Css.Declarations
2+
{
3+
using AngleSharp.Css.Dom;
4+
using System;
5+
using static ValueConverters;
6+
7+
static class ResizeDeclaration
8+
{
9+
public static String Name = PropertyNames.Resize;
10+
11+
public static IValueConverter Converter = ResizeConverter;
12+
13+
public static ICssValue InitialValue = InitialValues.ResizeDecl;
14+
15+
public static PropertyFlags Flags = PropertyFlags.None;
16+
}
17+
}

src/AngleSharp.Css/Dom/ResizeMode.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace AngleSharp.Css.Dom
2+
{
3+
/// <summary>
4+
/// The values for resize.
5+
/// </summary>
6+
public enum ResizeMode
7+
{
8+
/// <summary>
9+
/// The element offers no user-controllable method for resizing it.
10+
/// </summary>
11+
None,
12+
/// <summary>
13+
/// The element displays a mechanism for allowing the user to resize it, which may be resized both horizontally and vertically.
14+
/// </summary>
15+
Both,
16+
/// <summary>
17+
/// The element displays a mechanism for allowing the user to resize it in the horizontal direction.
18+
/// </summary>
19+
Horizontal,
20+
/// <summary>
21+
/// The element displays a mechanism for allowing the user to resize it in the vertical direction.
22+
/// </summary>
23+
Vertical,
24+
/// <summary>
25+
/// The element displays a mechanism for allowing the user to resize it in the block direction.
26+
/// </summary>
27+
Block,
28+
/// <summary>
29+
/// The element displays a mechanism for allowing the user to resize it in the inline direction.
30+
/// </summary>
31+
Inline,
32+
}
33+
}

src/AngleSharp.Css/Factories/DefaultDeclarationFactory.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,13 @@ public class DefaultDeclarationFactory : IDeclarationFactory
14051405
flags: BorderDeclaration.Flags,
14061406
longhands: BorderDeclaration.Longhands)
14071407
},
1408+
{
1409+
ResizeDeclaration.Name, new DeclarationInfo(
1410+
name: ResizeDeclaration.Name,
1411+
converter: ResizeDeclaration.Converter,
1412+
initialValue: ResizeDeclaration.InitialValue,
1413+
flags: ResizeDeclaration.Flags)
1414+
},
14081415
{
14091416
RubyAlignDeclaration.Name, new DeclarationInfo(
14101417
name: RubyAlignDeclaration.Name,

src/AngleSharp.Css/ValueConverters.cs

+5
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ static class ValueConverters
445445
/// </summary>
446446
public static readonly IValueConverter FontWeightConverter = Map.FontWeights.ToConverter();
447447

448+
/// <summary>
449+
/// Represents a converter for the ResizeMode enumeration.
450+
/// </summary>
451+
public static readonly IValueConverter ResizeConverter = Map.ResizeModes.ToConverter();
452+
448453
/// <summary>
449454
/// Represents a converter for the RubyAlignment enumeration.
450455
/// </summary>

0 commit comments

Comments
 (0)