1
0
Fork 0

[libdom] Possibility to build libcss code without ecmascript.

meson config option libcss enabled by default.
To enable libcss in elinks:
set document.css.libcss = 1
This commit is contained in:
Witold Filipczyk 2023-05-15 19:13:38 +02:00
parent 6c06b2f3de
commit 9a6edd69db
20 changed files with 143 additions and 81 deletions

View File

@ -412,6 +412,7 @@ if conf_data.get('CONFIG_ECMASCRIPT_SMJS') or conf_data.get('CONFIG_QUICKJS') or
endif
conf_data.set('CONFIG_LIBCSS', false)
cssdeps = false
if conf_data.get('CONFIG_ECMASCRIPT_SMJS') or conf_data.get('CONFIG_QUICKJS') or conf_data.get('CONFIG_MUJS')
cssdeps = dependency('libcss', static: st, version: '>=0.9.1')
@ -420,13 +421,25 @@ if conf_data.get('CONFIG_ECMASCRIPT_SMJS') or conf_data.get('CONFIG_QUICKJS') or
endif
conf_data.set('CONFIG_LIBDOM', false)
libdomdeps = false
if conf_data.get('CONFIG_ECMASCRIPT_SMJS') or conf_data.get('CONFIG_QUICKJS') or conf_data.get('CONFIG_MUJS')
cssdeps = dependency('libdom', static: st, version: '>=0.4.1')
deps += cssdeps
libdomdeps = dependency('libdom', static: st, version: '>=0.4.1')
deps += libdomdeps
conf_data.set('CONFIG_LIBDOM', true)
endif
if not cssdeps and get_option('libcss')
cssdeps = dependency('libcss', static: st, version: '>=0.9.1')
deps += cssdeps
conf_data.set('CONFIG_LIBCSS', true)
if not libdomdeps
libdomdeps = dependency('libdom', static: st, version: '>=0.4.1')
deps += libdomdeps
conf_data.set('CONFIG_LIBDOM', true)
endif
endif
if conf_data.get('CONFIG_SCRIPTING_LUA')
luadeps = dependency(luapkg, static: st)
deps += luadeps

View File

@ -76,3 +76,4 @@ option('docdir', type: 'string', value: '', description: 'Documentation installa
option('apidoc', type: 'boolean', value: true, description: 'whether to generate API docs with doxygen')
option('htmldoc', type: 'boolean', value: true, description: 'whether to build html docs')
option('pdfdoc', type: 'boolean', value: true, description: 'whether to build manual.pdf')
option('libcss', type: 'boolean', value: true, description: 'whether to compile libcss support, requires libdom. This option is automatically enabled with js support')

View File

@ -69,6 +69,7 @@
#endif
#ifdef CONFIG_LIBDOM
#include "document/libdom/doc.h"
#include "document/libdom/mapa.h"
#endif
@ -379,7 +380,9 @@ done_document(struct document *document)
}
}
free_list(document->timeouts);
#endif
#ifdef CONFIG_LIBDOM
mem_free_if(document->text);
free_document(document->dom);
@ -390,7 +393,6 @@ done_document(struct document *document)
delete_map(mapa);
}
#endif
free_list(document->tags);
free_list(document->nodes);

View File

@ -220,11 +220,14 @@ struct document {
/** used by setTimeout */
LIST_OF(struct ecmascript_timeout) timeouts;
int ecmascript_counter;
#endif
#ifdef CONFIG_LIBDOM
void *dom;
void *element_map;
char *text;
void *forms_nodeset;
#endif
#ifdef CONFIG_CSS
/** @todo FIXME: We should externally maybe using cache_entry store the
* dependencies between the various entries so nothing gets removed

View File

@ -1,6 +1,6 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
OBJS = corestrings.o css.o mapa.obj renderer.o renderer2.o
OBJS = corestrings.o css.o doc.o mapa.obj renderer.o renderer2.o
include $(top_srcdir)/Makefile.lib

91
src/document/libdom/doc.c Normal file
View File

@ -0,0 +1,91 @@
/* Parse document. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef CONFIG_LIBDOM
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
#endif
#include "elinks.h"
#include "cache/cache.h"
#include "document/document.h"
#include "document/libdom/doc.h"
#include "util/string.h"
void *
document_parse_text(char *data, size_t length)
{
dom_hubbub_parser *parser = NULL;
dom_hubbub_error error;
dom_hubbub_parser_params params;
dom_document *doc;
params.enc = NULL;
params.fix_enc = true;
params.enable_script = false;
params.msg = NULL;
params.script = NULL;
params.ctx = NULL;
params.daf = NULL;
/* Create Hubbub parser */
error = dom_hubbub_parser_create(&params, &parser, &doc);
if (error != DOM_HUBBUB_OK) {
fprintf(stderr, "Can't create Hubbub Parser\n");
return NULL;
}
/* Parse */
error = dom_hubbub_parser_parse_chunk(parser, (const uint8_t *)data, length);
if (error != DOM_HUBBUB_OK) {
dom_hubbub_parser_destroy(parser);
fprintf(stderr, "Parsing errors occur\n");
return NULL;
}
/* Done parsing file */
error = dom_hubbub_parser_completed(parser);
if (error != DOM_HUBBUB_OK) {
dom_hubbub_parser_destroy(parser);
fprintf(stderr, "Parsing error when construct DOM\n");
return NULL;
}
/* Finished with parser */
dom_hubbub_parser_destroy(parser);
return doc;
}
void *
document_parse(struct document *document)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct cache_entry *cached = document->cached;
struct fragment *f = get_cache_fragment(cached);
if (!f || !f->length) {
return NULL;
}
return document_parse_text(f->data, f->length);
}
void
free_document(void *doc)
{
if (!doc) {
return;
}
dom_node *ddd = (dom_node *)doc;
dom_node_unref(ddd);
}

