about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-19 21:38:49 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-19 21:38:49 +0100
commit352c2819ae7c8cd56d4f77954cfad9be45745f34 (patch)
tree997451e557a60972fc942f5fa344969c951d20f9
parentf2a492417295ed60443a956b4baf9ac16862442a (diff)
downloadchawan-352c2819ae7c8cd56d4f77954cfad9be45745f34.tar.gz
Re-implement list items
-rw-r--r--src/layout/box.nim2
-rw-r--r--src/layout/engine.nim20
2 files changed, 19 insertions, 3 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index c92db003..404ab10c 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -82,4 +82,4 @@ type
     bctx*: BlockContext
   InlineBlockBox* = ref object of BlockBox
     ictx*: InlineContext
-  ListItemBox* = ref object of CSSBox
+  ListItemBox* = ref object of BlockBox
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index d881924b..1e72c294 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -725,6 +725,13 @@ proc alignBlocks(bctx: BlockContext, blocks: seq[CSSBox]) =
       alignBlock(child)
       bctx.height += child.bctx.height
       bctx.width = max(bctx.width, child.bctx.width)
+    of DISPLAY_LIST_ITEM:
+      let child = ListItemBox(child)
+      flush_group()
+      child.bctx = newBlockContext(bctx, child)
+      alignBlock(child)
+      bctx.height += child.bctx.height
+      bctx.width = max(bctx.width, child.bctx.width)
     of DISPLAY_INLINE:
       if child.inlinelayout:
         blockgroup.add(child)
@@ -768,9 +775,9 @@ proc getBlockBox(specified: CSSSpecifiedValues): BlockBox =
 
 proc getTextBox(box: CSSBox): InlineBox =
   new(result)
-  result.inlinelayout = true
-  result.specified = box.specified
   result.t = DISPLAY_INLINE
+  result.inlinelayout = true
+  result.specified = box.specified.inheritProperties()
 
 proc getPseudoBox(specified: CSSSpecifiedValues): CSSBox =
   let box = getBox(specified)
@@ -800,6 +807,15 @@ proc generateBox(elem: Element, box = getBox(elem.css)): CSSBox =
       box.inlinelayout = false
 
   box.inlinelayout = true
+
+  if box.t == DISPLAY_LIST_ITEM:
+    var ordinalvalue = 1
+    if elem.tagType == TAG_LI:
+      ordinalvalue = HTMLLIElement(elem).ordinalvalue
+    let marker = box.getTextBox()
+    marker.text.add(elem.css{"list-style-type"}.listMarker(ordinalvalue))
+    add_box(marker)
+
   let before = elem.pseudo[PSEUDO_BEFORE]
   if before != nil:
     let bbox = getPseudoBox(before)