| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /* Browser bindings for the embedded JavaScript engine (QuickJS via js_mu).
- *
- * The host owns the document and the UI; this layer exposes the DOM surface
- * (elements, attributes, selectors, classList/dataset/style, innerHTML,
- * timers) plus document/window/location/navigator globals, and leaves the
- * node tree operations to browser_html.c. */
- #ifndef JS_BROWSER_H
- #define JS_BROWSER_H
- struct br_doc;
- struct js_browser_host {
- void (*status)(const char *msg, int error);
- void (*report)(const char *msg);
- void (*navigate)(const char *url);
- void (*changed)(void);
- /* Viewport-relative border box for getBoundingClientRect(); returns 0
- * when the node has no laid-out box. */
- int (*rect)(unsigned int node, int *x, int *y, int *w, int *h);
- /* Live form state; return 1 when the node has a control state. */
- int (*form_value)(unsigned int node, char *buf, int cap);
- int (*form_checked)(unsigned int node);
- int (*form_selected)(unsigned int node);
- int (*form_set_value)(unsigned int node, const char *value);
- int (*form_set_checked)(unsigned int node, int checked);
- int (*form_set_selected)(unsigned int node, int index);
- /* Collect a form's listed controls (input/select/textarea/button). */
- int (*form_elements)(unsigned int form, unsigned int *out, int cap);
- int (*form_submit)(unsigned int form); /* JS submit(), no event */
- int (*form_reset)(unsigned int form); /* JS reset(), fires reset */
- int (*click)(unsigned int node); /* element.click() */
- /* Computed style for getComputedStyle(); return 1 when known. */
- int (*computed)(unsigned int node, const char *property, char *buf,
- int cap);
- const char *page_url; /* location.href for every script on the page */
- unsigned int width; /* viewport size for window.inner* */
- unsigned int height;
- };
- /* Create a state for this document. Returns 0 on success. */
- int js_browser_start(struct br_doc *doc, const struct js_browser_host *host);
- void js_browser_stop(void);
- /* Run one script. `url` is used in error messages and by location.href. */
- int js_browser_run(const char *source, const char *url);
- /* Run due setTimeout/setInterval callbacks; call once per UI loop. */
- void js_browser_tick(void);
- /* Dispatch a DOM event at a node. Returns 0 when a handler called
- * preventDefault(). Bubbles to ancestors, document and window. */
- int js_browser_event(unsigned int node, const char *type, int bubbles,
- int cancelable);
- int js_browser_active(void);
- #endif
|