This commit is contained in:
2026-03-03 22:52:22 +01:00
parent 8d00476ed2
commit 8f49007930
11 changed files with 167 additions and 39 deletions

View File

@@ -21,6 +21,7 @@
rkt-webview-set-url!
rkt-webview-set-html!
rkt-webview-run-js
rkt-webview-call-js
rkt-webview-move
rkt-webview-resize
rkt-webview-exit
@@ -200,6 +201,9 @@
(define (rkt-webview-run-js wv js)
(rkt_webview_run_js (rkt-wv-win wv) js))
(define (rkt-webview-call-js wv js)
(rkt_webview_call_js (rkt-wv-win wv) js))
(define (rkt-webview-resize wv w h)
(rkt_webview_resize (rkt-wv-win wv) w h))

View File

@@ -18,10 +18,12 @@
webview-devtools
webview-close
webview-run-js
webview-call-js
webview-move
webview-resize
webview-bind!
webview-standard-file-getter
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -113,7 +115,7 @@
#:parent [p 0])
(let* ((h (make-wv #f current-servlet-port -1 file-getter bj #f))
(server (let ((s (start-web-server h)))
(sleep 1)
(sleep 1) ;;; TODO: Check if web server is up.
s))
(event-processor (λ (wv evt)
(event-callback h (util-parse-event evt))))
@@ -166,9 +168,9 @@
(on-not-exist file base-path p)
p)))))
;(define (webview-call-js wv js)
; (let ((result (rkt_webview_call_js (wv-handle wv) js)))
; result))
(define (webview-call-js wv js)
(let ((result (rkt_webview_call_js (wv-handle wv) js)))
result))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; testing

View File

@@ -79,6 +79,18 @@
(set! _std_x 50))
)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Storage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define windows (make-hash))
(define (ww-debug msg)
(displayln (format "DBG: ~a" msg)))
(define (ww-error msg)
(displayln (format "ERR: ~a" msg)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Class representing an element in the HTML page
;; each element is identified by an id.
@@ -94,9 +106,9 @@
(define/public (get-id)
id)
(define/public (win)
(let ((w (hash-ref windows (ww-win-id win-id) #f)))
w))
;(define/public (win)
; (let ((w (hash-ref windows (ww-win-id win-id) #f)))
; w))
(define connected-callbacks (make-hash))
@@ -110,7 +122,7 @@
(apply cb args)))))
(define/public (exec-js js)
(ww-exec-js win-id js))
(webview-run-js win-id js))
(define/public (connect evt func)
(hash-set! connected-callbacks evt func))
@@ -119,34 +131,34 @@
(hash-remove! connected-callbacks evt))
(define/public (add-style! st)
(ww-add-style win-id id st))
(webview-add-style win-id id st))
(define/public (set-style! st)
(ww-set-style win-id id st))
(webview-set-style win-id id st))
(define/public (style)
(ww-get-style win-id id))
(webview-get-style win-id id))
(define/public (get-attr a)
(ww-get-attr win-id id a))
(webview-get-attr win-id id a))
(define/public (set-attr! a val)
(ww-set-attr win-id id a val))
(webview-set-attr win-id id a val))
(define/public (del-attr a)
(ww-del-attr win-id id a))
(webview-del-attr win-id id a))
(define/public (get-attrs)
(ww-get-attrs win-id id))
(webview-get-attrs win-id id))
(define/public (add-class! cl)
(ww-add-class win-id id cl))
(webview-add-class win-id id cl))
(define/public (remove-class! cl)
(ww-remove-class win-id id cl))
(webview-remove-class win-id id cl))
(define/public (has-class? cl)
(ww-has-class? win-id id cl))
(webview-has-class? win-id id cl))
(define/public (enable)
(send this remove-class! 'disabled))
@@ -175,7 +187,7 @@
(define/public (set-inner-html! html-or-sexpr)
(if (string? html-or-sexpr)
(ww-set-inner-html win-id id html-or-sexpr)
(webview-set-inner-html! win-id id html-or-sexpr)
(set-inner-html! (xexpr->html5 html-or-sexpr))))
(super-new)
@@ -345,6 +357,8 @@
[height (if (eq? settings #f) _std_h (send settings get 'window-height _std_h))]
[icon #f]
[menu #f]
[base-path (build-path ".")]
[on-not-exist (λ (file base-path path) path)]
[html-file #f]
)
@@ -525,10 +539,10 @@
(ww-get-elements win-id selector))
(define/public (move x y)
(ww-move win-id x y))
(webview-move win-id x y))
(define/public (resize x y)
(ww-resize win-id x y))
(webview-resize win-id x y))
(define/public (get-x) x)
(define/public (get-y) y)
@@ -731,14 +745,17 @@
; (ww-new profile use-browser)
; (ww-new profile use-browser parent-id)))
(set! win-id (webview-create
(λ (file) file)
(webview-standard-file-getter base-path
#:not-exist not-exist)
event-handler))
(when (eq? win-id #f)
(error "Window could not be constructed"))
(hash-set! windows-evt-handlers (ww-win-id win-id) event-handler)
;(hash-set! windows-evt-handlers (ww-win-id win-id) event-handler)
(hash-set! windows (ww-win-id win-id) this)
(ww-resize win-id width height)
(webview-resize win-id width height)
(when parent
(let* ((parent-width (send parent get-width))
@@ -750,7 +767,7 @@
(set! y (+ parent-y (/ (- parent-height height) 2)))
)
)
(ww-move win-id x y)
(webview-move win-id x y)
(send this set-title! title)