aboutsummaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-07 19:27:16 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-07 20:18:47 +0100
commitd57ef74a78ba32e8187d74c1975e7a4181af36c0 (patch)
treef29a16e1d0c7e600f438862bc37f925acfc3eb45 /src/server
parentebdb900ebc843e93dec4846e2f2434bf18ad8613 (diff)
downloadchawan-d57ef74a78ba32e8187d74c1975e7a4181af36c0.tar.gz
layout: unify BlockBox and InlineBox, refactor building
* normalize flow baseline computation * fix various margin collapsing bugs * eliminate inlineStack * eliminate push* * derive BlockBox and InlineBox from CSSBox This removes a pointer from BlockBox, and adds a pointer to both BlockBox and InlineBox (type field). A net loss, but it makes the code more manageable. Plus, inline groups now need one less allocation, so overall it's not that bad.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/buffer.nim38
1 files changed, 15 insertions, 23 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 5cc68245..01b288cf 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -663,32 +663,24 @@ type GotoAnchorResult* = object
y*: int
focus*: ReadLineResult
-proc findAnchor(box: BlockBox; anchor: Element): Offset
-
-proc findAnchor(box: InlineBox; anchor: Element): Offset =
- if box.t == ibtBox:
- let off = box.box.findAnchor(anchor)
- if off.y >= 0:
- return off
- elif box.t == ibtParent:
- for child in box.children:
+proc findAnchor(box: CSSBox; anchor: Element): Offset =
+ if box of InlineBox:
+ let ibox = InlineBox(box)
+ if ibox.t == ibtBox:
+ let off = ibox.box.findAnchor(anchor)
+ if off.y >= 0:
+ return off
+ elif ibox.t == ibtParent:
+ for child in ibox.children:
+ let off = child.findAnchor(anchor)
+ if off.y >= 0:
+ return off
+ else:
+ for child in BlockBox(box).children:
let off = child.findAnchor(anchor)
if off.y >= 0:
return off
- if box.node == anchor:
- return box.render.offset
- return offset(-1, -1)
-
-proc findAnchor(box: BlockBox; anchor: Element): Offset =
- if box.inline != nil:
- let off = box.inline.findAnchor(anchor)
- if off.y >= 0:
- return off
- for child in box.children:
- let off = child.findAnchor(anchor)
- if off.y >= 0:
- return off
- if box.node == anchor:
+ if box.element == anchor:
return box.render.offset
return offset(-1, -1)