summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2017-02-04 22:53:14 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2017-02-04 22:53:14 (GMT)
commitf3983f3743eebf1006877527b9e787e1189ebed1 (patch)
tree5d2c0881707b7f5b57da2cb903b66029bc095b2b
parentbba349d0729f12f1631c776e9581d6feb39d314d (diff)
downloadlibnslayout-f3983f3743eebf1006877527b9e787e1189ebed1.tar.gz
libnslayout-f3983f3743eebf1006877527b9e787e1189ebed1.tar.bz2
dom debug: Split watcher event dump out into debug module.
-rw-r--r--src/dom/Makefile4
-rw-r--r--src/dom/debug.c103
-rw-r--r--src/dom/debug.h41
-rw-r--r--src/dom/watcher.c81
4 files changed, 150 insertions, 79 deletions
diff --git a/src/dom/Makefile b/src/dom/Makefile
index 0baa497..0b345cb 100644
--- a/src/dom/Makefile
+++ b/src/dom/Makefile
@@ -6,6 +6,8 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := watcher.c
+DIR_SOURCES := \
+ debug.c \
+ watcher.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/dom/debug.c b/src/dom/debug.c
new file mode 100644
index 0000000..468c2f7
--- a/dev/null
+++ b/src/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 <tlsa@netsurf-browser.org>
+ */
+
+/** \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
new file mode 100644
index 0000000..7d6b186
--- a/dev/null
+++ b/src/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 <tlsa@netsurf-browser.org>
+ */
+
+/** \file src/dom/debug.h
+ * DOM debug
+ */
+
+#ifndef nslayout_dom_debug_h_
+#define nslayout_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
index 0788354..7de4f31 100644
--- a/src/dom/watcher.c
+++ b/src/dom/watcher.c
@@ -14,37 +14,12 @@
#include <string.h>
#include "layout.h"
+#include "dom/debug.h"
#include "dom/watcher.h"
#include "util/dom-str.h"
#include "util/util.h"
/**
- * Convert a dom node type to a string
- *
- * \param[in] type DOM node type
- * \return appropriate string.
- */
-static 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];
-}
-
-/**
* LibDOM event handler
*
* \param[in] evt The LibDOM event object
@@ -52,52 +27,9 @@ static const char *nsl__dom_node_type_to_string(dom_node_type type)
*/
static void nsl__dom_event_handler(struct dom_event *evt, void *pw)
{
- dom_event_target *node = NULL;
- dom_node_type node_type;
- dom_string *name = NULL;
- dom_string *type = NULL;
- dom_exception exc;
-
UNUSED(pw);
- 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));
- }
+ nsl_dom_debug_dump_event(evt);
/* TODO: Based on event type:
* 1. call to do (re)selection:
@@ -105,16 +37,9 @@ static void nsl__dom_event_handler(struct dom_event *evt, void *pw)
* b. just this node?
* 2. call to update layout, if needed.
*/
-
-fail:
- if (type != NULL) dom_string_unref(type);
- if (name != NULL) dom_string_unref(name);
- if (node != NULL) dom_node_unref(node);
-
- printf("\n");
}
-/* Exported function, documented in src/dom/event.h */
+/* Exported function, documented in src/dom/watcher.h */
nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout)
{
dom_exception exc;