From 5ea0b92f65b0e31edf68b3ee6212efd5916c4204 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Mon, 1 Jun 2020 22:18:26 +0000 Subject: [PATCH] WebView: - fix unclosed tag - use collection_int for colors - download images, no draw yet git-svn-id: svn://kolibrios.org@8016 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 35 +++++++---- programs/cmm/TWB/colors.h | 9 ++- programs/cmm/TWB/img.h | 83 ++++++++++++++++++++++++-- programs/cmm/browser/WebView.c | 106 +++++++++++++++++---------------- programs/cmm/browser/cache.h | 27 +++++---- programs/cmm/browser/history.h | 12 ++-- programs/cmm/browser/texts.h | 2 - 7 files changed, 179 insertions(+), 95 deletions(-) diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index d0a83c1427..8e0ac95023 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -18,6 +18,7 @@ char line[500]; struct _style { bool b, u, s, h, + font, pre, blq, button, @@ -30,6 +31,7 @@ struct _style { struct TWebBrowser { llist list; _style style; + _img page_img; dword draw_y, stolbec; int zoom; dword o_bufpointer; @@ -95,8 +97,8 @@ void TWebBrowser::Paint() DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); } - text_color__ = text_colors[text_color_index]; - if (link) && (text_colors[text_color_index]==text_colors[0]) text_color__ = link_color_default; + text_color__ = text_colors.get_last(); + if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default; DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL); if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL); @@ -117,7 +119,7 @@ void TWebBrowser::Paint() void TWebBrowser::SetPageDefaults() { style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = - link = text_color_index = text_colors[0] = style.tag_title = false; + link = style.tag_title = style.font = false; style.tag_list.reset(); link_color_default = 0x0000FF; link_color_active = 0xFF0000; @@ -126,6 +128,9 @@ void TWebBrowser::SetPageDefaults() DrawBuf.Fill(0, page_bg); links.clear(); anchors.clear(); + page_img.clear(); + text_colors.drop(); + text_colors.add(0); header = NULL; cur_encoding = CH_CP866; draw_y = BODY_MARGIN; @@ -339,7 +344,7 @@ void TWebBrowser::SetStyle() { t_body = tag.opened; if (value = tag.get_value_of("link=")) link_color_default = GetColor(value); if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value); - if (value = tag.get_value_of("text=")) text_colors[0]=GetColor(value); + if (value = tag.get_value_of("text=")) text_colors.set(0, GetColor(value)); if (value = tag.get_value_of("bgcolor=")) { style.bg_color = page_bg = GetColor(value); DrawBuf.Fill(0, page_bg); @@ -384,19 +389,23 @@ void TWebBrowser::SetStyle() { NewLine(); } if (tag.is("font")) { + style.font = tag.opened; style.bg_color = page_bg; if (tag.opened) { - text_color_index++; - text_colors[text_color_index] = text_colors[text_color_index-1]; - if (value = tag.get_value_of("color=")) text_colors[text_color_index] = GetColor(value); if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value); + if (value = tag.get_value_of("color=")) { + text_colors.add(GetColor(value)); + } else { + text_colors.add(text_colors.get_last()); + } } - else if (text_color_index > 0) text_color_index--; + else text_colors.pop(); return; } if (tag.is("div")) { if (streq(#tag.prior,"div")) && (tag.opened) return; + if (!tag.opened) && (style.font) text_colors.pop(); NewLine(); return; } @@ -435,8 +444,8 @@ void TWebBrowser::SetStyle() { if (value = tag.get_value_of("alt=")) && (strlen(value)'#') return text_colors[0]; + if (ESBYTE[htmlcolor]<>'#') return text_colors.get(0); textlen = strlen(htmlcolor); @@ -177,7 +176,7 @@ dword StrToCol(char* htmlcolor) return color; } - return text_colors[0]; + return text_colors.get(0); } dword GetColor(char* color_str) @@ -192,5 +191,5 @@ dword GetColor(char* color_str) if (!strcmpi(color_str, color_specs[ii].name)) return color_specs[ii].rgb; } - return text_colors[0]; + return text_colors.get(0); } diff --git a/programs/cmm/TWB/img.h b/programs/cmm/TWB/img.h index 072f6f4f6c..fcba9ccdc4 100644 --- a/programs/cmm/TWB/img.h +++ b/programs/cmm/TWB/img.h @@ -1,15 +1,86 @@ -struct img +struct _img { - collection src; - collection_int data; + collection url; collection_int xywh; - void drop(); + collection_int data; + int getid; + dword add(); + void clear(); + dword current_url(); + bool next_url(); + void set_data(); + void draw(); }; -void img::drop() +dword _img::add(dword _path, _x, _y) { - src.drop(); + char full_path[URL_SIZE]; + strncpy(#full_path, _path, URL_SIZE); + GetAbsoluteURL(#full_path, history.current()); + + url.add(#full_path); + xywh.add(_x); + xywh.add(_y); + xywh.add(0); + xywh.add(0); + return full_path; +} + +void _img::clear() +{ + url.drop(); + xywh.drop(); data.drop(); + getid = 0; +} + +dword _img::current_url() +{ + return url.get(getid); +} + +bool _img::next_url() +{ + if (getid < url.count-1) { + getid++; + return 1; + } + return 0; +} + +void _img::set_data(dword _data, _data_len) +{ + data.set(getid, _data); +} + +void DrawLibimgImage(dword _x, _y, _data, _data_len) +{ + libimg_image im; + img_decode stdcall (_data, _data_len, 0); + $or eax, eax + $jz __ERROR__ + + im.image = EAX; + im.set_vars(); + im.draw(_x, _y, im.w, im.h, 0, 0); +__ERROR__: +} + +void _img::draw(int _x, _y, _start, _height) +{ + int i, img_x, img_y; + + for (i=0; i _start) && (img_y < _start + _height) + { + if (cache.has(url.get(i))) + DrawLibimgImage(img_x + _x, img_y-_start + _y, cache.current_buf, cache.current_size); + } + } } /* diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 1d6036eed4..7c0ed4760e 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -1,8 +1,6 @@ //Copyright 2007-2020 by Veliant & Leency //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... -//Licence restriction: compiling this app for WIN32 is forbidden. - #ifndef AUTOBUILD #include "lang.h--" #endif @@ -32,6 +30,10 @@ #include "..\lib\patterns\toolbar_button.h" #include "..\lib\patterns\restart_process.h" +#define URL_SIZE 4000 + +char version[]="WebView 2.65"; + #include "texts.h" #include "cache.h" #include "show_src.h" @@ -64,12 +66,13 @@ enum { TAB_CLOSE_ID = 900 }; +_history history; + enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB }; #include "..\TWB\TWB.c" //HTML Parser, a core component TWebBrowser WB1; -_history history; #include "history.h" @@ -79,10 +82,6 @@ _history history; #define TAB_H 20 dword TOOLBAR_H = PADDING+TSZE+PADDING+2; -#define URL_SIZE 4000 - -int action_buf; - _http http = 0; bool source_mode = false; @@ -106,6 +105,8 @@ char editbox_icons[] = FROM "editbox_icons.raw"; dword shared_url; +dword http_get_type; + void LoadLibraries() { load_dll(boxlib, #box_lib_init,0); @@ -202,7 +203,7 @@ void main() break; case evButton: - ProcessEvent( GetButtonID() ); + ProcessEvent( @GetButtonID() ); break; case evKey: @@ -260,7 +261,8 @@ void main() http.free(); GetAbsoluteURL(#http.redirect_url, history.current()); history.back(); - OpenPage(#http.redirect_url); + if (http_get_type==PAGE) OpenPage(#http.redirect_url); + else if (http_get_type==IMG) http.get(#http.redirect_url); } else { notify("'Too many redirects.' -E"); StopLoading(); @@ -270,8 +272,15 @@ void main() // Loading the page is complete, free resources redirect_count = 0; http.free(); - pages_cache.add(history.current(), http.content_pointer, http.content_received); - LoadInternalPage(http.content_pointer, http.content_received); + if (http_get_type==PAGE) { + cache.add(history.current(), http.content_pointer, http.content_received, PAGE); + LoadInternalPage(http.content_pointer, http.content_received); + } + else if (http_get_type==IMG) { + cache.add(WB1.page_img.current_url(), http.content_pointer, http.content_received, IMG); + WB1.page_img.set_data(cache.data.get_last(), http.content_received); + GetImg(); + } } break; default: @@ -287,44 +296,20 @@ bool ProcessCtrlKeyEvent() { if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) { - case SCAN_CODE_KEY_O: - EventOpenDialog(); - return true; - case SCAN_CODE_KEY_H: - ProcessEvent(VIEW_HISTORY); - return true; - case SCAN_CODE_KEY_U: - EventViewSource(); - return true; - case SCAN_CODE_KEY_T: - EventOpenNewTab(URL_SERVICE_HOMEPAGE); - return true; - case SCAN_CODE_KEY_N: - RunProgram(#program_path, NULL); - return true; - case SCAN_CODE_KEY_J: - ProcessEvent(DOWNLOAD_MANAGER); - return true; - case SCAN_CODE_KEY_R: - ProcessEvent(REFRESH_BUTTON); - return true; - case SCAN_CODE_ENTER: - EventSeachWeb(); - return true; - case SCAN_CODE_LEFT: - ProcessEvent(BACK_BUTTON); - return true; - case SCAN_CODE_RIGHT: - ProcessEvent(FORWARD_BUTTON); - return true; - case SCAN_CODE_KEY_W: - EventCloseActiveTab(); - return true; - case SCAN_CODE_TAB: - EventActivateNextTab(); - return true; + case SCAN_CODE_KEY_O: EventOpenDialog(); return true; + case SCAN_CODE_KEY_H: ProcessEvent(VIEW_HISTORY); return true; + case SCAN_CODE_KEY_U: EventViewSource(); return true; + case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return true; + case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return true; + case SCAN_CODE_KEY_J: ProcessEvent(DOWNLOAD_MANAGER); return true; + case SCAN_CODE_KEY_R: ProcessEvent(REFRESH_BUTTON); return true; + case SCAN_CODE_ENTER: EventSeachWeb(); return true; + case SCAN_CODE_LEFT: ProcessEvent(BACK_BUTTON); return true; + case SCAN_CODE_RIGHT: ProcessEvent(FORWARD_BUTTON); return true; + case SCAN_CODE_KEY_W: EventCloseActiveTab(); return true; + case SCAN_CODE_TAB: EventActivateNextTab(); return true; + default: return false; } - return false; } void SetElementSizes() @@ -462,7 +447,7 @@ void ProcessEvent(dword id__) EventUpdateBrowser(); return; case CLEAR_CACHE: - pages_cache.clear(); + cache.clear(); notify(#clear_cache_ok); EventRefreshPage(); return; @@ -603,9 +588,9 @@ void OpenPage(dword _open_URL) and then halndle it in the propper way. */ - if (pages_cache.has(#new_url)) { + if (cache.has(#new_url)) { //CACHED PAGE - LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size); + LoadInternalPage(cache.current_buf, cache.current_size); } else if (!strncmp(#new_url,"WebView:",8)) { //INTERNAL PAGE @@ -620,6 +605,7 @@ void OpenPage(dword _open_URL) strcpy(#editURL, #new_url); } + http_get_type = PAGE; if (!strncmp(#new_url,"http:",5)) { http.get(#new_url); } else if (!strncmp(#new_url,"https://",8)) { @@ -777,8 +763,9 @@ void LoadInternalPage(dword _bufdata, _in_bufsize){ WB1.custom_encoding = CH_CP866; ShowSource(WB1.bufpointer, _in_bufsize); } else { - WB1.DrawPage(); + WB1.DrawPage(); } + //GetImg(); } } @@ -941,6 +928,9 @@ void DrawStatusBar() ESI = math.min(status_w/6, strlen(links.active_url)); WriteText(10, status_y, 0, sc.work_text, links.active_url); } + if (http.transfer>0) && (http_get_type==IMG) { + // + } DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING); WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets); } @@ -983,4 +973,16 @@ dword GetAbsoluteActiveURL() return 0; } +dword GetImg() +{ + while (WB1.page_img.next_url()) { + if (cache.has(WB1.page_img.current_url())) continue; + http_get_type = IMG; + http.get(WB1.page_img.current_url()); + return; + } + DrawOmnibox(); + WB1.DrawPage(); +} + stop: \ No newline at end of file diff --git a/programs/cmm/browser/cache.h b/programs/cmm/browser/cache.h index 114feddb6e..fcae61ff5e 100644 --- a/programs/cmm/browser/cache.h +++ b/programs/cmm/browser/cache.h @@ -1,17 +1,21 @@ +enum { + PAGE=1, IMG +}; -struct PAGES_CACHE +struct _cache { - dword current_page_buf; - dword current_page_size; + dword current_buf; + dword current_size; collection url; collection_int data; collection_int size; + collection_int type; void add(); bool has(); void clear(); -} pages_cache=0; +} cache=0; -void PAGES_CACHE::add(dword _url, _data, _size) +void _cache::add(dword _url, _data, _size, _type) { dword data_pointer; data_pointer = malloc(_size); @@ -20,25 +24,26 @@ void PAGES_CACHE::add(dword _url, _data, _size) url.add(_url); size.add(_size); + type.add(_type); } -bool PAGES_CACHE::has(dword _link) +bool _cache::has(dword _link) { int pos; pos = url.get_pos_by_name(_link); if (pos != -1) { - current_page_buf = data.get(pos); - current_page_size = size.get(pos); + current_buf = data.get(pos); + current_size = size.get(pos); return true; } return false; } -void PAGES_CACHE::clear() +void _cache::clear() { url.drop(); data.drop(); size.drop(); - current_page_buf = NULL; - current_page_size = NULL; + current_buf = NULL; + current_size = NULL; } \ No newline at end of file diff --git a/programs/cmm/browser/history.h b/programs/cmm/browser/history.h index 5eb2926b86..a217cc933b 100644 --- a/programs/cmm/browser/history.h +++ b/programs/cmm/browser/history.h @@ -30,7 +30,7 @@ ShowHistory() free(history_pointer); history_pointer = malloc(history.items.data_size+256); strcat(history_pointer, HISTORY_HEADER); - for (i=0; i"); - strcat(history_pointer, #pics[i].path); + strcat(history_pointer, cache.url.get(i)); strcat(history_pointer, "
"); // strcat(history_pointer, "
"); // strcat(history_pointer, #pics[i].path); } - */ + strcat(history_pointer, ""); LoadInternalPage(history_pointer, strlen(history_pointer)); } \ No newline at end of file diff --git a/programs/cmm/browser/texts.h b/programs/cmm/browser/texts.h index a4d27c9150..02a5536475 100644 --- a/programs/cmm/browser/texts.h +++ b/programs/cmm/browser/texts.h @@ -1,5 +1,3 @@ -char version[]="WebView 2.61b"; - #ifdef LANG_RUS char buidin_page_error[] = FROM "buidin_pages\\page_not_found_ru.htm""\0"; char buidin_page_home[] = FROM "buidin_pages\\homepage_ru.htm""\0";