From 8256819a57f2842154a545c9c7a1f1342aa4be58 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sun, 22 Mar 2020 19:50:16 +0000 Subject: [PATCH] WebView 1.9: tweaks for better view, reworked source view git-svn-id: svn://kolibrios.org@7746 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 111 ++++++++++++++---------- programs/cmm/TWB/links.h | 1 + programs/cmm/TWB/parce_tag.h | 50 +---------- programs/cmm/browser/WebView.c | 15 ++-- programs/cmm/browser/download_manager.h | 2 +- programs/cmm/browser/show_src.h | 104 ++++++++++++---------- programs/cmm/codeview/codeview.c | 1 - programs/cmm/examples/collections.c | 6 +- programs/cmm/lib/debug.h | 13 +-- programs/cmm/lib/obj/iconv.h | 7 +- programs/cmm/liza/liza.c | 1 - programs/cmm/liza/mail_box.c | 8 +- programs/cmm/liza/parselist.c | 12 +-- 13 files changed, 150 insertions(+), 181 deletions(-) diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index d38cecaedd..5af0fecdf8 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -22,6 +22,8 @@ struct TWebBrowser { _style style; DrawBufer DrawBuf; int zoom; + bool opened; //is this a "start tag" or "end tag" + void SetPageDefaults(); void Prepare(); void SetStyle(); void DrawStyle(); @@ -36,7 +38,6 @@ struct TWebBrowser { bool link, - ignor_text, cur_encoding, t_html, t_body; @@ -112,8 +113,10 @@ void TWebBrowser::DrawStyle() if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]); if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]); if (link) { - DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, text_colors[text_color_index]); - PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom); //TODO: set bigger underline_h for style.h + if (streq[0]=' ') && (line[1]==NULL) {} else { + DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, text_colors[text_color_index]); + PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom); + } } stolbec += stolbec_len; } @@ -125,14 +128,10 @@ void TWebBrowser::LoadInternalPage(dword bufpos, in_filesize){ Prepare(); } //============================================================================================ -void TWebBrowser::Prepare(){ - word bukva[2]; - dword j; - byte ignor_param; - dword bufpos; - dword line_len; - style.b = style.u = style.s = style.h = style.blq = t_html = t_body = - style.li = link = ignor_text = text_color_index = text_colors[0] = style.li_tab = 0; +void TWebBrowser::SetPageDefaults() +{ + style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = + style.li = link = text_color_index = text_colors[0] = style.li_tab = false; style.align = ALIGN_LEFT; link_color_inactive = 0x0000FF; link_color_active = 0xFF0000; @@ -141,26 +140,23 @@ void TWebBrowser::Prepare(){ DrawBuf.Fill(0, page_bg); PageLinks.Clear(); strcpy(#header, #version); + cur_encoding = CH_NULL; draw_y = body_magrin; stolbec = 0; line = 0; - zoom = 1; - //for plaint text use CP866 for other UTF - if (strstri(bufpointer, "html")!=-1) - { - debugln(" found"); - style.pre = false; - cur_encoding = CH_NULL; - } - else - { - debugln("no "); - style.pre = true; - cur_encoding = CH_NULL; - } + zoom = 1; +} +//============================================================================================ +void TWebBrowser::Prepare(){ + word bukva[2]; + dword j; + bool ignor_param; + dword bufpos; + dword line_len; + SetPageDefaults(); + if (strstri(bufpointer, "0; j--) tag[j]=tag[j-1]; + tag[0] = '/'; + j = strstri(bufpos, #tag); + if (j!=-1) { + bufpos = j; + } + break; + } + if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/ if (tagparam) GetNextParam(); - Perenos(); - DrawStyle(); - line = NULL; - if (tag) SetStyle(); + + if (tag[0] == '/') + { + opened = 0; + strcpy(#tag, #tag+1); + } + else opened = 1; + + if (tag) && (!istag("span")) && (!istag("i")) && (!istag("svg")) { + Perenos(); + DrawStyle(); + line = NULL; + if (tag) SetStyle(); + } strlcpy(#oldtag, #tag, sizeof(oldtag)); tag = attr = tagparam = ignor_param = NULL; break; @@ -270,25 +287,15 @@ void TWebBrowser::Perenos() void TWebBrowser::SetStyle() { char img_path[4096]; int left1 = body_magrin + list.x; - bool opened; int meta_encoding; - if (tag[0] == '/') - { - opened = 0; - strcpy(#tag, #tag+1); - } - else opened = 1; if (istag("html")) { t_html = opened; return; } - if (istag("script")) || (istag("style")) || (istag("binary")) || (istag("select")) { ignor_text = opened; return; } - if (istag("form")) if (!opened) ignor_text = false; if(istag("title")) { if (opened) header=NULL; return; } - if (ignor_text) return; IF(istag("q")) { @@ -360,14 +367,20 @@ void TWebBrowser::SetStyle() { else if (text_color_index > 0) text_color_index--; return; } - if (istag("div")) || (istag("header")) || (istag("article")) || (istag("footer")) { - IF(oldtag[0] != 'h') NewLine(); + if (istag("div")) { + if (streq(#oldtag,"div")) && (opened) return; + NewLine(); + //IF (oldtag[0] != 'h') + return; + } + if (istag("header")) || (istag("article")) || (istag("footer")) || (istag("figure")) { + NewLine(); return; } if (istag("p")) { - IF(oldtag[0] == 'h') return; + IF (oldtag[0] == 'h') || (streq(#oldtag,"td")) || (streq(#oldtag,"p")) return; NewLine(); - IF(opened) NewLine(); + //IF(opened) NewLine(); return; } if (istag("br")) { NewLine(); return; } @@ -383,7 +396,9 @@ void TWebBrowser::SetStyle() { do{ if (isattr("src=")) strcpy(#img_path, #val); if (isattr("alt=")) sprintf(#line, "[%s]", #val); + if (isattr("title=")) sprintf(#line, "[%s]", #val); } while(GetNextParam()); + debugln(#val); style.image = true; text_color_index++; text_colors[text_color_index] = 0x9A6F29; @@ -455,8 +470,10 @@ void TWebBrowser::SetStyle() { $push edi; NewLine(); $pop edi; + draw_y += 10; DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI); NewLine(); + draw_y += 10; return; } if (istag("meta")) || (istag("?xml")) { @@ -477,7 +494,7 @@ void TWebBrowser::SetStyle() { return; } } - +//============================================================================================ void TWebBrowser::BufEncode(dword set_new_encoding) { if (cur_encoding == set_new_encoding) return; diff --git a/programs/cmm/TWB/links.h b/programs/cmm/TWB/links.h index 63fd1ec41c..049c7dfcf9 100644 --- a/programs/cmm/TWB/links.h +++ b/programs/cmm/TWB/links.h @@ -64,6 +64,7 @@ PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, #temp, 0 bool LinksArray::HoverAndProceed(dword mx, my) { int i; + if (!count) return true; for (i=0; ilinks[i].x) && (my>links[i].y) && (mx 0) && ((tagparam[i] == '"') || (tagparam[i] == ' ') || (tagparam[i] == '\'') || (tagparam[i] == '/'))) - { - IF (tagparam[i] == '"') || (tagparam[i] == '\'') kavichki=tagparam[i]; - tagparam[i] = 0x00; - i--; - } - - if (kavichki) - { - i = strrchr(#tagparam, kavichki); - strlcpy(#val, #tagparam + i, sizeof(val)); - } - else - { - WHILE((i > 0) && (tagparam[i] <>'=')) i--; //i=strrchr(#tagparam, '=')+1; - i++; - strlcpy(#val, #tagparam + i, sizeof(val)); - - WHILE (val[0] == ' ') strcpy(#val, #val+1); - ESBYTE[strchr(#val, ' ')] = NULL; - } - tagparam[i] = 0x00; - - FOR ( ; ((tagparam[i] <>' ') && (i > 0); i--) - { - IF (tagparam[i] == '=') //dirty fix (kludge) - tagparam[i + 1] = 0x00; - } - strlcpy(#attr, #tagparam + i + 1, sizeof(attr)); - tagparam[i] = 0x00; - strlwr(#attr); - return 1; -} \ No newline at end of file diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 8ddf16dd1d..9ffeed354c 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -30,7 +30,7 @@ _http http = {0, 0, 0, 0, 0, 0, 0}; #ifdef LANG_RUS -char version[]="Текстовый браузер 1.85"; +char version[]="Текстовый браузер 1.9"; ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" ?define T_LAST_SLIDE "Это последний слайд" char loading[] = "Загрузка страницы...
"; @@ -47,7 +47,7 @@ char link_menu[] = "Копировать ссылку Скачать содержимое ссылки"; #else -char version[]="Text-based Browser 1.85"; +char version[]="Text-based Browser 1.9"; ?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define T_LAST_SLIDE "This slide is the last" char loading[] = "Loading...
"; @@ -88,7 +88,6 @@ dword panel_color = 0xE3E2E2; dword border_color = 0x8C8C8C; bool debug_mode = false; -bool old_tag_parser_mode = false; progress_bar wv_progress_bar; bool souce_mode = false; @@ -115,7 +114,7 @@ enum { #include "download_manager.h" char editURL[sizeof(URL)]; -edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,2,19,19}; +edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,NULL,19,19}; #define SKIN_Y 24 @@ -263,7 +262,7 @@ void SetElementSizes() WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h); WB1.list.wheel_size = 7 * basic_line_h; - WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; + WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; WB1.list.visible = WB1.list.h; if (WB1.list.w!=WB1.DrawBuf.bufw) { WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 800*20); @@ -377,11 +376,6 @@ void ProcessEvent(dword id__) if (debug_mode) notify("'Debug mode ON'-I"); else notify("'Debug mode OFF'-I"); return; - case SCAN_CODE_F11: - old_tag_parser_mode ^= 1; - if (old_tag_parser_mode) notify("'Old tag parser ON'-I"); - else notify("'Old tag parser OFF'-I"); - return; } } @@ -398,6 +392,7 @@ void StopLoading() http.transfer=0; bufsize = 0; bufpointer = free(bufpointer); + pause(10); } wv_progress_bar.value = 0; DrawOmnibox(); diff --git a/programs/cmm/browser/download_manager.h b/programs/cmm/browser/download_manager.h index 2a8d903dba..811b0dcb76 100644 --- a/programs/cmm/browser/download_manager.h +++ b/programs/cmm/browser/download_manager.h @@ -24,7 +24,7 @@ char save_to[4096] = "/tmp0/1/Downloads"; proc_info DL_Form; char downloader_edit[10000]; char filepath[4096]; -edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit)-2,#downloader_edit,0,2,19,19}; +edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit)-2,#downloader_edit,0,ed_focus,19,19}; progress_bar pb = {0, CONX, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; //progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; //progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color; diff --git a/programs/cmm/browser/show_src.h b/programs/cmm/browser/show_src.h index 2eb8a9aa2e..742607e846 100644 --- a/programs/cmm/browser/show_src.h +++ b/programs/cmm/browser/show_src.h @@ -1,10 +1,10 @@ -enum { TAG, OPTION_VALUE, TEXT, COMMENT, INLINE_COMMENT, CODE }; +enum { TAG, OPTION_VALUE, TEXT, COMMENT, SCRIPT}; -//you are butifull, you are butifull dword ShowSource() { - dword new_buf, new_buf_start, i; - int mode; + dword new_buf, new_buf_start, i, j; + int opened_font=0; + int mode = TEXT; if (souce_mode) return; souce_mode = true; @@ -18,70 +18,81 @@ dword ShowSource() switch (ESBYTE[i]) { case '<': - if (mode == COMMENT) - { + if (mode == TEXT) && (!strncmp(i+1,"script", 6)) { + mode = SCRIPT; + strcpy(new_buf, "<script"); opened_font++; + new_buf+=54; + i+=6; + break; + } + if (mode == COMMENT) || (mode == SCRIPT) && (!strncmp(i+1,"/script>", 8)) { + mode = TEXT; + while (opened_font) { + strcpy(new_buf, ""); opened_font--; + new_buf+=7; + } + strcpy(new_buf, "</script>"); + new_buf+=39; + i+=8; + break; + } + if (ESBYTE[i+1]=='!') && (ESBYTE[i+2]=='-') && (ESBYTE[i+3]=='-') { + mode = COMMENT; + strcpy(new_buf, "<"); opened_font++; + new_buf+=21; + break; + } + if (mode == TEXT) { + mode = TAG; + strcpy(new_buf, "<"); opened_font++; + new_buf+=21; + break; + } + if (mode == COMMENT) || (mode == SCRIPT) { strcpy(new_buf, "<"); new_buf+=4; break; } - if (ESBYTE[i+1]=='!') && (ESBYTE[i+2]=='-') && (ESBYTE[i+3]=='-') - { - strcpy(new_buf, "<"); - new_buf+=21; - mode = COMMENT; - break; - } - if (mode != COMMENT) - { - strcpy(new_buf, "<"); - new_buf+=21; - mode = TAG; - break; - } break; case '>': - if (mode == OPTION_VALUE) //fix non-closed quote in TAG - { - strcpy(new_buf, """); - new_buf+=13; - mode = TAG; - break; - } - if (mode == COMMENT) && (ESBYTE[i-1]=='-') && (ESBYTE[i-2]=='-') - { - strcpy(new_buf, ">"); - new_buf+=11; + if (mode == OPTION_VALUE) { //fix non-closed quote in TAG mode = TEXT; + while (opened_font) { + strcpy(new_buf, """); opened_font--; + new_buf+=13; + } break; } - if (mode == COMMENT) - { + if (mode == COMMENT) && (ESBYTE[i-1]=='-') && (ESBYTE[i-2]=='-') { + mode = TEXT; + strcpy(new_buf, ">"); opened_font--; + new_buf+=11; + break; + } + if (mode == COMMENT) || (mode == SCRIPT) { strcpy(new_buf, ">"); new_buf+=4; break; } - if (mode == TAG) - { - strcpy(new_buf, ">"); - new_buf+=11; + if (mode == TAG) { mode = TEXT; + strcpy(new_buf, ">"); opened_font--; + new_buf+=11; break; } break; case '\"': case '\'': - if (mode == TAG) - { - strcpy(new_buf, "'"); - new_buf+=22; + if (mode == TAG) { mode = OPTION_VALUE; + strcpy(new_buf, "'"); opened_font++; + new_buf+=25; break; } - if (mode == OPTION_VALUE) - { - strcpy(new_buf, "'"); - new_buf+=12; + if (mode == OPTION_VALUE) { mode = TAG; + strcpy(new_buf, "'"); opened_font--; + new_buf+=12; break; } default: @@ -96,6 +107,9 @@ dword ShowSource() } /* + +enum { TAG, OPTION_VALUE, TEXT, COMMENT, INLINE_COMMENT, CODE }; + char* C_HL_keywords[] = { "switch", "if", "while", "for", "break", "continue", "return", "else", "union", "typedef", "static", "class", "case", "#include", diff --git a/programs/cmm/codeview/codeview.c b/programs/cmm/codeview/codeview.c index fc8c656c60..14efcff187 100644 --- a/programs/cmm/codeview/codeview.c +++ b/programs/cmm/codeview/codeview.c @@ -41,7 +41,6 @@ dword panel_color = 0xE3E2E2; dword border_color = 0x8C8C8C; bool debug_mode = false; -bool old_tag_parser_mode = false; bool open_in_a_new_window = false; diff --git a/programs/cmm/examples/collections.c b/programs/cmm/examples/collections.c index 72c6ebe06c..7af979a376 100644 --- a/programs/cmm/examples/collections.c +++ b/programs/cmm/examples/collections.c @@ -29,10 +29,12 @@ void test2() ci.add(1); ci.add(2); ci.add(3); - for (i=0; i 0 1 2 3 + debugln("-> 0 1 2 3"); + for (i=0; i 0 1 2 3 ci.count--; ci.count--; ci.add(4); - for (i=0; i 0 1 4 + debugln("-> 0 1 4"); + for (i=0; i 0 1 4 ci.drop(); } \ No newline at end of file diff --git a/programs/cmm/lib/debug.h b/programs/cmm/lib/debug.h index 211beb9506..c98b612f36 100644 --- a/programs/cmm/lib/debug.h +++ b/programs/cmm/lib/debug.h @@ -42,18 +42,13 @@ inline fastcall void debugln( EDX) debugch(10); } -inline void debugi(dword d_int) +:void debugval(dword text,number) { char tmpch[12]; - itoa_(#tmpch, d_int); + debug(text); + debug(": "); + itoa_(#tmpch, number); debugln(#tmpch); } -:void debugval(dword text,number) -{ - debug(text); - debug(": "); - debugi(number); -} - #endif \ No newline at end of file diff --git a/programs/cmm/lib/obj/iconv.h b/programs/cmm/lib/obj/iconv.h index deb5179e07..4033735bcf 100644 --- a/programs/cmm/lib/obj/iconv.h +++ b/programs/cmm/lib/obj/iconv.h @@ -37,10 +37,9 @@ dword ChangeCharset(dword from_chs, to_chs, conv_buf) cd = EAX; if (cd!=0) { - debugln("iconv: something is wrong with stdcall iconv()"); - debugi(cd); - debug("in_len:"); debugi(in_len); - debug("out_len:"); debugi(out_len); + debugval("iconv: something is wrong with stdcall iconv()", cd); + debugval("in_len", in_len); + debugval("out_len", out_len); new_buf = free(new_buf); return 0; } diff --git a/programs/cmm/liza/liza.c b/programs/cmm/liza/liza.c index 8b9ed34c31..3c4d91f764 100644 --- a/programs/cmm/liza/liza.c +++ b/programs/cmm/liza/liza.c @@ -29,7 +29,6 @@ byte letter_icons[sizeof(file "img/letter_icons.raw")] = FROM "img/letter_icons. #include "img/letter_icons.h" _http http = {0}; -bool old_tag_parser_mode = false; bool debug_mode = false; char accept_language[]= "Accept-Language: ru\n"; diff --git a/programs/cmm/liza/mail_box.c b/programs/cmm/liza/mail_box.c index 306e6c8a64..13ecc73546 100644 --- a/programs/cmm/liza/mail_box.c +++ b/programs/cmm/liza/mail_box.c @@ -107,15 +107,15 @@ void MailBoxNetworkProcess() { aim=NULL; break; } - debug("mailsize: "); debugi(mailsize); + debugval("mailsize", mailsize); aim = GET_ANSWER_RETR; debugln("goto GET_ANSWER_RETR"); break; case GET_ANSWER_RETR: - debug("mailsize: "); debugi(mailsize); - debug("mailstart: "); debugi(mailstart); - debug("mailend: "); debugi(mailend); + debugval("mailsize", mailsize); + debugval("mailstart", mailstart); + debugval("mailend", mailend); ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT); if (ticks == 0xffffffff) break; mailend = mailend + ticks; diff --git a/programs/cmm/liza/parselist.c b/programs/cmm/liza/parselist.c index 76e5f7ebe9..4953ef70c9 100644 --- a/programs/cmm/liza/parselist.c +++ b/programs/cmm/liza/parselist.c @@ -123,20 +123,16 @@ void ProcessBase64() int clean_mailstart; b_start = strstr(mailstart, "?B?"); - debug("b_size"); - debugi(b_start); + debugval("b_size", b_start); if (b_start) { b_end = strstr(b_start, "?="); - debug("b_end"); - debugi(b_end); + debugval("b_end", b_end); b_size = b_end - b_start; - debug("b_size"); - debugi(b_size); + debugval("b_size", b_size); b_buf = malloc(b_size); strcpyb(mailstart, b_buf, "?B?", "?="); - debug("b_buf"); - debug(b_buf); + debugval("b_buf", b_buf); base64_decode stdcall (b_buf, b_buf, b_size-3); ConvertToDOS(b_buf, mailstart);