summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2017-02-04 11:00:24 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2017-02-04 12:01:58 (GMT)
commit9c10dfcb92088e2a89939c58560e89ddd0b69228 (patch)
treedf77b9b683ae6b283ebf19d372041258a62fb0f9
parent4143b787a2496b74c7a684fe8507c593b136cf8b (diff)
downloadlibnslayout-9c10dfcb92088e2a89939c58560e89ddd0b69228.tar.gz
libnslayout-9c10dfcb92088e2a89939c58560e89ddd0b69228.tar.bz2
dom watcher: Add event type listeners and improve error handling.
-rw-r--r--src/dom/watcher.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/dom/watcher.c b/src/dom/watcher.c
index 00a023a..d81d350 100644
--- a/src/dom/watcher.c
+++ b/src/dom/watcher.c
@@ -117,7 +117,6 @@ fail:
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout)
{
- nslayout_error err;
dom_exception exc;
/* TODO: LibDOM event listeners are really slow. Need to find a better
@@ -127,33 +126,68 @@ nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout)
exc = dom_event_listener_create(nsl__dom_event_handler,
layout, &layout->listener);
if (exc != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc);
+ goto fail_listener_create;
}
+
exc = dom_event_target_add_event_listener(
- layout->doc, nsl_dom_str_node_inserted,
+ layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- err = NSL_DOM_ERR(exc);
- goto fail;
+ goto fail_add_listener_node_inserted;
}
exc = dom_event_target_add_event_listener(
- layout->doc, nsl_dom_str_subtree_modified,
+ layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- (void) dom_event_target_remove_event_listener(
- layout->doc, nsl_dom_str_node_inserted,
- layout->listener, false);
- err = NSL_DOM_ERR(exc);
- goto fail;
+ goto fail_add_listener_subtree_modified;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_node_removed,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto fail_add_listener_node_removed;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_attr_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto fail_add_listener_attr_modified;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_characterdata_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto fail_add_listener_characterdata_modified;
}
return NSLAYOUT_OK;
-fail:
+fail_add_listener_characterdata_modified:
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_attr_modified,
+ layout->listener, false);
+
+fail_add_listener_attr_modified:
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_removed,
+ layout->listener, false);
+
+fail_add_listener_node_removed:
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+
+fail_add_listener_subtree_modified:
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+
+fail_add_listener_node_inserted:
dom_event_listener_unref(layout->listener);
layout->listener = NULL;
- return err;
+fail_listener_create:
+ return NSL_DOM_ERR(exc);
}
/* Exported function, documented in src/dom/event.h */