1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

Merge with git+ssh://pasky/srv/git/elinks.git

This commit is contained in:
Jonas Fonseca 2005-10-20 20:20:21 +02:00 committed by Jonas Fonseca
commit c4c034804b
3 changed files with 97 additions and 88 deletions

View File

@ -1066,7 +1066,7 @@ EL_ARG_DEPEND(CONFIG_SYSMOUSE, sysmouse,
[ --disable-sysmouse disable BSD sysmouse support]) [ --disable-sysmouse disable BSD sysmouse support])
EL_ARG_ENABLE(CONFIG_88_COLORS, 88-colors, [88 colors], EL_ARG_ENABLE(CONFIG_88_COLORS, 88-colors, [88 colors],
[ --enable-88-colors enable 88 color support]) [ --enable-88-colors enable 88 color support])
EL_ARG_ENABLE(CONFIG_256_COLORS, 256-colors, [256 colors], EL_ARG_ENABLE(CONFIG_256_COLORS, 256-colors, [256 colors],
[ --enable-256-colors enable 256 color support]) [ --enable-256-colors enable 256 color support])

View File

@ -90,11 +90,11 @@ struct table_cache_entry {
#define MAX_TABLE_CACHE_ENTRIES 16384 #define MAX_TABLE_CACHE_ENTRIES 16384
/* Global variables */ /* Global variables */
static int table_cache_entries;
static struct hash *table_cache;
struct renderer_context { struct renderer_context {
int table_cache_entries;
struct hash *table_cache;
int last_link_to_move; int last_link_to_move;
struct tag *last_tag_to_move; struct tag *last_tag_to_move;
/* All tags between document->tags and this tag (inclusive) should /* All tags between document->tags and this tag (inclusive) should
@ -137,11 +137,21 @@ void put_chars(struct html_context *, unsigned char *, int);
#define ALIGN_SPACES(x, o, n) mem_align_alloc(x, o, n, unsigned char, SPACES_GRANULARITY) #define ALIGN_SPACES(x, o, n) mem_align_alloc(x, o, n, unsigned char, SPACES_GRANULARITY)
static inline void
set_screen_char_color(struct screen_char *schar,
color_T bgcolor, color_T fgcolor,
enum color_flags color_flags,
enum color_mode color_mode)
{
struct color_pair colors = INIT_COLOR_PAIR(bgcolor, fgcolor);
set_term_color(schar, &colors, color_flags, color_mode);
}
static int static int
realloc_line(struct html_context *html_context, struct document *document, realloc_line(struct html_context *html_context, struct document *document,
int y, int length) int y, int length)
{ {
struct color_pair colors = INIT_COLOR_PAIR(par_format.bgcolor, 0x0);
struct screen_char *pos, *end; struct screen_char *pos, *end;
struct line *line; struct line *line;
@ -162,7 +172,8 @@ realloc_line(struct html_context *html_context, struct document *document,
end = &line->chars[length]; end = &line->chars[length];
end->data = ' '; end->data = ' ';
end->attr = 0; end->attr = 0;
set_term_color(end, &colors, 0, document->options.color_mode); set_screen_char_color(end, par_format.bgcolor, 0x0,
0, document->options.color_mode);
for (pos = &line->chars[line->length]; pos < end; pos++) { for (pos = &line->chars[line->length]; pos < end; pos++) {
copy_screen_chars(pos, end, 1); copy_screen_chars(pos, end, 1);
@ -219,7 +230,6 @@ static inline void
clear_hchars(struct html_context *html_context, int x, int y, int width) clear_hchars(struct html_context *html_context, int x, int y, int width)
{ {
struct part *part; struct part *part;
struct color_pair colors = INIT_COLOR_PAIR(par_format.bgcolor, 0x0);
struct screen_char *pos, *end; struct screen_char *pos, *end;
assert(html_context); assert(html_context);
@ -240,7 +250,8 @@ clear_hchars(struct html_context *html_context, int x, int y, int width)
end = pos + width - 1; end = pos + width - 1;
end->data = ' '; end->data = ' ';
end->attr = 0; end->attr = 0;
set_term_color(end, &colors, 0, part->document->options.color_mode); set_screen_char_color(end, par_format.bgcolor, 0x0,
0, part->document->options.color_mode);
while (pos < end) while (pos < end)
copy_screen_chars(pos++, end, 1); copy_screen_chars(pos++, end, 1);
@ -254,10 +265,7 @@ get_frame_char(struct html_context *html_context, struct part *part,
int x, int y, unsigned char data, int x, int y, unsigned char data,
color_T bgcolor, color_T fgcolor) color_T bgcolor, color_T fgcolor)
{ {
struct color_pair colors = INIT_COLOR_PAIR(bgcolor, fgcolor);
struct screen_char *template; struct screen_char *template;
static enum color_flags color_flags;
static enum color_mode color_mode;
assert(html_context); assert(html_context);
if_assert_failed return NULL; if_assert_failed return NULL;
@ -274,11 +282,9 @@ get_frame_char(struct html_context *html_context, struct part *part,
template = &POS(x, y); template = &POS(x, y);
template->data = data; template->data = data;
template->attr = SCREEN_ATTR_FRAME; template->attr = SCREEN_ATTR_FRAME;
set_screen_char_color(template, bgcolor, fgcolor,
color_mode = part->document->options.color_mode; part->document->options.color_flags,
color_flags = part->document->options.color_flags; part->document->options.color_mode);
set_term_color(template, &colors, color_flags, color_mode);
return template; return template;
} }
@ -356,15 +362,10 @@ get_format_screen_char(struct html_context *html_context,
schar_cache.attr |= SCREEN_ATTR_UNDERLINE; schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
} }
{ set_screen_char_color(&schar_cache, format.style.bg, format.style.fg,
struct color_pair colors = INIT_COLOR_PAIR(format.style.bg, html_context->options->color_flags,
format.style.fg); html_context->options->color_mode);
set_term_color(&schar_cache, &colors,
html_context->options->color_flags,
html_context->options->color_mode);
}
if (html_context->options->display_subs) { if (html_context->options->display_subs) {
if (format.style.attr & AT_SUBSCRIPT) { if (format.style.attr & AT_SUBSCRIPT) {
if (format.style.attr & AT_UPDATE_SUB) { if (format.style.attr & AT_UPDATE_SUB) {
@ -614,14 +615,14 @@ shift_chars(struct html_context *html_context, int y, int shift)
len = LEN(y); len = LEN(y);
a = mem_alloc(len * sizeof(*a)); a = fmem_alloc(len * sizeof(*a));
if (!a) return; if (!a) return;
copy_screen_chars(a, &POS(0, y), len); copy_screen_chars(a, &POS(0, y), len);
clear_hchars(html_context, 0, y, shift); clear_hchars(html_context, 0, y, shift);
copy_chars(html_context, shift, y, len, a); copy_chars(html_context, shift, y, len, a);
mem_free(a); fmem_free(a);
move_links(html_context, 0, y, shift, y); move_links(html_context, 0, y, shift, y);
} }
@ -915,6 +916,38 @@ align_line(struct html_context *html_context, int y, int last)
shift_chars(html_context, y, shift); shift_chars(html_context, y, shift);
} }
static inline void
init_link_event_hooks(struct html_context *html_context, struct link *link)
{
link->event_hooks = mem_calloc(1, sizeof(*link->event_hooks));
if (!link->event_hooks) return;
#define add_evhook(list_, type_, src_) \
do { \
struct script_event_hook *evhook; \
\
if (!src_) break; \
\
evhook = mem_calloc(1, sizeof(*evhook)); \
if (!evhook) break; \
\
evhook->type = type_; \
evhook->src = stracpy(src_); \
add_to_list(*(list_), evhook); \
} while (0)
init_list(*link->event_hooks);
add_evhook(link->event_hooks, SEVHOOK_ONCLICK, format.onclick);
add_evhook(link->event_hooks, SEVHOOK_ONDBLCLICK, format.ondblclick);
add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOVER, format.onmouseover);
add_evhook(link->event_hooks, SEVHOOK_ONHOVER, format.onhover);
add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, format.onfocus);
add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, format.onmouseout);
add_evhook(link->event_hooks, SEVHOOK_ONBLUR, format.onblur);
#undef add_evhook
}
static struct link * static struct link *
new_link(struct html_context *html_context, unsigned char *name, int namelen) new_link(struct html_context *html_context, unsigned char *name, int namelen)
{ {
@ -1008,28 +1041,7 @@ new_link(struct html_context *html_context, unsigned char *name, int namelen)
link->color.foreground = link_is_textinput(link) link->color.foreground = link_is_textinput(link)
? format.style.fg : format.clink; ? format.style.fg : format.clink;
link->event_hooks = mem_calloc(1, sizeof(*link->event_hooks)); init_link_event_hooks(html_context, link);
if (link->event_hooks) {
init_list(*link->event_hooks);
#define add_evhook(list_, type_, src_) \
do { \
struct script_event_hook *evhook = mem_calloc(1, sizeof(*evhook)); \
\
if (evhook) { \
evhook->type = type_; \
evhook->src = stracpy(src_); \
add_to_list(*list_, evhook); \
} \
} while (0)
if (format.onclick) add_evhook(link->event_hooks, SEVHOOK_ONCLICK, format.onclick);
if (format.ondblclick) add_evhook(link->event_hooks, SEVHOOK_ONDBLCLICK, format.ondblclick);
if (format.onmouseover) add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOVER, format.onmouseover);
if (format.onhover) add_evhook(link->event_hooks, SEVHOOK_ONHOVER, format.onhover);
if (format.onfocus) add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, format.onfocus);
if (format.onmouseout) add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, format.onmouseout);
if (format.onblur) add_evhook(link->event_hooks, SEVHOOK_ONBLUR, format.onblur);
#undef add_evhook
}
return link; return link;
} }
@ -1046,14 +1058,14 @@ html_special_tag(struct document *document, unsigned char *t, int x, int y)
tag_len = strlen(t); tag_len = strlen(t);
/* One byte is reserved for name in struct tag. */ /* One byte is reserved for name in struct tag. */
tag = mem_alloc(sizeof(*tag) + tag_len); tag = mem_alloc(sizeof(*tag) + tag_len);
if (tag) { if (!tag) return;
tag->x = x;
tag->y = y; tag->x = x;
memcpy(tag->name, t, tag_len + 1); tag->y = y;
add_to_list(document->tags, tag); memcpy(tag->name, t, tag_len + 1);
if ((void *) renderer_context.last_tag_for_newline == &document->tags) add_to_list(document->tags, tag);
renderer_context.last_tag_for_newline = tag; if (renderer_context.last_tag_for_newline == (struct tag *) &document->tags)
} renderer_context.last_tag_for_newline = tag;
} }
@ -1309,7 +1321,7 @@ put_chars(struct html_context *html_context, unsigned char *chars, int charslen)
* non-whitespace content. */ * non-whitespace content. */
if (html_is_preformatted() if (html_is_preformatted()
|| html_has_non_space_chars(chars, charslen)) { || html_has_non_space_chars(chars, charslen)) {
renderer_context.last_tag_for_newline = (void *) &part->document->tags; renderer_context.last_tag_for_newline = (struct tag *) &part->document->tags;
} }
int_lower_bound(&part->box.height, part->cy + 1); int_lower_bound(&part->box.height, part->cy + 1);
@ -1417,7 +1429,7 @@ line_break(struct html_context *html_context)
if (part->cx > 0) align_line(html_context, part->cy, 1); if (part->cx > 0) align_line(html_context, part->cy, 1);
for (tag = renderer_context.last_tag_for_newline; for (tag = renderer_context.last_tag_for_newline;
tag && (void *) tag != &part->document->tags; tag && tag != (struct tag *) &part->document->tags;
tag = tag->prev) { tag = tag->prev) {
tag->x = X(0); tag->x = X(0);
tag->y = Y(part->cy + 1); tag->y = Y(part->cy + 1);
@ -1738,20 +1750,20 @@ html_special(struct html_context *html_context, enum html_special_type c, ...)
void void
free_table_cache(void) free_table_cache(void)
{ {
if (renderer_context.table_cache) { if (table_cache) {
struct hash_item *item; struct hash_item *item;
int i; int i;
/* We do not free key here. */ /* We do not free key here. */
foreach_hash_item (item, *renderer_context.table_cache, i) { foreach_hash_item (item, *table_cache, i) {
mem_free_if(item->value); mem_free_if(item->value);
} }
free_hash(renderer_context.table_cache); free_hash(table_cache);
} }
renderer_context.table_cache = NULL; table_cache = NULL;
renderer_context.table_cache_entries = 0; table_cache_entries = 0;
} }
struct part * struct part *
@ -1765,14 +1777,12 @@ format_html_part(struct html_context *html_context,
struct html_element *html_state; struct html_element *html_state;
int llm = renderer_context.last_link_to_move; int llm = renderer_context.last_link_to_move;
struct tag *ltm = renderer_context.last_tag_to_move; struct tag *ltm = renderer_context.last_tag_to_move;
/*struct tag *ltn = last_tag_for_newline;*/
int lm = html_context->margin;
int ef = renderer_context.empty_format; int ef = renderer_context.empty_format;
struct table_cache_entry *tce; int lm = html_context->margin;
/* Hash creation if needed. */ /* Hash creation if needed. */
if (!renderer_context.table_cache) { if (!table_cache) {
renderer_context.table_cache = init_hash(8, &strhash); table_cache = init_hash(8, &strhash);
} else if (!document) { } else if (!document) {
/* Search for cached entry. */ /* Search for cached entry. */
struct table_cache_entry_key key; struct table_cache_entry_key key;
@ -1790,7 +1800,7 @@ format_html_part(struct html_context *html_context,
key.x = x; key.x = x;
key.link_num = link_num; key.link_num = link_num;
item = get_hash_item(renderer_context.table_cache, item = get_hash_item(table_cache,
(unsigned char *) &key, (unsigned char *) &key,
sizeof(key)); sizeof(key));
if (item) { /* We found it in cache, so just copy and return. */ if (item) { /* We found it in cache, so just copy and return. */
@ -1817,12 +1827,12 @@ format_html_part(struct html_context *html_context,
} }
renderer_context.last_link_to_move = document->nlinks; renderer_context.last_link_to_move = document->nlinks;
renderer_context.last_tag_to_move = (void *) &document->tags; renderer_context.last_tag_to_move = (struct tag *) &document->tags;
renderer_context.last_tag_for_newline = (void *) &document->tags; renderer_context.last_tag_for_newline = (struct tag *) &document->tags;
} else { } else {
renderer_context.last_link_to_move = 0; renderer_context.last_link_to_move = 0;
renderer_context.last_tag_to_move = NULL; renderer_context.last_tag_to_move = (struct tag *) NULL;
renderer_context.last_tag_for_newline = NULL; renderer_context.last_tag_for_newline = (struct tag *) NULL;
} }
html_context->margin = margin; html_context->margin = margin;
@ -1863,17 +1873,17 @@ format_html_part(struct html_context *html_context,
ret: ret:
renderer_context.last_link_to_move = llm; renderer_context.last_link_to_move = llm;
renderer_context.last_tag_to_move = ltm; renderer_context.last_tag_to_move = ltm;
/* renderer_context.last_tag_for_newline = ltn; */
html_context->margin = lm;
renderer_context.empty_format = ef; renderer_context.empty_format = ef;
html_context->margin = lm;
if (html_context->table_level > 1 && !document if (html_context->table_level > 1 && !document
&& renderer_context.table_cache && table_cache
&& renderer_context.table_cache_entries < MAX_TABLE_CACHE_ENTRIES) { && table_cache_entries < MAX_TABLE_CACHE_ENTRIES) {
/* Create a new entry. */ /* Create a new entry. */
/* Clear memory to prevent bad key comparaison due to alignment /* Clear memory to prevent bad key comparaison due to alignment
* of key fields. */ * of key fields. */
tce = mem_calloc(1, sizeof(*tce)); struct table_cache_entry *tce = mem_calloc(1, sizeof(*tce));
/* A goto is used here to prevent a test or code /* A goto is used here to prevent a test or code
* redundancy. */ * redundancy. */
if (!tce) goto end; if (!tce) goto end;
@ -1887,12 +1897,12 @@ ret:
tce->key.link_num = link_num; tce->key.link_num = link_num;
copy_struct(&tce->part, part); copy_struct(&tce->part, part);
if (!add_hash_item(renderer_context.table_cache, if (!add_hash_item(table_cache,
(unsigned char *) &tce->key, (unsigned char *) &tce->key,
sizeof(tce->key), tce)) { sizeof(tce->key), tce)) {
mem_free(tce); mem_free(tce);
} else { } else {
renderer_context.table_cache_entries++; table_cache_entries++;
} }
} }
@ -1907,8 +1917,8 @@ render_html_document(struct cache_entry *cached, struct document *document,
{ {
struct html_context *html_context; struct html_context *html_context;
struct part *part; struct part *part;
unsigned char *start = NULL; unsigned char *start;
unsigned char *end = NULL; unsigned char *end;
struct string title; struct string title;
struct string head; struct string head;
int i; int i;
@ -1918,20 +1928,19 @@ render_html_document(struct cache_entry *cached, struct document *document,
if (!init_string(&head)) return; if (!init_string(&head)) return;
renderer_context.g_ctrl_num = 0; if (cached->head) add_to_string(&head, cached->head);
renderer_context.cached = cached;
start = buffer->source; start = buffer->source;
end = buffer->source + buffer->length; end = buffer->source + buffer->length;
if (cached->head) add_to_string(&head, cached->head);
html_context = init_html_parser(cached->uri, &document->options, html_context = init_html_parser(cached->uri, &document->options,
start, end, &head, &title, start, end, &head, &title,
put_chars_conv, line_break, put_chars_conv, line_break,
html_special); html_special);
if (!html_context) return; if (!html_context) return;
renderer_context.g_ctrl_num = 0;
renderer_context.cached = cached;
renderer_context.convert_table = get_convert_table(head.source, renderer_context.convert_table = get_convert_table(head.source,
document->options.cp, document->options.cp,
document->options.assume_cp, document->options.assume_cp,

View File

@ -166,7 +166,7 @@ really_close_tab(struct session *ses)
switch_to_tab(term, term->current_tab - 1, num_tabs - 1); switch_to_tab(term, term->current_tab - 1, num_tabs - 1);
} }
delete_window(ses->tab); delete_window(ses->tab);
} }