From f18b7ad86fe25e32cac7d9bca1abe92c46437535 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 5 Feb 2017 22:41:04 +0000 Subject: dom watcher: Add callback for dom mutation watching. --- src/layout.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/layout.c') diff --git a/src/layout.c b/src/layout.c index d894f13..e4824bf 100644 --- a/src/layout.c +++ b/src/layout.c @@ -14,6 +14,7 @@ #include "libnslayout/nslayout.h" #include "layout.h" +#include "util/util.h" #include "dom/watcher.h" #include "util/dom-str.h" @@ -46,6 +47,40 @@ nslayout_error nslayout_fini(void) } +/** + * Callback function for dom modifications. + * + * \param[in] type The mutation type. + * \param[in] node The target node. (Caller yields ownership.) + * \param[in] node_type The type of node. + * \param[in] pw The layout object. + * \return NSLAYOUT_OK on success, appropriate error otherwise. + */ +static nslayout_error nsl_layout_dom_watcher_cb( + enum nsl_dom_watcher_type type, + dom_event_target *node, + dom_node_type node_type, + void *pw) +{ + nslayout_layout *layout = pw; + + UNUSED(type); + UNUSED(layout); + UNUSED(node_type); + + /* TODO: Based on event type: + * 1. call to do (re)selection: + * a. all nodes? + * b. just this node? + * 2. call to update layout, if needed. + */ + + dom_node_unref(node); + + return NSLAYOUT_OK; +} + + /* Publically exported function, documented in include/libnslayout/nslayout.h */ nslayout_error nslayout_layout_create( dom_document *doc, @@ -75,7 +110,8 @@ nslayout_error nslayout_layout_create( l->cb = cb; l->pw = pw; - err = nsl_dom_watcher_create(&l->watcher, l->document); + err = nsl_dom_watcher_create(&l->watcher, l->document, + nsl_layout_dom_watcher_cb, l); if (err != NSLAYOUT_OK) { return err; } -- cgit v1.2.3