diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2018-08-15 15:05:54 +0100 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2018-08-15 15:05:54 +0100 |
commit | b34c357bbd4883e409a8d617c528db92bf0963c0 (patch) | |
tree | b272a51d36733739b05053437eca8aeba94724d7 /test/test-loader.c | |
parent | ecb247eb155ff5495a91e32b6e416fd0b6c6a53e (diff) | |
download | libnslayout-b34c357bbd4883e409a8d617c528db92bf0963c0.tar.gz libnslayout-b34c357bbd4883e409a8d617c528db92bf0963c0.tar.bz2 |
Library: DOM change watching is now the job of the client.
Diffstat (limited to 'test/test-loader.c')
-rw-r--r-- | test/test-loader.c | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/test/test-loader.c b/test/test-loader.c index cab08d6..5cbd788 100644 --- a/test/test-loader.c +++ b/test/test-loader.c @@ -15,6 +15,8 @@ #include <libnslayout/nslayout.h> +#include "dom/watcher.h" + #ifndef UNUSED #define UNUSED(x) (void)(x) #endif @@ -42,11 +44,46 @@ struct test_loader_ctx { dom_document *doc; css_select_ctx *css_ctx; css_stylesheet *css_sheet; + + struct nsl_dom_watcher *watcher; }; +/** + * 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 NSL_OK on success, appropriate error otherwise. + */ +static bool nsl_layout_dom_watcher_cb( + enum nsl_dom_watcher_type type, + dom_event_target *node, + dom_node_type node_type, + void *pw) +{ + nsl_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 true; +} + + static bool test_loader_doc_load_start( - size_t chunk_length, struct test_loader_ctx *load_ctx) { dom_hubbub_parser_params params; @@ -67,21 +104,6 @@ static bool test_loader_doc_load_start( return false; } - /* Find length of first chunk */ - if (chunk_length > (load_ctx->html->len - load_ctx->html->pos)) - chunk_length = load_ctx->html->len - load_ctx->html->pos; - - /* Load first chunk */ - error = dom_hubbub_parser_parse_chunk(load_ctx->parser, - load_ctx->html->buf + load_ctx->html->pos, - chunk_length); - load_ctx->html->pos += chunk_length; - if (error != DOM_HUBBUB_OK) { - dom_hubbub_parser_destroy(load_ctx->parser); - printf("Parsing errors occur\n"); - return false; - } - return true; } @@ -106,7 +128,6 @@ bool test_loader_doc_load_next( chunk_length); load_ctx->html->pos += chunk_length; if (error != DOM_HUBBUB_OK) { - dom_hubbub_parser_destroy(load_ctx->parser); printf("Parsing errors occur\n"); return false; } @@ -122,14 +143,10 @@ bool test_loader_doc_load_next( /* Done parsing file */ error = dom_hubbub_parser_completed(load_ctx->parser); if (error != DOM_HUBBUB_OK) { - dom_hubbub_parser_destroy(load_ctx->parser); printf("Parsing error when construct DOM\n"); return false; } - /* Finished with parser */ - dom_hubbub_parser_destroy(load_ctx->parser); - return true; } @@ -308,11 +325,18 @@ static bool test_loader( load_ctx.css_ctx = NULL; printf("Starting load\n"); - if (!test_loader_doc_load_start(chunk_size, &load_ctx)) { + if (!test_loader_doc_load_start(&load_ctx)) { printf("ERROR: doc_load_start\n"); goto fail; } + printf("Adding dom watcher\n"); + if (!nsl_dom_watcher_create(&load_ctx.watcher, load_ctx.doc, + nsl_layout_dom_watcher_cb, &load_ctx)) { + printf("ERROR: nsl_dom_watcher_create\n"); + goto fail; + } + printf("Creating style context\n"); if (!test_loader_css_init(&load_ctx)) { printf("ERROR: create_style_context\n"); @@ -349,8 +373,15 @@ fail: nsl_layout_destroy(layout); } test_loader_css_fini(&load_ctx); + + nsl_dom_watcher_destroy(load_ctx.watcher); + dom_node_unref(load_ctx.doc); + if (load_ctx.parser != NULL) { + dom_hubbub_parser_destroy(load_ctx.parser); + } + return ret; } |