diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-02 13:42:26 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-02 13:42:49 +0100 |
commit | d16a0aeee4a7c6fd485b4286db4c56f83d966853 (patch) | |
tree | 60499de299fb092a3e8a1f3900382d6749d062c8 /src/html | |
parent | c64617b0bf11fc0d805cb921c8931938a2b18225 (diff) | |
download | chawan-d16a0aeee4a7c6fd485b4286db4c56f83d966853.tar.gz |
env: add window.screen
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 4 | ||||
-rw-r--r-- | src/html/env.nim | 22 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 3f0a516a..0e3b12bc 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -69,6 +69,7 @@ type attrs*: WindowAttributes console* {.jsget.}: Console navigator* {.jsget.}: Navigator + screen* {.jsget.}: Screen settings*: EnvironmentSettings loader*: Option[FileLoader] location* {.jsget.}: Location @@ -90,6 +91,8 @@ type MimeTypeArray* = object + Screen* = object + NamedNodeMap = ref object element: Element attrlist: seq[Attr] @@ -370,6 +373,7 @@ type jsDestructor(Navigator) jsDestructor(PluginArray) jsDestructor(MimeTypeArray) +jsDestructor(Screen) jsDestructor(Window) jsDestructor(Element) diff --git a/src/html/env.nim b/src/html/env.nim index 9e817ea0..c614e90f 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -67,10 +67,27 @@ proc length(mimeTypeArray: ptr MimeTypeArray): uint32 {.jsfget.} = 0 proc getter(pluginArray: ptr PluginArray, i: int): Option[JSValue] {.jsgetprop.} = discard proc getter(mimeTypeArray: ptr MimeTypeArray, i: int): Option[JSValue] {.jsgetprop.} = discard +# Screen +proc availWidth(screen: ptr Screen): int64 {.jsfget.} = + #TODO this is a fingerprinting vector, but users should be able to allow it + # selectively + # for now just return something standard-ish + 80 * 9 +proc availHeight(screen: ptr Screen): int64 {.jsfget.} = + #TODO see above + 24 * 18 +proc width(screen: ptr Screen): int64 {.jsfget.} = + screen.availWidth +proc height(screen: ptr Screen): int64 {.jsfget.} = + screen.availHeight +proc colorDepth(screen: ptr Screen): int64 {.jsfget.} = 24 +proc pixelDepth(screen: ptr Screen): int64 {.jsfget.} = screen.colorDepth + proc addNavigatorModule(ctx: JSContext) = ctx.registerType(Navigator) ctx.registerType(PluginArray) ctx.registerType(MimeTypeArray) + ctx.registerType(Screen) proc fetch[T: Request|string](window: Window, req: T, init = none(RequestInit)): JSResult[FetchPromise] {.jsfunc.} = @@ -96,7 +113,10 @@ proc screenX(window: Window): int64 {.jsfget.} = 0 proc screenY(window: Window): int64 {.jsfget.} = 0 proc screenLeft(window: Window): int64 {.jsfget.} = 0 proc screenTop(window: Window): int64 {.jsfget.} = 0 -#TODO outerWidth, outerHeight +proc outerWidth(window: Window): int64 {.jsfget.} = + (addr window.screen).availWidth +proc outerHeight(window: Window): int64 {.jsfget.} = + (addr window.screen).availHeight proc devicePixelRatio(window: Window): float64 {.jsfget.} = 1 proc setLocation(window: Window, s: string): Err[JSError] |