Skip to content

Commit 50181ec

Browse files
jhaygood86eXpl0it3r
authored andcommitted
CSS engine: sync CSS Grid properties and factory registrations
The grid property set from PeachPDF v0.9.6 (upstream 4319393 and the follow-up grid work in fb7a769, 12ec795, 253de51): grid-template-columns/-rows/-areas, the grid-column/-row/-area placement shorthands, grid-auto-flow/-columns/-rows, the `grid` and `grid-template` mega-shorthands, and justify-items/-self plus the place-items/-content/-self shorthands. grid-template-columns/-rows carry a parsed GridTemplate through the cascade via CssProperty<T>, rather than only their authored text. The `grid` and `grid-template` shorthands are registered through AddLogicalShorthand so the serializer will not try to reconstruct them from their longhands - their multi-slash and areas grammar is not worth rebuilding and doing so could change existing output. Parse-and-cascade only: HTML-Renderer has no grid layout engine, so `display: grid` still lays out as a block and these declarations are ignored at the box boundary. Wiring them up needs a layout engine and is a separate piece of work.
1 parent 072886e commit 50181ec

21 files changed

Lines changed: 379 additions & 0 deletions

‎Source/HtmlRenderer/Core/CssEngine/Factories/PropertyFactory.cs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,47 @@ private PropertyFactory()
366366
_fontsBuilder.Add(PropertyNames.Src, () => new SrcProperty());
367367
_fontsBuilder.Add(PropertyNames.UnicodeRange, () => new UnicodeRangeProperty());
368368

