Added visiblity state changes for document

This commit is contained in:
David Botton 2024-02-12 08:11:17 -05:00
parent ed9e5519f6
commit 772a236266
3 changed files with 54 additions and 4 deletions

View file

@ -141,11 +141,28 @@ clog-document object. (Private)"))
;;;;;;;;;;;;;;;;;
(defgeneric ready-state (clog-document)
(:documentation "Get ready-state."))
(:documentation "Get ready-state. Returns 'loading'|'interactive'|'complete'.
The state would only change if the boot-page was still loading css, graphics, etc.
Under normal circumstance there is no need in CLOG to check if the state is ready
as on-new-window is only called once one can interact with page. See also
SET-ON-READY-STATE-CHANGE"))
(defmethod ready-state ((obj clog-document))
(query obj "readyState"))
;;;;;;;;;;;;;;;;;;;;;;
;; visibility-state ;;
;;;;;;;;;;;;;;;;;;;;;;
(defgeneric visibility-state (clog-document)
(:documentation "Get visibility-state. Returns the string 'visible' if
browser is in non-minmized state and is partialy visible and 'hidden' is
browser is minimized or no part of page is visible including an OS screen
lock."))
(defmethod visibility-state ((obj clog-document))
(query obj "visibilityState"))
;;;;;;;;;;;;;;
;; load-css ;;
;;;;;;;;;;;;;;
@ -286,3 +303,30 @@ If ON-FULL-SCREEN-CHANGE-HANDLER is nil unbind the event."))
(defmethod set-on-full-screen-change ((obj clog-document) handler)
(set-on-event obj "fullscreenchange" handler))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set-on-visibility-change ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgeneric set-on-visibility-change (clog-document
on-visibility-change-handler)
(:documentation "Set the ON-VISIBILITY-CHANGE-HANDLER for CLOG-OBJ.
If ON-VISIBILITY-CHANGE-HANDLER is nil unbind the event. This event
is fired when the page visibility has changed such as a tab being
switch of browser minimized. Use the VISIBILITY-STATE property to
identify chage."))
(defmethod set-on-visibility-change ((obj clog-document) handler)
(set-on-event obj "visibilitychange" handler))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set-on-ready-state-change ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgeneric set-on-ready-state-change (clog-document
on-ready-state-change-handler)
(:documentation "Set the ON-READY-STATE-CHANGE-HANDLER for CLOG-OBJ.
If ON-READY-STATE-CHANGE-HANDLER is nil unbind the event."))
(defmethod set-on-ready-state-change ((obj clog-document) handler)
(set-on-event obj "readystatechange" handler))

View file

@ -92,12 +92,15 @@
;; clog-repl ;;
;;;;;;;;;;;;;;;
(defun clog-repl (&key (clog-gui-initialize t) (clog-web-initialize t))
(defun clog-repl (&key (clog-gui-initialize t)
(clog-web-initialize t)
(boot-file "/debug.html")
(port 8080))
"Set a path /repl that opens a blank page and sets the global
clog-user:*body* to last window openned to /repl. Debug mode is
set (logging to browser console), "
set (logging to browser console) in the default debug.html boot-file."
(unless *clog-running*
(initialize nil :boot-file "/debug.html"))
(initialize nil :boot-file boot-file :port port))
(set-on-new-window (lambda (body)
(clog-connection:debug-mode (connection-id body))
(when clog-web-initialize

View file

@ -1010,6 +1010,7 @@ embedded in a native template application.)"
(head-element generic-function)
(body-element generic-function)
(document-element generic-function)
(visibility-state generic-function)
(ready-state generic-function)
(load-css generic-function)
(load-script generic-function)
@ -1020,6 +1021,8 @@ embedded in a native template application.)"
"CLOG-Document - Events"
(set-on-full-screen-change generic-function)
(set-on-visibility-change generic-function)
(set-on-ready-state-change generic-function)
(set-on-load-script generic-function))
(defsection @clog-navigator (:title "CLOG Navigator Objects")