about summary refs log tree commit diff stats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-19 21:27:30 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-19 21:27:30 +0100
commitf2a492417295ed60443a956b4baf9ac16862442a (patch)
tree76cd2e4094741f170742f6de5c1e6a8582d5ab1a /src/layout
parentf93f67cdd0f34409f88b1507252055ca4c5fb9bc (diff)
downloadchawan-f2a492417295ed60443a956b4baf9ac16862442a.tar.gz
Make sure :root is always block
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/box.nim1
-rw-r--r--src/layout/engine.nim16
2 files changed, 11 insertions, 6 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index acbacd52..c92db003 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -83,4 +83,3 @@ type
   InlineBlockBox* = ref object of BlockBox
     ictx*: InlineContext
   ListItemBox* = ref object of CSSBox
-
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index afd66c72..d881924b 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -759,6 +759,13 @@ proc getBox(specified: CSSSpecifiedValues): CSSBox =
   result.t = specified{"display"}
   result.specified = specified
 
+# Returns a block box, disregarding the specified value
+proc getBlockBox(specified: CSSSpecifiedValues): BlockBox =
+  new(result)
+  result.t = DISPLAY_BLOCK
+  result.specified = specified.copyProperties()
+  result.specified{"display"} = DISPLAY_BLOCK
+
 proc getTextBox(box: CSSBox): InlineBox =
   new(result)
   result.inlinelayout = true
@@ -767,6 +774,7 @@ proc getTextBox(box: CSSBox): InlineBox =
 
 proc getPseudoBox(specified: CSSSpecifiedValues): CSSBox =
   let box = getBox(specified)
+
   if box == nil:
     return nil
   box.inlinelayout = true
@@ -776,9 +784,7 @@ proc getPseudoBox(specified: CSSSpecifiedValues): CSSBox =
     box.children.add(content)
   return box
 
-proc generateBox(elem: Element): CSSBox =
-  let box = getBox(elem.css)
-
+proc generateBox(elem: Element, box = getBox(elem.css)): CSSBox =
   if box == nil:
     return nil
 
@@ -829,9 +835,9 @@ proc generateBox(elem: Element): CSSBox =
   return box
 
 proc generateBoxes(document: Document): BlockBox =
-  let box = document.root.generateBox()
+  let box = document.root.generateBox(getBlockBox(document.root.css))
   assert box != nil
-  assert box.t == DISPLAY_BLOCK #TODO this shouldn't be enforced by the ua stylesheet
+  assert box.t == DISPLAY_BLOCK
 
   return BlockBox(box)