about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/layout/box.nim2
-rw-r--r--src/layout/engine.nim22
-rw-r--r--src/render/renderdocument.nim6
-rw-r--r--src/server/buffer.nim8
4 files changed, 16 insertions, 22 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index f7a36255..86accfa9 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -30,7 +30,7 @@ type
     u*: LayoutUnit
 
   Viewport* = ref object
-    window*: WindowAttributes
+    attrs*: WindowAttributes
     positioned*: seq[BlockBox]
 
   BoxBuilder* = ref object of RootObj
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index d7e28a52..6f4852b5 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -13,13 +13,13 @@ import utils/twtstr
 # Build phase
 func px(l: CSSLength, viewport: Viewport, p: LayoutUnit = 0):
     LayoutUnit {.inline.} =
-  return px(l, viewport.window, p)
+  return px(l, viewport.attrs, p)
 
 func px(l: CSSLength, viewport: Viewport, p: Option[LayoutUnit]):
     Option[LayoutUnit] {.inline.} =
   if l.unit == UNIT_PERC and p.isNone:
     return none(LayoutUnit)
-  return some(px(l, viewport.window, p.get(0)))
+  return some(px(l, viewport.attrs, p.get(0)))
 
 func canpx(l: CSSLength, sc: SizeConstraint): bool =
   return l.unit != UNIT_PERC or sc.isDefinite()
@@ -37,7 +37,7 @@ func px(l: CSSLength, viewport: Viewport, p: SizeConstraint): LayoutUnit =
       return 0
     of STRETCH, FIT_CONTENT:
       return l.px(viewport, p.u)
-  return px(l, viewport.window, 0)
+  return px(l, viewport.attrs, 0)
 
 func applySizeConstraint(u: LayoutUnit, availableSize: SizeConstraint):
     LayoutUnit =
@@ -87,13 +87,13 @@ func nowrap(computed: CSSComputedValues): bool =
   computed{"white-space"} in {WHITESPACE_NOWRAP, WHITESPACE_PRE}
 
 func cellwidth(viewport: Viewport): LayoutUnit =
-  viewport.window.ppc
+  viewport.attrs.ppc
 
 func cellwidth(state: InlineState): LayoutUnit =
   state.viewport.cellwidth
 
 func cellheight(viewport: Viewport): LayoutUnit =
-  viewport.window.ppl
+  viewport.attrs.ppl
 
 func cellheight(state: InlineState): LayoutUnit =
   state.viewport.cellheight
@@ -1046,9 +1046,9 @@ proc positionAbsolute(box: BlockBox) =
   let right = box.computed{"right"}
   let top = box.computed{"top"}
   let bottom = box.computed{"bottom"}
-  let parentWidth = applySizeConstraint(viewport.window.width_px,
+  let parentWidth = applySizeConstraint(viewport.attrs.width_px,
     last.availableWidth)
-  let parentHeight = applySizeConstraint(viewport.window.height_px,
+  let parentHeight = applySizeConstraint(viewport.attrs.height_px,
     last.availableHeight)
   box.x_positioned = not (left.auto and right.auto)
   box.y_positioned = not (top.auto and bottom.auto)
@@ -1658,9 +1658,9 @@ proc buildBlock(builder: BlockBoxBuilder, parent: BlockBox): BlockBox =
 
 # Establish a new flow-root context and build a block box.
 proc buildRootBlock(viewport: Viewport, builder: BlockBoxBuilder): BlockBox =
-  let w = stretch(viewport.window.width_px)
+  let w = stretch(viewport.attrs.width_px)
   let h = maxContent()
-  let vh: LayoutUnit = viewport.window.height_px
+  let vh: LayoutUnit = viewport.attrs.height_px
   let box = viewport.newFlowRootBox(builder, w, h, some(vh))
   viewport.positioned.add(box)
   box.buildLayout(builder)
@@ -2134,7 +2134,7 @@ proc generateTableBox(styledNode: StyledNode, viewport: Viewport,
   box.generateTableChildWrappers()
   return box
 
-proc renderLayout*(viewport: Viewport, root: StyledNode): BlockBox =
-  viewport.positioned.setLen(0)
+proc renderLayout*(root: StyledNode, attrs: WindowAttributes): BlockBox =
+  let viewport = Viewport(attrs: attrs)
   let builder = root.generateBlockBox(viewport)
   return viewport.buildRootBlock(builder)
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim
index 319d0f08..27435633 100644
--- a/src/render/renderdocument.nim
+++ b/src/render/renderdocument.nim
@@ -370,10 +370,10 @@ proc renderBlockBox(grid: var FlexibleGrid, box: BlockBox, x, y: LayoutUnit,
       for i in countdown(box.nested.high, 0):
         stack.add((box.nested[i], x, y, posx, posy))
 
-proc renderDocument*(styledRoot: StyledNode, viewport: Viewport,
-    attrs: WindowAttributes): FlexibleGrid =
+proc renderDocument*(styledRoot: StyledNode, attrs: WindowAttributes):
+    FlexibleGrid =
   var grid: FlexibleGrid
-  let rootBox = viewport.renderLayout(styledRoot)
+  let rootBox = renderLayout(styledRoot, attrs)
   grid.renderBlockBox(rootBox, 0, 0, attrs)
   if grid.len == 0:
     grid.addLine()
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 1a2b7e02..3a458cc4 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -35,7 +35,6 @@ import js/fromjs
 import js/javascript
 import js/regex
 import js/timeout
-import layout/box
 import loader/connecterror
 import loader/headers
 import loader/loader
@@ -99,7 +98,6 @@ type
     attrs: WindowAttributes
     window: Window
     document: Document
-    viewport: Viewport
     prevstyled: StyledNode
     selector: Selector[int]
     istream: Stream
@@ -591,15 +589,13 @@ let quirkstyle = quirk.parseStylesheet()
 
 proc do_reshape(buffer: Buffer) =
   if buffer.ishtml:
-    if buffer.viewport == nil:
-      buffer.viewport = Viewport(window: buffer.attrs)
     let uastyle = if buffer.document.mode != QUIRKS:
       uastyle
     else:
       quirkstyle
     let styledRoot = buffer.document.applyStylesheets(uastyle,
       buffer.userstyle, buffer.prevstyled)
-    buffer.lines = renderDocument(styledRoot, buffer.viewport, buffer.attrs)
+    buffer.lines = renderDocument(styledRoot, buffer.attrs)
     buffer.prevstyled = styledRoot
   else:
     buffer.lines.renderStream(buffer.srenderer, buffer.available)
@@ -607,7 +603,6 @@ proc do_reshape(buffer: Buffer) =
 
 proc windowChange*(buffer: Buffer, attrs: WindowAttributes) {.proxy.} =
   buffer.attrs = attrs
-  buffer.viewport = Viewport(window: buffer.attrs)
   buffer.width = buffer.attrs.width
   buffer.height = buffer.attrs.height - 1
 
@@ -1720,7 +1715,6 @@ proc launchBuffer*(config: BufferConfig, source: BufferSource,
     loader: loader,
     source: source,
     sstream: newStringStream(),
-    viewport: Viewport(window: attrs),
     width: attrs.width,
     height: attrs.height - 1,
     readbufsize: BufferSize,