libnslayout: branch master updated. 9b0852e12713b44d4dd82ff67496c84a19af84b3
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/9b0852e12713b44d4...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/9b0852e12713b44d4dd...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/9b0852e12713b44d4dd82...
The branch, master has been updated
via 9b0852e12713b44d4dd82ff67496c84a19af84b3 (commit)
via b4ef9675d824597a2d1bfc2c0a2c0e3b29ee17a6 (commit)
from 91366856f641dc74b6ad05168b65e4c38976d48a (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=9b0852e12713b44...
commit 9b0852e12713b44d4dd82ff67496c84a19af84b3
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add request callback wrappers.
diff --git a/src/request.h b/src/request.h
new file mode 100644
index 0000000..c28468e
--- /dev/null
+++ b/src/request.h
@@ -0,0 +1,141 @@
+/*
+ * 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/request.h
+ * Client callback wrappers
+ */
+
+#ifndef nslayout_request_h_
+#define nslayout_request_h_
+
+#include <libnslayout/nslayout.h>
+
+/**
+ * Perform GET_RESOURCE client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] url Absolute URL to request replaced object handle for.
+ * \param[out] replaced Returns the replaced element content handle.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_get_resource(
+ nslayout_layout *layout,
+ const char *url,
+ nslayout_replaced **replaced)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_GET_RESOURCE;
+ req.request.get_resource.url = url;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ *replaced = *req.response.get_resource.replaced;
+ return err;
+}
+
+/**
+ * Perform CREATE_REPLACED client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] element DOM element that needs replacement object.
+ * \param[out] replaced Returns the replaced element content handle.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_create_replaced(
+ nslayout_layout *layout,
+ dom_element *element,
+ nslayout_replaced **replaced)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_CREATE_REPLACED;
+ req.request.create_replaced.element = element;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ *replaced = *req.response.create_replaced.replaced;
+ return err;
+}
+
+/**
+ * Perform RENDER client callback
+ *
+ * \param[in] layout Layout object being rendered.
+ * \param[in] list Render list to render.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_render(
+ nslayout_layout *layout,
+ nslayout_render_list *list)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_RENDER;
+ req.request.render.list = list;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ return err;
+}
+
+/**
+ * Perform SET_EXTENTS client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] width The layout's full width.
+ * \param[in] height The layout's full height.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_set_extents(
+ nslayout_layout *layout,
+ unsigned int width,
+ unsigned int height)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_SET_EXTENTS;
+ req.request.set_extents.width = width;
+ req.request.set_extents.height = height;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ return err;
+}
+
+/**
+ * Perform GET_INTRINSIC_SIZE client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] replaced Replaced object to get intrinsic size of.
+ * \param[out] width Returns the replaced object's width.
+ * \param[out] height Returns the replaced object's height.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_get_intrinsic_size(
+ nslayout_layout *layout,
+ nslayout_replaced *replaced,
+ unsigned int *width,
+ unsigned int *height)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_GET_INTRINSIC_SIZE;
+ req.request.get_intrinsic_size.replaced = replaced;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ *width = *req.response.get_intrinsic_size.width;
+ *height = *req.response.get_intrinsic_size.height;
+ return err;
+}
+
+#endif
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=b4ef9675d824597...
commit b4ef9675d824597a2d1bfc2c0a2c0e3b29ee17a6
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Update documentation and minor fixes.
diff --git a/docs/Doxyfile b/docs/Doxyfile
new file mode 100644
index 0000000..56c3433
--- /dev/null
+++ b/docs/Doxyfile
@@ -0,0 +1,261 @@
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = "LibNSLayout"
+PROJECT_NUMBER =
+PROJECT_BRIEF = "The NetSurf Browser Layout Engine"
+PROJECT_LOGO =
+OUTPUT_DIRECTORY = docs/
+CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING =
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = NO
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+INPUT =
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS =
+RECURSIVE = YES
+EXCLUDE = test/
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = YES
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+CLANG_ASSISTED_PARSING = NO
+CLANG_OPTIONS =
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES =
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = YES
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = NO
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_STYLESHEET =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+RTF_SOURCE_CODE = NO
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_SUBDIR =
+MAN_LINKS = NO
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_PROGRAMLISTING = YES
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+DOCBOOK_PROGRAMLISTING = NO
+GENERATE_AUTOGEN_DEF = NO
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+PLANTUML_JAR_PATH =
+PLANTUML_INCLUDE_PATH =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index f42bed7..2610e42 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -5,6 +5,10 @@
* Copyright 2015 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+/** \file include/libnslayout/nslayout.h
+ * Layout object handling
+ */
+
#ifndef nslayout_nslayout_h_
#define nslayout_nslayout_h_
@@ -21,10 +25,10 @@ typedef void nslayout_replaced;
/** A rectangle */
typedef struct nslayout_rect {
- int x;
- int y;
- int w;
- int h;
+ int x; /**< X position of left of rect in px */
+ int y; /**< Y position of top of rect in px */
+ int w; /**< Width of rect in px */
+ int h; /**< Height of rect in px */
} nslayout_rect;
/** Render list */
@@ -41,7 +45,7 @@ typedef struct nslayout_layout nslayout_layout;
*/
typedef struct nslayout_request {
/** Request type */
- enum type {
+ enum {
NSLAYOUT_GET_RESOURCE,
NSLAYOUT_CREATE_REPLACED,
NSLAYOUT_RENDER,
@@ -105,25 +109,25 @@ nslayout_error nslayout_fini(void);
/**
* LibNSLayout client callback function
*
- * \param req The request details.
- * \param layout The layout we're making a request for.
- * \param pw The client's private data for this layout.
+ * \param[in] layout The layout we're making a request for.
+ * \param[in] pw The client's private data for this layout.
+ * \param[in,out] req The request details.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
typedef nslayout_error (*nslayout_callback)(
- nslayout_request *req,
nslayout_layout *layout,
- void *pw);
+ void *pw,
+ nslayout_request *req);
/**
* Create a Layout object for a given DOM
*
- * \param doc The LibDOM document to build a layout for.
- * \param css_ctx The LibCSS selection context for the document.
- * \param media The LibCSS media to use when selecting for this layout.
- * \param cb The client's private data for this layout.
- * \param pw The client's private data for this layout.
- * \param layout Returns a pointer to the created layout object.
+ * \param[in] doc The LibDOM document to build a layout for.
+ * \param[in] css_ctx The LibCSS selection context for the document.
+ * \param[in] media The LibCSS media to use when selecting.
+ * \param[in] cb The client's private data for this layout.
+ * \param[in] pw The client's private data for this layout.
+ * \param[out] layout Returns a pointer to the created layout object.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_create(
@@ -137,7 +141,7 @@ nslayout_error nslayout_layout_create(
/**
* Destroy a Layout object
*
- * \param layout Returns a pointer to the created layout object.
+ * \param[in] layout Returns a pointer to the created layout object.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_destroy(
@@ -150,10 +154,10 @@ nslayout_error nslayout_layout_destroy(
* data structures for the document, but will not start to position
* things and will not emit render lists.
*
- * \param layout Layout to set viewport for.
- * \param viewport Viewport dimensions and offset.
- * \param scale Rendering scale.
- * \param dpi DPI of render target with viewport.
+ * \param[in] layout Layout to set viewport for.
+ * \param[in] viewport Viewport dimensions and offset.
+ * \param[in] scale Rendering scale.
+ * \param[in] dpi DPI of render target with viewport.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_update_viewport(
@@ -163,23 +167,25 @@ nslayout_error nslayout_update_viewport(
unsigned int dpi);
/**
- * Find the top-most element at a given point, in terms of z-order.
+ * Find the area occupied by element.
*
- * \param layout Layout to locate an element in.
- * \param element Updated to area with position relative to viewport.
+ * \param[in] layout Layout to locate an element in.
+ * \param[in] element Element to get area of.
+ * \param[out] area Returns area with position relative to viewport.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_element_get_location(
nslayout_layout *layout,
+ dom_element *element,
nslayout_rect *area);
/**
* Find the top-most element at a given point, in terms of z-order.
*
- * \param layout Layout to find an element in.
- * \param x Mouse x-coordinate (viewport relative).
- * \param y Mouse y-coordinate (viewport relative).
- * \param element Updated to point at the element we found.
+ * \param[in] layout Layout to find an element in.
+ * \param[in] x Mouse x-coordinate (viewport relative).
+ * \param[in] y Mouse y-coordinate (viewport relative).
+ * \param[out] element Returns the element we found.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_element_at_point(
@@ -191,10 +197,10 @@ nslayout_error nslayout_element_at_point(
/**
* Mark an element (or part of it) as needing redraw.
*
- * \param layout Layout to indicate redraw is required for.
- * \param element Element to mark as needing redraw.
- * \param rel_area Area of element to redraw relative to object's top-left.
- * May be NULL, to redraw whole element.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] element Element to mark as needing redraw.
+ * \param[in] rel_area Area of element to redraw relative to object's top-left.
+ * May be NULL, to redraw whole element.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_dirty_element(
@@ -205,8 +211,8 @@ nslayout_error nslayout_layout_dirty_element(
/**
* Mark an area as needing redraw.
*
- * \param layout Layout to indicate redraw is required for.
- * \param area Area to redraw relative to viewport's top-left.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] area Area to redraw relative to viewport's top-left.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_dirty_area(
diff --git a/src/layout.c b/src/layout.c
index 43570fb..915475b 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -4,6 +4,10 @@
* Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
*/
+/** \file src/layout.c
+ * Layout object handling
+ */
+
#include <assert.h>
#include <stdlib.h>
diff --git a/src/layout.h b/src/layout.h
index 6e8f4c9..9946663 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -4,6 +4,10 @@
* Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
*/
+/** \file src/layout.h
+ * Layout object handling
+ */
+
#ifndef nslayout_layout_h_
#define nslayout_layout_h_
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
index 6dec991..cdaf5e2 100644
--- a/test/basic-layout-tests.c
+++ b/test/basic-layout-tests.c
@@ -17,9 +17,9 @@
int pw;
static nslayout_error nslayout_test_callback(
- nslayout_request *req,
nslayout_layout *layout,
- void *pw)
+ void *pw,
+ nslayout_request *req)
{
UNUSED(req);
UNUSED(layout);
-----------------------------------------------------------------------
Summary of changes:
docs/Doxyfile | 261 ++++++++++++++++++++++++++++++++++++++++
include/libnslayout/nslayout.h | 74 ++++++------
src/layout.c | 4 +
src/layout.h | 4 +
src/request.h | 141 ++++++++++++++++++++++
test/basic-layout-tests.c | 4 +-
6 files changed, 452 insertions(+), 36 deletions(-)
create mode 100644 docs/Doxyfile
create mode 100644 src/request.h
diff --git a/docs/Doxyfile b/docs/Doxyfile
new file mode 100644
index 0000000..56c3433
--- /dev/null
+++ b/docs/Doxyfile
@@ -0,0 +1,261 @@
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = "LibNSLayout"
+PROJECT_NUMBER =
+PROJECT_BRIEF = "The NetSurf Browser Layout Engine"
+PROJECT_LOGO =
+OUTPUT_DIRECTORY = docs/
+CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING =
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = NO
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+INPUT =
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS =
+RECURSIVE = YES
+EXCLUDE = test/
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = YES
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+CLANG_ASSISTED_PARSING = NO
+CLANG_OPTIONS =
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES =
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = YES
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = NO
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_STYLESHEET =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+RTF_SOURCE_CODE = NO
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_SUBDIR =
+MAN_LINKS = NO
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_PROGRAMLISTING = YES
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+DOCBOOK_PROGRAMLISTING = NO
+GENERATE_AUTOGEN_DEF = NO
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+PLANTUML_JAR_PATH =
+PLANTUML_INCLUDE_PATH =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index f42bed7..2610e42 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -5,6 +5,10 @@
* Copyright 2015 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+/** \file include/libnslayout/nslayout.h
+ * Layout object handling
+ */
+
#ifndef nslayout_nslayout_h_
#define nslayout_nslayout_h_
@@ -21,10 +25,10 @@ typedef void nslayout_replaced;
/** A rectangle */
typedef struct nslayout_rect {
- int x;
- int y;
- int w;
- int h;
+ int x; /**< X position of left of rect in px */
+ int y; /**< Y position of top of rect in px */
+ int w; /**< Width of rect in px */
+ int h; /**< Height of rect in px */
} nslayout_rect;
/** Render list */
@@ -41,7 +45,7 @@ typedef struct nslayout_layout nslayout_layout;
*/
typedef struct nslayout_request {
/** Request type */
- enum type {
+ enum {
NSLAYOUT_GET_RESOURCE,
NSLAYOUT_CREATE_REPLACED,
NSLAYOUT_RENDER,
@@ -105,25 +109,25 @@ nslayout_error nslayout_fini(void);
/**
* LibNSLayout client callback function
*
- * \param req The request details.
- * \param layout The layout we're making a request for.
- * \param pw The client's private data for this layout.
+ * \param[in] layout The layout we're making a request for.
+ * \param[in] pw The client's private data for this layout.
+ * \param[in,out] req The request details.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
typedef nslayout_error (*nslayout_callback)(
- nslayout_request *req,
nslayout_layout *layout,
- void *pw);
+ void *pw,
+ nslayout_request *req);
/**
* Create a Layout object for a given DOM
*
- * \param doc The LibDOM document to build a layout for.
- * \param css_ctx The LibCSS selection context for the document.
- * \param media The LibCSS media to use when selecting for this layout.
- * \param cb The client's private data for this layout.
- * \param pw The client's private data for this layout.
- * \param layout Returns a pointer to the created layout object.
+ * \param[in] doc The LibDOM document to build a layout for.
+ * \param[in] css_ctx The LibCSS selection context for the document.
+ * \param[in] media The LibCSS media to use when selecting.
+ * \param[in] cb The client's private data for this layout.
+ * \param[in] pw The client's private data for this layout.
+ * \param[out] layout Returns a pointer to the created layout object.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_create(
@@ -137,7 +141,7 @@ nslayout_error nslayout_layout_create(
/**
* Destroy a Layout object
*
- * \param layout Returns a pointer to the created layout object.
+ * \param[in] layout Returns a pointer to the created layout object.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_destroy(
@@ -150,10 +154,10 @@ nslayout_error nslayout_layout_destroy(
* data structures for the document, but will not start to position
* things and will not emit render lists.
*
- * \param layout Layout to set viewport for.
- * \param viewport Viewport dimensions and offset.
- * \param scale Rendering scale.
- * \param dpi DPI of render target with viewport.
+ * \param[in] layout Layout to set viewport for.
+ * \param[in] viewport Viewport dimensions and offset.
+ * \param[in] scale Rendering scale.
+ * \param[in] dpi DPI of render target with viewport.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_update_viewport(
@@ -163,23 +167,25 @@ nslayout_error nslayout_update_viewport(
unsigned int dpi);
/**
- * Find the top-most element at a given point, in terms of z-order.
+ * Find the area occupied by element.
*
- * \param layout Layout to locate an element in.
- * \param element Updated to area with position relative to viewport.
+ * \param[in] layout Layout to locate an element in.
+ * \param[in] element Element to get area of.
+ * \param[out] area Returns area with position relative to viewport.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_element_get_location(
nslayout_layout *layout,
+ dom_element *element,
nslayout_rect *area);
/**
* Find the top-most element at a given point, in terms of z-order.
*
- * \param layout Layout to find an element in.
- * \param x Mouse x-coordinate (viewport relative).
- * \param y Mouse y-coordinate (viewport relative).
- * \param element Updated to point at the element we found.
+ * \param[in] layout Layout to find an element in.
+ * \param[in] x Mouse x-coordinate (viewport relative).
+ * \param[in] y Mouse y-coordinate (viewport relative).
+ * \param[out] element Returns the element we found.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_element_at_point(
@@ -191,10 +197,10 @@ nslayout_error nslayout_element_at_point(
/**
* Mark an element (or part of it) as needing redraw.
*
- * \param layout Layout to indicate redraw is required for.
- * \param element Element to mark as needing redraw.
- * \param rel_area Area of element to redraw relative to object's top-left.
- * May be NULL, to redraw whole element.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] element Element to mark as needing redraw.
+ * \param[in] rel_area Area of element to redraw relative to object's top-left.
+ * May be NULL, to redraw whole element.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_dirty_element(
@@ -205,8 +211,8 @@ nslayout_error nslayout_layout_dirty_element(
/**
* Mark an area as needing redraw.
*
- * \param layout Layout to indicate redraw is required for.
- * \param area Area to redraw relative to viewport's top-left.
+ * \param[in] layout Layout to indicate redraw is required for.
+ * \param[in] area Area to redraw relative to viewport's top-left.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nslayout_layout_dirty_area(
diff --git a/src/layout.c b/src/layout.c
index 43570fb..915475b 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -4,6 +4,10 @@
* Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
*/
+/** \file src/layout.c
+ * Layout object handling
+ */
+
#include <assert.h>
#include <stdlib.h>
diff --git a/src/layout.h b/src/layout.h
index 6e8f4c9..9946663 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -4,6 +4,10 @@
* Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
*/
+/** \file src/layout.h
+ * Layout object handling
+ */
+
#ifndef nslayout_layout_h_
#define nslayout_layout_h_
diff --git a/src/request.h b/src/request.h
new file mode 100644
index 0000000..c28468e
--- /dev/null
+++ b/src/request.h
@@ -0,0 +1,141 @@
+/*
+ * 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/request.h
+ * Client callback wrappers
+ */
+
+#ifndef nslayout_request_h_
+#define nslayout_request_h_
+
+#include <libnslayout/nslayout.h>
+
+/**
+ * Perform GET_RESOURCE client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] url Absolute URL to request replaced object handle for.
+ * \param[out] replaced Returns the replaced element content handle.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_get_resource(
+ nslayout_layout *layout,
+ const char *url,
+ nslayout_replaced **replaced)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_GET_RESOURCE;
+ req.request.get_resource.url = url;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ *replaced = *req.response.get_resource.replaced;
+ return err;
+}
+
+/**
+ * Perform CREATE_REPLACED client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] element DOM element that needs replacement object.
+ * \param[out] replaced Returns the replaced element content handle.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_create_replaced(
+ nslayout_layout *layout,
+ dom_element *element,
+ nslayout_replaced **replaced)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_CREATE_REPLACED;
+ req.request.create_replaced.element = element;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ *replaced = *req.response.create_replaced.replaced;
+ return err;
+}
+
+/**
+ * Perform RENDER client callback
+ *
+ * \param[in] layout Layout object being rendered.
+ * \param[in] list Render list to render.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_render(
+ nslayout_layout *layout,
+ nslayout_render_list *list)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_RENDER;
+ req.request.render.list = list;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ return err;
+}
+
+/**
+ * Perform SET_EXTENTS client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] width The layout's full width.
+ * \param[in] height The layout's full height.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_set_extents(
+ nslayout_layout *layout,
+ unsigned int width,
+ unsigned int height)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_SET_EXTENTS;
+ req.request.set_extents.width = width;
+ req.request.set_extents.height = height;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ return err;
+}
+
+/**
+ * Perform GET_INTRINSIC_SIZE client callback
+ *
+ * \param[in] layout Layout object that the request concerns.
+ * \param[in] replaced Replaced object to get intrinsic size of.
+ * \param[out] width Returns the replaced object's width.
+ * \param[out] height Returns the replaced object's height.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_get_intrinsic_size(
+ nslayout_layout *layout,
+ nslayout_replaced *replaced,
+ unsigned int *width,
+ unsigned int *height)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_GET_INTRINSIC_SIZE;
+ req.request.get_intrinsic_size.replaced = replaced;
+
+ err = layout->cb(layout, layout->pw, &req);
+
+ *width = *req.response.get_intrinsic_size.width;
+ *height = *req.response.get_intrinsic_size.height;
+ return err;
+}
+
+#endif
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
index 6dec991..cdaf5e2 100644
--- a/test/basic-layout-tests.c
+++ b/test/basic-layout-tests.c
@@ -17,9 +17,9 @@
int pw;
static nslayout_error nslayout_test_callback(
- nslayout_request *req,
nslayout_layout *layout,
- void *pw)
+ void *pw,
+ nslayout_request *req)
{
UNUSED(req);
UNUSED(layout);
--
NetSurf Layout Engine
7 years, 10 months
netsurf: branch master updated. release/3.3-232-g70fd706
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/70fd706e65ba0470ac7d2...
...commit http://git.netsurf-browser.org/netsurf.git/commit/70fd706e65ba0470ac7d289...
...tree http://git.netsurf-browser.org/netsurf.git/tree/70fd706e65ba0470ac7d28964...
The branch, master has been updated
via 70fd706e65ba0470ac7d289646efa6b785c91ccb (commit)
from 5ea99617371386a99fe9ddc4759b310069ae8440 (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=70fd706e65ba0470ac7...
commit 70fd706e65ba0470ac7d289646efa6b785c91ccb
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
NULL-terminate font name in IFF DR2D FONS
diff --git a/amiga/iff_dr2d.c b/amiga/iff_dr2d.c
index 32a49ca..0d4d77e 100644
--- a/amiga/iff_dr2d.c
+++ b/amiga/iff_dr2d.c
@@ -280,8 +280,8 @@ bool ami_svg_to_dr2d(struct IFFHandle *iffh, const char *buffer,
fons = AllocVecTagList(sizeof(struct fons_struct), NULL);
if(!(PushChunk(iffh,0,ID_FONS,IFFSIZE_UNKNOWN)))
{
- WriteChunkBytes(iffh,fons,sizeof(struct fons_struct));
- WriteChunkBytes(iffh,"Topaz",5);
+ WriteChunkBytes(iffh, fons, sizeof(struct fons_struct));
+ WriteChunkBytes(iffh, "Topaz\0", 6);
PopChunk(iffh);
}
FreeVec(fons);
-----------------------------------------------------------------------
Summary of changes:
amiga/iff_dr2d.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/amiga/iff_dr2d.c b/amiga/iff_dr2d.c
index 32a49ca..0d4d77e 100644
--- a/amiga/iff_dr2d.c
+++ b/amiga/iff_dr2d.c
@@ -280,8 +280,8 @@ bool ami_svg_to_dr2d(struct IFFHandle *iffh, const char *buffer,
fons = AllocVecTagList(sizeof(struct fons_struct), NULL);
if(!(PushChunk(iffh,0,ID_FONS,IFFSIZE_UNKNOWN)))
{
- WriteChunkBytes(iffh,fons,sizeof(struct fons_struct));
- WriteChunkBytes(iffh,"Topaz",5);
+ WriteChunkBytes(iffh, fons, sizeof(struct fons_struct));
+ WriteChunkBytes(iffh, "Topaz\0", 6);
PopChunk(iffh);
}
FreeVec(fons);
--
NetSurf Browser
7 years, 10 months
netsurf: branch chris/display-idna updated. release/3.3-239-g3de0e15
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/3de0e15b0fe18143fb855...
...commit http://git.netsurf-browser.org/netsurf.git/commit/3de0e15b0fe18143fb85567...
...tree http://git.netsurf-browser.org/netsurf.git/tree/3de0e15b0fe18143fb8556793...
The branch, chris/display-idna has been updated
via 3de0e15b0fe18143fb8556793e4739819b10fce3 (commit)
via bd4841e90dcc5530bf4470753d81f6b6e10fc44a (commit)
via 5ea99617371386a99fe9ddc4759b310069ae8440 (commit)
via 80e9a23fc10b0749e3daede512557e7202e438bb (commit)
via daef57aaeec8c8271860983e158609be275bdc29 (commit)
via a470aacdb2e01b52d59ebe9575dda9e46c00d593 (commit)
via abc7a71117e4ae03f9b7146ce3f299a4b931b1ef (commit)
from 5bec5bf72a5087df679a6fc89ea72a84c0ba9a07 (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=3de0e15b0fe18143fb8...
commit 3de0e15b0fe18143fb8556793e4739819b10fce3
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Add URL fragment
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 6675ee1..78647b4 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -1731,7 +1731,7 @@ char *nsurl_access_utf8(const nsurl *url)
return strdup(url->string);
}
- if (nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY,
+ if (nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY | NSURL_FRAGMENT,
&path, &path_len) != NSERROR_OK) {
return strdup(url->string);
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=bd4841e90dcc5530bf4...
commit bd4841e90dcc5530bf4470753d81f6b6e10fc44a
Merge: 5bec5bf 5ea9961
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Merge branch 'master' of git://git.netsurf-browser.org/netsurf into chris/display-idna
-----------------------------------------------------------------------
Summary of changes:
riscos/gui/url_bar.c | 31 +++++++++++++++++++++++++++----
riscos/url_complete.c | 9 +++++----
utils/nsurl.c | 2 +-
3 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 5eccd60..6003fe3 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -83,6 +83,7 @@ struct url_bar {
wimp_i text_icon;
char *text_buffer;
size_t text_size;
+ char *text_buffer_utf8;
wimp_i suggest_icon;
int suggest_x, suggest_y;
@@ -177,7 +178,12 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->text_size = RO_GUI_MAX_URL_SIZE;
url_bar->text_buffer = malloc(url_bar->text_size);
- strncpy(url_bar->text_buffer, "", url_bar->text_size);
+ if (url_bar->text_buffer == NULL) {
+ free(url_bar);
+ return NULL;
+ }
+ url_bar->text_buffer[0] = 0;
+ url_bar->text_buffer_utf8 = NULL;
url_bar->hidden = false;
@@ -508,6 +514,12 @@ void ro_gui_url_bar_destroy(struct url_bar *url_bar)
if (url_bar == NULL)
return;
+ if (url_bar->text_buffer_utf8 != NULL)
+ free(url_bar->text_buffer_utf8);
+
+ if (url_bar->text_buffer != NULL)
+ free(url_bar->text_buffer);
+
free(url_bar);
}
@@ -973,8 +985,7 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
*/
if (strlen(local_url) >= url_bar->text_size) {
- strncpy(url_bar->text_buffer, "", url_bar->text_size - 1);
- url_bar->text_buffer[url_bar->text_size - 1] = '\0';
+ url_bar->text_buffer[0] = '\0';
warn_user("LongURL", NULL);
LOG("Long URL (%d chars): %s", strlen(url), url);
} else {
@@ -1070,9 +1081,21 @@ static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set)
const char *ro_gui_url_bar_get_url(struct url_bar *url_bar)
{
- if (url_bar == NULL)
+ if ((url_bar == NULL) || (url_bar->text_buffer == NULL))
return NULL;
+ if (url_bar->text_buffer_utf8 != NULL) {
+ free(url_bar->text_buffer_utf8);
+ url_bar->text_buffer_utf8 = NULL;
+ }
+
+ if (url_bar->text_buffer[0] == '\0')
+ return (const char *) url_bar->text_buffer;
+
+ if (utf8_from_local_encoding(url_bar->text_buffer, 0, &url_bar->text_buffer_utf8) == NSERROR_OK) {
+ return (const char *) url_bar->text_buffer_utf8;
+ }
+
return (const char *) url_bar->text_buffer;
}
diff --git a/riscos/url_complete.c b/riscos/url_complete.c
index 3d189a0..ff91b1c 100644
--- a/riscos/url_complete.c
+++ b/riscos/url_complete.c
@@ -85,10 +85,11 @@ void ro_gui_url_complete_start(struct toolbar *toolbar)
ro_gui_url_complete_close();
url = ro_toolbar_get_url(toolbar);
-
- url_complete_matched_string = strdup(url);
- if (url_complete_matched_string)
- url_complete_parent = parent;
+ if (url != NULL) {
+ url_complete_matched_string = strdup(url);
+ if (url_complete_matched_string)
+ url_complete_parent = parent;
+ }
}
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 6675ee1..78647b4 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -1731,7 +1731,7 @@ char *nsurl_access_utf8(const nsurl *url)
return strdup(url->string);
}
- if (nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY,
+ if (nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY | NSURL_FRAGMENT,
&path, &path_len) != NSERROR_OK) {
return strdup(url->string);
}
--
NetSurf Browser
7 years, 10 months
netsurf: branch dsilvers/dukky updated. release/3.3-236-gd4222fa
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/d4222fab05f9092266175...
...commit http://git.netsurf-browser.org/netsurf.git/commit/d4222fab05f909226617587...
...tree http://git.netsurf-browser.org/netsurf.git/tree/d4222fab05f909226617587f8...
The branch, dsilvers/dukky has been updated
via d4222fab05f909226617587f85223e7551b5323e (commit)
from bfd72abdc7ec0d63e920d7650c358a5a8080af11 (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=d4222fab05f90922661...
commit d4222fab05f909226617587f85223e7551b5323e
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
REWORK: ARGFHiufdsfds
diff --git a/javascript/Makefile b/javascript/Makefile
index 7c7006d..3d3e273 100644
--- a/javascript/Makefile
+++ b/javascript/Makefile
@@ -63,7 +63,8 @@ ifeq ($(NETSURF_USE_DUKTAPE),YES)
S_DUKKY := event_target.c window.c node.c document.c \
element.c html_element.c html_unknown_element.c \
- character_data.c text.c comment.c html_collection.c node_list.c
+ character_data.c text.c comment.c html_collection.c node_list.c \
+ html_br_element.c
S_JAVASCRIPT += dukky.c duktape.c content.c fetcher.c $(addprefix duktape/,$(S_DUKKY))
diff --git a/javascript/dukky.c b/javascript/dukky.c
index e5836be..0e9e39a 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -22,11 +22,13 @@
*/
#include "content/content.h"
+
#include "utils/nsoption.h"
+#include "utils/log.h"
+#include "utils/corestrings.h"
#include "javascript/js.h"
#include "javascript/content.h"
-#include "utils/log.h"
#include "duktape.h"
#include "dukky.h"
@@ -46,9 +48,9 @@ static duk_ret_t dukky_populate_object(duk_context *ctx)
duk_get_prop(ctx, -2);
/* ... obj args prototab {proto/undefined} */
if (duk_is_undefined(ctx, -1)) {
- LOG("RuhRoh, couldn't find a prototype, getting htmlelement");
+ LOG("RuhRoh, couldn't find a prototype, HTMLUnknownElement it is");
duk_pop(ctx);
- duk_push_string(ctx, PROTO_NAME(html_unknown_element));
+ duk_push_string(ctx, PROTO_NAME(HTMLUNKNOWNELEMENT));
duk_get_prop(ctx, -2);
}
/* ... obj args prototab proto */
@@ -185,39 +187,57 @@ dukky_push_node_klass(duk_context *ctx, struct dom_node *node)
err = dom_node_get_node_type(node, &nodetype);
if (err != DOM_NO_ERR) {
/* Oh bum, just node then */
- duk_push_string(ctx, PROTO_NAME(node));
+ duk_push_string(ctx, PROTO_NAME(NODE));
return;
}
switch(nodetype) {
case DOM_ELEMENT_NODE: {
- dom_string *namespace;
+ dom_string *namespace, *tag;
err = dom_node_get_namespace(node, &namespace);
if (err != DOM_NO_ERR) {
/* Feck it, element */
- duk_push_string(ctx, PROTO_NAME(element));
+ LOG("dom_node_get_namespace() failed");
+ duk_push_string(ctx, PROTO_NAME(ELEMENT));
break;
}
if (namespace == NULL) {
/* No namespace, -> element */
- duk_push_string(ctx, PROTO_NAME(element));
+ LOG("no namespace");
+ duk_push_string(ctx, PROTO_NAME(ELEMENT));
break;
}
- /* TODO: Work out how to decide between Element and HTML */
- duk_push_string(ctx, PROTO_NAME(html_unknown_element));
-
+ if (dom_string_isequal(namespace, corestring_dom_html_namespace) == false) {
+ /* definitely not an HTML element of some kind */
+ duk_push_string(ctx, PROTO_NAME(ELEMENT));
+ dom_string_unref(namespace);
+ break;
+ }
dom_string_unref(namespace);
+
+ err = dom_node_get_node_name(node, &tag);
+ if (err != DOM_NO_ERR) {
+ duk_push_string(ctx, PROTO_NAME(HTMLUNKNOWNELEMENT));
+ break;
+ }
+
+ duk_push_string(ctx, PROTO_NAME(HTML));
+ duk_push_lstring(ctx, dom_string_data(tag), dom_string_length(tag));
+ dom_string_unref(tag);
+ duk_push_string(ctx, "ELEMENT");
+ duk_concat(ctx, 3);
+
break;
}
case DOM_TEXT_NODE:
- duk_push_string(ctx, PROTO_NAME(text));
+ duk_push_string(ctx, PROTO_NAME(TEXT));
break;
case DOM_COMMENT_NODE:
- duk_push_string(ctx, PROTO_NAME(comment));
+ duk_push_string(ctx, PROTO_NAME(COMMENT));
break;
case DOM_DOCUMENT_NODE:
- duk_push_string(ctx, PROTO_NAME(document));
+ duk_push_string(ctx, PROTO_NAME(DOCUMENT));
break;
case DOM_ATTRIBUTE_NODE:
case DOM_PROCESSING_INSTRUCTION_NODE:
@@ -229,7 +249,7 @@ dukky_push_node_klass(duk_context *ctx, struct dom_node *node)
case DOM_CDATA_SECTION_NODE:
default:
/* Oh bum, just node then */
- duk_push_string(ctx, PROTO_NAME(node));
+ duk_push_string(ctx, PROTO_NAME(NODE));
}
}
@@ -315,8 +335,8 @@ void js_finalise(void)
/* NADA for now */
}
-#define DUKKY_NEW_PROTOTYPE(klass, klass_name) \
- dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(klass), klass_name)
+#define DUKKY_NEW_PROTOTYPE(klass, uklass, klass_name) \
+ dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(uklass), klass_name)
jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
{
@@ -332,20 +352,21 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
duk_put_prop_string(ctx, -2, "protos");
duk_put_global_string(ctx, PROTO_MAGIC);
/* Create prototypes here? */
- DUKKY_NEW_PROTOTYPE(event_target, "EventTarget");
- DUKKY_NEW_PROTOTYPE(node, "Node");
- DUKKY_NEW_PROTOTYPE(character_data, "CharacterData");
- DUKKY_NEW_PROTOTYPE(text, "Text");
- DUKKY_NEW_PROTOTYPE(comment, "Comment");
- DUKKY_NEW_PROTOTYPE(document, "Document");
- DUKKY_NEW_PROTOTYPE(element, "Element");
- DUKKY_NEW_PROTOTYPE(html_element, "HTMLElement");
- DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
- DUKKY_NEW_PROTOTYPE(html_collection, "HTMLCollection");
- DUKKY_NEW_PROTOTYPE(node_list, "NodeList");
+ DUKKY_NEW_PROTOTYPE(event_target, EVENTTARGET, "EventTarget");
+ DUKKY_NEW_PROTOTYPE(node, NODE, "Node");
+ DUKKY_NEW_PROTOTYPE(character_data, CHARACTERDATA, "CharacterData");
+ DUKKY_NEW_PROTOTYPE(text, TEXT, "Text");
+ DUKKY_NEW_PROTOTYPE(comment, COMMENT, "Comment");
+ DUKKY_NEW_PROTOTYPE(document, DOCUMENT, "Document");
+ DUKKY_NEW_PROTOTYPE(element, ELEMENT, "Element");
+ DUKKY_NEW_PROTOTYPE(html_element, HTMLELEMENT, "HTMLElement");
+ DUKKY_NEW_PROTOTYPE(html_unknown_element, HTMLUNKNOWNELEMENT, "HTMLUnknownElement");
+ DUKKY_NEW_PROTOTYPE(html_br_element, HTMLBRELEMENT, "HTMLBRElement");
+ DUKKY_NEW_PROTOTYPE(html_collection, HTMLCOLLECTION, "HTMLCollection");
+ DUKKY_NEW_PROTOTYPE(node_list, NODELIST, "NodeList");
/* Finally window's prototype */
- DUKKY_NEW_PROTOTYPE(window, "Window");
+ DUKKY_NEW_PROTOTYPE(window, WINDOW, "Window");
return ret;
}
@@ -370,7 +391,7 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
/* win_priv is a browser_window, doc_priv is an html content struct */
duk_push_pointer(CTX, win_priv);
duk_push_pointer(CTX, doc_priv);
- dukky_create_object(CTX, PROTO_NAME(window), 2);
+ dukky_create_object(CTX, PROTO_NAME(WINDOW), 2);
duk_push_global_object(CTX);
duk_put_prop_string(CTX, -2, PROTO_MAGIC);
duk_set_global_object(CTX);
diff --git a/javascript/duktape/character_data.c b/javascript/duktape/character_data.c
index a71de47..608c655 100644
--- a/javascript/duktape/character_data.c
+++ b/javascript/duktape/character_data.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(character_data, __proto)
/* Populate character_data's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, character_data);
diff --git a/javascript/duktape/comment.c b/javascript/duktape/comment.c
index 877793a..8fbf79f 100644
--- a/javascript/duktape/comment.c
+++ b/javascript/duktape/comment.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(comment, __proto)
/* Populate comment's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(character_data);
+ DUKKY_GET_PROTOTYPE(CHARACTERDATA);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, comment);
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index 76fec75..f09629a 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -223,7 +223,7 @@ static DUKKY_FUNC(document, getElementsByTagName)
if (nodes == NULL) return 0; /* coerced to undefined */
duk_push_pointer(ctx, nodes);
- dukky_create_object(ctx, PROTO_NAME(node_list), 1);
+ dukky_create_object(ctx, PROTO_NAME(NODELIST), 1);
dom_nodelist_unref(nodes);
return 1;
}
@@ -239,7 +239,7 @@ DUKKY_FUNC(document, __proto)
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
DUKKY_POPULATE_READONLY_PROPERTY(document, head);
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, document);
diff --git a/javascript/duktape/element.c b/javascript/duktape/element.c
index 23c7627..b86e940 100644
--- a/javascript/duktape/element.c
+++ b/javascript/duktape/element.c
@@ -211,7 +211,7 @@ DUKKY_FUNC(element, __proto)
DUKKY_POPULATE_READONLY_PROPERTY(element, previousElementSibling);
DUKKY_POPULATE_READONLY_PROPERTY(element, childElementCount);
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, element);
diff --git a/javascript/duktape/html_element.c b/javascript/duktape/html_element.c
index c129866..1b22f67 100644
--- a/javascript/duktape/html_element.c
+++ b/javascript/duktape/html_element.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(html_element, __proto)
/* Populate html_element's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(element);
+ DUKKY_GET_PROTOTYPE(ELEMENT);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, html_element);
diff --git a/javascript/duktape/html_unknown_element.c b/javascript/duktape/html_unknown_element.c
index e728b48..977450a 100644
--- a/javascript/duktape/html_unknown_element.c
+++ b/javascript/duktape/html_unknown_element.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(html_unknown_element, __proto)
/* Populate html_unknown_element's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(html_element);
+ DUKKY_GET_PROTOTYPE(HTMLELEMENT);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, html_unknown_element);
diff --git a/javascript/duktape/node.c b/javascript/duktape/node.c
index 2d7b1cf..c81c1be 100644
--- a/javascript/duktape/node.c
+++ b/javascript/duktape/node.c
@@ -42,7 +42,7 @@ static DUKKY_FUNC(node, appendChild)
{
DUKKY_GET_METHOD_PRIVATE(node);
- if (!dukky_instanceof(ctx, PROTO_NAME(node))) return 0;
+ if (!dukky_instanceof(ctx, PROTO_NAME(NODE))) return 0;
DUKKY_SAFE_GET_ANOTHER(other,node,0);
@@ -82,7 +82,7 @@ DUKKY_FUNC(node, __proto)
DUKKY_ADD_METHOD(node, appendChild, 1);
DUKKY_POPULATE_READONLY_PROPERTY(node, textContent);
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(event_target);
+ DUKKY_GET_PROTOTYPE(EVENTTARGET);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, node);
diff --git a/javascript/duktape/node_list.c b/javascript/duktape/node_list.c
index c127c24..5ee9ec6 100644
--- a/javascript/duktape/node_list.c
+++ b/javascript/duktape/node_list.c
@@ -40,7 +40,7 @@ static DUKKY_GETTER(node_list, length)
{
DUKKY_GET_METHOD_PRIVATE(node_list);
dom_exception err;
- unsigned long len;
+ uint32_t len;
err = dom_nodelist_get_length(priv->nodes, &len);
@@ -57,8 +57,6 @@ static DUKKY_FUNC(node_list, item)
dom_exception err;
dom_node *node;
- LOG("Looking up %u in %p", i, priv->nodes);
-
err = dom_nodelist_item(priv->nodes, i, &node);
if (err != DOM_NO_ERR) return 0; /* coerced to undefied */
diff --git a/javascript/duktape/private.h b/javascript/duktape/private.h
index 42c2079..da97031 100644
--- a/javascript/duktape/private.h
+++ b/javascript/duktape/private.h
@@ -12,6 +12,7 @@ struct dom_node_text;
struct dom_node_list;
struct dom_node_comment;
struct dom_html_collection;
+struct dom_html_br_element;
typedef struct {
} event_target_private_t;
@@ -52,6 +53,10 @@ typedef struct {
} html_unknown_element_private_t;
typedef struct {
+ html_element_private_t parent;
+} html_br_element_private_t;
+
+typedef struct {
node_private_t parent;
} document_private_t;
diff --git a/javascript/duktape/prototypes.h b/javascript/duktape/prototypes.h
index 1f25424..746f85c 100644
--- a/javascript/duktape/prototypes.h
+++ b/javascript/duktape/prototypes.h
@@ -11,6 +11,7 @@ DUKKY_DECLARE_INTERFACE(document, struct dom_document *);
DUKKY_DECLARE_INTERFACE(element, struct dom_element *);
DUKKY_DECLARE_INTERFACE(html_element, struct dom_html_element *);
DUKKY_DECLARE_INTERFACE(html_unknown_element, struct dom_html_element *);
+DUKKY_DECLARE_INTERFACE(html_br_element, struct dom_html_br_element *);
DUKKY_DECLARE_INTERFACE(html_collection, struct dom_html_collection *);
DUKKY_DECLARE_INTERFACE(node_list, struct dom_nodelist *);
diff --git a/javascript/duktape/text.c b/javascript/duktape/text.c
index 7669bae..2645774 100644
--- a/javascript/duktape/text.c
+++ b/javascript/duktape/text.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(text, __proto)
/* Populate text's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(character_data);
+ DUKKY_GET_PROTOTYPE(CHARACTERDATA);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, text);
diff --git a/javascript/duktape/window.c b/javascript/duktape/window.c
index 3bad2ab..fd070aa 100644
--- a/javascript/duktape/window.c
+++ b/javascript/duktape/window.c
@@ -78,10 +78,10 @@ DUKKY_FUNC(window, __proto)
/* Populate window's prototypical functionality */
DUKKY_POPULATE_FULL_PROPERTY(window, document);
/* Exposed prototypes */
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_put_prop_string(ctx, 0, "Node");
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(event_target);
+ DUKKY_GET_PROTOTYPE(EVENTTARGET);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, window);
-----------------------------------------------------------------------
Summary of changes:
javascript/Makefile | 3 +-
javascript/dukky.c | 79 ++++++++++++++++++-----------
javascript/duktape/character_data.c | 2 +-
javascript/duktape/comment.c | 2 +-
javascript/duktape/document.c | 4 +-
javascript/duktape/element.c | 2 +-
javascript/duktape/html_element.c | 2 +-
javascript/duktape/html_unknown_element.c | 2 +-
javascript/duktape/node.c | 4 +-
javascript/duktape/node_list.c | 4 +-
javascript/duktape/private.h | 5 ++
javascript/duktape/prototypes.h | 1 +
javascript/duktape/text.c | 2 +-
javascript/duktape/window.c | 4 +-
14 files changed, 71 insertions(+), 45 deletions(-)
diff --git a/javascript/Makefile b/javascript/Makefile
index 7c7006d..3d3e273 100644
--- a/javascript/Makefile
+++ b/javascript/Makefile
@@ -63,7 +63,8 @@ ifeq ($(NETSURF_USE_DUKTAPE),YES)
S_DUKKY := event_target.c window.c node.c document.c \
element.c html_element.c html_unknown_element.c \
- character_data.c text.c comment.c html_collection.c node_list.c
+ character_data.c text.c comment.c html_collection.c node_list.c \
+ html_br_element.c
S_JAVASCRIPT += dukky.c duktape.c content.c fetcher.c $(addprefix duktape/,$(S_DUKKY))
diff --git a/javascript/dukky.c b/javascript/dukky.c
index e5836be..0e9e39a 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -22,11 +22,13 @@
*/
#include "content/content.h"
+
#include "utils/nsoption.h"
+#include "utils/log.h"
+#include "utils/corestrings.h"
#include "javascript/js.h"
#include "javascript/content.h"
-#include "utils/log.h"
#include "duktape.h"
#include "dukky.h"
@@ -46,9 +48,9 @@ static duk_ret_t dukky_populate_object(duk_context *ctx)
duk_get_prop(ctx, -2);
/* ... obj args prototab {proto/undefined} */
if (duk_is_undefined(ctx, -1)) {
- LOG("RuhRoh, couldn't find a prototype, getting htmlelement");
+ LOG("RuhRoh, couldn't find a prototype, HTMLUnknownElement it is");
duk_pop(ctx);
- duk_push_string(ctx, PROTO_NAME(html_unknown_element));
+ duk_push_string(ctx, PROTO_NAME(HTMLUNKNOWNELEMENT));
duk_get_prop(ctx, -2);
}
/* ... obj args prototab proto */
@@ -185,39 +187,57 @@ dukky_push_node_klass(duk_context *ctx, struct dom_node *node)
err = dom_node_get_node_type(node, &nodetype);
if (err != DOM_NO_ERR) {
/* Oh bum, just node then */
- duk_push_string(ctx, PROTO_NAME(node));
+ duk_push_string(ctx, PROTO_NAME(NODE));
return;
}
switch(nodetype) {
case DOM_ELEMENT_NODE: {
- dom_string *namespace;
+ dom_string *namespace, *tag;
err = dom_node_get_namespace(node, &namespace);
if (err != DOM_NO_ERR) {
/* Feck it, element */
- duk_push_string(ctx, PROTO_NAME(element));
+ LOG("dom_node_get_namespace() failed");
+ duk_push_string(ctx, PROTO_NAME(ELEMENT));
break;
}
if (namespace == NULL) {
/* No namespace, -> element */
- duk_push_string(ctx, PROTO_NAME(element));
+ LOG("no namespace");
+ duk_push_string(ctx, PROTO_NAME(ELEMENT));
break;
}
- /* TODO: Work out how to decide between Element and HTML */
- duk_push_string(ctx, PROTO_NAME(html_unknown_element));
-
+ if (dom_string_isequal(namespace, corestring_dom_html_namespace) == false) {
+ /* definitely not an HTML element of some kind */
+ duk_push_string(ctx, PROTO_NAME(ELEMENT));
+ dom_string_unref(namespace);
+ break;
+ }
dom_string_unref(namespace);
+
+ err = dom_node_get_node_name(node, &tag);
+ if (err != DOM_NO_ERR) {
+ duk_push_string(ctx, PROTO_NAME(HTMLUNKNOWNELEMENT));
+ break;
+ }
+
+ duk_push_string(ctx, PROTO_NAME(HTML));
+ duk_push_lstring(ctx, dom_string_data(tag), dom_string_length(tag));
+ dom_string_unref(tag);
+ duk_push_string(ctx, "ELEMENT");
+ duk_concat(ctx, 3);
+
break;
}
case DOM_TEXT_NODE:
- duk_push_string(ctx, PROTO_NAME(text));
+ duk_push_string(ctx, PROTO_NAME(TEXT));
break;
case DOM_COMMENT_NODE:
- duk_push_string(ctx, PROTO_NAME(comment));
+ duk_push_string(ctx, PROTO_NAME(COMMENT));
break;
case DOM_DOCUMENT_NODE:
- duk_push_string(ctx, PROTO_NAME(document));
+ duk_push_string(ctx, PROTO_NAME(DOCUMENT));
break;
case DOM_ATTRIBUTE_NODE:
case DOM_PROCESSING_INSTRUCTION_NODE:
@@ -229,7 +249,7 @@ dukky_push_node_klass(duk_context *ctx, struct dom_node *node)
case DOM_CDATA_SECTION_NODE:
default:
/* Oh bum, just node then */
- duk_push_string(ctx, PROTO_NAME(node));
+ duk_push_string(ctx, PROTO_NAME(NODE));
}
}
@@ -315,8 +335,8 @@ void js_finalise(void)
/* NADA for now */
}
-#define DUKKY_NEW_PROTOTYPE(klass, klass_name) \
- dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(klass), klass_name)
+#define DUKKY_NEW_PROTOTYPE(klass, uklass, klass_name) \
+ dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(uklass), klass_name)
jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
{
@@ -332,20 +352,21 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
duk_put_prop_string(ctx, -2, "protos");
duk_put_global_string(ctx, PROTO_MAGIC);
/* Create prototypes here? */
- DUKKY_NEW_PROTOTYPE(event_target, "EventTarget");
- DUKKY_NEW_PROTOTYPE(node, "Node");
- DUKKY_NEW_PROTOTYPE(character_data, "CharacterData");
- DUKKY_NEW_PROTOTYPE(text, "Text");
- DUKKY_NEW_PROTOTYPE(comment, "Comment");
- DUKKY_NEW_PROTOTYPE(document, "Document");
- DUKKY_NEW_PROTOTYPE(element, "Element");
- DUKKY_NEW_PROTOTYPE(html_element, "HTMLElement");
- DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
- DUKKY_NEW_PROTOTYPE(html_collection, "HTMLCollection");
- DUKKY_NEW_PROTOTYPE(node_list, "NodeList");
+ DUKKY_NEW_PROTOTYPE(event_target, EVENTTARGET, "EventTarget");
+ DUKKY_NEW_PROTOTYPE(node, NODE, "Node");
+ DUKKY_NEW_PROTOTYPE(character_data, CHARACTERDATA, "CharacterData");
+ DUKKY_NEW_PROTOTYPE(text, TEXT, "Text");
+ DUKKY_NEW_PROTOTYPE(comment, COMMENT, "Comment");
+ DUKKY_NEW_PROTOTYPE(document, DOCUMENT, "Document");
+ DUKKY_NEW_PROTOTYPE(element, ELEMENT, "Element");
+ DUKKY_NEW_PROTOTYPE(html_element, HTMLELEMENT, "HTMLElement");
+ DUKKY_NEW_PROTOTYPE(html_unknown_element, HTMLUNKNOWNELEMENT, "HTMLUnknownElement");
+ DUKKY_NEW_PROTOTYPE(html_br_element, HTMLBRELEMENT, "HTMLBRElement");
+ DUKKY_NEW_PROTOTYPE(html_collection, HTMLCOLLECTION, "HTMLCollection");
+ DUKKY_NEW_PROTOTYPE(node_list, NODELIST, "NodeList");
/* Finally window's prototype */
- DUKKY_NEW_PROTOTYPE(window, "Window");
+ DUKKY_NEW_PROTOTYPE(window, WINDOW, "Window");
return ret;
}
@@ -370,7 +391,7 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
/* win_priv is a browser_window, doc_priv is an html content struct */
duk_push_pointer(CTX, win_priv);
duk_push_pointer(CTX, doc_priv);
- dukky_create_object(CTX, PROTO_NAME(window), 2);
+ dukky_create_object(CTX, PROTO_NAME(WINDOW), 2);
duk_push_global_object(CTX);
duk_put_prop_string(CTX, -2, PROTO_MAGIC);
duk_set_global_object(CTX);
diff --git a/javascript/duktape/character_data.c b/javascript/duktape/character_data.c
index a71de47..608c655 100644
--- a/javascript/duktape/character_data.c
+++ b/javascript/duktape/character_data.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(character_data, __proto)
/* Populate character_data's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, character_data);
diff --git a/javascript/duktape/comment.c b/javascript/duktape/comment.c
index 877793a..8fbf79f 100644
--- a/javascript/duktape/comment.c
+++ b/javascript/duktape/comment.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(comment, __proto)
/* Populate comment's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(character_data);
+ DUKKY_GET_PROTOTYPE(CHARACTERDATA);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, comment);
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index 76fec75..f09629a 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -223,7 +223,7 @@ static DUKKY_FUNC(document, getElementsByTagName)
if (nodes == NULL) return 0; /* coerced to undefined */
duk_push_pointer(ctx, nodes);
- dukky_create_object(ctx, PROTO_NAME(node_list), 1);
+ dukky_create_object(ctx, PROTO_NAME(NODELIST), 1);
dom_nodelist_unref(nodes);
return 1;
}
@@ -239,7 +239,7 @@ DUKKY_FUNC(document, __proto)
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
DUKKY_POPULATE_READONLY_PROPERTY(document, head);
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, document);
diff --git a/javascript/duktape/element.c b/javascript/duktape/element.c
index 23c7627..b86e940 100644
--- a/javascript/duktape/element.c
+++ b/javascript/duktape/element.c
@@ -211,7 +211,7 @@ DUKKY_FUNC(element, __proto)
DUKKY_POPULATE_READONLY_PROPERTY(element, previousElementSibling);
DUKKY_POPULATE_READONLY_PROPERTY(element, childElementCount);
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, element);
diff --git a/javascript/duktape/html_element.c b/javascript/duktape/html_element.c
index c129866..1b22f67 100644
--- a/javascript/duktape/html_element.c
+++ b/javascript/duktape/html_element.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(html_element, __proto)
/* Populate html_element's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(element);
+ DUKKY_GET_PROTOTYPE(ELEMENT);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, html_element);
diff --git a/javascript/duktape/html_unknown_element.c b/javascript/duktape/html_unknown_element.c
index e728b48..977450a 100644
--- a/javascript/duktape/html_unknown_element.c
+++ b/javascript/duktape/html_unknown_element.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(html_unknown_element, __proto)
/* Populate html_unknown_element's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(html_element);
+ DUKKY_GET_PROTOTYPE(HTMLELEMENT);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, html_unknown_element);
diff --git a/javascript/duktape/node.c b/javascript/duktape/node.c
index 2d7b1cf..c81c1be 100644
--- a/javascript/duktape/node.c
+++ b/javascript/duktape/node.c
@@ -42,7 +42,7 @@ static DUKKY_FUNC(node, appendChild)
{
DUKKY_GET_METHOD_PRIVATE(node);
- if (!dukky_instanceof(ctx, PROTO_NAME(node))) return 0;
+ if (!dukky_instanceof(ctx, PROTO_NAME(NODE))) return 0;
DUKKY_SAFE_GET_ANOTHER(other,node,0);
@@ -82,7 +82,7 @@ DUKKY_FUNC(node, __proto)
DUKKY_ADD_METHOD(node, appendChild, 1);
DUKKY_POPULATE_READONLY_PROPERTY(node, textContent);
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(event_target);
+ DUKKY_GET_PROTOTYPE(EVENTTARGET);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, node);
diff --git a/javascript/duktape/node_list.c b/javascript/duktape/node_list.c
index c127c24..5ee9ec6 100644
--- a/javascript/duktape/node_list.c
+++ b/javascript/duktape/node_list.c
@@ -40,7 +40,7 @@ static DUKKY_GETTER(node_list, length)
{
DUKKY_GET_METHOD_PRIVATE(node_list);
dom_exception err;
- unsigned long len;
+ uint32_t len;
err = dom_nodelist_get_length(priv->nodes, &len);
@@ -57,8 +57,6 @@ static DUKKY_FUNC(node_list, item)
dom_exception err;
dom_node *node;
- LOG("Looking up %u in %p", i, priv->nodes);
-
err = dom_nodelist_item(priv->nodes, i, &node);
if (err != DOM_NO_ERR) return 0; /* coerced to undefied */
diff --git a/javascript/duktape/private.h b/javascript/duktape/private.h
index 42c2079..da97031 100644
--- a/javascript/duktape/private.h
+++ b/javascript/duktape/private.h
@@ -12,6 +12,7 @@ struct dom_node_text;
struct dom_node_list;
struct dom_node_comment;
struct dom_html_collection;
+struct dom_html_br_element;
typedef struct {
} event_target_private_t;
@@ -52,6 +53,10 @@ typedef struct {
} html_unknown_element_private_t;
typedef struct {
+ html_element_private_t parent;
+} html_br_element_private_t;
+
+typedef struct {
node_private_t parent;
} document_private_t;
diff --git a/javascript/duktape/prototypes.h b/javascript/duktape/prototypes.h
index 1f25424..746f85c 100644
--- a/javascript/duktape/prototypes.h
+++ b/javascript/duktape/prototypes.h
@@ -11,6 +11,7 @@ DUKKY_DECLARE_INTERFACE(document, struct dom_document *);
DUKKY_DECLARE_INTERFACE(element, struct dom_element *);
DUKKY_DECLARE_INTERFACE(html_element, struct dom_html_element *);
DUKKY_DECLARE_INTERFACE(html_unknown_element, struct dom_html_element *);
+DUKKY_DECLARE_INTERFACE(html_br_element, struct dom_html_br_element *);
DUKKY_DECLARE_INTERFACE(html_collection, struct dom_html_collection *);
DUKKY_DECLARE_INTERFACE(node_list, struct dom_nodelist *);
diff --git a/javascript/duktape/text.c b/javascript/duktape/text.c
index 7669bae..2645774 100644
--- a/javascript/duktape/text.c
+++ b/javascript/duktape/text.c
@@ -41,7 +41,7 @@ DUKKY_FUNC(text, __proto)
/* Populate text's prototypical functionality */
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(character_data);
+ DUKKY_GET_PROTOTYPE(CHARACTERDATA);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, text);
diff --git a/javascript/duktape/window.c b/javascript/duktape/window.c
index 3bad2ab..fd070aa 100644
--- a/javascript/duktape/window.c
+++ b/javascript/duktape/window.c
@@ -78,10 +78,10 @@ DUKKY_FUNC(window, __proto)
/* Populate window's prototypical functionality */
DUKKY_POPULATE_FULL_PROPERTY(window, document);
/* Exposed prototypes */
- DUKKY_GET_PROTOTYPE(node);
+ DUKKY_GET_PROTOTYPE(NODE);
duk_put_prop_string(ctx, 0, "Node");
/* Set this prototype's prototype (left-parent)*/
- DUKKY_GET_PROTOTYPE(event_target);
+ DUKKY_GET_PROTOTYPE(EVENTTARGET);
duk_set_prototype(ctx, 0);
/* And the initialiser/finalizer */
DUKKY_SET_DESTRUCTOR(0, window);
--
NetSurf Browser
7 years, 10 months
netsurf: branch dsilvers/dukky updated. release/3.3-235-gbfd72ab
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/bfd72abdc7ec0d63e920d...
...commit http://git.netsurf-browser.org/netsurf.git/commit/bfd72abdc7ec0d63e920d76...
...tree http://git.netsurf-browser.org/netsurf.git/tree/bfd72abdc7ec0d63e920d7650...
The branch, dsilvers/dukky has been updated
via bfd72abdc7ec0d63e920d7650c358a5a8080af11 (commit)
from 72a78ba9f5e2098480b922ab5cb5117ecdb05b36 (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=bfd72abdc7ec0d63e92...
commit bfd72abdc7ec0d63e920d7650c358a5a8080af11
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
More bits
diff --git a/javascript/dukky.c b/javascript/dukky.c
index 6536fa7..e5836be 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -333,7 +333,6 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
duk_put_global_string(ctx, PROTO_MAGIC);
/* Create prototypes here? */
DUKKY_NEW_PROTOTYPE(event_target, "EventTarget");
- DUKKY_NEW_PROTOTYPE(window, "Window");
DUKKY_NEW_PROTOTYPE(node, "Node");
DUKKY_NEW_PROTOTYPE(character_data, "CharacterData");
DUKKY_NEW_PROTOTYPE(text, "Text");
@@ -344,6 +343,9 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
DUKKY_NEW_PROTOTYPE(html_collection, "HTMLCollection");
DUKKY_NEW_PROTOTYPE(node_list, "NodeList");
+
+ /* Finally window's prototype */
+ DUKKY_NEW_PROTOTYPE(window, "Window");
return ret;
}
diff --git a/javascript/duktape/window.c b/javascript/duktape/window.c
index e52fcb0..3bad2ab 100644
--- a/javascript/duktape/window.c
+++ b/javascript/duktape/window.c
@@ -77,6 +77,9 @@ DUKKY_FUNC(window, __proto)
STEAL_THING(undefined);
/* Populate window's prototypical functionality */
DUKKY_POPULATE_FULL_PROPERTY(window, document);
+ /* Exposed prototypes */
+ DUKKY_GET_PROTOTYPE(node);
+ duk_put_prop_string(ctx, 0, "Node");
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(event_target);
duk_set_prototype(ctx, 0);
-----------------------------------------------------------------------
Summary of changes:
javascript/dukky.c | 4 +++-
javascript/duktape/window.c | 3 +++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/javascript/dukky.c b/javascript/dukky.c
index 6536fa7..e5836be 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -333,7 +333,6 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
duk_put_global_string(ctx, PROTO_MAGIC);
/* Create prototypes here? */
DUKKY_NEW_PROTOTYPE(event_target, "EventTarget");
- DUKKY_NEW_PROTOTYPE(window, "Window");
DUKKY_NEW_PROTOTYPE(node, "Node");
DUKKY_NEW_PROTOTYPE(character_data, "CharacterData");
DUKKY_NEW_PROTOTYPE(text, "Text");
@@ -344,6 +343,9 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
DUKKY_NEW_PROTOTYPE(html_collection, "HTMLCollection");
DUKKY_NEW_PROTOTYPE(node_list, "NodeList");
+
+ /* Finally window's prototype */
+ DUKKY_NEW_PROTOTYPE(window, "Window");
return ret;
}
diff --git a/javascript/duktape/window.c b/javascript/duktape/window.c
index e52fcb0..3bad2ab 100644
--- a/javascript/duktape/window.c
+++ b/javascript/duktape/window.c
@@ -77,6 +77,9 @@ DUKKY_FUNC(window, __proto)
STEAL_THING(undefined);
/* Populate window's prototypical functionality */
DUKKY_POPULATE_FULL_PROPERTY(window, document);
+ /* Exposed prototypes */
+ DUKKY_GET_PROTOTYPE(node);
+ duk_put_prop_string(ctx, 0, "Node");
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(event_target);
duk_set_prototype(ctx, 0);
--
NetSurf Browser
7 years, 10 months
netsurf: branch dsilvers/dukky updated. release/3.3-234-g72a78ba
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/72a78ba9f5e2098480b92...
...commit http://git.netsurf-browser.org/netsurf.git/commit/72a78ba9f5e2098480b922a...
...tree http://git.netsurf-browser.org/netsurf.git/tree/72a78ba9f5e2098480b922ab5...
The branch, dsilvers/dukky has been updated
via 72a78ba9f5e2098480b922ab5cb5117ecdb05b36 (commit)
from 8ec9e559e00f7c2288fa724591208e710690eff5 (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=72a78ba9f5e2098480b...
commit 72a78ba9f5e2098480b922ab5cb5117ecdb05b36
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Getting further
diff --git a/javascript/Makefile b/javascript/Makefile
index 80bba84..7c7006d 100644
--- a/javascript/Makefile
+++ b/javascript/Makefile
@@ -63,7 +63,7 @@ ifeq ($(NETSURF_USE_DUKTAPE),YES)
S_DUKKY := event_target.c window.c node.c document.c \
element.c html_element.c html_unknown_element.c \
- character_data.c text.c comment.c
+ character_data.c text.c comment.c html_collection.c node_list.c
S_JAVASCRIPT += dukky.c duktape.c content.c fetcher.c $(addprefix duktape/,$(S_DUKKY))
diff --git a/javascript/dukky.c b/javascript/dukky.c
index 9fd208f..6536fa7 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -342,6 +342,8 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
DUKKY_NEW_PROTOTYPE(element, "Element");
DUKKY_NEW_PROTOTYPE(html_element, "HTMLElement");
DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
+ DUKKY_NEW_PROTOTYPE(html_collection, "HTMLCollection");
+ DUKKY_NEW_PROTOTYPE(node_list, "NodeList");
return ret;
}
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index b4f8cef..76fec75 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -44,7 +44,8 @@ static DUKKY_FUNC(document, write)
DUKKY_GET_METHOD_PRIVATE(document);
struct html_content *htmlc;
duk_size_t text_len;
- const char *text = duk_get_lstring(ctx, 0, &text_len);
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ LOG("Writing %*s", (int)text_len, text);
dom_exception err;
err = dom_node_get_user_data(priv->parent.node,
corestring_dom___ns_key_html_content_data,
@@ -114,6 +115,35 @@ static DUKKY_FUNC(document, createElement)
return 1;
}
+static DUKKY_GETTER(document, head)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ struct dom_nodelist *nodes;
+ struct dom_node *retnode;
+ dom_exception err;
+ err = dom_document_get_elements_by_tag_name(priv->parent.node,
+ corestring_dom_HEAD,
+ &nodes);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_nodelist_item(nodes, 0, &retnode);
+
+ if (err != DOM_NO_ERR) {
+ dom_nodelist_unref(nodes);
+ return 0; /* coerced to undefined */
+ }
+
+ dom_nodelist_unref(nodes);
+
+ if (retnode == NULL) return 0; /* coerced to undefined */
+
+ dukky_push_node(ctx, retnode);
+
+ dom_node_unref(retnode);
+
+ return 1;
+}
+
static DUKKY_GETTER(document, body)
{
DUKKY_GET_METHOD_PRIVATE(document);
@@ -143,13 +173,71 @@ static DUKKY_GETTER(document, body)
return 1;
}
+static DUKKY_FUNC(document, getElementById)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_string *elementId_dom;
+ dom_element *element;
+ dom_exception exc;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+
+ exc = dom_string_create((uint8_t*)text, text_len, &elementId_dom);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ exc = dom_document_get_element_by_id(((node_private_t *)priv)->node,
+ elementId_dom, &element);
+ dom_string_unref(elementId_dom);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ if (element != NULL) {
+ dukky_push_node(ctx, (dom_node *)element);
+ return 1;
+ }
+
+ return 0;
+}
+
+static DUKKY_FUNC(document, getElementsByTagName)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_nodelist *nodes;
+ dom_exception err;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ dom_string *tag;
+
+ err = dom_string_create((uint8_t*)text, text_len, &tag);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_document_get_elements_by_tag_name(((node_private_t *)priv)->node,
+ tag, &nodes);
+ dom_string_unref(tag);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ if (nodes == NULL) return 0; /* coerced to undefined */
+
+ duk_push_pointer(ctx, nodes);
+ dukky_create_object(ctx, PROTO_NAME(node_list), 1);
+ dom_nodelist_unref(nodes);
+ return 1;
+}
+
DUKKY_FUNC(document, __proto)
{
/* Populate document's prototypical functionality */
DUKKY_ADD_METHOD(document, write, 1);
DUKKY_ADD_METHOD(document, createTextNode, 1);
DUKKY_ADD_METHOD(document, createElement, 1);
+ DUKKY_ADD_METHOD(document, getElementById, 1);
+ DUKKY_ADD_METHOD(document, getElementsByTagName, 1);
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
+ DUKKY_POPULATE_READONLY_PROPERTY(document, head);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/element.c b/javascript/duktape/element.c
index f495d86..23c7627 100644
--- a/javascript/duktape/element.c
+++ b/javascript/duktape/element.c
@@ -36,10 +36,180 @@ static DUKKY_FUNC(element, __destructor)
return 0;
}
+static DUKKY_GETTER(element, firstElementChild)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *next_node;
+
+ exc = dom_node_get_first_child(((node_private_t*)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_next_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, lastElementChild)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *next_node;
+
+ exc = dom_node_get_last_child(((node_private_t*)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_previous_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, previousElementSibling)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *sib_node;
+
+ exc = dom_node_get_previous_sibling(((node_private_t *)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_previous_sibling(element, &sib_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = sib_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, nextElementSibling)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *sib_node;
+
+ exc = dom_node_get_next_sibling(((node_private_t *)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_next_sibling(element, &sib_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = sib_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, childElementCount)
+{
+ LOG("MOO");
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *next_node;
+ duk_uint_t jsret = 0;
+
+ exc = dom_node_get_first_child(((node_private_t *)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ jsret += 1;
+ }
+
+ exc = dom_node_get_next_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ }
+ LOG("I found %u of them", jsret);
+ duk_push_uint(ctx, jsret);
+ return 1;
+}
+
DUKKY_FUNC(element, __proto)
{
/* Populate element's prototypical functionality */
-
+ DUKKY_POPULATE_READONLY_PROPERTY(element, firstElementChild);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, lastElementChild);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, nextElementSibling);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, previousElementSibling);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, childElementCount);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/html_collection.c b/javascript/duktape/html_collection.c
new file mode 100644
index 0000000..835398a
--- /dev/null
+++ b/javascript/duktape/html_collection.c
@@ -0,0 +1,48 @@
+/* DO NOT USE, DODGY EXAMPLE FOR VINCE */
+
+#include "utils/log.h"
+
+#include <dom/dom.h>
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(html_collection, struct dom_html_collection *coll)
+{
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+ priv->coll = coll;
+ dom_html_collection_ref(coll);
+}
+
+DUKKY_FUNC_FINI(html_collection)
+{
+ /* do any html_collection finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ dom_html_collection_unref(priv->coll);
+}
+
+static DUKKY_FUNC(html_collection, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(html_collection);
+ DUKKY_FUNC_T(html_collection, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ return 1;
+}
+
+static DUKKY_FUNC(html_collection, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(html_collection, 0);
+ DUKKY_FUNC_T(html_collection, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(html_collection, __proto)
+{
+ /* Populate html_collection's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, html_collection);
+ DUKKY_SET_CONSTRUCTOR(0, html_collection, 0);
+ return 1; /* The proto object */
+}
diff --git a/javascript/duktape/node.c b/javascript/duktape/node.c
index d632a24..2d7b1cf 100644
--- a/javascript/duktape/node.c
+++ b/javascript/duktape/node.c
@@ -56,10 +56,31 @@ static DUKKY_FUNC(node, appendChild)
return 0;
}
+static DUKKY_GETTER(node, textContent)
+{
+ DUKKY_GET_METHOD_PRIVATE(node);
+ dom_exception exc;
+ dom_string *content;
+
+ exc = dom_node_get_text_content(priv->node, &content);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ if (content != NULL) {
+ duk_push_lstring(ctx, dom_string_data(content), dom_string_length(content));
+ dom_string_unref(content);
+ return 1;
+ }
+
+ return 0;
+}
+
DUKKY_FUNC(node, __proto)
{
/* Populate node's prototypical functionality */
DUKKY_ADD_METHOD(node, appendChild, 1);
+ DUKKY_POPULATE_READONLY_PROPERTY(node, textContent);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(event_target);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/node_list.c b/javascript/duktape/node_list.c
new file mode 100644
index 0000000..c127c24
--- /dev/null
+++ b/javascript/duktape/node_list.c
@@ -0,0 +1,84 @@
+/* DO NOT USE, DODGY EXAMPLE FOR VINCE */
+
+#include "utils/log.h"
+
+#include <dom/dom.h>
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(node_list, struct dom_nodelist *nodes)
+{
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+ priv->nodes = nodes;
+ dom_nodelist_ref(nodes);
+}
+
+DUKKY_FUNC_FINI(node_list)
+{
+ /* do any node_list finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ dom_nodelist_unref(priv->nodes);
+}
+
+static DUKKY_FUNC(node_list, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(node_list);
+ DUKKY_FUNC_T(node_list, __init)(ctx, priv, duk_get_pointer(ctx, 1));
+ duk_pop(ctx);
+ return 1;
+}
+
+static DUKKY_FUNC(node_list, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(node_list, 0);
+ DUKKY_FUNC_T(node_list, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+static DUKKY_GETTER(node_list, length)
+{
+ DUKKY_GET_METHOD_PRIVATE(node_list);
+ dom_exception err;
+ unsigned long len;
+
+ err = dom_nodelist_get_length(priv->nodes, &len);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ duk_push_uint(ctx, (duk_uint_t)len);
+ return 1;
+}
+
+static DUKKY_FUNC(node_list, item)
+{
+ DUKKY_GET_METHOD_PRIVATE(node_list);
+ unsigned long i = duk_to_uint(ctx, 0);
+ dom_exception err;
+ dom_node *node;
+
+ LOG("Looking up %u in %p", i, priv->nodes);
+
+ err = dom_nodelist_item(priv->nodes, i, &node);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefied */
+
+ dukky_push_node(ctx, node);
+ dom_node_unref(node);
+
+ return 1;
+}
+
+/** TODO: ARRAY-LIKE behaviour missing */
+
+DUKKY_FUNC(node_list, __proto)
+{
+ /* Populate node_list's prototypical functionality */
+ DUKKY_POPULATE_READONLY_PROPERTY(node_list, length);
+ DUKKY_ADD_METHOD(node_list, item, 1);
+ /* Set this prototype's prototype (left-parent)*/
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, node_list);
+ DUKKY_SET_CONSTRUCTOR(0, node_list, 1);
+ return 1; /* The proto object */
+}
diff --git a/javascript/duktape/private.h b/javascript/duktape/private.h
index 6dd3086..42c2079 100644
--- a/javascript/duktape/private.h
+++ b/javascript/duktape/private.h
@@ -9,7 +9,9 @@ struct dom_document;
struct dom_html_element;
struct dom_node_character_data;
struct dom_node_text;
+struct dom_node_list;
struct dom_node_comment;
+struct dom_html_collection;
typedef struct {
} event_target_private_t;
@@ -53,4 +55,12 @@ typedef struct {
node_private_t parent;
} document_private_t;
+typedef struct {
+ struct dom_html_collection *coll;
+} html_collection_private_t;
+
+typedef struct {
+ struct dom_nodelist *nodes;
+} node_list_private_t;
+
#endif
diff --git a/javascript/duktape/prototypes.h b/javascript/duktape/prototypes.h
index aa1813e..1f25424 100644
--- a/javascript/duktape/prototypes.h
+++ b/javascript/duktape/prototypes.h
@@ -11,6 +11,8 @@ DUKKY_DECLARE_INTERFACE(document, struct dom_document *);
DUKKY_DECLARE_INTERFACE(element, struct dom_element *);
DUKKY_DECLARE_INTERFACE(html_element, struct dom_html_element *);
DUKKY_DECLARE_INTERFACE(html_unknown_element, struct dom_html_element *);
+DUKKY_DECLARE_INTERFACE(html_collection, struct dom_html_collection *);
+DUKKY_DECLARE_INTERFACE(node_list, struct dom_nodelist *);
#endif
diff --git a/test/js/dom-element-firstElementChild.html b/test/js/dom-element-firstElementChild.html
index 2d7762d..e3ff9bb 100644
--- a/test/js/dom-element-firstElementChild.html
+++ b/test/js/dom-element-firstElementChild.html
@@ -1,10 +1,10 @@
<html>
<head>
-<title>DOM firstElementChild reference</title>
+<title>DOM firstElementChild reference (title)</title>
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
-<h1>DOM firstElementChild reference</h1>
+<h1>DOM firstElementChild reference (body)</h1>
<p><b>head.firstElementChild:</b> <script>document.write(document.head.firstElementChild.textContent);</script></p>
<p><b>body.firstElementChild:</b> <script>document.write(document.body.firstElementChild.textContent);</script></p>
</body>
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 1d20362..1a016a2 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -261,6 +261,7 @@ dom_string *corestring_dom_INPUT;
dom_string *corestring_dom_SELECT;
dom_string *corestring_dom_TEXTAREA;
dom_string *corestring_dom_BODY;
+dom_string *corestring_dom_HEAD;
dom_string *corestring_dom_html_namespace;
dom_string *corestring_dom_button;
dom_string *corestring_dom_image;
@@ -534,6 +535,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(SELECT);
CSS_DOM_STRING_UNREF(TEXTAREA);
CSS_DOM_STRING_UNREF(BODY);
+ CSS_DOM_STRING_UNREF(HEAD);
/* DOM namespaces, not really CSS */
CSS_DOM_STRING_UNREF(html_namespace);
/* DOM input types, not really CSS */
@@ -854,6 +856,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(SELECT);
CSS_DOM_STRING_INTERN(TEXTAREA);
CSS_DOM_STRING_INTERN(BODY);
+ CSS_DOM_STRING_INTERN(HEAD);
/* DOM input types, not really CSS */
CSS_DOM_STRING_INTERN(button);
CSS_DOM_STRING_INTERN(image);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 415dece..e452354 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -273,6 +273,7 @@ extern struct dom_string *corestring_dom_INPUT;
extern struct dom_string *corestring_dom_SELECT;
extern struct dom_string *corestring_dom_TEXTAREA;
extern struct dom_string *corestring_dom_BODY;
+extern struct dom_string *corestring_dom_HEAD;
/* DOM namespaces */
extern struct dom_string *corestring_dom_html_namespace;
/* DOM input node types */
-----------------------------------------------------------------------
Summary of changes:
javascript/Makefile | 2 +-
javascript/dukky.c | 2 +
javascript/duktape/document.c | 90 ++++++++++++++-
javascript/duktape/element.c | 172 +++++++++++++++++++++++++++-
javascript/duktape/html_collection.c | 48 ++++++++
javascript/duktape/node.c | 21 ++++
javascript/duktape/node_list.c | 84 ++++++++++++++
javascript/duktape/private.h | 10 ++
javascript/duktape/prototypes.h | 2 +
test/js/dom-element-firstElementChild.html | 4 +-
utils/corestrings.c | 3 +
utils/corestrings.h | 1 +
12 files changed, 434 insertions(+), 5 deletions(-)
create mode 100644 javascript/duktape/html_collection.c
create mode 100644 javascript/duktape/node_list.c
diff --git a/javascript/Makefile b/javascript/Makefile
index 80bba84..7c7006d 100644
--- a/javascript/Makefile
+++ b/javascript/Makefile
@@ -63,7 +63,7 @@ ifeq ($(NETSURF_USE_DUKTAPE),YES)
S_DUKKY := event_target.c window.c node.c document.c \
element.c html_element.c html_unknown_element.c \
- character_data.c text.c comment.c
+ character_data.c text.c comment.c html_collection.c node_list.c
S_JAVASCRIPT += dukky.c duktape.c content.c fetcher.c $(addprefix duktape/,$(S_DUKKY))
diff --git a/javascript/dukky.c b/javascript/dukky.c
index 9fd208f..6536fa7 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -342,6 +342,8 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
DUKKY_NEW_PROTOTYPE(element, "Element");
DUKKY_NEW_PROTOTYPE(html_element, "HTMLElement");
DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
+ DUKKY_NEW_PROTOTYPE(html_collection, "HTMLCollection");
+ DUKKY_NEW_PROTOTYPE(node_list, "NodeList");
return ret;
}
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index b4f8cef..76fec75 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -44,7 +44,8 @@ static DUKKY_FUNC(document, write)
DUKKY_GET_METHOD_PRIVATE(document);
struct html_content *htmlc;
duk_size_t text_len;
- const char *text = duk_get_lstring(ctx, 0, &text_len);
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ LOG("Writing %*s", (int)text_len, text);
dom_exception err;
err = dom_node_get_user_data(priv->parent.node,
corestring_dom___ns_key_html_content_data,
@@ -114,6 +115,35 @@ static DUKKY_FUNC(document, createElement)
return 1;
}
+static DUKKY_GETTER(document, head)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ struct dom_nodelist *nodes;
+ struct dom_node *retnode;
+ dom_exception err;
+ err = dom_document_get_elements_by_tag_name(priv->parent.node,
+ corestring_dom_HEAD,
+ &nodes);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_nodelist_item(nodes, 0, &retnode);
+
+ if (err != DOM_NO_ERR) {
+ dom_nodelist_unref(nodes);
+ return 0; /* coerced to undefined */
+ }
+
+ dom_nodelist_unref(nodes);
+
+ if (retnode == NULL) return 0; /* coerced to undefined */
+
+ dukky_push_node(ctx, retnode);
+
+ dom_node_unref(retnode);
+
+ return 1;
+}
+
static DUKKY_GETTER(document, body)
{
DUKKY_GET_METHOD_PRIVATE(document);
@@ -143,13 +173,71 @@ static DUKKY_GETTER(document, body)
return 1;
}
+static DUKKY_FUNC(document, getElementById)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_string *elementId_dom;
+ dom_element *element;
+ dom_exception exc;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+
+ exc = dom_string_create((uint8_t*)text, text_len, &elementId_dom);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ exc = dom_document_get_element_by_id(((node_private_t *)priv)->node,
+ elementId_dom, &element);
+ dom_string_unref(elementId_dom);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ if (element != NULL) {
+ dukky_push_node(ctx, (dom_node *)element);
+ return 1;
+ }
+
+ return 0;
+}
+
+static DUKKY_FUNC(document, getElementsByTagName)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_nodelist *nodes;
+ dom_exception err;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ dom_string *tag;
+
+ err = dom_string_create((uint8_t*)text, text_len, &tag);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_document_get_elements_by_tag_name(((node_private_t *)priv)->node,
+ tag, &nodes);
+ dom_string_unref(tag);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ if (nodes == NULL) return 0; /* coerced to undefined */
+
+ duk_push_pointer(ctx, nodes);
+ dukky_create_object(ctx, PROTO_NAME(node_list), 1);
+ dom_nodelist_unref(nodes);
+ return 1;
+}
+
DUKKY_FUNC(document, __proto)
{
/* Populate document's prototypical functionality */
DUKKY_ADD_METHOD(document, write, 1);
DUKKY_ADD_METHOD(document, createTextNode, 1);
DUKKY_ADD_METHOD(document, createElement, 1);
+ DUKKY_ADD_METHOD(document, getElementById, 1);
+ DUKKY_ADD_METHOD(document, getElementsByTagName, 1);
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
+ DUKKY_POPULATE_READONLY_PROPERTY(document, head);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/element.c b/javascript/duktape/element.c
index f495d86..23c7627 100644
--- a/javascript/duktape/element.c
+++ b/javascript/duktape/element.c
@@ -36,10 +36,180 @@ static DUKKY_FUNC(element, __destructor)
return 0;
}
+static DUKKY_GETTER(element, firstElementChild)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *next_node;
+
+ exc = dom_node_get_first_child(((node_private_t*)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_next_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, lastElementChild)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *next_node;
+
+ exc = dom_node_get_last_child(((node_private_t*)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_previous_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, previousElementSibling)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *sib_node;
+
+ exc = dom_node_get_previous_sibling(((node_private_t *)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_previous_sibling(element, &sib_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = sib_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, nextElementSibling)
+{
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *sib_node;
+
+ exc = dom_node_get_next_sibling(((node_private_t *)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ /* found it */
+ dukky_push_node(ctx, (dom_node *)element);
+ dom_node_unref(element);
+ return 1;
+ }
+
+ exc = dom_node_get_next_sibling(element, &sib_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = sib_node;
+ } else {
+ element = NULL;
+ }
+ }
+ return 0;
+}
+
+static DUKKY_GETTER(element, childElementCount)
+{
+ LOG("MOO");
+ DUKKY_GET_METHOD_PRIVATE(element);
+ dom_node *element;
+ dom_exception exc;
+ dom_node_type node_type;
+ dom_node *next_node;
+ duk_uint_t jsret = 0;
+
+ exc = dom_node_get_first_child(((node_private_t *)priv)->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ while (element != NULL) {
+ exc = dom_node_get_node_type(element, &node_type);
+ if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
+ jsret += 1;
+ }
+
+ exc = dom_node_get_next_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ }
+ LOG("I found %u of them", jsret);
+ duk_push_uint(ctx, jsret);
+ return 1;
+}
+
DUKKY_FUNC(element, __proto)
{
/* Populate element's prototypical functionality */
-
+ DUKKY_POPULATE_READONLY_PROPERTY(element, firstElementChild);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, lastElementChild);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, nextElementSibling);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, previousElementSibling);
+ DUKKY_POPULATE_READONLY_PROPERTY(element, childElementCount);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/html_collection.c b/javascript/duktape/html_collection.c
new file mode 100644
index 0000000..835398a
--- /dev/null
+++ b/javascript/duktape/html_collection.c
@@ -0,0 +1,48 @@
+/* DO NOT USE, DODGY EXAMPLE FOR VINCE */
+
+#include "utils/log.h"
+
+#include <dom/dom.h>
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(html_collection, struct dom_html_collection *coll)
+{
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+ priv->coll = coll;
+ dom_html_collection_ref(coll);
+}
+
+DUKKY_FUNC_FINI(html_collection)
+{
+ /* do any html_collection finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ dom_html_collection_unref(priv->coll);
+}
+
+static DUKKY_FUNC(html_collection, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(html_collection);
+ DUKKY_FUNC_T(html_collection, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ return 1;
+}
+
+static DUKKY_FUNC(html_collection, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(html_collection, 0);
+ DUKKY_FUNC_T(html_collection, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(html_collection, __proto)
+{
+ /* Populate html_collection's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, html_collection);
+ DUKKY_SET_CONSTRUCTOR(0, html_collection, 0);
+ return 1; /* The proto object */
+}
diff --git a/javascript/duktape/node.c b/javascript/duktape/node.c
index d632a24..2d7b1cf 100644
--- a/javascript/duktape/node.c
+++ b/javascript/duktape/node.c
@@ -56,10 +56,31 @@ static DUKKY_FUNC(node, appendChild)
return 0;
}
+static DUKKY_GETTER(node, textContent)
+{
+ DUKKY_GET_METHOD_PRIVATE(node);
+ dom_exception exc;
+ dom_string *content;
+
+ exc = dom_node_get_text_content(priv->node, &content);
+ if (exc != DOM_NO_ERR) {
+ return 0;
+ }
+
+ if (content != NULL) {
+ duk_push_lstring(ctx, dom_string_data(content), dom_string_length(content));
+ dom_string_unref(content);
+ return 1;
+ }
+
+ return 0;
+}
+
DUKKY_FUNC(node, __proto)
{
/* Populate node's prototypical functionality */
DUKKY_ADD_METHOD(node, appendChild, 1);
+ DUKKY_POPULATE_READONLY_PROPERTY(node, textContent);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(event_target);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/node_list.c b/javascript/duktape/node_list.c
new file mode 100644
index 0000000..c127c24
--- /dev/null
+++ b/javascript/duktape/node_list.c
@@ -0,0 +1,84 @@
+/* DO NOT USE, DODGY EXAMPLE FOR VINCE */
+
+#include "utils/log.h"
+
+#include <dom/dom.h>
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(node_list, struct dom_nodelist *nodes)
+{
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+ priv->nodes = nodes;
+ dom_nodelist_ref(nodes);
+}
+
+DUKKY_FUNC_FINI(node_list)
+{
+ /* do any node_list finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ dom_nodelist_unref(priv->nodes);
+}
+
+static DUKKY_FUNC(node_list, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(node_list);
+ DUKKY_FUNC_T(node_list, __init)(ctx, priv, duk_get_pointer(ctx, 1));
+ duk_pop(ctx);
+ return 1;
+}
+
+static DUKKY_FUNC(node_list, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(node_list, 0);
+ DUKKY_FUNC_T(node_list, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+static DUKKY_GETTER(node_list, length)
+{
+ DUKKY_GET_METHOD_PRIVATE(node_list);
+ dom_exception err;
+ unsigned long len;
+
+ err = dom_nodelist_get_length(priv->nodes, &len);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ duk_push_uint(ctx, (duk_uint_t)len);
+ return 1;
+}
+
+static DUKKY_FUNC(node_list, item)
+{
+ DUKKY_GET_METHOD_PRIVATE(node_list);
+ unsigned long i = duk_to_uint(ctx, 0);
+ dom_exception err;
+ dom_node *node;
+
+ LOG("Looking up %u in %p", i, priv->nodes);
+
+ err = dom_nodelist_item(priv->nodes, i, &node);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefied */
+
+ dukky_push_node(ctx, node);
+ dom_node_unref(node);
+
+ return 1;
+}
+
+/** TODO: ARRAY-LIKE behaviour missing */
+
+DUKKY_FUNC(node_list, __proto)
+{
+ /* Populate node_list's prototypical functionality */
+ DUKKY_POPULATE_READONLY_PROPERTY(node_list, length);
+ DUKKY_ADD_METHOD(node_list, item, 1);
+ /* Set this prototype's prototype (left-parent)*/
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, node_list);
+ DUKKY_SET_CONSTRUCTOR(0, node_list, 1);
+ return 1; /* The proto object */
+}
diff --git a/javascript/duktape/private.h b/javascript/duktape/private.h
index 6dd3086..42c2079 100644
--- a/javascript/duktape/private.h
+++ b/javascript/duktape/private.h
@@ -9,7 +9,9 @@ struct dom_document;
struct dom_html_element;
struct dom_node_character_data;
struct dom_node_text;
+struct dom_node_list;
struct dom_node_comment;
+struct dom_html_collection;
typedef struct {
} event_target_private_t;
@@ -53,4 +55,12 @@ typedef struct {
node_private_t parent;
} document_private_t;
+typedef struct {
+ struct dom_html_collection *coll;
+} html_collection_private_t;
+
+typedef struct {
+ struct dom_nodelist *nodes;
+} node_list_private_t;
+
#endif
diff --git a/javascript/duktape/prototypes.h b/javascript/duktape/prototypes.h
index aa1813e..1f25424 100644
--- a/javascript/duktape/prototypes.h
+++ b/javascript/duktape/prototypes.h
@@ -11,6 +11,8 @@ DUKKY_DECLARE_INTERFACE(document, struct dom_document *);
DUKKY_DECLARE_INTERFACE(element, struct dom_element *);
DUKKY_DECLARE_INTERFACE(html_element, struct dom_html_element *);
DUKKY_DECLARE_INTERFACE(html_unknown_element, struct dom_html_element *);
+DUKKY_DECLARE_INTERFACE(html_collection, struct dom_html_collection *);
+DUKKY_DECLARE_INTERFACE(node_list, struct dom_nodelist *);
#endif
diff --git a/test/js/dom-element-firstElementChild.html b/test/js/dom-element-firstElementChild.html
index 2d7762d..e3ff9bb 100644
--- a/test/js/dom-element-firstElementChild.html
+++ b/test/js/dom-element-firstElementChild.html
@@ -1,10 +1,10 @@
<html>
<head>
-<title>DOM firstElementChild reference</title>
+<title>DOM firstElementChild reference (title)</title>
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
-<h1>DOM firstElementChild reference</h1>
+<h1>DOM firstElementChild reference (body)</h1>
<p><b>head.firstElementChild:</b> <script>document.write(document.head.firstElementChild.textContent);</script></p>
<p><b>body.firstElementChild:</b> <script>document.write(document.body.firstElementChild.textContent);</script></p>
</body>
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 1d20362..1a016a2 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -261,6 +261,7 @@ dom_string *corestring_dom_INPUT;
dom_string *corestring_dom_SELECT;
dom_string *corestring_dom_TEXTAREA;
dom_string *corestring_dom_BODY;
+dom_string *corestring_dom_HEAD;
dom_string *corestring_dom_html_namespace;
dom_string *corestring_dom_button;
dom_string *corestring_dom_image;
@@ -534,6 +535,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(SELECT);
CSS_DOM_STRING_UNREF(TEXTAREA);
CSS_DOM_STRING_UNREF(BODY);
+ CSS_DOM_STRING_UNREF(HEAD);
/* DOM namespaces, not really CSS */
CSS_DOM_STRING_UNREF(html_namespace);
/* DOM input types, not really CSS */
@@ -854,6 +856,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(SELECT);
CSS_DOM_STRING_INTERN(TEXTAREA);
CSS_DOM_STRING_INTERN(BODY);
+ CSS_DOM_STRING_INTERN(HEAD);
/* DOM input types, not really CSS */
CSS_DOM_STRING_INTERN(button);
CSS_DOM_STRING_INTERN(image);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 415dece..e452354 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -273,6 +273,7 @@ extern struct dom_string *corestring_dom_INPUT;
extern struct dom_string *corestring_dom_SELECT;
extern struct dom_string *corestring_dom_TEXTAREA;
extern struct dom_string *corestring_dom_BODY;
+extern struct dom_string *corestring_dom_HEAD;
/* DOM namespaces */
extern struct dom_string *corestring_dom_html_namespace;
/* DOM input node types */
--
NetSurf Browser
7 years, 10 months
libnslayout: branch master updated. 91366856f641dc74b6ad05168b65e4c38976d48a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/91366856f641dc74b...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/91366856f641dc74b6a...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/91366856f641dc74b6ad0...
The branch, master has been updated
via 91366856f641dc74b6ad05168b65e4c38976d48a (commit)
from 0aa5a727b3739a47a5a37741eb72b691e8b8fe57 (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=91366856f641dc7...
commit 91366856f641dc74b6ad05168b65e4c38976d48a
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add nslayout_layout_destroy basic API testing.
diff --git a/src/layout.c b/src/layout.c
index 773996a..43570fb 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -49,6 +49,7 @@ nslayout_error nslayout_layout_destroy(
nslayout_layout *layout)
{
/* TODO: free/unref the stuff we own in the layout */
+ assert(layout != NULL);
free(layout);
return NSLAYOUT_OK;
diff --git a/test/assert-tests.c b/test/assert-tests.c
index 4fca036..1b97814 100644
--- a/test/assert-tests.c
+++ b/test/assert-tests.c
@@ -22,16 +22,27 @@ START_TEST (test_nslayout_layout_create_aborts1)
}
END_TEST
+/* TODO: Test for each individual param being NULL. */
+START_TEST (test_nslayout_layout_destroy_aborts1)
+{
+ (void) nslayout_layout_destroy(NULL);
+}
+END_TEST
+
void nslayout_assert_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: API Assert tests");
- TCase *tc_assert = tcase_create("Creation/Destruction");
+ TCase *tc_assert = tcase_create("Creation/Destruction");
tcase_add_test_raise_signal(
tc_assert,
test_nslayout_layout_create_aborts1,
SIGABRT);
+ tcase_add_test_raise_signal(
+ tc_assert,
+ test_nslayout_layout_destroy_aborts1,
+ SIGABRT);
suite_add_tcase(s, tc_assert);
srunner_add_suite(sr, s);
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
index 84611a9..6dec991 100644
--- a/test/basic-layout-tests.c
+++ b/test/basic-layout-tests.c
@@ -52,11 +52,15 @@ START_TEST (test_nslayout_layout_create_ok)
nslayout_test_callback,
&pw,
&layout);
- fail_unless(error == NSLAYOUT_OK,
+ fail_unless(error == NSLAYOUT_OK,
"Unable to create layout");
- fail_unless(layout != NULL,
+ fail_unless(layout != NULL,
"Returned OK but str was still NULL");
+ error = nslayout_layout_destroy(layout);
+ fail_unless(error == NSLAYOUT_OK,
+ "Unable to destroy layout");
+
css_err = css_select_ctx_destroy(css_ctx);
ck_assert(css_err == CSS_OK);
@@ -68,10 +72,9 @@ END_TEST
void nslayout_basic_layout_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: basic layout tests");
- TCase *tc_layout_basic = tcase_create("Creation/Destruction");
+ TCase *tc_layout_basic = tcase_create("Creation/Destruction");
- tcase_add_test(tc_layout_basic,
- test_nslayout_layout_create_ok);
+ tcase_add_test(tc_layout_basic, test_nslayout_layout_create_ok);
suite_add_tcase(s, tc_layout_basic);
srunner_add_suite(sr, s);
-----------------------------------------------------------------------
Summary of changes:
src/layout.c | 1 +
test/assert-tests.c | 13 ++++++++++++-
test/basic-layout-tests.c | 13 ++++++++-----
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/layout.c b/src/layout.c
index 773996a..43570fb 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -49,6 +49,7 @@ nslayout_error nslayout_layout_destroy(
nslayout_layout *layout)
{
/* TODO: free/unref the stuff we own in the layout */
+ assert(layout != NULL);
free(layout);
return NSLAYOUT_OK;
diff --git a/test/assert-tests.c b/test/assert-tests.c
index 4fca036..1b97814 100644
--- a/test/assert-tests.c
+++ b/test/assert-tests.c
@@ -22,16 +22,27 @@ START_TEST (test_nslayout_layout_create_aborts1)
}
END_TEST
+/* TODO: Test for each individual param being NULL. */
+START_TEST (test_nslayout_layout_destroy_aborts1)
+{
+ (void) nslayout_layout_destroy(NULL);
+}
+END_TEST
+
void nslayout_assert_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: API Assert tests");
- TCase *tc_assert = tcase_create("Creation/Destruction");
+ TCase *tc_assert = tcase_create("Creation/Destruction");
tcase_add_test_raise_signal(
tc_assert,
test_nslayout_layout_create_aborts1,
SIGABRT);
+ tcase_add_test_raise_signal(
+ tc_assert,
+ test_nslayout_layout_destroy_aborts1,
+ SIGABRT);
suite_add_tcase(s, tc_assert);
srunner_add_suite(sr, s);
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
index 84611a9..6dec991 100644
--- a/test/basic-layout-tests.c
+++ b/test/basic-layout-tests.c
@@ -52,11 +52,15 @@ START_TEST (test_nslayout_layout_create_ok)
nslayout_test_callback,
&pw,
&layout);
- fail_unless(error == NSLAYOUT_OK,
+ fail_unless(error == NSLAYOUT_OK,
"Unable to create layout");
- fail_unless(layout != NULL,
+ fail_unless(layout != NULL,
"Returned OK but str was still NULL");
+ error = nslayout_layout_destroy(layout);
+ fail_unless(error == NSLAYOUT_OK,
+ "Unable to destroy layout");
+
css_err = css_select_ctx_destroy(css_ctx);
ck_assert(css_err == CSS_OK);
@@ -68,10 +72,9 @@ END_TEST
void nslayout_basic_layout_suite(SRunner *sr)
{
Suite *s = suite_create("libnslayout: basic layout tests");
- TCase *tc_layout_basic = tcase_create("Creation/Destruction");
+ TCase *tc_layout_basic = tcase_create("Creation/Destruction");
- tcase_add_test(tc_layout_basic,
- test_nslayout_layout_create_ok);
+ tcase_add_test(tc_layout_basic, test_nslayout_layout_create_ok);
suite_add_tcase(s, tc_layout_basic);
srunner_add_suite(sr, s);
--
NetSurf Layout Engine
7 years, 10 months
libnslayout: branch master updated. 0aa5a727b3739a47a5a37741eb72b691e8b8fe57
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/0aa5a727b3739a47a...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/0aa5a727b3739a47a5a...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/0aa5a727b3739a47a5a37...
The branch, master has been updated
via 0aa5a727b3739a47a5a37741eb72b691e8b8fe57 (commit)
via 2e86255e49f316c9749f350cf57d0f17a36abdaa (commit)
via a0ad0c682444aeb8e058f846fde121f061eb17b7 (commit)
via d01aac9ac10d902a799aade8270093bcba3e3a88 (commit)
from aed0dede52601d8e94f643c0b39a50da835ec8cd (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=0aa5a727b3739a4...
commit 0aa5a727b3739a47a5a37741eb72b691e8b8fe57
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add basic tests for creating a layout object.
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..5703e79
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;basic-layout-tests.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/test/assert-tests.c b/test/assert-tests.c
new file mode 100644
index 0000000..4fca036
--- /dev/null
+++ b/test/assert-tests.c
@@ -0,0 +1,38 @@
+/*
+ * 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 <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+/* TODO: Test for each individual param being NULL. */
+START_TEST (test_nslayout_layout_create_aborts1)
+{
+ nslayout_layout *layout;
+ (void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
+}
+END_TEST
+
+
+void nslayout_assert_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: API Assert tests");
+ TCase *tc_assert = tcase_create("Creation/Destruction");
+
+ tcase_add_test_raise_signal(
+ tc_assert,
+ test_nslayout_layout_create_aborts1,
+ SIGABRT);
+ suite_add_tcase(s, tc_assert);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
new file mode 100644
index 0000000..84611a9
--- /dev/null
+++ b/test/basic-layout-tests.c
@@ -0,0 +1,78 @@
+/*
+ * 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 <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+int pw;
+
+static nslayout_error nslayout_test_callback(
+ nslayout_request *req,
+ nslayout_layout *layout,
+ void *pw)
+{
+ UNUSED(req);
+ UNUSED(layout);
+ UNUSED(pw);
+ return NSLAYOUT_OK;
+}
+
+START_TEST (test_nslayout_layout_create_ok)
+{
+ nslayout_layout *layout = NULL;
+ nslayout_error error;
+ dom_exception dom_error;
+ css_error css_err;
+ dom_document *doc;
+ css_select_ctx *css_ctx;
+ css_media_type media = CSS_MEDIA_SCREEN;
+
+ /* Create a DOM document */
+ dom_error = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
+ NULL, NULL, NULL, NULL, NULL, &doc);
+ ck_assert(dom_error == DOM_NO_ERR);
+
+ /* Create a selection context (with no sheets added) */
+ css_err = css_select_ctx_create(&css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ error = nslayout_layout_create(doc,
+ css_ctx,
+ &media,
+ nslayout_test_callback,
+ &pw,
+ &layout);
+ fail_unless(error == NSLAYOUT_OK,
+ "Unable to create layout");
+ fail_unless(layout != NULL,
+ "Returned OK but str was still NULL");
+
+ css_err = css_select_ctx_destroy(css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ dom_node_unref(doc);
+}
+END_TEST
+
+
+void nslayout_basic_layout_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: basic layout tests");
+ TCase *tc_layout_basic = tcase_create("Creation/Destruction");
+
+ tcase_add_test(tc_layout_basic,
+ test_nslayout_layout_create_ok);
+ suite_add_tcase(s, tc_layout_basic);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/tests.c b/test/tests.c
new file mode 100644
index 0000000..a58e038
--- /dev/null
+++ b/test/tests.c
@@ -0,0 +1,52 @@
+/*
+ * 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 <assert.h>
+#include <stdlib.h>
+
+#include <check.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) ((x) = (x))
+#endif
+
+#ifndef NDEBUG
+/* This means that assertion failures are silent in tests */
+void __assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function) {
+ (void)__assertion;
+ (void)__file;
+ (void)__line;
+ (void)__function;
+ abort();
+}
+#endif
+
+int main(int argc, char **argv)
+{
+ int number_failed = 0;
+ SRunner *sr;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ sr = srunner_create(suite_create("Test suite for libnslayout"));
+
+#ifndef NDEBUG
+ nslayout_assert_suite(sr);
+#endif
+ nslayout_basic_layout_suite(sr);
+
+ srunner_set_fork_status(sr, CK_FORK);
+ srunner_run_all(sr, CK_ENV);
+ number_failed = srunner_ntests_failed(sr);
+
+ srunner_free(sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/test/tests.h b/test/tests.h
new file mode 100644
index 0000000..4f7795f
--- /dev/null
+++ b/test/tests.h
@@ -0,0 +1,19 @@
+/*
+ * 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>
+ */
+
+#ifndef nslayout_tests_h_
+#define nslayout_tests_h_
+
+#include <signal.h>
+
+#include <check.h>
+
+#include <libnslayout/nslayout.h>
+
+extern void nslayout_assert_suite(SRunner *);
+extern void nslayout_basic_layout_suite(SRunner *);
+
+#endif
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=2e86255e49f316c...
commit 2e86255e49f316c9749f350cf57d0f17a36abdaa
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add ignore file.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..015f2f7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build-*
+*~
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=a0ad0c682444aeb...
commit a0ad0c682444aeb8e058f846fde121f061eb17b7
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix link order.
diff --git a/Makefile b/Makefile
index beb2b46..0a84269 100644
--- a/Makefile
+++ b/Makefile
@@ -41,9 +41,9 @@ endif
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
ifneq ($(PKGCONFIG),)
CFLAGS := $(CFLAGS) $(shell $(PKGCONFIG) \
- libwapcaplet libparserutils libcss libdom --cflags)
+ libcss libdom libwapcaplet libparserutils --cflags)
LDFLAGS := $(LDFLAGS) $(shell $(PKGCONFIG) \
- libwapcaplet libparserutils libcss libdom --libs)
+ libcss libdom libwapcaplet libparserutils --libs)
else
CFLAGS := $(CFLAGS) -I$(PREFIX)/include
LDFLAGS := $(LDFLAGS) -lparserutils -lwapcaplet -lcss -ldom
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=d01aac9ac10d902...
commit d01aac9ac10d902a799aade8270093bcba3e3a88
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix callback parameter.
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 2a48690..f42bed7 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -130,7 +130,7 @@ nslayout_error nslayout_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback *cb,
+ nslayout_callback cb,
void *pw,
nslayout_layout **layout);
diff --git a/src/layout.c b/src/layout.c
index dab4855..773996a 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -15,7 +15,7 @@ nslayout_error nslayout_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback *cb,
+ nslayout_callback cb,
void *pw,
nslayout_layout **layout)
{
diff --git a/src/layout.h b/src/layout.h
index 5b43bc6..6e8f4c9 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -13,7 +13,7 @@ struct nslayout_layout {
dom_document *doc;
css_select_ctx *css_ctx;
css_media_type *media;
- nslayout_callback *cb;
+ nslayout_callback cb;
void *pw;
};
-----------------------------------------------------------------------
Summary of changes:
.gitignore | 2 ++
Makefile | 4 +--
include/libnslayout/nslayout.h | 2 +-
src/layout.c | 2 +-
src/layout.h | 2 +-
test/Makefile | 3 ++
test/assert-tests.c | 38 ++++++++++++++++++++
test/basic-layout-tests.c | 78 ++++++++++++++++++++++++++++++++++++++++
test/tests.c | 52 +++++++++++++++++++++++++++
test/tests.h | 19 ++++++++++
10 files changed, 197 insertions(+), 5 deletions(-)
create mode 100644 .gitignore
create mode 100644 test/Makefile
create mode 100644 test/assert-tests.c
create mode 100644 test/basic-layout-tests.c
create mode 100644 test/tests.c
create mode 100644 test/tests.h
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..015f2f7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build-*
+*~
diff --git a/Makefile b/Makefile
index beb2b46..0a84269 100644
--- a/Makefile
+++ b/Makefile
@@ -41,9 +41,9 @@ endif
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
ifneq ($(PKGCONFIG),)
CFLAGS := $(CFLAGS) $(shell $(PKGCONFIG) \
- libwapcaplet libparserutils libcss libdom --cflags)
+ libcss libdom libwapcaplet libparserutils --cflags)
LDFLAGS := $(LDFLAGS) $(shell $(PKGCONFIG) \
- libwapcaplet libparserutils libcss libdom --libs)
+ libcss libdom libwapcaplet libparserutils --libs)
else
CFLAGS := $(CFLAGS) -I$(PREFIX)/include
LDFLAGS := $(LDFLAGS) -lparserutils -lwapcaplet -lcss -ldom
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 2a48690..f42bed7 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -130,7 +130,7 @@ nslayout_error nslayout_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback *cb,
+ nslayout_callback cb,
void *pw,
nslayout_layout **layout);
diff --git a/src/layout.c b/src/layout.c
index dab4855..773996a 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -15,7 +15,7 @@ nslayout_error nslayout_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
- nslayout_callback *cb,
+ nslayout_callback cb,
void *pw,
nslayout_layout **layout)
{
diff --git a/src/layout.h b/src/layout.h
index 5b43bc6..6e8f4c9 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -13,7 +13,7 @@ struct nslayout_layout {
dom_document *doc;
css_select_ctx *css_ctx;
css_media_type *media;
- nslayout_callback *cb;
+ nslayout_callback cb;
void *pw;
};
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..5703e79
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;basic-layout-tests.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/test/assert-tests.c b/test/assert-tests.c
new file mode 100644
index 0000000..4fca036
--- /dev/null
+++ b/test/assert-tests.c
@@ -0,0 +1,38 @@
+/*
+ * 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 <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+/* TODO: Test for each individual param being NULL. */
+START_TEST (test_nslayout_layout_create_aborts1)
+{
+ nslayout_layout *layout;
+ (void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
+}
+END_TEST
+
+
+void nslayout_assert_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: API Assert tests");
+ TCase *tc_assert = tcase_create("Creation/Destruction");
+
+ tcase_add_test_raise_signal(
+ tc_assert,
+ test_nslayout_layout_create_aborts1,
+ SIGABRT);
+ suite_add_tcase(s, tc_assert);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
new file mode 100644
index 0000000..84611a9
--- /dev/null
+++ b/test/basic-layout-tests.c
@@ -0,0 +1,78 @@
+/*
+ * 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 <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+int pw;
+
+static nslayout_error nslayout_test_callback(
+ nslayout_request *req,
+ nslayout_layout *layout,
+ void *pw)
+{
+ UNUSED(req);
+ UNUSED(layout);
+ UNUSED(pw);
+ return NSLAYOUT_OK;
+}
+
+START_TEST (test_nslayout_layout_create_ok)
+{
+ nslayout_layout *layout = NULL;
+ nslayout_error error;
+ dom_exception dom_error;
+ css_error css_err;
+ dom_document *doc;
+ css_select_ctx *css_ctx;
+ css_media_type media = CSS_MEDIA_SCREEN;
+
+ /* Create a DOM document */
+ dom_error = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
+ NULL, NULL, NULL, NULL, NULL, &doc);
+ ck_assert(dom_error == DOM_NO_ERR);
+
+ /* Create a selection context (with no sheets added) */
+ css_err = css_select_ctx_create(&css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ error = nslayout_layout_create(doc,
+ css_ctx,
+ &media,
+ nslayout_test_callback,
+ &pw,
+ &layout);
+ fail_unless(error == NSLAYOUT_OK,
+ "Unable to create layout");
+ fail_unless(layout != NULL,
+ "Returned OK but str was still NULL");
+
+ css_err = css_select_ctx_destroy(css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ dom_node_unref(doc);
+}
+END_TEST
+
+
+void nslayout_basic_layout_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: basic layout tests");
+ TCase *tc_layout_basic = tcase_create("Creation/Destruction");
+
+ tcase_add_test(tc_layout_basic,
+ test_nslayout_layout_create_ok);
+ suite_add_tcase(s, tc_layout_basic);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/tests.c b/test/tests.c
new file mode 100644
index 0000000..a58e038
--- /dev/null
+++ b/test/tests.c
@@ -0,0 +1,52 @@
+/*
+ * 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 <assert.h>
+#include <stdlib.h>
+
+#include <check.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) ((x) = (x))
+#endif
+
+#ifndef NDEBUG
+/* This means that assertion failures are silent in tests */
+void __assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function) {
+ (void)__assertion;
+ (void)__file;
+ (void)__line;
+ (void)__function;
+ abort();
+}
+#endif
+
+int main(int argc, char **argv)
+{
+ int number_failed = 0;
+ SRunner *sr;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ sr = srunner_create(suite_create("Test suite for libnslayout"));
+
+#ifndef NDEBUG
+ nslayout_assert_suite(sr);
+#endif
+ nslayout_basic_layout_suite(sr);
+
+ srunner_set_fork_status(sr, CK_FORK);
+ srunner_run_all(sr, CK_ENV);
+ number_failed = srunner_ntests_failed(sr);
+
+ srunner_free(sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/test/tests.h b/test/tests.h
new file mode 100644
index 0000000..4f7795f
--- /dev/null
+++ b/test/tests.h
@@ -0,0 +1,19 @@
+/*
+ * 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>
+ */
+
+#ifndef nslayout_tests_h_
+#define nslayout_tests_h_
+
+#include <signal.h>
+
+#include <check.h>
+
+#include <libnslayout/nslayout.h>
+
+extern void nslayout_assert_suite(SRunner *);
+extern void nslayout_basic_layout_suite(SRunner *);
+
+#endif
--
NetSurf Layout Engine
7 years, 10 months
netsurf: branch dsilvers/dukky updated. release/3.3-233-g8ec9e55
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/8ec9e559e00f7c2288fa7...
...commit http://git.netsurf-browser.org/netsurf.git/commit/8ec9e559e00f7c2288fa724...
...tree http://git.netsurf-browser.org/netsurf.git/tree/8ec9e559e00f7c2288fa72459...
The branch, dsilvers/dukky has been updated
via 8ec9e559e00f7c2288fa724591208e710690eff5 (commit)
from e4f46aceb3a3406d4f52d73f72a69e28578b7af4 (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=8ec9e559e00f7c2288f...
commit 8ec9e559e00f7c2288fa724591208e710690eff5
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Override toString for our prototypes
diff --git a/javascript/dukky.c b/javascript/dukky.c
index f5fae4e..9fd208f 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -87,9 +87,31 @@ duk_ret_t dukky_create_object(duk_context *ctx, const char *name, int args)
return DUK_EXEC_SUCCESS;
}
+static duk_ret_t
+dukky_to_string(duk_context *ctx)
+{
+ /* */
+ duk_push_this(ctx);
+ /* this */
+ duk_get_prototype(ctx, -1);
+ /* this proto */
+ duk_get_prop_string(ctx, -1, MAGIC(klass_name));
+ /* this proto classname */
+ duk_push_string(ctx, "[object ");
+ /* this proto classname str */
+ duk_insert(ctx, -2);
+ /* this proto str classname */
+ duk_push_string(ctx, "]");
+ /* this proto str classname str */
+ duk_concat(ctx, 3);
+ /* this proto str */
+ return 1;
+}
+
static duk_ret_t dukky_create_prototype(duk_context *ctx,
duk_safe_call_function genproto,
- const char *proto_name)
+ const char *proto_name,
+ const char *klass_name)
{
duk_int_t ret;
duk_push_object(ctx);
@@ -99,6 +121,12 @@ static duk_ret_t dukky_create_prototype(duk_context *ctx,
return ret;
}
/* top of stack is the ready prototype, inject it */
+ duk_push_string(ctx, klass_name);
+ duk_put_prop_string(ctx, -2, MAGIC(klass_name));
+ duk_push_c_function(ctx, dukky_to_string, 0);
+ duk_put_prop_string(ctx, -2, "toString");
+ duk_push_string(ctx, "toString");
+ duk_def_prop(ctx, -2, DUK_DEFPROP_HAVE_ENUMERABLE);
duk_put_global_string(ctx, proto_name);
return 0;
}
@@ -287,8 +315,8 @@ void js_finalise(void)
/* NADA for now */
}
-#define DUKKY_NEW_PROTOTYPE(klass) \
- dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(klass))
+#define DUKKY_NEW_PROTOTYPE(klass, klass_name) \
+ dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(klass), klass_name)
jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
{
@@ -304,16 +332,16 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
duk_put_prop_string(ctx, -2, "protos");
duk_put_global_string(ctx, PROTO_MAGIC);
/* Create prototypes here? */
- DUKKY_NEW_PROTOTYPE(event_target);
- DUKKY_NEW_PROTOTYPE(window);
- DUKKY_NEW_PROTOTYPE(node);
- DUKKY_NEW_PROTOTYPE(character_data);
- DUKKY_NEW_PROTOTYPE(text);
- DUKKY_NEW_PROTOTYPE(comment);
- DUKKY_NEW_PROTOTYPE(document);
- DUKKY_NEW_PROTOTYPE(element);
- DUKKY_NEW_PROTOTYPE(html_element);
- DUKKY_NEW_PROTOTYPE(html_unknown_element);
+ DUKKY_NEW_PROTOTYPE(event_target, "EventTarget");
+ DUKKY_NEW_PROTOTYPE(window, "Window");
+ DUKKY_NEW_PROTOTYPE(node, "Node");
+ DUKKY_NEW_PROTOTYPE(character_data, "CharacterData");
+ DUKKY_NEW_PROTOTYPE(text, "Text");
+ DUKKY_NEW_PROTOTYPE(comment, "Comment");
+ DUKKY_NEW_PROTOTYPE(document, "Document");
+ DUKKY_NEW_PROTOTYPE(element, "Element");
+ DUKKY_NEW_PROTOTYPE(html_element, "HTMLElement");
+ DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
return ret;
}
-----------------------------------------------------------------------
Summary of changes:
javascript/dukky.c | 54 +++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 41 insertions(+), 13 deletions(-)
diff --git a/javascript/dukky.c b/javascript/dukky.c
index f5fae4e..9fd208f 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -87,9 +87,31 @@ duk_ret_t dukky_create_object(duk_context *ctx, const char *name, int args)
return DUK_EXEC_SUCCESS;
}
+static duk_ret_t
+dukky_to_string(duk_context *ctx)
+{
+ /* */
+ duk_push_this(ctx);
+ /* this */
+ duk_get_prototype(ctx, -1);
+ /* this proto */
+ duk_get_prop_string(ctx, -1, MAGIC(klass_name));
+ /* this proto classname */
+ duk_push_string(ctx, "[object ");
+ /* this proto classname str */
+ duk_insert(ctx, -2);
+ /* this proto str classname */
+ duk_push_string(ctx, "]");
+ /* this proto str classname str */
+ duk_concat(ctx, 3);
+ /* this proto str */
+ return 1;
+}
+
static duk_ret_t dukky_create_prototype(duk_context *ctx,
duk_safe_call_function genproto,
- const char *proto_name)
+ const char *proto_name,
+ const char *klass_name)
{
duk_int_t ret;
duk_push_object(ctx);
@@ -99,6 +121,12 @@ static duk_ret_t dukky_create_prototype(duk_context *ctx,
return ret;
}
/* top of stack is the ready prototype, inject it */
+ duk_push_string(ctx, klass_name);
+ duk_put_prop_string(ctx, -2, MAGIC(klass_name));
+ duk_push_c_function(ctx, dukky_to_string, 0);
+ duk_put_prop_string(ctx, -2, "toString");
+ duk_push_string(ctx, "toString");
+ duk_def_prop(ctx, -2, DUK_DEFPROP_HAVE_ENUMERABLE);
duk_put_global_string(ctx, proto_name);
return 0;
}
@@ -287,8 +315,8 @@ void js_finalise(void)
/* NADA for now */
}
-#define DUKKY_NEW_PROTOTYPE(klass) \
- dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(klass))
+#define DUKKY_NEW_PROTOTYPE(klass, klass_name) \
+ dukky_create_prototype(ctx, dukky_##klass##___proto, PROTO_NAME(klass), klass_name)
jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
{
@@ -304,16 +332,16 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
duk_put_prop_string(ctx, -2, "protos");
duk_put_global_string(ctx, PROTO_MAGIC);
/* Create prototypes here? */
- DUKKY_NEW_PROTOTYPE(event_target);
- DUKKY_NEW_PROTOTYPE(window);
- DUKKY_NEW_PROTOTYPE(node);
- DUKKY_NEW_PROTOTYPE(character_data);
- DUKKY_NEW_PROTOTYPE(text);
- DUKKY_NEW_PROTOTYPE(comment);
- DUKKY_NEW_PROTOTYPE(document);
- DUKKY_NEW_PROTOTYPE(element);
- DUKKY_NEW_PROTOTYPE(html_element);
- DUKKY_NEW_PROTOTYPE(html_unknown_element);
+ DUKKY_NEW_PROTOTYPE(event_target, "EventTarget");
+ DUKKY_NEW_PROTOTYPE(window, "Window");
+ DUKKY_NEW_PROTOTYPE(node, "Node");
+ DUKKY_NEW_PROTOTYPE(character_data, "CharacterData");
+ DUKKY_NEW_PROTOTYPE(text, "Text");
+ DUKKY_NEW_PROTOTYPE(comment, "Comment");
+ DUKKY_NEW_PROTOTYPE(document, "Document");
+ DUKKY_NEW_PROTOTYPE(element, "Element");
+ DUKKY_NEW_PROTOTYPE(html_element, "HTMLElement");
+ DUKKY_NEW_PROTOTYPE(html_unknown_element, "HTMLUnknownElement");
return ret;
}
--
NetSurf Browser
7 years, 10 months
netsurf: branch dsilvers/dukky updated. release/3.3-232-ge4f46ac
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/e4f46aceb3a3406d4f52d...
...commit http://git.netsurf-browser.org/netsurf.git/commit/e4f46aceb3a3406d4f52d73...
...tree http://git.netsurf-browser.org/netsurf.git/tree/e4f46aceb3a3406d4f52d73f7...
The branch, dsilvers/dukky has been updated
via e4f46aceb3a3406d4f52d73f72a69e28578b7af4 (commit)
from 10c5dcd078700ff574512fc692adb6835653ba38 (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=e4f46aceb3a3406d4f5...
commit e4f46aceb3a3406d4f52d73f72a69e28578b7af4
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Support createElement
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index 701d2d4..b4f8cef 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -84,6 +84,36 @@ static DUKKY_FUNC(document, createTextNode)
return 1;
}
+static DUKKY_FUNC(document, createElement)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_node *newnode;
+ dom_exception err;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ dom_string *text_str;
+
+ err = dom_string_create((const uint8_t*)text, text_len, &text_str);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_document_create_element_ns(priv->parent.node,
+ corestring_dom_html_namespace,
+ text_str,
+ &newnode);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(text_str);
+ return 0; /* coerced to undefined */
+ }
+
+ dom_string_unref(text_str);
+
+ dukky_push_node(ctx, newnode);
+
+ dom_node_unref(newnode);
+
+ return 1;
+}
+
static DUKKY_GETTER(document, body)
{
DUKKY_GET_METHOD_PRIVATE(document);
@@ -118,6 +148,7 @@ DUKKY_FUNC(document, __proto)
/* Populate document's prototypical functionality */
DUKKY_ADD_METHOD(document, write, 1);
DUKKY_ADD_METHOD(document, createTextNode, 1);
+ DUKKY_ADD_METHOD(document, createElement, 1);
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 20036a5..1d20362 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -261,6 +261,7 @@ dom_string *corestring_dom_INPUT;
dom_string *corestring_dom_SELECT;
dom_string *corestring_dom_TEXTAREA;
dom_string *corestring_dom_BODY;
+dom_string *corestring_dom_html_namespace;
dom_string *corestring_dom_button;
dom_string *corestring_dom_image;
dom_string *corestring_dom_radio;
@@ -533,6 +534,8 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(SELECT);
CSS_DOM_STRING_UNREF(TEXTAREA);
CSS_DOM_STRING_UNREF(BODY);
+ /* DOM namespaces, not really CSS */
+ CSS_DOM_STRING_UNREF(html_namespace);
/* DOM input types, not really CSS */
CSS_DOM_STRING_UNREF(button);
CSS_DOM_STRING_UNREF(image);
@@ -882,11 +885,19 @@ nserror corestrings_init(void)
goto error;
}
+ exc = dom_string_create_interned((const uint8_t *) "http://www.w3.org/1999/xhtml",
+ SLEN("http://www.w3.org/1999/xhtml"),
+ &corestring_dom_html_namespace);
+ if ((exc != DOM_NO_ERR) || (corestring_dom_html_namespace == NULL)) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
error = nsurl_create("about:blank", &corestring_nsurl_about_blank);
if (error != NSERROR_OK) {
goto error;
}
-
+
return NSERROR_OK;
error:
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 2c3c448..415dece 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -273,6 +273,8 @@ extern struct dom_string *corestring_dom_INPUT;
extern struct dom_string *corestring_dom_SELECT;
extern struct dom_string *corestring_dom_TEXTAREA;
extern struct dom_string *corestring_dom_BODY;
+/* DOM namespaces */
+extern struct dom_string *corestring_dom_html_namespace;
/* DOM input node types */
extern struct dom_string *corestring_dom_button;
/* extern struct dom_string *corestring_dom_submit; */
-----------------------------------------------------------------------
Summary of changes:
javascript/duktape/document.c | 31 +++++++++++++++++++++++++++++++
utils/corestrings.c | 13 ++++++++++++-
utils/corestrings.h | 2 ++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index 701d2d4..b4f8cef 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -84,6 +84,36 @@ static DUKKY_FUNC(document, createTextNode)
return 1;
}
+static DUKKY_FUNC(document, createElement)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_node *newnode;
+ dom_exception err;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ dom_string *text_str;
+
+ err = dom_string_create((const uint8_t*)text, text_len, &text_str);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_document_create_element_ns(priv->parent.node,
+ corestring_dom_html_namespace,
+ text_str,
+ &newnode);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(text_str);
+ return 0; /* coerced to undefined */
+ }
+
+ dom_string_unref(text_str);
+
+ dukky_push_node(ctx, newnode);
+
+ dom_node_unref(newnode);
+
+ return 1;
+}
+
static DUKKY_GETTER(document, body)
{
DUKKY_GET_METHOD_PRIVATE(document);
@@ -118,6 +148,7 @@ DUKKY_FUNC(document, __proto)
/* Populate document's prototypical functionality */
DUKKY_ADD_METHOD(document, write, 1);
DUKKY_ADD_METHOD(document, createTextNode, 1);
+ DUKKY_ADD_METHOD(document, createElement, 1);
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 20036a5..1d20362 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -261,6 +261,7 @@ dom_string *corestring_dom_INPUT;
dom_string *corestring_dom_SELECT;
dom_string *corestring_dom_TEXTAREA;
dom_string *corestring_dom_BODY;
+dom_string *corestring_dom_html_namespace;
dom_string *corestring_dom_button;
dom_string *corestring_dom_image;
dom_string *corestring_dom_radio;
@@ -533,6 +534,8 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(SELECT);
CSS_DOM_STRING_UNREF(TEXTAREA);
CSS_DOM_STRING_UNREF(BODY);
+ /* DOM namespaces, not really CSS */
+ CSS_DOM_STRING_UNREF(html_namespace);
/* DOM input types, not really CSS */
CSS_DOM_STRING_UNREF(button);
CSS_DOM_STRING_UNREF(image);
@@ -882,11 +885,19 @@ nserror corestrings_init(void)
goto error;
}
+ exc = dom_string_create_interned((const uint8_t *) "http://www.w3.org/1999/xhtml",
+ SLEN("http://www.w3.org/1999/xhtml"),
+ &corestring_dom_html_namespace);
+ if ((exc != DOM_NO_ERR) || (corestring_dom_html_namespace == NULL)) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
error = nsurl_create("about:blank", &corestring_nsurl_about_blank);
if (error != NSERROR_OK) {
goto error;
}
-
+
return NSERROR_OK;
error:
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 2c3c448..415dece 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -273,6 +273,8 @@ extern struct dom_string *corestring_dom_INPUT;
extern struct dom_string *corestring_dom_SELECT;
extern struct dom_string *corestring_dom_TEXTAREA;
extern struct dom_string *corestring_dom_BODY;
+/* DOM namespaces */
+extern struct dom_string *corestring_dom_html_namespace;
/* DOM input node types */
extern struct dom_string *corestring_dom_button;
/* extern struct dom_string *corestring_dom_submit; */
--
NetSurf Browser
7 years, 10 months