aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-19 14:58:25 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-19 14:58:25 +0100
commit0c0aa01a19d5dfb86562650c200cdc8c4b216fa0 (patch)
tree1104eac59d46050b5e4a83b34d2f7a22d7261365 /src
parentc40820c1d5f579147643a9438ef0500052d28004 (diff)
downloadchawan-0c0aa01a19d5dfb86562650c200cdc8c4b216fa0.tar.gz
Re-implement pseudo elements
Diffstat (limited to 'src')
-rw-r--r--src/layout/box.nim2
-rw-r--r--src/layout/engine.nim44
2 files changed, 34 insertions, 12 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index c6ced854..74e97c97 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -79,7 +79,7 @@ type
bottom*: int
InlineBox* = ref object of CSSBox
- text*: seq[Text]
+ text*: seq[string]
ictx*: InlineContext
newline*: bool
BlockBox* = ref object of CSSBox
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 6e2449b2..417d5d2c 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -682,7 +682,7 @@ proc alignInline(pctx: BlockContext, box: InlineBox) =
box.ictx.flushLine()
for text in box.text:
assert box.children.len == 0
- box.ictx.renderText(text.data, pctx.compwidth, box.specified)
+ box.ictx.renderText(text, pctx.compwidth, box.specified)
for child in box.children:
let child = InlineBox(child)
@@ -764,6 +764,17 @@ proc getTextBox(box: CSSBox): InlineBox =
result.inlinelayout = true
result.specified = box.specified
+proc getPseudoBox(specified: CSSSpecifiedValues): CSSBox =
+ let box = getBox(specified)
+ if box == nil:
+ return nil
+ box.inlinelayout = true
+ if specified{"content"}.len > 0:
+ let content = getTextBox(box)
+ content.text.add($specified{"content"})
+ box.children.add(content)
+ return box
+
proc generateBox(elem: Element): CSSBox =
let box = getBox(elem.css)
@@ -776,33 +787,44 @@ proc generateBox(elem: Element): CSSBox =
box.children.add(ibox)
ibox = nil
+ template add_box(child: CSSBox) =
+ box.children.add(child)
+ if child.t != BOX_INLINE or not child.inlinelayout:
+ box.inlinelayout = false
+
box.inlinelayout = true
+ let before = elem.pseudo[PSEUDO_BEFORE]
+ if before != nil:
+ let bbox = getPseudoBox(before)
+ if bbox != nil:
+ add_box(bbox)
+
for child in elem.childNodes:
case child.nodeType
of ELEMENT_NODE:
let elem = Element(child)
if elem.tagType == TAG_BR:
add_ibox()
- if box.t == BOX_INLINE:
- let box = InlineBox(box)
- box.newline = true
- else:
- ibox = box.getTextBox()
- ibox.newline = true
+ ibox = box.getTextBox()
+ ibox.newline = true
let cbox = generateBox(elem)
if cbox != nil:
add_ibox()
- box.children.add(cbox)
- if cbox.t != BOX_INLINE or not cbox.inlinelayout:
- box.inlinelayout = false
+ add_box(cbox)
of TEXT_NODE:
if ibox == nil:
ibox = box.getTextBox()
- ibox.text.add(Text(child))
+ ibox.text.add(Text(child).data)
else: discard
add_ibox()
+ let after = elem.pseudo[PSEUDO_AFTER]
+ if after != nil:
+ let abox = getPseudoBox(after)
+ if abox != nil:
+ add_box(abox)
+
return box
proc generateBoxes(document: Document): BlockBox =