From ce732ebdd3acd160e19143716a67fdf8a0076647 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sat, 21 Mar 2020 14:33:54 +0000 Subject: [PATCH] WebView 1.84: - deny more than 2 empty line breaks - h1 is now bolder than h2, propper align of list items, show buttons, distinct images in text - add hotkeys - improve proceed of urls git-svn-id: svn://kolibrios.org@7742 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 69 +++++-- programs/cmm/TWB/absolute_url.h | 4 +- programs/cmm/TWB/img_cache.h | 21 +-- programs/cmm/TWB/links.h | 4 +- programs/cmm/TWB/unicode_tags.h | 1 + programs/cmm/browser/WebView.c | 193 +++++++++++--------- programs/cmm/browser/history.h | 11 +- programs/cmm/codeview/codeview.c | 2 +- programs/cmm/lib/keyboard.h | 2 + programs/cmm/lib/patterns/http_downloader.h | 2 + programs/cmm/lib/strings.h | 5 - programs/cmm/liza/mail_box.c | 2 +- programs/cmm/pixie2/pixie.c | 4 +- 13 files changed, 194 insertions(+), 126 deletions(-) diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index 17f1ed468e..fc4aa0a413 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -4,12 +4,14 @@ scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0 enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT}; struct _style { -byte +bool b, u, s, h, pre, blq, li, li_tab, + button, + image, align; }; @@ -30,7 +32,7 @@ struct TWebBrowser { } WB1; -byte +bool link, ignor_text, cur_encoding, @@ -91,6 +93,14 @@ void TWebBrowser::DrawStyle() stolbec_len = strlen(#line) * zoom; line_length = stolbec_len * list.font_w; + if (style.image) { + DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xF9DBCB); + } + if (style.button) { + DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc); + DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); + } + DrawBuf.WriteText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line); if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line); if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]); @@ -239,7 +249,10 @@ void TWebBrowser::Perenos() char new_line_text[4096]; if (strlen(#line)*zoom + stolbec < list.column_max) return; perenos_num = strrchr(#line, ' '); - if (!perenos_num) && (strlen(#line)*zoom>list.column_max) perenos_num=list.column_max/zoom; + if (!perenos_num) && (strlen(#line)*zoom>list.column_max) { + perenos_num=list.column_max/zoom; + if (!stolbec)&&(style.pre) draw_y-=list.item_h; //hack to fix https://prnt.sc/rk3kyt + } strcpy(#new_line_text, #line + perenos_num); line[perenos_num] = 0x00; DrawStyle(); @@ -248,9 +261,10 @@ void TWebBrowser::Perenos() } //============================================================================================ void TWebBrowser::SetStyle() { + char img_path[4096]; int left1 = body_magrin + list.x; - byte opened; - byte meta_encoding; + bool opened; + int meta_encoding; if (tag[0] == '/') { opened = 0; @@ -291,8 +305,9 @@ void TWebBrowser::SetStyle() { } } while(GetNextParam()); if (opened) && (cur_encoding==CH_NULL) { - cur_encoding = CH_UTF8; - debugln("Document has no information about encoding, UTF will be used"); + cur_encoding = CH_CP866; + //BufEncode(CH_UTF8); + debugln("Document has no information about encoding!"); } if (opened) { if (strcmp(#header, #version) != 0) { @@ -349,12 +364,33 @@ void TWebBrowser::SetStyle() { if (istag("br")) { NewLine(); return; } if (istag("tr")) { if (opened) NewLine(); return; } if (istag("b")) || (istag("strong")) || (istag("big")) { style.b = opened; return; } + if (istag("button")) { style.button = opened; stolbec++; return; } if (istag("u")) || (istag("ins")) { style.u=opened; return;} if (istag("s")) || (istag("strike")) || (istag("del")) { style.s=opened; return; } if (istag("dd")) { stolbec += 5; return; } if (istag("blockquote")) { style.blq = opened; return; } if (istag("pre")) || (istag("code")) { style.pre = opened; return; } - if (istag("img")) { ImgCache.Images( left1, draw_y, WB1.list.w); return; } + if (istag("img")) { + do{ + if (isattr("src=")) strcpy(#img_path, #val); + if (isattr("alt=")) sprintf(#line, "[%s]", #val); + } while(GetNextParam()); + style.image = true; + text_color_index++; + text_colors[text_color_index] = 0x9A6F29; + if (!line) { + if (!strncmp(#img_path, "data:", 5)) img_path=0; + sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); + line[50]= NULL; + } + if (strlen(#line) + stolbec > list.column_max) Perenos(); + DrawStyle(); + line=0; + text_color_index--; + style.image = false; + //ImgCache.Images( left1, draw_y, WB1.list.w); + return; + } if (istag("h1")) || (istag("h2")) || (istag("h3")) || (istag("caption")) { style.h = opened; if (opened) @@ -366,9 +402,11 @@ void TWebBrowser::SetStyle() { if (isattr("align=")) && (isval("center")) style.align = ALIGN_CENTER; if (isattr("align=")) && (isval("right")) style.align = ALIGN_RIGHT; list.item_h = basic_line_h * 2; + if (istag("h1")) style.b = true; } else { + if (istag("h1")) style.b = false; NewLine(); WB1.zoom=1; WB1.list.font_type = 10011000b; @@ -388,7 +426,8 @@ void TWebBrowser::SetStyle() { if (opened) { NewLine(); - strcpy(#line, "\31 \0"); + strcpy(#line, "\31 "); + stolbec-=2; } return; } @@ -441,8 +480,8 @@ void TWebBrowser::BufEncode(dword set_new_encoding) { strcpy(bufpointer, o_bufpointer); } - debugval("cur_encoding ", cur_encoding); - debugval("set_new_encoding", set_new_encoding); + //debugval("cur_encoding ", cur_encoding); + //debugval("set_new_encoding", set_new_encoding); cur_encoding = set_new_encoding; bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer); } @@ -462,8 +501,16 @@ void TWebBrowser::DrawScroller() void TWebBrowser::NewLine() { dword onleft, ontop; + static int empty_line=0; if (!stolbec) && (draw_y==body_magrin) return; + + if (!stolbec) { + if (empty_line<1) empty_line++; + else return; + } else { + empty_line=0; + } onleft = list.x + body_magrin; ontop = draw_y + list.y; diff --git a/programs/cmm/TWB/absolute_url.h b/programs/cmm/TWB/absolute_url.h index eba0212868..91eff4c05c 100644 --- a/programs/cmm/TWB/absolute_url.h +++ b/programs/cmm/TWB/absolute_url.h @@ -12,7 +12,7 @@ void GetAbsoluteURL(dword in_URL) if (check_is_the_url_absolute(in_URL)) return; - IF (!strcmpn(in_URL,"//", 2)) + IF (!strncmp(in_URL,"//", 2)) { //strcpy(#newurl, "http:"); //strcat(#newurl, in_URL); @@ -21,7 +21,7 @@ void GetAbsoluteURL(dword in_URL) return; } - IF (!strcmpn(in_URL,"./", 2)) in_URL+=2; + IF (!strncmp(in_URL,"./", 2)) in_URL+=2; if (!http.transfer) { strcpy(#newurl, history.current()); diff --git a/programs/cmm/TWB/img_cache.h b/programs/cmm/TWB/img_cache.h index 5e7cfba3d8..5d4767fd4d 100644 --- a/programs/cmm/TWB/img_cache.h +++ b/programs/cmm/TWB/img_cache.h @@ -37,28 +37,13 @@ int ImageCache::GetImage(dword i_path) void ImageCache::Images(dword left1, top1, width1) { dword image; - char img_path[4096], alt[4096]=0; dword imgw=0, imgh=0, img_lines_first=0, cur_pic=0; - do{ - if (isattr("src=")) - { - strcpy(#img_path, #val); - GetAbsoluteURL(#img_path); - cur_pic = GetImage(#img_path); - } - if (isattr("alt=")) - { - strcpy(#alt, "["); - strcat(#alt, #val); - strcat(#alt, "]"); - } + //GetAbsoluteURL(#img_path); + //cur_pic = GetImage(#img_path); - } while(GetNextParam()); - if (!pics[cur_pic].image) { - if (alt) strcat(#line, #alt); //cur_pic = GetImage("/sys/network/noimg.png"); return; } @@ -67,7 +52,7 @@ void ImageCache::Images(dword left1, top1, width1) imgh = DSWORD[pics[cur_pic].image+8]; if (imgw > width1) imgw = width1; - draw_y += imgh + 5; + //draw_y += imgh + 5; TEMPORARY TURN OFF!!! if (top1+imghWB1.list.y+WB1.list.h-10) return; //if all image is out of visible area if (top1 0) @@ -467,92 +466,77 @@ void OpenPage() } } -DrawEditBoxWebView() +void ProcessAnchor() { - int skin_x_offset; - DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color); - DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color); - //address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); - //address_box.offset = 0; - EditBox_UpdateText(#address_box, address_box.flags); - edit_box_draw stdcall(#address_box); - if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51; - img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y); + char anchor[256]; + int anchor_pos; + + anchor_pos = strrchr(#URL, '#')-1; + strlcpy(#anchor, #URL+anchor_pos, sizeof(anchor)); + URL[anchor_pos] = 0x00; + + //#1 + if (URL[0] == NULL) + { + if (anchor[1] == NULL) { + WB1.list.first = 0; + } + else { + if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1); + } + strcpy(#URL, history.current()); + } + //liner.ru#1 + else + { + GetAbsoluteURL(#URL); + OpenPage(); + if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1); + } + + WB1.DrawPage(); + strcpy(#editURL, #URL); + strcat(#editURL, #anchor); + DrawEditBoxWebView(); } - -void ShowPage() +void EventSubmitOmnibox() { - DrawEditBoxWebView(); - if (!bufsize) + if (!editURL[0]) return; + if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') + || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { - if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); - else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); + strcpy(#URL, #editURL); } else { - WB1.Prepare(); + strlcpy(#URL,"http://",7); + strcat(#URL, #editURL); } + ProcessLink(); } -byte UrlExtIs(dword ext) +void EventClickLink() { - if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true; - return false; + strcpy(#URL, PageLinks.GetURL(PageLinks.active)); + GetAbsoluteURL(#URL); + ProcessLink(); } -void DrawProgress() -{ - dword persent; - if (http.transfer == 0) return; - if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10; - DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color); -} - - -void ClickLink() -char anchor[256]; -int anchor_pos; +void ProcessLink() { if (http.transfer > 0) { StopLoading(); history.back(); } - strcpy(#URL, PageLinks.GetURL(PageLinks.active)); - ReplaceSpaceInUrl(); - //#1 - if (URL[0] == '#') - { - if (URL[1] == NULL) { - WB1.list.first = 0; - } - else { - if (anchors.get_anchor_pos(#URL+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#URL+1); - } - strlcpy(#anchor, #URL, sizeof(anchor)); - strcpy(#URL, history.current()); - strcpy(#editURL, #URL); - strcat(#editURL, #anchor); - DrawEditBoxWebView(); - WB1.DrawPage(); - return; - } - //liner.ru#1 - else if (strrchr(#URL, '#')!=0) - { - anchor_pos = strrchr(#URL, '#')-1; - strlcpy(#anchor, #URL+anchor_pos, sizeof(anchor)); - URL[anchor_pos] = 0x00; - OpenPage(); - strcat(#editURL, #anchor); - DrawEditBoxWebView(); - if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1); - WB1.DrawPage(); + + if (strrchr(#URL, '#')!=0) { + ProcessAnchor(); return; } - if (!strncmp(#URL,"mailto:", 7)) + if (!strncmp(#URL,"mailto:", 7)) || (!strncmp(#URL,"tel:", 4)) { notify(#URL); strcpy(#editURL, history.current()); @@ -560,7 +544,10 @@ int anchor_pos; return; } - GetAbsoluteURL(#URL); + if (!strncmp(#URL,"WebView:",8)) { + OpenPage(); + return; + } if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0) { @@ -606,6 +593,48 @@ int anchor_pos; open_in_a_new_window = false; } +void DrawEditBoxWebView() +{ + int skin_x_offset; + DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color); + DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color); + //address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); + //address_box.offset = 0; + EditBox_UpdateText(#address_box, address_box.flags); + edit_box_draw stdcall(#address_box); + if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51; + img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y); +} + + +void ShowPage() +{ + DrawEditBoxWebView(); + if (!bufsize) + { + if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); + else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); + } + else + { + WB1.Prepare(); + } +} + +byte UrlExtIs(dword ext) +{ + if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true; + return false; +} + +void DrawProgress() +{ + dword persent; + if (http.transfer == 0) return; + if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10; + DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color); +} + void EventShowPageMenu(dword _left, _top) { menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE); @@ -626,7 +655,7 @@ void EventUpdateProgressBar() } } -DrawStatusBar(dword _status_text) +void DrawStatusBar(dword _status_text) { status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10; status_text.start_y = Form.cheight - STATUSBAR_H + 3; diff --git a/programs/cmm/browser/history.h b/programs/cmm/browser/history.h index b30f910117..3630c292a7 100644 --- a/programs/cmm/browser/history.h +++ b/programs/cmm/browser/history.h @@ -10,19 +10,26 @@ ShowHistory() strcat(history_pointer, "
Visited pages
"); for (i=0; i"); strcat(history_pointer, history.items.get(i)); strcat(history_pointer, "
"); } - strcat(history_pointer, "
Cached images"); + strcat(history_pointer, "
Cached images
"); for (i=1; i"); + strcat(history_pointer, #pics[i].path); + strcat(history_pointer, "
"); + /* strcat(history_pointer, "
"); strcat(history_pointer, #pics[i].path); + */ } strcat(history_pointer, ""); WB1.LoadInternalPage(history_pointer, strlen(history_pointer)); diff --git a/programs/cmm/codeview/codeview.c b/programs/cmm/codeview/codeview.c index ddf5a515ba..fc8c656c60 100644 --- a/programs/cmm/codeview/codeview.c +++ b/programs/cmm/codeview/codeview.c @@ -242,7 +242,7 @@ void ShowPage() } void DrawStatusBar() {return;}; -void ClickLink() {return;}; +void EventClickLink() {return;}; void EventShowLinkMenu() {return;}; char anchor[256]; diff --git a/programs/cmm/lib/keyboard.h b/programs/cmm/lib/keyboard.h index 5393e627f8..421861ab9e 100644 --- a/programs/cmm/lib/keyboard.h +++ b/programs/cmm/lib/keyboard.h @@ -75,6 +75,7 @@ #define SCAN_CODE_KEY_D 032 #define SCAN_CODE_KEY_E 018 #define SCAN_CODE_KEY_F 033 +#define SCAN_CODE_KEY_J 036 #define SCAN_CODE_KEY_H 035 #define SCAN_CODE_KEY_I 023 #define SCAN_CODE_KEY_L 038 @@ -88,6 +89,7 @@ #define SCAN_CODE_KEY_T 020 #define SCAN_CODE_KEY_U 022 #define SCAN_CODE_KEY_V 047 +#define SCAN_CODE_KEY_W 017 #define SCAN_CODE_KEY_X 045 #define SCAN_CODE_KEY_Y 021 #define SCAN_CODE_KEY_Z 044 diff --git a/programs/cmm/lib/patterns/http_downloader.h b/programs/cmm/lib/patterns/http_downloader.h index cb91f829bb..083939c1a8 100644 --- a/programs/cmm/lib/patterns/http_downloader.h +++ b/programs/cmm/lib/patterns/http_downloader.h @@ -174,6 +174,8 @@ int check_is_the_url_absolute(dword _in) if(!strncmp(_in,"http:",5)) return true; if(!strncmp(_in,"https:",6)) return true; if(!strncmp(_in,"mailto:",7)) return true; + if(!strncmp(_in,"tel:",4)) return true; + if(!strncmp(_in,"#",1)) return true; if(check_is_the_adress_local(_in)) return true; return false; } diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index 400920201d..a5757fb4fb 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -936,9 +936,4 @@ inline signed strcoll(dword text1,text2) ESBYTE[in_str+length]=0; } - -#define strnmov strmovn -#define stricmp strcmpi -#define strcmpn strncmp - #endif \ No newline at end of file diff --git a/programs/cmm/liza/mail_box.c b/programs/cmm/liza/mail_box.c index ffde699382..306e6c8a64 100644 --- a/programs/cmm/liza/mail_box.c +++ b/programs/cmm/liza/mail_box.c @@ -416,6 +416,6 @@ int GetLetterSize_(int number) { } -void ClickLink() { +void EventClickLink() { RunProgram("/sys/network/WebView", PageLinks.GetURL(PageLinks.active)); } \ No newline at end of file diff --git a/programs/cmm/pixie2/pixie.c b/programs/cmm/pixie2/pixie.c index 9b56e97bd7..edb369e3c2 100644 --- a/programs/cmm/pixie2/pixie.c +++ b/programs/cmm/pixie2/pixie.c @@ -76,8 +76,8 @@ enum { int player_run_id; int notify_run_id; -bool repeat; -bool shuffle; +bool repeat=false; +bool shuffle=false; int current_playing_file_n=0;