From 352c2819ae7c8cd56d4f77954cfad9be45745f34 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 19 Jan 2022 21:38:49 +0100 Subject: Re-implement list items --- src/layout/box.nim | 2 +- src/layout/engine.nim | 20 ++++++++++++++++++-- 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) -- cgit 1.4.1-2-gfad0