libnslayout: branch master updated. 94a7c5432f68b1f86c85747ae4689a4f433661c0
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/94a7c5432f68b1f86...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/94a7c5432f68b1f86c8...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/94a7c5432f68b1f86c857...
The branch, master has been updated
via 94a7c5432f68b1f86c85747ae4689a4f433661c0 (commit)
from e1cc804ada3b839ef3cdb71d4a3e2f5e74705908 (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=94a7c5432f68b1f...
commit 94a7c5432f68b1f86c85747ae4689a4f433661c0
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Improve documentation and naming for DOM change watcher.
diff --git a/src/dom/Makefile b/src/dom/Makefile
index 30e1847..0baa497 100644
--- a/src/dom/Makefile
+++ b/src/dom/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := event.c
+DIR_SOURCES := watcher.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/dom/event.c b/src/dom/event.c
deleted file mode 100644
index e24b699..0000000
--- a/src/dom/event.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
- */
-
-/** \file src/dom/event.c
- * DOM mutation handling
- */
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "layout.h"
-#include "dom/event.h"
-#include "util/dom-str.h"
-#include "util/util.h"
-
-static const char *nsl__dom_node_type_to_string(dom_node_type type)
-{
- const char *str[] = {
- "ELEMENT_NODE",
- "ATTRIBUTE_NODE",
- "TEXT_NODE",
- "CDATA_SECTION_NODE",
- "ENTITY_REFERENCE_NODE",
- "ENTITY_NODE",
- "PROCESSING_INSTRUCTION_NODE",
- "COMMENT_NODE",
- "DOCUMENT_NODE",
- "DOCUMENT_TYPE_NODE",
- "DOCUMENT_FRAGMENT_NODE",
- "NOTATION_NODE"
- };
- assert(DOM_NODE_TYPE_COUNT == 12);
-
- return str[type - 1];
-}
-
-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));
- }
-
-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 */
-nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
-{
- nslayout_error err;
- dom_exception exc;
-
- /* TODO: LibDOM event listeners are really slow. Need to find a better
- * way to get DOM change notifications.
- */
-
- exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
- layout, &layout->listener);
- if (exc != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc);
- }
- exc = dom_event_target_add_event_listener(
- layout->doc, nsl_dom_str_node_inserted,
- layout->listener, false);
- if (exc != DOM_NO_ERR) {
- err = NSL_DOM_ERR(exc);
- goto fail;
- }
- exc = dom_event_target_add_event_listener(
- layout->doc, nsl_dom_str_subtree_modified,
- layout->listener, false);
- if (exc != DOM_NO_ERR) {
- (void) dom_event_target_remove_event_listener(
- layout->doc, nsl_dom_str_node_inserted,
- layout->listener, false);
- err = NSL_DOM_ERR(exc);
- goto fail;
- }
-
- return NSLAYOUT_OK;
-
-fail:
- dom_event_listener_unref(layout->listener);
- layout->listener = NULL;
-
- return err;
-}
-
-/* Exported function, documented in src/dom/event.h */
-nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
-{
- dom_exception exc1, exc2;
-
- exc1 = dom_event_target_remove_event_listener(
- layout->doc, nsl_dom_str_node_inserted,
- layout->listener, false);
- exc2 = dom_event_target_remove_event_listener(
- layout->doc, nsl_dom_str_subtree_modified,
- layout->listener, false);
-
- if (exc1 != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc1);
- }
- if (exc2 != DOM_NO_ERR) {
- return NSL_DOM_ERR(exc2);
- }
-
- dom_event_listener_unref(layout->listener);
- layout->listener = NULL;
-
- return NSLAYOUT_OK;
-}
diff --git a/src/dom/event.h b/src/dom/event.h
deleted file mode 100644
index f519f40..0000000
--- a/src/dom/event.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
- */
-
-/** \file src/dom/event.h
- * Layout object handling
- */
-
-#ifndef nslayout_dom_event_h_
-#define nslayout_dom_event_h_
-
-#include <libnslayout/nslayout.h>
-
-nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout);
-nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout);
-
-#endif
diff --git a/src/dom/watcher.c b/src/dom/watcher.c
new file mode 100644
index 0000000..a4e8d64
--- /dev/null
+++ b/src/dom/watcher.c
@@ -0,0 +1,176 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/dom/watcher.c
+ * DOM mutation handling
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "layout.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)
+{
+ const char *str[] = {
+ "ELEMENT_NODE",
+ "ATTRIBUTE_NODE",
+ "TEXT_NODE",
+ "CDATA_SECTION_NODE",
+ "ENTITY_REFERENCE_NODE",
+ "ENTITY_NODE",
+ "PROCESSING_INSTRUCTION_NODE",
+ "COMMENT_NODE",
+ "DOCUMENT_NODE",
+ "DOCUMENT_TYPE_NODE",
+ "DOCUMENT_FRAGMENT_NODE",
+ "NOTATION_NODE"
+ };
+ assert(DOM_NODE_TYPE_COUNT == 12);
+
+ return str[type - 1];
+}
+
+/**
+ * LibDOM event handler
+ *
+ * \param[in] evt The LibDOM event object
+ * \param[in] pw Pointer to our nslayout_layout object
+ */
+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));
+ }
+
+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 */
+nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout)
+{
+ nslayout_error err;
+ dom_exception exc;
+
+ /* TODO: LibDOM event listeners are really slow. Need to find a better
+ * way to get DOM change notifications.
+ */
+
+ exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
+ layout, &layout->listener);
+ if (exc != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc);
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ err = NSL_DOM_ERR(exc);
+ goto fail;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ err = NSL_DOM_ERR(exc);
+ goto fail;
+ }
+
+ return NSLAYOUT_OK;
+
+fail:
+ dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
+
+ return err;
+}
+
+/* Exported function, documented in src/dom/event.h */
+nslayout_error nsl_dom_watcher_remove_for_layout(nslayout_layout *layout)
+{
+ dom_exception exc1, exc2;
+
+ exc1 = dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ exc2 = dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+
+ if (exc1 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc1);
+ }
+ if (exc2 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc2);
+ }
+
+ dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
+
+ return NSLAYOUT_OK;
+}
diff --git a/src/dom/watcher.h b/src/dom/watcher.h
new file mode 100644
index 0000000..87f0a1b
--- /dev/null
+++ b/src/dom/watcher.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/dom/watcher.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_dom_watcher_h_
+#define nslayout_dom_watcher_h_
+
+#include <libnslayout/nslayout.h>
+
+/**
+ * Add DOM change watchers to the layout's document.'
+ *
+ * \param[in] layout nslayout_layout object to set watchers for.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout);
+
+/**
+ * Remove DOM change watchers from the layout's document.
+ *
+ * \param[in] layout nslayout_layout object remove watchers from.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_watcher_remove_for_layout(nslayout_layout *layout);
+
+#endif
diff --git a/src/layout.c b/src/layout.c
index f1a1490..1c341b6 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -13,7 +13,7 @@
#include <stdio.h>
#include "layout.h"
-#include "dom/event.h"
+#include "dom/watcher.h"
#include "util/dom-str.h"
@@ -62,7 +62,7 @@ nslayout_error nslayout_layout_create(
l->pw = pw;
/* TODO: error handling */
- nsl_dom_event_layout_init(l);
+ nsl_dom_watcher_add_for_layout(l);
*layout = l;
return NSLAYOUT_OK;
@@ -77,7 +77,7 @@ nslayout_error nslayout_layout_destroy(
/* TODO: free/unref the stuff we own in the layout */
/* TODO: error handling */
- nsl_dom_event_layout_fini(layout);
+ nsl_dom_watcher_remove_for_layout(layout);
free(layout);
return NSLAYOUT_OK;
-----------------------------------------------------------------------
Summary of changes:
src/dom/Makefile | 2 +-
src/dom/event.h | 19 -------------------
src/dom/{event.c => watcher.c} | 20 ++++++++++++++++----
src/dom/watcher.h | 32 ++++++++++++++++++++++++++++++++
src/layout.c | 6 +++---
5 files changed, 52 insertions(+), 27 deletions(-)
delete mode 100644 src/dom/event.h
rename src/dom/{event.c => watcher.c} (88%)
create mode 100644 src/dom/watcher.h
diff --git a/src/dom/Makefile b/src/dom/Makefile
index 30e1847..0baa497 100644
--- a/src/dom/Makefile
+++ b/src/dom/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := event.c
+DIR_SOURCES := watcher.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/dom/event.h b/src/dom/event.h
deleted file mode 100644
index f519f40..0000000
--- a/src/dom/event.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * This file is part of LibNSLayout
- * Licensed under the ISC License, http://opensource.org/licenses/ISC
- * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
- */
-
-/** \file src/dom/event.h
- * Layout object handling
- */
-
-#ifndef nslayout_dom_event_h_
-#define nslayout_dom_event_h_
-
-#include <libnslayout/nslayout.h>
-
-nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout);
-nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout);
-
-#endif
diff --git a/src/dom/event.c b/src/dom/watcher.c
similarity index 88%
rename from src/dom/event.c
rename to src/dom/watcher.c
index e24b699..a4e8d64 100644
--- a/src/dom/event.c
+++ b/src/dom/watcher.c
@@ -4,7 +4,7 @@
* Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
*/
-/** \file src/dom/event.c
+/** \file src/dom/watcher.c
* DOM mutation handling
*/
@@ -14,10 +14,16 @@
#include <string.h>
#include "layout.h"
-#include "dom/event.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)
{
const char *str[] = {
@@ -39,6 +45,12 @@ static const char *nsl__dom_node_type_to_string(dom_node_type type)
return str[type - 1];
}
+/**
+ * LibDOM event handler
+ *
+ * \param[in] evt The LibDOM event object
+ * \param[in] pw Pointer to our nslayout_layout object
+ */
static void nsl__dom_event_handler(struct dom_event *evt, void *pw)
{
dom_event_target *node = NULL;
@@ -97,7 +109,7 @@ fail:
}
/* Exported function, documented in src/dom/event.h */
-nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
+nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout)
{
nslayout_error err;
dom_exception exc;
@@ -139,7 +151,7 @@ fail:
}
/* Exported function, documented in src/dom/event.h */
-nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
+nslayout_error nsl_dom_watcher_remove_for_layout(nslayout_layout *layout)
{
dom_exception exc1, exc2;
diff --git a/src/dom/watcher.h b/src/dom/watcher.h
new file mode 100644
index 0000000..87f0a1b
--- /dev/null
+++ b/src/dom/watcher.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/dom/watcher.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_dom_watcher_h_
+#define nslayout_dom_watcher_h_
+
+#include <libnslayout/nslayout.h>
+
+/**
+ * Add DOM change watchers to the layout's document.'
+ *
+ * \param[in] layout nslayout_layout object to set watchers for.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_watcher_add_for_layout(nslayout_layout *layout);
+
+/**
+ * Remove DOM change watchers from the layout's document.
+ *
+ * \param[in] layout nslayout_layout object remove watchers from.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_watcher_remove_for_layout(nslayout_layout *layout);
+
+#endif
diff --git a/src/layout.c b/src/layout.c
index f1a1490..1c341b6 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -13,7 +13,7 @@
#include <stdio.h>
#include "layout.h"
-#include "dom/event.h"
+#include "dom/watcher.h"
#include "util/dom-str.h"
@@ -62,7 +62,7 @@ nslayout_error nslayout_layout_create(
l->pw = pw;
/* TODO: error handling */
- nsl_dom_event_layout_init(l);
+ nsl_dom_watcher_add_for_layout(l);
*layout = l;
return NSLAYOUT_OK;
@@ -77,7 +77,7 @@ nslayout_error nslayout_layout_destroy(
/* TODO: free/unref the stuff we own in the layout */
/* TODO: error handling */
- nsl_dom_event_layout_fini(layout);
+ nsl_dom_watcher_remove_for_layout(layout);
free(layout);
return NSLAYOUT_OK;
--
NetSurf Layout Engine
7 years, 6 months
libnslayout: branch master updated. e1cc804ada3b839ef3cdb71d4a3e2f5e74705908
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/e1cc804ada3b839ef...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/e1cc804ada3b839ef3c...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/e1cc804ada3b839ef3cdb...
The branch, master has been updated
via e1cc804ada3b839ef3cdb71d4a3e2f5e74705908 (commit)
from 46a4a0b2fe92f34e7f789b1587c8b46a6497495c (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=e1cc804ada3b839...
commit e1cc804ada3b839ef3cdb71d4a3e2f5e74705908
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Typo.
diff --git a/src/dom/event.c b/src/dom/event.c
index cc5596d..e24b699 100644
--- a/src/dom/event.c
+++ b/src/dom/event.c
@@ -102,7 +102,7 @@ nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
nslayout_error err;
dom_exception exc;
- /* TODO: LibDOM even listeners are really slow. Need to find a better
+ /* TODO: LibDOM event listeners are really slow. Need to find a better
* way to get DOM change notifications.
*/
-----------------------------------------------------------------------
Summary of changes:
src/dom/event.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/dom/event.c b/src/dom/event.c
index cc5596d..e24b699 100644
--- a/src/dom/event.c
+++ b/src/dom/event.c
@@ -102,7 +102,7 @@ nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
nslayout_error err;
dom_exception exc;
- /* TODO: LibDOM even listeners are really slow. Need to find a better
+ /* TODO: LibDOM event listeners are really slow. Need to find a better
* way to get DOM change notifications.
*/
--
NetSurf Layout Engine
7 years, 6 months
libnslayout: branch master updated. 46a4a0b2fe92f34e7f789b1587c8b46a6497495c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/46a4a0b2fe92f34e7...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/46a4a0b2fe92f34e7f7...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/46a4a0b2fe92f34e7f789...
The branch, master has been updated
via 46a4a0b2fe92f34e7f789b1587c8b46a6497495c (commit)
via 0fa07ce595512146f3833d82dc552f473be8a5c2 (commit)
via 91fd7c25fe5184e2917ea496be27ae24e4125bca (commit)
via 31c13f67167a0150728ef1ff67451b69081fa4cd (commit)
from 743416123ea60e7beed896abe54cafbc92116918 (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=46a4a0b2fe92f34...
commit 46a4a0b2fe92f34e7f789b1587c8b46a6497495c
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Tweak tester's remaining string iterator.
diff --git a/dev/main.c b/dev/main.c
index ca87816..9e4e578 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -11,9 +11,9 @@
*/
-static void lwc_iterator(lwc_string *str, void *pw)
+static void nsl_test_lwc_iterator(lwc_string *str, void *pw)
{
- printf("[%3u] %.*s", str->refcnt,
+ printf(" [%3u] %.*s\n", str->refcnt,
(int)lwc_string_length(str),
lwc_string_data(str));
}
@@ -24,8 +24,8 @@ int main(void)
test_loader("test-writing-mode.html", CSS_MEDIA_ALL, 15);
nslayout_fini();
- printf("Reamining lwc strings:\n");
- lwc_iterate_strings(lwc_iterator, NULL);
+ printf("Remaining lwc strings:\n");
+ lwc_iterate_strings(nsl_test_lwc_iterator, NULL);
return EXIT_SUCCESS;
}
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=0fa07ce59551214...
commit 0fa07ce595512146f3833d82dc552f473be8a5c2
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Error handling.
diff --git a/src/dom/event.c b/src/dom/event.c
index 6217e7a..cc5596d 100644
--- a/src/dom/event.c
+++ b/src/dom/event.c
@@ -99,6 +99,7 @@ fail:
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
{
+ nslayout_error err;
dom_exception exc;
/* TODO: LibDOM even listeners are really slow. Need to find a better
@@ -108,52 +109,56 @@ nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
layout, &layout->listener);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ return NSL_DOM_ERR(exc);
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ err = NSL_DOM_ERR(exc);
+ goto fail;
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ err = NSL_DOM_ERR(exc);
+ goto fail;
}
return NSLAYOUT_OK;
+
+fail:
+ dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
+
+ return err;
}
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
{
- dom_exception exc;
+ dom_exception exc1, exc2;
- exc = dom_event_target_remove_event_listener(
+ exc1 = dom_event_target_remove_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
- if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to remove event handler!\n");
- return NSLAYOUT_NO_MEM;
- }
- exc = dom_event_target_remove_event_listener(
+ exc2 = dom_event_target_remove_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
- if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to remove event handler!\n");
- return NSLAYOUT_NO_MEM;
+
+ if (exc1 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc1);
+ }
+ if (exc2 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc2);
}
+
dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
return NSLAYOUT_OK;
}
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=91fd7c25fe5184e...
commit 91fd7c25fe5184e2917ea496be27ae24e4125bca
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add error conversion macros.
diff --git a/src/util/util.h b/src/util/util.h
index c03691b..f63f40f 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -12,11 +12,14 @@
#define nslayout_util_util_h_
#ifndef UNUSED
-#define UNUSED(x) (void)(x)
+#define UNUSED(x_) (void)(x_)
#endif
#ifndef SLEN
-#define SLEN(x) (sizeof((x)) - 1)
+#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)
+
#endif
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=31c13f67167a015...
commit 31c13f67167a0150728ef1ff67451b69081fa4cd
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Imporve TODO.
diff --git a/src/dom/event.c b/src/dom/event.c
index 152fd34..6217e7a 100644
--- a/src/dom/event.c
+++ b/src/dom/event.c
@@ -101,13 +101,8 @@ nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
{
dom_exception exc;
- /* TODO: Somehow register with libdom to get DOM change notifications.
- *
- * At the moment, for testing, the client calls our event
- * handler directly. It looks as though libdom needs its
- * DOM event handling improved. Either add DOM mutation
- * observer support, or add some specific client notification
- * system, like other rendering engines.
+ /* TODO: LibDOM even listeners are really slow. Need to find a better
+ * way to get DOM change notifications.
*/
exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
-----------------------------------------------------------------------
Summary of changes:
dev/main.c | 8 ++++----
src/dom/event.c | 56 +++++++++++++++++++++++++++----------------------------
src/util/util.h | 7 +++++--
3 files changed, 37 insertions(+), 34 deletions(-)
diff --git a/dev/main.c b/dev/main.c
index ca87816..9e4e578 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -11,9 +11,9 @@
*/
-static void lwc_iterator(lwc_string *str, void *pw)
+static void nsl_test_lwc_iterator(lwc_string *str, void *pw)
{
- printf("[%3u] %.*s", str->refcnt,
+ printf(" [%3u] %.*s\n", str->refcnt,
(int)lwc_string_length(str),
lwc_string_data(str));
}
@@ -24,8 +24,8 @@ int main(void)
test_loader("test-writing-mode.html", CSS_MEDIA_ALL, 15);
nslayout_fini();
- printf("Reamining lwc strings:\n");
- lwc_iterate_strings(lwc_iterator, NULL);
+ printf("Remaining lwc strings:\n");
+ lwc_iterate_strings(nsl_test_lwc_iterator, NULL);
return EXIT_SUCCESS;
}
diff --git a/src/dom/event.c b/src/dom/event.c
index 152fd34..cc5596d 100644
--- a/src/dom/event.c
+++ b/src/dom/event.c
@@ -99,66 +99,66 @@ fail:
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
{
+ nslayout_error err;
dom_exception exc;
- /* TODO: Somehow register with libdom to get DOM change notifications.
- *
- * At the moment, for testing, the client calls our event
- * handler directly. It looks as though libdom needs its
- * DOM event handling improved. Either add DOM mutation
- * observer support, or add some specific client notification
- * system, like other rendering engines.
+ /* TODO: LibDOM even listeners are really slow. Need to find a better
+ * way to get DOM change notifications.
*/
exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
layout, &layout->listener);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ return NSL_DOM_ERR(exc);
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ err = NSL_DOM_ERR(exc);
+ goto fail;
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ err = NSL_DOM_ERR(exc);
+ goto fail;
}
return NSLAYOUT_OK;
+
+fail:
+ dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
+
+ return err;
}
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
{
- dom_exception exc;
+ dom_exception exc1, exc2;
- exc = dom_event_target_remove_event_listener(
+ exc1 = dom_event_target_remove_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
- if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to remove event handler!\n");
- return NSLAYOUT_NO_MEM;
- }
- exc = dom_event_target_remove_event_listener(
+ exc2 = dom_event_target_remove_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
- if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to remove event handler!\n");
- return NSLAYOUT_NO_MEM;
+
+ if (exc1 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc1);
+ }
+ if (exc2 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc2);
}
+
dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
return NSLAYOUT_OK;
}
diff --git a/src/util/util.h b/src/util/util.h
index c03691b..f63f40f 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -12,11 +12,14 @@
#define nslayout_util_util_h_
#ifndef UNUSED
-#define UNUSED(x) (void)(x)
+#define UNUSED(x_) (void)(x_)
#endif
#ifndef SLEN
-#define SLEN(x) (sizeof((x)) - 1)
+#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)
+
#endif
--
NetSurf Layout Engine
7 years, 6 months
libnslayout: branch master updated. 743416123ea60e7beed896abe54cafbc92116918
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/743416123ea60e7be...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/743416123ea60e7beed...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/743416123ea60e7beed89...
The branch, master has been updated
via 743416123ea60e7beed896abe54cafbc92116918 (commit)
from 5b8635deb1fcc1faf5afb19d0b59a8c8e1c48ec4 (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=743416123ea60e7...
commit 743416123ea60e7beed896abe54cafbc92116918
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add error header.
diff --git a/Makefile b/Makefile
index eed0e81..1cb230f 100644
--- a/Makefile
+++ b/Makefile
@@ -65,5 +65,6 @@ endif
I := /$(INCLUDEDIR)/lib$(COMPONENT)
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/lib$(COMPONENT)/nslayout.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/lib$(COMPONENT)/error.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h
new file mode 100644
index 0000000..0e2321f
--- /dev/null
+++ b/include/libnslayout/error.h
@@ -0,0 +1,109 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file include/libnslayout/error.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_error_h_
+#define nslayout_error_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Libnslayout return codes
+ *
+ * NSLAYOUT_OK indicates no error.
+ */
+typedef enum nslayout_error {
+ /** No error code */
+ NSLAYOUT_OK = 0,
+
+ /** Error provenance */
+ NSLAYOUT_NSLAYOUT = (1 << 0),
+ NSLAYOUT_LIBDOM = (1 << 1),
+ NSLAYOUT_LIBCSS = (1 << 2),
+
+ /** LibNSLayout errors */
+ NSLAYOUT_NO_MEM = (1 << 8) + NSLAYOUT_NSLAYOUT,
+} nslayout_error;
+
+
+/**
+ * Check if error is from libnslayout
+ *
+ * \param[in] err Error code to test
+ * \return true iff error is from libnslayout
+ */
+static inline bool nslayout_error_is_layout(nslayout_error err)
+{
+ return err & NSLAYOUT_NSLAYOUT;
+}
+
+
+/**
+ * Check if error is from libdom
+ *
+ * \param[in] err Error code to test
+ * \return true iff error is from libdom
+ */
+static inline bool nslayout_error_is_libdom(nslayout_error err)
+{
+ return err & NSLAYOUT_LIBDOM;
+}
+
+/**
+ * Check if error is from libcss
+ *
+ * \param[in] err Error code to test
+ * \return true iff error is from libcss
+ */
+static inline bool nslayout_error_is_libcss(nslayout_error err)
+{
+ return err & NSLAYOUT_LIBCSS;
+}
+
+/**
+ * Turn libnslayout return code into libnslayout error
+ *
+ * \param[in] err Error code to convert
+ * \return libnslayout error
+ */
+static inline nslayout_error nslayout_error_to_layout(nslayout_error err)
+{
+ return err;
+}
+
+/**
+ * Turn libnslayout return code into libdom error
+ *
+ * \param[in] err Error code to convert
+ * \return dom exception
+ */
+static inline dom_exception nslayout_error_to_libdom(nslayout_error err)
+{
+ return err >> 8;
+}
+
+/**
+ * Turn libnslayout return code into libcss error
+ *
+ * \param[in] err Error code to convert
+ * \return libcss error
+ */
+static inline css_error nslayout_error_to_libcss(nslayout_error err)
+{
+ return err >> 8;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 2610e42..b486cba 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -20,6 +20,8 @@ extern "C"
#include <libcss/libcss.h>
#include <dom/dom.h>
+#include <libnslayout/error.h>
+
/** An opaque client-owned replaced element */
typedef void nslayout_replaced;
@@ -86,11 +88,6 @@ typedef struct nslayout_request {
} response;
} nslayout_request;
-/** Libnslayout return codes */
-typedef enum nslayout_error {
- NSLAYOUT_OK,
- NSLAYOUT_NO_MEM
-} nslayout_error;
/**
* Initialise LibNSLayout
-----------------------------------------------------------------------
Summary of changes:
Makefile | 1 +
include/libnslayout/error.h | 109 ++++++++++++++++++++++++++++++++++++++++
include/libnslayout/nslayout.h | 7 +--
3 files changed, 112 insertions(+), 5 deletions(-)
create mode 100644 include/libnslayout/error.h
diff --git a/Makefile b/Makefile
index eed0e81..1cb230f 100644
--- a/Makefile
+++ b/Makefile
@@ -65,5 +65,6 @@ endif
I := /$(INCLUDEDIR)/lib$(COMPONENT)
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/lib$(COMPONENT)/nslayout.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/lib$(COMPONENT)/error.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h
new file mode 100644
index 0000000..0e2321f
--- /dev/null
+++ b/include/libnslayout/error.h
@@ -0,0 +1,109 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file include/libnslayout/error.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_error_h_
+#define nslayout_error_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Libnslayout return codes
+ *
+ * NSLAYOUT_OK indicates no error.
+ */
+typedef enum nslayout_error {
+ /** No error code */
+ NSLAYOUT_OK = 0,
+
+ /** Error provenance */
+ NSLAYOUT_NSLAYOUT = (1 << 0),
+ NSLAYOUT_LIBDOM = (1 << 1),
+ NSLAYOUT_LIBCSS = (1 << 2),
+
+ /** LibNSLayout errors */
+ NSLAYOUT_NO_MEM = (1 << 8) + NSLAYOUT_NSLAYOUT,
+} nslayout_error;
+
+
+/**
+ * Check if error is from libnslayout
+ *
+ * \param[in] err Error code to test
+ * \return true iff error is from libnslayout
+ */
+static inline bool nslayout_error_is_layout(nslayout_error err)
+{
+ return err & NSLAYOUT_NSLAYOUT;
+}
+
+
+/**
+ * Check if error is from libdom
+ *
+ * \param[in] err Error code to test
+ * \return true iff error is from libdom
+ */
+static inline bool nslayout_error_is_libdom(nslayout_error err)
+{
+ return err & NSLAYOUT_LIBDOM;
+}
+
+/**
+ * Check if error is from libcss
+ *
+ * \param[in] err Error code to test
+ * \return true iff error is from libcss
+ */
+static inline bool nslayout_error_is_libcss(nslayout_error err)
+{
+ return err & NSLAYOUT_LIBCSS;
+}
+
+/**
+ * Turn libnslayout return code into libnslayout error
+ *
+ * \param[in] err Error code to convert
+ * \return libnslayout error
+ */
+static inline nslayout_error nslayout_error_to_layout(nslayout_error err)
+{
+ return err;
+}
+
+/**
+ * Turn libnslayout return code into libdom error
+ *
+ * \param[in] err Error code to convert
+ * \return dom exception
+ */
+static inline dom_exception nslayout_error_to_libdom(nslayout_error err)
+{
+ return err >> 8;
+}
+
+/**
+ * Turn libnslayout return code into libcss error
+ *
+ * \param[in] err Error code to convert
+ * \return libcss error
+ */
+static inline css_error nslayout_error_to_libcss(nslayout_error err)
+{
+ return err >> 8;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 2610e42..b486cba 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -20,6 +20,8 @@ extern "C"
#include <libcss/libcss.h>
#include <dom/dom.h>
+#include <libnslayout/error.h>
+
/** An opaque client-owned replaced element */
typedef void nslayout_replaced;
@@ -86,11 +88,6 @@ typedef struct nslayout_request {
} response;
} nslayout_request;
-/** Libnslayout return codes */
-typedef enum nslayout_error {
- NSLAYOUT_OK,
- NSLAYOUT_NO_MEM
-} nslayout_error;
/**
* Initialise LibNSLayout
--
NetSurf Layout Engine
7 years, 6 months
nsgenbind: branch vince/interfacemap updated. release/0.1.0-32-g6fb336e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenbind.git/shortlog/6fb336e6587d550bf4a...
...commit http://git.netsurf-browser.org/nsgenbind.git/commit/6fb336e6587d550bf4a83...
...tree http://git.netsurf-browser.org/nsgenbind.git/tree/6fb336e6587d550bf4a8355...
The branch, vince/interfacemap has been updated
via 6fb336e6587d550bf4a8355e65923efb0bf14cab (commit)
from cb2089531d4165786772c5cef17d28dc1a8e28d6 (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/nsgenbind.git/commit/?id=6fb336e6587d550bf...
commit 6fb336e6587d550bf4a8355e65923efb0bf14cab
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
generate binding header and source
These allow a closed set of functions used by the automatic bindings
and gives an external interface allowing all the generated prototypes to be
created in the correct order
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 590afa2..4dbc8e2 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -25,6 +25,8 @@
/** prefix for all generated functions */
#define DLPFX "duckky"
+#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
+
#define NSGENBIND_PREAMBLE \
"/* Generated by nsgenbind\n" \
" *\n" \
@@ -62,24 +64,42 @@ static int output_safe_get_private(FILE* outf, char *class_name, int idx)
return 0;
}
+
/**
- * generate code that gets a prototype by name
+ * generate a duktape prototype name
*/
-static int output_get_prototype(FILE* outf, const char *interface_name)
+static char *get_prototype_name(const char *interface_name)
{
char *proto_name;
int pnamelen;
+ int pfxlen;
/* duplicate the interface name in upper case */
- pnamelen = strlen(interface_name) + 1; /* allow for null byte */
- proto_name = malloc(pnamelen);
- for ( ; pnamelen >= 0; pnamelen--) {
- proto_name[pnamelen] = toupper(interface_name[pnamelen]);
+ pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
+ pnamelen = strlen(interface_name) + 1;
+
+ proto_name = malloc(pnamelen + pfxlen);
+ snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, interface_name);
+ for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen + pfxlen] = toupper(interface_name[pnamelen]);
}
+ return proto_name;
+}
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *interface_name)
+{
+ char *proto_name;
+
+ proto_name = get_prototype_name(interface_name);
+
fprintf(outf, "\t/* get prototype */\n");
- fprintf(outf, "\tduk_get_global_string(ctx, PROTO_MAGIC);\n");
- fprintf(outf, "\tduk_get_prop_string(ctx, -1, PROTO_NAME(%s));\n",
- proto_name);
+ fprintf(outf,
+ "\tduk_get_global_string(ctx, \"%sPROTOTYPES\");\n", MAGICPFX);
+ fprintf(outf,
+ "\tduk_get_prop_string(ctx, -1, \"%s\");\n", proto_name);
fprintf(outf, "\tduk_replace(ctx, -2);\n");
free(proto_name);
@@ -235,6 +255,16 @@ output_get_method_private(FILE* outf, char *class_name)
}
/**
+ * generate preface block for nsgenbind
+ */
+static int output_tool_preface(FILE* outf)
+{
+ fprintf(outf, "\n%s\n", NSGENBIND_PREAMBLE);
+
+ return 0;
+}
+
+/**
* Generate a C class name for the interface.
*
* The IDL interface names are camelcase and not similar to libdom naming so it
@@ -319,6 +349,53 @@ output_cdata(FILE* outf,
return 0;
}
+static FILE *open_header(struct interface_map *interface_map, const char *name)
+{
+ FILE *hdrf;
+ char *fname;
+ int fnamel;
+
+ fnamel = strlen(name) + 4;
+ fname = malloc(fnamel);
+ snprintf(fname, fnamel, "%s.h", name);
+
+ /* open output file */
+ hdrf = genb_fopen(fname, "w");
+ free(fname);
+ if (hdrf == NULL) {
+ return NULL;
+ }
+
+ /* binding preface */
+ output_cdata(hdrf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool preface */
+ output_tool_preface(hdrf);
+
+ /* header guard */
+ fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
+ fprintf(hdrf, "#define %s_%s_h\n\n", DLPFX, name);
+
+ return hdrf;
+}
+
+static int close_header(struct interface_map *interface_map, FILE *hdrf)
+{
+ fprintf(hdrf, "\n#endif\n");
+
+ /* binding postface */
+ output_cdata(hdrf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+ fclose(hdrf);
+
+ return 0;
+}
+
+
/**
* generate the interface constructor
*/
@@ -963,15 +1040,6 @@ output_interface_attributes(FILE* outf,
return 0;
}
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_preface(FILE* outf)
-{
- fprintf(outf, "\n%s\n", NSGENBIND_PREAMBLE);
-
- return 0;
-}
/**
* generate preface block for nsgenbind
@@ -980,10 +1048,14 @@ static int output_tool_prologue(FILE* outf)
{
char *fpath;
- fpath = genb_fpath("private.h");
+ fpath = genb_fpath("binding.h");
fprintf(outf, "\n#include \"%s\"\n", fpath);
free(fpath);
+ fpath = genb_fpath("private.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
+
fpath = genb_fpath("prototype.h");
fprintf(outf, "#include \"%s\"\n", fpath);
free(fpath);
@@ -1105,23 +1177,8 @@ output_private_header(struct interface_map *interface_map)
int idx;
FILE *privf;
- /* open output file */
- privf = genb_fopen("private.h", "w");
- if (privf == NULL) {
- return -1;
- }
-
- /* binding preface */
- output_cdata(privf,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* tool preface */
- output_tool_preface(privf);
-
- /* header guard */
- fprintf(privf, "\n#ifndef duk_libdom_private_h\n");
- fprintf(privf, "#define duk_libdom_private_h\n\n");
+ /* open header */
+ privf = open_header(interface_map, "private");
for (idx = 0; idx < interface_map->entryc; idx++) {
struct interface_map_entry *interfacee;
@@ -1168,20 +1225,13 @@ output_private_header(struct interface_map *interface_map)
}
- /* binding postface */
- output_cdata(privf,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
- fprintf(privf, "\n#endif\n");
-
- fclose(privf);
+ close_header(interface_map, privf);
return 0;
}
/**
- * generate protottype header
+ * generate prototype header
*/
static int
output_prototype_header(struct interface_map *interface_map)
@@ -1189,23 +1239,8 @@ output_prototype_header(struct interface_map *interface_map)
int idx;
FILE *protof;
- /* open output file */
- protof = genb_fopen("prototype.h", "w");
- if (protof == NULL) {
- return -1;
- }
-
- /* binding preface */
- output_cdata(protof,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* tool preface */
- output_tool_preface(protof);
-
- /* header guard */
- fprintf(protof, "\n#ifndef duk_libdom_prototype_h\n");
- fprintf(protof, "#define duk_libdom_prototype_h\n\n");
+ /* open header */
+ protof = open_header(interface_map, "prototype");
for (idx = 0; idx < interface_map->entryc; idx++) {
struct interface_map_entry *interfacee;
@@ -1224,6 +1259,13 @@ output_prototype_header(struct interface_map *interface_map)
fprintf(protof, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
DLPFX, interfacee->class_name);
+ /** \todo if the interface has no references (no other
+ * interface inherits from it) there is no reason to export
+ * the initalisor/finaliser as no other class
+ * constructor/destructor should call them. Additionally the
+ * init/fini definition should be made static.
+ */
+
/* finaliser declaration */
fprintf(protof,
"void %s_%s___fini(duk_context *ctx, %s_private_t *priv);\n",
@@ -1239,20 +1281,13 @@ output_prototype_header(struct interface_map *interface_map)
fprintf(protof, ";\n\n");
}
- /* binding postface */
- output_cdata(protof,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
- fprintf(protof, "\n#endif\n");
-
- fclose(protof);
+ close_header(interface_map, protof);
return 0;
}
/**
- * generate protottype header
+ * generate makefile fragment
*/
static int
output_makefile(struct interface_map *interface_map)
@@ -1268,7 +1303,7 @@ output_makefile(struct interface_map *interface_map)
fprintf(makef, "# duk libdom makefile fragment\n\n");
- fprintf(makef, "NSGENBIND_SOURCES:=");
+ fprintf(makef, "NSGENBIND_SOURCES:=binding.c ");
for (idx = 0; idx < interface_map->entryc; idx++) {
struct interface_map_entry *interfacee;
@@ -1288,6 +1323,241 @@ output_makefile(struct interface_map *interface_map)
return 0;
}
+
+/**
+ * generate binding header
+ *
+ * The binding header contains all the duk-libdom specific binding interface
+ * macros and definitions.
+ *
+ * the create prototypes interface is used to cause all the prototype creation
+ * functions for all generated classes to be called in the correct order with
+ * the primary global (if any) generated last.
+ */
+static int
+output_binding_header(struct interface_map *interface_map)
+{
+ FILE *bindf;
+
+ /* open header */
+ bindf = open_header(interface_map, "binding");
+
+ fprintf(bindf,
+ "#define _MAGIC(S) (\"%s\" S)\n"
+ "#define MAGIC(S) _MAGIC(#S)\n"
+ "#define PROTO_MAGIC MAGIC(PROTOTYPES)\n"
+ "#define PRIVATE_MAGIC MAGIC(PRIVATE)\n"
+ "#define INIT_MAGIC MAGIC(INIT)\n"
+ "#define NODE_MAGIC MAGIC(NODE_MAP)\n"
+ "#define _PROTO_NAME(K) _MAGIC(\"PROTOTYPE_\" K)\n"
+ "#define PROTO_NAME(K) _PROTO_NAME(#K)\n"
+ "#define _PROP_NAME(K,V) _MAGIC(K \"_PROPERTY_\" V)\n"
+ "#define PROP_NAME(K,V) _PROP_NAME(#K,#V)\n"
+ "\n",
+ MAGICPFX);
+
+ fprintf(bindf,
+ "duk_bool_t %s_instanceof(duk_context *ctx, const char *klass);\n",
+ DLPFX);
+
+ fprintf(bindf,
+ "duk_ret_t %s_create_prototypes(duk_context *ctx);\n", DLPFX);
+
+ close_header(interface_map, bindf);
+
+ return 0;
+}
+
+
+/**
+ * generate binding source
+ *
+ * The binding header contains all the duk-libdom specific binding
+ * implementations.
+ */
+static int
+output_binding_src(struct interface_map *interface_map)
+{
+ int idx;
+ FILE *bindf;
+ struct interface_map_entry *pglobale = NULL;
+ char *proto_name;
+
+ /* open output file */
+ bindf = genb_fopen("binding.c", "w");
+ if (bindf == NULL) {
+ return -1;
+ }
+
+ /* binding preface */
+ output_cdata(bindf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool preface */
+ output_tool_preface(bindf);
+
+ /* binding prologue */
+ output_cdata(bindf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_PROLOGUE);
+
+ output_tool_prologue(bindf);
+
+ fprintf(bindf, "\n");
+
+ /* instance of helper */
+ fprintf(bindf,
+ "duk_bool_t\n"
+ "%s_instanceof(duk_context *ctx, const char *klass)\n",
+ DLPFX);
+ fprintf(bindf,
+ "{\n"
+ "\t/* ... ??? */\n"
+ "\tif (!duk_check_type(ctx, -1, DUK_TYPE_OBJECT)) {\n"
+ "\t\treturn false;\n"
+ "\t}\n"
+ "\t/* ... obj */\n"
+ "\tduk_get_global_string(ctx, \"%sPROTOTYPES\");\n"
+ "\t/* ... obj protos */\n"
+ "\tduk_get_prop_string(ctx, -1, klass);\n"
+ "\t/* ... obj protos goalproto */\n"
+ "\tduk_get_prototype(ctx, -3);\n"
+ "\t/* ... obj protos goalproto proto? */\n"
+ "\twhile (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\tif (duk_strict_equals(ctx, -1, -2)) {\n"
+ "\t\t\tduk_pop_3(ctx);\n"
+ "\t\t\treturn true;\n"
+ "\t\t}\n"
+ "\t\tduk_get_prototype(ctx, -1);\n"
+ "\t\t/* ... obj protos goalproto proto proto? */\n"
+ "\t\tduk_replace(ctx, -2);\n"
+ "\t\t/* ... obj protos goalproto proto? */\n"
+ "\t}\n"
+ "\tduk_pop_3(ctx);\n"
+ "\t/* ... obj */\n"
+ "\treturn false;\n"
+ "}\n"
+ "\n",
+ MAGICPFX);
+
+ /* prototype creation helper function */
+ fprintf(bindf,
+ "static duk_ret_t\n"
+ "%s_to_string(duk_context *ctx)\n"
+ "{\n"
+ "\t/* */\n"
+ "\tduk_push_this(ctx);\n"
+ "\t/* this */\n"
+ "\tduk_get_prototype(ctx, -1);\n"
+ "\t/* this proto */\n"
+ "\tduk_get_prop_string(ctx, -1, \"%sklass_name\");\n"
+ "\t/* this proto classname */\n"
+ "\tduk_push_string(ctx, \"[object \");\n"
+ "\t/* this proto classname str */\n"
+ "\tduk_insert(ctx, -2);\n"
+ "\t/* this proto str classname */\n"
+ "\tduk_push_string(ctx, \"]\");\n"
+ "\t/* this proto str classname str */\n"
+ "\tduk_concat(ctx, 3);\n"
+ "\t/* this proto str */\n"
+ "\treturn 1;\n"
+ "}\n"
+ "\n",
+ DLPFX,
+ MAGICPFX);
+
+ fprintf(bindf,
+ "static duk_ret_t %s_create_prototype(duk_context *ctx,\n",
+ DLPFX);
+ fprintf(bindf,
+ "\t\t\t\t\tduk_safe_call_function genproto,\n"
+ "\t\t\t\t\tconst char *proto_name,\n"
+ "\t\t\t\t\tconst char *klass_name)\n"
+ "{\n"
+ "\tduk_int_t ret;\n"
+ "\tduk_push_object(ctx);\n"
+ "\tif ((ret = duk_safe_call(ctx, genproto, 1, 1)) != DUK_EXEC_SUCCESS) {\n"
+ "\t\tduk_pop(ctx);\n"
+ "\t\tLOG(\"Failed to register prototype for %%s\", proto_name + 2);\n"
+ "\t\treturn ret;\n"
+ "\t}\n"
+ "\t/* top of stack is the ready prototype, inject it */\n"
+ "\tduk_push_string(ctx, klass_name);\n"
+ "\tduk_put_prop_string(ctx, -2, \"%sklass_name\");\n"
+ "\tduk_push_c_function(ctx, %s_to_string, 0);\n"
+ "\tduk_put_prop_string(ctx, -2, \"toString\");\n"
+ "\tduk_push_string(ctx, \"toString\");\n"
+ "\tduk_def_prop(ctx, -2, DUK_DEFPROP_HAVE_ENUMERABLE);\n"
+ "\tduk_put_global_string(ctx, proto_name);\n"
+ "\treturn DUK_ERR_NONE;\n"
+ "}\n\n",
+ MAGICPFX,
+ DLPFX);
+
+ /* generate prototype creation */
+ fprintf(bindf,
+ "duk_ret_t %s_create_prototypes(duk_context *ctx)\n", DLPFX);
+
+ fprintf(bindf, "{\n");
+
+ for (idx = 0; idx < interface_map->entryc; idx++) {
+ struct interface_map_entry *interfacee;
+
+ interfacee = interface_map->entries + idx;
+
+ /* do not generate prototype calls for interfaces marked
+ * no output
+ */
+ if (interfacee->noobject) {
+ continue;
+ }
+
+ if (interfacee->primary_global) {
+ pglobale = interfacee;
+ continue;
+ }
+
+ proto_name = get_prototype_name(interfacee->name);
+
+ fprintf(bindf,
+ "\t%s_create_prototype(ctx, %s_%s___proto, \"%s\", \"%s\");\n",
+ DLPFX,
+ DLPFX,
+ interfacee->class_name,
+ proto_name,
+ interfacee->name);
+
+ free(proto_name);
+ }
+
+ if (pglobale != NULL) {
+ fprintf(bindf, "\n\t/* Global object prototype is last */\n");
+
+ proto_name = get_prototype_name(pglobale->name);
+ fprintf(bindf,
+ "\t%s_create_prototype(ctx, %s_%s___proto, \"%s\", \"%s\");\n",
+ DLPFX,
+ DLPFX,
+ pglobale->class_name,
+ proto_name,
+ pglobale->name);
+ free(proto_name);
+ }
+
+ fprintf(bindf, "\n\treturn DUK_ERR_NONE;\n");
+
+ fprintf(bindf, "}\n");
+
+ /* binding postface */
+ output_cdata(bindf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+ fclose(bindf);
+ return 0;
+}
+
int duk_libdom_output(struct interface_map *interface_map)
{
int idx;
@@ -1314,6 +1584,18 @@ int duk_libdom_output(struct interface_map *interface_map)
goto output_err;
}
+ /* generate binding header */
+ res = output_binding_header(interface_map);
+ if (res != 0) {
+ goto output_err;
+ }
+
+ /* generate binding source */
+ res = output_binding_src(interface_map);
+ if (res != 0) {
+ goto output_err;
+ }
+
/* generate makefile fragment */
res = output_makefile(interface_map);
diff --git a/src/interface-map.c b/src/interface-map.c
index 467c0ed..555156a 100644
--- a/src/interface-map.c
+++ b/src/interface-map.c
@@ -111,6 +111,7 @@ interface_topoligical_sort(struct interface_map_entry *srcinf, int infc)
dstinf[idx].node = srcinf[inf].node;
dstinf[idx].inherit_name = srcinf[inf].inherit_name;
dstinf[idx].noobject = srcinf[inf].noobject;
+ dstinf[idx].primary_global = srcinf[inf].primary_global;
dstinf[idx].operationc = srcinf[inf].operationc;
dstinf[idx].operationv = srcinf[inf].operationv;
dstinf[idx].attributec = srcinf[inf].attributec;
@@ -422,6 +423,7 @@ int interface_map_new(struct genbind_node *genbind,
NULL,
WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE));
+ /* is the interface marked as not generating an object */
if (webidl_node_find_type_ident(
webidl_node_getnode(node),
WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE,
@@ -433,6 +435,18 @@ int interface_map_new(struct genbind_node *genbind,
ecur->noobject = true;
}
+ /* is the interface marked as the primary global */
+ if (webidl_node_find_type_ident(
+ webidl_node_getnode(node),
+ WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE,
+ "PrimaryGlobal") != NULL) {
+ /** \todo we should ensure nothing inherits *from* this
+ * class or all hell will break loose having two
+ * primary globals.
+ */
+ ecur->primary_global = true;
+ }
+
/* matching class from binding */
ecur->class = genbind_node_find_type_ident(genbind,
NULL, GENBIND_NODE_TYPE_CLASS, ecur->name);
diff --git a/src/interface-map.h b/src/interface-map.h
index e07aa19..c34eb4b 100644
--- a/src/interface-map.h
+++ b/src/interface-map.h
@@ -49,6 +49,9 @@ struct interface_map_entry {
* generated. This allows for interfaces which do not
* generate code. For implements (mixin) interfaces
*/
+ bool primary_global; /**< flag indicating the interface is the primary
+ * global javascript object.
+ */
int operationc; /**< number of operations on interface */
struct interface_map_operation_entry *operationv;
-----------------------------------------------------------------------
Summary of changes:
src/duk-libdom.c | 426 ++++++++++++++++++++++++++++++++++++++++++---------
src/interface-map.c | 14 ++
src/interface-map.h | 3 +
3 files changed, 371 insertions(+), 72 deletions(-)
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 590afa2..4dbc8e2 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -25,6 +25,8 @@
/** prefix for all generated functions */
#define DLPFX "duckky"
+#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
+
#define NSGENBIND_PREAMBLE \
"/* Generated by nsgenbind\n" \
" *\n" \
@@ -62,24 +64,42 @@ static int output_safe_get_private(FILE* outf, char *class_name, int idx)
return 0;
}
+
/**
- * generate code that gets a prototype by name
+ * generate a duktape prototype name
*/
-static int output_get_prototype(FILE* outf, const char *interface_name)
+static char *get_prototype_name(const char *interface_name)
{
char *proto_name;
int pnamelen;
+ int pfxlen;
/* duplicate the interface name in upper case */
- pnamelen = strlen(interface_name) + 1; /* allow for null byte */
- proto_name = malloc(pnamelen);
- for ( ; pnamelen >= 0; pnamelen--) {
- proto_name[pnamelen] = toupper(interface_name[pnamelen]);
+ pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
+ pnamelen = strlen(interface_name) + 1;
+
+ proto_name = malloc(pnamelen + pfxlen);
+ snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, interface_name);
+ for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen + pfxlen] = toupper(interface_name[pnamelen]);
}
+ return proto_name;
+}
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *interface_name)
+{
+ char *proto_name;
+
+ proto_name = get_prototype_name(interface_name);
+
fprintf(outf, "\t/* get prototype */\n");
- fprintf(outf, "\tduk_get_global_string(ctx, PROTO_MAGIC);\n");
- fprintf(outf, "\tduk_get_prop_string(ctx, -1, PROTO_NAME(%s));\n",
- proto_name);
+ fprintf(outf,
+ "\tduk_get_global_string(ctx, \"%sPROTOTYPES\");\n", MAGICPFX);
+ fprintf(outf,
+ "\tduk_get_prop_string(ctx, -1, \"%s\");\n", proto_name);
fprintf(outf, "\tduk_replace(ctx, -2);\n");
free(proto_name);
@@ -235,6 +255,16 @@ output_get_method_private(FILE* outf, char *class_name)
}
/**
+ * generate preface block for nsgenbind
+ */
+static int output_tool_preface(FILE* outf)
+{
+ fprintf(outf, "\n%s\n", NSGENBIND_PREAMBLE);
+
+ return 0;
+}
+
+/**
* Generate a C class name for the interface.
*
* The IDL interface names are camelcase and not similar to libdom naming so it
@@ -319,6 +349,53 @@ output_cdata(FILE* outf,
return 0;
}
+static FILE *open_header(struct interface_map *interface_map, const char *name)
+{
+ FILE *hdrf;
+ char *fname;
+ int fnamel;
+
+ fnamel = strlen(name) + 4;
+ fname = malloc(fnamel);
+ snprintf(fname, fnamel, "%s.h", name);
+
+ /* open output file */
+ hdrf = genb_fopen(fname, "w");
+ free(fname);
+ if (hdrf == NULL) {
+ return NULL;
+ }
+
+ /* binding preface */
+ output_cdata(hdrf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool preface */
+ output_tool_preface(hdrf);
+
+ /* header guard */
+ fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
+ fprintf(hdrf, "#define %s_%s_h\n\n", DLPFX, name);
+
+ return hdrf;
+}
+
+static int close_header(struct interface_map *interface_map, FILE *hdrf)
+{
+ fprintf(hdrf, "\n#endif\n");
+
+ /* binding postface */
+ output_cdata(hdrf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+ fclose(hdrf);
+
+ return 0;
+}
+
+
/**
* generate the interface constructor
*/
@@ -963,15 +1040,6 @@ output_interface_attributes(FILE* outf,
return 0;
}
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_preface(FILE* outf)
-{
- fprintf(outf, "\n%s\n", NSGENBIND_PREAMBLE);
-
- return 0;
-}
/**
* generate preface block for nsgenbind
@@ -980,10 +1048,14 @@ static int output_tool_prologue(FILE* outf)
{
char *fpath;
- fpath = genb_fpath("private.h");
+ fpath = genb_fpath("binding.h");
fprintf(outf, "\n#include \"%s\"\n", fpath);
free(fpath);
+ fpath = genb_fpath("private.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
+
fpath = genb_fpath("prototype.h");
fprintf(outf, "#include \"%s\"\n", fpath);
free(fpath);
@@ -1105,23 +1177,8 @@ output_private_header(struct interface_map *interface_map)
int idx;
FILE *privf;
- /* open output file */
- privf = genb_fopen("private.h", "w");
- if (privf == NULL) {
- return -1;
- }
-
- /* binding preface */
- output_cdata(privf,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* tool preface */
- output_tool_preface(privf);
-
- /* header guard */
- fprintf(privf, "\n#ifndef duk_libdom_private_h\n");
- fprintf(privf, "#define duk_libdom_private_h\n\n");
+ /* open header */
+ privf = open_header(interface_map, "private");
for (idx = 0; idx < interface_map->entryc; idx++) {
struct interface_map_entry *interfacee;
@@ -1168,20 +1225,13 @@ output_private_header(struct interface_map *interface_map)
}
- /* binding postface */
- output_cdata(privf,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
- fprintf(privf, "\n#endif\n");
-
- fclose(privf);
+ close_header(interface_map, privf);
return 0;
}
/**
- * generate protottype header
+ * generate prototype header
*/
static int
output_prototype_header(struct interface_map *interface_map)
@@ -1189,23 +1239,8 @@ output_prototype_header(struct interface_map *interface_map)
int idx;
FILE *protof;
- /* open output file */
- protof = genb_fopen("prototype.h", "w");
- if (protof == NULL) {
- return -1;
- }
-
- /* binding preface */
- output_cdata(protof,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* tool preface */
- output_tool_preface(protof);
-
- /* header guard */
- fprintf(protof, "\n#ifndef duk_libdom_prototype_h\n");
- fprintf(protof, "#define duk_libdom_prototype_h\n\n");
+ /* open header */
+ protof = open_header(interface_map, "prototype");
for (idx = 0; idx < interface_map->entryc; idx++) {
struct interface_map_entry *interfacee;
@@ -1224,6 +1259,13 @@ output_prototype_header(struct interface_map *interface_map)
fprintf(protof, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
DLPFX, interfacee->class_name);
+ /** \todo if the interface has no references (no other
+ * interface inherits from it) there is no reason to export
+ * the initalisor/finaliser as no other class
+ * constructor/destructor should call them. Additionally the
+ * init/fini definition should be made static.
+ */
+
/* finaliser declaration */
fprintf(protof,
"void %s_%s___fini(duk_context *ctx, %s_private_t *priv);\n",
@@ -1239,20 +1281,13 @@ output_prototype_header(struct interface_map *interface_map)
fprintf(protof, ";\n\n");
}
- /* binding postface */
- output_cdata(protof,
- interface_map->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
- fprintf(protof, "\n#endif\n");
-
- fclose(protof);
+ close_header(interface_map, protof);
return 0;
}
/**
- * generate protottype header
+ * generate makefile fragment
*/
static int
output_makefile(struct interface_map *interface_map)
@@ -1268,7 +1303,7 @@ output_makefile(struct interface_map *interface_map)
fprintf(makef, "# duk libdom makefile fragment\n\n");
- fprintf(makef, "NSGENBIND_SOURCES:=");
+ fprintf(makef, "NSGENBIND_SOURCES:=binding.c ");
for (idx = 0; idx < interface_map->entryc; idx++) {
struct interface_map_entry *interfacee;
@@ -1288,6 +1323,241 @@ output_makefile(struct interface_map *interface_map)
return 0;
}
+
+/**
+ * generate binding header
+ *
+ * The binding header contains all the duk-libdom specific binding interface
+ * macros and definitions.
+ *
+ * the create prototypes interface is used to cause all the prototype creation
+ * functions for all generated classes to be called in the correct order with
+ * the primary global (if any) generated last.
+ */
+static int
+output_binding_header(struct interface_map *interface_map)
+{
+ FILE *bindf;
+
+ /* open header */
+ bindf = open_header(interface_map, "binding");
+
+ fprintf(bindf,
+ "#define _MAGIC(S) (\"%s\" S)\n"
+ "#define MAGIC(S) _MAGIC(#S)\n"
+ "#define PROTO_MAGIC MAGIC(PROTOTYPES)\n"
+ "#define PRIVATE_MAGIC MAGIC(PRIVATE)\n"
+ "#define INIT_MAGIC MAGIC(INIT)\n"
+ "#define NODE_MAGIC MAGIC(NODE_MAP)\n"
+ "#define _PROTO_NAME(K) _MAGIC(\"PROTOTYPE_\" K)\n"
+ "#define PROTO_NAME(K) _PROTO_NAME(#K)\n"
+ "#define _PROP_NAME(K,V) _MAGIC(K \"_PROPERTY_\" V)\n"
+ "#define PROP_NAME(K,V) _PROP_NAME(#K,#V)\n"
+ "\n",
+ MAGICPFX);
+
+ fprintf(bindf,
+ "duk_bool_t %s_instanceof(duk_context *ctx, const char *klass);\n",
+ DLPFX);
+
+ fprintf(bindf,
+ "duk_ret_t %s_create_prototypes(duk_context *ctx);\n", DLPFX);
+
+ close_header(interface_map, bindf);
+
+ return 0;
+}
+
+
+/**
+ * generate binding source
+ *
+ * The binding header contains all the duk-libdom specific binding
+ * implementations.
+ */
+static int
+output_binding_src(struct interface_map *interface_map)
+{
+ int idx;
+ FILE *bindf;
+ struct interface_map_entry *pglobale = NULL;
+ char *proto_name;
+
+ /* open output file */
+ bindf = genb_fopen("binding.c", "w");
+ if (bindf == NULL) {
+ return -1;
+ }
+
+ /* binding preface */
+ output_cdata(bindf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool preface */
+ output_tool_preface(bindf);
+
+ /* binding prologue */
+ output_cdata(bindf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_PROLOGUE);
+
+ output_tool_prologue(bindf);
+
+ fprintf(bindf, "\n");
+
+ /* instance of helper */
+ fprintf(bindf,
+ "duk_bool_t\n"
+ "%s_instanceof(duk_context *ctx, const char *klass)\n",
+ DLPFX);
+ fprintf(bindf,
+ "{\n"
+ "\t/* ... ??? */\n"
+ "\tif (!duk_check_type(ctx, -1, DUK_TYPE_OBJECT)) {\n"
+ "\t\treturn false;\n"
+ "\t}\n"
+ "\t/* ... obj */\n"
+ "\tduk_get_global_string(ctx, \"%sPROTOTYPES\");\n"
+ "\t/* ... obj protos */\n"
+ "\tduk_get_prop_string(ctx, -1, klass);\n"
+ "\t/* ... obj protos goalproto */\n"
+ "\tduk_get_prototype(ctx, -3);\n"
+ "\t/* ... obj protos goalproto proto? */\n"
+ "\twhile (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\tif (duk_strict_equals(ctx, -1, -2)) {\n"
+ "\t\t\tduk_pop_3(ctx);\n"
+ "\t\t\treturn true;\n"
+ "\t\t}\n"
+ "\t\tduk_get_prototype(ctx, -1);\n"
+ "\t\t/* ... obj protos goalproto proto proto? */\n"
+ "\t\tduk_replace(ctx, -2);\n"
+ "\t\t/* ... obj protos goalproto proto? */\n"
+ "\t}\n"
+ "\tduk_pop_3(ctx);\n"
+ "\t/* ... obj */\n"
+ "\treturn false;\n"
+ "}\n"
+ "\n",
+ MAGICPFX);
+
+ /* prototype creation helper function */
+ fprintf(bindf,
+ "static duk_ret_t\n"
+ "%s_to_string(duk_context *ctx)\n"
+ "{\n"
+ "\t/* */\n"
+ "\tduk_push_this(ctx);\n"
+ "\t/* this */\n"
+ "\tduk_get_prototype(ctx, -1);\n"
+ "\t/* this proto */\n"
+ "\tduk_get_prop_string(ctx, -1, \"%sklass_name\");\n"
+ "\t/* this proto classname */\n"
+ "\tduk_push_string(ctx, \"[object \");\n"
+ "\t/* this proto classname str */\n"
+ "\tduk_insert(ctx, -2);\n"
+ "\t/* this proto str classname */\n"
+ "\tduk_push_string(ctx, \"]\");\n"
+ "\t/* this proto str classname str */\n"
+ "\tduk_concat(ctx, 3);\n"
+ "\t/* this proto str */\n"
+ "\treturn 1;\n"
+ "}\n"
+ "\n",
+ DLPFX,
+ MAGICPFX);
+
+ fprintf(bindf,
+ "static duk_ret_t %s_create_prototype(duk_context *ctx,\n",
+ DLPFX);
+ fprintf(bindf,
+ "\t\t\t\t\tduk_safe_call_function genproto,\n"
+ "\t\t\t\t\tconst char *proto_name,\n"
+ "\t\t\t\t\tconst char *klass_name)\n"
+ "{\n"
+ "\tduk_int_t ret;\n"
+ "\tduk_push_object(ctx);\n"
+ "\tif ((ret = duk_safe_call(ctx, genproto, 1, 1)) != DUK_EXEC_SUCCESS) {\n"
+ "\t\tduk_pop(ctx);\n"
+ "\t\tLOG(\"Failed to register prototype for %%s\", proto_name + 2);\n"
+ "\t\treturn ret;\n"
+ "\t}\n"
+ "\t/* top of stack is the ready prototype, inject it */\n"
+ "\tduk_push_string(ctx, klass_name);\n"
+ "\tduk_put_prop_string(ctx, -2, \"%sklass_name\");\n"
+ "\tduk_push_c_function(ctx, %s_to_string, 0);\n"
+ "\tduk_put_prop_string(ctx, -2, \"toString\");\n"
+ "\tduk_push_string(ctx, \"toString\");\n"
+ "\tduk_def_prop(ctx, -2, DUK_DEFPROP_HAVE_ENUMERABLE);\n"
+ "\tduk_put_global_string(ctx, proto_name);\n"
+ "\treturn DUK_ERR_NONE;\n"
+ "}\n\n",
+ MAGICPFX,
+ DLPFX);
+
+ /* generate prototype creation */
+ fprintf(bindf,
+ "duk_ret_t %s_create_prototypes(duk_context *ctx)\n", DLPFX);
+
+ fprintf(bindf, "{\n");
+
+ for (idx = 0; idx < interface_map->entryc; idx++) {
+ struct interface_map_entry *interfacee;
+
+ interfacee = interface_map->entries + idx;
+
+ /* do not generate prototype calls for interfaces marked
+ * no output
+ */
+ if (interfacee->noobject) {
+ continue;
+ }
+
+ if (interfacee->primary_global) {
+ pglobale = interfacee;
+ continue;
+ }
+
+ proto_name = get_prototype_name(interfacee->name);
+
+ fprintf(bindf,
+ "\t%s_create_prototype(ctx, %s_%s___proto, \"%s\", \"%s\");\n",
+ DLPFX,
+ DLPFX,
+ interfacee->class_name,
+ proto_name,
+ interfacee->name);
+
+ free(proto_name);
+ }
+
+ if (pglobale != NULL) {
+ fprintf(bindf, "\n\t/* Global object prototype is last */\n");
+
+ proto_name = get_prototype_name(pglobale->name);
+ fprintf(bindf,
+ "\t%s_create_prototype(ctx, %s_%s___proto, \"%s\", \"%s\");\n",
+ DLPFX,
+ DLPFX,
+ pglobale->class_name,
+ proto_name,
+ pglobale->name);
+ free(proto_name);
+ }
+
+ fprintf(bindf, "\n\treturn DUK_ERR_NONE;\n");
+
+ fprintf(bindf, "}\n");
+
+ /* binding postface */
+ output_cdata(bindf,
+ interface_map->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+ fclose(bindf);
+ return 0;
+}
+
int duk_libdom_output(struct interface_map *interface_map)
{
int idx;
@@ -1314,6 +1584,18 @@ int duk_libdom_output(struct interface_map *interface_map)
goto output_err;
}
+ /* generate binding header */
+ res = output_binding_header(interface_map);
+ if (res != 0) {
+ goto output_err;
+ }
+
+ /* generate binding source */
+ res = output_binding_src(interface_map);
+ if (res != 0) {
+ goto output_err;
+ }
+
/* generate makefile fragment */
res = output_makefile(interface_map);
diff --git a/src/interface-map.c b/src/interface-map.c
index 467c0ed..555156a 100644
--- a/src/interface-map.c
+++ b/src/interface-map.c
@@ -111,6 +111,7 @@ interface_topoligical_sort(struct interface_map_entry *srcinf, int infc)
dstinf[idx].node = srcinf[inf].node;
dstinf[idx].inherit_name = srcinf[inf].inherit_name;
dstinf[idx].noobject = srcinf[inf].noobject;
+ dstinf[idx].primary_global = srcinf[inf].primary_global;
dstinf[idx].operationc = srcinf[inf].operationc;
dstinf[idx].operationv = srcinf[inf].operationv;
dstinf[idx].attributec = srcinf[inf].attributec;
@@ -422,6 +423,7 @@ int interface_map_new(struct genbind_node *genbind,
NULL,
WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE));
+ /* is the interface marked as not generating an object */
if (webidl_node_find_type_ident(
webidl_node_getnode(node),
WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE,
@@ -433,6 +435,18 @@ int interface_map_new(struct genbind_node *genbind,
ecur->noobject = true;
}
+ /* is the interface marked as the primary global */
+ if (webidl_node_find_type_ident(
+ webidl_node_getnode(node),
+ WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE,
+ "PrimaryGlobal") != NULL) {
+ /** \todo we should ensure nothing inherits *from* this
+ * class or all hell will break loose having two
+ * primary globals.
+ */
+ ecur->primary_global = true;
+ }
+
/* matching class from binding */
ecur->class = genbind_node_find_type_ident(genbind,
NULL, GENBIND_NODE_TYPE_CLASS, ecur->name);
diff --git a/src/interface-map.h b/src/interface-map.h
index e07aa19..c34eb4b 100644
--- a/src/interface-map.h
+++ b/src/interface-map.h
@@ -49,6 +49,9 @@ struct interface_map_entry {
* generated. This allows for interfaces which do not
* generate code. For implements (mixin) interfaces
*/
+ bool primary_global; /**< flag indicating the interface is the primary
+ * global javascript object.
+ */
int operationc; /**< number of operations on interface */
struct interface_map_operation_entry *operationv;
--
NetSurf Generator for JavaScript bindings
7 years, 6 months
libnslayout: branch master updated. 5b8635deb1fcc1faf5afb19d0b59a8c8e1c48ec4
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/5b8635deb1fcc1faf...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/5b8635deb1fcc1faf5a...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/5b8635deb1fcc1faf5afb...
The branch, master has been updated
via 5b8635deb1fcc1faf5afb19d0b59a8c8e1c48ec4 (commit)
via 887073c951c8491172074efcd166cc01143f0dee (commit)
from 0367977ad546bd82a4c5c6bb747f913e4c40e00a (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=5b8635deb1fcc1f...
commit 5b8635deb1fcc1faf5afb19d0b59a8c8e1c48ec4
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add simple development testing harness.
diff --git a/dev/main.c b/dev/main.c
new file mode 100644
index 0000000..ca87816
--- /dev/null
+++ b/dev/main.c
@@ -0,0 +1,31 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include "../test/test-loader.c"
+
+/*
+ * cd ../ && make && make install && cd dev/ && gcc `pkg-config libnslayout --cflags` main.c `pkg-config libnslayout --libs` && ./a.out ; cd ~/dev-netsurf/workspace/libnslayout/dev
+ */
+
+
+static void lwc_iterator(lwc_string *str, void *pw)
+{
+ printf("[%3u] %.*s", str->refcnt,
+ (int)lwc_string_length(str),
+ lwc_string_data(str));
+}
+
+int main(void)
+{
+ nslayout_init();
+ test_loader("test-writing-mode.html", CSS_MEDIA_ALL, 15);
+ nslayout_fini();
+
+ printf("Reamining lwc strings:\n");
+ lwc_iterate_strings(lwc_iterator, NULL);
+
+ return EXIT_SUCCESS;
+}
diff --git a/dev/test-writing-mode.html b/dev/test-writing-mode.html
new file mode 100644
index 0000000..96c811e
--- /dev/null
+++ b/dev/test-writing-mode.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+html {
+ -ms-writing-mode: lr-tb;
+ -webkit-writing-mode: horizontal-tb;
+ -moz-writing-mode: horizontal-tb;
+ -ms-writing-mode: horizontal-tb;
+ writing-mode: horizontal-tb;
+}
+html:hover {
+ -ms-writing-mode: tb-rl;
+ -webkit-writing-mode: vertical-rl;
+ -moz-writing-mode: vertical-rl;
+ -ms-writing-mode: vertical-rl;
+ writing-mode: vertical-rl;
+}
+h1 {
+ background: #600;
+ color: #fff;
+ width: 50%;
+ margin: 0;
+ padding: 3px;
+ border-bottom: 2px solid black;
+}
+p {
+ margin: 0;
+ padding: 3px;
+ border: 1px solid green;
+ border-left-width: 1em;
+ margin-top: 3em;
+}
+</style>
+</head>
+<body>
+<h1>Test</h1>
+<p>Here's some text to test CSS3 writing modes <a href="https://drafts.csswg.org/css-writing-modes/#abstract-layout">abstract box layout</a>!</p>
+</body>
+</html>
diff --git a/test/test-loader.c b/test/test-loader.c
new file mode 100644
index 0000000..234561d
--- /dev/null
+++ b/test/test-loader.c
@@ -0,0 +1,305 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <dom/dom.h>
+#include <dom/bindings/hubbub/parser.h>
+#include <libcss/libcss.h>
+
+#include <libnslayout/nslayout.h>
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+static nslayout_error nslayout_test_callback(
+ nslayout_layout *layout,
+ void *pw,
+ nslayout_request *req)
+{
+ UNUSED(req);
+ UNUSED(layout);
+ UNUSED(pw);
+ return NSLAYOUT_OK;
+}
+
+struct doc_load_ctx {
+ dom_hubbub_parser *parser;
+ dom_document *doc;
+ unsigned char *buffer;
+ size_t buffer_size;
+ FILE *handle;
+ css_select_ctx *css_ctx;
+ css_stylesheet *css_sheet;
+};
+
+
+static bool doc_load_start(const char *file, size_t buffer_size,
+ struct doc_load_ctx *load_ctx)
+{
+ dom_hubbub_parser_params params;
+ dom_hubbub_error error;
+ size_t chunk_length;
+
+ params.enc = NULL;
+ params.fix_enc = true;
+ params.enable_script = false;
+ params.msg = NULL;
+ params.script = NULL;
+ params.ctx = NULL;
+ params.daf = NULL;
+
+ load_ctx->buffer = malloc(buffer_size);
+ if (load_ctx->buffer == NULL) {
+ return false;
+ }
+
+ load_ctx->buffer_size = buffer_size;
+
+ /* Create Hubbub parser */
+ error = dom_hubbub_parser_create(¶ms, &load_ctx->parser,
+ &load_ctx->doc);
+ if (error != DOM_HUBBUB_OK) {
+ free(load_ctx->buffer);
+ return false;
+ }
+
+ /* Open input file */
+ load_ctx->handle = fopen(file, "rb");
+ if (load_ctx->handle == NULL) {
+ dom_hubbub_parser_destroy(load_ctx->parser);
+ free(load_ctx->buffer);
+ return false;
+ }
+
+ /* Parse input file in chunks */
+ chunk_length = buffer_size;
+ chunk_length = fread(load_ctx->buffer, 1, load_ctx->buffer_size,
+ load_ctx->handle);
+ error = dom_hubbub_parser_parse_chunk(load_ctx->parser,
+ load_ctx->buffer, chunk_length);
+ if (error != DOM_HUBBUB_OK) {
+ dom_hubbub_parser_destroy(load_ctx->parser);
+ printf("Parsing errors occur\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+static bool doc_load_next(struct doc_load_ctx *load_ctx, bool *complete)
+{
+ dom_hubbub_error error;
+ int chunk_length;
+
+ /* Parse input file in chunks */
+ chunk_length = fread(load_ctx->buffer, 1, load_ctx->buffer_size,
+ load_ctx->handle);
+ if (chunk_length != 0) {
+ error = dom_hubbub_parser_parse_chunk(load_ctx->parser,
+ load_ctx->buffer, chunk_length);
+ if (error != DOM_HUBBUB_OK) {
+ dom_hubbub_parser_destroy(load_ctx->parser);
+ printf("Parsing errors occur\n");
+ return false;
+ }
+ *complete = false;
+ return true;
+ }
+
+ *complete = true;
+
+ /* 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);
+
+ /* Close input file */
+ if (fclose(load_ctx->handle) != 0) {
+ printf("Can't close test input file\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+static css_error resolve_url(void *pw, const char *base,
+ lwc_string *rel, lwc_string **abs)
+{
+ UNUSED(pw);
+ UNUSED(base);
+
+ /* No join implementation; just copy rel to abs for now. */
+ *abs = lwc_string_ref(rel);
+
+ return CSS_OK;
+}
+
+
+static bool test_loader_css_fini(struct doc_load_ctx *load_ctx)
+{
+ css_error css_err = CSS_OK;
+
+ if (load_ctx->css_ctx != NULL) {
+ css_err = css_select_ctx_destroy(load_ctx->css_ctx);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_select_ctx_destroy\n");
+ }
+ }
+ if (load_ctx->css_sheet != NULL) {
+ css_err = css_stylesheet_destroy(load_ctx->css_sheet);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_stylesheet_destroy\n");
+ }
+ }
+
+ return (css_err == CSS_OK);
+}
+
+
+static bool test_loader_css_init(struct doc_load_ctx *load_ctx)
+{
+ css_error css_err;
+ css_stylesheet_params params;
+ const char *ua_style =
+ "div, p, h1, h2, h3, h4, h5 {display:block}";
+
+ params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
+ params.level = CSS_LEVEL_21;
+ params.charset = "UTF-8";
+ params.url = "foo";
+ params.title = "foo";
+ params.allow_quirks = false;
+ params.inline_style = false;
+ params.resolve = resolve_url;
+ params.resolve_pw = NULL;
+ params.import = NULL;
+ params.import_pw = NULL;
+ params.color = NULL;
+ params.color_pw = NULL;
+ params.font = NULL;
+ params.font_pw = NULL;
+
+ /* create a stylesheet */
+ css_err = css_stylesheet_create(¶ms, &load_ctx->css_sheet);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_stylesheet_create\n");
+ goto fail;
+ }
+
+ css_err = css_stylesheet_append_data(load_ctx->css_sheet,
+ (const uint8_t *) ua_style, sizeof ua_style);
+ if (css_err != CSS_OK && css_err != CSS_NEEDDATA) {
+ printf("ERROR: css_stylesheet_append_data\n");
+ goto fail;
+ }
+ css_err = css_stylesheet_data_done(load_ctx->css_sheet);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_stylesheet_data_done\n");
+ goto fail;
+ }
+
+ /* Create a selection context (with no sheets added) */
+ css_err = css_select_ctx_create(&load_ctx->css_ctx);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_select_ctx_create\n");
+ goto fail;
+ }
+
+ css_err = css_select_ctx_append_sheet(load_ctx->css_ctx,
+ load_ctx->css_sheet, CSS_ORIGIN_UA, CSS_MEDIA_ALL);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_select_ctx_append_sheet\n");
+ goto fail;
+ }
+
+ return true;
+
+fail:
+ test_loader_css_fini(load_ctx);
+
+ return false;
+}
+
+
+static bool test_loader(const char *document_path,
+ css_media_type media,
+ size_t chunk_size)
+{
+ nslayout_layout *layout = NULL;
+ nslayout_error error;
+ struct doc_load_ctx load_ctx;
+ bool complete = false;
+ bool ret = false;
+
+ printf("Test loader\n");
+
+ load_ctx.parser = NULL;
+ load_ctx.doc = NULL;
+ load_ctx.buffer = NULL;
+ load_ctx.buffer_size = 0;
+ load_ctx.handle = NULL;
+ load_ctx.css_sheet = NULL;
+ load_ctx.css_ctx = NULL;
+
+ printf("Starting load\n");
+ if (!doc_load_start(document_path, chunk_size, &load_ctx)) {
+ printf("ERROR: doc_load_start\n");
+ goto fail;
+ }
+
+ printf("Creating style context\n");
+ if (!test_loader_css_init(&load_ctx)) {
+ printf("ERROR: create_style_context\n");
+ goto fail;
+ }
+
+ printf("Creating nsl layout\n");
+ error = nslayout_layout_create(load_ctx.doc,
+ load_ctx.css_ctx,
+ &media,
+ nslayout_test_callback,
+ NULL,
+ &layout);
+ if (error != NSLAYOUT_OK) {
+ goto fail;
+ }
+
+ while (!complete) {
+ printf("Loading a chunk of the document\n");
+ if (!doc_load_next(&load_ctx, &complete)) {
+ printf("ERROR: doc_load_next\n");
+ goto fail;
+ }
+ }
+
+ printf("Destroying layout\n");
+ error = nslayout_layout_destroy(layout);
+ layout = NULL;
+
+ ret = (error == NSLAYOUT_OK);
+fail:
+ if (layout != NULL) {
+ nslayout_layout_destroy(layout);
+ }
+ test_loader_css_fini(&load_ctx);
+ dom_node_unref(load_ctx.doc);
+ free(load_ctx.buffer);
+
+ return ret;
+}
+
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=887073c951c8491...
commit 887073c951c8491172074efcd166cc01143f0dee
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add DOM event handler.
Currently just prints the events it gets.
diff --git a/src/dom/Makefile b/src/dom/Makefile
new file mode 100644
index 0000000..30e1847
--- /dev/null
+++ b/src/dom/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile for libnslayout
+#
+# Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+#
+# Released under the ISC License (see COPYING file)
+
+# Sources
+DIR_SOURCES := event.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/src/dom/event.c b/src/dom/event.c
new file mode 100644
index 0000000..152fd34
--- /dev/null
+++ b/src/dom/event.c
@@ -0,0 +1,164 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/dom/event.c
+ * DOM mutation handling
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "layout.h"
+#include "dom/event.h"
+#include "util/dom-str.h"
+#include "util/util.h"
+
+static const char *nsl__dom_node_type_to_string(dom_node_type type)
+{
+ const char *str[] = {
+ "ELEMENT_NODE",
+ "ATTRIBUTE_NODE",
+ "TEXT_NODE",
+ "CDATA_SECTION_NODE",
+ "ENTITY_REFERENCE_NODE",
+ "ENTITY_NODE",
+ "PROCESSING_INSTRUCTION_NODE",
+ "COMMENT_NODE",
+ "DOCUMENT_NODE",
+ "DOCUMENT_TYPE_NODE",
+ "DOCUMENT_FRAGMENT_NODE",
+ "NOTATION_NODE"
+ };
+ assert(DOM_NODE_TYPE_COUNT == 12);
+
+ return str[type - 1];
+}
+
+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));
+ }
+
+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 */
+nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
+{
+ dom_exception exc;
+
+ /* TODO: Somehow register with libdom to get DOM change notifications.
+ *
+ * At the moment, for testing, the client calls our event
+ * handler directly. It looks as though libdom needs its
+ * DOM event handling improved. Either add DOM mutation
+ * observer support, or add some specific client notification
+ * system, like other rendering engines.
+ */
+
+ exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
+ layout, &layout->listener);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to register event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to register event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to register event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+
+ return NSLAYOUT_OK;
+}
+
+/* Exported function, documented in src/dom/event.h */
+nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
+{
+ dom_exception exc;
+
+ exc = dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to remove event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to remove event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ dom_event_listener_unref(layout->listener);
+
+ return NSLAYOUT_OK;
+}
diff --git a/src/dom/event.h b/src/dom/event.h
new file mode 100644
index 0000000..f519f40
--- /dev/null
+++ b/src/dom/event.h
@@ -0,0 +1,19 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/dom/event.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_dom_event_h_
+#define nslayout_dom_event_h_
+
+#include <libnslayout/nslayout.h>
+
+nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout);
+nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout);
+
+#endif
diff --git a/src/layout.c b/src/layout.c
index b5d74c2..f1a1490 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -10,8 +10,25 @@
#include <assert.h>
#include <stdlib.h>
+#include <stdio.h>
#include "layout.h"
+#include "dom/event.h"
+#include "util/dom-str.h"
+
+
+/* Publically exported function, documented in include/libnslayout/nslayout.h */
+nslayout_error nslayout_init(void)
+{
+ return nsl_dom_str_init();
+}
+
+
+/* Publically exported function, documented in include/libnslayout/nslayout.h */
+nslayout_error nslayout_fini(void)
+{
+ return nsl_dom_str_fini();
+}
/* Publically exported function, documented in include/libnslayout/nslayout.h */
@@ -23,13 +40,15 @@ nslayout_error nslayout_layout_create(
void *pw,
nslayout_layout **layout)
{
- nslayout_layout *l;
+ nslayout_layout *l = NULL;
assert(doc != NULL);
assert(css_ctx != NULL);
assert(media != NULL);
assert(cb != NULL);
+ printf("Called layout_create\n");
+
l = calloc(1, sizeof(nslayout_layout));
if (l == NULL) {
return NSLAYOUT_NO_MEM;
@@ -42,6 +61,9 @@ nslayout_error nslayout_layout_create(
l->cb = cb;
l->pw = pw;
+ /* TODO: error handling */
+ nsl_dom_event_layout_init(l);
+
*layout = l;
return NSLAYOUT_OK;
}
@@ -51,9 +73,12 @@ nslayout_error nslayout_layout_create(
nslayout_error nslayout_layout_destroy(
nslayout_layout *layout)
{
- /* TODO: free/unref the stuff we own in the layout */
assert(layout != NULL);
+ /* TODO: free/unref the stuff we own in the layout */
+ /* TODO: error handling */
+ nsl_dom_event_layout_fini(layout);
+
free(layout);
return NSLAYOUT_OK;
}
diff --git a/src/layout.h b/src/layout.h
index 9946663..e71d5aa 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -19,6 +19,8 @@ struct nslayout_layout {
css_media_type *media;
nslayout_callback cb;
void *pw;
+
+ dom_event_listener *listener;
};
#endif
diff --git a/src/util/Makefile b/src/util/Makefile
new file mode 100644
index 0000000..4f95e74
--- /dev/null
+++ b/src/util/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile for libnslayout
+#
+# Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+#
+# Released under the ISC License (see COPYING file)
+
+# Sources
+DIR_SOURCES := dom-str.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/src/util/dom-str.c b/src/util/dom-str.c
new file mode 100644
index 0000000..b959afe
--- /dev/null
+++ b/src/util/dom-str.c
@@ -0,0 +1,54 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/util/dom-str.c
+ * Layout object handling
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util/dom-str.h"
+#include "util/util.h"
+
+dom_string *nsl_dom_str_node_inserted;
+dom_string *nsl_dom_str_subtree_modified;
+
+
+/* Exported function, documented in src/util/dom-str.h */
+nslayout_error nsl_dom_str_init(void)
+{
+ dom_exception exc;
+
+ exc = dom_string_create((const uint8_t *)"DOMNodeInserted",
+ SLEN("DOMNodeInserted"),
+ &nsl_dom_str_node_inserted);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to create string!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_string_create((const uint8_t *)"DOMSubtreeModified",
+ SLEN("DOMSubtreeModified"),
+ &nsl_dom_str_subtree_modified);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to create string!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+
+ return NSLAYOUT_OK;
+}
+
+
+/* Exported function, documented in src/util/dom-str.h */
+nslayout_error nsl_dom_str_fini(void)
+{
+ dom_string_unref(nsl_dom_str_node_inserted);
+ dom_string_unref(nsl_dom_str_subtree_modified);
+
+ return NSLAYOUT_OK;
+}
diff --git a/src/util/dom-str.h b/src/util/dom-str.h
new file mode 100644
index 0000000..9a51ad5
--- /dev/null
+++ b/src/util/dom-str.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/util/dom-str.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_util_dom_str_h_
+#define nslayout_util_dom_str_h_
+
+#include <libnslayout/nslayout.h>
+
+extern dom_string *nsl_dom_str_node_inserted;
+extern dom_string *nsl_dom_str_subtree_modified;
+
+/**
+ * Create the internal DOM strings
+ *
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_str_init(void);
+
+/**
+ * Unref the internal DOM strings
+ *
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_str_fini(void);
+
+#endif
diff --git a/src/util/util.h b/src/util/util.h
new file mode 100644
index 0000000..c03691b
--- /dev/null
+++ b/src/util/util.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/util/util.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_util_util_h_
+#define nslayout_util_util_h_
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+#ifndef SLEN
+#define SLEN(x) (sizeof((x)) - 1)
+#endif
+
+#endif
diff --git a/test/assert-tests.c b/test/assert-tests.c
index 1b97814..44bc2f7 100644
--- a/test/assert-tests.c
+++ b/test/assert-tests.c
@@ -18,6 +18,7 @@
START_TEST (test_nslayout_layout_create_aborts1)
{
nslayout_layout *layout;
+
(void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
}
END_TEST
diff --git a/test/nslayout-object-tests.c b/test/nslayout-object-tests.c
index a2f9afc..612a983 100644
--- a/test/nslayout-object-tests.c
+++ b/test/nslayout-object-tests.c
@@ -44,6 +44,8 @@ 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);
+
error = nslayout_layout_create(doc,
css_ctx,
&media,
@@ -59,6 +61,8 @@ START_TEST (test_nslayout_layout_create_ok)
fail_unless(error == NSLAYOUT_OK,
"Unable to destroy layout");
+ ck_assert(nslayout_fini() == NSLAYOUT_OK);
+
css_err = css_select_ctx_destroy(css_ctx);
ck_assert(css_err == CSS_OK);
-----------------------------------------------------------------------
Summary of changes:
dev/main.c | 31 +++++
dev/test-writing-mode.html | 40 ++++++
src/{ => dom}/Makefile | 2 +-
src/dom/event.c | 164 ++++++++++++++++++++++
src/{layout.h => dom/event.h} | 15 +-
src/layout.c | 29 +++-
src/layout.h | 2 +
src/{ => util}/Makefile | 2 +-
src/util/dom-str.c | 54 ++++++++
src/util/dom-str.h | 33 +++++
src/util/util.h | 22 +++
test/assert-tests.c | 1 +
test/nslayout-object-tests.c | 4 +
test/test-loader.c | 305 +++++++++++++++++++++++++++++++++++++++++
14 files changed, 690 insertions(+), 14 deletions(-)
create mode 100644 dev/main.c
create mode 100644 dev/test-writing-mode.html
copy src/{ => dom}/Makefile (88%)
create mode 100644 src/dom/event.c
copy src/{layout.h => dom/event.h} (52%)
copy src/{ => util}/Makefile (88%)
create mode 100644 src/util/dom-str.c
create mode 100644 src/util/dom-str.h
create mode 100644 src/util/util.h
create mode 100644 test/test-loader.c
diff --git a/dev/main.c b/dev/main.c
new file mode 100644
index 0000000..ca87816
--- /dev/null
+++ b/dev/main.c
@@ -0,0 +1,31 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include "../test/test-loader.c"
+
+/*
+ * cd ../ && make && make install && cd dev/ && gcc `pkg-config libnslayout --cflags` main.c `pkg-config libnslayout --libs` && ./a.out ; cd ~/dev-netsurf/workspace/libnslayout/dev
+ */
+
+
+static void lwc_iterator(lwc_string *str, void *pw)
+{
+ printf("[%3u] %.*s", str->refcnt,
+ (int)lwc_string_length(str),
+ lwc_string_data(str));
+}
+
+int main(void)
+{
+ nslayout_init();
+ test_loader("test-writing-mode.html", CSS_MEDIA_ALL, 15);
+ nslayout_fini();
+
+ printf("Reamining lwc strings:\n");
+ lwc_iterate_strings(lwc_iterator, NULL);
+
+ return EXIT_SUCCESS;
+}
diff --git a/dev/test-writing-mode.html b/dev/test-writing-mode.html
new file mode 100644
index 0000000..96c811e
--- /dev/null
+++ b/dev/test-writing-mode.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+html {
+ -ms-writing-mode: lr-tb;
+ -webkit-writing-mode: horizontal-tb;
+ -moz-writing-mode: horizontal-tb;
+ -ms-writing-mode: horizontal-tb;
+ writing-mode: horizontal-tb;
+}
+html:hover {
+ -ms-writing-mode: tb-rl;
+ -webkit-writing-mode: vertical-rl;
+ -moz-writing-mode: vertical-rl;
+ -ms-writing-mode: vertical-rl;
+ writing-mode: vertical-rl;
+}
+h1 {
+ background: #600;
+ color: #fff;
+ width: 50%;
+ margin: 0;
+ padding: 3px;
+ border-bottom: 2px solid black;
+}
+p {
+ margin: 0;
+ padding: 3px;
+ border: 1px solid green;
+ border-left-width: 1em;
+ margin-top: 3em;
+}
+</style>
+</head>
+<body>
+<h1>Test</h1>
+<p>Here's some text to test CSS3 writing modes <a href="https://drafts.csswg.org/css-writing-modes/#abstract-layout">abstract box layout</a>!</p>
+</body>
+</html>
diff --git a/src/Makefile b/src/dom/Makefile
similarity index 88%
copy from src/Makefile
copy to src/dom/Makefile
index 7a6251d..30e1847 100644
--- a/src/Makefile
+++ b/src/dom/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := layout.c
+DIR_SOURCES := event.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/dom/event.c b/src/dom/event.c
new file mode 100644
index 0000000..152fd34
--- /dev/null
+++ b/src/dom/event.c
@@ -0,0 +1,164 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/dom/event.c
+ * DOM mutation handling
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "layout.h"
+#include "dom/event.h"
+#include "util/dom-str.h"
+#include "util/util.h"
+
+static const char *nsl__dom_node_type_to_string(dom_node_type type)
+{
+ const char *str[] = {
+ "ELEMENT_NODE",
+ "ATTRIBUTE_NODE",
+ "TEXT_NODE",
+ "CDATA_SECTION_NODE",
+ "ENTITY_REFERENCE_NODE",
+ "ENTITY_NODE",
+ "PROCESSING_INSTRUCTION_NODE",
+ "COMMENT_NODE",
+ "DOCUMENT_NODE",
+ "DOCUMENT_TYPE_NODE",
+ "DOCUMENT_FRAGMENT_NODE",
+ "NOTATION_NODE"
+ };
+ assert(DOM_NODE_TYPE_COUNT == 12);
+
+ return str[type - 1];
+}
+
+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));
+ }
+
+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 */
+nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
+{
+ dom_exception exc;
+
+ /* TODO: Somehow register with libdom to get DOM change notifications.
+ *
+ * At the moment, for testing, the client calls our event
+ * handler directly. It looks as though libdom needs its
+ * DOM event handling improved. Either add DOM mutation
+ * observer support, or add some specific client notification
+ * system, like other rendering engines.
+ */
+
+ exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
+ layout, &layout->listener);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to register event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to register event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_event_target_add_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to register event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+
+ return NSLAYOUT_OK;
+}
+
+/* Exported function, documented in src/dom/event.h */
+nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
+{
+ dom_exception exc;
+
+ exc = dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to remove event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_subtree_modified,
+ layout->listener, false);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to remove event handler!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ dom_event_listener_unref(layout->listener);
+
+ return NSLAYOUT_OK;
+}
diff --git a/src/layout.h b/src/dom/event.h
similarity index 52%
copy from src/layout.h
copy to src/dom/event.h
index 9946663..f519f40 100644
--- a/src/layout.h
+++ b/src/dom/event.h
@@ -4,21 +4,16 @@
* Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
*/
-/** \file src/layout.h
+/** \file src/dom/event.h
* Layout object handling
*/
-#ifndef nslayout_layout_h_
-#define nslayout_layout_h_
+#ifndef nslayout_dom_event_h_
+#define nslayout_dom_event_h_
#include <libnslayout/nslayout.h>
-struct nslayout_layout {
- dom_document *doc;
- css_select_ctx *css_ctx;
- css_media_type *media;
- nslayout_callback cb;
- void *pw;
-};
+nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout);
+nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout);
#endif
diff --git a/src/layout.c b/src/layout.c
index b5d74c2..f1a1490 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -10,8 +10,25 @@
#include <assert.h>
#include <stdlib.h>
+#include <stdio.h>
#include "layout.h"
+#include "dom/event.h"
+#include "util/dom-str.h"
+
+
+/* Publically exported function, documented in include/libnslayout/nslayout.h */
+nslayout_error nslayout_init(void)
+{
+ return nsl_dom_str_init();
+}
+
+
+/* Publically exported function, documented in include/libnslayout/nslayout.h */
+nslayout_error nslayout_fini(void)
+{
+ return nsl_dom_str_fini();
+}
/* Publically exported function, documented in include/libnslayout/nslayout.h */
@@ -23,13 +40,15 @@ nslayout_error nslayout_layout_create(
void *pw,
nslayout_layout **layout)
{
- nslayout_layout *l;
+ nslayout_layout *l = NULL;
assert(doc != NULL);
assert(css_ctx != NULL);
assert(media != NULL);
assert(cb != NULL);
+ printf("Called layout_create\n");
+
l = calloc(1, sizeof(nslayout_layout));
if (l == NULL) {
return NSLAYOUT_NO_MEM;
@@ -42,6 +61,9 @@ nslayout_error nslayout_layout_create(
l->cb = cb;
l->pw = pw;
+ /* TODO: error handling */
+ nsl_dom_event_layout_init(l);
+
*layout = l;
return NSLAYOUT_OK;
}
@@ -51,9 +73,12 @@ nslayout_error nslayout_layout_create(
nslayout_error nslayout_layout_destroy(
nslayout_layout *layout)
{
- /* TODO: free/unref the stuff we own in the layout */
assert(layout != NULL);
+ /* TODO: free/unref the stuff we own in the layout */
+ /* TODO: error handling */
+ nsl_dom_event_layout_fini(layout);
+
free(layout);
return NSLAYOUT_OK;
}
diff --git a/src/layout.h b/src/layout.h
index 9946663..e71d5aa 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -19,6 +19,8 @@ struct nslayout_layout {
css_media_type *media;
nslayout_callback cb;
void *pw;
+
+ dom_event_listener *listener;
};
#endif
diff --git a/src/Makefile b/src/util/Makefile
similarity index 88%
copy from src/Makefile
copy to src/util/Makefile
index 7a6251d..4f95e74 100644
--- a/src/Makefile
+++ b/src/util/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := layout.c
+DIR_SOURCES := dom-str.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/util/dom-str.c b/src/util/dom-str.c
new file mode 100644
index 0000000..b959afe
--- /dev/null
+++ b/src/util/dom-str.c
@@ -0,0 +1,54 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/util/dom-str.c
+ * Layout object handling
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util/dom-str.h"
+#include "util/util.h"
+
+dom_string *nsl_dom_str_node_inserted;
+dom_string *nsl_dom_str_subtree_modified;
+
+
+/* Exported function, documented in src/util/dom-str.h */
+nslayout_error nsl_dom_str_init(void)
+{
+ dom_exception exc;
+
+ exc = dom_string_create((const uint8_t *)"DOMNodeInserted",
+ SLEN("DOMNodeInserted"),
+ &nsl_dom_str_node_inserted);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to create string!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+ exc = dom_string_create((const uint8_t *)"DOMSubtreeModified",
+ SLEN("DOMSubtreeModified"),
+ &nsl_dom_str_subtree_modified);
+ if (exc != DOM_NO_ERR) {
+ /* TODO: free stuff, return value */
+ printf("Failed to create string!\n");
+ return NSLAYOUT_NO_MEM;
+ }
+
+ return NSLAYOUT_OK;
+}
+
+
+/* Exported function, documented in src/util/dom-str.h */
+nslayout_error nsl_dom_str_fini(void)
+{
+ dom_string_unref(nsl_dom_str_node_inserted);
+ dom_string_unref(nsl_dom_str_subtree_modified);
+
+ return NSLAYOUT_OK;
+}
diff --git a/src/util/dom-str.h b/src/util/dom-str.h
new file mode 100644
index 0000000..9a51ad5
--- /dev/null
+++ b/src/util/dom-str.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/util/dom-str.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_util_dom_str_h_
+#define nslayout_util_dom_str_h_
+
+#include <libnslayout/nslayout.h>
+
+extern dom_string *nsl_dom_str_node_inserted;
+extern dom_string *nsl_dom_str_subtree_modified;
+
+/**
+ * Create the internal DOM strings
+ *
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_str_init(void);
+
+/**
+ * Unref the internal DOM strings
+ *
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nsl_dom_str_fini(void);
+
+#endif
diff --git a/src/util/util.h b/src/util/util.h
new file mode 100644
index 0000000..c03691b
--- /dev/null
+++ b/src/util/util.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/util/util.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_util_util_h_
+#define nslayout_util_util_h_
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+#ifndef SLEN
+#define SLEN(x) (sizeof((x)) - 1)
+#endif
+
+#endif
diff --git a/test/assert-tests.c b/test/assert-tests.c
index 1b97814..44bc2f7 100644
--- a/test/assert-tests.c
+++ b/test/assert-tests.c
@@ -18,6 +18,7 @@
START_TEST (test_nslayout_layout_create_aborts1)
{
nslayout_layout *layout;
+
(void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
}
END_TEST
diff --git a/test/nslayout-object-tests.c b/test/nslayout-object-tests.c
index a2f9afc..612a983 100644
--- a/test/nslayout-object-tests.c
+++ b/test/nslayout-object-tests.c
@@ -44,6 +44,8 @@ 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);
+
error = nslayout_layout_create(doc,
css_ctx,
&media,
@@ -59,6 +61,8 @@ START_TEST (test_nslayout_layout_create_ok)
fail_unless(error == NSLAYOUT_OK,
"Unable to destroy layout");
+ ck_assert(nslayout_fini() == NSLAYOUT_OK);
+
css_err = css_select_ctx_destroy(css_ctx);
ck_assert(css_err == CSS_OK);
diff --git a/test/test-loader.c b/test/test-loader.c
new file mode 100644
index 0000000..234561d
--- /dev/null
+++ b/test/test-loader.c
@@ -0,0 +1,305 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <dom/dom.h>
+#include <dom/bindings/hubbub/parser.h>
+#include <libcss/libcss.h>
+
+#include <libnslayout/nslayout.h>
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+static nslayout_error nslayout_test_callback(
+ nslayout_layout *layout,
+ void *pw,
+ nslayout_request *req)
+{
+ UNUSED(req);
+ UNUSED(layout);
+ UNUSED(pw);
+ return NSLAYOUT_OK;
+}
+
+struct doc_load_ctx {
+ dom_hubbub_parser *parser;
+ dom_document *doc;
+ unsigned char *buffer;
+ size_t buffer_size;
+ FILE *handle;
+ css_select_ctx *css_ctx;
+ css_stylesheet *css_sheet;
+};
+
+
+static bool doc_load_start(const char *file, size_t buffer_size,
+ struct doc_load_ctx *load_ctx)
+{
+ dom_hubbub_parser_params params;
+ dom_hubbub_error error;
+ size_t chunk_length;
+
+ params.enc = NULL;
+ params.fix_enc = true;
+ params.enable_script = false;
+ params.msg = NULL;
+ params.script = NULL;
+ params.ctx = NULL;
+ params.daf = NULL;
+
+ load_ctx->buffer = malloc(buffer_size);
+ if (load_ctx->buffer == NULL) {
+ return false;
+ }
+
+ load_ctx->buffer_size = buffer_size;
+
+ /* Create Hubbub parser */
+ error = dom_hubbub_parser_create(¶ms, &load_ctx->parser,
+ &load_ctx->doc);
+ if (error != DOM_HUBBUB_OK) {
+ free(load_ctx->buffer);
+ return false;
+ }
+
+ /* Open input file */
+ load_ctx->handle = fopen(file, "rb");
+ if (load_ctx->handle == NULL) {
+ dom_hubbub_parser_destroy(load_ctx->parser);
+ free(load_ctx->buffer);
+ return false;
+ }
+
+ /* Parse input file in chunks */
+ chunk_length = buffer_size;
+ chunk_length = fread(load_ctx->buffer, 1, load_ctx->buffer_size,
+ load_ctx->handle);
+ error = dom_hubbub_parser_parse_chunk(load_ctx->parser,
+ load_ctx->buffer, chunk_length);
+ if (error != DOM_HUBBUB_OK) {
+ dom_hubbub_parser_destroy(load_ctx->parser);
+ printf("Parsing errors occur\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+static bool doc_load_next(struct doc_load_ctx *load_ctx, bool *complete)
+{
+ dom_hubbub_error error;
+ int chunk_length;
+
+ /* Parse input file in chunks */
+ chunk_length = fread(load_ctx->buffer, 1, load_ctx->buffer_size,
+ load_ctx->handle);
+ if (chunk_length != 0) {
+ error = dom_hubbub_parser_parse_chunk(load_ctx->parser,
+ load_ctx->buffer, chunk_length);
+ if (error != DOM_HUBBUB_OK) {
+ dom_hubbub_parser_destroy(load_ctx->parser);
+ printf("Parsing errors occur\n");
+ return false;
+ }
+ *complete = false;
+ return true;
+ }
+
+ *complete = true;
+
+ /* 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);
+
+ /* Close input file */
+ if (fclose(load_ctx->handle) != 0) {
+ printf("Can't close test input file\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+static css_error resolve_url(void *pw, const char *base,
+ lwc_string *rel, lwc_string **abs)
+{
+ UNUSED(pw);
+ UNUSED(base);
+
+ /* No join implementation; just copy rel to abs for now. */
+ *abs = lwc_string_ref(rel);
+
+ return CSS_OK;
+}
+
+
+static bool test_loader_css_fini(struct doc_load_ctx *load_ctx)
+{
+ css_error css_err = CSS_OK;
+
+ if (load_ctx->css_ctx != NULL) {
+ css_err = css_select_ctx_destroy(load_ctx->css_ctx);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_select_ctx_destroy\n");
+ }
+ }
+ if (load_ctx->css_sheet != NULL) {
+ css_err = css_stylesheet_destroy(load_ctx->css_sheet);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_stylesheet_destroy\n");
+ }
+ }
+
+ return (css_err == CSS_OK);
+}
+
+
+static bool test_loader_css_init(struct doc_load_ctx *load_ctx)
+{
+ css_error css_err;
+ css_stylesheet_params params;
+ const char *ua_style =
+ "div, p, h1, h2, h3, h4, h5 {display:block}";
+
+ params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
+ params.level = CSS_LEVEL_21;
+ params.charset = "UTF-8";
+ params.url = "foo";
+ params.title = "foo";
+ params.allow_quirks = false;
+ params.inline_style = false;
+ params.resolve = resolve_url;
+ params.resolve_pw = NULL;
+ params.import = NULL;
+ params.import_pw = NULL;
+ params.color = NULL;
+ params.color_pw = NULL;
+ params.font = NULL;
+ params.font_pw = NULL;
+
+ /* create a stylesheet */
+ css_err = css_stylesheet_create(¶ms, &load_ctx->css_sheet);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_stylesheet_create\n");
+ goto fail;
+ }
+
+ css_err = css_stylesheet_append_data(load_ctx->css_sheet,
+ (const uint8_t *) ua_style, sizeof ua_style);
+ if (css_err != CSS_OK && css_err != CSS_NEEDDATA) {
+ printf("ERROR: css_stylesheet_append_data\n");
+ goto fail;
+ }
+ css_err = css_stylesheet_data_done(load_ctx->css_sheet);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_stylesheet_data_done\n");
+ goto fail;
+ }
+
+ /* Create a selection context (with no sheets added) */
+ css_err = css_select_ctx_create(&load_ctx->css_ctx);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_select_ctx_create\n");
+ goto fail;
+ }
+
+ css_err = css_select_ctx_append_sheet(load_ctx->css_ctx,
+ load_ctx->css_sheet, CSS_ORIGIN_UA, CSS_MEDIA_ALL);
+ if (css_err != CSS_OK) {
+ printf("ERROR: css_select_ctx_append_sheet\n");
+ goto fail;
+ }
+
+ return true;
+
+fail:
+ test_loader_css_fini(load_ctx);
+
+ return false;
+}
+
+
+static bool test_loader(const char *document_path,
+ css_media_type media,
+ size_t chunk_size)
+{
+ nslayout_layout *layout = NULL;
+ nslayout_error error;
+ struct doc_load_ctx load_ctx;
+ bool complete = false;
+ bool ret = false;
+
+ printf("Test loader\n");
+
+ load_ctx.parser = NULL;
+ load_ctx.doc = NULL;
+ load_ctx.buffer = NULL;
+ load_ctx.buffer_size = 0;
+ load_ctx.handle = NULL;
+ load_ctx.css_sheet = NULL;
+ load_ctx.css_ctx = NULL;
+
+ printf("Starting load\n");
+ if (!doc_load_start(document_path, chunk_size, &load_ctx)) {
+ printf("ERROR: doc_load_start\n");
+ goto fail;
+ }
+
+ printf("Creating style context\n");
+ if (!test_loader_css_init(&load_ctx)) {
+ printf("ERROR: create_style_context\n");
+ goto fail;
+ }
+
+ printf("Creating nsl layout\n");
+ error = nslayout_layout_create(load_ctx.doc,
+ load_ctx.css_ctx,
+ &media,
+ nslayout_test_callback,
+ NULL,
+ &layout);
+ if (error != NSLAYOUT_OK) {
+ goto fail;
+ }
+
+ while (!complete) {
+ printf("Loading a chunk of the document\n");
+ if (!doc_load_next(&load_ctx, &complete)) {
+ printf("ERROR: doc_load_next\n");
+ goto fail;
+ }
+ }
+
+ printf("Destroying layout\n");
+ error = nslayout_layout_destroy(layout);
+ layout = NULL;
+
+ ret = (error == NSLAYOUT_OK);
+fail:
+ if (layout != NULL) {
+ nslayout_layout_destroy(layout);
+ }
+ test_loader_css_fini(&load_ctx);
+ dom_node_unref(load_ctx.doc);
+ free(load_ctx.buffer);
+
+ return ret;
+}
+
--
NetSurf Layout Engine
7 years, 6 months
libdom: branch master updated. release/0.1.2-7-g419b9a7
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/419b9a774b533462d9fa59...
...commit http://git.netsurf-browser.org/libdom.git/commit/419b9a774b533462d9fa59e8...
...tree http://git.netsurf-browser.org/libdom.git/tree/419b9a774b533462d9fa59e873...
The branch, master has been updated
via 419b9a774b533462d9fa59e8733425a7e33c3efc (commit)
via 32efbef928f239b1dc35d1ecd6a0baed1893291e (commit)
from ff1caf307c8ea8a8f407c44da48fa6c55cb5e30a (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/libdom.git/commit/?id=419b9a774b533462d9fa...
commit 419b9a774b533462d9fa59e8733425a7e33c3efc
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix removal of event listeners.
diff --git a/src/events/event_target.c b/src/events/event_target.c
index 6df683d..cb4e25b 100644
--- a/src/events/event_target.c
+++ b/src/events/event_target.c
@@ -109,6 +109,13 @@ dom_exception _dom_event_target_remove_event_listener(
if (dom_string_isequal(le->type, type) &&
le->listener == listener &&
le->capture == capture) {
+ if (le->list.next == &le->list) {
+ eti->listeners = NULL;
+ } else {
+ eti->listeners =
+ (struct listener_entry *)
+ le->list.next;
+ }
list_del(&le->list);
dom_event_listener_unref(le->listener);
dom_string_unref(le->type);
@@ -117,7 +124,7 @@ dom_exception _dom_event_target_remove_event_listener(
}
le = (struct listener_entry *) le->list.next;
- } while (le != eti->listeners);
+ } while (eti->listeners != NULL && le != eti->listeners);
}
return DOM_NO_ERR;
commitdiff http://git.netsurf-browser.org/libdom.git/commit/?id=32efbef928f239b1dc35...
commit 32efbef928f239b1dc35d1ecd6a0baed1893291e
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Leave top 8 bits of dom exception unused.
diff --git a/include/dom/core/exceptions.h b/include/dom/core/exceptions.h
index 04c7f18..0370a00 100644
--- a/include/dom/core/exceptions.h
+++ b/include/dom/core/exceptions.h
@@ -11,13 +11,13 @@
/**
* Class of a DOM exception.
*
- * The top 16 bits of a dom_exception are a bitfield
+ * The top 8 bits of a dom_exception are unused, the next 8 bits are a bitfield
* indicating which class the exception belongs to.
*/
typedef enum {
DOM_EXCEPTION_CLASS_NORMAL = 0,
- DOM_EXCEPTION_CLASS_EVENT = (1<<30),
- DOM_EXCEPTION_CLASS_INTERNAL = (1<<31)
+ DOM_EXCEPTION_CLASS_EVENT = (1<<16),
+ DOM_EXCEPTION_CLASS_INTERNAL = (1<<17)
} dom_exception_class;
/* The DOM spec says that this is actually an unsigned short */
-----------------------------------------------------------------------
Summary of changes:
include/dom/core/exceptions.h | 6 +++---
src/events/event_target.c | 9 ++++++++-
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/dom/core/exceptions.h b/include/dom/core/exceptions.h
index 04c7f18..0370a00 100644
--- a/include/dom/core/exceptions.h
+++ b/include/dom/core/exceptions.h
@@ -11,13 +11,13 @@
/**
* Class of a DOM exception.
*
- * The top 16 bits of a dom_exception are a bitfield
+ * The top 8 bits of a dom_exception are unused, the next 8 bits are a bitfield
* indicating which class the exception belongs to.
*/
typedef enum {
DOM_EXCEPTION_CLASS_NORMAL = 0,
- DOM_EXCEPTION_CLASS_EVENT = (1<<30),
- DOM_EXCEPTION_CLASS_INTERNAL = (1<<31)
+ DOM_EXCEPTION_CLASS_EVENT = (1<<16),
+ DOM_EXCEPTION_CLASS_INTERNAL = (1<<17)
} dom_exception_class;
/* The DOM spec says that this is actually an unsigned short */
diff --git a/src/events/event_target.c b/src/events/event_target.c
index 6df683d..cb4e25b 100644
--- a/src/events/event_target.c
+++ b/src/events/event_target.c
@@ -109,6 +109,13 @@ dom_exception _dom_event_target_remove_event_listener(
if (dom_string_isequal(le->type, type) &&
le->listener == listener &&
le->capture == capture) {
+ if (le->list.next == &le->list) {
+ eti->listeners = NULL;
+ } else {
+ eti->listeners =
+ (struct listener_entry *)
+ le->list.next;
+ }
list_del(&le->list);
dom_event_listener_unref(le->listener);
dom_string_unref(le->type);
@@ -117,7 +124,7 @@ dom_exception _dom_event_target_remove_event_listener(
}
le = (struct listener_entry *) le->list.next;
- } while (le != eti->listeners);
+ } while (eti->listeners != NULL && le != eti->listeners);
}
return DOM_NO_ERR;
--
Document Object Model library
7 years, 6 months
netsurf: branch dsilvers/dukky updated. release/3.3-237-g19b4528
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/19b4528665f166b09d34f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/19b4528665f166b09d34fc5...
...tree http://git.netsurf-browser.org/netsurf.git/tree/19b4528665f166b09d34fc5e3...
The branch, dsilvers/dukky has been updated
via 19b4528665f166b09d34fc5e35a504b9c853d6b5 (commit)
from d4222fab05f909226617587f85223e7551b5323e (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/netsurf.git/commit/?id=19b4528665f166b09d3...
commit 19b4528665f166b09d34fc5e35a504b9c853d6b5
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
missing file
diff --git a/javascript/duktape/html_br_element.c b/javascript/duktape/html_br_element.c
new file mode 100644
index 0000000..6b5dd9e
--- /dev/null
+++ b/javascript/duktape/html_br_element.c
@@ -0,0 +1,50 @@
+/* DO NOT USE, DODGY BIT FOR VINCE */
+
+#include <dom/dom.h>
+
+#include "utils/log.h"
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(html_br_element, struct dom_html_br_element *html_br_element)
+{
+ DUKKY_FUNC_T(html_element, __init)(ctx, &priv->parent, (struct dom_html_element *)html_br_element);
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+}
+
+DUKKY_FUNC_FINI(html_br_element)
+{
+ /* do any html_br_element finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ DUKKY_FUNC_T(html_element, __fini)(ctx, &priv->parent);
+}
+
+static DUKKY_FUNC(html_br_element, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(html_br_element);
+ DUKKY_FUNC_T(html_br_element, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ duk_set_top(ctx, 1);
+ return 1;
+}
+
+static DUKKY_FUNC(html_br_element, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(html_br_element, 0);
+ DUKKY_FUNC_T(html_br_element, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(html_br_element, __proto)
+{
+ /* Populate html_br_element's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ DUKKY_GET_PROTOTYPE(HTMLELEMENT);
+ duk_set_prototype(ctx, 0);
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, html_br_element);
+ DUKKY_SET_CONSTRUCTOR(0, html_br_element, 1);
+ return 1; /* The proto object */
+}
-----------------------------------------------------------------------
Summary of changes:
javascript/duktape/html_br_element.c | 50 ++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 javascript/duktape/html_br_element.c
diff --git a/javascript/duktape/html_br_element.c b/javascript/duktape/html_br_element.c
new file mode 100644
index 0000000..6b5dd9e
--- /dev/null
+++ b/javascript/duktape/html_br_element.c
@@ -0,0 +1,50 @@
+/* DO NOT USE, DODGY BIT FOR VINCE */
+
+#include <dom/dom.h>
+
+#include "utils/log.h"
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(html_br_element, struct dom_html_br_element *html_br_element)
+{
+ DUKKY_FUNC_T(html_element, __init)(ctx, &priv->parent, (struct dom_html_element *)html_br_element);
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+}
+
+DUKKY_FUNC_FINI(html_br_element)
+{
+ /* do any html_br_element finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ DUKKY_FUNC_T(html_element, __fini)(ctx, &priv->parent);
+}
+
+static DUKKY_FUNC(html_br_element, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(html_br_element);
+ DUKKY_FUNC_T(html_br_element, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ duk_set_top(ctx, 1);
+ return 1;
+}
+
+static DUKKY_FUNC(html_br_element, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(html_br_element, 0);
+ DUKKY_FUNC_T(html_br_element, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(html_br_element, __proto)
+{
+ /* Populate html_br_element's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ DUKKY_GET_PROTOTYPE(HTMLELEMENT);
+ duk_set_prototype(ctx, 0);
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, html_br_element);
+ DUKKY_SET_CONSTRUCTOR(0, html_br_element, 1);
+ return 1; /* The proto object */
+}
--
NetSurf Browser
7 years, 6 months