js_browser.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* Browser bindings for the embedded MuJS interpreter.
  2. *
  3. * The host owns the document and the UI; this layer exposes the DOM surface
  4. * (elements, attributes, selectors, classList/dataset/style, innerHTML,
  5. * timers) plus document/window/location/navigator globals, and leaves the
  6. * node tree operations to browser_html.c. */
  7. #ifndef JS_BROWSER_H
  8. #define JS_BROWSER_H
  9. struct br_doc;
  10. struct js_browser_host {
  11. void (*status)(const char *msg, int error);
  12. void (*report)(const char *msg);
  13. void (*navigate)(const char *url);
  14. void (*changed)(void);
  15. const char *page_url; /* location.href for every script on the page */
  16. unsigned int width; /* viewport size for window.inner* */
  17. unsigned int height;
  18. };
  19. /* Create a state for this document. Returns 0 on success. */
  20. int js_browser_start(struct br_doc *doc, const struct js_browser_host *host);
  21. void js_browser_stop(void);
  22. /* Run one script. `url` is used in error messages and by location.href. */
  23. int js_browser_run(const char *source, const char *url);
  24. /* Run due setTimeout/setInterval callbacks; call once per UI loop. */
  25. void js_browser_tick(void);
  26. int js_browser_active(void);
  27. #endif