Vixen
dd8b0a81
csharp
public sealed class GridAreaTemplate

CSS Grid §7.3's grid-template-areas: a rectangle of named cells.

Read the guide page for this →

Remarks

An area is a name and four lines, and the four lines are what the rest of grid reads. §7.3 says that an area named header makes four implicit named lines — header-start and header-end on both axes — so grid-area: header is shorthand for naming those four, and everything downstream of TryGetArea is ordinary line placement. That is why this type resolves to line indices and never to a position: §8 still does the placing.

⚠ The parser is the part with an external oracle, and it is the part that is easy to get plausibly wrong. web-platform-tests' css/css-grid/grid-definition/grid-support-grid-template-areas-001.html pins thirty accepted values with their canonical serialisation and sixteen refused ones, and several of the sixteen are values a hand-written parser accepts happily: "a b a" and "a b" "b a" are non-rectangular areas, and a row count that disagrees between two strings invalidates the whole declaration rather than the row. GridTemplateAreasTests is that file, case for case.

⚠ A run of full stops is one null cell, not one per stop. "..a" is two columns and "...header header...." is four. That is CSS Syntax's tokenisation showing through — the grammar is a sequence of <name> and <null-cell-token> productions rather than a per-character grid — and reading it per character gives a wider grid that lays out and is wrong, which no assertion about one item's position would necessarily catch.

⚠ A name is a run of CSS name code points, which is wider than an identifier. The oracle accepts 10, 1-st, -minus, ©copy_right and line¶ — all of which a <custom-ident> reading would refuse for starting with a digit or a hyphen-digit — and refuses 10%, USD$ and ,. So the test is CSS Syntax §4.2's name code point exactly: a letter, a digit, _, -, or anything outside ASCII.

Immutable, and compared by its canonical text. A template is written by a stylesheet on every restyle, so the store has to be able to answer "is this the same one?" without walking two grids; the serialisation is computed once in the constructor and is what Equals reads.

⚠ Named lines written into a track list — [main-start] 1fr [main-end] — are a different feature and are still not implemented. They have no oracle in either conformance corpus, exactly as this had none, and the WPT files that cover them (grid-placement-using-named-grid-lines-00*) are reftests whose geometry is not stated. This type covers the half that has an oracle.

Fields and properties (3)

  • public int Rows

    How many rows of the explicit grid the template names.

  • public int Columns

    How many columns of the explicit grid the template names.

  • public IReadOnlyList<string> Names

    The distinct area names, in the order they were first seen.

Methods (7)

  • public static bool TryParse(string value, out GridAreaTemplate? template, out string? refusal)

    Reads a grid-template-areas value.

  • public static bool IsAreaName(string value)

    Whether a placement value is spelled like a reference to a named area.

  • public string? NameAt(int row, int column)

    The area covering one cell, or for a null cell.

  • public bool TryGetArea(string name, out int rowStart, out int rowEnd, out int columnStart, out int columnEnd)

    The four lines an area's name stands for.

  • public override string ToString()

    The value as CSS serialises it: one quoted string per row, one space per cell.

  • public override bool Equals(object? obj)

    Determines whether the specified object is equal to the current object.

  • public override int GetHashCode()

    Serves as the default hash function.

Used by (5)

  • AreaTemplatePropertyVixen.Ui
  • GridTemplateAreasTestsVixen.Ui.Layout.Tests
  • LayoutTreeVixen.Ui.Layout
  • NamedPlacementPropertyVixen.Ui
  • TaffyStyleMapVixen.Ui.Layout.Tests