From 67d3c20b4e223009d0bebe0477c9dd198aa1f2ac Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sat, 5 Dec 2020 23:22:38 +0000 Subject: [PATCH] WebView images support (temporary is off, press F11 to enable) git-svn-id: svn://kolibrios.org@8330 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/img.h | 142 -------------------- programs/cmm/{ => browser}/TWB/TWB.c | 92 +++++++++---- programs/cmm/{ => browser}/TWB/acid_0.1.htm | 0 programs/cmm/{ => browser}/TWB/anchors.h | 0 programs/cmm/{ => browser}/TWB/colors.h | 0 programs/cmm/browser/TWB/img.h | 98 ++++++++++++++ programs/cmm/{ => browser}/TWB/links.h | 2 +- programs/cmm/{ => browser}/TWB/parse_tag.h | 0 programs/cmm/{ => browser}/TWB/pointer.cur | Bin programs/cmm/{ => browser}/TWB/special.h | 0 programs/cmm/{ => browser}/TWB/tag_list.h | 0 programs/cmm/browser/WebView.c | 92 +++++++------ programs/cmm/browser/history.h | 10 +- programs/cmm/lib/collection.h | 5 +- programs/cmm/lib/mouse.h | 2 +- 15 files changed, 223 insertions(+), 220 deletions(-) delete mode 100644 programs/cmm/TWB/img.h rename programs/cmm/{ => browser}/TWB/TWB.c (87%) rename programs/cmm/{ => browser}/TWB/acid_0.1.htm (100%) rename programs/cmm/{ => browser}/TWB/anchors.h (100%) rename programs/cmm/{ => browser}/TWB/colors.h (100%) create mode 100644 programs/cmm/browser/TWB/img.h rename programs/cmm/{ => browser}/TWB/links.h (93%) rename programs/cmm/{ => browser}/TWB/parse_tag.h (100%) rename programs/cmm/{ => browser}/TWB/pointer.cur (100%) rename programs/cmm/{ => browser}/TWB/special.h (100%) rename programs/cmm/{ => browser}/TWB/tag_list.h (100%) diff --git a/programs/cmm/TWB/img.h b/programs/cmm/TWB/img.h deleted file mode 100644 index a3de8b1768..0000000000 --- a/programs/cmm/TWB/img.h +++ /dev/null @@ -1,142 +0,0 @@ - -struct _img -{ - collection url; - collection_int xywh; - int getid; - - void clear(); - dword add_pos(); - bool set_size(); - - dword current_url(); - bool next_url(); - - void draw_all(); - bool draw(); -}; - -void _img::clear() -{ - url.drop(); - xywh.drop(); - getid = 0; -} - -dword _img::add_pos(dword _path, _x, _y) -{ - char full_path[URL_SIZE]; - strncpy(#full_path, _path, URL_SIZE); - get_absolute_url(#full_path, history.current()); - - url.add(#full_path); - xywh.add(_x); - xywh.add(_y); - xywh.add(NULL); - xywh.add(NULL); - return full_path; -} - -bool _img::set_size(dword _buf, _size) -{ - char vvv[1000]; - int w, h; - img_decode stdcall (_buf, _size, 0); - if (EAX) { - EDI = EAX; - w = ESDWORD[EDI+4]; - h = ESDWORD[EDI+8]; - xywh.set(getid*4+2, ESDWORD[EDI+4]); - xywh.set(getid*4+3, ESDWORD[EDI+8]); - sprintf(#vvv, "%s w:%i h:%i", current_url(), w, h); - debugln(#vvv); - } -} - -dword _img::current_url() -{ - return url.get(getid); -} - -bool _img::next_url() -{ - if (getid < url.count-1) { - getid++; - return 1; - } - return 0; -} - -void _img::draw_all(int _x, _y, _start, _height) -{ - int i, img_y; - - for (i=0; i _start) && (img_y < _start + _height) - && (cache.has(url.get(i))) draw(_x, _y, _start, i); - } -} - -bool _img::draw(int _x, _y, _start, i) -{ - libimg_image im; - img_decode stdcall (cache.current_buf, cache.current_size, 0); - if (EAX) { - im.image = EAX; - im.draw(xywh.get(i*4) + _x, xywh.get(i*4+1) - _start + _y, im.w, im.h, 0, 0); - } -} - -/* - -void ImageCache::Images(dword left1, top1, width1) -{ - dword image; - dword imgw=0, imgh=0, img_lines_first=0, cur_pic=0; - - //getting abs url from (#img_path); - //cur_pic = GetImage(#img_path); - - if (!pics[cur_pic].image) - { - //cur_pic = GetImage("/sys/network/noimg.png"); - return; - } - - imgw = DSWORD[pics[cur_pic].image+4]; - imgh = DSWORD[pics[cur_pic].image+8]; - if (imgw > width1) imgw = width1; - - 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 (top1WB1.list.y+WB1.list.h-imgh-5) //if image partly visible (at the bottom) - { - imgh=WB1.list.y+WB1.list.h-top1-5; - } - if (imgh<=0) return; - - img_draw stdcall (pics[cur_pic].image, left1-5, top1, imgw, imgh,0,img_lines_first); - DrawBar(left1+imgw - 5, top1, WB1.list.w-imgw, imgh, page_bg); - DrawBar(WB1.list.x, top1+imgh, WB1.list.w, -imgh % WB1.list.item_h + WB1.list.item_h, page_bg); - if (link) - { - UnsafeDefineButton(left1 - 5, top1, imgw, imgh-1, links.count + 400 + BT_HIDE, 0xB5BFC9); - links.AddText(0, imgw, imgh-1, NOLINE, 1); - WB1.DrawPage(); - } -} - -ImageCache ImgCache; - -*/ - diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/browser/TWB/TWB.c similarity index 87% rename from programs/cmm/TWB/TWB.c rename to programs/cmm/browser/TWB/TWB.c index 5a814a6781..9ae628f295 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/browser/TWB/TWB.c @@ -1,13 +1,13 @@ -#include "..\TWB\colors.h" -#include "..\TWB\anchors.h" -#include "..\TWB\parse_tag.h" -#include "..\TWB\special.h" -#include "..\TWB\img.h" -#include "..\TWB\tag_list.h" +#include "TWB\colors.h" +#include "TWB\anchors.h" +#include "TWB\parse_tag.h" +#include "TWB\special.h" +#include "TWB\img.h" +#include "TWB\tag_list.h" dword page_bg; dword link_color_default; dword link_color_active; -#include "..\TWB\links.h" +#include "TWB\links.h" #define BODY_MARGIN 6 #define BASIC_LINE_H 18 @@ -189,8 +189,8 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ } for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) { - bukva = ESBYTE[bufpos]; - switch (bukva) + //bukva = ESBYTE[bufpos]; + switch (ESBYTE[bufpos]) { case 0x0a: if (style.pre) { @@ -223,11 +223,22 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ } break; case '<': - if (!is_html) goto _default; + if (!is_html) goto _DEFAULT; bufpos++; + switch (ESBYTE[bufpos]) { + case '!': + case '/': + case 'a'...'z': + case 'A'...'Z': + goto _TAG; + default: + goto _DEFAULT; + } + _TAG: if (!strncmp(bufpos,"!--",3)) { bufpos+=3; + //STRSTR while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize) { bufpos++; @@ -245,13 +256,10 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû { bukva = ESBYTE[bufpos]; - if (bukva == '\x9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' '; - if (!ignor_param) && (bukva <>' ') - { + if (__isWhite(bukva)) bukva = ' '; + if (!ignor_param) && (bukva <>' ') { if (strlen(#tag.name)+1 list.column_max) NewLine(); + value = page_img.xywh.get(page_img.url.count-1*4+3); + if (value > list.item_h) {draw_y += value - list.item_h; NewLine();} + + return; + } + } + + if (value = tag.get_value_of("title=")) && (strlen(value) _start) && (img_y < _start + _h) + && (cache.has(url.get(i))) draw(_x, _y, _w, _h, _start, i); + } +} + +bool _img::draw(int _x, _y, _w, _h, _start, i) +{ + int img_x, img_y, img_w, img_h; + img_decode stdcall (cache.current_buf, cache.current_size, 0); + if (EAX) { + EDI = EAX; + + img_x = xywh.get(i*4+0); + img_y = xywh.get(i*4+1); + img_w = math.min(xywh.set(getid*4+2, ESDWORD[EDI+4]), _w - img_x); + img_h = math.min(xywh.set(getid*4+3, ESDWORD[EDI+8]), _h + _start - img_y); + + + img_draw stdcall(EDI, img_x + _x, img_y - _start + _y, img_w, img_h, 0, 0); + free(EDI); + } +} diff --git a/programs/cmm/TWB/links.h b/programs/cmm/browser/TWB/links.h similarity index 93% rename from programs/cmm/TWB/links.h rename to programs/cmm/browser/TWB/links.h index 0c33a9d3ee..7b3b6241f8 100644 --- a/programs/cmm/TWB/links.h +++ b/programs/cmm/browser/TWB/links.h @@ -1,5 +1,5 @@ CustomCursor CursorPointer; -dword CursorFile = FROM "../TWB/pointer.cur"; +dword CursorFile = FROM "TWB/pointer.cur"; #include "..\lib\collection.h" struct PAGE_LINKS { diff --git a/programs/cmm/TWB/parse_tag.h b/programs/cmm/browser/TWB/parse_tag.h similarity index 100% rename from programs/cmm/TWB/parse_tag.h rename to programs/cmm/browser/TWB/parse_tag.h diff --git a/programs/cmm/TWB/pointer.cur b/programs/cmm/browser/TWB/pointer.cur similarity index 100% rename from programs/cmm/TWB/pointer.cur rename to programs/cmm/browser/TWB/pointer.cur diff --git a/programs/cmm/TWB/special.h b/programs/cmm/browser/TWB/special.h similarity index 100% rename from programs/cmm/TWB/special.h rename to programs/cmm/browser/TWB/special.h diff --git a/programs/cmm/TWB/tag_list.h b/programs/cmm/browser/TWB/tag_list.h similarity index 100% rename from programs/cmm/TWB/tag_list.h rename to programs/cmm/browser/TWB/tag_list.h diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 607598e40b..ebf95337c4 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -22,6 +22,7 @@ #include "..\lib\obj\http.h" #include "..\lib\obj\iconv.h" #include "..\lib\obj\proc_lib.h" +#include "..\lib\obj\netcode.h" //useful patterns #include "..\lib\patterns\history.h" @@ -31,13 +32,14 @@ char editbox_icons[] = FROM "res/editbox_icons.raw"; -char version[]="WebView 2.7e"; +char version[]="WebView 2.8 ALPHA PREVIEW"; #include "texts.h" #include "cache.h" #include "show_src.h" bool debug_mode = false; +bool show_images = false; enum { NEW_TAB=600, @@ -68,7 +70,7 @@ _history history; enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB }; -#include "..\TWB\TWB.c" //HTML Parser, a core component +#include "TWB\TWB.c" //HTML Parser, a core component TWebBrowser WB1; @@ -84,7 +86,7 @@ _http http = 0; bool source_mode = false; -progress_bar wv_progress_bar; +progress_bar prbar; char stak[4096]; proc_info Form; @@ -105,12 +107,13 @@ dword http_get_type; void LoadLibraries() { - load_dll(boxlib, #box_lib_init,0); - load_dll(libio, #libio_init,1); - load_dll(libimg, #libimg_init,1); - load_dll(libHTTP, #http_lib_init,1); - load_dll(iconv_lib, #iconv_open,0); - load_dll(Proc_lib, #OpenDialog_init,0); + load_dll(boxlib, #box_lib_init,0); + load_dll(libio, #libio_init,1); + load_dll(libimg, #libimg_init,1); + load_dll(libHTTP, #http_lib_init,1); + load_dll(iconv_lib, #iconv_open,0); + load_dll(netcode_lib, #base64_encode,0); + load_dll(Proc_lib, #OpenDialog_init,0); OpenDialog_init stdcall (#o_dialog); } @@ -156,7 +159,7 @@ void main() if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); scrollbar_v_mouse (#scroll_wv); - if (scroll_wv.delta) { + if (scroll_wv.delta2) { WB1.list.first = scroll_wv.position; WB1.DrawPage(); break; @@ -164,24 +167,24 @@ void main() if (links.hover(WB1.list.y, WB1.list.first)) { - if (mouse.mkm) { + if (mouse.key&MOUSE_MIDDLE) && (mouse.up) { if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { EventClickLink(TARGET_NEW_WINDOW); } else { EventClickLink(TARGET_NEW_TAB); } } - if (mouse.lkm) { + if (mouse.key&MOUSE_LEFT) && (mouse.up) { CursorPointer.Restore(); EventClickLink(TARGET_SAME_TAB); } - if (mouse.pkm) { + if (mouse.key&MOUSE_RIGHT) && (mouse.up) { CursorPointer.Restore(); EventShowLinkMenu(); } } else { CursorPointer.Restore(); - if (mouse.pkm) && (WB1.list.MouseOver(mouse.x, mouse.y)) { + if (mouse.key&MOUSE_RIGHT) && (mouse.up) && (WB1.list.MouseOver(mouse.x, mouse.y)) { EventShowPageMenu(); } } @@ -259,7 +262,7 @@ void main() } else if (http_get_type==IMG) { cache.add(WB1.page_img.current_url(), http.content_pointer, http.content_received, IMG); - WB1.page_img.set_size(http.content_pointer, http.content_received); + WB1.page_img.set_size(WB1.page_img.getid, http.content_pointer, http.content_received); GetImg(); } } @@ -397,6 +400,7 @@ void ProcessEvent(dword id__) case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return; case OPEN_FILE: EventOpenDialog(); return; case SCAN_CODE_F12: EventToggleDebugMode(); return; + case SCAN_CODE_F11: show_images^=1; return; } } @@ -420,10 +424,10 @@ void EventAllTabsClick(dword _n) void EventEditSource() { if (check_is_the_adress_local(history.current())) { - RunProgram("/rd/1/tinypad", history.current()); + RunProgram("/rd/1/quark", history.current()); } else { CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); - if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); + if (!EAX) RunProgram("/rd/1/quark", "/tmp0/1/WebView_tmp.htm"); } } @@ -443,7 +447,7 @@ void EventCopyLinkToClipboard() void StopLoading() { if (http.stop()) pause(10); - wv_progress_bar.value = 0; + prbar.value = 0; DrawOmnibox(); } @@ -494,10 +498,22 @@ bool GetLocalFileData(dword _path) return true; } +void GetUrl(dword _http_url) +{ + char new_url_full[URL_SIZE+1]; + + if (!strncmp(_http_url,"http:",5)) { + http.get(_http_url); + } else if (!strncmp(_http_url,"https://",8)) { + strcpy(#new_url_full, "http://gate.aspero.pro/?site="); + strncat(#new_url_full, _http_url, URL_SIZE); + http.get(#new_url_full); + } +} + void OpenPage(dword _open_URL) { char new_url[URL_SIZE+1]; - char new_url_full[URL_SIZE+1]; int unz_id; StopLoading(); @@ -542,13 +558,7 @@ void OpenPage(dword _open_URL) } http_get_type = PAGE; - if (!strncmp(#new_url,"http:",5)) { - http.get(#new_url); - } else if (!strncmp(#new_url,"https://",8)) { - strcpy(#new_url_full, "http://gate.aspero.pro/?site="); - strncat(#new_url_full, #new_url, URL_SIZE); - http.get(#new_url_full); - } + GetUrl(#new_url); DrawOmnibox(); @@ -703,7 +713,7 @@ void LoadInternalPage(dword _bufdata, _in_bufsize){ } else { WB1.DrawPage(); } - //GetImg(); + GetImg(); } } @@ -715,14 +725,11 @@ bool UrlExtIs(dword base, ext) 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-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB); + dword pct; + if (!http.transfer) return; + if (http_get_type==PAGE) && (prbar.max) pct = prbar.value*30/prbar.max; else pct = 10; + if (http_get_type==IMG) pct = WB1.page_img.getid * 70 / WB1.page_img.url.count + 30; + DrawBar(address_box.left-1, address_box.top+20, pct*address_box.width+16/100, 2, 0x72B7EB); } void EventShowPageMenu() @@ -766,10 +773,10 @@ void ProcessMenuClick() void EventUpdateProgressBar() { - wv_progress_bar.max = http.content_length; - if (wv_progress_bar.value != http.content_received) + prbar.max = http.content_length; + if (prbar.value != http.content_received) { - wv_progress_bar.value = http.content_received; + prbar.value = http.content_received; DrawProgress(); } } @@ -925,21 +932,24 @@ void HandleRedirect() char redirect_url[URL_SIZE]; http.header_field("location", #redirect_url, URL_SIZE); get_absolute_url(#redirect_url, history.current()); - history.back(); + if (http_get_type==PAGE) history.back(); http.hfree(); if (http_get_type==PAGE) OpenPage(#redirect_url); - else if (http_get_type==IMG) http.get(#redirect_url); + else if (http_get_type==IMG) GetUrl(#redirect_url); } dword GetImg() { + if (!show_images) return; while (WB1.page_img.next_url()) { + DrawProgress(); if (cache.has(WB1.page_img.current_url())) continue; http_get_type = IMG; - http.get(WB1.page_img.current_url()); + GetUrl(WB1.page_img.current_url()); return; } DrawOmnibox(); + WB1.ParseHtml(WB1.o_bufpointer, WB1.bufsize); WB1.DrawPage(); } diff --git a/programs/cmm/browser/history.h b/programs/cmm/browser/history.h index a217cc933b..5ae6604741 100644 --- a/programs/cmm/browser/history.h +++ b/programs/cmm/browser/history.h @@ -42,16 +42,10 @@ ShowHistory() strcat(history_pointer, "
Cached images
"); for (i=1; i"); + strcat(history_pointer, "
"); - // strcat(history_pointer, #pics[i].path); + strcat(history_pointer, "'>
"); } strcat(history_pointer, ""); diff --git a/programs/cmm/lib/collection.h b/programs/cmm/lib/collection.h index afdc0eb8d4..befc38eb96 100644 --- a/programs/cmm/lib/collection.h +++ b/programs/cmm/lib/collection.h @@ -16,7 +16,7 @@ struct collection_int void alloc(); void add(); dword get(); - void set(); + dword set(); void swap(); dword len(); dword get_last(); @@ -47,10 +47,11 @@ struct collection_int } -:void collection_int::set(dword pos, _in) { +:dword collection_int::set(dword pos, _in) { while (pos >= count) add(0); EAX = pos * sizeof(dword) + buf; ESDWORD[EAX] = _in; + return ESDWORD[EAX]; } :void collection_int::swap(dword pos1, pos2) { diff --git a/programs/cmm/lib/mouse.h b/programs/cmm/lib/mouse.h index 74a6ec1300..e13e85bcbe 100644 --- a/programs/cmm/lib/mouse.h +++ b/programs/cmm/lib/mouse.h @@ -5,7 +5,7 @@ #define MOUSE_LEFT 001b #define MOUSE_RIGHT 010b #define MOUSE_LR 011b -#define MOUSE_CENTER 100b +#define MOUSE_MIDDLE 100b /** * The structure of the MOUSE