Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified demo_app/test/goldens/inline/margin/auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo_app/test/table/aspect_ratio_img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed demo_app/test/table/height_1px.png
Binary file not shown.
Binary file modified demo_app/test/table/row_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo_app/test/table/sizing_height_1px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo_app/test/table/sizing_width_100_percent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo_app/test/table/text_align_center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo_app/test/table/width_in_percent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo_app/test/table/width_in_px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions packages/core/lib/src/core_widget_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
case kCssMinHeight:
case kCssMinWidth:
case kCssWidth:
StyleSizing.registerSizingOp(this, tree);
StyleSizing.registerSizingOp(tree);

case kCssLineHeight:
final value = style.value;
Expand Down Expand Up @@ -1114,13 +1114,13 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {

/// Parses display inline style.
void parseStyleDisplay(BuildTree tree, String? value) {
StyleSizing.maybeRegisterChildOp(this, tree);
StyleSizing.maybeRegisterChildOp(tree);

switch (value) {
case kCssDisplayFlex:
tree.register(_styleDisplayFlex ??= StyleDisplayFlex(this).buildOp);
case kCssDisplayBlock:
StyleSizing.registerBlockOp(this, tree);
StyleSizing.registerBlockOp(tree);
case kCssDisplayInlineBlock:
tree.register(displayInlineBlock);
case kCssDisplayNone:
Expand Down
18 changes: 4 additions & 14 deletions packages/core/lib/src/internal/ops/style_sizing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class StyleSizing {

static final _elementTree = Expando<BuildTree>();
static final _treeIsBlock = Expando<bool>();
static final _skipBuilding = Expando<bool>();

static void maybeRegisterChildOp(WidgetFactory wf, BuildTree tree) {
static void maybeRegisterChildOp(BuildTree tree) {
final parentElement = tree.element.parent;
if (parentElement == null || _elementTree[parentElement] == null) {
return;
Expand All @@ -27,7 +26,7 @@ class StyleSizing {
tree.register(StyleSizing().childOp);
}

static void registerBlockOp(WidgetFactory wf, BuildTree tree) {
static void registerBlockOp(BuildTree tree) {
_elementTree[tree.element] = tree;
_treeIsBlock[tree] = true;

Expand All @@ -37,7 +36,7 @@ class StyleSizing {
..register(instance.sizingOp);
}

static void registerSizingOp(WidgetFactory wf, BuildTree tree) {
static void registerSizingOp(BuildTree tree) {
_elementTree[tree.element] = tree;
tree.register(StyleSizing().sizingOp);
}
Expand Down Expand Up @@ -99,7 +98,7 @@ class StyleSizing {
}

static Widget _sizingBlock(BuildTree tree, WidgetPlaceholder placeholder) {
if (_skipBuilding[tree] == true || placeholder.isEmpty) {
if (placeholder.isEmpty) {
return placeholder;
}

Expand All @@ -115,10 +114,6 @@ class StyleSizing {
}

static void _sizingInline(BuildTree tree) {
if (_skipBuilding[tree] == true) {
return;
}

final input = tree.sizingInput;
if (input == null) {
return;
Expand All @@ -145,11 +140,6 @@ class StyleSizing {
.wrapWith((c, w) => _build(c, w, input, tree.inheritanceResolvers));
}

static void skip(BuildTree tree) {
assert(_skipBuilding[tree] != true, 'Built ${tree.element} already');
_skipBuilding[tree] = true;
}

static Widget _build(
BuildContext context,
Widget child,
Expand Down
25 changes: 9 additions & 16 deletions packages/core/lib/src/internal/ops/tag_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,12 @@ class TagTable {

final layoutBuilder = LayoutBuilder(
builder: (context, bc) {
// wrap the table in a builder to obtain the layout constraints early
// in order to calculate a conservative width
// the whole thing becomes scrollable when columns are too wide
final maxWidth = bc.maxWidth;

final resolved = tableTree.inheritanceResolvers.resolve(context);
Widget built = ValignBaselineContainer(
child: HtmlTable(
border: border.getBorder(resolved),
borderCollapse: borderCollapse == kCssBorderCollapseCollapse,
borderSpacing: borderSpacing?.getValue(resolved) ?? 0.0,
maxWidth: maxWidth,
textDirection: resolved.directionOrLtr,
children: List.from(
data.builders
Expand All @@ -107,7 +101,14 @@ class TagTable {
),
);

if (maxWidth.isFinite) {
// provide hints to size the columns properly
built = CssSizingHint(
maxWidth: bc.maxWidth,
minWidth: bc.minWidth,
child: built,
);

if (bc.maxWidth.isFinite) {
built = wf.buildHorizontalScrollView(tableTree, built) ?? built;
}

Expand Down Expand Up @@ -203,7 +204,6 @@ class TagTable {
columnStart: columnStart,
rowSpan: rowSpan,
rowStart: rowStart,
width: cell.width?.getSizing(resolved),
child: child,
);
});
Expand Down Expand Up @@ -326,7 +326,6 @@ class TagTable {

static BuildTree _onTableParsed(BuildTree tableTree) {
StyleBorder.skip(tableTree);
StyleSizing.skip(tableTree);
return tableTree;
}
}
Expand Down Expand Up @@ -379,17 +378,13 @@ class _TagTableRow {
}

void _onCellRenderedBlock(BuildTree cellTree, Widget block) {
final widthValue = cellTree.getStyle(kCssWidth)?.value;
final width = widthValue != null ? tryParseCssLength(widthValue) : null;

final attributes = cellTree.element.attributes;
cells.add(
_TagTableDataCell(
cellTree,
child: block,
columnSpan: tryParseIntFromMap(attributes, kAttributeColspan) ?? 1,
rowSpan: tryParseIntFromMap(attributes, kAttributeRowspan) ?? 1,
width: width,
),
);
}
Expand All @@ -407,7 +402,7 @@ class _TagTableRow {

cellTree.register(_cellOp);
StyleBorder.skip(cellTree);
StyleSizing.skip(cellTree);
StyleSizing.registerBlockOp(cellTree);
}

static StylesMap _cssVerticalAlignFromAttribute(dom.Element element) {
Expand Down Expand Up @@ -484,13 +479,11 @@ class _TagTableDataCell {
final int columnSpan;
final BuildTree tree;
final int rowSpan;
final CssLength? width;

const _TagTableDataCell(
this.tree, {
required this.child,
required this.columnSpan,
required this.rowSpan,
this.width,
});
}
19 changes: 15 additions & 4 deletions packages/core/lib/src/widgets/css_sizing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class CssSizing extends SingleChildRenderObjectWidget {
return _RenderCssSizing(
maxHeight: maxHeight ?? hint?.maxHeight.cssSizingValue,
maxWidth: maxWidth ?? hint?.maxWidth.cssSizingValue,
minHeight: minHeight,
minWidth: minWidth,
minHeight: minHeight ?? hint?.minHeight.cssSizingValue,
minWidth: minWidth ?? hint?.minWidth.cssSizingValue,
preferredAxis: preferredAxis,
preferredHeight: preferredHeight,
preferredWidth: preferredWidth,
Expand Down Expand Up @@ -137,17 +137,24 @@ class CssSizing extends SingleChildRenderObjectWidget {
class CssSizingHint extends InheritedWidget {
final double? maxHeight;
final double? maxWidth;
final double? minHeight;
final double? minWidth;

const CssSizingHint({
required super.child,
super.key,
this.maxHeight,
this.maxWidth,
this.minHeight,
this.minWidth,
});

@override
bool updateShouldNotify(CssSizingHint oldWidget) =>
maxHeight != oldWidget.maxHeight || maxWidth != oldWidget.maxWidth;
maxHeight != oldWidget.maxHeight ||
maxWidth != oldWidget.maxWidth ||
minHeight != oldWidget.minHeight ||
minWidth != oldWidget.minWidth;
}

class _RenderCssSizing extends RenderProxyBox {
Expand Down Expand Up @@ -273,13 +280,17 @@ class _RenderCssSizing extends RenderProxyBox {
)
: null;

final cc = BoxConstraints(
var cc = BoxConstraints(
maxHeight: stableChildSize?.height ?? preferredHeight ?? maxHeight,
maxWidth: stableChildSize?.width ?? preferredWidth ?? maxWidth,
minHeight: stableChildSize?.height ?? preferredHeight ?? minHeight,
minWidth: stableChildSize?.width ?? preferredWidth ?? minWidth,
);

// after everything... if the incoming is tight then we must follow it
cc = c.hasTightWidth ? cc.tighten(width: c.maxWidth) : cc;
cc = c.hasTightHeight ? cc.tighten(height: c.maxHeight) : cc;

return cc;
}

Expand Down
Loading