diff options
author | bptato <nincsnevem662@gmail.com> | 2022-10-19 11:51:06 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-10-19 11:51:06 +0200 |
commit | ec82803b87aee94be1e44204bf62426df39f3087 (patch) | |
tree | 113ef554f5ebce44563c5406af6be2d5cfe7da32 /src/io/buffer.nim | |
parent | 7fbedc1f0d7e58fbbce3bdb469f81e9b7c411c15 (diff) | |
download | chawan-ec82803b87aee94be1e44204bf62426df39f3087.tar.gz |
Re-enable media queries
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r-- | src/io/buffer.nim | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 1e0a1c29..0443f514 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -6,6 +6,9 @@ import tables import terminal import unicode +import css/cascade +import css/cssparser +import css/mediaquery import css/sheet import css/stylednode import config/config @@ -831,6 +834,19 @@ proc updateHover(buffer: Buffer) = buffer.prevnode = thisnode +proc loadResource(buffer: Buffer, document: Document, elem: HTMLLinkElement) = + let url = parseUrl(elem.href, document.location.some) + if url.isSome: + let url = url.get + if url.scheme == buffer.location.scheme: + let media = elem.media + if media != "": + let media = parseMediaQueryList(parseListOfComponentValues(newStringStream(media))) + if not media.applies(): return + let fs = buffer.loader.doRequest(newRequest(url)) + if fs.body != nil and fs.contenttype == "text/css": + elem.sheet = parseStylesheet(fs.body) + proc loadResources(buffer: Buffer, document: Document) = var stack: seq[Element] if document.html != nil: @@ -841,13 +857,7 @@ proc loadResources(buffer: Buffer, document: Document) = if elem.tagType == TAG_LINK: let elem = HTMLLinkElement(elem) if elem.rel == "stylesheet": - let url = parseUrl(elem.href, document.location.some) - if url.issome: - let url = url.get - if url.scheme == buffer.location.scheme: - let fs = buffer.loader.doRequest(newRequest(url)) - if fs.body != nil and fs.contenttype == "text/css": - elem.sheet = parseStylesheet(fs.body) + buffer.loadResource(document, elem) for child in elem.children_rev: stack.add(child) |