Add fire_dom_event, it's in a bad place but we can move it later

This commit is contained in:
Daniel Silverstone 2015-10-31 18:01:17 +01:00
parent 4ca737408c
commit 310162474a
2 changed files with 42 additions and 0 deletions

View File

@ -70,6 +70,30 @@ static const char *html_types[] = {
"text/html" "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 * 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); 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) { if (htmlc->jscontext != NULL) {
js_handle_new_element(htmlc->jscontext, js_handle_new_element(htmlc->jscontext,
(dom_element *) node); (dom_element *) node);

View File

@ -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_open_objects(html_content *html, struct browser_window *bw);
nserror html_object_abort_objects(html_content *html); 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 */ /* Useful dom_string pointers */
struct dom_string; struct dom_string;