js_browser.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /* Viewport-relative border box for getBoundingClientRect(); returns 0
  16. * when the node has no laid-out box. */
  17. int (*rect)(unsigned int node, int *x, int *y, int *w, int *h);
  18. /* Live form state; return 1 when the node has a control state. */
  19. int (*form_value)(unsigned int node, char *buf, int cap);
  20. int (*form_checked)(unsigned int node);
  21. int (*form_selected)(unsigned int node);
  22. int (*form_set_value)(unsigned int node, const char *value);
  23. int (*form_set_checked)(unsigned int node, int checked);
  24. int (*form_set_selected)(unsigned int node, int index);
  25. const char *page_url; /* location.href for every script on the page */
  26. unsigned int width; /* viewport size for window.inner* */
  27. unsigned int height;
  28. };
  29. /* Create a state for this document. Returns 0 on success. */
  30. int js_browser_start(struct br_doc *doc, const struct js_browser_host *host);
  31. void js_browser_stop(void);
  32. /* Run one script. `url` is used in error messages and by location.href. */
  33. int js_browser_run(const char *source, const char *url);
  34. /* Run due setTimeout/setInterval callbacks; call once per UI loop. */
  35. void js_browser_tick(void);
  36. int js_browser_active(void);
  37. #endif