aboutsummaryrefslogtreecommitdiffstats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-01 20:01:03 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-01 20:06:56 +0200
commit3cc7f9d2131c5d6bb866da8d517391a249edd6c7 (patch)
tree4f84dd986b6642b5cb90f934d855011cc4d7a978 /src/html
parentf848a910814842a4c6b164f7b1f0898e74083abe (diff)
downloadchawan-3cc7f9d2131c5d6bb866da8d517391a249edd6c7.tar.gz
cssparser: refactor
* factor out skipWhitespace * remove streams dependency (cssparser could never stream without blocking the event loop, so we were just passing a StringStream in all cases, which made the whole streaming pointless.)
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index e7d7e28e..6f57960a 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -3,7 +3,6 @@ import std/deques
import std/math
import std/options
import std/sets
-import std/streams
import std/strutils
import std/tables
@@ -2344,7 +2343,7 @@ isDefaultPassive = func (eventTarget: EventTarget): bool =
EventTarget(node.document.body) == eventTarget
proc parseColor(element: Element; s: string): ARGBColor =
- let cval = parseComponentValue(newStringStream(s))
+ let cval = parseComponentValue(s)
#TODO return element style
# For now we just use white.
let ec = rgb(255, 255, 255)
@@ -2731,12 +2730,12 @@ proc delAttr(element: Element; i: int; keep = false) =
proc newCSSStyleDeclaration(element: Element; value: string):
CSSStyleDeclaration =
- let inline_rules = newStringStream(value).parseListOfDeclarations2()
+ let inlineRules = value.parseDeclarations2()
var decls: seq[CSSDeclaration]
- for rule in inline_rules:
+ for rule in inlineRules:
if rule.name.isSupportedProperty():
decls.add(rule)
- return CSSStyleDeclaration(decls: inline_rules, element: element)
+ return CSSStyleDeclaration(decls: inlineRules, element: element)
proc cssText(this: CSSStyleDeclaration): string {.jsfunc.} =
#TODO this is incorrect
@@ -2794,7 +2793,7 @@ proc setValue(this: CSSStyleDeclaration; i: int; cvals: seq[CSSComponentValue]):
proc setter[T: uint32|string](this: CSSStyleDeclaration; u: T;
value: string) {.jssetprop.} =
- let cvals = parseListOfComponentValues(newStringStream(value))
+ let cvals = parseComponentValues(value)
when u is uint32:
if this.setValue(int(u), cvals).isErr:
return
@@ -2836,7 +2835,7 @@ proc loadResource(window: Window; link: HTMLLinkElement) =
let url = url.get
let media = link.media
if media != "":
- let cvals = parseListOfComponentValues(newStringStream(media))
+ let cvals = parseComponentValues(media)
let media = parseMediaQueryList(cvals)
if not media.appliesFwdDecl(window):
return
@@ -2845,15 +2844,13 @@ proc loadResource(window: Window; link: HTMLLinkElement) =
).then(proc(res: JSResult[Response]): Promise[JSResult[string]] =
if res.isOk:
let res = res.get
- #TODO we should use ReadableStreams for this (which would allow us to
- # parse CSS asynchronously)
if res.getContentType() == "text/css":
return res.text()
res.unregisterFun()
).then(proc(s: JSResult[string]) =
if s.isOk:
#TODO non-utf-8 css?
- link.sheet = parseStylesheet(newStringStream(s.get), window.factory)
+ link.sheet = parseStylesheet(s.get, window.factory)
window.document.cachedSheetsInvalid = true
)
window.loadingResourcePromises.add(p)