Skip to content

Commit

Permalink
Merge pull request #18 from lightpanda-io/current_script
Browse files Browse the repository at this point in the history
html_document: add current script
  • Loading branch information
krichprollsch authored Sep 24, 2024
2 parents 3677430 + 64bb867 commit 51c34d6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
24 changes: 24 additions & 0 deletions include/dom/html/html_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down
14 changes: 14 additions & 0 deletions src/html/html_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
12 changes: 10 additions & 2 deletions src/html/html_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand All @@ -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, \
Expand Down

0 comments on commit 51c34d6

Please sign in to comment.