summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2017-02-04 16:50:33 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2017-02-04 16:50:33 (GMT)
commitc8e49af1cbd7d17b37f579bdb8d02bfcc6d982bb (patch)
treee0c74045777a2d8c9bc63e9a299356364407f332
parent46305b75b9a4ec8f0e4a93e3efb1b8e12ff2f390 (diff)
downloadlibnslayout-c8e49af1cbd7d17b37f579bdb8d02bfcc6d982bb.tar.gz
libnslayout-c8e49af1cbd7d17b37f579bdb8d02bfcc6d982bb.tar.bz2
dom watcher: Clean up listener cleanup. Requires new LibDOM.
-rw-r--r--src/dom/watcher.c59
1 files changed, 16 insertions, 43 deletions
diff --git a/src/dom/watcher.c b/src/dom/watcher.c
index 6e35926..0788354 100644
--- a/src/dom/watcher.c
+++ b/src/dom/watcher.c
@@ -124,90 +124,63 @@ nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout)
* LibDOM probably needs to gain Mutation Observer support.
*/
+ assert(layout->listener == NULL);
+
exc = dom_event_listener_create(nsl__dom_event_handler,
layout, &layout->listener);
if (exc != DOM_NO_ERR) {
- goto fail_listener_create;
+ goto error;
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- goto fail_add_listener_node_inserted;
+ goto error;
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- goto fail_add_listener_subtree_modified;
+ goto error;
}
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;
+ goto error;
}
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;
+ goto error;
}
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;
+ goto error;
}
return NSLAYOUT_OK;
-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);
+error:
+ nsl_dom_watcher_remove_for_layout(layout);
-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;
-
-fail_listener_create:
return NSL_DOM_ERR(exc);
}
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_watcher_remove_for_layout(nslayout_layout *layout)
{
- dom_exception exc1, exc2;
-
- exc1 = dom_event_target_remove_event_listener(
- layout->doc, nsl_dom_str_node_inserted,
- layout->listener, false);
- exc2 = dom_event_target_remove_event_listener(
- layout->doc, nsl_dom_str_subtree_modified,
- layout->listener, false);
+ dom_exception exc;
- if (exc1 != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc1);
- }
- if (exc2 != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc2);
+ /* Passing NULL as type, removes listener for all event types. */
+ exc = dom_event_target_remove_event_listener(
+ layout->doc, NULL, layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc);
}
dom_event_listener_unref(layout->listener);