From 9bf5494d10b577052a92dac252b596a2bb994482 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 31 Jul 2021 14:48:13 +0200 Subject: [PATCH] [iframes] Draw frame around iframe. --- src/document/html/iframes.c | 3 +- src/document/html/iframes.h | 1 + src/document/html/parser/link.c | 4 +-- src/viewer/text/draw.c | 50 ++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/document/html/iframes.c b/src/document/html/iframes.c index 170cb083..e80ce477 100644 --- a/src/document/html/iframes.c +++ b/src/document/html/iframes.c @@ -48,6 +48,7 @@ void add_iframeset_entry(struct iframeset_desc **parent, iframe_desc = &iframeset_desc->iframe_desc[offset]; iframe_desc->name = stracpy(name); iframe_desc->uri = get_uri(url, 0); + iframe_desc->x = 1; iframe_desc->y = y; iframe_desc->width = width; iframe_desc->height = height; @@ -203,7 +204,7 @@ format_iframes(struct session *ses, struct iframeset_desc *ifsd, struct iframe_desc *iframe_desc = &ifsd->iframe_desc[j]; struct document_view *doc_view; - o.box.x = op->box.x; + o.box.x = iframe_desc->x; o.box.y = iframe_desc->y; o.box.width = iframe_desc->width; diff --git a/src/document/html/iframes.h b/src/document/html/iframes.h index e3d51c04..f8bbed14 100644 --- a/src/document/html/iframes.h +++ b/src/document/html/iframes.h @@ -13,6 +13,7 @@ struct iframe_desc { char *name; struct uri *uri; + int x; int y; int width, height; }; diff --git a/src/document/html/parser/link.c b/src/document/html/parser/link.c index dc03a3a3..b729ba8b 100644 --- a/src/document/html/parser/link.c +++ b/src/document/html/parser/link.c @@ -503,9 +503,9 @@ html_iframe_do(char *a, char *object_src, } if (height > 0) { - int y = html_context->part->cy; + int y = html_context->part->cy + 1; char *url2; - ln_break(html_context, height + 1); + ln_break(html_context, height + 3); url2 = join_urls(html_context->base_href, url); diff --git a/src/viewer/text/draw.c b/src/viewer/text/draw.c index 2bb435c7..db6f8f48 100644 --- a/src/viewer/text/draw.c +++ b/src/viewer/text/draw.c @@ -17,6 +17,7 @@ #include "cache/cache.h" #include "document/document.h" #include "document/html/frames.h" +#include "document/html/iframes.h" #include "document/options.h" #include "document/refresh.h" #include "document/renderer.h" @@ -165,6 +166,46 @@ draw_frame_lines(struct terminal *term, struct frameset_desc *frameset_desc, } } +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; + + int y = iframe_desc->iframe_desc[j].y - 1; + int x = iframe_desc->iframe_desc[j].x - 1; + + int height = iframe_desc->iframe_desc[j].height + 1; + int width = iframe_desc->iframe_desc[j].width + 1; + + 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); + } +} + + static void draw_clipboard(struct terminal *term, struct document_view *doc_view) { @@ -288,13 +329,14 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active) } if (document_has_frames(doc_view->document)) { - draw_box(term, box, ' ', 0, &color); + draw_box(term, box, ' ', 0, &color); draw_frame_lines(term, doc_view->document->frame_desc, box->x, box->y, &color); if (vs->current_link == -1) vs->current_link = 0; return; } + if (ses->navigate_mode == NAVIGATE_LINKWISE) { check_vs(doc_view); } else { @@ -362,6 +404,12 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active) draw_view_status(ses, doc_view, active); if (has_search_word(doc_view)) doc_view->last_x = doc_view->last_y = -1; + + if (document_has_iframes(doc_view->document)) { + draw_iframe_lines(term, doc_view->document->iframe_desc, box->x, box->y, &color); + if (vs->current_link == -1) + vs->current_link = 0; + } } static void