about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-03-03 22:07:20 +0100
committerbptato <nincsnevem662@gmail.com>2025-03-03 22:42:17 +0100
commitbd5ef49b64991607bde95e0c0a487b636d59ae42 (patch)
treef5a5c71fd0323db131eaffb2b63e349bd3383f97
parenta0b345318e08d73eaedfc9b1caeec5b78fc270e3 (diff)
downloadchawan-bd5ef49b64991607bde95e0c0a487b636d59ae42.tar.gz
layout: adjust table cell height to fill rows
Achieved by generating an anonymous flow root child for the contents and
positioning that.  (Not the cell contents directly - that wouldn't work
because of inline child boxes.)
-rw-r--r--src/css/csstree.nim5
-rw-r--r--src/css/layout.nim17
-rw-r--r--test/layout/table.color.expected6
3 files changed, 16 insertions, 12 deletions
diff --git a/src/css/csstree.nim b/src/css/csstree.nim
index 80d73758..79872920 100644
--- a/src/css/csstree.nim
+++ b/src/css/csstree.nim
@@ -263,6 +263,11 @@ proc getParent(frame: var TreeFrame; computed: CSSValues; display: CSSDisplay):
     if frame.computed{"list-style-position"} == ListStylePositionOutside and
         frame.children.len >= 2:
       return frame.children[1].anonChildren
+  of DisplayTableCell:
+    if frame.anonComputed == nil:
+      frame.anonComputed = frame.inheritFor(DisplayFlowRoot)
+      frame.children.add(initStyledAnon(frame.parent, frame.anonComputed))
+    return frame.children[^1].anonChildren
   elif display in DisplayInternalTable:
     return frame.addAnonTable(parentDisplay, display)
   else:
diff --git a/src/css/layout.nim b/src/css/layout.nim
index 7d94c138..f943d55e 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -2322,15 +2322,14 @@ proc preLayoutTableRow(pctx: var TableContext; row, parent: BlockBox;
   return ctx
 
 proc alignTableCell(cell: BlockBox; availableHeight, baseline: LUnit) =
-  case cell.computed{"vertical-align"}.keyword
-  of VerticalAlignTop:
-    cell.state.offset.y = 0
-  of VerticalAlignMiddle:
-    cell.state.offset.y = availableHeight div 2 - cell.state.size.h div 2
-  of VerticalAlignBottom:
-    cell.state.offset.y = availableHeight - cell.state.size.h
-  else:
-    cell.state.offset.y = baseline - cell.state.firstBaseline
+  let firstChild = BlockBox(cell.firstChild)
+  if firstChild != nil:
+    firstChild.state.offset.y = case cell.computed{"vertical-align"}.keyword
+    of VerticalAlignTop: 0.toLUnit()
+    of VerticalAlignMiddle: availableHeight div 2 - cell.state.size.h div 2
+    of VerticalAlignBottom: availableHeight - cell.state.size.h
+    else: baseline - cell.state.firstBaseline
+  cell.state.size.h = availableHeight
 
 proc layoutTableRow(tctx: TableContext; ctx: RowContext;
     parent, row: BlockBox) =
diff --git a/test/layout/table.color.expected b/test/layout/table.color.expected
index 532766bb..3864b50a 100644
--- a/test/layout/table.color.expected
+++ b/test/layout/table.color.expected
@@ -1,10 +1,10 @@
                                     caption
-                                     lorem ipsum dolor sit amet, consectetur   
+                                     lorem ipsum dolor sit amet, consectetur   
  one two                             adipiscing elit, sed do eiusmod tempor    
  three                               incididunt ut labore et dolore magna      
  four five                       c d aliqua いろはにほへとちりぬるをわかよたれ 
  six seven                           そつ one two three four five six seven    
  eight                               eight nine ten elevenn twelve thirteen    
-                                     fourteen sixteen seventeen eighteen       
-           internationalization      nineteen                                  
+                                     fourteen sixteen seventeen eighteen       
+           internationalization      nineteen                                  
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa