2007-07-27 07:13:27 -04:00
|
|
|
/** Text mode drawing functions
|
|
|
|
* @file */
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2023-05-19 15:31:51 -04:00
|
|
|
#include <stdio.h>
|
2005-09-15 09:58:31 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "cache/cache.h"
|
|
|
|
#include "document/document.h"
|
|
|
|
#include "document/html/frames.h"
|
2021-07-31 08:48:13 -04:00
|
|
|
#include "document/html/iframes.h"
|
2024-01-26 12:43:33 -05:00
|
|
|
#include "document/libdom/renderer2.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "document/options.h"
|
|
|
|
#include "document/refresh.h"
|
|
|
|
#include "document/renderer.h"
|
|
|
|
#include "document/view.h"
|
|
|
|
#include "dialogs/status.h" /* print_screen_status() */
|
|
|
|
#include "intl/charsets.h"
|
2021-08-08 15:25:08 -04:00
|
|
|
#include "intl/libintl.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/location.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "terminal/draw.h"
|
2023-05-28 04:53:07 -04:00
|
|
|
#ifdef CONFIG_LIBSIXEL
|
2023-05-19 15:31:51 -04:00
|
|
|
#include "terminal/sixel.h"
|
2023-05-28 04:53:07 -04:00
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "terminal/tab.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/error.h"
|
2024-01-26 12:43:33 -05:00
|
|
|
#include "util/hash.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "util/lists.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "viewer/text/draw.h"
|
|
|
|
#include "viewer/text/form.h"
|
|
|
|
#include "viewer/text/link.h"
|
|
|
|
#include "viewer/text/search.h"
|
|
|
|
#include "viewer/text/view.h" /* current_frame() */
|
|
|
|
#include "viewer/text/vs.h"
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
check_document_fragment(struct session *ses, struct document_view *doc_view)
|
|
|
|
{
|
|
|
|
struct document *document = doc_view->document;
|
|
|
|
struct uri *uri = doc_view->vs->uri;
|
2006-12-05 13:04:53 -05:00
|
|
|
int vy;
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string fragment;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-12-05 13:04:53 -05:00
|
|
|
assert(uri->fragmentlen);
|
|
|
|
|
|
|
|
if (!init_string(&fragment)) return -2;
|
|
|
|
if (!add_uri_to_string(&fragment, uri, URI_FRAGMENT)) {
|
|
|
|
done_string(&fragment);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
decode_uri_string(&fragment);
|
|
|
|
assert(fragment.length);
|
|
|
|
assert(*fragment.source);
|
|
|
|
|
|
|
|
/* Omit the leading '#' when calling find_tag. */
|
|
|
|
vy = find_tag(document, fragment.source + 1, fragment.length - 1);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (vy == -1) {
|
2006-12-09 22:11:04 -05:00
|
|
|
struct cache_entry *cached = document->cached;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-12-09 22:11:04 -05:00
|
|
|
assert(cached);
|
2008-04-20 16:25:10 -04:00
|
|
|
if (cached->incomplete || cached->cache_id != document->cache_id) {
|
2006-12-05 13:04:53 -05:00
|
|
|
done_string(&fragment);
|
2005-09-15 09:58:31 -04:00
|
|
|
return -2;
|
2006-12-05 13:04:53 -05:00
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
if (get_opt_bool("document.browse.links.missing_fragment",
|
2007-08-30 17:11:51 -04:00
|
|
|
ses)) {
|
2005-09-15 09:58:31 -04:00
|
|
|
info_box(ses->tab->term, MSGBOX_FREE_TEXT,
|
|
|
|
N_("Missing fragment"), ALIGN_CENTER,
|
|
|
|
msg_text(ses->tab->term, N_("The requested fragment "
|
2006-12-05 13:04:53 -05:00
|
|
|
"\"%s\" doesn't exist."),
|
|
|
|
fragment.source));
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int_bounds(&vy, 0, document->height - 1);
|
|
|
|
}
|
|
|
|
|
2006-12-05 13:04:53 -05:00
|
|
|
done_string(&fragment);
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
return vy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_frame_lines(struct terminal *term, struct frameset_desc *frameset_desc,
|
|
|
|
int xp, int yp, struct color_pair *colors)
|
|
|
|
{
|
|
|
|
int y, j;
|
|
|
|
|
|
|
|
assert(term && frameset_desc && frameset_desc->frame_desc);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
y = yp - 1;
|
|
|
|
for (j = 0; j < frameset_desc->box.height; j++) {
|
|
|
|
int x, i;
|
|
|
|
int height = frameset_desc->frame_desc[j * frameset_desc->box.width].height;
|
|
|
|
|
|
|
|
x = xp - 1;
|
|
|
|
for (i = 0; i < frameset_desc->box.width; i++) {
|
|
|
|
int width = frameset_desc->frame_desc[i].width;
|
|
|
|
|
|
|
|
if (i) {
|
2018-09-09 13:14:56 -04:00
|
|
|
struct el_box box;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
set_box(&box, x, y + 1, 1, height);
|
|
|
|
draw_box(term, &box, BORDER_SVLINE, SCREEN_ATTR_FRAME, colors);
|
|
|
|
|
|
|
|
if (j == frameset_desc->box.height - 1)
|
|
|
|
draw_border_cross(term, x, y + height + 1,
|
|
|
|
BORDER_X_UP, colors);
|
|
|
|
} else if (j) {
|
|
|
|
if (x >= 0)
|
|
|
|
draw_border_cross(term, x, y,
|
|
|
|
BORDER_X_RIGHT, colors);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j) {
|
2018-09-09 13:14:56 -04:00
|
|
|
struct el_box box;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
set_box(&box, x + 1, y, width, 1);
|
|
|
|
draw_box(term, &box, BORDER_SHLINE, SCREEN_ATTR_FRAME, colors);
|
|
|
|
|
|
|
|
if (i == frameset_desc->box.width - 1
|
|
|
|
&& x + width + 1 < term->width)
|
|
|
|
draw_border_cross(term, x + width + 1, y,
|
|
|
|
BORDER_X_LEFT, colors);
|
|
|
|
} else if (i) {
|
|
|
|
draw_border_cross(term, x, y, BORDER_X_DOWN, colors);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i && j)
|
|
|
|
draw_border_char(term, x, y, BORDER_SCROSS, colors);
|
|
|
|
|
|
|
|
x += width + 1;
|
|
|
|
}
|
|
|
|
y += height + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
y = yp - 1;
|
|
|
|
for (j = 0; j < frameset_desc->box.height; j++) {
|
|
|
|
int x, i;
|
|
|
|
int pj = j * frameset_desc->box.width;
|
|
|
|
int height = frameset_desc->frame_desc[pj].height;
|
|
|
|
|
|
|
|
x = xp - 1;
|
|
|
|
for (i = 0; i < frameset_desc->box.width; i++) {
|
|
|
|
int width = frameset_desc->frame_desc[i].width;
|
|
|
|
int p = pj + i;
|
|
|
|
|
|
|
|
if (frameset_desc->frame_desc[p].subframe) {
|
|
|
|
draw_frame_lines(term, frameset_desc->frame_desc[p].subframe,
|
|
|
|
x + 1, y + 1, colors);
|
|
|
|
}
|
|
|
|
x += width + 1;
|
|
|
|
}
|
|
|
|
y += height + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 08:48:13 -04:00
|
|
|
static void
|
|
|
|
draw_iframe_lines(struct terminal *term, struct iframeset_desc *iframe_desc,
|
|
|
|
int xp, int yp, struct color_pair *colors)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
assert(term && iframe_desc && iframe_desc->iframe_desc);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
for (j = 0; j < iframe_desc->n; j++) {
|
|
|
|
struct el_box box;
|
|
|
|
|
2023-06-10 11:57:28 -04:00
|
|
|
int y = yp + iframe_desc->iframe_desc[j].box.y - 1;
|
|
|
|
int x = xp + iframe_desc->iframe_desc[j].box.x - 1;
|
2021-07-31 08:48:13 -04:00
|
|
|
|
2023-06-10 11:57:28 -04:00
|
|
|
int height = iframe_desc->iframe_desc[j].box.height + 1;
|
|
|
|
int width = iframe_desc->iframe_desc[j].box.width + 1;
|
2021-07-31 08:48:13 -04:00
|
|
|
|
|
|
|
set_box(&box, x, y + 1, 1, height - 1);
|
|
|
|
draw_box(term, &box, BORDER_SVLINE, SCREEN_ATTR_FRAME, colors);
|
|
|
|
|
|
|
|
set_box(&box, x + width, y + 1, 1, height - 1);
|
|
|
|
draw_box(term, &box, BORDER_SVLINE, SCREEN_ATTR_FRAME, colors);
|
|
|
|
|
|
|
|
set_box(&box, x + 1, y, width -1 , 1);
|
|
|
|
draw_box(term, &box, BORDER_SHLINE, SCREEN_ATTR_FRAME, colors);
|
|
|
|
|
|
|
|
set_box(&box, x + 1, y + height, width - 1, 1);
|
|
|
|
draw_box(term, &box, BORDER_SHLINE, SCREEN_ATTR_FRAME, colors);
|
|
|
|
|
|
|
|
draw_border_char(term, x, y, BORDER_SULCORNER, colors);
|
|
|
|
draw_border_char(term, x, y + height, BORDER_SDLCORNER, colors);
|
|
|
|
|
|
|
|
draw_border_char(term, x + width, y, BORDER_SURCORNER, colors);
|
|
|
|
draw_border_char(term, x + width, y + height, BORDER_SDRCORNER, colors);
|
|
|
|
draw_border_cross(term, x, y, BORDER_X_DOWN, colors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-01 17:25:21 -04:00
|
|
|
static void
|
|
|
|
draw_clipboard(struct terminal *term, struct document_view *doc_view)
|
|
|
|
{
|
|
|
|
struct document *document = doc_view->document;
|
2022-10-16 09:18:34 -04:00
|
|
|
struct color_pair *color;
|
2020-08-01 17:25:21 -04:00
|
|
|
int starty, startx, endy, endx, x, y, xoffset, yoffset;
|
|
|
|
|
|
|
|
assert(term && doc_view);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
2020-08-03 12:27:25 -04:00
|
|
|
if (document->clipboard_status == CLIPBOARD_NONE) {
|
2020-08-01 17:25:21 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:18:34 -04:00
|
|
|
color = get_bfu_color(term, "clipboard");
|
2020-08-01 17:25:21 -04:00
|
|
|
xoffset = doc_view->box.x - doc_view->vs->x;
|
|
|
|
yoffset = doc_view->box.y - doc_view->vs->y;
|
|
|
|
|
|
|
|
|
2020-08-04 13:22:31 -04:00
|
|
|
if (document->clipboard_box.height >= 0) {
|
|
|
|
starty = int_max(doc_view->box.y, document->clipboard_box.y + yoffset);
|
|
|
|
endy = int_min(doc_view->box.y + doc_view->box.height,
|
|
|
|
document->clipboard_box.y + document->clipboard_box.height + yoffset);
|
|
|
|
} else {
|
|
|
|
endy = int_max(doc_view->box.y, document->clipboard_box.y + yoffset);
|
|
|
|
starty = int_min(doc_view->box.y + doc_view->box.height,
|
|
|
|
document->clipboard_box.y + document->clipboard_box.height + yoffset);
|
2020-08-03 12:27:25 -04:00
|
|
|
}
|
|
|
|
|
2020-08-04 13:22:31 -04:00
|
|
|
if (document->clipboard_box.width >= 0) {
|
|
|
|
startx = int_max(doc_view->box.x, document->clipboard_box.x + xoffset);
|
|
|
|
endx = int_min(doc_view->box.x + doc_view->box.width,
|
|
|
|
document->clipboard_box.x + document->clipboard_box.width + xoffset);
|
|
|
|
} else {
|
|
|
|
endx = int_max(doc_view->box.x, document->clipboard_box.x + xoffset);
|
|
|
|
startx = int_min(doc_view->box.x + doc_view->box.width,
|
|
|
|
document->clipboard_box.x + document->clipboard_box.width + xoffset);
|
2020-08-03 12:27:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (y = starty; y <= endy; ++y) {
|
|
|
|
for (x = startx; x <= endx; ++x) {
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_char_color(term, x, y, color);
|
2020-08-01 17:25:21 -04:00
|
|
|
}
|
|
|
|
}
|
2020-08-03 11:22:21 -04:00
|
|
|
doc_view->last_x = doc_view->last_y = -1;
|
|
|
|
|
2020-08-01 17:25:21 -04:00
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
static void
|
|
|
|
draw_view_status(struct session *ses, struct document_view *doc_view, int active)
|
|
|
|
{
|
|
|
|
struct terminal *term = ses->tab->term;
|
|
|
|
|
|
|
|
draw_forms(term, doc_view);
|
|
|
|
if (active) {
|
|
|
|
draw_searched(term, doc_view);
|
2020-08-01 17:25:21 -04:00
|
|
|
draw_clipboard(term, doc_view);
|
2005-09-15 09:58:31 -04:00
|
|
|
draw_current_link(ses, doc_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-27 07:13:27 -04:00
|
|
|
/** Checks if there is a link under the cursor so it can become the current
|
2005-09-15 09:58:31 -04:00
|
|
|
* highlighted link. */
|
|
|
|
static void
|
|
|
|
check_link_under_cursor(struct session *ses, struct document_view *doc_view)
|
|
|
|
{
|
|
|
|
int x = ses->tab->x;
|
|
|
|
int y = ses->tab->y;
|
2018-09-09 13:14:56 -04:00
|
|
|
struct el_box *box = &doc_view->box;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct link *link;
|
|
|
|
|
|
|
|
link = get_link_at_coordinates(doc_view, x - box->x, y - box->y);
|
|
|
|
if (link && link != get_current_link(doc_view)) {
|
|
|
|
doc_view->vs->current_link = link - doc_view->document->links;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-27 07:13:27 -04:00
|
|
|
/** Puts the formatted document on the given terminal's screen.
|
|
|
|
* @a active indicates whether the document is focused -- i.e.,
|
2005-09-15 09:58:31 -04:00
|
|
|
* whether it is displayed in the selected frame or document. */
|
|
|
|
static void
|
|
|
|
draw_doc(struct session *ses, struct document_view *doc_view, int active)
|
|
|
|
{
|
|
|
|
struct color_pair color;
|
|
|
|
struct view_state *vs;
|
|
|
|
struct terminal *term;
|
2018-09-09 13:14:56 -04:00
|
|
|
struct el_box *box;
|
2022-10-17 04:04:46 -04:00
|
|
|
struct screen_char *last = NULL;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
int vx, vy;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
assert(ses && ses->tab && ses->tab->term && doc_view);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
box = &doc_view->box;
|
|
|
|
term = ses->tab->term;
|
|
|
|
|
|
|
|
/* The code in this function assumes that both width and height are
|
|
|
|
* bigger than 1 so we have to bail out here. */
|
|
|
|
if (box->width < 2 || box->height < 2) return;
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
/* When redrawing the document after things like link menu we
|
|
|
|
* have to reset the cursor routing state. */
|
|
|
|
if (ses->navigate_mode == NAVIGATE_CURSOR_ROUTING) {
|
|
|
|
set_cursor(term, ses->tab->x, ses->tab->y, 0);
|
|
|
|
} else {
|
|
|
|
set_cursor(term, box->x + box->width - 1, box->y + box->height - 1, 1);
|
|
|
|
set_window_ptr(ses->tab, box->x, box->y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-30 17:11:51 -04:00
|
|
|
color.foreground = get_opt_color("document.colors.text", ses);
|
2005-09-15 09:58:31 -04:00
|
|
|
color.background = doc_view->document->height
|
2007-10-12 10:50:47 -04:00
|
|
|
? doc_view->document->color.background
|
2007-08-30 17:11:51 -04:00
|
|
|
: get_opt_color("document.colors.background", ses);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
vs = doc_view->vs;
|
2023-06-10 11:57:28 -04:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!vs) {
|
2022-10-16 09:45:09 -04:00
|
|
|
int bgchar = get_opt_int("ui.background_char", ses);
|
|
|
|
#ifdef CONFIG_UTF8
|
|
|
|
draw_box(term, box, bgchar, 0, get_bfu_color(term, "desktop"));
|
|
|
|
#else
|
|
|
|
draw_box(term, box, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (document_has_frames(doc_view->document)) {
|
2022-10-16 09:45:09 -04:00
|
|
|
int bgchar = get_opt_int("ui.background_char", ses);
|
|
|
|
#ifdef CONFIG_UTF8
|
|
|
|
draw_box(term, box, bgchar, 0, get_bfu_color(term, "desktop"));
|
|
|
|
#else
|
|
|
|
draw_box(term, box, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
draw_frame_lines(term, doc_view->document->frame_desc, box->x, box->y, &color);
|
|
|
|
if (vs->current_link == -1)
|
|
|
|
vs->current_link = 0;
|
2023-06-10 11:57:28 -04:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-31 08:48:13 -04:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
if (ses->navigate_mode == NAVIGATE_LINKWISE) {
|
|
|
|
check_vs(doc_view);
|
|
|
|
} else {
|
|
|
|
check_link_under_cursor(ses, doc_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vs->did_fragment) {
|
|
|
|
vy = check_document_fragment(ses, doc_view);
|
|
|
|
|
|
|
|
if (vy != -2) vs->did_fragment = 1;
|
|
|
|
if (vy >= 0) {
|
|
|
|
doc_view->vs->y = vy;
|
|
|
|
set_link(doc_view);
|
|
|
|
}
|
2020-04-28 13:13:36 -04:00
|
|
|
if (vy == -1) {
|
|
|
|
struct location *loc = cur_loc(ses);
|
|
|
|
|
|
|
|
if (loc) {
|
|
|
|
struct uri *cur_uri = loc->vs.uri;
|
|
|
|
|
|
|
|
if (list_has_prev(ses->history.history, loc)) {
|
|
|
|
struct uri *prev_uri = loc->prev->vs.uri;
|
|
|
|
|
|
|
|
if (compare_uri(cur_uri, prev_uri, URI_BASE)) {
|
|
|
|
doc_view->vs->y = doc_view->prev_y;
|
|
|
|
set_link(doc_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
vx = vs->x;
|
|
|
|
vy = vs->y;
|
|
|
|
if (doc_view->last_x != -1
|
|
|
|
&& doc_view->last_x == vx
|
|
|
|
&& doc_view->last_y == vy
|
2023-06-10 11:57:28 -04:00
|
|
|
&& !has_search_word(doc_view)
|
|
|
|
&& !document_has_iframes(doc_view->document)) {
|
2005-09-15 09:58:31 -04:00
|
|
|
clear_link(term, doc_view);
|
|
|
|
draw_view_status(ses, doc_view, active);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
doc_view->last_x = vx;
|
|
|
|
doc_view->last_y = vy;
|
2022-10-16 09:45:09 -04:00
|
|
|
|
|
|
|
int bgchar = get_opt_int("ui.background_char", ses);
|
|
|
|
#ifdef CONFIG_UTF8
|
|
|
|
draw_box(term, box, bgchar, 0, get_bfu_color(term, "desktop"));
|
|
|
|
#else
|
|
|
|
draw_box(term, box, (unsigned char)bgchar, 0, get_bfu_color(term, "desktop"));
|
|
|
|
#endif
|
2023-06-10 11:57:28 -04:00
|
|
|
if (!doc_view->document->height) {
|
|
|
|
return;
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
while (vs->y >= doc_view->document->height) vs->y -= box->height;
|
|
|
|
int_lower_bound(&vs->y, 0);
|
|
|
|
if (vy != vs->y) {
|
|
|
|
vy = vs->y;
|
|
|
|
if (ses->navigate_mode == NAVIGATE_LINKWISE)
|
|
|
|
check_vs(doc_view);
|
|
|
|
}
|
2024-01-26 12:43:33 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
for (y = int_max(vy, 0);
|
|
|
|
y < int_min(doc_view->document->height, box->height + vy);
|
|
|
|
y++) {
|
2022-10-17 04:04:46 -04:00
|
|
|
struct screen_char *first = NULL;
|
|
|
|
int i, j;
|
|
|
|
int last_index = 0;
|
2005-09-15 09:58:31 -04:00
|
|
|
int st = int_max(vx, 0);
|
|
|
|
int en = int_min(doc_view->document->data[y].length,
|
|
|
|
box->width + vx);
|
2022-10-17 04:04:46 -04:00
|
|
|
int max = int_min(en, st + 200);
|
|
|
|
|
|
|
|
if (en - st > 0) {
|
|
|
|
draw_line(term, box->x + st - vx, box->y + y - vy,
|
|
|
|
en - st,
|
2023-05-18 05:12:05 -04:00
|
|
|
&doc_view->document->data[y].ch.chars[st]);
|
2022-10-17 04:04:46 -04:00
|
|
|
|
|
|
|
for (i = en - 1; i >= 0; --i) {
|
2023-05-18 05:12:05 -04:00
|
|
|
if (doc_view->document->data[y].ch.chars[i].data != ' ') {
|
|
|
|
last = &doc_view->document->data[y].ch.chars[i];
|
2022-10-17 04:04:46 -04:00
|
|
|
last_index = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-26 12:43:33 -05:00
|
|
|
|
2022-10-17 04:04:46 -04:00
|
|
|
for (i = st; i < max; i++) {
|
2023-05-18 05:12:05 -04:00
|
|
|
if (doc_view->document->data[y].ch.chars[i].data != ' ') {
|
|
|
|
first = &doc_view->document->data[y].ch.chars[i];
|
2022-10-17 04:04:46 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = st; j < i; j++) {
|
|
|
|
draw_space(term, box->x + j - vx, box->y + y - vy,
|
|
|
|
first);
|
|
|
|
}
|
2017-06-13 16:39:53 -04:00
|
|
|
|
2022-10-17 04:04:46 -04:00
|
|
|
for (i = last_index; i < box->width + vx; i++) {
|
|
|
|
draw_space(term, box->x + i - vx, box->y + y - vy,
|
|
|
|
last);
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
2024-01-26 12:43:33 -05:00
|
|
|
#if 0
|
|
|
|
try_to_color(term, box, doc_view->document, vx, vy);
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
draw_view_status(ses, doc_view, active);
|
|
|
|
if (has_search_word(doc_view))
|
|
|
|
doc_view->last_x = doc_view->last_y = -1;
|
2021-07-31 08:48:13 -04:00
|
|
|
|
|
|
|
if (document_has_iframes(doc_view->document)) {
|
|
|
|
draw_iframe_lines(term, doc_view->document->iframe_desc, box->x, box->y, &color);
|
2023-06-04 11:46:22 -04:00
|
|
|
// if (vs->current_link == -1)
|
|
|
|
// vs->current_link = 0;
|
2021-07-31 08:48:13 -04:00
|
|
|
}
|
2023-05-19 15:31:51 -04:00
|
|
|
#ifdef CONFIG_LIBSIXEL
|
|
|
|
while (!list_empty(term->images)) {
|
|
|
|
delete_image((struct image *)term->images.next);
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:32:57 -04:00
|
|
|
if (1) {
|
2023-05-19 15:31:51 -04:00
|
|
|
struct image *im;
|
|
|
|
|
|
|
|
foreach (im, doc_view->document->images) {
|
2023-05-21 15:17:13 -04:00
|
|
|
if (im->y >= vs->y + box->height) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (im->y + ((im->height + term->cell_height - 1) / term->cell_height) < vs->y) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:32:57 -04:00
|
|
|
if (im->x >= vs->x + box->width) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (im->x + ((im->width + term->cell_width - 1) / term->cell_width) < vs->x) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct image *im_copy = copy_frame(im, box->width, box->height, term->cell_width, term->cell_height, vs->x, vs->y);
|
2023-05-21 15:17:13 -04:00
|
|
|
|
|
|
|
if (im_copy) {
|
|
|
|
add_to_list(term->images, im_copy);
|
2023-05-19 15:31:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_frames(struct session *ses)
|
|
|
|
{
|
|
|
|
struct document_view *doc_view, *current_doc_view;
|
|
|
|
int *l;
|
2005-12-13 10:59:10 -05:00
|
|
|
int n, d;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(ses && ses->doc_view && ses->doc_view->document);
|
2023-06-10 11:57:28 -04:00
|
|
|
if_assert_failed {
|
|
|
|
return;
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2023-06-10 11:57:28 -04:00
|
|
|
if (!document_has_frames(ses->doc_view->document)) {
|
|
|
|
return;
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
n = 0;
|
|
|
|
foreach (doc_view, ses->scrn_frames) {
|
|
|
|
doc_view->last_x = doc_view->last_y = -1;
|
|
|
|
n++;
|
|
|
|
}
|
2023-06-04 11:46:22 -04:00
|
|
|
|
|
|
|
if (n) {
|
|
|
|
l = &cur_loc(ses)->vs.current_link;
|
|
|
|
*l = int_max(*l, 0) % int_max(n, 1);
|
2021-07-26 15:28:19 -04:00
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
current_doc_view = current_frame(ses);
|
|
|
|
d = 0;
|
2005-12-13 10:59:10 -05:00
|
|
|
while (1) {
|
|
|
|
int more = 0;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
foreach (doc_view, ses->scrn_frames) {
|
|
|
|
if (doc_view->depth == d)
|
|
|
|
draw_doc(ses, doc_view, doc_view == current_doc_view);
|
|
|
|
else if (doc_view->depth > d)
|
|
|
|
more = 1;
|
|
|
|
}
|
2005-12-13 10:59:10 -05:00
|
|
|
|
|
|
|
if (!more) break;
|
2005-09-15 09:58:31 -04:00
|
|
|
d++;
|
2005-12-13 10:59:10 -05:00
|
|
|
};
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
2023-06-10 11:57:28 -04:00
|
|
|
static void
|
|
|
|
draw_iframes(struct session *ses)
|
|
|
|
{
|
|
|
|
struct document_view *doc_view, *current_doc_view;
|
|
|
|
|
|
|
|
assert(ses && ses->doc_view && ses->doc_view->document);
|
|
|
|
if_assert_failed {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (doc_view, ses->scrn_iframes) {
|
|
|
|
doc_view->last_x = doc_view->last_y = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_doc_view = current_frame(ses);
|
|
|
|
|
|
|
|
foreach (doc_view, ses->scrn_iframes) {
|
|
|
|
draw_doc(ses, doc_view, doc_view == current_doc_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-27 07:13:27 -04:00
|
|
|
/** @todo @a rerender is ridiciously wound-up. */
|
2005-09-15 09:58:31 -04:00
|
|
|
void
|
|
|
|
draw_formatted(struct session *ses, int rerender)
|
|
|
|
{
|
|
|
|
assert(ses && ses->tab);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
if (rerender) {
|
|
|
|
rerender--; /* Mind this when analyzing @rerender. */
|
2024-06-22 06:29:07 -04:00
|
|
|
if (!(rerender & 2) && session_is_loading(ses)) {
|
2005-09-15 09:58:31 -04:00
|
|
|
rerender |= 2;
|
2024-06-22 06:29:07 -04:00
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
render_document_frames(ses, rerender);
|
|
|
|
|
|
|
|
/* Rerendering kills the document refreshing so restart it. */
|
2007-09-06 14:37:17 -04:00
|
|
|
start_document_refreshes(ses);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ses->tab != get_current_tab(ses->tab->term))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ses->doc_view || !ses->doc_view->document) {
|
|
|
|
/*INTERNAL("document not formatted");*/
|
2018-09-09 13:14:56 -04:00
|
|
|
struct el_box box;
|
2022-10-16 09:45:09 -04:00
|
|
|
int bgchar = get_opt_int("ui.background_char", ses);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
set_box(&box, 0, 1,
|
|
|
|
ses->tab->term->width,
|
|
|
|
ses->tab->term->height - 2);
|
2022-10-16 09:45:09 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
|
|
|
draw_box(ses->tab->term, &box, bgchar, 0, get_bfu_color(ses->tab->term, "desktop"));
|
|
|
|
#else
|
|
|
|
draw_box(ses->tab->term, &box, (unsigned char)bgchar, 0, get_bfu_color(ses->tab->term, "desktop"));
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ses->doc_view->vs && have_location(ses))
|
|
|
|
ses->doc_view->vs = &cur_loc(ses)->vs;
|
|
|
|
ses->doc_view->last_x = ses->doc_view->last_y = -1;
|
|
|
|
|
|
|
|
refresh_view(ses, ses->doc_view, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
refresh_view(struct session *ses, struct document_view *doc_view, int frames)
|
|
|
|
{
|
2008-07-22 05:13:27 -04:00
|
|
|
/* If refresh_view() is being called because the value of a
|
|
|
|
* form field has changed, @ses might not be in the current
|
|
|
|
* tab: consider SELECT pop-ups behind which -remote loads
|
|
|
|
* another tab, or setTimeout in ECMAScript. */
|
|
|
|
if (ses->tab == get_current_tab(ses->tab->term)) {
|
2023-06-10 11:57:28 -04:00
|
|
|
if (doc_view->parent_doc_view) {
|
2024-01-26 12:43:33 -05:00
|
|
|
#ifdef CONFIG_LIBDOM
|
2024-03-02 13:13:45 -05:00
|
|
|
//scan_document(doc_view->parent_doc_view);
|
2024-01-26 12:43:33 -05:00
|
|
|
#endif
|
2023-06-10 11:57:28 -04:00
|
|
|
draw_doc(ses, doc_view->parent_doc_view, 0);
|
|
|
|
} else {
|
2024-01-26 12:43:33 -05:00
|
|
|
#ifdef CONFIG_LIBDOM
|
2024-03-02 13:13:45 -05:00
|
|
|
//scan_document(doc_view);
|
2024-01-26 12:43:33 -05:00
|
|
|
#endif
|
2023-06-10 11:57:28 -04:00
|
|
|
draw_doc(ses, doc_view, 1);
|
|
|
|
}
|
2008-07-22 05:13:27 -04:00
|
|
|
if (frames) draw_frames(ses);
|
2023-06-10 11:57:28 -04:00
|
|
|
draw_iframes(ses);
|
2008-07-22 05:13:27 -04:00
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
print_screen_status(ses);
|
|
|
|
}
|