2022-03-05 18:52:17 +00:00
|
|
|
(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))
|
|
|
|
|
|
|
|
(local Listeners (require :listeners))
|
|
|
|
|
2022-03-06 23:11:55 +00:00
|
|
|
(fn scale-surface [source image-width image-height]
|
|
|
|
(let [scaled (cairo.ImageSurface.create
|
|
|
|
cairo.Format.ARGB32
|
|
|
|
image-width image-height)
|
|
|
|
ctx (cairo.Context.create scaled)
|
|
|
|
source-width (cairo.ImageSurface.get_width source)
|
|
|
|
source-height (cairo.ImageSurface.get_height source)
|
|
|
|
scale (/ image-width source-width)]
|
|
|
|
;; XXX do we need to destroy this context? the example
|
|
|
|
;; in C called cairo_destroy(cr), but I haven't found a
|
|
|
|
;; gi equivalent
|
|
|
|
(doto ctx
|
|
|
|
(: :scale scale scale)
|
|
|
|
(: :set_source_surface source 0 0)
|
|
|
|
(: :paint))
|
|
|
|
scaled))
|
|
|
|
|
|
|
|
(fn thumbnail-image [widget width height fun]
|
|
|
|
;; underlying call is async, so use callback
|
|
|
|
(widget:get_snapshot
|
|
|
|
WebKit2.SnapshotRegion.VISIBLE
|
|
|
|
WebKit2.SnapshotOptions.NONE
|
|
|
|
nil
|
|
|
|
(fn [self res]
|
|
|
|
(let [surface (widget:get_snapshot_finish res)
|
|
|
|
scaled (scale-surface surface width height)
|
|
|
|
img (doto (Gtk.Image) (: :set_from_surface scaled))]
|
|
|
|
(fun img)))))
|
|
|
|
|
2022-03-05 18:52:17 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
:new
|
|
|
|
#(let [listeners (Listeners.new)
|
|
|
|
props {}
|
|
|
|
widget (WebKit2.WebView {
|
|
|
|
:on_notify
|
|
|
|
(fn [self pspec]
|
|
|
|
(when (not (= pspec.name :parent))
|
|
|
|
(let [val (. self pspec.name)]
|
|
|
|
(tset props pspec.name val)
|
|
|
|
(listeners:notify pspec.name val))))
|
|
|
|
})]
|
|
|
|
;;(load-adblocks webview.user_content_manager content-filter-store)
|
|
|
|
{
|
|
|
|
:listen #(listeners:add $2 $3)
|
|
|
|
:visit (fn [self url]
|
|
|
|
(widget:load_uri url))
|
|
|
|
:stop-loading #(widget:stop_loading)
|
|
|
|
:refresh #(widget:reload)
|
|
|
|
:go-back #(and (widget:can_go_back) (widget:go_back))
|
|
|
|
|
2022-03-06 23:11:55 +00:00
|
|
|
:thumbnail-image (fn [self width height fun]
|
|
|
|
(thumbnail-image widget width height fun))
|
|
|
|
|
2022-03-05 18:52:17 +00:00
|
|
|
:properties props
|
|
|
|
:widget widget
|
|
|
|
})
|
|
|
|
}
|