Gitweb links:
...log
http://git.netsurf-browser.org/libnslayout.git/shortlog/c67cd8eaaeb63777c6c9118b0b49d82adaf77088
...commit
http://git.netsurf-browser.org/libnslayout.git/commit/c67cd8eaaeb63777c6c9118b0b49d82adaf77088
...tree
http://git.netsurf-browser.org/libnslayout.git/tree/c67cd8eaaeb63777c6c9118b0b49d82adaf77088
The branch, master has been updated
via c67cd8eaaeb63777c6c9118b0b49d82adaf77088 (commit)
via b34c357bbd4883e409a8d617c528db92bf0963c0 (commit)
via ecb247eb155ff5495a91e32b6e416fd0b6c6a53e (commit)
via 6a783002e8b17995132fc6334b4e0900c36bf9a0 (commit)
from b77ae8ab7d1ce435d8afd3c77613c5a56c477025 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libnslayout.git/commit/?id=c67cd8eaaeb63777c6c9118b0b49d82adaf77088
commit c67cd8eaaeb63777c6c9118b0b49d82adaf77088
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Tests: Rename the suite that just creates an empty layout.
diff --git a/src/Makefile b/src/Makefile
index 7a6251d..b02f0b9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := layout.c
+DIR_SOURCES := layout.c node.c
include $(NSBUILD)/Makefile.subdir
diff --git a/test/Makefile b/test/Makefile
index 967d8da..feb4d77 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,3 @@
-DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;nslayout-object-tests.c
+DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;basic-tests.c
include $(NSBUILD)/Makefile.subdir
diff --git a/test/basic-tests.c b/test/basic-tests.c
new file mode 100644
index 0000000..c4be121
--- /dev/null
+++ b/test/basic-tests.c
@@ -0,0 +1,83 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <[email protected]>
+ */
+
+#include <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+static nsl_error nsl_test_callback(
+ nsl_layout *layout,
+ void *pw,
+ nsl_request *req)
+{
+ UNUSED(req);
+ UNUSED(layout);
+ UNUSED(pw);
+ return NSL_OK;
+}
+
+START_TEST (test_nsl_layout_create_ok)
+{
+ nsl_layout *layout = NULL;
+ nsl_error error;
+ dom_exception dom_error;
+ css_error css_err;
+ dom_document *doc;
+ css_select_ctx *css_ctx;
+ css_media_type media = CSS_MEDIA_SCREEN;
+
+ /* Create a DOM document */
+ dom_error = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
+ NULL, NULL, NULL, NULL, NULL, &doc);
+ ck_assert(dom_error == DOM_NO_ERR);
+
+ /* Create a selection context (with no sheets added) */
+ css_err = css_select_ctx_create(&css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ ck_assert(nsl_init() == NSL_OK);
+
+ error = nsl_layout_create(doc,
+ css_ctx,
+ &media,
+ nsl_test_callback,
+ NULL,
+ &layout);
+ fail_unless(error == NSL_OK,
+ "Unable to create layout");
+ fail_unless(layout != NULL,
+ "Returned OK but str was still NULL");
+
+ error = nsl_layout_destroy(layout);
+ fail_unless(error == NSL_OK,
+ "Unable to destroy layout");
+
+ ck_assert(nsl_fini() == NSL_OK);
+
+ css_err = css_select_ctx_destroy(css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ dom_node_unref(doc);
+}
+END_TEST
+
+
+void nsl_basic_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: nslayout object tests");
+ TCase *tc_layout_basic = tcase_create("Creation/Destruction");
+
+ tcase_add_test(tc_layout_basic, test_nsl_layout_create_ok);
+ suite_add_tcase(s, tc_layout_basic);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/nslayout-object-tests.c b/test/nslayout-object-tests.c
deleted file mode 100644
index 4a3f2c4..0000000
--- a/test/nslayout-object-tests.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This file is part of LibNSLayout's tests
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015 Michael Drake <[email protected]>
- */
-
-#include <check.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "tests.h"
-
-#ifndef UNUSED
-#define UNUSED(x) (void)(x)
-#endif
-
-static nsl_error nsl_test_callback(
- nsl_layout *layout,
- void *pw,
- nsl_request *req)
-{
- UNUSED(req);
- UNUSED(layout);
- UNUSED(pw);
- return NSL_OK;
-}
-
-START_TEST (test_nsl_layout_create_ok)
-{
- nsl_layout *layout = NULL;
- nsl_error error;
- dom_exception dom_error;
- css_error css_err;
- dom_document *doc;
- css_select_ctx *css_ctx;
- css_media_type media = CSS_MEDIA_SCREEN;
-
- /* Create a DOM document */
- dom_error = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
- NULL, NULL, NULL, NULL, NULL, &doc);
- ck_assert(dom_error == DOM_NO_ERR);
-
- /* Create a selection context (with no sheets added) */
- css_err = css_select_ctx_create(&css_ctx);
- ck_assert(css_err == CSS_OK);
-
- ck_assert(nsl_init() == NSL_OK);
-
- error = nsl_layout_create(doc,
- css_ctx,
- &media,
- nsl_test_callback,
- NULL,
- &layout);
- fail_unless(error == NSL_OK,
- "Unable to create layout");
- fail_unless(layout != NULL,
- "Returned OK but str was still NULL");
-
- error = nsl_layout_destroy(layout);
- fail_unless(error == NSL_OK,
- "Unable to destroy layout");
-
- ck_assert(nsl_fini() == NSL_OK);
-
- css_err = css_select_ctx_destroy(css_ctx);
- ck_assert(css_err == CSS_OK);
-
- dom_node_unref(doc);
-}
-END_TEST
-
-
-void nsl_nsl_object_suite(SRunner *sr)
-{
- Suite *s = suite_create("libnslayout: nslayout object tests");
- TCase *tc_layout_basic = tcase_create("Creation/Destruction");
-
- tcase_add_test(tc_layout_basic, test_nsl_layout_create_ok);
- suite_add_tcase(s, tc_layout_basic);
-
- srunner_add_suite(sr, s);
-}
diff --git a/test/tests.c b/test/tests.c
index 9ca987c..e2edf88 100644
--- a/test/tests.c
+++ b/test/tests.c
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
#ifndef NDEBUG
nsl_assert_suite(sr);
#endif
- nsl_nsl_object_suite(sr);
+ nsl_basic_suite(sr);
srunner_set_fork_status(sr, CK_FORK);
srunner_run_all(sr, CK_ENV);
diff --git a/test/tests.h b/test/tests.h
index fd89bea..1f31da7 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -14,6 +14,6 @@
#include <libnslayout/nslayout.h>
extern void nsl_assert_suite(SRunner *);
-extern void nsl_nsl_object_suite(SRunner *);
+extern void nsl_basic_suite(SRunner *);
#endif
commitdiff
http://git.netsurf-browser.org/libnslayout.git/commit/?id=b34c357bbd4883e409a8d617c528db92bf0963c0
commit b34c357bbd4883e409a8d617c528db92bf0963c0
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Library: DOM change watching is now the job of the client.
diff --git a/src/dom/Makefile b/src/dom/Makefile
deleted file mode 100644
index 0b345cb..0000000
--- a/src/dom/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-#
-# Makefile for libnslayout
-#
-# Copyright 2015 Michael Drake <[email protected]>
-#
-# Released under the ISC License (see COPYING file)
-
-# Sources
-DIR_SOURCES := \
- debug.c \
- watcher.c
-
-include $(NSBUILD)/Makefile.subdir
diff --git a/src/dom/debug.c b/src/dom/debug.c
deleted file mode 100644
index 98a5e9b..0000000
--- a/src/dom/debug.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015-2017 Michael Drake <[email protected]>
- */
-
-/** \file src/dom/debug.c
- * DOM debug
- */
-
-#include <stdio.h>
-
-#include <dom/dom.h>
-
-#include "dom/debug.h"
-
-
-#ifdef NSL_DOM_TRACE
-
-/**
- * Convert a dom node type to a string
- *
- * \param[in] type DOM node type
- * \return appropriate string.
- */
-static inline const char *nsl__dom_node_type_to_string(dom_node_type type)
-{
- static const char *str[DOM_NODE_TYPE_COUNT] = {
- [DOM_ELEMENT_NODE] = "ELEMENT_NODE",
- [DOM_ATTRIBUTE_NODE] = "ATTRIBUTE_NODE",
- [DOM_TEXT_NODE] = "TEXT_NODE",
- [DOM_CDATA_SECTION_NODE] = "CDATA_SECTION_NODE",
- [DOM_ENTITY_REFERENCE_NODE] = "ENTITY_REFERENCE_NODE",
- [DOM_ENTITY_NODE] = "ENTITY_NODE",
- [DOM_PROCESSING_INSTRUCTION_NODE] =
"PROCESSING_INSTRUCTION_NODE",
- [DOM_COMMENT_NODE] = "COMMENT_NODE",
- [DOM_DOCUMENT_NODE] = "DOCUMENT_NODE",
- [DOM_DOCUMENT_TYPE_NODE] = "DOCUMENT_TYPE_NODE",
- [DOM_DOCUMENT_FRAGMENT_NODE] = "DOCUMENT_FRAGMENT_NODE",
- [DOM_NOTATION_NODE] = "NOTATION_NODE"
- };
-
- return str[type];
-}
-
-
-/* Exported function, documented in src/dom/debug.h */
-void nsl__dom_debug_dump_event(const struct dom_event *evt)
-{
- dom_event_target *node = NULL;
- dom_node_type node_type;
- dom_string *name = NULL;
- dom_string *type = NULL;
- dom_exception exc;
-
- printf(" DOM Event: ");
-
- /* Ugly test to see what events come out */
- exc = dom_event_get_target(evt, &node);
- if ((exc != DOM_NO_ERR) || (node == NULL)) {
- printf("FAILED to get target node!\n");
- goto fail;
- }
-
- exc = dom_node_get_node_type(node, &node_type);
- if (exc != DOM_NO_ERR) {
- printf("FAILED to get target node type!\n");
- goto fail;
- }
-
- if (node_type == DOM_ELEMENT_NODE) {
- exc = dom_node_get_node_name(node, &name);
- if ((exc != DOM_NO_ERR) || (name == NULL)) {
- printf("FAILED to get target node name!\n");
- goto fail;
- }
- }
-
- exc = dom_event_get_type(evt, &type);
- if ((exc != DOM_NO_ERR) || (type == NULL)) {
- printf("FAILED to get event type!\n");
- goto fail;
- }
-
- if (node_type == DOM_ELEMENT_NODE) {
- printf("<%s> %s",
- dom_string_data(name),
- dom_string_data(type));
- } else {
- printf("%s %s",
- nsl__dom_node_type_to_string(node_type),
- dom_string_data(type));
- }
-
-fail:
- if (type != NULL) dom_string_unref(type);
- if (name != NULL) dom_string_unref(name);
- if (node != NULL) dom_node_unref(node);
-
- printf("\n");
-}
-
-#endif
diff --git a/src/dom/debug.h b/src/dom/debug.h
deleted file mode 100644
index cbe8559..0000000
--- a/src/dom/debug.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015-2017 Michael Drake <[email protected]>
- */
-
-/** \file src/dom/debug.h
- * DOM debug
- */
-
-#ifndef nsl_dom_debug_h_
-#define nsl_dom_debug_h_
-
-/** Define to enable DOM trace debug output */
-#undef NSL_DOM_TRACE
-#define NSL_DOM_TRACE
-
-#include "util/util.h"
-
-struct dom_event;
-
-/** Don't use directly */
-void nsl__dom_debug_dump_event(const struct dom_event *evt);
-
-
-/**
- * Dump debug for dom event
- *
- * \param[in] evt Dump debug concerning a DOM event.
- */
-static inline void nsl_dom_debug_dump_event(const struct dom_event *evt)
-{
-#ifdef NSL_DOM_TRACE
- nsl__dom_debug_dump_event(evt);
-#else
- UNUSED(evt);
-#endif
-}
-
-
-#endif
diff --git a/src/dom/watcher.c b/src/dom/watcher.c
deleted file mode 100644
index db1f8a9..0000000
--- a/src/dom/watcher.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015 Michael Drake <[email protected]>
- */
-
-/** \file src/dom/watcher.c
- * Implementation of DOM mutation watching.
- *
- * TODO: LibDOM mutation event listeners are really slow.
- * Need to find a better way to get DOM change notifications.
- * LibDOM probably needs to gain Mutation Observer support, or
- * gain a LibDOM-specific extension API.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "libnslayout/nslayout.h"
-
-#include "dom/debug.h"
-#include "dom/watcher.h"
-#include "util/dom-str.h"
-#include "util/util.h"
-
-
-/**
- * A dom watcher object
- */
-struct nsl_dom_watcher {
- dom_document *document; /**< DOM document */
- dom_event_listener *listener; /**< DOM event listener object */
- nsl_dom_watcher_cb watcher_cb; /**< Client callback */
- void *pw; /**< Client data */
-};
-
-/**
- * LibDOM event handler
- *
- * \param[in] evt The LibDOM event object
- * \param[in] pw Pointer to our dom watcher object
- */
-static void nsl__dom_event_handler(struct dom_event *evt, void *pw)
-{
- const struct nsl_dom_watcher *watcher = pw;
- enum nsl_dom_watcher_type type;
- dom_event_target *node = NULL;
- dom_string *evt_type = NULL;
- dom_node_type node_type;
- dom_exception exc;
-
- nsl_dom_debug_dump_event(evt);
-
- exc = dom_event_get_target(evt, &node);
- if ((exc != DOM_NO_ERR) || (node == NULL)) {
- printf("FAILED to get target node!\n");
- goto fail;
- }
-
- exc = dom_node_get_node_type(node, &node_type);
- if (exc != DOM_NO_ERR) {
- printf("FAILED to get target node type!\n");
- goto fail;
- }
-
- exc = dom_event_get_type(evt, &evt_type);
- if ((exc != DOM_NO_ERR) || (evt_type == NULL)) {
- printf("FAILED to get event type!\n");
- goto fail;
- }
-
- if (dom_string_isequal(evt_type,
- nsl_dom_str_node_inserted)) {
- type = NSL_DOM_WATCHER_NODE_INSERTED;
-
- } else if (dom_string_isequal(evt_type,
- nsl_dom_str_node_removed)) {
- type = NSL_DOM_WATCHER_NODE_REMOVED;
-
- } else if (dom_string_isequal(evt_type,
- nsl_dom_str_subtree_modified)) {
- type = NSL_DOM_WATCHER_SUBTREE_MODIFIED;
-
- } else if (dom_string_isequal(evt_type,
- nsl_dom_str_attr_modified)) {
- type = NSL_DOM_WATCHER_ATTR_MODIFIED;
-
- } else if (dom_string_isequal(evt_type,
- nsl_dom_str_characterdata_modified)) {
- type = NSL_DOM_WATCHER_CHAR_DATA_MODIFIED;
- } else {
- printf("FAILED: unrecognised event type: '%s'",
- dom_string_data(evt_type));
- goto fail;
- }
-
- dom_string_unref(evt_type);
-
- watcher->watcher_cb(type, node, node_type, watcher->pw);
- return;
-
-fail:
- if (evt_type != NULL) dom_string_unref(evt_type);
- if (node != NULL) dom_node_unref(node);
-}
-
-
-/**
- * Destroy a DOM document's event listener
- *
- * \param[in] listener The listener to destroy
- * \param[in] document The document that the listener was registerd for.
- * \return NSL_OK on success, appropriate error otherwise.
- */
-static nsl_error nsl__dom_listener_destroy(
- dom_event_listener *listener,
- dom_document *document)
-{
- dom_exception exc;
-
- /* Passing NULL as type, removes listener for all event types. */
- exc = dom_event_target_remove_event_listener(
- document, NULL, listener, false);
- if (exc != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc);
- }
-
- dom_event_listener_unref(listener);
-
- return NSL_OK;
-}
-
-
-/**
- * Create a dom event listener.
- *
- * \param[out] listener_out Returns a dom listener for watcher's document.
- * \param[in] watcher DOM watcher object that listener is used for.
- * \return NSL_OK on success, appropriate error otherwise.
- */
-static nsl_error nsl__dom_listener_create(
- dom_event_listener **listener_out,
- const struct nsl_dom_watcher *watcher)
-{
- dom_event_listener *listener;
- dom_exception exc;
-
- /* Create listener */
- exc = dom_event_listener_create(nsl__dom_event_handler,
- (void *) watcher, &listener);
- if (exc != DOM_NO_ERR) {
- goto error;
- }
-
- /* Set the event types it should listen to */
- exc = dom_event_target_add_event_listener(watcher->document,
- nsl_dom_str_node_inserted, listener, false);
- if (exc != DOM_NO_ERR) {
- goto error;
- }
- exc = dom_event_target_add_event_listener(watcher->document,
- nsl_dom_str_subtree_modified, listener, false);
- if (exc != DOM_NO_ERR) {
- goto error;
- }
- exc = dom_event_target_add_event_listener(watcher->document,
- nsl_dom_str_node_removed, listener, false);
- if (exc != DOM_NO_ERR) {
- goto error;
- }
- exc = dom_event_target_add_event_listener(watcher->document,
- nsl_dom_str_attr_modified, listener, false);
- if (exc != DOM_NO_ERR) {
- goto error;
- }
- exc = dom_event_target_add_event_listener(watcher->document,
- nsl_dom_str_characterdata_modified, listener, false);
- if (exc != DOM_NO_ERR) {
- goto error;
- }
-
- *listener_out = listener;
- return NSL_OK;
-
-error:
- nsl__dom_listener_destroy(listener, watcher->document);
-
- return NSL_DOM_ERR(exc);
-}
-
-/* Exported function, documented in src/dom/watcher.h */
-nsl_error nsl_dom_watcher_create(
- struct nsl_dom_watcher **watcher_out,
- dom_document *document,
- nsl_dom_watcher_cb watcher_cb,
- void *pw)
-{
- struct nsl_dom_watcher *watcher;
- nsl_error err;
-
- watcher = malloc(sizeof(*watcher));
- if (watcher == NULL) {
- return NSL_NO_MEM;
- }
-
- watcher->document = document;
- watcher->watcher_cb = watcher_cb;
- watcher->pw = pw;
-
- err = nsl__dom_listener_create(&watcher->listener, watcher);
- if (err != NSL_OK) {
- free(watcher);
- return err;
- }
-
- *watcher_out = watcher;
- return NSL_OK;
-}
-
-/* Exported function, documented in src/dom/watcher.h */
-nsl_error nsl_dom_watcher_destroy(
- struct nsl_dom_watcher *watcher)
-{
- nsl__dom_listener_destroy(watcher->listener, watcher->document);
- free(watcher);
-
- return NSL_OK;
-}
diff --git a/src/dom/watcher.h b/src/dom/watcher.h
deleted file mode 100644
index 2cfa26e..0000000
--- a/src/dom/watcher.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015 Michael Drake <[email protected]>
- */
-
-/** \file src/dom/watcher.h
- * Interface to DOM mutation watching.
- */
-
-#ifndef nsl_dom_watcher_h_
-#define nsl_dom_watcher_h_
-
-struct dom_document;
-struct nsl_dom_watcher;
-
-/**
- * DOM watcher's mutation types
- */
-enum nsl_dom_watcher_type {
- NSL_DOM_WATCHER_NODE_INSERTED,
- NSL_DOM_WATCHER_NODE_REMOVED,
- NSL_DOM_WATCHER_SUBTREE_MODIFIED,
- NSL_DOM_WATCHER_ATTR_MODIFIED,
- NSL_DOM_WATCHER_CHAR_DATA_MODIFIED,
- NSL_DOM_WATCHER__COUNT,
-};
-
-
-/**
- * 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 dom watcher owner's private data.
- * \return NSL_OK on success, appropriate error otherwise.
- */
-typedef nsl_error (*nsl_dom_watcher_cb)(
- enum nsl_dom_watcher_type type,
- dom_event_target *node,
- dom_node_type node_type,
- void *pw);
-
-
-/**
- * Create DOM change watcher for a DOM document.
- *
- * \param[out] watcher_out Returns a dom watcher object for layout.
- * \param[in] document DOM document to create watcher for.
- * \param[in] watcher_cb Function to call when dom modification happens.
- * \param[in] pw Private data passed back to `watcher_cb`.
- * \return NSL_OK on success, appropriate error otherwise.
- */
-nsl_error nsl_dom_watcher_create(
- struct nsl_dom_watcher **watcher_out,
- dom_document *document,
- nsl_dom_watcher_cb watcher_cb,
- void *pw);
-
-
-/**
- * Destroy a document change DOM change watcher.
- *
- * \param[in] watcher DOM change watcher to destroy.
- * \return NSL_OK on success, appropriate error otherwise.
- */
-nsl_error nsl_dom_watcher_destroy(
- struct nsl_dom_watcher *watcher);
-
-#endif
diff --git a/src/layout.c b/src/layout.c
index 0c11660..b3b57ce 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -15,7 +15,6 @@
#include "layout.h"
#include "util/util.h"
-#include "dom/watcher.h"
#include "util/dom-str.h"
@@ -28,8 +27,6 @@ struct nsl_layout {
css_media_type *media;
nsl_callback cb;
void *pw;
-
- struct nsl_dom_watcher *watcher;
};
@@ -47,40 +44,6 @@ nsl_error nsl_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 NSL_OK on success, appropriate error otherwise.
- */
-static nsl_error 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 NSL_OK;
-}
-
-
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
nsl_error nsl_layout_create(
dom_document *doc,
@@ -91,7 +54,6 @@ nsl_error nsl_layout_create(
nsl_layout **layout)
{
nsl_layout *l = NULL;
- nsl_error err;
assert(doc != NULL);
assert(css_ctx != NULL);
@@ -110,12 +72,6 @@ nsl_error nsl_layout_create(
l->cb = cb;
l->pw = pw;
- err = nsl_dom_watcher_create(&l->watcher, l->document,
- nsl_layout_dom_watcher_cb, l);
- if (err != NSL_OK) {
- return err;
- }
-
*layout = l;
return NSL_OK;
}
@@ -125,15 +81,9 @@ nsl_error nsl_layout_create(
nsl_error nsl_layout_destroy(
nsl_layout *layout)
{
- nsl_error err;
-
assert(layout != NULL);
/* TODO: free/unref the stuff we own in the layout */
- err = nsl_dom_watcher_destroy(layout->watcher);
- if (err != NSL_OK) {
- return err;
- }
free(layout);
return NSL_OK;
diff --git a/test/dom/Makefile b/test/dom/Makefile
new file mode 100644
index 0000000..0b345cb
--- /dev/null
+++ b/test/dom/Makefile
@@ -0,0 +1,13 @@
+#
+# Makefile for libnslayout
+#
+# Copyright 2015 Michael Drake <[email protected]>
+#
+# Released under the ISC License (see COPYING file)
+
+# Sources
+DIR_SOURCES := \
+ debug.c \
+ watcher.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/test/dom/debug.c b/test/dom/debug.c
new file mode 100644
index 0000000..9e3e0b0
--- /dev/null
+++ b/test/dom/debug.c
@@ -0,0 +1,103 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015-2017 Michael Drake <[email protected]>
+ */
+
+/** \file src/dom/debug.c
+ * DOM debug
+ */
+
+#include <stdio.h>
+
+#include <dom/dom.h>
+
+#include "debug.h"
+
+
+#ifdef NSL_DOM_TRACE
+
+/**
+ * Convert a dom node type to a string
+ *
+ * \param[in] type DOM node type
+ * \return appropriate string.
+ */
+static inline const char *nsl__dom_node_type_to_string(dom_node_type type)
+{
+ static const char *str[DOM_NODE_TYPE_COUNT] = {
+ [DOM_ELEMENT_NODE] = "ELEMENT_NODE",
+ [DOM_ATTRIBUTE_NODE] = "ATTRIBUTE_NODE",
+ [DOM_TEXT_NODE] = "TEXT_NODE",
+ [DOM_CDATA_SECTION_NODE] = "CDATA_SECTION_NODE",
+ [DOM_ENTITY_REFERENCE_NODE] = "ENTITY_REFERENCE_NODE",
+ [DOM_ENTITY_NODE] = "ENTITY_NODE",
+ [DOM_PROCESSING_INSTRUCTION_NODE] =
"PROCESSING_INSTRUCTION_NODE",
+ [DOM_COMMENT_NODE] = "COMMENT_NODE",
+ [DOM_DOCUMENT_NODE] = "DOCUMENT_NODE",
+ [DOM_DOCUMENT_TYPE_NODE] = "DOCUMENT_TYPE_NODE",
+ [DOM_DOCUMENT_FRAGMENT_NODE] = "DOCUMENT_FRAGMENT_NODE",
+ [DOM_NOTATION_NODE] = "NOTATION_NODE"
+ };
+
+ return str[type];
+}
+
+
+/* Exported function, documented in src/dom/debug.h */
+void nsl__dom_debug_dump_event(const struct dom_event *evt)
+{
+ dom_event_target *node = NULL;
+ dom_node_type node_type;
+ dom_string *name = NULL;
+ dom_string *type = NULL;
+ dom_exception exc;
+
+ printf(" DOM Event: ");
+
+ /* Ugly test to see what events come out */
+ exc = dom_event_get_target(evt, &node);
+ if ((exc != DOM_NO_ERR) || (node == NULL)) {
+ printf("FAILED to get target node!\n");
+ goto fail;
+ }
+
+ exc = dom_node_get_node_type(node, &node_type);
+ if (exc != DOM_NO_ERR) {
+ printf("FAILED to get target node type!\n");
+ goto fail;
+ }
+
+ if (node_type == DOM_ELEMENT_NODE) {
+ exc = dom_node_get_node_name(node, &name);
+ if ((exc != DOM_NO_ERR) || (name == NULL)) {
+ printf("FAILED to get target node name!\n");
+ goto fail;
+ }
+ }
+
+ exc = dom_event_get_type(evt, &type);
+ if ((exc != DOM_NO_ERR) || (type == NULL)) {
+ printf("FAILED to get event type!\n");
+ goto fail;
+ }
+
+ if (node_type == DOM_ELEMENT_NODE) {
+ printf("<%s> %s",
+ dom_string_data(name),
+ dom_string_data(type));
+ } else {
+ printf("%s %s",
+ nsl__dom_node_type_to_string(node_type),
+ dom_string_data(type));
+ }
+
+fail:
+ if (type != NULL) dom_string_unref(type);
+ if (name != NULL) dom_string_unref(name);
+ if (node != NULL) dom_node_unref(node);
+
+ printf("\n");
+}
+
+#endif
diff --git a/test/dom/debug.h b/test/dom/debug.h
new file mode 100644
index 0000000..cbe8559
--- /dev/null
+++ b/test/dom/debug.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015-2017 Michael Drake <[email protected]>
+ */
+
+/** \file src/dom/debug.h
+ * DOM debug
+ */
+
+#ifndef nsl_dom_debug_h_
+#define nsl_dom_debug_h_
+
+/** Define to enable DOM trace debug output */
+#undef NSL_DOM_TRACE
+#define NSL_DOM_TRACE
+
+#include "util/util.h"
+
+struct dom_event;
+
+/** Don't use directly */
+void nsl__dom_debug_dump_event(const struct dom_event *evt);
+
+
+/**
+ * Dump debug for dom event
+ *
+ * \param[in] evt Dump debug concerning a DOM event.
+ */
+static inline void nsl_dom_debug_dump_event(const struct dom_event *evt)
+{
+#ifdef NSL_DOM_TRACE
+ nsl__dom_debug_dump_event(evt);
+#else
+ UNUSED(evt);
+#endif
+}
+
+
+#endif
diff --git a/test/dom/watcher.c b/test/dom/watcher.c
new file mode 100644
index 0000000..312dbf2
--- /dev/null
+++ b/test/dom/watcher.c
@@ -0,0 +1,231 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <[email protected]>
+ */
+
+/** \file src/dom/watcher.c
+ * Implementation of DOM mutation watching.
+ *
+ * TODO: LibDOM mutation event listeners are really slow.
+ * Need to find a better way to get DOM change notifications.
+ * LibDOM probably needs to gain Mutation Observer support, or
+ * gain a LibDOM-specific extension API.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "libnslayout/nslayout.h"
+
+#include "debug.h"
+#include "watcher.h"
+#include "util/dom-str.h"
+#include "util/util.h"
+
+
+/**
+ * A dom watcher object
+ */
+struct nsl_dom_watcher {
+ dom_document *document; /**< DOM document */
+ dom_event_listener *listener; /**< DOM event listener object */
+ nsl_dom_watcher_cb watcher_cb; /**< Client callback */
+ void *pw; /**< Client data */
+};
+
+/**
+ * LibDOM event handler
+ *
+ * \param[in] evt The LibDOM event object
+ * \param[in] pw Pointer to our dom watcher object
+ */
+static void nsl__dom_event_handler(struct dom_event *evt, void *pw)
+{
+ const struct nsl_dom_watcher *watcher = pw;
+ enum nsl_dom_watcher_type type;
+ dom_event_target *node = NULL;
+ dom_string *evt_type = NULL;
+ dom_node_type node_type;
+ dom_exception exc;
+
+ nsl_dom_debug_dump_event(evt);
+
+ exc = dom_event_get_target(evt, &node);
+ if ((exc != DOM_NO_ERR) || (node == NULL)) {
+ printf("FAILED to get target node!\n");
+ goto fail;
+ }
+
+ exc = dom_node_get_node_type(node, &node_type);
+ if (exc != DOM_NO_ERR) {
+ printf("FAILED to get target node type!\n");
+ goto fail;
+ }
+
+ exc = dom_event_get_type(evt, &evt_type);
+ if ((exc != DOM_NO_ERR) || (evt_type == NULL)) {
+ printf("FAILED to get event type!\n");
+ goto fail;
+ }
+
+ if (dom_string_isequal(evt_type,
+ nsl_dom_str_node_inserted)) {
+ type = NSL_DOM_WATCHER_NODE_INSERTED;
+
+ } else if (dom_string_isequal(evt_type,
+ nsl_dom_str_node_removed)) {
+ type = NSL_DOM_WATCHER_NODE_REMOVED;
+
+ } else if (dom_string_isequal(evt_type,
+ nsl_dom_str_subtree_modified)) {
+ type = NSL_DOM_WATCHER_SUBTREE_MODIFIED;
+
+ } else if (dom_string_isequal(evt_type,
+ nsl_dom_str_attr_modified)) {
+ type = NSL_DOM_WATCHER_ATTR_MODIFIED;
+
+ } else if (dom_string_isequal(evt_type,
+ nsl_dom_str_characterdata_modified)) {
+ type = NSL_DOM_WATCHER_CHAR_DATA_MODIFIED;
+ } else {
+ printf("FAILED: unrecognised event type: '%s'",
+ dom_string_data(evt_type));
+ goto fail;
+ }
+
+ dom_string_unref(evt_type);
+
+ watcher->watcher_cb(type, node, node_type, watcher->pw);
+ return;
+
+fail:
+ if (evt_type != NULL) dom_string_unref(evt_type);
+ if (node != NULL) dom_node_unref(node);
+}
+
+
+/**
+ * Destroy a DOM document's event listener
+ *
+ * \param[in] listener The listener to destroy
+ * \param[in] document The document that the listener was registerd for.
+ * \return NSL_OK on success, appropriate error otherwise.
+ */
+static nsl_error nsl__dom_listener_destroy(
+ dom_event_listener *listener,
+ dom_document *document)
+{
+ dom_exception exc;
+
+ /* Passing NULL as type, removes listener for all event types. */
+ exc = dom_event_target_remove_event_listener(
+ document, NULL, listener, false);
+ if (exc != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc);
+ }
+
+ dom_event_listener_unref(listener);
+
+ return NSL_OK;
+}
+
+
+/**
+ * Create a dom event listener.
+ *
+ * \param[out] listener_out Returns a dom listener for watcher's document.
+ * \param[in] watcher DOM watcher object that listener is used for.
+ * \return NSL_OK on success, appropriate error otherwise.
+ */
+static nsl_error nsl__dom_listener_create(
+ dom_event_listener **listener_out,
+ const struct nsl_dom_watcher *watcher)
+{
+ dom_event_listener *listener;
+ dom_exception exc;
+
+ /* Create listener */
+ exc = dom_event_listener_create(nsl__dom_event_handler,
+ (void *) watcher, &listener);
+ if (exc != DOM_NO_ERR) {
+ goto error;
+ }
+
+ /* Set the event types it should listen to */
+ exc = dom_event_target_add_event_listener(watcher->document,
+ nsl_dom_str_node_inserted, listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto error;
+ }
+ exc = dom_event_target_add_event_listener(watcher->document,
+ nsl_dom_str_subtree_modified, listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto error;
+ }
+ exc = dom_event_target_add_event_listener(watcher->document,
+ nsl_dom_str_node_removed, listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto error;
+ }
+ exc = dom_event_target_add_event_listener(watcher->document,
+ nsl_dom_str_attr_modified, listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto error;
+ }
+ exc = dom_event_target_add_event_listener(watcher->document,
+ nsl_dom_str_characterdata_modified, listener, false);
+ if (exc != DOM_NO_ERR) {
+ goto error;
+ }
+
+ *listener_out = listener;
+ return NSL_OK;
+
+error:
+ nsl__dom_listener_destroy(listener, watcher->document);
+
+ return NSL_DOM_ERR(exc);
+}
+
+/* Exported function, documented in src/dom/watcher.h */
+bool nsl_dom_watcher_create(
+ struct nsl_dom_watcher **watcher_out,
+ dom_document *document,
+ nsl_dom_watcher_cb watcher_cb,
+ void *pw)
+{
+ struct nsl_dom_watcher *watcher;
+ nsl_error err;
+
+ watcher = malloc(sizeof(*watcher));
+ if (watcher == NULL) {
+ return false;
+ }
+
+ watcher->document = document;
+ watcher->watcher_cb = watcher_cb;
+ watcher->pw = pw;
+
+ err = nsl__dom_listener_create(&watcher->listener, watcher);
+ if (err != NSL_OK) {
+ free(watcher);
+ return false;
+ }
+
+ *watcher_out = watcher;
+ return true;
+}
+
+/* Exported function, documented in src/dom/watcher.h */
+bool nsl_dom_watcher_destroy(
+ struct nsl_dom_watcher *watcher)
+{
+ nsl__dom_listener_destroy(watcher->listener, watcher->document);
+ free(watcher);
+
+ return true;
+}
diff --git a/test/dom/watcher.h b/test/dom/watcher.h
new file mode 100644
index 0000000..cf26a56
--- /dev/null
+++ b/test/dom/watcher.h
@@ -0,0 +1,71 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <[email protected]>
+ */
+
+/** \file src/dom/watcher.h
+ * Interface to DOM mutation watching.
+ */
+
+#ifndef nsl_dom_watcher_h_
+#define nsl_dom_watcher_h_
+
+struct dom_document;
+struct nsl_dom_watcher;
+
+/**
+ * DOM watcher's mutation types
+ */
+enum nsl_dom_watcher_type {
+ NSL_DOM_WATCHER_NODE_INSERTED,
+ NSL_DOM_WATCHER_NODE_REMOVED,
+ NSL_DOM_WATCHER_SUBTREE_MODIFIED,
+ NSL_DOM_WATCHER_ATTR_MODIFIED,
+ NSL_DOM_WATCHER_CHAR_DATA_MODIFIED,
+ NSL_DOM_WATCHER__COUNT,
+};
+
+
+/**
+ * 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 dom watcher owner's private data.
+ * \return NSL_OK on success, appropriate error otherwise.
+ */
+typedef bool (*nsl_dom_watcher_cb)(
+ enum nsl_dom_watcher_type type,
+ dom_event_target *node,
+ dom_node_type node_type,
+ void *pw);
+
+
+/**
+ * Create DOM change watcher for a DOM document.
+ *
+ * \param[out] watcher_out Returns a dom watcher object for layout.
+ * \param[in] document DOM document to create watcher for.
+ * \param[in] watcher_cb Function to call when dom modification happens.
+ * \param[in] pw Private data passed back to `watcher_cb`.
+ * \return NSL_OK on success, appropriate error otherwise.
+ */
+bool nsl_dom_watcher_create(
+ struct nsl_dom_watcher **watcher_out,
+ dom_document *document,
+ nsl_dom_watcher_cb watcher_cb,
+ void *pw);
+
+
+/**
+ * Destroy a document change DOM change watcher.
+ *
+ * \param[in] watcher DOM change watcher to destroy.
+ * \return NSL_OK on success, appropriate error otherwise.
+ */
+bool nsl_dom_watcher_destroy(
+ struct nsl_dom_watcher *watcher);
+
+#endif
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;
}
commitdiff
http://git.netsurf-browser.org/libnslayout.git/commit/?id=ecb247eb155ff5495a91e32b6e416fd0b6c6a53e
commit ecb247eb155ff5495a91e32b6e416fd0b6c6a53e
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Style: Use spaces, not tabs, for alignment.
Tabs are only allowed at the start of a line.
diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h
index ee8a428..5c09179 100644
--- a/include/libnslayout/error.h
+++ b/include/libnslayout/error.h
@@ -43,7 +43,7 @@ typedef enum nsl_error {
/**
* Get error provenance.
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return error provenance
*/
static inline nsl_error nsl_error_provenance(nsl_error err)
@@ -55,7 +55,7 @@ static inline nsl_error nsl_error_provenance(nsl_error err)
/**
* Check if error is from libnslayout
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return true iff error is from libnslayout
*/
static inline bool nsl_error_is_layout(nsl_error err)
@@ -67,7 +67,7 @@ static inline bool nsl_error_is_layout(nsl_error err)
/**
* Check if error is from libdom
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return true iff error is from libdom
*/
static inline bool nsl_error_is_libdom(nsl_error err)
@@ -78,7 +78,7 @@ static inline bool nsl_error_is_libdom(nsl_error err)
/**
* Check if error is from libcss
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return true iff error is from libcss
*/
static inline bool nsl_error_is_libcss(nsl_error err)
@@ -89,7 +89,7 @@ static inline bool nsl_error_is_libcss(nsl_error err)
/**
* Turn libnslayout return code into libnslayout error
*
- * \param[in] err Error code to convert
+ * \param[in] err Error code to convert
* \return libnslayout error
*/
static inline nsl_error nsl_error_to_layout(nsl_error err)
@@ -100,7 +100,7 @@ static inline nsl_error nsl_error_to_layout(nsl_error err)
/**
* Turn libnslayout return code into libdom error
*
- * \param[in] err Error code to convert
+ * \param[in] err Error code to convert
* \return dom exception
*/
static inline dom_exception nsl_error_to_libdom(nsl_error err)
@@ -111,7 +111,7 @@ static inline dom_exception nsl_error_to_libdom(nsl_error
err)
/**
* Turn libnslayout return code into libcss error
*
- * \param[in] err Error code to convert
+ * \param[in] err Error code to convert
* \return libcss error
*/
static inline css_error nsl_error_to_libcss(nsl_error err)
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 551e550..6a95412 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -138,7 +138,7 @@ nsl_error nsl_node_event_set_intrinsic_dimensions(
/**
* Client calls to tell NSLayout that everything requires reselection.
*
- * \param[in]layout The layout to who's selection context has changed.
+ * \param[in] layout The layout to who's selection context has changed.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_selection_context_updated(
@@ -162,9 +162,9 @@ nsl_error nsl_fini(void);
/**
* LibNSLayout client callback function
*
- * \param[in] layout The layout we're making a request for.
- * \param[in] pw The client's private data for this layout.
- * \param[in,out] req The request details.
+ * \param[in] layout The layout we're making a request for.
+ * \param[in] pw The client's private data for this layout.
+ * \param[in,out] req The request details.
* \return NSL_OK on success, appropriate error otherwise.
*/
typedef nsl_error (*nsl_callback)(
@@ -175,12 +175,12 @@ typedef nsl_error (*nsl_callback)(
/**
* Create a Layout object for a given DOM
*
- * \param[in] doc The LibDOM document to build a layout for.
- * \param[in] css_ctx The LibCSS selection context for the document.
- * \param[in] media The LibCSS media to use when selecting.
- * \param[in] cb The client's private data for this layout.
- * \param[in] pw The client's private data for this layout.
- * \param[out] layout Returns a pointer to the created layout object.
+ * \param[in] doc The LibDOM document to build a layout for.
+ * \param[in] css_ctx The LibCSS selection context for the document.
+ * \param[in] media The LibCSS media to use when selecting.
+ * \param[in] cb The client's private data for this layout.
+ * \param[in] pw The client's private data for this layout.
+ * \param[out] layout Returns a pointer to the created layout object.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_create(
@@ -194,7 +194,7 @@ nsl_error nsl_layout_create(
/**
* Destroy a Layout object
*
- * \param[in] layout Returns a pointer to the created layout object.
+ * \param[in] layout Returns a pointer to the created layout object.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_destroy(
@@ -207,10 +207,10 @@ nsl_error nsl_layout_destroy(
* data structures for the document, but will not start to position
* things and will not emit render lists.
*
- * \param[in] layout Layout to set viewport for.
- * \param[in] viewport Viewport dimensions and offset.
- * \param[in] scale Rendering scale.
- * \param[in] dpi DPI of render target with viewport.
+ * \param[in] layout Layout to set viewport for.
+ * \param[in] viewport Viewport dimensions and offset.
+ * \param[in] scale Rendering scale.
+ * \param[in] dpi DPI of render target with viewport.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_update_viewport(
@@ -222,9 +222,9 @@ nsl_error nsl_update_viewport(
/**
* Find the area occupied by element.
*
- * \param[in] layout Layout to locate an element in.
- * \param[in] element Element to get area of.
- * \param[out] area Returns area with position relative to viewport.
+ * \param[in] layout Layout to locate an element in.
+ * \param[in] element Element to get area of.
+ * \param[out] area Returns area with position relative to viewport.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_element_get_location(
@@ -235,10 +235,10 @@ nsl_error nsl_element_get_location(
/**
* Find the top-most element at a given point, in terms of z-order.
*
- * \param[in] layout Layout to find an element in.
- * \param[in] x Mouse x-coordinate (viewport relative).
- * \param[in] y Mouse y-coordinate (viewport relative).
- * \param[out] element Returns the element we found.
+ * \param[in] layout Layout to find an element in.
+ * \param[in] x Mouse x-coordinate (viewport relative).
+ * \param[in] y Mouse y-coordinate (viewport relative).
+ * \param[out] element Returns the element we found.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_element_at_point(
@@ -250,10 +250,10 @@ nsl_error nsl_element_at_point(
/**
* Mark an element (or part of it) as needing redraw.
*
- * \param[in] layout Layout to indicate redraw is required for.
- * \param[in] element Element to mark as needing redraw.
- * \param[in] rel_area Area of element to redraw relative to object's top-left.
- * May be NULL, to redraw whole element.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] element Element to mark as needing redraw.
+ * \param[in] rel_area Area of element to redraw relative to object's
top-left.
+ * May be NULL, to redraw whole element.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_dirty_element(
@@ -264,8 +264,8 @@ nsl_error nsl_layout_dirty_element(
/**
* Mark an area as needing redraw.
*
- * \param[in] layout Layout to indicate redraw is required for.
- * \param[in] area Area to redraw relative to viewport's top-left.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] area Area to redraw relative to viewport's top-left.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_dirty_area(
diff --git a/src/dom/debug.c b/src/dom/debug.c
index 468c2f7..98a5e9b 100644
--- a/src/dom/debug.c
+++ b/src/dom/debug.c
@@ -20,7 +20,7 @@
/**
* Convert a dom node type to a string
*
- * \param[in] type DOM node type
+ * \param[in] type DOM node type
* \return appropriate string.
*/
static inline const char *nsl__dom_node_type_to_string(dom_node_type type)
diff --git a/src/request.h b/src/request.h
index 7c21731..ea15147 100644
--- a/src/request.h
+++ b/src/request.h
@@ -16,9 +16,9 @@
/**
* Perform GET_RESOURCE client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] url Absolute URL to request replaced object handle for.
- * \param[out] replaced Returns the replaced element content handle.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] url Absolute URL to request replaced object handle for.
+ * \param[out] replaced Returns the replaced element content handle.
* \return NSL_OK on success, appropriate error otherwise.
*/
static inline nsl_error nsl_request_get_resource(
@@ -41,9 +41,9 @@ static inline nsl_error nsl_request_get_resource(
/**
* Perform CREATE_REPLACED client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] element DOM element that needs replacement object.
- * \param[out] replaced Returns the replaced element content handle.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] element DOM element that needs replacement object.
+ * \param[out] replaced Returns the replaced element content handle.
* \return NSL_OK on success, appropriate error otherwise.
*/
static inline nsl_error nsl_request_create_replaced(
@@ -66,8 +66,8 @@ static inline nsl_error nsl_request_create_replaced(
/**
* Perform RENDER client callback
*
- * \param[in] layout Layout object being rendered.
- * \param[in] list Render list to render.
+ * \param[in] layout Layout object being rendered.
+ * \param[in] list Render list to render.
* \return NSL_OK on success, appropriate error otherwise.
*/
static inline nsl_error nsl_request_render(
@@ -88,9 +88,9 @@ static inline nsl_error nsl_request_render(
/**
* Perform SET_EXTENTS client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] width The layout's full width.
- * \param[in] height The layout's full height.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] width The layout's full width.
+ * \param[in] height The layout's full height.
* \return NSL_OK on success, appropriate error otherwise.
*/
static inline nsl_error nsl_request_set_extents(
@@ -113,10 +113,10 @@ static inline nsl_error nsl_request_set_extents(
/**
* Perform GET_INTRINSIC_SIZE client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] replaced Replaced object to get intrinsic size of.
- * \param[out] width Returns the replaced object's width.
- * \param[out] height Returns the replaced object's height.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] replaced Replaced object to get intrinsic size of.
+ * \param[out] width Returns the replaced object's width.
+ * \param[out] height Returns the replaced object's height.
* \return NSL_OK on success, appropriate error otherwise.
*/
static inline nsl_error nsl_request_get_intrinsic_size(
commitdiff
http://git.netsurf-browser.org/libnslayout.git/commit/?id=6a783002e8b17995132fc6334b4e0900c36bf9a0
commit 6a783002e8b17995132fc6334b4e0900c36bf9a0
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Library: Use `nsl` as library namespace.
diff --git a/dev/main.c b/dev/main.c
index 77c408b..a2f9f1a 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -30,12 +30,12 @@ int main(void)
&buffer);
if (!ok) return EXIT_FAILURE;
- nslayout_init();
+ nsl_init();
ok = test_loader(buffer, CSS_MEDIA_ALL, 15);
if (!ok) return EXIT_FAILURE;
- nslayout_fini();
+ nsl_fini();
test_loader_free_buffer(buffer);
diff --git a/docs/architecture.md b/docs/architecture.md
index 63142fe..e347b24 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -169,7 +169,7 @@ resource. Since there is a non-null client resource
handle, LibNSLayout
knows it's a replaced element, and can ask the client for intrinsic dimensions.
```c
-nslayout_res nslayout_dom_event_add_element_replaced(
+nsl_res nsl_dom_event_add_element_replaced(
nslayout *layout,
dom_node *element,
nsl_resource_t *replaced,
diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h
index 5e7b87a..ee8a428 100644
--- a/include/libnslayout/error.h
+++ b/include/libnslayout/error.h
@@ -8,8 +8,8 @@
* Layout object handling
*/
-#ifndef nslayout_error_h_
-#define nslayout_error_h_
+#ifndef nsl_error_h_
+#define nsl_error_h_
#ifdef __cplusplus
extern "C"
@@ -17,27 +17,27 @@ extern "C"
#endif
/**
- * Number of bits in an `nslayout_error` that indicate the source of the error.
+ * Number of bits in an `nsl_error` that indicate the source of the error.
*/
-#define NSLAYOUT_ERROR_PROV 8
+#define NSL_ERROR_PROV 8
/**
* Libnslayout return codes
*
- * NSLAYOUT_OK indicates no error.
+ * NSL_OK indicates no error.
*/
-typedef enum nslayout_error {
+typedef enum nsl_error {
/** No error code */
- NSLAYOUT_OK = 0,
+ NSL_OK = 0,
/** Error provenance (bits 0..7) */
- NSLAYOUT_NSLAYOUT = (1 << 0),
- NSLAYOUT_LIBDOM = (1 << 1),
- NSLAYOUT_LIBCSS = (1 << 2),
+ NSL_NSLAYOUT = (1 << 0),
+ NSL_LIBDOM = (1 << 1),
+ NSL_LIBCSS = (1 << 2),
/** LibNSLayout errors (bits 8..31) */
- NSLAYOUT_NO_MEM = (1 << NSLAYOUT_ERROR_PROV) | NSLAYOUT_NSLAYOUT,
-} nslayout_error;
+ NSL_NO_MEM = (1 << NSL_ERROR_PROV) | NSL_NSLAYOUT,
+} nsl_error;
/**
@@ -46,9 +46,9 @@ typedef enum nslayout_error {
* \param[in] err Error code to test
* \return error provenance
*/
-static inline nslayout_error nslayout_error_provenance(nslayout_error err)
+static inline nsl_error nsl_error_provenance(nsl_error err)
{
- return err & ((1 << NSLAYOUT_ERROR_PROV) - 1);
+ return err & ((1 << NSL_ERROR_PROV) - 1);
}
@@ -58,9 +58,9 @@ static inline nslayout_error
nslayout_error_provenance(nslayout_error err)
* \param[in] err Error code to test
* \return true iff error is from libnslayout
*/
-static inline bool nslayout_error_is_layout(nslayout_error err)
+static inline bool nsl_error_is_layout(nsl_error err)
{
- return err & NSLAYOUT_NSLAYOUT;
+ return err & NSL_NSLAYOUT;
}
@@ -70,9 +70,9 @@ static inline bool nslayout_error_is_layout(nslayout_error
err)
* \param[in] err Error code to test
* \return true iff error is from libdom
*/
-static inline bool nslayout_error_is_libdom(nslayout_error err)
+static inline bool nsl_error_is_libdom(nsl_error err)
{
- return err & NSLAYOUT_LIBDOM;
+ return err & NSL_LIBDOM;
}
/**
@@ -81,9 +81,9 @@ static inline bool nslayout_error_is_libdom(nslayout_error
err)
* \param[in] err Error code to test
* \return true iff error is from libcss
*/
-static inline bool nslayout_error_is_libcss(nslayout_error err)
+static inline bool nsl_error_is_libcss(nsl_error err)
{
- return err & NSLAYOUT_LIBCSS;
+ return err & NSL_LIBCSS;
}
/**
@@ -92,7 +92,7 @@ static inline bool nslayout_error_is_libcss(nslayout_error
err)
* \param[in] err Error code to convert
* \return libnslayout error
*/
-static inline nslayout_error nslayout_error_to_layout(nslayout_error err)
+static inline nsl_error nsl_error_to_layout(nsl_error err)
{
return err;
}
@@ -103,7 +103,7 @@ static inline nslayout_error
nslayout_error_to_layout(nslayout_error err)
* \param[in] err Error code to convert
* \return dom exception
*/
-static inline dom_exception nslayout_error_to_libdom(nslayout_error err)
+static inline dom_exception nsl_error_to_libdom(nsl_error err)
{
return err >> 8;
}
@@ -114,7 +114,7 @@ static inline dom_exception
nslayout_error_to_libdom(nslayout_error err)
* \param[in] err Error code to convert
* \return libcss error
*/
-static inline css_error nslayout_error_to_libcss(nslayout_error err)
+static inline css_error nsl_error_to_libcss(nsl_error err)
{
return err >> 8;
}
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 62ce584..551e550 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -9,8 +9,8 @@
* Layout object handling
*/
-#ifndef nslayout_nslayout_h_
-#define nslayout_nslayout_h_
+#ifndef nsl_nslayout_h_
+#define nsl_nslayout_h_
#ifdef __cplusplus
extern "C"
@@ -23,45 +23,45 @@ extern "C"
#include <libnslayout/error.h>
/** A client-defined replaced element structure */
-typedef struct nslayout_replaced nslayout_replaced;
+typedef struct nsl_replaced nsl_replaced;
/** A rectangle */
-typedef struct nslayout_rect {
+typedef struct nsl_rect {
int x; /**< X position of left of rect in px */
int y; /**< Y position of top of rect in px */
int w; /**< Width of rect in px */
int h; /**< Height of rect in px */
-} nslayout_rect;
+} nsl_rect;
/***/
-enum nslayout_dom_node_event_type {
- NSLAYOUT_DOM_NODE_INSERTED,
- NSLAYOUT_DOM_NODE_MODIFIED,
- NSLAYOUT_DOM_NODE_REMOVED,
- NSLAYOUT_DOM_NODE__COUNT,
+enum nsl_dom_node_event_type {
+ NSL_DOM_NODE_INSERTED,
+ NSL_DOM_NODE_MODIFIED,
+ NSL_DOM_NODE_REMOVED,
+ NSL_DOM_NODE__COUNT,
};
/** Render list */
-typedef struct nslayout_render_list {
-} nslayout_render_list;
+typedef struct nsl_render_list {
+} nsl_render_list;
/** Opaque layout tree object */
-typedef struct nslayout_layout nslayout_layout;
+typedef struct nsl_layout nsl_layout;
/**
* A LibNSLayout request
* Client calls to set replaced element intrinsic dimensions.
*
- * Passed to the client via nslayout_callback
+ * Passed to the client via nsl_callback
*/
-typedef struct nslayout_request {
+typedef struct nsl_request {
/** Request type */
enum {
- NSLAYOUT_GET_RESOURCE,
- NSLAYOUT_RENDER,
- NSLAYOUT_SET_EXTENTS,
- NSLAYOUT_GET_INTRINSIC_SIZE
+ NSL_GET_RESOURCE,
+ NSL_RENDER,
+ NSL_SET_EXTENTS,
+ NSL_GET_INTRINSIC_SIZE
} type;
/** Request's type-specific parameters */
union {
@@ -69,27 +69,27 @@ typedef struct nslayout_request {
const char *url; /**< Absolute URL */
} get_resource;
struct {
- nslayout_render_list *list; /**< Render list */
+ nsl_render_list *list; /**< Render list */
} render;
struct {
unsigned int width; /**< Document width in px */
unsigned int height; /**< Document height in px */
} set_extents;
struct {
- nslayout_replaced *replaced; /** A replacement object */
+ nsl_replaced *replaced; /** A replacement object */
} get_intrinsic_size;
} request;
/** Request's type-specific return values */
union {
struct {
- nslayout_replaced **replaced; /** Replacement object */
+ nsl_replaced **replaced; /** Replacement object */
} get_resource;
struct {
unsigned int *width; /** Replacement object's width */
unsigned int *height; /** Replacement object's height */
} get_intrinsic_size;
} response;
-} nslayout_request;
+} nsl_request;
/**
@@ -98,12 +98,12 @@ typedef struct nslayout_request {
* \param[in] layout The layout requiring update for DOM change.
* \param[in] node The DOM node which is concerned in the event.
* \param[in] type The type of DOM change event.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_dom_node_event(
- nslayout_layout *layout,
+nsl_error nsl_dom_node_event(
+ nsl_layout *layout,
dom_event_target *node,
- enum nslayout_dom_node_event_type type);
+ enum nsl_dom_node_event_type type);
/**
* Client calls to set node as client-replaced.
@@ -111,12 +111,12 @@ nslayout_error nslayout_dom_node_event(
* \param[in] layout The layout to replace an element in.
* \param[in] node The DOM node which is to be replaced.
* \param[in] replaced The client's replacement object to register with node.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_node_event_set_replaced(
- nslayout_layout *layout,
+nsl_error nsl_node_event_set_replaced(
+ nsl_layout *layout,
dom_event_target *node,
- nslayout_replaced *replaced);
+ nsl_replaced *replaced);
/**
@@ -126,10 +126,10 @@ nslayout_error nslayout_node_event_set_replaced(
* \param[in] node The DOM node which is to be replaced.
* \param[in] width Width in pixels.
* \param[in] height Height in pixels.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_node_event_set_intrinsic_dimensions(
- nslayout_layout *layout,
+nsl_error nsl_node_event_set_intrinsic_dimensions(
+ nsl_layout *layout,
dom_event_target *node,
unsigned int width,
unsigned int height);
@@ -139,25 +139,25 @@ nslayout_error
nslayout_node_event_set_intrinsic_dimensions(
* Client calls to tell NSLayout that everything requires reselection.
*
* \param[in]layout The layout to who's selection context has changed.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_selection_context_updated(
- nslayout_layout *layout);
+nsl_error nsl_selection_context_updated(
+ nsl_layout *layout);
/**
* Initialise LibNSLayout
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_init(void);
+nsl_error nsl_init(void);
/**
* Finalise LibNSLayout
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_fini(void);
+nsl_error nsl_fini(void);
/**
* LibNSLayout client callback function
@@ -165,12 +165,12 @@ nslayout_error nslayout_fini(void);
* \param[in] layout The layout we're making a request for.
* \param[in] pw The client's private data for this layout.
* \param[in,out] req The request details.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-typedef nslayout_error (*nslayout_callback)(
- nslayout_layout *layout,
+typedef nsl_error (*nsl_callback)(
+ nsl_layout *layout,
void *pw,
- nslayout_request *req);
+ nsl_request *req);
/**
* Create a Layout object for a given DOM
@@ -181,24 +181,24 @@ typedef nslayout_error (*nslayout_callback)(
* \param[in] cb The client's private data for this layout.
* \param[in] pw The client's private data for this layout.
* \param[out] layout Returns a pointer to the created layout object.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_create(
+nsl_error nsl_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback cb,
+ nsl_callback cb,
void *pw,
- nslayout_layout **layout);
+ nsl_layout **layout);
/**
* Destroy a Layout object
*
* \param[in] layout Returns a pointer to the created layout object.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_destroy(
- nslayout_layout *layout);
+nsl_error nsl_layout_destroy(
+ nsl_layout *layout);
/**
* Update the viewport for a layout
@@ -211,11 +211,11 @@ nslayout_error nslayout_layout_destroy(
* \param[in] viewport Viewport dimensions and offset.
* \param[in] scale Rendering scale.
* \param[in] dpi DPI of render target with viewport.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_update_viewport(
- nslayout_layout *layout,
- nslayout_rect *viewport,
+nsl_error nsl_update_viewport(
+ nsl_layout *layout,
+ nsl_rect *viewport,
css_fixed scale,
unsigned int dpi);
@@ -225,12 +225,12 @@ nslayout_error nslayout_update_viewport(
* \param[in] layout Layout to locate an element in.
* \param[in] element Element to get area of.
* \param[out] area Returns area with position relative to viewport.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_element_get_location(
- nslayout_layout *layout,
+nsl_error nsl_element_get_location(
+ nsl_layout *layout,
dom_element *element,
- nslayout_rect *area);
+ nsl_rect *area);
/**
* Find the top-most element at a given point, in terms of z-order.
@@ -239,10 +239,10 @@ nslayout_error nslayout_element_get_location(
* \param[in] x Mouse x-coordinate (viewport relative).
* \param[in] y Mouse y-coordinate (viewport relative).
* \param[out] element Returns the element we found.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_element_at_point(
- nslayout_layout *layout,
+nsl_error nsl_element_at_point(
+ nsl_layout *layout,
unsigned int x,
unsigned int y,
dom_event_target **element);
@@ -254,23 +254,23 @@ nslayout_error nslayout_element_at_point(
* \param[in] element Element to mark as needing redraw.
* \param[in] rel_area Area of element to redraw relative to object's top-left.
* May be NULL, to redraw whole element.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_dirty_element(
- nslayout_layout *layout,
+nsl_error nsl_layout_dirty_element(
+ nsl_layout *layout,
dom_element *element,
- nslayout_rect *rel_area);
+ nsl_rect *rel_area);
/**
* Mark an area as needing redraw.
*
* \param[in] layout Layout to indicate redraw is required for.
* \param[in] area Area to redraw relative to viewport's top-left.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_dirty_area(
- nslayout_layout *layout,
- nslayout_rect *area);
+nsl_error nsl_layout_dirty_area(
+ nsl_layout *layout,
+ nsl_rect *area);
#ifdef __cplusplus
}
diff --git a/src/dom/debug.h b/src/dom/debug.h
index 7d6b186..cbe8559 100644
--- a/src/dom/debug.h
+++ b/src/dom/debug.h
@@ -8,8 +8,8 @@
* DOM debug
*/
-#ifndef nslayout_dom_debug_h_
-#define nslayout_dom_debug_h_
+#ifndef nsl_dom_debug_h_
+#define nsl_dom_debug_h_
/** Define to enable DOM trace debug output */
#undef NSL_DOM_TRACE
diff --git a/src/dom/watcher.c b/src/dom/watcher.c
index d515cf6..db1f8a9 100644
--- a/src/dom/watcher.c
+++ b/src/dom/watcher.c
@@ -113,9 +113,9 @@ fail:
*
* \param[in] listener The listener to destroy
* \param[in] document The document that the listener was registerd for.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static nslayout_error nsl__dom_listener_destroy(
+static nsl_error nsl__dom_listener_destroy(
dom_event_listener *listener,
dom_document *document)
{
@@ -130,7 +130,7 @@ static nslayout_error nsl__dom_listener_destroy(
dom_event_listener_unref(listener);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
@@ -139,9 +139,9 @@ static nslayout_error nsl__dom_listener_destroy(
*
* \param[out] listener_out Returns a dom listener for watcher's document.
* \param[in] watcher DOM watcher object that listener is used for.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static nslayout_error nsl__dom_listener_create(
+static nsl_error nsl__dom_listener_create(
dom_event_listener **listener_out,
const struct nsl_dom_watcher *watcher)
{
@@ -183,7 +183,7 @@ static nslayout_error nsl__dom_listener_create(
}
*listener_out = listener;
- return NSLAYOUT_OK;
+ return NSL_OK;
error:
nsl__dom_listener_destroy(listener, watcher->document);
@@ -192,18 +192,18 @@ error:
}
/* Exported function, documented in src/dom/watcher.h */
-nslayout_error nsl_dom_watcher_create(
+nsl_error nsl_dom_watcher_create(
struct nsl_dom_watcher **watcher_out,
dom_document *document,
nsl_dom_watcher_cb watcher_cb,
void *pw)
{
struct nsl_dom_watcher *watcher;
- nslayout_error err;
+ nsl_error err;
watcher = malloc(sizeof(*watcher));
if (watcher == NULL) {
- return NSLAYOUT_NO_MEM;
+ return NSL_NO_MEM;
}
watcher->document = document;
@@ -211,21 +211,21 @@ nslayout_error nsl_dom_watcher_create(
watcher->pw = pw;
err = nsl__dom_listener_create(&watcher->listener, watcher);
- if (err != NSLAYOUT_OK) {
+ if (err != NSL_OK) {
free(watcher);
return err;
}
*watcher_out = watcher;
- return NSLAYOUT_OK;
+ return NSL_OK;
}
/* Exported function, documented in src/dom/watcher.h */
-nslayout_error nsl_dom_watcher_destroy(
+nsl_error nsl_dom_watcher_destroy(
struct nsl_dom_watcher *watcher)
{
nsl__dom_listener_destroy(watcher->listener, watcher->document);
free(watcher);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
diff --git a/src/dom/watcher.h b/src/dom/watcher.h
index 0883fd2..2cfa26e 100644
--- a/src/dom/watcher.h
+++ b/src/dom/watcher.h
@@ -8,8 +8,8 @@
* Interface to DOM mutation watching.
*/
-#ifndef nslayout_dom_watcher_h_
-#define nslayout_dom_watcher_h_
+#ifndef nsl_dom_watcher_h_
+#define nsl_dom_watcher_h_
struct dom_document;
struct nsl_dom_watcher;
@@ -34,9 +34,9 @@ enum nsl_dom_watcher_type {
* \param[in] node The target node. (Caller yields ownership.)
* \param[in] node_type The type of node.
* \param[in] pw The dom watcher owner's private data.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-typedef nslayout_error (*nsl_dom_watcher_cb)(
+typedef nsl_error (*nsl_dom_watcher_cb)(
enum nsl_dom_watcher_type type,
dom_event_target *node,
dom_node_type node_type,
@@ -50,9 +50,9 @@ typedef nslayout_error (*nsl_dom_watcher_cb)(
* \param[in] document DOM document to create watcher for.
* \param[in] watcher_cb Function to call when dom modification happens.
* \param[in] pw Private data passed back to `watcher_cb`.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_watcher_create(
+nsl_error nsl_dom_watcher_create(
struct nsl_dom_watcher **watcher_out,
dom_document *document,
nsl_dom_watcher_cb watcher_cb,
@@ -63,9 +63,9 @@ nslayout_error nsl_dom_watcher_create(
* Destroy a document change DOM change watcher.
*
* \param[in] watcher DOM change watcher to destroy.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_watcher_destroy(
+nsl_error nsl_dom_watcher_destroy(
struct nsl_dom_watcher *watcher);
#endif
diff --git a/src/layout.c b/src/layout.c
index e4824bf..0c11660 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -22,11 +22,11 @@
/**
* The layout object for a DOM document
*/
-struct nslayout_layout {
+struct nsl_layout {
dom_document *document;
css_select_ctx *css_ctx;
css_media_type *media;
- nslayout_callback cb;
+ nsl_callback cb;
void *pw;
struct nsl_dom_watcher *watcher;
@@ -34,14 +34,14 @@ struct nslayout_layout {
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_init(void)
+nsl_error nsl_init(void)
{
return nsl_dom_str_init();
}
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_fini(void)
+nsl_error nsl_fini(void)
{
return nsl_dom_str_fini();
}
@@ -54,15 +54,15 @@ nslayout_error nslayout_fini(void)
* \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.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static nslayout_error nsl_layout_dom_watcher_cb(
+static nsl_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;
+ nsl_layout *layout = pw;
UNUSED(type);
UNUSED(layout);
@@ -77,30 +77,30 @@ static nslayout_error nsl_layout_dom_watcher_cb(
dom_node_unref(node);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_layout_create(
+nsl_error nsl_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback cb,
+ nsl_callback cb,
void *pw,
- nslayout_layout **layout)
+ nsl_layout **layout)
{
- nslayout_layout *l = NULL;
- nslayout_error err;
+ nsl_layout *l = NULL;
+ nsl_error err;
assert(doc != NULL);
assert(css_ctx != NULL);
assert(media != NULL);
assert(cb != NULL);
- l = calloc(1, sizeof(nslayout_layout));
+ l = calloc(1, sizeof(nsl_layout));
if (l == NULL) {
- return NSLAYOUT_NO_MEM;
+ return NSL_NO_MEM;
}
/* TODO: Decide: ownership will probably be passed to libnslayout */
@@ -112,29 +112,29 @@ nslayout_error nslayout_layout_create(
err = nsl_dom_watcher_create(&l->watcher, l->document,
nsl_layout_dom_watcher_cb, l);
- if (err != NSLAYOUT_OK) {
+ if (err != NSL_OK) {
return err;
}
*layout = l;
- return NSLAYOUT_OK;
+ return NSL_OK;
}
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_layout_destroy(
- nslayout_layout *layout)
+nsl_error nsl_layout_destroy(
+ nsl_layout *layout)
{
- nslayout_error err;
+ nsl_error err;
assert(layout != NULL);
/* TODO: free/unref the stuff we own in the layout */
err = nsl_dom_watcher_destroy(layout->watcher);
- if (err != NSLAYOUT_OK) {
+ if (err != NSL_OK) {
return err;
}
free(layout);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
diff --git a/src/layout.h b/src/layout.h
index d8fa3b2..22c05e4 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -8,9 +8,9 @@
* Layout object handling
*/
-#ifndef nslayout_layout_h_
-#define nslayout_layout_h_
+#ifndef nsl_layout_h_
+#define nsl_layout_h_
-struct nslayout_layout;
+struct nsl_layout;
#endif
diff --git a/src/request.h b/src/request.h
index c28468e..7c21731 100644
--- a/src/request.h
+++ b/src/request.h
@@ -8,8 +8,8 @@
* Client callback wrappers
*/
-#ifndef nslayout_request_h_
-#define nslayout_request_h_
+#ifndef nsl_request_h_
+#define nsl_request_h_
#include <libnslayout/nslayout.h>
@@ -19,17 +19,17 @@
* \param[in] layout Layout object that the request concerns.
* \param[in] url Absolute URL to request replaced object handle for.
* \param[out] replaced Returns the replaced element content handle.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_get_resource(
- nslayout_layout *layout,
+static inline nsl_error nsl_request_get_resource(
+ nsl_layout *layout,
const char *url,
- nslayout_replaced **replaced)
+ nsl_replaced **replaced)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_GET_RESOURCE;
+ req.type = NSL_GET_RESOURCE;
req.request.get_resource.url = url;
err = layout->cb(layout, layout->pw, &req);
@@ -44,17 +44,17 @@ static inline nslayout_error nsl_request_get_resource(
* \param[in] layout Layout object that the request concerns.
* \param[in] element DOM element that needs replacement object.
* \param[out] replaced Returns the replaced element content handle.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_create_replaced(
- nslayout_layout *layout,
+static inline nsl_error nsl_request_create_replaced(
+ nsl_layout *layout,
dom_element *element,
- nslayout_replaced **replaced)
+ nsl_replaced **replaced)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_CREATE_REPLACED;
+ req.type = NSL_CREATE_REPLACED;
req.request.create_replaced.element = element;
err = layout->cb(layout, layout->pw, &req);
@@ -68,16 +68,16 @@ static inline nslayout_error nsl_request_create_replaced(
*
* \param[in] layout Layout object being rendered.
* \param[in] list Render list to render.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_render(
- nslayout_layout *layout,
- nslayout_render_list *list)
+static inline nsl_error nsl_request_render(
+ nsl_layout *layout,
+ nsl_render_list *list)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_RENDER;
+ req.type = NSL_RENDER;
req.request.render.list = list;
err = layout->cb(layout, layout->pw, &req);
@@ -91,17 +91,17 @@ static inline nslayout_error nsl_request_render(
* \param[in] layout Layout object that the request concerns.
* \param[in] width The layout's full width.
* \param[in] height The layout's full height.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_set_extents(
- nslayout_layout *layout,
+static inline nsl_error nsl_request_set_extents(
+ nsl_layout *layout,
unsigned int width,
unsigned int height)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_SET_EXTENTS;
+ req.type = NSL_SET_EXTENTS;
req.request.set_extents.width = width;
req.request.set_extents.height = height;
@@ -117,18 +117,18 @@ static inline nslayout_error nsl_request_set_extents(
* \param[in] replaced Replaced object to get intrinsic size of.
* \param[out] width Returns the replaced object's width.
* \param[out] height Returns the replaced object's height.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_get_intrinsic_size(
- nslayout_layout *layout,
- nslayout_replaced *replaced,
+static inline nsl_error nsl_request_get_intrinsic_size(
+ nsl_layout *layout,
+ nsl_replaced *replaced,
unsigned int *width,
unsigned int *height)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_GET_INTRINSIC_SIZE;
+ req.type = NSL_GET_INTRINSIC_SIZE;
req.request.get_intrinsic_size.replaced = replaced;
err = layout->cb(layout, layout->pw, &req);
diff --git a/src/util/dom-str.c b/src/util/dom-str.c
index 3c0865a..db53c76 100644
--- a/src/util/dom-str.c
+++ b/src/util/dom-str.c
@@ -23,9 +23,9 @@ dom_string *nsl_dom_str_characterdata_modified;
/* Exported function, documented in src/util/dom-str.h */
-nslayout_error nsl_dom_str_init(void)
+nsl_error nsl_dom_str_init(void)
{
- nslayout_error err;
+ nsl_error err;
dom_exception exc;
exc = dom_string_create((const uint8_t *)"DOMNodeInserted",
@@ -59,7 +59,7 @@ nslayout_error nsl_dom_str_init(void)
goto out;
}
- err = NSLAYOUT_OK;
+ err = NSL_OK;
out:
if (exc != DOM_NO_ERR) {
printf("Failed to initialise dom_str!\n");
@@ -72,7 +72,7 @@ out:
/* Exported function, documented in src/util/dom-str.h */
-nslayout_error nsl_dom_str_fini(void)
+nsl_error nsl_dom_str_fini(void)
{
dom_string_unref(nsl_dom_str_node_inserted);
dom_string_unref(nsl_dom_str_node_removed);
@@ -80,5 +80,5 @@ nslayout_error nsl_dom_str_fini(void)
dom_string_unref(nsl_dom_str_attr_modified);
dom_string_unref(nsl_dom_str_characterdata_modified);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
diff --git a/src/util/dom-str.h b/src/util/dom-str.h
index 9ce7bb9..fb2d0ff 100644
--- a/src/util/dom-str.h
+++ b/src/util/dom-str.h
@@ -8,8 +8,8 @@
* Layout object handling
*/
-#ifndef nslayout_util_dom_str_h_
-#define nslayout_util_dom_str_h_
+#ifndef nsl_util_dom_str_h_
+#define nsl_util_dom_str_h_
extern dom_string *nsl_dom_str_node_inserted;
extern dom_string *nsl_dom_str_node_removed;
@@ -20,15 +20,15 @@ extern dom_string *nsl_dom_str_characterdata_modified;
/**
* Create the internal DOM strings
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_str_init(void);
+nsl_error nsl_dom_str_init(void);
/**
* Unref the internal DOM strings
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_str_fini(void);
+nsl_error nsl_dom_str_fini(void);
#endif
diff --git a/src/util/util.h b/src/util/util.h
index f63f40f..5bb661e 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -8,8 +8,8 @@
* Layout object handling
*/
-#ifndef nslayout_util_util_h_
-#define nslayout_util_util_h_
+#ifndef nsl_util_util_h_
+#define nsl_util_util_h_
#ifndef UNUSED
#define UNUSED(x_) (void)(x_)
@@ -19,7 +19,7 @@
#define SLEN(x_) (sizeof((x_)) - 1)
#endif
-#define NSL_DOM_ERR(x_) ((x_ << 8) | NSLAYOUT_LIBDOM)
-#define NSL_CSS_ERR(x_) ((x_ << 8) | NSLAYOUT_LIBCSS)
+#define NSL_DOM_ERR(x_) ((x_ << 8) | NSL_LIBDOM)
+#define NSL_CSS_ERR(x_) ((x_ << 8) | NSL_LIBCSS)
#endif
diff --git a/test/assert-tests.c b/test/assert-tests.c
index 44bc2f7..f30efed 100644
--- a/test/assert-tests.c
+++ b/test/assert-tests.c
@@ -15,34 +15,34 @@
#endif
/* TODO: Test for each individual param being NULL. */
-START_TEST (test_nslayout_layout_create_aborts1)
+START_TEST (test_nsl_layout_create_aborts1)
{
- nslayout_layout *layout;
+ nsl_layout *layout;
- (void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
+ (void) nsl_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
}
END_TEST
/* TODO: Test for each individual param being NULL. */
-START_TEST (test_nslayout_layout_destroy_aborts1)
+START_TEST (test_nsl_layout_destroy_aborts1)
{
- (void) nslayout_layout_destroy(NULL);
+ (void) nsl_layout_destroy(NULL);
}
END_TEST
-void nslayout_assert_suite(SRunner *sr)
+void nsl_assert_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: API Assert tests");
TCase *tc_assert = tcase_create("Creation/Destruction");
tcase_add_test_raise_signal(
tc_assert,
- test_nslayout_layout_create_aborts1,
+ test_nsl_layout_create_aborts1,
SIGABRT);
tcase_add_test_raise_signal(
tc_assert,
- test_nslayout_layout_destroy_aborts1,
+ test_nsl_layout_destroy_aborts1,
SIGABRT);
suite_add_tcase(s, tc_assert);
diff --git a/test/nslayout-object-tests.c b/test/nslayout-object-tests.c
index 612a983..4a3f2c4 100644
--- a/test/nslayout-object-tests.c
+++ b/test/nslayout-object-tests.c
@@ -14,21 +14,21 @@
#define UNUSED(x) (void)(x)
#endif
-static nslayout_error nslayout_test_callback(
- nslayout_layout *layout,
+static nsl_error nsl_test_callback(
+ nsl_layout *layout,
void *pw,
- nslayout_request *req)
+ nsl_request *req)
{
UNUSED(req);
UNUSED(layout);
UNUSED(pw);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
-START_TEST (test_nslayout_layout_create_ok)
+START_TEST (test_nsl_layout_create_ok)
{
- nslayout_layout *layout = NULL;
- nslayout_error error;
+ nsl_layout *layout = NULL;
+ nsl_error error;
dom_exception dom_error;
css_error css_err;
dom_document *doc;
@@ -44,24 +44,24 @@ START_TEST (test_nslayout_layout_create_ok)
css_err = css_select_ctx_create(&css_ctx);
ck_assert(css_err == CSS_OK);
- ck_assert(nslayout_init() == NSLAYOUT_OK);
+ ck_assert(nsl_init() == NSL_OK);
- error = nslayout_layout_create(doc,
+ error = nsl_layout_create(doc,
css_ctx,
&media,
- nslayout_test_callback,
+ nsl_test_callback,
NULL,
&layout);
- fail_unless(error == NSLAYOUT_OK,
+ fail_unless(error == NSL_OK,
"Unable to create layout");
fail_unless(layout != NULL,
"Returned OK but str was still NULL");
- error = nslayout_layout_destroy(layout);
- fail_unless(error == NSLAYOUT_OK,
+ error = nsl_layout_destroy(layout);
+ fail_unless(error == NSL_OK,
"Unable to destroy layout");
- ck_assert(nslayout_fini() == NSLAYOUT_OK);
+ ck_assert(nsl_fini() == NSL_OK);
css_err = css_select_ctx_destroy(css_ctx);
ck_assert(css_err == CSS_OK);
@@ -71,12 +71,12 @@ START_TEST (test_nslayout_layout_create_ok)
END_TEST
-void nslayout_nslayout_object_suite(SRunner *sr)
+void nsl_nsl_object_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: nslayout object tests");
TCase *tc_layout_basic = tcase_create("Creation/Destruction");
- tcase_add_test(tc_layout_basic, test_nslayout_layout_create_ok);
+ tcase_add_test(tc_layout_basic, test_nsl_layout_create_ok);
suite_add_tcase(s, tc_layout_basic);
srunner_add_suite(sr, s);
diff --git a/test/test-loader.c b/test/test-loader.c
index 6d52691..cab08d6 100644
--- a/test/test-loader.c
+++ b/test/test-loader.c
@@ -19,15 +19,15 @@
#define UNUSED(x) (void)(x)
#endif
-static nslayout_error test_loader_nslayout_test_callback(
- nslayout_layout *layout,
+static nsl_error test_loader_nsl_test_callback(
+ nsl_layout *layout,
void *pw,
- nslayout_request *req)
+ nsl_request *req)
{
UNUSED(req);
UNUSED(layout);
UNUSED(pw);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
struct test_loader_buffer {
@@ -293,8 +293,8 @@ static bool test_loader(
css_media_type media,
size_t chunk_size)
{
- nslayout_layout *layout = NULL;
- nslayout_error error;
+ nsl_layout *layout = NULL;
+ nsl_error error;
struct test_loader_ctx load_ctx;
bool complete = false;
bool ret = false;
@@ -320,13 +320,13 @@ static bool test_loader(
}
printf("Creating nsl layout\n");
- error = nslayout_layout_create(load_ctx.doc,
+ error = nsl_layout_create(load_ctx.doc,
load_ctx.css_ctx,
&media,
- test_loader_nslayout_test_callback,
+ test_loader_nsl_test_callback,
NULL,
&layout);
- if (error != NSLAYOUT_OK) {
+ if (error != NSL_OK) {
goto fail;
}
@@ -340,13 +340,13 @@ static bool test_loader(
}
printf("Destroying layout\n");
- error = nslayout_layout_destroy(layout);
+ error = nsl_layout_destroy(layout);
layout = NULL;
- ret = (error == NSLAYOUT_OK);
+ ret = (error == NSL_OK);
fail:
if (layout != NULL) {
- nslayout_layout_destroy(layout);
+ nsl_layout_destroy(layout);
}
test_loader_css_fini(&load_ctx);
dom_node_unref(load_ctx.doc);
diff --git a/test/tests.c b/test/tests.c
index 48fc68c..9ca987c 100644
--- a/test/tests.c
+++ b/test/tests.c
@@ -38,9 +38,9 @@ int main(int argc, char **argv)
sr = srunner_create(suite_create("Test suite for libnslayout"));
#ifndef NDEBUG
- nslayout_assert_suite(sr);
+ nsl_assert_suite(sr);
#endif
- nslayout_nslayout_object_suite(sr);
+ nsl_nsl_object_suite(sr);
srunner_set_fork_status(sr, CK_FORK);
srunner_run_all(sr, CK_ENV);
diff --git a/test/tests.h b/test/tests.h
index 9f05d9c..fd89bea 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -4,8 +4,8 @@
* Copyright 2015 Michael Drake <[email protected]>
*/
-#ifndef nslayout_tests_h_
-#define nslayout_tests_h_
+#ifndef nsl_tests_h_
+#define nsl_tests_h_
#include <signal.h>
@@ -13,7 +13,7 @@
#include <libnslayout/nslayout.h>
-extern void nslayout_assert_suite(SRunner *);
-extern void nslayout_nslayout_object_suite(SRunner *);
+extern void nsl_assert_suite(SRunner *);
+extern void nsl_nsl_object_suite(SRunner *);
#endif
-----------------------------------------------------------------------
Summary of changes:
dev/main.c | 4 +-
docs/architecture.md | 2 +-
include/libnslayout/error.h | 60 +++----
include/libnslayout/nslayout.h | 198 +++++++++++------------
src/Makefile | 2 +-
src/layout.c | 78 ++-------
src/layout.h | 6 +-
src/request.h | 102 ++++++------
src/util/dom-str.c | 10 +-
src/util/dom-str.h | 12 +-
src/util/util.h | 8 +-
test/Makefile | 2 +-
test/assert-tests.c | 16 +-
test/{nslayout-object-tests.c => basic-tests.c} | 32 ++--
{src => test}/dom/Makefile | 0
{src => test}/dom/debug.c | 4 +-
{src => test}/dom/debug.h | 4 +-
{src => test}/dom/watcher.c | 32 ++--
{src => test}/dom/watcher.h | 16 +-
test/test-loader.c | 99 ++++++++----
test/tests.c | 4 +-
test/tests.h | 8 +-
22 files changed, 340 insertions(+), 359 deletions(-)
rename test/{nslayout-object-tests.c => basic-tests.c} (68%)
rename {src => test}/dom/Makefile (100%)
rename {src => test}/dom/debug.c (97%)
rename {src => test}/dom/debug.h (92%)
rename {src => test}/dom/watcher.c (91%)
rename {src => test}/dom/watcher.h (80%)
diff --git a/dev/main.c b/dev/main.c
index 77c408b..a2f9f1a 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -30,12 +30,12 @@ int main(void)
&buffer);
if (!ok) return EXIT_FAILURE;
- nslayout_init();
+ nsl_init();
ok = test_loader(buffer, CSS_MEDIA_ALL, 15);
if (!ok) return EXIT_FAILURE;
- nslayout_fini();
+ nsl_fini();
test_loader_free_buffer(buffer);
diff --git a/docs/architecture.md b/docs/architecture.md
index 63142fe..e347b24 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -169,7 +169,7 @@ resource. Since there is a non-null client resource
handle, LibNSLayout
knows it's a replaced element, and can ask the client for intrinsic dimensions.
```c
-nslayout_res nslayout_dom_event_add_element_replaced(
+nsl_res nsl_dom_event_add_element_replaced(
nslayout *layout,
dom_node *element,
nsl_resource_t *replaced,
diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h
index 5e7b87a..5c09179 100644
--- a/include/libnslayout/error.h
+++ b/include/libnslayout/error.h
@@ -8,8 +8,8 @@
* Layout object handling
*/
-#ifndef nslayout_error_h_
-#define nslayout_error_h_
+#ifndef nsl_error_h_
+#define nsl_error_h_
#ifdef __cplusplus
extern "C"
@@ -17,82 +17,82 @@ extern "C"
#endif
/**
- * Number of bits in an `nslayout_error` that indicate the source of the error.
+ * Number of bits in an `nsl_error` that indicate the source of the error.
*/
-#define NSLAYOUT_ERROR_PROV 8
+#define NSL_ERROR_PROV 8
/**
* Libnslayout return codes
*
- * NSLAYOUT_OK indicates no error.
+ * NSL_OK indicates no error.
*/
-typedef enum nslayout_error {
+typedef enum nsl_error {
/** No error code */
- NSLAYOUT_OK = 0,
+ NSL_OK = 0,
/** Error provenance (bits 0..7) */
- NSLAYOUT_NSLAYOUT = (1 << 0),
- NSLAYOUT_LIBDOM = (1 << 1),
- NSLAYOUT_LIBCSS = (1 << 2),
+ NSL_NSLAYOUT = (1 << 0),
+ NSL_LIBDOM = (1 << 1),
+ NSL_LIBCSS = (1 << 2),
/** LibNSLayout errors (bits 8..31) */
- NSLAYOUT_NO_MEM = (1 << NSLAYOUT_ERROR_PROV) | NSLAYOUT_NSLAYOUT,
-} nslayout_error;
+ NSL_NO_MEM = (1 << NSL_ERROR_PROV) | NSL_NSLAYOUT,
+} nsl_error;
/**
* Get error provenance.
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return error provenance
*/
-static inline nslayout_error nslayout_error_provenance(nslayout_error err)
+static inline nsl_error nsl_error_provenance(nsl_error err)
{
- return err & ((1 << NSLAYOUT_ERROR_PROV) - 1);
+ return err & ((1 << NSL_ERROR_PROV) - 1);
}
/**
* Check if error is from libnslayout
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return true iff error is from libnslayout
*/
-static inline bool nslayout_error_is_layout(nslayout_error err)
+static inline bool nsl_error_is_layout(nsl_error err)
{
- return err & NSLAYOUT_NSLAYOUT;
+ return err & NSL_NSLAYOUT;
}
/**
* Check if error is from libdom
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return true iff error is from libdom
*/
-static inline bool nslayout_error_is_libdom(nslayout_error err)
+static inline bool nsl_error_is_libdom(nsl_error err)
{
- return err & NSLAYOUT_LIBDOM;
+ return err & NSL_LIBDOM;
}
/**
* Check if error is from libcss
*
- * \param[in] err Error code to test
+ * \param[in] err Error code to test
* \return true iff error is from libcss
*/
-static inline bool nslayout_error_is_libcss(nslayout_error err)
+static inline bool nsl_error_is_libcss(nsl_error err)
{
- return err & NSLAYOUT_LIBCSS;
+ return err & NSL_LIBCSS;
}
/**
* Turn libnslayout return code into libnslayout error
*
- * \param[in] err Error code to convert
+ * \param[in] err Error code to convert
* \return libnslayout error
*/
-static inline nslayout_error nslayout_error_to_layout(nslayout_error err)
+static inline nsl_error nsl_error_to_layout(nsl_error err)
{
return err;
}
@@ -100,10 +100,10 @@ static inline nslayout_error
nslayout_error_to_layout(nslayout_error err)
/**
* Turn libnslayout return code into libdom error
*
- * \param[in] err Error code to convert
+ * \param[in] err Error code to convert
* \return dom exception
*/
-static inline dom_exception nslayout_error_to_libdom(nslayout_error err)
+static inline dom_exception nsl_error_to_libdom(nsl_error err)
{
return err >> 8;
}
@@ -111,10 +111,10 @@ static inline dom_exception
nslayout_error_to_libdom(nslayout_error err)
/**
* Turn libnslayout return code into libcss error
*
- * \param[in] err Error code to convert
+ * \param[in] err Error code to convert
* \return libcss error
*/
-static inline css_error nslayout_error_to_libcss(nslayout_error err)
+static inline css_error nsl_error_to_libcss(nsl_error err)
{
return err >> 8;
}
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 62ce584..6a95412 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -9,8 +9,8 @@
* Layout object handling
*/
-#ifndef nslayout_nslayout_h_
-#define nslayout_nslayout_h_
+#ifndef nsl_nslayout_h_
+#define nsl_nslayout_h_
#ifdef __cplusplus
extern "C"
@@ -23,45 +23,45 @@ extern "C"
#include <libnslayout/error.h>
/** A client-defined replaced element structure */
-typedef struct nslayout_replaced nslayout_replaced;
+typedef struct nsl_replaced nsl_replaced;
/** A rectangle */
-typedef struct nslayout_rect {
+typedef struct nsl_rect {
int x; /**< X position of left of rect in px */
int y; /**< Y position of top of rect in px */
int w; /**< Width of rect in px */
int h; /**< Height of rect in px */
-} nslayout_rect;
+} nsl_rect;
/***/
-enum nslayout_dom_node_event_type {
- NSLAYOUT_DOM_NODE_INSERTED,
- NSLAYOUT_DOM_NODE_MODIFIED,
- NSLAYOUT_DOM_NODE_REMOVED,
- NSLAYOUT_DOM_NODE__COUNT,
+enum nsl_dom_node_event_type {
+ NSL_DOM_NODE_INSERTED,
+ NSL_DOM_NODE_MODIFIED,
+ NSL_DOM_NODE_REMOVED,
+ NSL_DOM_NODE__COUNT,
};
/** Render list */
-typedef struct nslayout_render_list {
-} nslayout_render_list;
+typedef struct nsl_render_list {
+} nsl_render_list;
/** Opaque layout tree object */
-typedef struct nslayout_layout nslayout_layout;
+typedef struct nsl_layout nsl_layout;
/**
* A LibNSLayout request
* Client calls to set replaced element intrinsic dimensions.
*
- * Passed to the client via nslayout_callback
+ * Passed to the client via nsl_callback
*/
-typedef struct nslayout_request {
+typedef struct nsl_request {
/** Request type */
enum {
- NSLAYOUT_GET_RESOURCE,
- NSLAYOUT_RENDER,
- NSLAYOUT_SET_EXTENTS,
- NSLAYOUT_GET_INTRINSIC_SIZE
+ NSL_GET_RESOURCE,
+ NSL_RENDER,
+ NSL_SET_EXTENTS,
+ NSL_GET_INTRINSIC_SIZE
} type;
/** Request's type-specific parameters */
union {
@@ -69,27 +69,27 @@ typedef struct nslayout_request {
const char *url; /**< Absolute URL */
} get_resource;
struct {
- nslayout_render_list *list; /**< Render list */
+ nsl_render_list *list; /**< Render list */
} render;
struct {
unsigned int width; /**< Document width in px */
unsigned int height; /**< Document height in px */
} set_extents;
struct {
- nslayout_replaced *replaced; /** A replacement object */
+ nsl_replaced *replaced; /** A replacement object */
} get_intrinsic_size;
} request;
/** Request's type-specific return values */
union {
struct {
- nslayout_replaced **replaced; /** Replacement object */
+ nsl_replaced **replaced; /** Replacement object */
} get_resource;
struct {
unsigned int *width; /** Replacement object's width */
unsigned int *height; /** Replacement object's height */
} get_intrinsic_size;
} response;
-} nslayout_request;
+} nsl_request;
/**
@@ -98,12 +98,12 @@ typedef struct nslayout_request {
* \param[in] layout The layout requiring update for DOM change.
* \param[in] node The DOM node which is concerned in the event.
* \param[in] type The type of DOM change event.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_dom_node_event(
- nslayout_layout *layout,
+nsl_error nsl_dom_node_event(
+ nsl_layout *layout,
dom_event_target *node,
- enum nslayout_dom_node_event_type type);
+ enum nsl_dom_node_event_type type);
/**
* Client calls to set node as client-replaced.
@@ -111,12 +111,12 @@ nslayout_error nslayout_dom_node_event(
* \param[in] layout The layout to replace an element in.
* \param[in] node The DOM node which is to be replaced.
* \param[in] replaced The client's replacement object to register with node.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_node_event_set_replaced(
- nslayout_layout *layout,
+nsl_error nsl_node_event_set_replaced(
+ nsl_layout *layout,
dom_event_target *node,
- nslayout_replaced *replaced);
+ nsl_replaced *replaced);
/**
@@ -126,10 +126,10 @@ nslayout_error nslayout_node_event_set_replaced(
* \param[in] node The DOM node which is to be replaced.
* \param[in] width Width in pixels.
* \param[in] height Height in pixels.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_node_event_set_intrinsic_dimensions(
- nslayout_layout *layout,
+nsl_error nsl_node_event_set_intrinsic_dimensions(
+ nsl_layout *layout,
dom_event_target *node,
unsigned int width,
unsigned int height);
@@ -138,67 +138,67 @@ nslayout_error
nslayout_node_event_set_intrinsic_dimensions(
/**
* Client calls to tell NSLayout that everything requires reselection.
*
- * \param[in]layout The layout to who's selection context has changed.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout The layout to who's selection context has changed.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_selection_context_updated(
- nslayout_layout *layout);
+nsl_error nsl_selection_context_updated(
+ nsl_layout *layout);
/**
* Initialise LibNSLayout
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_init(void);
+nsl_error nsl_init(void);
/**
* Finalise LibNSLayout
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_fini(void);
+nsl_error nsl_fini(void);
/**
* LibNSLayout client callback function
*
- * \param[in] layout The layout we're making a request for.
- * \param[in] pw The client's private data for this layout.
- * \param[in,out] req The request details.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout The layout we're making a request for.
+ * \param[in] pw The client's private data for this layout.
+ * \param[in,out] req The request details.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-typedef nslayout_error (*nslayout_callback)(
- nslayout_layout *layout,
+typedef nsl_error (*nsl_callback)(
+ nsl_layout *layout,
void *pw,
- nslayout_request *req);
+ nsl_request *req);
/**
* Create a Layout object for a given DOM
*
- * \param[in] doc The LibDOM document to build a layout for.
- * \param[in] css_ctx The LibCSS selection context for the document.
- * \param[in] media The LibCSS media to use when selecting.
- * \param[in] cb The client's private data for this layout.
- * \param[in] pw The client's private data for this layout.
- * \param[out] layout Returns a pointer to the created layout object.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] doc The LibDOM document to build a layout for.
+ * \param[in] css_ctx The LibCSS selection context for the document.
+ * \param[in] media The LibCSS media to use when selecting.
+ * \param[in] cb The client's private data for this layout.
+ * \param[in] pw The client's private data for this layout.
+ * \param[out] layout Returns a pointer to the created layout object.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_create(
+nsl_error nsl_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback cb,
+ nsl_callback cb,
void *pw,
- nslayout_layout **layout);
+ nsl_layout **layout);
/**
* Destroy a Layout object
*
- * \param[in] layout Returns a pointer to the created layout object.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Returns a pointer to the created layout object.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_destroy(
- nslayout_layout *layout);
+nsl_error nsl_layout_destroy(
+ nsl_layout *layout);
/**
* Update the viewport for a layout
@@ -207,42 +207,42 @@ nslayout_error nslayout_layout_destroy(
* data structures for the document, but will not start to position
* things and will not emit render lists.
*
- * \param[in] layout Layout to set viewport for.
- * \param[in] viewport Viewport dimensions and offset.
- * \param[in] scale Rendering scale.
- * \param[in] dpi DPI of render target with viewport.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout to set viewport for.
+ * \param[in] viewport Viewport dimensions and offset.
+ * \param[in] scale Rendering scale.
+ * \param[in] dpi DPI of render target with viewport.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_update_viewport(
- nslayout_layout *layout,
- nslayout_rect *viewport,
+nsl_error nsl_update_viewport(
+ nsl_layout *layout,
+ nsl_rect *viewport,
css_fixed scale,
unsigned int dpi);
/**
* Find the area occupied by element.
*
- * \param[in] layout Layout to locate an element in.
- * \param[in] element Element to get area of.
- * \param[out] area Returns area with position relative to viewport.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout to locate an element in.
+ * \param[in] element Element to get area of.
+ * \param[out] area Returns area with position relative to viewport.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_element_get_location(
- nslayout_layout *layout,
+nsl_error nsl_element_get_location(
+ nsl_layout *layout,
dom_element *element,
- nslayout_rect *area);
+ nsl_rect *area);
/**
* Find the top-most element at a given point, in terms of z-order.
*
- * \param[in] layout Layout to find an element in.
- * \param[in] x Mouse x-coordinate (viewport relative).
- * \param[in] y Mouse y-coordinate (viewport relative).
- * \param[out] element Returns the element we found.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout to find an element in.
+ * \param[in] x Mouse x-coordinate (viewport relative).
+ * \param[in] y Mouse y-coordinate (viewport relative).
+ * \param[out] element Returns the element we found.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_element_at_point(
- nslayout_layout *layout,
+nsl_error nsl_element_at_point(
+ nsl_layout *layout,
unsigned int x,
unsigned int y,
dom_event_target **element);
@@ -250,27 +250,27 @@ nslayout_error nslayout_element_at_point(
/**
* Mark an element (or part of it) as needing redraw.
*
- * \param[in] layout Layout to indicate redraw is required for.
- * \param[in] element Element to mark as needing redraw.
- * \param[in] rel_area Area of element to redraw relative to object's top-left.
- * May be NULL, to redraw whole element.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] element Element to mark as needing redraw.
+ * \param[in] rel_area Area of element to redraw relative to object's
top-left.
+ * May be NULL, to redraw whole element.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_dirty_element(
- nslayout_layout *layout,
+nsl_error nsl_layout_dirty_element(
+ nsl_layout *layout,
dom_element *element,
- nslayout_rect *rel_area);
+ nsl_rect *rel_area);
/**
* Mark an area as needing redraw.
*
- * \param[in] layout Layout to indicate redraw is required for.
- * \param[in] area Area to redraw relative to viewport's top-left.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] area Area to redraw relative to viewport's top-left.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nslayout_layout_dirty_area(
- nslayout_layout *layout,
- nslayout_rect *area);
+nsl_error nsl_layout_dirty_area(
+ nsl_layout *layout,
+ nsl_rect *area);
#ifdef __cplusplus
}
diff --git a/src/Makefile b/src/Makefile
index 7a6251d..b02f0b9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := layout.c
+DIR_SOURCES := layout.c node.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/layout.c b/src/layout.c
index e4824bf..b3b57ce 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -15,92 +15,54 @@
#include "layout.h"
#include "util/util.h"
-#include "dom/watcher.h"
#include "util/dom-str.h"
/**
* The layout object for a DOM document
*/
-struct nslayout_layout {
+struct nsl_layout {
dom_document *document;
css_select_ctx *css_ctx;
css_media_type *media;
- nslayout_callback cb;
+ nsl_callback cb;
void *pw;
-
- struct nsl_dom_watcher *watcher;
};
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_init(void)
+nsl_error nsl_init(void)
{
return nsl_dom_str_init();
}
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_fini(void)
+nsl_error nsl_fini(void)
{
return nsl_dom_str_fini();
}
-/**
- * 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(
+nsl_error nsl_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback cb,
+ nsl_callback cb,
void *pw,
- nslayout_layout **layout)
+ nsl_layout **layout)
{
- nslayout_layout *l = NULL;
- nslayout_error err;
+ nsl_layout *l = NULL;
assert(doc != NULL);
assert(css_ctx != NULL);
assert(media != NULL);
assert(cb != NULL);
- l = calloc(1, sizeof(nslayout_layout));
+ l = calloc(1, sizeof(nsl_layout));
if (l == NULL) {
- return NSLAYOUT_NO_MEM;
+ return NSL_NO_MEM;
}
/* TODO: Decide: ownership will probably be passed to libnslayout */
@@ -110,31 +72,19 @@ nslayout_error nslayout_layout_create(
l->cb = cb;
l->pw = pw;
- err = nsl_dom_watcher_create(&l->watcher, l->document,
- nsl_layout_dom_watcher_cb, l);
- if (err != NSLAYOUT_OK) {
- return err;
- }
-
*layout = l;
- return NSLAYOUT_OK;
+ return NSL_OK;
}
/* Publically exported function, documented in include/libnslayout/nslayout.h
*/
-nslayout_error nslayout_layout_destroy(
- nslayout_layout *layout)
+nsl_error nsl_layout_destroy(
+ nsl_layout *layout)
{
- nslayout_error err;
-
assert(layout != NULL);
/* TODO: free/unref the stuff we own in the layout */
- err = nsl_dom_watcher_destroy(layout->watcher);
- if (err != NSLAYOUT_OK) {
- return err;
- }
free(layout);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
diff --git a/src/layout.h b/src/layout.h
index d8fa3b2..22c05e4 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -8,9 +8,9 @@
* Layout object handling
*/
-#ifndef nslayout_layout_h_
-#define nslayout_layout_h_
+#ifndef nsl_layout_h_
+#define nsl_layout_h_
-struct nslayout_layout;
+struct nsl_layout;
#endif
diff --git a/src/request.h b/src/request.h
index c28468e..ea15147 100644
--- a/src/request.h
+++ b/src/request.h
@@ -8,28 +8,28 @@
* Client callback wrappers
*/
-#ifndef nslayout_request_h_
-#define nslayout_request_h_
+#ifndef nsl_request_h_
+#define nsl_request_h_
#include <libnslayout/nslayout.h>
/**
* Perform GET_RESOURCE client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] url Absolute URL to request replaced object handle for.
- * \param[out] replaced Returns the replaced element content handle.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] url Absolute URL to request replaced object handle for.
+ * \param[out] replaced Returns the replaced element content handle.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_get_resource(
- nslayout_layout *layout,
+static inline nsl_error nsl_request_get_resource(
+ nsl_layout *layout,
const char *url,
- nslayout_replaced **replaced)
+ nsl_replaced **replaced)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_GET_RESOURCE;
+ req.type = NSL_GET_RESOURCE;
req.request.get_resource.url = url;
err = layout->cb(layout, layout->pw, &req);
@@ -41,20 +41,20 @@ static inline nslayout_error nsl_request_get_resource(
/**
* Perform CREATE_REPLACED client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] element DOM element that needs replacement object.
- * \param[out] replaced Returns the replaced element content handle.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] element DOM element that needs replacement object.
+ * \param[out] replaced Returns the replaced element content handle.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_create_replaced(
- nslayout_layout *layout,
+static inline nsl_error nsl_request_create_replaced(
+ nsl_layout *layout,
dom_element *element,
- nslayout_replaced **replaced)
+ nsl_replaced **replaced)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_CREATE_REPLACED;
+ req.type = NSL_CREATE_REPLACED;
req.request.create_replaced.element = element;
err = layout->cb(layout, layout->pw, &req);
@@ -66,18 +66,18 @@ static inline nslayout_error nsl_request_create_replaced(
/**
* Perform RENDER client callback
*
- * \param[in] layout Layout object being rendered.
- * \param[in] list Render list to render.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout object being rendered.
+ * \param[in] list Render list to render.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_render(
- nslayout_layout *layout,
- nslayout_render_list *list)
+static inline nsl_error nsl_request_render(
+ nsl_layout *layout,
+ nsl_render_list *list)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_RENDER;
+ req.type = NSL_RENDER;
req.request.render.list = list;
err = layout->cb(layout, layout->pw, &req);
@@ -88,20 +88,20 @@ static inline nslayout_error nsl_request_render(
/**
* Perform SET_EXTENTS client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] width The layout's full width.
- * \param[in] height The layout's full height.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] width The layout's full width.
+ * \param[in] height The layout's full height.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_set_extents(
- nslayout_layout *layout,
+static inline nsl_error nsl_request_set_extents(
+ nsl_layout *layout,
unsigned int width,
unsigned int height)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_SET_EXTENTS;
+ req.type = NSL_SET_EXTENTS;
req.request.set_extents.width = width;
req.request.set_extents.height = height;
@@ -113,22 +113,22 @@ static inline nslayout_error nsl_request_set_extents(
/**
* Perform GET_INTRINSIC_SIZE client callback
*
- * \param[in] layout Layout object that the request concerns.
- * \param[in] replaced Replaced object to get intrinsic size of.
- * \param[out] width Returns the replaced object's width.
- * \param[out] height Returns the replaced object's height.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] replaced Replaced object to get intrinsic size of.
+ * \param[out] width Returns the replaced object's width.
+ * \param[out] height Returns the replaced object's height.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static inline nslayout_error nsl_request_get_intrinsic_size(
- nslayout_layout *layout,
- nslayout_replaced *replaced,
+static inline nsl_error nsl_request_get_intrinsic_size(
+ nsl_layout *layout,
+ nsl_replaced *replaced,
unsigned int *width,
unsigned int *height)
{
- nslayout_error err;
- nslayout_request req;
+ nsl_error err;
+ nsl_request req;
- req.type = NSLAYOUT_GET_INTRINSIC_SIZE;
+ req.type = NSL_GET_INTRINSIC_SIZE;
req.request.get_intrinsic_size.replaced = replaced;
err = layout->cb(layout, layout->pw, &req);
diff --git a/src/util/dom-str.c b/src/util/dom-str.c
index 3c0865a..db53c76 100644
--- a/src/util/dom-str.c
+++ b/src/util/dom-str.c
@@ -23,9 +23,9 @@ dom_string *nsl_dom_str_characterdata_modified;
/* Exported function, documented in src/util/dom-str.h */
-nslayout_error nsl_dom_str_init(void)
+nsl_error nsl_dom_str_init(void)
{
- nslayout_error err;
+ nsl_error err;
dom_exception exc;
exc = dom_string_create((const uint8_t *)"DOMNodeInserted",
@@ -59,7 +59,7 @@ nslayout_error nsl_dom_str_init(void)
goto out;
}
- err = NSLAYOUT_OK;
+ err = NSL_OK;
out:
if (exc != DOM_NO_ERR) {
printf("Failed to initialise dom_str!\n");
@@ -72,7 +72,7 @@ out:
/* Exported function, documented in src/util/dom-str.h */
-nslayout_error nsl_dom_str_fini(void)
+nsl_error nsl_dom_str_fini(void)
{
dom_string_unref(nsl_dom_str_node_inserted);
dom_string_unref(nsl_dom_str_node_removed);
@@ -80,5 +80,5 @@ nslayout_error nsl_dom_str_fini(void)
dom_string_unref(nsl_dom_str_attr_modified);
dom_string_unref(nsl_dom_str_characterdata_modified);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
diff --git a/src/util/dom-str.h b/src/util/dom-str.h
index 9ce7bb9..fb2d0ff 100644
--- a/src/util/dom-str.h
+++ b/src/util/dom-str.h
@@ -8,8 +8,8 @@
* Layout object handling
*/
-#ifndef nslayout_util_dom_str_h_
-#define nslayout_util_dom_str_h_
+#ifndef nsl_util_dom_str_h_
+#define nsl_util_dom_str_h_
extern dom_string *nsl_dom_str_node_inserted;
extern dom_string *nsl_dom_str_node_removed;
@@ -20,15 +20,15 @@ extern dom_string *nsl_dom_str_characterdata_modified;
/**
* Create the internal DOM strings
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_str_init(void);
+nsl_error nsl_dom_str_init(void);
/**
* Unref the internal DOM strings
*
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_str_fini(void);
+nsl_error nsl_dom_str_fini(void);
#endif
diff --git a/src/util/util.h b/src/util/util.h
index f63f40f..5bb661e 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -8,8 +8,8 @@
* Layout object handling
*/
-#ifndef nslayout_util_util_h_
-#define nslayout_util_util_h_
+#ifndef nsl_util_util_h_
+#define nsl_util_util_h_
#ifndef UNUSED
#define UNUSED(x_) (void)(x_)
@@ -19,7 +19,7 @@
#define SLEN(x_) (sizeof((x_)) - 1)
#endif
-#define NSL_DOM_ERR(x_) ((x_ << 8) | NSLAYOUT_LIBDOM)
-#define NSL_CSS_ERR(x_) ((x_ << 8) | NSLAYOUT_LIBCSS)
+#define NSL_DOM_ERR(x_) ((x_ << 8) | NSL_LIBDOM)
+#define NSL_CSS_ERR(x_) ((x_ << 8) | NSL_LIBCSS)
#endif
diff --git a/test/Makefile b/test/Makefile
index 967d8da..feb4d77 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,3 @@
-DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;nslayout-object-tests.c
+DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;basic-tests.c
include $(NSBUILD)/Makefile.subdir
diff --git a/test/assert-tests.c b/test/assert-tests.c
index 44bc2f7..f30efed 100644
--- a/test/assert-tests.c
+++ b/test/assert-tests.c
@@ -15,34 +15,34 @@
#endif
/* TODO: Test for each individual param being NULL. */
-START_TEST (test_nslayout_layout_create_aborts1)
+START_TEST (test_nsl_layout_create_aborts1)
{
- nslayout_layout *layout;
+ nsl_layout *layout;
- (void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
+ (void) nsl_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
}
END_TEST
/* TODO: Test for each individual param being NULL. */
-START_TEST (test_nslayout_layout_destroy_aborts1)
+START_TEST (test_nsl_layout_destroy_aborts1)
{
- (void) nslayout_layout_destroy(NULL);
+ (void) nsl_layout_destroy(NULL);
}
END_TEST
-void nslayout_assert_suite(SRunner *sr)
+void nsl_assert_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: API Assert tests");
TCase *tc_assert = tcase_create("Creation/Destruction");
tcase_add_test_raise_signal(
tc_assert,
- test_nslayout_layout_create_aborts1,
+ test_nsl_layout_create_aborts1,
SIGABRT);
tcase_add_test_raise_signal(
tc_assert,
- test_nslayout_layout_destroy_aborts1,
+ test_nsl_layout_destroy_aborts1,
SIGABRT);
suite_add_tcase(s, tc_assert);
diff --git a/test/nslayout-object-tests.c b/test/basic-tests.c
similarity index 68%
rename from test/nslayout-object-tests.c
rename to test/basic-tests.c
index 612a983..c4be121 100644
--- a/test/nslayout-object-tests.c
+++ b/test/basic-tests.c
@@ -14,21 +14,21 @@
#define UNUSED(x) (void)(x)
#endif
-static nslayout_error nslayout_test_callback(
- nslayout_layout *layout,
+static nsl_error nsl_test_callback(
+ nsl_layout *layout,
void *pw,
- nslayout_request *req)
+ nsl_request *req)
{
UNUSED(req);
UNUSED(layout);
UNUSED(pw);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
-START_TEST (test_nslayout_layout_create_ok)
+START_TEST (test_nsl_layout_create_ok)
{
- nslayout_layout *layout = NULL;
- nslayout_error error;
+ nsl_layout *layout = NULL;
+ nsl_error error;
dom_exception dom_error;
css_error css_err;
dom_document *doc;
@@ -44,24 +44,24 @@ START_TEST (test_nslayout_layout_create_ok)
css_err = css_select_ctx_create(&css_ctx);
ck_assert(css_err == CSS_OK);
- ck_assert(nslayout_init() == NSLAYOUT_OK);
+ ck_assert(nsl_init() == NSL_OK);
- error = nslayout_layout_create(doc,
+ error = nsl_layout_create(doc,
css_ctx,
&media,
- nslayout_test_callback,
+ nsl_test_callback,
NULL,
&layout);
- fail_unless(error == NSLAYOUT_OK,
+ fail_unless(error == NSL_OK,
"Unable to create layout");
fail_unless(layout != NULL,
"Returned OK but str was still NULL");
- error = nslayout_layout_destroy(layout);
- fail_unless(error == NSLAYOUT_OK,
+ error = nsl_layout_destroy(layout);
+ fail_unless(error == NSL_OK,
"Unable to destroy layout");
- ck_assert(nslayout_fini() == NSLAYOUT_OK);
+ ck_assert(nsl_fini() == NSL_OK);
css_err = css_select_ctx_destroy(css_ctx);
ck_assert(css_err == CSS_OK);
@@ -71,12 +71,12 @@ START_TEST (test_nslayout_layout_create_ok)
END_TEST
-void nslayout_nslayout_object_suite(SRunner *sr)
+void nsl_basic_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: nslayout object tests");
TCase *tc_layout_basic = tcase_create("Creation/Destruction");
- tcase_add_test(tc_layout_basic, test_nslayout_layout_create_ok);
+ tcase_add_test(tc_layout_basic, test_nsl_layout_create_ok);
suite_add_tcase(s, tc_layout_basic);
srunner_add_suite(sr, s);
diff --git a/src/dom/Makefile b/test/dom/Makefile
similarity index 100%
rename from src/dom/Makefile
rename to test/dom/Makefile
diff --git a/src/dom/debug.c b/test/dom/debug.c
similarity index 97%
rename from src/dom/debug.c
rename to test/dom/debug.c
index 468c2f7..9e3e0b0 100644
--- a/src/dom/debug.c
+++ b/test/dom/debug.c
@@ -12,7 +12,7 @@
#include <dom/dom.h>
-#include "dom/debug.h"
+#include "debug.h"
#ifdef NSL_DOM_TRACE
@@ -20,7 +20,7 @@
/**
* Convert a dom node type to a string
*
- * \param[in] type DOM node type
+ * \param[in] type DOM node type
* \return appropriate string.
*/
static inline const char *nsl__dom_node_type_to_string(dom_node_type type)
diff --git a/src/dom/debug.h b/test/dom/debug.h
similarity index 92%
rename from src/dom/debug.h
rename to test/dom/debug.h
index 7d6b186..cbe8559 100644
--- a/src/dom/debug.h
+++ b/test/dom/debug.h
@@ -8,8 +8,8 @@
* DOM debug
*/
-#ifndef nslayout_dom_debug_h_
-#define nslayout_dom_debug_h_
+#ifndef nsl_dom_debug_h_
+#define nsl_dom_debug_h_
/** Define to enable DOM trace debug output */
#undef NSL_DOM_TRACE
diff --git a/src/dom/watcher.c b/test/dom/watcher.c
similarity index 91%
rename from src/dom/watcher.c
rename to test/dom/watcher.c
index d515cf6..312dbf2 100644
--- a/src/dom/watcher.c
+++ b/test/dom/watcher.c
@@ -21,8 +21,8 @@
#include "libnslayout/nslayout.h"
-#include "dom/debug.h"
-#include "dom/watcher.h"
+#include "debug.h"
+#include "watcher.h"
#include "util/dom-str.h"
#include "util/util.h"
@@ -113,9 +113,9 @@ fail:
*
* \param[in] listener The listener to destroy
* \param[in] document The document that the listener was registerd for.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static nslayout_error nsl__dom_listener_destroy(
+static nsl_error nsl__dom_listener_destroy(
dom_event_listener *listener,
dom_document *document)
{
@@ -130,7 +130,7 @@ static nslayout_error nsl__dom_listener_destroy(
dom_event_listener_unref(listener);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
@@ -139,9 +139,9 @@ static nslayout_error nsl__dom_listener_destroy(
*
* \param[out] listener_out Returns a dom listener for watcher's document.
* \param[in] watcher DOM watcher object that listener is used for.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-static nslayout_error nsl__dom_listener_create(
+static nsl_error nsl__dom_listener_create(
dom_event_listener **listener_out,
const struct nsl_dom_watcher *watcher)
{
@@ -183,7 +183,7 @@ static nslayout_error nsl__dom_listener_create(
}
*listener_out = listener;
- return NSLAYOUT_OK;
+ return NSL_OK;
error:
nsl__dom_listener_destroy(listener, watcher->document);
@@ -192,18 +192,18 @@ error:
}
/* Exported function, documented in src/dom/watcher.h */
-nslayout_error nsl_dom_watcher_create(
+bool nsl_dom_watcher_create(
struct nsl_dom_watcher **watcher_out,
dom_document *document,
nsl_dom_watcher_cb watcher_cb,
void *pw)
{
struct nsl_dom_watcher *watcher;
- nslayout_error err;
+ nsl_error err;
watcher = malloc(sizeof(*watcher));
if (watcher == NULL) {
- return NSLAYOUT_NO_MEM;
+ return false;
}
watcher->document = document;
@@ -211,21 +211,21 @@ nslayout_error nsl_dom_watcher_create(
watcher->pw = pw;
err = nsl__dom_listener_create(&watcher->listener, watcher);
- if (err != NSLAYOUT_OK) {
+ if (err != NSL_OK) {
free(watcher);
- return err;
+ return false;
}
*watcher_out = watcher;
- return NSLAYOUT_OK;
+ return true;
}
/* Exported function, documented in src/dom/watcher.h */
-nslayout_error nsl_dom_watcher_destroy(
+bool nsl_dom_watcher_destroy(
struct nsl_dom_watcher *watcher)
{
nsl__dom_listener_destroy(watcher->listener, watcher->document);
free(watcher);
- return NSLAYOUT_OK;
+ return true;
}
diff --git a/src/dom/watcher.h b/test/dom/watcher.h
similarity index 80%
rename from src/dom/watcher.h
rename to test/dom/watcher.h
index 0883fd2..cf26a56 100644
--- a/src/dom/watcher.h
+++ b/test/dom/watcher.h
@@ -8,8 +8,8 @@
* Interface to DOM mutation watching.
*/
-#ifndef nslayout_dom_watcher_h_
-#define nslayout_dom_watcher_h_
+#ifndef nsl_dom_watcher_h_
+#define nsl_dom_watcher_h_
struct dom_document;
struct nsl_dom_watcher;
@@ -34,9 +34,9 @@ enum nsl_dom_watcher_type {
* \param[in] node The target node. (Caller yields ownership.)
* \param[in] node_type The type of node.
* \param[in] pw The dom watcher owner's private data.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-typedef nslayout_error (*nsl_dom_watcher_cb)(
+typedef bool (*nsl_dom_watcher_cb)(
enum nsl_dom_watcher_type type,
dom_event_target *node,
dom_node_type node_type,
@@ -50,9 +50,9 @@ typedef nslayout_error (*nsl_dom_watcher_cb)(
* \param[in] document DOM document to create watcher for.
* \param[in] watcher_cb Function to call when dom modification happens.
* \param[in] pw Private data passed back to `watcher_cb`.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_watcher_create(
+bool nsl_dom_watcher_create(
struct nsl_dom_watcher **watcher_out,
dom_document *document,
nsl_dom_watcher_cb watcher_cb,
@@ -63,9 +63,9 @@ nslayout_error nsl_dom_watcher_create(
* Destroy a document change DOM change watcher.
*
* \param[in] watcher DOM change watcher to destroy.
- * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ * \return NSL_OK on success, appropriate error otherwise.
*/
-nslayout_error nsl_dom_watcher_destroy(
+bool nsl_dom_watcher_destroy(
struct nsl_dom_watcher *watcher);
#endif
diff --git a/test/test-loader.c b/test/test-loader.c
index 6d52691..5cbd788 100644
--- a/test/test-loader.c
+++ b/test/test-loader.c
@@ -15,19 +15,21 @@
#include <libnslayout/nslayout.h>
+#include "dom/watcher.h"
+
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
-static nslayout_error test_loader_nslayout_test_callback(
- nslayout_layout *layout,
+static nsl_error test_loader_nsl_test_callback(
+ nsl_layout *layout,
void *pw,
- nslayout_request *req)
+ nsl_request *req)
{
UNUSED(req);
UNUSED(layout);
UNUSED(pw);
- return NSLAYOUT_OK;
+ return NSL_OK;
}
struct test_loader_buffer {
@@ -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;
}
@@ -293,8 +310,8 @@ static bool test_loader(
css_media_type media,
size_t chunk_size)
{
- nslayout_layout *layout = NULL;
- nslayout_error error;
+ nsl_layout *layout = NULL;
+ nsl_error error;
struct test_loader_ctx load_ctx;
bool complete = false;
bool ret = false;
@@ -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");
@@ -320,13 +344,13 @@ static bool test_loader(
}
printf("Creating nsl layout\n");
- error = nslayout_layout_create(load_ctx.doc,
+ error = nsl_layout_create(load_ctx.doc,
load_ctx.css_ctx,
&media,
- test_loader_nslayout_test_callback,
+ test_loader_nsl_test_callback,
NULL,
&layout);
- if (error != NSLAYOUT_OK) {
+ if (error != NSL_OK) {
goto fail;
}
@@ -340,17 +364,24 @@ static bool test_loader(
}
printf("Destroying layout\n");
- error = nslayout_layout_destroy(layout);
+ error = nsl_layout_destroy(layout);
layout = NULL;
- ret = (error == NSLAYOUT_OK);
+ ret = (error == NSL_OK);
fail:
if (layout != NULL) {
- nslayout_layout_destroy(layout);
+ 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;
}
diff --git a/test/tests.c b/test/tests.c
index 48fc68c..e2edf88 100644
--- a/test/tests.c
+++ b/test/tests.c
@@ -38,9 +38,9 @@ int main(int argc, char **argv)
sr = srunner_create(suite_create("Test suite for libnslayout"));
#ifndef NDEBUG
- nslayout_assert_suite(sr);
+ nsl_assert_suite(sr);
#endif
- nslayout_nslayout_object_suite(sr);
+ nsl_basic_suite(sr);
srunner_set_fork_status(sr, CK_FORK);
srunner_run_all(sr, CK_ENV);
diff --git a/test/tests.h b/test/tests.h
index 9f05d9c..1f31da7 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -4,8 +4,8 @@
* Copyright 2015 Michael Drake <[email protected]>
*/
-#ifndef nslayout_tests_h_
-#define nslayout_tests_h_
+#ifndef nsl_tests_h_
+#define nsl_tests_h_
#include <signal.h>
@@ -13,7 +13,7 @@
#include <libnslayout/nslayout.h>
-extern void nslayout_assert_suite(SRunner *);
-extern void nslayout_nslayout_object_suite(SRunner *);
+extern void nsl_assert_suite(SRunner *);
+extern void nsl_basic_suite(SRunner *);
#endif
--
NetSurf Layout Engine
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org