WebView 1.92:

- fix crash with <img> tag
- fix links hovering on the header
- update gate.aspero.pro so it toss a redirect location to the browser
- allow websearch with the space in phrase
- allow render pages with <html> without <body> tag
- Ctrl+O to open files via OpenDialog

git-svn-id: svn://kolibrios.org@7748 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-03-23 01:11:31 +00:00
parent 26ac5e5b3f
commit f53868d3c8
3 changed files with 88 additions and 54 deletions

View File

@ -155,6 +155,7 @@ void TWebBrowser::Prepare(){
dword line_len; dword line_len;
SetPageDefaults(); SetPageDefaults();
if (strstri(bufpointer, "<html")==-1) style.pre = true; //show linebreaks for a plaint text if (strstri(bufpointer, "<html")==-1) style.pre = true; //show linebreaks for a plaint text
else if (strstri(bufpointer, "<body")==-1) t_body = true;
for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
{ {
bukva = ESBYTE[bufpos]; bukva = ESBYTE[bufpos];
@ -220,12 +221,12 @@ void TWebBrowser::Prepare(){
// ignore text inside the next tags // ignore text inside the next tags
if (istag("script")) || (istag("style")) || (istag("binary")) || (istag("select")) { if (istag("script")) || (istag("style")) || (istag("binary")) || (istag("select")) {
for (j=10; j>0; j--) tag[j]=tag[j-1]; sprintf(#tagparam, "</%s>", #tag);
tag[0] = '/'; j = strstri(bufpos, #tagparam);
j = strstri(bufpos, #tag);
if (j!=-1) { if (j!=-1) {
bufpos = j; bufpos = j;
} }
tag = tagparam = NULL;
break; break;
} }
@ -243,7 +244,7 @@ void TWebBrowser::Prepare(){
Perenos(); Perenos();
DrawStyle(); DrawStyle();
line = NULL; line = NULL;
if (tag) SetStyle(); if (tag) SetStyle();
} }
strlcpy(#oldtag, #tag, sizeof(oldtag)); strlcpy(#oldtag, #tag, sizeof(oldtag));
tag = attr = tagparam = ignor_param = NULL; tag = attr = tagparam = ignor_param = NULL;
@ -394,11 +395,10 @@ void TWebBrowser::SetStyle() {
if (istag("pre")) || (istag("code")) { style.pre = opened; return; } if (istag("pre")) || (istag("code")) { style.pre = opened; return; }
if (istag("img")) { if (istag("img")) {
do{ do{
if (isattr("src=")) strcpy(#img_path, #val); if (isattr("src=")) strncpy(#img_path, #val, sizeof(img_path)-1);
if (isattr("alt=")) sprintf(#line, "[%s]", #val); if (isattr("alt=")) && (strlen(#val)<sizeof(line)-3) sprintf(#line, "[%s]", #val);
if (isattr("title=")) sprintf(#line, "[%s]", #val); if (isattr("title=")) && (strlen(#val)<sizeof(line)-3) sprintf(#line, "[%s]", #val);
} while(GetNextParam()); } while(GetNextParam());
debugln(#val);
style.image = true; style.image = true;
text_color_index++; text_color_index++;
text_colors[text_color_index] = 0x9A6F29; text_colors[text_color_index] = 0x9A6F29;

View File

@ -67,7 +67,9 @@ bool LinksArray::HoverAndProceed(dword mx, my)
if (!count) return true; if (!count) return true;
for (i=0; i<count; i++) for (i=0; i<count; i++)
{ {
if (mx>links[i].x) && (my>links[i].y) && (mx<links[i].x+links[i].w) && (my<links[i].y+links[i].h) if (mx>links[i].x) && (my>links[i].y)
&& (mx<links[i].x+links[i].w) && (my<links[i].y+links[i].h)
&& (my>WB1.list.y+WB1.list.first)
{ {
if (mouse.lkm) && (mouse.down) { if (mouse.lkm) && (mouse.down) {
DrawRectangle(links[active].x, -WB1.list.first + links[active].y, DrawRectangle(links[active].x, -WB1.list.first + links[active].y,
@ -91,9 +93,9 @@ bool LinksArray::HoverAndProceed(dword mx, my)
if (active==i) return false; if (active==i) return false;
CursorPointer.Load(#CursorFile); CursorPointer.Load(#CursorFile);
CursorPointer.Set(); CursorPointer.Set();
if (links[active].underline) DrawBar(links[active].x, -WB1.list.first + links[active].y if (links[active].underline) DrawUnderline(links[active].x, -WB1.list.first + links[active].y
+ links[active].h, links[active].w, links[active].underline_h, link_color_inactive); + links[active].h, links[active].w, links[active].underline_h, link_color_inactive);
if (links[i].underline) DrawBar(links[i].x, -WB1.list.first + links[i].y if (links[i].underline) DrawUnderline(links[i].x, -WB1.list.first + links[i].y
+ links[i].h, links[i].w, links[i].underline_h, page_bg); + links[i].h, links[i].w, links[i].underline_h, page_bg);
active = i; active = i;
DrawStatusBar(links[active].link); DrawStatusBar(links[active].link);
@ -104,7 +106,7 @@ bool LinksArray::HoverAndProceed(dword mx, my)
{ {
CursorPointer.Restore(); CursorPointer.Restore();
if (links[active].underline) { if (links[active].underline) {
DrawBar(links[active].x, -WB1.list.first + links[active].y + links[active].h,links[active].w, DrawUnderline(links[active].x, -WB1.list.first + links[active].y + links[active].h,links[active].w,
links[active].underline_h, link_color_inactive); links[active].underline_h, link_color_inactive);
} }
DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg); DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
@ -112,4 +114,7 @@ bool LinksArray::HoverAndProceed(dword mx, my)
} }
} }
void DrawUnderline(dword x,y,w,h,color)
{
if (y>WB1.list.y) DrawBar(x,y,w,h,color);
}

View File

@ -22,18 +22,19 @@
#include "..\lib\obj\libimg.h" #include "..\lib\obj\libimg.h"
#include "..\lib\obj\http.h" #include "..\lib\obj\http.h"
#include "..\lib\obj\iconv.h" #include "..\lib\obj\iconv.h"
#include "..\lib\obj\proc_lib.h"
//useful patterns //useful patterns
#include "..\lib\patterns\history.h" #include "..\lib\patterns\history.h"
#include "..\lib\patterns\http_downloader.h" #include "..\lib\patterns\http_downloader.h"
#include "..\lib\patterns\simple_open_dialog.h"
_http http = {0, 0, 0, 0, 0, 0, 0}; _http http = {0, 0, 0, 0, 0, 0, 0};
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.9"; char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.92";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" #define T_LOADING "‡ £à㧪  áâà ­¨æë..."
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" #define T_RENDERING "<22>¥­¤¥à¨­£..."
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0"; char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
char homepage[] = FROM "html\\homepage_ru.htm""\0"; char homepage[] = FROM "html\\homepage_ru.htm""\0";
char help[] = FROM "html\\help_ru.htm""\0"; char help[] = FROM "html\\help_ru.htm""\0";
@ -48,9 +49,8 @@ char link_menu[] =
ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨"; ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
#else #else
char version[]="Text-based Browser 1.9"; char version[]="Text-based Browser 1.9";
?define IMAGES_CACHE_CLEARED "Images cache cleared" #define T_LOADING "Loading..."
?define T_LAST_SLIDE "This slide is the last" #define T_RENDERING "Rendering..."
char loading[] = "Loading...<br>";
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0"; char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
char homepage[] = FROM "html\\homepage_en.htm""\0"; char homepage[] = FROM "html\\homepage_en.htm""\0";
char help[] = FROM "html\\help_en.htm""\0"; char help[] = FROM "html\\help_en.htm""\0";
@ -73,9 +73,6 @@ Download link contents";
proc_info Form; proc_info Form;
//char search_path[]="http://nigma.ru/index.php?s=";
int redirected = 0;
char stak[4096]; char stak[4096];
int action_buf; int action_buf;
@ -90,6 +87,7 @@ dword border_color = 0x8C8C8C;
bool debug_mode = false; bool debug_mode = false;
progress_bar wv_progress_bar; progress_bar wv_progress_bar;
bool souce_mode = false; bool souce_mode = false;
bool open_in_a_new_window = false; bool open_in_a_new_window = false;
@ -102,7 +100,6 @@ enum {
VIEW_SOURCE=1100, VIEW_SOURCE=1100,
EDIT_SOURCE, EDIT_SOURCE,
VIEW_HISTORY, VIEW_HISTORY,
//FREE_IMG_CACHE,
DOWNLOAD_MANAGER, DOWNLOAD_MANAGER,
COPY_LINK_URL=1200, COPY_LINK_URL=1200,
DOWNLOAD_LINK_CONTENTS, DOWNLOAD_LINK_CONTENTS,
@ -113,29 +110,49 @@ enum {
#include "show_src.h" #include "show_src.h"
#include "download_manager.h" #include "download_manager.h"
char default_dir[] = "/rd/1";
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
char editURL[sizeof(URL)]; char editURL[sizeof(URL)];
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,NULL,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 #define SKIN_Y 24
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);
OpenDialog_init stdcall (#o_dialog);
}
void HandleParam()
{
if (param) {
if (param[0]=='-') && (param[1]=='d') {
strcpy(#downloader_edit, #param+3);
CreateThread(#Downloader,#downloader_stak+4092);
ExitProcess();
} else {
strcpy(#URL, #param);
}
} else {
strcpy(#URL, URL_SERVICE_HOMEPAGE);
}
}
void main() void main()
{ {
int redirect_count = 0;
int i; int i;
load_dll(boxlib, #box_lib_init,0); LoadLibraries();
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);
Libimg_LoadImage(#skin, "/sys/toolbar.png");
skin.h = 26;
wv_progress_bar.progress_color = 0x72B7EB;
CreateDir("/tmp0/1/downloads"); CreateDir("/tmp0/1/downloads");
if (param) && (param[0]=='-') && (param[1]=='d') { Libimg_LoadImage(#skin, "/sys/toolbar.png");
strcpy(#downloader_edit, #param+3); HandleParam();
CreateThread(#Downloader,#downloader_stak+4092); skin.h = 26;
ExitProcess();
}
else if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOMEPAGE);
WB1.list.SetFont(8, 14, 10011000b); WB1.list.SetFont(8, 14, 10011000b);
WB1.list.no_selection = true; WB1.list.no_selection = true;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
@ -166,6 +183,7 @@ void main()
case evKey: case evKey:
GetKeys(); GetKeys();
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) { if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
if (key_scancode == SCAN_CODE_KEY_O) EventOpenDialog();
if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY); if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY);
if (key_scancode == SCAN_CODE_KEY_U) ProcessEvent(VIEW_SOURCE); if (key_scancode == SCAN_CODE_KEY_U) ProcessEvent(VIEW_SOURCE);
if (key_scancode == SCAN_CODE_KEY_T) if (key_scancode == SCAN_CODE_KEY_T)
@ -206,24 +224,27 @@ void main()
ProcessEvent(menu.cur_y); ProcessEvent(menu.cur_y);
menu.cur_y = 0; menu.cur_y = 0;
} }
DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0); DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,0,0,0);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
system.color.get();
col_bg = system.color.work;
if (Form.status_window>2) { DrawTitle(#header); break; } if (Form.status_window>2) { DrawTitle(#header); break; }
if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
Draw_Window(); draw_window();
break; break;
case evNetwork: case evNetwork:
if (http.transfer > 0) { if (http.transfer > 0) {
http.receive(); http.receive();
EventUpdateProgressBar(); EventUpdateProgressBar();
DrawStatusBar(T_LOADING);
if (http.receive_result == 0) { if (http.receive_result == 0) {
// Handle redirects // Handle redirects
if (http.status_code >= 300) && (http.status_code < 400) if (http.status_code >= 300) && (http.status_code < 400)
{ {
redirected++; redirect_count++;
if (redirected>5) if (redirect_count>5)
{ {
notify("'Too many redirects.' -E"); notify("'Too many redirects.' -E");
StopLoading(); StopLoading();
@ -233,7 +254,9 @@ void main()
http.handle_redirect(); http.handle_redirect();
http.free(); http.free();
GetAbsoluteURL(#http.redirect_url); GetAbsoluteURL(#http.redirect_url);
debug("Redirect: "); debugln(#http.redirect_url);
history.back(); history.back();
strcpy(#URL, #http.redirect_url);
strcpy(#editURL, #URL); strcpy(#editURL, #URL);
DrawOmnibox(); DrawOmnibox();
OpenPage(); OpenPage();
@ -241,14 +264,16 @@ void main()
} }
break; break;
} }
redirected = 0; redirect_count = 0;
// Loading the page is complete, free resources // Loading the page is complete, free resources
history.add(#URL); history.add(#URL);
bufpointer = http.content_pointer; bufpointer = http.content_pointer;
bufsize = http.content_received; bufsize = http.content_received;
http.free(); http.free();
SetPageDefaults(); SetPageDefaults();
DrawStatusBar(T_RENDERING);
ShowPage(); ShowPage();
DrawStatusBar(NULL);
} }
} }
} }
@ -272,7 +297,7 @@ void SetElementSizes()
void Draw_Window() void draw_window()
{ {
DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color); DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3); DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
@ -326,7 +351,7 @@ void ProcessEvent(dword id__)
if (http.transfer > 0) if (http.transfer > 0)
{ {
StopLoading(); StopLoading();
Draw_Window(); draw_window();
} }
else OpenPage(); else OpenPage();
return; return;
@ -346,11 +371,6 @@ void ProcessEvent(dword id__)
} }
else RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #URL);
return; return;
// case FREE_IMG_CACHE:
// ImgCache.Free();
// notify(IMAGES_CACHE_CLEARED);
// WB1.DrawPage();
// return;
case VIEW_HISTORY: case VIEW_HISTORY:
strcpy(#URL, URL_SERVICE_HISTORY); strcpy(#URL, URL_SERVICE_HISTORY);
OpenPage(); OpenPage();
@ -620,8 +640,7 @@ void ShowPage()
DrawOmnibox(); DrawOmnibox();
if (!bufsize) if (!bufsize)
{ {
if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
} }
else else
{ {
@ -640,7 +659,7 @@ void DrawProgress()
dword persent; dword persent;
if (http.transfer == 0) return; if (http.transfer == 0) return;
if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10; 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); DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, 0x72B7EB);
} }
void EventShowPageMenu(dword _left, _top) void EventShowPageMenu(dword _left, _top)
@ -666,12 +685,22 @@ void EventUpdateProgressBar()
void EventSeachWeb() void EventSeachWeb()
{ {
sprintf(#URL, "https://www.google.com/search?q=%s", #editURL); sprintf(#URL, "https://www.google.com/search?q=%s", #editURL);
replace_char(#URL, ' ', '_', sizeof(URL));
ProcessLink(); ProcessLink();
} }
void EventOpenDialog()
{
OpenDialog_start stdcall (#o_dialog);
if (o_dialog.status) {
strcpy(#URL, #openfile_path);
OpenPage();
}
}
void 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_x = 10;
status_text.start_y = Form.cheight - STATUSBAR_H + 3; status_text.start_y = Form.cheight - STATUSBAR_H + 3;
status_text.area_size_x = Form.cwidth - status_text.start_x -3; status_text.area_size_x = Form.cwidth - status_text.start_x -3;
DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg); DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);