Skip to content

Commit fc9e2a9

Browse files
committed
Add in support for "box-sizing" property
Support for the box-sizing property was missing, resulting in nothing being present in the parsed stylesheet object model when fed CSS which was setting this. For example, parsing something like ".test { box-sizing: border-box; }" would result in ".test { }"
1 parent a0f9914 commit fc9e2a9

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Xunit;
2+
3+
namespace ExCSS.Tests.PropertyTests
4+
{
5+
public class BoxSizingPropertyTests : CssConstructionFunctions
6+
{
7+
[Fact]
8+
public void BoxSizingContentBoxLegal()
9+
{
10+
var snippet = "box-sizing: content-box";
11+
var property = ParseDeclaration(snippet);
12+
Assert.Equal("box-sizing", property.Name);
13+
Assert.False(property.IsImportant);
14+
Assert.IsType<BoxSizingProperty>(property);
15+
var concrete = (BoxSizingProperty)property;
16+
Assert.False(concrete.IsInherited);
17+
Assert.True(concrete.HasValue);
18+
Assert.Equal("content-box", concrete.Value);
19+
}
20+
21+
[Fact]
22+
public void BoxSizingBorderBoxLegal()
23+
{
24+
var snippet = "box-sizing: border-box";
25+
var property = ParseDeclaration(snippet);
26+
Assert.Equal("box-sizing", property.Name);
27+
Assert.False(property.IsImportant);
28+
Assert.IsType<BoxSizingProperty>(property);
29+
var concrete = (BoxSizingProperty)property;
30+
Assert.False(concrete.IsInherited);
31+
Assert.True(concrete.HasValue);
32+
Assert.Equal("border-box", concrete.Value);
33+
}
34+
}
35+
}

src/ExCSS/Factories/PropertyFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private PropertyFactory()
5858

5959
AddLonghand(PropertyNames.BorderSpacing, () => new BorderSpacingProperty());
6060
AddLonghand(PropertyNames.BorderCollapse, () => new BorderCollapseProperty());
61+
AddLonghand(PropertyNames.BoxSizing, () => new BoxSizingProperty());
6162
AddLonghand(PropertyNames.BoxShadow, () => new BoxShadowProperty(), true);
6263
AddLonghand(PropertyNames.BoxDecorationBreak, () => new BoxDecorationBreak());
6364
AddLonghand(PropertyNames.BreakAfter, () => new BreakAfterProperty());

src/ExCSS/Model/Converters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ public static readonly IValueConverter
373373
public static readonly IValueConverter BoxDecorationConverter = Toggle(Keywords.Clone, Keywords.Slice);
374374
public static readonly IValueConverter ColumnSpanConverter = Toggle(Keywords.All, Keywords.None);
375375
public static readonly IValueConverter ColumnFillConverter = Toggle(Keywords.Balance, Keywords.Auto);
376+
public static readonly IValueConverter BoxSizingConverter = Toggle(Keywords.ContentBox, Keywords.BorderBox);
376377

377378
#endregion
378379

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace ExCSS
2+
{
3+
internal class BoxSizingProperty : Property
4+
{
5+
private static readonly IValueConverter StyleConverter = Converters.BoxSizingConverter.OrDefault(Keywords.ContentBox);
6+
7+
public BoxSizingProperty()
8+
: base(PropertyNames.BoxSizing, PropertyFlags.None)
9+
{ }
10+
11+
internal override IValueConverter Converter => StyleConverter;
12+
}
13+
}

0 commit comments

Comments
 (0)