19
src/document/libdom/doc.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef EL__DOCUMENT_LIBDOM_DOC_H
#define EL__DOCUMENT_LIBDOM_DOC_H
#ifdef __cplusplus
extern "C" {
#endif
struct document;
struct string;
void *document_parse_text(char *data, size_t length);
void *document_parse(struct document *document);
void free_document(void *doc);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1 +1 @@
srcs += files('corestrings.c', 'css.c', 'mapa.cpp', 'renderer.c', 'renderer2.c')
srcs += files('corestrings.c', 'css.c', 'doc.c', 'mapa.cpp', 'renderer.c', 'renderer2.c')

View File

@ -13,12 +13,12 @@
#include "cache/cache.h"
#include "document/document.h"
#include "document/renderer.h"
#include "document/libdom/doc.h"
#include "document/libdom/mapa.h"
#include "document/libdom/renderer.h"
#include "document/plain/renderer.h"
#include "ecmascript/libdom/parse.h"
static bool
dump_dom_element_closing(struct string *buf, dom_node *node)
{

View File

@ -15,6 +15,7 @@
#include "document/renderer.h"
#include "document/html/renderer.h"
#include "document/libdom/corestrings.h"
#include "document/libdom/doc.h"
#include "document/libdom/mapa.h"
#include "document/libdom/renderer2.h"
#include "ecmascript/libdom/parse.h"

View File

@ -293,7 +293,7 @@ render_encoded_document(struct cache_entry *cached, struct document *document)
&& (!c_strlcasecmp("text/gemini", 11, cached->content_type, -1)))
render_gemini_document(cached, document, &buffer);
else
#if defined(CONFIG_LIBDOM) && defined(CONFIG_ECMASCRIPT)
#ifdef CONFIG_LIBDOM
if (1) {
if (encoding != ENCODING_NONE) {
done_string(&buffer);

View File

@ -196,7 +196,6 @@ void check_for_rerender(struct ecmascript_interpreter *interpreter, const char*
void toggle_ecmascript(struct session *ses);
void free_document(void *doc);
void location_goto(struct document_view *doc_view, char *url);
void location_goto_const(struct document_view *doc_view, const char *url);

View File

@ -25,6 +25,7 @@
#include "document/html/frames.h"
#include "document/document.h"
#include "document/forms.h"
#include "document/libdom/doc.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/mujs/mapa.h"

View File

@ -10,6 +10,7 @@
#include "elinks.h"
#include "document/libdom/doc.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/parse.h"
#include "ecmascript/mujs.h"

View File

@ -18,77 +18,6 @@
#include "document/document.h"
#include "util/string.h"
void *
document_parse_text(char *data, size_t length)
{
dom_hubbub_parser *parser = NULL;
dom_hubbub_error error;
dom_hubbub_parser_params params;
dom_document *doc;
params.enc = NULL;
params.fix_enc = true;
params.enable_script = false;
params.msg = NULL;
params.script = NULL;
params.ctx = NULL;
params.daf = NULL;
/* Create Hubbub parser */
error = dom_hubbub_parser_create(&params, &parser, &doc);
if (error != DOM_HUBBUB_OK) {
fprintf(stderr, "Can't create Hubbub Parser\n");
return NULL;
}
/* Parse */
error = dom_hubbub_parser_parse_chunk(parser, (const uint8_t *)data, length);
if (error != DOM_HUBBUB_OK) {
dom_hubbub_parser_destroy(parser);
fprintf(stderr, "Parsing errors occur\n");
return NULL;
}
/* Done parsing file */
error = dom_hubbub_parser_completed(parser);
if (error != DOM_HUBBUB_OK) {
dom_hubbub_parser_destroy(parser);
fprintf(stderr, "Parsing error when construct DOM\n");
return NULL;
}
/* Finished with parser */
dom_hubbub_parser_destroy(parser);
return doc;
}
void *
document_parse(struct document *document)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct cache_entry *cached = document->cached;
struct fragment *f = get_cache_fragment(cached);
if (!f || !f->length) {
return NULL;
}
return document_parse_text(f->data, f->length);
}
void
free_document(void *doc)
{
if (!doc) {
return;
}
dom_node *ddd = (dom_node *)doc;
dom_node_unref(ddd);
}
void
el_insert_before(struct document *document, void *element, struct string *source)
{

View File

@ -8,8 +8,6 @@ extern "C" {
struct document;
struct string;
void *document_parse_text(char *data, size_t length);
void *document_parse(struct document *document);
void el_insert_before(struct document *document, void *element, struct string *source);
#ifdef __cplusplus

View File

@ -18,6 +18,7 @@
#include "cookies/cookies.h"
#include "dialogs/status.h"
#include "document/document.h"
#include "document/libdom/doc.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/parse.h"

View File

@ -15,6 +15,7 @@
#include "elinks.h"
#include "document/libdom/doc.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/parse.h"
#include "ecmascript/quickjs.h"

View File

@ -24,6 +24,7 @@
#include "document/html/frames.h"
#include "document/document.h"
#include "document/forms.h"
#include "document/libdom/doc.h"
#include "document/view.h"
#include "ecmascript/css2xpath.h"
#include "ecmascript/ecmascript.h"

View File

@ -10,6 +10,7 @@
#include "elinks.h"
#include "document/libdom/doc.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/parse.h"
#include "ecmascript/spidermonkey/document.h"