about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/layout/engine.nim10
-rw-r--r--test/layout/table-colwidth-overconstrained-too-small.color.expected2
-rw-r--r--test/layout/table-colwidth-overconstrained-too-small.html6
3 files changed, 16 insertions, 2 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 4fe4d5ce..28235c82 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1951,7 +1951,7 @@ proc calcUnspecifiedColIndices(ctx: var TableContext; W: var LayoutUnit;
       weight += w
       inc j
     else:
-      if specifiedRatio < 1:
+      if specifiedRatio != 1:
         col.width *= specifiedRatio
         col.reflow = true
       W -= col.width
@@ -1976,14 +1976,20 @@ proc redistributeWidth(ctx: var TableContext) =
   W -= ctx.cols.len * ctx.inlineSpacing * 2
   var weight = 0f64
   var totalSpecified: LayoutUnit = 0
+  var hasUnspecified = false
   for col in ctx.cols:
     if col.wspecified:
       totalSpecified += col.width
     else:
+      hasUnspecified = true
       # Hack: reserve the minimum space needed for unspecified columns,
       # like other browsers do.
       totalSpecified += col.minwidth
-  let specifiedRatio = if totalSpecified != 0: W / totalSpecified else: 1
+  var specifiedRatio = if totalSpecified != 0: W / totalSpecified else: 1
+  if specifiedRatio > 1 and hasUnspecified:
+    # Only grow specified columns if no unspecified column exists to take the
+    # rest of the space.
+    specifiedRatio = 1
   var avail = ctx.calcUnspecifiedColIndices(W, weight, specifiedRatio)
   var redo = true
   while redo and avail.len > 0 and weight != 0:
diff --git a/test/layout/table-colwidth-overconstrained-too-small.color.expected b/test/layout/table-colwidth-overconstrained-too-small.color.expected
new file mode 100644
index 00000000..483d97aa
--- /dev/null
+++ b/test/layout/table-colwidth-overconstrained-too-small.color.expected
@@ -0,0 +1,2 @@
+ e                                      h?                                     
+
diff --git a/test/layout/table-colwidth-overconstrained-too-small.html b/test/layout/table-colwidth-overconstrained-too-small.html
new file mode 100644
index 00000000..5d2bbb5b
--- /dev/null
+++ b/test/layout/table-colwidth-overconstrained-too-small.html
@@ -0,0 +1,6 @@
+<table width=100%>
+<tr>
+<td width=25% bgcolor=red>e
+<td width=25% bgcolor=green>h?
+</tr>
+</table>