From 64bb8672ffad491658a4795403ee92778f0483bf Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 24 Sep 2024 09:16:50 +0200 Subject: [PATCH] html_document: add current script --- include/dom/html/html_document.h | 24 ++++++++++++++++++++++++ src/html/html_document.c | 14 ++++++++++++++ src/html/html_document.h | 12 ++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/dom/html/html_document.h b/include/dom/html/html_document.h index 936ea69d..8eb7fc15 100644 --- a/include/dom/html/html_document.h +++ b/include/dom/html/html_document.h @@ -37,6 +37,10 @@ typedef struct dom_html_document_vtable { struct dom_html_element **body); dom_exception (*set_body)(dom_html_document *doc, struct dom_html_element *body); + dom_exception (*get_current_script)(dom_html_document *doc, + struct dom_html_element **script); + dom_exception (*set_current_script)(dom_html_document *doc, + struct dom_html_element *script); dom_exception (*get_images)(dom_html_document *doc, struct dom_html_collection **col); dom_exception (*get_applets)(dom_html_document *doc, @@ -127,6 +131,26 @@ static inline dom_exception dom_html_document_set_body(dom_html_document *doc, dom_html_document_set_body((dom_html_document *) (d), \ (struct dom_html_element **) (b)) +static inline dom_exception dom_html_document_get_current_script(dom_html_document *doc, + struct dom_html_element **script) +{ + return ((dom_html_document_vtable *) ((dom_node *) doc)->vtable)-> + get_current_script(doc, script); +} +#define dom_html_document_get_current_script(d, b) \ + dom_html_document_get_current_script((dom_html_document *) (d), \ + (struct dom_html_element **) (b)) + +static inline dom_exception dom_html_document_set_current_script(dom_html_document *doc, + struct dom_html_element *script) +{ + return ((dom_html_document_vtable *) ((dom_node *) doc)->vtable)-> + set_current_script(doc, script); +} +#define dom_html_document_set_current_script(d, b) \ + dom_html_document_set_current_script((dom_html_document *) (d), \ + (struct dom_html_element **) (b)) + static inline dom_exception dom_html_document_get_images(dom_html_document *doc, struct dom_html_collection **col) { diff --git a/src/html/html_document.c b/src/html/html_document.c index cf3c25db..e259e93d 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -1191,6 +1191,20 @@ dom_exception _dom_html_document_set_body(dom_html_document *doc, return DOM_NO_ERR; } +dom_exception _dom_html_document_get_current_script(dom_html_document *doc, + struct dom_html_element **script) +{ + *script = doc->current_script; + return DOM_NO_ERR; +} + +dom_exception _dom_html_document_set_current_script(dom_html_document *doc, + struct dom_html_element *script) +{ + doc->current_script = script; + return DOM_NO_ERR; +} + /** * Callback for creating the images collection * diff --git a/src/html/html_document.h b/src/html/html_document.h index fce41c8b..2d05ee9f 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -25,7 +25,9 @@ struct dom_html_document { dom_string *url; /**< HTML document URL */ dom_string *cookie; /**< HTML document cookie */ dom_html_element *body; /**< HTML BodyElement */ - + + dom_html_element *current_script; /**< current script */ + /** Cached strings for html objects to use */ dom_string **memoised; /** Cached strings for HTML element names */ @@ -83,7 +85,11 @@ dom_exception _dom_html_document_get_cookie(dom_html_document *doc, dom_string **cookie); dom_exception _dom_html_document_set_cookie(dom_html_document *doc, dom_string *cookie); - +dom_exception _dom_html_document_set_current_script(dom_html_document *doc, + dom_html_element *script); +dom_exception _dom_html_document_get_current_script(dom_html_document *node, + dom_html_element **result); + dom_exception _dom_html_document_open(dom_html_document *doc); dom_exception _dom_html_document_close(dom_html_document *doc); dom_exception _dom_html_document_write(dom_html_document *doc, @@ -102,6 +108,8 @@ dom_exception _dom_html_document_get_elements_by_name(dom_html_document *doc, _dom_html_document_get_url, \ _dom_html_document_get_body, \ _dom_html_document_set_body, \ + _dom_html_document_get_current_script, \ + _dom_html_document_set_current_script, \ _dom_html_document_get_images, \ _dom_html_document_get_applets, \ _dom_html_document_get_links, \