setUpChildBaselineForBFC method
void
setUpChildBaselineForBFC()
Implementation
void setUpChildBaselineForBFC() {
// Cache CSS baselines for non-IFC flow: use line metrics when overflow is visible.
final paddingTop = renderStyle.paddingTop.computedValue;
final borderTop = renderStyle.effectiveBorderTopWidth.computedValue;
final bool overflowVisible = renderStyle.effectiveOverflowX == CSSOverflowType.visible &&
renderStyle.effectiveOverflowY == CSSOverflowType.visible;
double? firstBaseline;
double? lastBaseline;
// Special handling for inline-block elements
if (renderStyle.display == CSSDisplay.inlineBlock && boxSize != null) {
// Search for in-flow descendants that expose a CSS baseline:
// - Prefer inline formatting contexts (line boxes) when present.
// - Otherwise, use flex/grid container baselines if available.
// If none exist anywhere inside, synthesize from the bottom margin edge.
double? descendantBaseline = _findDescendantBaseline();
if (descendantBaseline != null) {
firstBaseline = descendantBaseline;
lastBaseline = descendantBaseline;
} else {
final double marginBottom = renderStyle.marginBottom.computedValue;
firstBaseline = boxSize!.height + marginBottom;
lastBaseline = firstBaseline;
}
} else if (overflowVisible && _lineMetrics.isNotEmpty) {
if (_lineMetrics.first.baseline != null) {
firstBaseline = _lineMetrics.first.baseline! + paddingTop + borderTop;
}
double yOffset = 0;
for (int i = 0; i < _lineMetrics.length; i++) {
final line = _lineMetrics[i];
if (line.baseline != null) {
lastBaseline = yOffset + line.baseline! + paddingTop + borderTop;
}
if (i < _lineMetrics.length - 1) {
yOffset += line.crossAxisExtent;
}
}
} else if (boxSize != null) {
// No in-flow line boxes found: per CSS 2.1 §10.8.1, synthesize baseline from
// the bottom margin edge for block-level boxes.
final double marginBottom = renderStyle.marginBottom.computedValue;
firstBaseline = boxSize!.height + marginBottom;
lastBaseline = firstBaseline;
}
setCssBaselines(first: firstBaseline, last: lastBaseline);
}