369+
// CSS Grid Layout Level 1/2. The engine parses and validates the full grid property set;
370+
// the renderer has no grid layout engine yet, so these cascade and are then ignored at the
371+
// box boundary.
372+
AddLonghand(PropertyNames.GridTemplateColumns, () => new GridTemplateColumnsProperty());
373+
AddLonghand(PropertyNames.GridTemplateRows, () => new GridTemplateRowsProperty());
374+
AddLonghand(PropertyNames.GridTemplateAreas, () => new GridTemplateAreasProperty());
375+
AddLonghand(PropertyNames.GridColumnStart, () => new GridColumnStartProperty());
376+
AddLonghand(PropertyNames.GridColumnEnd, () => new GridColumnEndProperty());
377+
AddLonghand(PropertyNames.GridRowStart, () => new GridRowStartProperty());
378+
AddLonghand(PropertyNames.GridRowEnd, () => new GridRowEndProperty());
379+
380+
AddShorthand(PropertyNames.GridColumn, () => new GridColumnProperty(),
381+
PropertyNames.GridColumnStart, PropertyNames.GridColumnEnd);
382+
AddShorthand(PropertyNames.GridRow, () => new GridRowProperty(),
383+
PropertyNames.GridRowStart, PropertyNames.GridRowEnd);
384+
AddShorthand(PropertyNames.GridArea, () => new GridAreaProperty(),
385+
PropertyNames.GridRowStart, PropertyNames.GridColumnStart,
386+
PropertyNames.GridRowEnd, PropertyNames.GridColumnEnd);
387+
388+
AddLonghand(PropertyNames.GridAutoFlow, () => new GridAutoFlowProperty());
389+
AddLonghand(PropertyNames.GridAutoColumns, () => new GridAutoColumnsProperty());
390+
AddLonghand(PropertyNames.GridAutoRows, () => new GridAutoRowsProperty());
391+
392+
// The grid mega-shorthands parse/expand like any other, but are excluded from serialization
393+
// reconstruction (via _logicalShorthands) - reconstructing a `grid`/`grid-template` from its
394+
// longhands is not worth the complexity and could change existing output.
395+
AddLogicalShorthand(PropertyNames.GridTemplate, () => new GridTemplateProperty(),
396+
PropertyNames.GridTemplateRows, PropertyNames.GridTemplateColumns, PropertyNames.GridTemplateAreas);
397+
AddLogicalShorthand(PropertyNames.Grid, () => new GridProperty(),
398+
PropertyNames.GridTemplateRows, PropertyNames.GridTemplateColumns, PropertyNames.GridTemplateAreas,
399+
PropertyNames.GridAutoFlow, PropertyNames.GridAutoRows, PropertyNames.GridAutoColumns);
400+
401+
AddLonghand(PropertyNames.JustifyItems, () => new JustifyItemsProperty());
402+
AddLonghand(PropertyNames.JustifySelf, () => new JustifySelfProperty());
403+
AddShorthand(PropertyNames.PlaceItems, () => new PlaceItemsProperty(),
404+
PropertyNames.AlignItems, PropertyNames.JustifyItems);
405+
AddShorthand(PropertyNames.PlaceContent, () => new PlaceContentProperty(),
406+
PropertyNames.AlignContent, PropertyNames.JustifyContent);
407+
AddShorthand(PropertyNames.PlaceSelf, () => new PlaceSelfProperty(),
408+
PropertyNames.AlignSelf, PropertyNames.JustifySelf);
409+
369410
// CSS Logical Properties and Values Level 1. Layout here is always LTR / horizontal-tb,
370411
// so each logical property is registered to produce/export the existing physical
371412
// longhands (block-start = top, block-end = bottom, inline-start = left,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>
4+
/// The <c>grid-area</c> shorthand (CSS Grid §8.3.1): <c>&lt;grid-line&gt; [ / &lt;grid-line&gt; ]{0,3}</c>,
5+
/// expanding to <c>grid-row-start</c> / <c>grid-column-start</c> / <c>grid-row-end</c> /
6+
/// <c>grid-column-end</c>. The single named-area form is out of v1 scope.
7+
/// </summary>
8+
internal sealed class GridAreaProperty : ShorthandProperty
9+
{
10+
private static readonly IValueConverter StyleConverter = Converters.GridAreaConverter.OrGlobalValue();
11+
12+
internal GridAreaProperty()
13+
: base(PropertyNames.GridArea)
14+
{
15+
}
16+
17+
internal override IValueConverter Converter => StyleConverter;
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>The <c>grid-auto-columns</c> property (CSS Grid §7.6): the size of implicitly-created columns.</summary>
4+
internal sealed class GridAutoColumnsProperty : Property
5+
{
6+
private static readonly IValueConverter StyleConverter = new GridAutoTracksValueConverter().OrDefault();
7+
8+
internal GridAutoColumnsProperty()
9+
: base(PropertyNames.GridAutoColumns)
10+
{
11+
}
12+
13+
internal override IValueConverter Converter => StyleConverter;
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>The <c>grid-auto-flow</c> property (CSS Grid §7.7): the auto-placement direction and packing.</summary>
4+
internal sealed class GridAutoFlowProperty : Property
5+
{
6+
private static readonly IValueConverter StyleConverter = new GridAutoFlowValueConverter().OrDefault();
7+
8+
internal GridAutoFlowProperty()
9+
: base(PropertyNames.GridAutoFlow)
10+
{
11+
}
12+
13+
internal override IValueConverter Converter => StyleConverter;
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>The <c>grid-auto-rows</c> property (CSS Grid §7.6): the size of implicitly-created rows.</summary>
4+
internal sealed class GridAutoRowsProperty : Property
5+
{
6+
private static readonly IValueConverter StyleConverter = new GridAutoTracksValueConverter().OrDefault();
7+
8+
internal GridAutoRowsProperty()
9+
: base(PropertyNames.GridAutoRows)
10+
{
11+
}
12+
13+
internal override IValueConverter Converter => StyleConverter;
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>
4+
/// The <c>grid-column-end</c> longhand (CSS Grid §8.3), one edge of a
5+
/// grid item's placement. Validated by the shared <see cref="GridLineGrammar"/>.
6+
/// </summary>
7+
internal sealed class GridColumnEndProperty : Property
8+
{
9+
private static readonly IValueConverter StyleConverter = Converters.GridLineConverter.OrDefault();
10+
11+
internal GridColumnEndProperty()
12+
: base(PropertyNames.GridColumnEnd)
13+
{
14+
}
15+
16+
internal override IValueConverter Converter => StyleConverter;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>
4+
/// The <c>grid-column</c> shorthand (CSS Grid §8.3.1): <c>&lt;grid-line&gt; [ / &lt;grid-line&gt; ]?</c>,
5+
/// expanding to <c>grid-column-start</c> / <c>grid-column-end</c>.
6+
/// </summary>
7+
internal sealed class GridColumnProperty : ShorthandProperty
8+
{
9+
private static readonly IValueConverter StyleConverter = Converters.GridColumnConverter.OrGlobalValue();
10+
11+
internal GridColumnProperty()
12+
: base(PropertyNames.GridColumn)
13+
{
14+
}
15+
16+
internal override IValueConverter Converter => StyleConverter;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>
4+
/// The <c>grid-column-start</c> longhand (CSS Grid §8.3), one edge of a
5+
/// grid item's placement. Validated by the shared <see cref="GridLineGrammar"/>.
6+
/// </summary>
7+
internal sealed class GridColumnStartProperty : Property
8+
{
9+
private static readonly IValueConverter StyleConverter = Converters.GridLineConverter.OrDefault();
10+
11+
internal GridColumnStartProperty()
12+
: base(PropertyNames.GridColumnStart)
13+
{
14+
}
15+
16+
internal override IValueConverter Converter => StyleConverter;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>
4+
/// The <c>grid</c> shorthand (CSS Grid §7.8): expands to the three <c>grid-template-*</c> longhands plus
5+
/// <c>grid-auto-flow</c> / <c>grid-auto-rows</c> / <c>grid-auto-columns</c>.
6+
/// </summary>
7+
internal sealed class GridProperty : ShorthandProperty
8+
{
9+
private static readonly IValueConverter StyleConverter = Converters.GridConverter.OrGlobalValue();
10+
11+
internal GridProperty()
12+
: base(PropertyNames.Grid)
13+
{
14+
}
15+
16+
internal override IValueConverter Converter => StyleConverter;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace TheArtOfDev.HtmlRenderer.Core.CssEngine
2+
{
3+
/// <summary>
4+
/// The <c>grid-row-end</c> longhand (CSS Grid §8.3), one edge of a
5+
/// grid item's placement. Validated by the shared <see cref="GridLineGrammar"/>.
6+
/// </summary>
7+
internal sealed class GridRowEndProperty : Property
8+
{
9+
private static readonly IValueConverter StyleConverter = Converters.GridLineConverter.OrDefault();
10+
11+
internal GridRowEndProperty()
12+
: base(PropertyNames.GridRowEnd)
13+
{
14+
}
15+
16+
internal override IValueConverter Converter => StyleConverter;
17+
}
18+
}

0 commit comments

Comments
 (0)