WebView 1.0 beta 3: fix for special pages, code optimization, remove tabs

git-svn-id: svn://kolibrios.org@4692 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2014-03-23 22:49:49 +00:00
parent d47b6609eb
commit e2062546c2
5 changed files with 78 additions and 87 deletions

View File

@ -247,12 +247,12 @@ void TWebBrowser::Parse(){
line[perenos_num] = 0x00;
if (stroka-1 > list.visible) && (list.first <>0) break 1; //óõîäèì...
DrawPage();
strcpy(#line, #temp);
NewLine(list.x + 5, stroka * 10 + list.y + 5); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
strcpy(#line, #temp);
NewLine(); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
}
DrawPage();
line = NULL;
if (tag) SetTextStyle(list.x + 5, stroka * 10 + list.y + 5); //îáðàáîòêà òåãîâ
if (tag) SetTextStyle(list.x + 5, stroka * list.line_h + list.y + 5); //îáðàáîòêà òåãîâ
tag = parametr = tagparam = ignor_param = NULL;
break;
default:
@ -275,18 +275,15 @@ void TWebBrowser::Parse(){
if (stroka-1 > list.visible) && (list.first <>0) break 1;
DrawPage();
strcpy(#line, #temp);
NewLine(list.x + 5, stroka * 10 + list.y + 5);
NewLine();
}
}
}
DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
NewLine(list.x + 5, stroka * 10 + list.y + 5); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
if (list.visible * 10 + 25 <= list.h)
DrawBar(list.x, list.visible * 10 + list.y + 25, list.w, -list.visible * 10 + list.h - 25, bg_color);
if (stroka * 10 + 5 <= list.h)
DrawBar(list.x, stroka * 10 + list.y + 5, list.w, -stroka * 10 + list.h - 5, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
DrawPage();
NewLine();
DrawBar(list.x, stroka * list.line_h + list.y + 5, list.w, -stroka * list.line_h + list.h - 5, bg_color);
DrawBar(list.x, list.visible * list.line_h + list.y + 4, list.w, -list.visible * list.line_h + list.h - 4, bg_color);
if (list.first == 0) list.count = stroka;
if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
{
@ -334,13 +331,13 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
{
if (opened)
{
NewLine(left1, top1);
NewLine();
strcat(#line, ' \"');
}
if (!opened)
{
chrcat(#line, '\"');
NewLine(left1, top1);
NewLine();
}
}
@ -424,23 +421,23 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
return;
}
if (isTag("br")) {
NewLine(left1, top1);
NewLine();
return;
}
if (isTag("div")) || (isTag("header")) || (isTag("article")) || (isTag("footer")) {
IF(oldtag[0] <>'h') NewLine(left1, top1);
IF(oldtag[0] <>'h') NewLine();
return;
}
if (isTag("p")) {
IF(oldtag[0] == 'h') return;
NewLine(left1, top1);
IF(opened) NewLine(left1, top1 + 10);
NewLine();
IF(opened) NewLine();
return;
}
if(isTag("table")) {
table.active = opened;
NewLine(left1, top1);
NewLine();
if (opened) table.NewTable();
}
@ -453,9 +450,9 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
if (!strcmp(#parametr, "width="))
{
table.col_w[table.cur_col] = atoi(#options);
// NewLine(left1, top1);
// NewLine();
// strcpy(#line, #options);
// NewLine(left1, top1);
// NewLine();
}
} while(GetNextParam());
}
@ -474,7 +471,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
}
else
{
NewLine(left1, top1);
NewLine();
if (table.cur_row == 0) table.max_cols = table.cur_col;
table.cur_row++;
table.max_cols = table.cur_col;
@ -487,7 +484,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
if (opened) text_align = ALIGN_CENTER;
if (!opened)
{
NewLine(left1, top1);
NewLine();
text_align = ALIGN_LEFT;
}
return;
@ -497,15 +494,15 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
if (opened) text_align = ALIGN_RIGHT;
if (!opened)
{
NewLine(left1, top1);
NewLine();
text_align = ALIGN_LEFT;
}
return;
}
*/
if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) {
NewLine(left1, top1);
if (opened) && (stroka>1) NewLine(left1, top1 + 10);
NewLine();
if (opened) && (stroka>1) NewLine();
strcpy(#oldtag, #tag);
if (opened)
{
@ -535,7 +532,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
{
li_text = opened;
IF(opened == 0) return;
NewLine(left1, top1);
NewLine();
return;
}
if (isTag("condition"))
@ -549,7 +546,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
li_text = opened;
if (opened)
{
NewLine(left1, top1);
NewLine();
if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
}
return;
@ -560,7 +557,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
{
li_text = opened;
li_tab--;
NewLine(left1, top1);
NewLine();
} ELSE li_tab++;
if (isTag("dd")) stolbec += 5;
if (isTag("blockquote")) blq_text = opened;
@ -573,9 +570,9 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
return;
}
if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
NewLine(left1, top1);
NewLine();
DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color);
NewLine(left1, top1+list.line_h);
NewLine();
}
if (isTag("img"))
{
@ -617,15 +614,20 @@ void TWebBrowser::DrawScroller()
}
void TWebBrowser::NewLine(int left1, top1)
void TWebBrowser::NewLine()
{
int onleft;
int ontop;
onleft = list.x + 5;
ontop = stroka * list.line_h + list.y + 5;
if (!stroka) DrawBar(list.x, list.y, list.w, 5, bg_color);
if (t_html) && (!t_body) return;
if (top1>=list.y) && ( top1 < list.h+list.y-10) && (!anchor)
if (ontop>=list.y) && ( ontop < list.h+list.y-10) && (!anchor)
{
if (text_align == ALIGN_CENTER) DrawBuf.AlignCenter(left1,top1,list.w,list.line_h,stolbec * 6);
if (text_align == ALIGN_RIGHT) DrawBuf.AlignRight(left1,top1,list.w,list.line_h,stolbec * 6);
DrawBuf.bufy = top1;
if (text_align == ALIGN_CENTER) DrawBuf.AlignCenter(onleft,ontop,list.w,list.line_h,stolbec * 6);
if (text_align == ALIGN_RIGHT) DrawBuf.AlignRight(onleft,ontop,list.w,list.line_h,stolbec * 6);
DrawBuf.bufy = ontop;
DrawBuf.Show();
DrawBuf.Fill(bg_color);
}

View File

@ -29,14 +29,14 @@
char homepage[] = FROM "html\homepage.htm";
#ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.0 Beta 2";
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.0 Beta 3";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
char page_not_found[] = FROM "html\page_not_found_ru.htm";
char accept_language[]= "Accept-Language: ru\n";
#else
char version[]=" Text-based Browser 1.0 Beta 2";
char version[]=" Text-based Browser 1.0 Beta 3";
?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>";
@ -59,10 +59,10 @@ int action_buf;
dword http_transfer = 0;
dword http_buffer;
dword TAB_H = 19;
dword TAB_H = false; //19;
dword TAB_W = 150;
dword TOOLBAR_H = 50;
dword STATUSBAR_H =18;
dword TOOLBAR_H = 31; //50;
dword STATUSBAR_H =16;
dword col_bg = 0xE4DFE1;
dword panel_color = 0xF1F1F1;
dword border_color = 0x9F9F9F;
@ -270,7 +270,7 @@ void SetElementSizes()
address_box.width = Form.cwidth - address_box.left - 25 - 22;
WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 10);
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
}
@ -283,17 +283,20 @@ void Draw_Window()
if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
// tab {
DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
WriteText(4, 6, 0x80, 0, "Index.htm");
if (TAB_H)
{
DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
WriteText(4, 6, 0x80, 0, "Index.htm");
DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
}
else DrawBar(0,0, Form.cwidth,1, col_bg);
// }
DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
SetElementSizes();
DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
@ -307,15 +310,14 @@ void Draw_Window()
img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
// config
DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
ShowPage();
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
//status bar
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
progress_bar.top = Form.cheight - STATUSBAR_H + 4;
DrawProgress();
ShowPage();
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
}
@ -402,7 +404,12 @@ void Scan(int id)
strcpy(#editURL, "http://kolibrios.org/");
case GOTOURL:
case 0x0D: //enter
if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
if ((strncmp(#editURL,"http:",5)!=0) && (editURL[0]!='/') && ((strncmp(#editURL,"WebView:",8)!=0))
{
strcpy(#URL,"http://");
}
else
URL[0] = 0;
strcat(#URL, #editURL);
OpenPage();
return;
@ -554,7 +561,19 @@ void OpenPage()
StopLoading();
strcpy(#editURL, #URL);
BrowserHistory.AddUrl();
if (strncmp(#URL,"WebView:",8)==0) return;
if (strncmp(#URL,"WebView:",8)==0)
{
SetPageDefaults();
if (strcmp(#URL, URL_SERVICE_HOME)==0)
{
WB1.Prepare(#homepage, sizeof(homepage));
}
if (strcmp(#URL, URL_SERVICE_HISTORY)==0)
{
ShowHistory();
}
return;
}
if (strncmp(#URL,"http:",5)==0)
{
img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
@ -590,8 +609,6 @@ void ShowPage()
address_box.offset=0;
edit_box_draw stdcall(#address_box);
if (strcmp(#URL, URL_SERVICE_HOME)==0) WB1.Prepare(#homepage, sizeof(homepage)); else
if (strcmp(#URL, URL_SERVICE_HISTORY)==0) ShowHistory(); else
if (!bufsize)
{
PageLinks.Clear();

View File

@ -5,7 +5,7 @@ ShowHistory()
free(history_pointer);
history_pointer = malloc(64000);
strcat(history_pointer, " <title>History</title><h1>History</h1>");
strcat(history_pointer, "<html><head><title>History</title></head><body><h1>History</h1>");
strcat(history_pointer, "<h2>Visited pages</h2><blockquote><br>");
for (i=1; i<BrowserHistory.links_count; i++)
{
@ -20,8 +20,9 @@ ShowHistory()
{
strcat(history_pointer, "<img src='");
strcat(history_pointer, #pics[i].path);
strcat(history_pointer, "' /><br>");
strcat(history_pointer, "'><br>");
strcat(history_pointer, #pics[i].path);
}
strcat(history_pointer, "</body></html>");
WB1.Prepare(history_pointer, strlen(history_pointer));
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -346,35 +346,6 @@ inline fastcall strttl( EDX)
}while(AL!=0);
}
void trim(char *s)
{
// удаляем пробелы и табы с начала строки:
int i=0,j;
while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\r')||(s[i]=='\n'))
{
i++;
}
if(i>0)
{
for(j=0;j<strlen(s);j++)
{
s[j]=s[j+i];
}
s[j]='\0';
}
// удаляем пробелы и табы с конца строки:
i=strlen(s)-1;
while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\r')||(s[i]=='\n'))
{
i--;
}
if(i<strlen(s)-1)
{
s[i+1]='\0';
}
}
dword itoa( ESI)
{
unsigned char buffer[11];