From 8b8d6bf12d49b366e40a50f678ac71d19b76c1b0 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Mon, 21 Dec 2020 01:59:34 +0000 Subject: [PATCH] WebView 3.26: disable cache for pages with param (site/?par=val) git-svn-id: svn://kolibrios.org@8462 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/browser/TWB/TWB.c | 102 +++++-------------- programs/cmm/browser/TWB/render.h | 100 +++++++++++++++++++ programs/cmm/browser/TWB/set_style.h | 144 ++++++++++++++++----------- programs/cmm/browser/WebView.c | 8 +- programs/cmm/browser/const.h | 2 - programs/cmm/browser/res/test.htm | 5 +- 6 files changed, 218 insertions(+), 143 deletions(-) create mode 100644 programs/cmm/browser/TWB/render.h diff --git a/programs/cmm/browser/TWB/TWB.c b/programs/cmm/browser/TWB/TWB.c index 94af6d0335..5b347d119b 100644 --- a/programs/cmm/browser/TWB/TWB.c +++ b/programs/cmm/browser/TWB/TWB.c @@ -9,9 +9,9 @@ dword link_color_active; #include "TWB\links.h" #define BODY_MARGIN 6 +#define BASIC_CHAR_W 8 #define BASIC_LINE_H 18 -CANVAS canvas; char line[500]; struct STYLE { @@ -39,7 +39,7 @@ void STYLE::reset() struct TWebBrowser { llist list; STYLE style; - dword draw_y, draw_x; + dword draw_y, draw_x, draw_w, left_gap; dword o_bufpointer; int cur_encoding, custom_encoding; bool link, t_html, t_body; @@ -50,11 +50,13 @@ struct TWebBrowser { char header[150]; char redirect[URL_SIZE]; - void Paint(); + void SetStyle(); + void Render(); + bool RenderImage(); + void SetPageDefaults(); void AddCharToTheLine(); void ParseHtml(); - void SetStyle(); bool CheckForLineBreak(); void NewLine(); void ChangeEncoding(); @@ -75,68 +77,13 @@ struct TWebBrowser { void tag_iframe(); void tag_title(); void tag_font(); + void tag_table(); + void tag_td(); + void tag_tr(); }; +#include "TWB\render.h" #include "TWB\set_style.h" - -//============================================================================================ -void TWebBrowser::Paint() -{ - unsigned px; //paint x coordinate - unsigned pw; //paint y coordinate - dword pc; //paint color - int zoom; - - if (style.title) - { - strncpy(#header, #line, sizeof(TWebBrowser.header)-1); - strncat(#header, " - ", sizeof(TWebBrowser.header)-1); - strncat(#header, #version, sizeof(TWebBrowser.header)-1); - line = 0; - return; - } - if (t_html) && (!t_body) { - line = 0; - return; - } - - if (line) - { - pw = strlen(#line) * list.font_w; - zoom = list.font_w / BASIC_CHAR_W; - - style.cur_line_h = math.max(style.cur_line_h, list.item_h); - - if (bg_colors.get_last() - bg_colors.get(0)) { - canvas.DrawBar(draw_x, draw_y, pw, list.item_h, bg_colors.get_last()); - } - - if (style.image) { - canvas.DrawBar(draw_x, draw_y, pw, list.item_h-1, 0xF9DBCB); - } - if (style.button) { - canvas.DrawBar(draw_x, draw_y, pw, list.item_h - calc(zoom*2), 0xCCCccc); - canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2), pw, zoom, 0x999999); - } - - pc = text_colors.get_last(); - if (link) && (pc == text_colors.get(0)) pc = link_color_default; - - canvas.WriteText(draw_x, draw_y, list.font_type, pc, #line, NULL); - if (style.b) canvas.WriteText(draw_x+1, draw_y, list.font_type, pc, #line, NULL); - if (style.s) canvas.DrawBar(draw_x, list.item_h / 2 - zoom + draw_y, pw, zoom, pc); - if (style.u) canvas.DrawBar(draw_x, list.item_h - zoom - zoom + draw_y, pw, zoom, pc); - if (link) { - if (line[0]==' ') && (line[1]==NULL) {} else { - canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2)-1, pw, zoom, link_color_default); - links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom); - } - } - draw_x += pw; - if (debug_mode) debugln(#line); - line = NULL; - } -} //============================================================================================ void TWebBrowser::SetPageDefaults() { @@ -156,7 +103,8 @@ void TWebBrowser::SetPageDefaults() header = NULL; cur_encoding = CH_CP866; draw_y = BODY_MARGIN; - draw_x = BODY_MARGIN; + draw_x = left_gap = BODY_MARGIN; + draw_w = list.w - BODY_MARGIN; line = 0; redirect = '\0'; //hold original buffer @@ -199,7 +147,7 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ { case 0x0a: if (style.pre) { - Paint(); + Render(); NewLine(); } else { AddCharToTheLine(0x0a); @@ -207,7 +155,7 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ break; case 0x09: if (style.pre) { - tab_len = draw_x - BODY_MARGIN / list.font_w + strlen(#line) % 4; + tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4; if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; for (j=0; j list.w) { - break_pos = list.w - draw_x /list.font_w; + if (break_pos * list.font_w + draw_x > draw_w) { + break_pos = draw_w - draw_x /list.font_w; while(break_pos) && (line[break_pos]!=' ') break_pos--; } //Maybe a new line is too big for the whole new line? Then we have to split it if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) { - break_pos = list.w - draw_x / list.font_w; + break_pos = draw_w - draw_x / list.font_w; } strcpy(#next_line, #line + break_pos); line[break_pos] = 0x00; - Paint(); + Render(); strcpy(#line, #next_line); NewLine(); @@ -322,10 +270,10 @@ void TWebBrowser::NewLine() { static bool empty_line = true; - if (draw_x==BODY_MARGIN) && (draw_y==BODY_MARGIN) return; + if (draw_x==left_gap) && (draw_y==BODY_MARGIN) return; if (t_html) && (!t_body) return; - if (draw_x == style.tag_list.level * 5 * list.font_w + BODY_MARGIN) { + if (draw_x == style.tag_list.level * 5 * list.font_w + left_gap) { if (!empty_line) empty_line=true; else return; } else { empty_line = false; @@ -334,7 +282,7 @@ void TWebBrowser::NewLine() draw_y += style.cur_line_h; style.cur_line_h = list.item_h; if (style.blq) draw_x = 6 * list.font_w; else draw_x = 0; - draw_x += style.tag_list.level * 5 * list.font_w + BODY_MARGIN; + draw_x += style.tag_list.level * 5 * list.font_w + left_gap; } //============================================================================================ void TWebBrowser::ChangeEncoding(int _new_encoding) diff --git a/programs/cmm/browser/TWB/render.h b/programs/cmm/browser/TWB/render.h new file mode 100644 index 0000000000..b36b2ffc0f --- /dev/null +++ b/programs/cmm/browser/TWB/render.h @@ -0,0 +1,100 @@ +CANVAS canvas; + +void TWebBrowser::Render() +{ + unsigned px; //paint x coordinate + unsigned pw; //paint y coordinate + dword pc; //paint color + int zoom; + + if (style.title) + { + strncpy(#header, #line, sizeof(TWebBrowser.header)-1); + strncat(#header, " - ", sizeof(TWebBrowser.header)-1); + strncat(#header, #version, sizeof(TWebBrowser.header)-1); + line = 0; + return; + } + if (t_html) && (!t_body) { + line = 0; + return; + } + + if (line) + { + pw = strlen(#line) * list.font_w; + zoom = list.font_w / BASIC_CHAR_W; + + style.cur_line_h = math.max(style.cur_line_h, list.item_h); + + if (bg_colors.get_last() - bg_colors.get(0)) { + canvas.DrawBar(draw_x, draw_y, pw, list.item_h, bg_colors.get_last()); + } + + if (style.image) { + canvas.DrawBar(draw_x, draw_y, pw, list.item_h-1, 0xF9DBCB); + } + if (style.button) { + canvas.DrawBar(draw_x, draw_y, pw, list.item_h - calc(zoom*2), 0xCCCccc); + canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2), pw, zoom, 0x999999); + } + + pc = text_colors.get_last(); + if (link) && (pc == text_colors.get(0)) pc = link_color_default; + + canvas.WriteText(draw_x, draw_y, list.font_type, pc, #line, NULL); + if (style.b) canvas.WriteText(draw_x+1, draw_y, list.font_type, pc, #line, NULL); + if (style.s) canvas.DrawBar(draw_x, list.item_h / 2 - zoom + draw_y, pw, zoom, pc); + if (style.u) canvas.DrawBar(draw_x, list.item_h - zoom - zoom + draw_y, pw, zoom, pc); + if (link) { + if (line[0]==' ') && (line[1]==NULL) {} else { + canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2)-1, pw, zoom, link_color_default); + links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom); + } + } + draw_x += pw; + if (debug_mode) debugln(#line); + line = NULL; + } +} + +bool TWebBrowser::RenderImage(dword cur_img) +{ + int img_x, img_y, img_w, img_h; + dword imgbuf[44]; + + if (!cur_img) return false; + + img_h = ESDWORD[cur_img+8]; + img_w = ESDWORD[cur_img+4]; + + if (img_w + draw_x >= draw_w) NewLine(); + img_y = draw_y; + if (img_h < list.item_h) img_y += list.item_h - img_h / 2 - 1; else img_y -= 2; + style.cur_line_h = math.max(style.cur_line_h, img_h); + + img_w = math.min(img_w, canvas.bufw - draw_x); + + if (link) links.add_text(draw_x + list.x, img_y + list.y, img_w, img_h, 0); + + if (img_y + img_h >= canvas.bufh) canvas.IncreaseBufSize(); + + if (ESDWORD[cur_img+20] != IMAGE_BPP32) { + img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0); + $push eax + img_destroy stdcall(cur_img); + $pop eax + cur_img = EAX; + if (!EAX) return false; + } + imgbuf[04] = canvas.bufw; + imgbuf[08] = canvas.bufh; + imgbuf[20] = IMAGE_BPP32; + imgbuf[24] = buf_data+8; + img_blend stdcall(#imgbuf, cur_img, draw_x, img_y, 0, 0, img_w, img_h); + img_destroy stdcall(cur_img); + + draw_x += img_w; + if (draw_x >= draw_w) NewLine(); + return true; +} \ No newline at end of file diff --git a/programs/cmm/browser/TWB/set_style.h b/programs/cmm/browser/TWB/set_style.h index d2d149758f..f99ab3041f 100644 --- a/programs/cmm/browser/TWB/set_style.h +++ b/programs/cmm/browser/TWB/set_style.h @@ -17,21 +17,19 @@ void TWebBrowser::SetStyle() if (tag.is("footer")) { NewLine(); return; } if (tag.is("figure")) { NewLine(); return; } if (tag.is("w:p")) { NewLine(); return; } - if (tag.is("b")) { style.b = tag.opened; return; } - if (tag.is("strong")) { style.b = tag.opened; return; } - if (tag.is("big")) { style.b = tag.opened; return; } - if (tag.is("w:b")) { style.b = tag.opened; return; } - if (tag.is("u")) { style.u = tag.opened; return; } - if (tag.is("ins")) { style.u = tag.opened; return; } - if (tag.is("s")) { style.s = tag.opened; return; } - if (tag.is("strike")) { style.s = tag.opened; return; } - if (tag.is("del")) { style.s = tag.opened; return; } - if (tag.is("pre")) { style.pre = tag.opened; return; } - if (tag.is("blockquote")) { style.blq = tag.opened; return; } + if (tag.is("b")) { style.b = tag.opened; return; } + if (tag.is("strong")) { style.b = tag.opened; return; } + if (tag.is("big")) { style.b = tag.opened; return; } + if (tag.is("w:b")) { style.b = tag.opened; return; } + if (tag.is("u")) { style.u = tag.opened; return; } + if (tag.is("ins")) { style.u = tag.opened; return; } + if (tag.is("s")) { style.s = tag.opened; return; } + if (tag.is("strike")) { style.s = tag.opened; return; } + if (tag.is("del")) { style.s = tag.opened; return; } + if (tag.is("pre")) { style.pre = tag.opened; return; } + if (tag.is("blockquote")) { style.blq = tag.opened; return; } + if (tag.is("button")) { style.button = tag.opened; return; } if (tag.is("dl")) { if (tag.opened) NewLine(); return; } - if (tag.is("tr")) { if (tag.opened) NewLine(); return; } - if (tag.is("td")) { /*if (tag.opened) AddCharToTheLine(' ');*/ return; } - if (tag.is("button")) { style.button = tag.opened; draw_x+=10; return; } if (tag.is("w:r")) { if (!tag.opened) style.b = false; return; } if (tag.is("h1")) { tag_h1234_caption(); return; } if (tag.is("h2")) { tag_h1234_caption(); return; } @@ -52,6 +50,13 @@ void TWebBrowser::SetStyle() if (tag.is("title")) { tag_title(); return; } if (tag.is("body")) { tag_body(); return; } if (tag.is("html")) { t_html = tag.opened; return; } + + //TO BE REWORKED + //td_x = td_w = tr_y = highest_td = 0; + //if (tag.is("table")) { tag_table(); return; } + //if (tag.is("td")) { tag_td(); return; } + //if (tag.is("tr")) { tag_tr(); return; } + if (tag.is("dd")) { //NewLine(); //if (tag.opened) stolbec += 5; //may overflow! @@ -105,12 +110,12 @@ void TWebBrowser::tag_iframe() if (tag.get_value_of("src")) { NewLine(); strcpy(#line, "IFRAME: "); - Paint(); + Render(); link=true; links.add_link(tag.value); strncpy(#line, tag.value, sizeof(line)-1); while (CheckForLineBreak()) {}; - Paint(); + Render(); link=false; NewLine(); } @@ -180,11 +185,11 @@ void TWebBrowser::tag_li() if (!style.pre) NewLine(); if (style.tag_list.order_type() == 'u') { strcpy(#line, "\31 "); - draw_x = style.tag_list.level * 5 - 2 * list.font_w + BODY_MARGIN; + draw_x = style.tag_list.level * 5 - 2 * list.font_w + left_gap; } if (style.tag_list.order_type() == 'o') { sprintf(#line, "%i. ", style.tag_list.inc_counter()); - draw_x = style.tag_list.level * 5 - 1 - strlen(#line) * list.font_w + BODY_MARGIN; + draw_x = style.tag_list.level * 5 - 1 - strlen(#line) * list.font_w + left_gap; } } } @@ -259,9 +264,7 @@ void TWebBrowser::tag_h1234_caption() void TWebBrowser::tag_img() { char img_path[4096]=0; - dword imgbuf[44]; - dword cur_img; - int img_x, img_y, img_w, img_h; + dword base64img; if (!tag.get_value_of("data-large-image")) if (!tag.get_value_of("data-src")) @@ -271,11 +274,11 @@ void TWebBrowser::tag_img() if (!strstr(tag.value, "base64,")) goto NOIMG; EDX = EAX+7; if (ESBYTE[EDX]==' ') EDX++; - cur_img = malloc(strlen(EDX)); - base64_decode stdcall (EDX, cur_img, strlen(EDX)); - img_decode stdcall (cur_img, EAX, 0); + base64img = malloc(strlen(EDX)); + base64_decode stdcall (EDX, base64img, strlen(EDX)); + img_decode stdcall (base64img, EAX, 0); $push eax - free(cur_img); + free(base64img); $pop eax if (EAX) goto IMGOK; else goto NOIMG; } @@ -300,39 +303,7 @@ void TWebBrowser::tag_img() } IMGOK: - cur_img = EAX; - img_h = ESDWORD[cur_img+8]; - img_w = ESDWORD[cur_img+4]; - - if (img_w + draw_x >= list.w) NewLine(); - img_y = draw_y; - if (img_h < list.item_h) img_y += list.item_h - img_h / 2 - 1; else img_y -= 2; - style.cur_line_h = math.max(style.cur_line_h, img_h); - - img_w = math.min(img_w, canvas.bufw - draw_x); - - if (link) links.add_text(draw_x + list.x, img_y + list.y, img_w, img_h, 0); - - if (img_y + img_h >= canvas.bufh) canvas.IncreaseBufSize(); - - if (ESDWORD[cur_img+20] != IMAGE_BPP32) { - img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0); - $push eax - img_destroy stdcall(cur_img); - $pop eax - cur_img = EAX; - if (!EAX) goto NOIMG; - } - imgbuf[04] = canvas.bufw; - imgbuf[08] = canvas.bufh; - imgbuf[20] = IMAGE_BPP32; - imgbuf[24] = buf_data+8; - img_blend stdcall(#imgbuf, cur_img, draw_x, img_y, 0, 0, img_w, img_h); - img_destroy stdcall(cur_img); - - draw_x += img_w; - if (draw_x >= list.w) NewLine(); - return; + if (RenderImage(EAX)) return; NOIMG: if (tag.get_value_of("title")) || (tag.get_value_of("alt")) { @@ -348,7 +319,62 @@ NOIMG: while (CheckForLineBreak()) {}; text_colors.add(0x9A6F29); style.image = true; - Paint(); + Render(); style.image = false; text_colors.pop(); +} + + + +unsigned tr_y; +unsigned td_x, td_w; +unsigned highest_td; +int table_c=0; + +void TWebBrowser::tag_table() +{ + if (tag.opened) table_c++; else table_c--; +} + +void TWebBrowser::tag_tr() +{ + if (table_c>1) return; + //style.tr = tag.opened; + NewLine(); + draw_w = list.w - left_gap; + left_gap = BODY_MARGIN; + td_w = 0; + if (tag.opened) { + tr_y = draw_y; + } else { + //draw_y = highest_td; + } +} + +void TWebBrowser::tag_td() +{ + if (table_c>1) return; + if (tag.opened) { + NewLine(); + //highest_td = math.max(draw_y, tr_y); + if (tag.get_value_of("width")) td_w = atoi(tag.value); + draw_y = tr_y; + draw_x = left_gap; + debugval("td_w", td_w); + if (td_w > 20) draw_w = td_w; else draw_w = list.w - left_gap; + } else { + left_gap += td_w; + draw_w = list.w - left_gap; + /* + draw_w -= left_gap; + if (left_gap < 0) left_gap = BODY_MARGIN; + if (draw_w < 0) { + left_gap = BODY_MARGIN; + draw_w = list.w - left_gap; + } + debugval("left_gap", left_gap); + */ + } + debugval("td_w", td_w); + debugval("left_gap", left_gap); } \ No newline at end of file diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 45b58cdb40..56178bc9e3 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -41,7 +41,7 @@ // DATA // // // //===================================================// -char version[]="WebView 3.25"; +char version[]="WebView 3.26"; #define DEFAULT_URL URL_SERVICE_HOMEPAGE @@ -231,9 +231,11 @@ void main() http.hfree(); if (http_get_type==PAGE) { history.add(http.cur_url); - cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE); + if (!strchr(http.cur_url, '?')) { + cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE); + } + LoadInternalPage(http.content_pointer, http.content_received); free(http.content_pointer); - LoadInternalPage(cache.current_buf, cache.current_size); } else if (http_get_type==IMG) { _IMG_RES: diff --git a/programs/cmm/browser/const.h b/programs/cmm/browser/const.h index 20f943ca52..ea5e33c463 100644 --- a/programs/cmm/browser/const.h +++ b/programs/cmm/browser/const.h @@ -72,8 +72,6 @@ char buildin_page_test[] = FROM "res/test.htm""\0"; char webview_shared[] = "WEBVIEW"; -#define BASIC_CHAR_W 8 - enum { NEW_TAB=600, ENCODINGS=700, diff --git a/programs/cmm/browser/res/test.htm b/programs/cmm/browser/res/test.htm index 2e949f72d1..2f6625181d 100644 --- a/programs/cmm/browser/res/test.htm +++ b/programs/cmm/browser/res/test.htm @@ -22,6 +22,7 @@ samlib.ru/b UmVirt Conis -lor +LOR opennet -bash.im \ No newline at end of file +bash.im +Leotag X/O \ No newline at end of file