From 310162474a3690e00244a0edd87361bf1352be82 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 31 Oct 2015 18:01:17 +0100 Subject: Add fire_dom_event, it's in a bad place but we can move it later --- render/html.c | 34 ++++++++++++++++++++++++++++++++++ render/html_internal.h | 8 ++++++++ 2 files changed, 42 insertions(+) (limited to 'render') diff --git a/render/html.c b/render/html.c index 8722b1c4f..a21901775 100644 --- a/render/html.c +++ b/render/html.c @@ -70,6 +70,30 @@ static const char *html_types[] = { "text/html" }; +/* Exported interface, see html_internal.h */ +bool fire_dom_event(dom_string *type, dom_node *target, + bool bubbles, bool cancelable) +{ + dom_exception exc; + dom_event *evt; + bool result; + + exc = dom_event_create(&evt); + if (exc != DOM_NO_ERR) return false; + exc = dom_event_init(evt, type, bubbles, cancelable); + if (exc != DOM_NO_ERR) { + dom_event_unref(evt); + return false; + } + LOG("Dispatching '%*s' against %p", + dom_string_length(type), dom_string_data(type), target); + exc = dom_event_target_dispatch_event(target, evt, &result); + if (exc != DOM_NO_ERR) { + result = false; + } + dom_event_unref(evt); + return result; +} /** * Perform post-box-creation conversion of a document @@ -645,6 +669,16 @@ dom_default_action_DOMNodeInserted_cb(struct dom_event *evt, void *pw) dom_string_unref(name); } + /* ensure javascript context is available */ + if (htmlc->jscontext == NULL) { + union content_msg_data msg_data; + + msg_data.jscontext = &htmlc->jscontext; + content_broadcast(&htmlc->base, + CONTENT_MSG_GETCTX, + msg_data); + LOG("javascript context %p ", htmlc->jscontext); + } if (htmlc->jscontext != NULL) { js_handle_new_element(htmlc->jscontext, (dom_element *) node); diff --git a/render/html_internal.h b/render/html_internal.h index 97ac2da55..e5740dbda 100644 --- a/render/html_internal.h +++ b/render/html_internal.h @@ -352,6 +352,14 @@ nserror html_object_close_objects(html_content *html); nserror html_object_open_objects(html_content *html, struct browser_window *bw); nserror html_object_abort_objects(html_content *html); +/* Events */ +/** + * Construct an event and fire it at the DOM + * + */ +bool fire_dom_event(dom_string *type, dom_node *target, + bool bubbles, bool cancelable); + /* Useful dom_string pointers */ struct dom_string; -- cgit v1.2.3