Skip to content

feat(layout,paint): implement border-collapse - #439

Merged
tannevaled merged 1 commit into
mainfrom
bordercollapse-support
Nov 15, 2026
Merged

tannevaled merged 1 commit into
mainfrom
bordercollapse-support

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Implements border-collapse.

Closes #438.

Wikipedia's .wikitable class (used 88 times on, e.g., "List of countries by population") sets an identical border on both the <table> element and every cell:

.wikitable{border:1px solid #a2a9b1;border-collapse:collapse}
.wikitable>tr>th,.wikitable>tr>td{border:1px solid #a2a9b1;padding:0.2em 0.4em}

Under this engine's previously always-separate model, the table's own border box painted as an extra stroke outside the outermost cells' own border — roughly doubling the visible perimeter thickness versus a real browser's single merged collapsed line. A prior survey had concluded border-collapse was "a likely genuine no-op," but that was based on pkg.go.dev's rule, which sets no border at all on the <table> element, so there was nothing to double against there. Wikitable's case is different and genuinely visible.

  • css.Style.BorderCollapse bool, parsed from border-collapse: collapse|separate, inherited per spec alongside BorderSpacingH/V.
  • layout.table forces border-spacing to 0 when collapsed, regardless of what's declared (CSS 2.1: spacing has no effect once collapsed).
  • A new Box.SuppressOwnBorder, set on a collapsed table's own box once it has at least one real cell, read by paint's generic border step.
  • Deliberately scoped to the table-vs-outermost-cell conflict only (always preferring the cell) — not the full CSS 2.1 border-conflict-resolution algorithm across cell/row/row-group/column/column-group, which has no confirmed trigger yet.
  • FIDELITY.md updated (new round entry, corrected the Known-gaps bullet).

Test plan

  • css/parse_test.go: TestApplyBorderCollapse (mirrors TestApplyBorderSpacing's own shape: initial value, explicit set, invalid value no-op, default inheritance, explicit inherit).
  • layout/bordercollapse_test.go: border-spacing forced to 0 when collapsed; SuppressOwnBorder set only once a real cell exists (never on an empty table, never under separate).
  • paint/paint_test.go: TestPaintTableSuppressesOwnBorderWhenCollapsed — the actual pixel-level defect. The corner pixel only the table's own border stroke reaches is red under separate, white under collapse, while the cell's own border pixel stays red either way.
  • Git-stash-confirmed: reverting the implementation while keeping the tests fails to COMPILE (BorderCollapse/SuppressOwnBorder undefined).
  • go build/go vet/gofmt -l/go test ./.../govulncheck ./... clean.
  • css 99.5%, layout 100.0%, paint 100.0% coverage (all at their floors).
  • The combined webengine_nojs webengine_nonet webengine_fontsext build-tag lane builds and vets clean.

🤖 Generated with Claude Code

Wikipedia's .wikitable class (used 88 times on, e.g., "List of
countries by population") sets an identical border on both the
<table> and every cell; under this engine's always-separate model
the table's own border painted as an extra stroke outside the
outermost cells', roughly doubling the visible perimeter versus a
real browser's merged collapsed line.

Adds css.Style.BorderCollapse (parsed, inherited) and
Box.SuppressOwnBorder, set by layout.table once a collapsed table
has a real cell and read by paint's generic border step. Scoped to
the table-vs-outermost-cell conflict only, not the full CSS 2.1
border-conflict-resolution algorithm.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@tannevaled
tannevaled merged commit 4aa59e6 into main Nov 15, 2026
13 checks passed
@tannevaled
tannevaled deleted the bordercollapse-support branch November 15, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

layout: border-collapse is not implemented

1 participant