about summary refs log tree commit diff stats
path: root/src/server
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-17 00:54:02 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-17 01:12:08 +0100
commit6ec8abb19214835348bb96575455b0a65079741e (patch)
treedb7025ce171d1114d591aca12abb3d03c8d5d42a /src/server
parent6604bd6dc1fd9ad110fc5ff1f01f3b8b4c787ed8 (diff)
downloadchawan-6ec8abb19214835348bb96575455b0a65079741e.tar.gz
layout: use html/body bgcolor as canvas bgcolor
This is required by the standard. (Without this, lots of websites have
incorrect background colors, because they set the body height to 100%
of the viewport.)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/buffer.nim28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 3c6dfa21..3804d1b9 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -119,6 +119,7 @@ type
     userstyle: CSSStylesheet
     htmlParser: HTML5ParserWrapper
     srenderer: ref StreamRenderer
+    bgcolor: CellColor
 
   InterfaceOpaque = ref object
     stream: Stream
@@ -624,9 +625,11 @@ proc do_reshape(buffer: Buffer) =
       buffer.uastyle
     else:
       buffer.quirkstyle
+    if buffer.document.cachedSheetsInvalid:
+      buffer.prevstyled = nil
     let styledRoot = buffer.document.applyStylesheets(uastyle,
       buffer.userstyle, buffer.prevstyled)
-    buffer.lines = renderDocument(styledRoot, buffer.attrs)
+    buffer.lines.renderDocument(buffer.bgcolor, styledRoot, buffer.attrs)
     buffer.prevstyled = styledRoot
 
 proc processData(buffer: Buffer): bool =
@@ -1108,7 +1111,6 @@ proc onload(buffer: Buffer) =
         # EOF
         res.atend = true
         buffer.finishLoad().then(proc() =
-          buffer.prevstyled = nil # for incremental rendering
           buffer.do_reshape()
           res.lines = buffer.lines.len
           buffer.state = LOADED
@@ -1123,20 +1125,10 @@ proc onload(buffer: Buffer) =
       buffer.resolveTask(LOAD, res)
     except ErrorAgain:
       break
-  if buffer.document != nil:
-    # incremental rendering: only if we cannot read the entire stream in one
-    # pass
-    #TODO this is too simplistic to be really useful
-    let uastyle = if buffer.document.mode != QUIRKS:
-      buffer.uastyle
-    else:
-      buffer.quirkstyle
-    if buffer.document.cachedSheetsInvalid:
-      buffer.prevstyled = nil
-    let styledRoot = buffer.document.applyStylesheets(uastyle,
-      buffer.userstyle, buffer.prevstyled)
-    buffer.lines = renderDocument(styledRoot, buffer.attrs)
-    buffer.prevstyled = styledRoot
+  # incremental rendering: only if we cannot read the entire stream in one
+  # pass
+  #TODO this could be improved
+  buffer.do_reshape()
 
 proc getTitle*(buffer: Buffer): string {.proxy.} =
   if buffer.document != nil:
@@ -1606,7 +1598,8 @@ proc findAnchor*(buffer: Buffer, anchor: string): bool {.proxy.} =
 
 type GetLinesResult* = tuple[
   numLines: int,
-  lines: seq[SimpleFlexibleLine]
+  lines: seq[SimpleFlexibleLine],
+  bgcolor: CellColor
 ]
 
 proc getLines*(buffer: Buffer, w: Slice[int]): GetLinesResult {.proxy.} =
@@ -1620,6 +1613,7 @@ proc getLines*(buffer: Buffer, w: Slice[int]): GetLinesResult {.proxy.} =
       line.formats.add(SimpleFormatCell(format: f.format, pos: f.pos))
     result.lines.add(line)
   result.numLines = buffer.lines.len
+  result.bgcolor = buffer.bgcolor
 
 macro bufferDispatcher(funs: static ProxyMap, buffer: Buffer,
     cmd: BufferCommand, packetid: int) =