diff --git a/meson.build b/meson.build index ee939f0b..7faa249e 100644 --- a/meson.build +++ b/meson.build @@ -44,7 +44,7 @@ conf_data.set('CONFIG_TRUE_COLOR', get_option('true-color')) conf_data.set('CONFIG_EXMODE', get_option('exmode')) conf_data.set('CONFIG_LEDS', get_option('leds')) conf_data.set('CONFIG_MARKS', get_option('marks')) -conf_data.set10('CONFIG_CSS', get_option('css')) +conf_data.set('CONFIG_CSS', get_option('css')) conf_data.set('CONFIG_DOM', get_option('html-highlight')) conf_data.set('CONFIG_BACKTRACE', get_option('backtrace')) @@ -112,7 +112,6 @@ conf_data.set('CONFIG_SCRIPTING', true) #CONFIG_SCRIPTING_SPIDERMONKEY', false) #CONFIG_LEDS', true) #CONFIG_EXMODE', false) -#CONFIG_CSS', true) #CONFIG_BROTLI', true) #CONFIG_BZIP2', true) #CONFIG_GZIP', true) diff --git a/src/document/document.c b/src/document/document.c index 023ace88..84c9403a 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -300,7 +300,7 @@ find_tag(struct document *document, char *name, int namelen) /* ECMAScript doesn't like anything like CSS since it doesn't modify the * formatted document (yet). */ -#if CONFIG_CSS +#ifdef CONFIG_CSS unsigned long get_document_css_magic(struct document *document) { diff --git a/src/document/meson.build b/src/document/meson.build index ad949ad2..8873aa5f 100644 --- a/src/document/meson.build +++ b/src/document/meson.build @@ -1,4 +1,4 @@ -if conf_data.get('CONFIG_CSS') == 1 +if conf_data.get('CONFIG_CSS') subdir('css') endif if conf_data.get('CONFIG_DOM') diff --git a/src/document/renderer.c b/src/document/renderer.c index df5d89e4..c489b878 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -26,6 +26,7 @@ #include "document/renderer.h" #include "document/view.h" #include "ecmascript/ecmascript.h" +#include "ecmascript/spidermonkey/document.h" #include "encoding/encoding.h" #include "intl/charsets.h" #include "main/main.h" @@ -282,8 +283,7 @@ render_encoded_document(struct cache_entry *cached, struct document *document) else #endif #ifdef CONFIG_XML - if (document->dom) - render_xhtml_document(cached, document, &buffer); + if (true) render_xhtml_document(cached, document, NULL); else #endif render_html_document(cached, document, &buffer); diff --git a/src/document/xml/renderer2.c b/src/document/xml/renderer2.c index a17066bc..074fd9de 100644 --- a/src/document/xml/renderer2.c +++ b/src/document/xml/renderer2.c @@ -24,6 +24,7 @@ #include "document/renderer.h" #include "document/xml/renderer2.h" #include "document/xml/tags.h" +#include "ecmascript/spidermonkey/document.h" #include "globhist/globhist.h" #include "intl/charsets.h" #include "protocol/protocol.h" @@ -61,38 +62,9 @@ dump_text(struct source_renderer *renderer, unsigned char *html, int length) int noupdate = 0; main_loop: - if (!html_is_preformatted()) { - unsigned char *buffer = fmem_alloc(length+1); - unsigned char *dst; - html_context->part = renderer->part; - html_context->eoff = eof; - - if (!buffer) { - return; - } - dst = buffer; - *dst = *html; - - for (html++; html <= eof; html++) { - if (isspace(*html)) { - if (*dst != ' ') { - *(++dst) = ' '; - } - } else { - *(++dst) = *html; - } - } - - if (dst - buffer > 1) { - if (*buffer == ' ') { - html_context->putsp = HTML_SPACE_ADD; - } - } - put_chrs(html_context, buffer, dst - buffer); - fmem_free(buffer); - } - while (html < eof) { + char *name, *attr, *end; + int namelen, endingtag; int dotcounter = 0; if (!noupdate) { @@ -102,27 +74,60 @@ main_loop: } else { noupdate = 0; } + + if (isspace(*html) && !html_is_preformatted()) { + char *h = html; + + while (h < eof && isspace(*h)) + h++; + if (h + 1 < eof && h[0] == '<' && h[1] == '/') { + if (!parse_element(h, eof, &name, &namelen, &attr, &end)) { + put_chrs(html_context, base_pos, html - base_pos); + base_pos = html = h; + html_context->putsp = HTML_SPACE_ADD; + goto element; + } + } + html++; + if (!(html_context->position + (html - base_pos - 1))) + goto skip_w; /* ??? */ + if (*(html - 1) == ' ') { /* Do not replace with isspace() ! --Zas */ + /* BIG performance win; not sure if it doesn't cause any bug */ + if (html < eof && !isspace(*html)) { + noupdate = 1; + continue; + } + put_chrs(html_context, base_pos, html - base_pos); + } else { + put_chrs(html_context, base_pos, html - base_pos - 1); + put_chrs(html_context, " ", 1); + } + +skip_w: + while (html < eof && isspace(*html)) + html++; + continue; + } + if (html_is_preformatted()) { html_context->putsp = HTML_SPACE_NORMAL; if (*html == ASCII_TAB) { put_chrs(html_context, base_pos, html - base_pos); put_chrs(html_context, " ", - 8 - (html_context->position % 8)); + 8 - (html_context->position % 8)); html++; continue; } else if (*html == ASCII_CR || *html == ASCII_LF) { put_chrs(html_context, base_pos, html - base_pos); - if (html - base_pos == 0 && html_context->line_breax > 0) { + if (html - base_pos == 0 && html_context->line_breax > 0) html_context->line_breax--; - } next_break: - if (*html == ASCII_CR && html < eof - 1 && html[1] == ASCII_LF) { + if (*html == ASCII_CR && html < eof - 1 + && html[1] == ASCII_LF) html++; - } ln_break(html_context, 1); html++; - if (*html == ASCII_CR || *html == ASCII_LF) { html_context->line_breax = 0; goto next_break; @@ -140,7 +145,7 @@ next_break: int length = html - base_pos; int newlines; - html = (unsigned char *) count_newline_entities(html, eof, &newlines); + html = (char *) count_newline_entities(html, eof, &newlines); if (newlines) { put_chrs(html_context, base_pos, length); ln_break(html_context, newlines); @@ -149,15 +154,14 @@ next_break: } } - while (*html < ' ') { - if (html - base_pos) { + while ((unsigned char)*html < ' ') { + if (html - base_pos) put_chrs(html_context, base_pos, html - base_pos); - } dotcounter++; base_pos = ++html; if (*html >= ' ' || isspace(*html) || html >= eof) { - unsigned char *dots = fmem_alloc(dotcounter); + char *dots = fmem_alloc(dotcounter); if (dots) { memset(dots, '.', dotcounter); @@ -167,7 +171,49 @@ next_break: goto main_loop; } } + + if (html + 2 <= eof && html[0] == '<' && (html[1] == '!' || html[1] == '?') + && !(html_context->was_xmp || html_context->was_style)) { + put_chrs(html_context, base_pos, html - base_pos); + html = skip_comment(html, eof); + continue; + } + + if (*html != '<' || parse_element(html, eof, &name, &namelen, &attr, &end)) { + html++; + noupdate = 1; + continue; + } + +element: + endingtag = *name == '/'; name += endingtag; namelen -= endingtag; + if (!endingtag && html_context->putsp == HTML_SPACE_ADD && !html_top->invisible) + put_chrs(html_context, " ", 1); + put_chrs(html_context, base_pos, html - base_pos); + if (!html_is_preformatted() && !endingtag && html_context->putsp == HTML_SPACE_NORMAL) { + char *ee = end; + char *nm; + +/// while (!parse_element(ee, eof, &nm, NULL, NULL, &ee)) +/// if (*nm == '/') +/// goto ng; + if (ee < eof && isspace(*ee)) { + put_chrs(html_context, " ", 1); + } + } +//ng: +// html = process_element(name, namelen, endingtag, end, html, eof, attr, html_context); } + + if (noupdate) put_chrs(html_context, base_pos, html - base_pos); + ln_break(html_context, 1); + /* Restore the part in case the html_context was trashed in the last + * iteration so that when destroying the stack in the caller we still + * get the right part pointer. */ + html_context->part = renderer->part; + html_context->putsp = HTML_SPACE_SUPPRESS; + html_context->position = 0; + html_context->was_br = 0; } #define HTML_MAX_DOM_STRUCTURE_DEPTH 1024 @@ -218,10 +264,24 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str { struct html_context *html_context; struct part *part = NULL; + + part = mem_calloc(1, sizeof(*part)); + if (!part) { + return; + } + + part->document = document; + part->box.x = 0; + part->box.y = 0; + part->cx = -1; + part->cy = 0; + part->link_num = 0; + char *start; char *end; struct string title; struct string head; + struct string tt; struct source_renderer renderer; @@ -232,6 +292,17 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str if (cached->head) add_to_string(&head, cached->head); + if (!document->dom) { + document->dom = document_parse(document); + } + xmlpp::Document *doc = document->dom; + + if (!buffer) { + std::string text = doc->write_to_string_formatted(); + init_string(&tt); + add_bytes_to_string(&tt, text.c_str(), text.size()); + buffer = &tt; + } start = buffer->source; end = buffer->source + buffer->length; @@ -274,7 +345,6 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str } done_string(&title); - xmlpp::Document *doc = document->dom; xmlpp::Element *root = doc->get_root_node(); renderer.html_context = html_context; diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c index fd8def11..a6d28c15 100644 --- a/src/ecmascript/spidermonkey.c +++ b/src/ecmascript/spidermonkey.c @@ -21,6 +21,7 @@ #include "dialogs/status.h" #include "document/html/frames.h" #include "document/xml/renderer.h" +#include "document/xml/renderer2.h" #include "document/document.h" #include "document/forms.h" #include "document/renderer.h" @@ -444,7 +445,7 @@ delayed_reload(void *data) struct delayed_rel *rel = data; assert(rel); - render_source_document_cxx(rel->cached, rel->document, NULL); + render_xhtml_document(rel->cached, rel->document, NULL); mem_free(rel); } diff --git a/src/util/Makefile b/src/util/Makefile index c0fa9dfb..96a55d46 100644 --- a/src/util/Makefile +++ b/src/util/Makefile @@ -16,6 +16,7 @@ OBJS-unless$(CONFIG_OPENSSL) += md5.o endif ifeq ($(CONFIG_BITTORRENT),yes) +OBJS-$(CONFIG_BITTORRENT) += scanner.o # BitTorrent is the only user. Compile in SHA1 if testing libc or # there is no OpenSSL. The GNUTLS OpenSSL wrappers doesn't have it. OBJS-$(CONFIG_OWN_LIBC) += sha1.o diff --git a/src/util/meson.build b/src/util/meson.build index a270aa83..8c619ba9 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -3,7 +3,7 @@ if not conf_data.get('CONFIG_SMALL') srcs += files('fastfind.c') endif -if conf_data.get('CONFIG_CSS') == 1 +if conf_data.get('CONFIG_CSS') or conf_data.get('CONFIG_BITTORRENT') srcs += files('scanner.c') endif if conf_data.get('CONFIG_DEBUG')