WebView 2.0 beta 1:

- rewrite tag parsing procedure to use collections
- completely refactor TWB component
- fix a couple of issues: broken tabs in <pre>, mishandle of local page not found, anchors memory leak
- so finally all id's and names are included as anchors*
(*some anchors in web still don't work)

git-svn-id: svn://kolibrios.org@7752 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-03-26 00:12:32 +00:00
parent 00d0aad98e
commit d05eee0368
12 changed files with 393 additions and 365 deletions

View File

@ -1,10 +1,14 @@
scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
#include "..\TWB\colors.h"
#include "..\TWB\anchors.h"
#include "..\TWB\parce_tag.h"
#include "..\TWB\absolute_url.h"
char line[500];
#include "..\TWB\unicode_tags.h"
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
struct _style {
bool
bool
b, u, s, h,
pre,
blq,
@ -13,18 +17,19 @@ bool
button,
image,
align;
dword
bg_color;
dword bg_color;
};
struct TWebBrowser {
llist list;
_style style;
DrawBufer DrawBuf;
dword draw_y, stolbec;
int zoom;
bool opened; //is this a "start tag" or "end tag"
dword o_bufpointer;
void SetPageDefaults();
void Prepare();
void AddCharToTheLine();
void ParseHtml();
void SetStyle();
void DrawStyle();
void DrawPage();
@ -34,6 +39,9 @@ struct TWebBrowser {
void BufEncode();
} WB1;
dword link_color_inactive;
dword link_color_active;
dword page_bg;
bool
link,
@ -41,40 +49,19 @@ bool
t_html,
t_body;
#include "..\TWB\img_cache.h"
#include "..\TWB\links.h"
dword bufpointer=0;
dword o_bufpointer=0;
dword bufsize=0;
dword text_colors[300];
dword text_color_index;
dword link_color_inactive;
dword link_color_active;
dword page_bg;
int draw_y;
int stolbec;
int tab_len;
int body_magrin=5;
int body_magrin=6;
int basic_line_h=22;
char URL[10000];
char header[2048];
char line[500];
char tagparam[10000];
char tag[100];
char header[150];
char oldtag[100];
char attr[1200];
char val[4096];
#include "..\TWB\absolute_url.h"
#include "..\TWB\links.h"
#include "..\TWB\anchors.h"
#include "..\TWB\colors.h"
#include "..\TWB\unicode_tags.h"
#include "..\TWB\img_cache.h"
#include "..\TWB\parce_tag.h"
scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
//============================================================================================
void TWebBrowser::DrawStyle()
@ -83,7 +70,7 @@ void TWebBrowser::DrawStyle()
if (!header)
{
strcpy(#header, #line);
strncpy(#header, #line, sizeof(header)-1);
line = 0;
return;
}
@ -138,20 +125,39 @@ void TWebBrowser::SetPageDefaults()
style.bg_color = page_bg;
DrawBuf.Fill(0, page_bg);
PageLinks.Clear();
strcpy(#header, #version);
anchors.clear();
strncpy(#header, #version, sizeof(header)-1);
cur_encoding = CH_NULL;
draw_y = body_magrin;
stolbec = 0;
line = 0;
zoom = 1;
zoom = 1;
if (o_bufpointer) free(o_bufpointer);
o_bufpointer = 0;
}
//============================================================================================
void TWebBrowser::Prepare(){
word bukva[2];
dword j;
bool ignor_param;
dword bufpos;
void TWebBrowser::AddCharToTheLine(unsigned char _char)
{
dword line_len;
if (_char<=15) _char=' ';
line_len = strlen(#line);
if (!style.pre) && (_char == ' ')
{
if (line[line_len-1]==' ') return; //no double spaces
if (!stolbec) && (!line) return; //no paces at the beginning of the line
}
if (line_len < sizeof(line)) chrcat(#line, _char);
CheckForLineBreak();
}
//============================================================================================
void TWebBrowser::ParseHtml(){
word bukva[2];
char unicode_symbol[10];
dword unicode_symbol_result;
dword j;
bool ignor_param=false;
int tab_len;
dword bufpos;
SetPageDefaults();
if (strstri(bufpointer, "<body")==-1) {
t_body = true;
@ -163,34 +169,33 @@ void TWebBrowser::Prepare(){
switch (bukva)
{
case 0x0a:
if (style.pre)
{
if (style.pre) {
DrawStyle();
NewLine();
break;
} else {
AddCharToTheLine(0x0a);
}
goto DEFAULT_MARK;
case '\9':
if (style.pre) //otherwise go to 0x0d
{
tab_len = strlen(#line) % 4;
if (!tab_len) tab_len = 4;
break;
case 0x09:
if (style.pre) {
tab_len = strlen(#line) + stolbec % 4;
if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
for (j=0; j<tab_len; j++;) chrcat(#line,' ');
break;
} else {
AddCharToTheLine(0x09);
}
goto DEFAULT_MARK;
break;
case '&': //&nbsp; and so on
for (j=1, tag=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++)
for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++)
{
bukva = ESBYTE[bufpos+j];
chrcat(#tag, bukva);
chrcat(#unicode_symbol, bukva);
}
if (bukva = GetUnicodeSymbol(#tag)) {
if (bukva = GetUnicodeSymbol(#unicode_symbol)) {
bufpos += j;
CheckForLineBreak();
} else {
bukva = '&';
goto DEFAULT_MARK;
AddCharToTheLine('&');
}
break;
case '<':
@ -205,70 +210,56 @@ void TWebBrowser::Prepare(){
bufpos+=2;
break;
}
tag = attr = tagparam = ignor_param = NULL;
tag.reset();
if (ESBYTE[bufpos] == '/') {
tag.opened = false;
bufpos++;
}
ignor_param=false;
while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
{
bukva = ESBYTE[bufpos];
if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
if (!ignor_param) && (bukva <>' ')
{
if (strlen(#tag)+1<sizeof(tag)) chrcat(#tag, bukva);
if (strlen(#tag.name)+1<sizeof(tag.name)) chrcat(#tag.name, bukva);
}
else
{
ignor_param = true;
if (strlen(#tagparam)+1<sizeof(tagparam)) strcat(#tagparam, #bukva);
// chrncat(#tagparam, bukva, sizeof(tagparam)-1);
if (strlen(#tag.params)+1<sizeof(tag.params)) strcat(#tag.params, #bukva);
// chrncat(#tag.params, bukva, sizeof(tag.params)-1);
}
bufpos++;
}
strlwr(#tag);
strlwr(#tag.name);
// ignore text inside the next tags
if (istag("script")) || (istag("style")) || (istag("binary")) || (istag("select")) {
sprintf(#tagparam, "</%s>", #tag);
j = strstri(bufpos, #tagparam);
if (j!=-1) {
bufpos = j-1;
}
tag = tagparam = NULL;
if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select")) {
sprintf(#tag.params, "</%s>", #tag.name);
j = strstri(bufpos, #tag.params);
if (j!=-1) bufpos = j-1;
break;
}
if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
if (tagparam) GetNextParam();
if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
if (tag.params) tag.parse_params();
if (tag[0] == '/')
{
opened = 0;
strcpy(#tag, #tag+1);
}
else opened = 1;
if (tag) && (!istag("span")) && (!istag("i")) && (!istag("svg")) {
if (tag.name) && (!tag.is("i")) && (!tag.is("svg")) {
CheckForLineBreak();
DrawStyle();
if (tag) SetStyle();
if (tag.name) SetStyle();
}
strlcpy(#oldtag, #tag, sizeof(oldtag)-1);
tag = attr = tagparam = ignor_param = NULL;
strncpy(#oldtag, #tag.name, sizeof(oldtag)-1);
break;
default:
DEFAULT_MARK:
if (bukva<=15) bukva=' ';
line_len = strlen(#line);
if (!style.pre) && (bukva == ' ')
{
if (line[line_len-1]==' ') break; //no double spaces
if (!stolbec) && (!line) break; //no paces at the beginning of the line
}
if (line_len < sizeof(line)) chrcat(#line, bukva);
CheckForLineBreak();
AddCharToTheLine(ESBYTE[bufpos]);
}
}
DrawStyle();
NewLine();
if (list.first == 0) list.count = draw_y;
list.count = draw_y;
DrawPage();
}
//============================================================================================
@ -297,122 +288,115 @@ bool TWebBrowser::CheckForLineBreak()
//============================================================================================
void TWebBrowser::SetStyle() {
char img_path[4096]=0;
int left1 = body_magrin + list.x;
int meta_encoding;
if (istag("html")) {
t_html = opened;
dword value;
if (tag.is("html")) {
t_html = tag.opened;
return;
}
if(istag("title")) {
if (opened) header=NULL;
if(tag.is("title")) {
if (tag.opened) header=NULL;
return;
}
IF(istag("q"))
IF(tag.is("q"))
{
if (opened) {
if (tag.opened) {
meta_encoding = strlen(#line);
if (line[meta_encoding-1] != ' ') chrcat(#line, ' ');
chrcat(#line, '\"');
}
if (!opened) strcat(#line, "\" ");
if (!tag.opened) strcat(#line, "\" ");
return;
}
if (isattr("id=")) || (isattr("name=")) { // TO FIX: works only if the param is the last
anchors.add(#val, draw_y);
if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
anchors.add(value, draw_y);
}
if (istag("body")) {
t_body = opened;
do{
if (isattr("link=")) link_color_inactive = GetColor(#val);
if (isattr("alink=")) link_color_active = GetColor(#val);
if (isattr("text=")) text_colors[0]=GetColor(#val);
if (isattr("bgcolor="))
{
style.bg_color = page_bg = GetColor(#val);
DrawBuf.Fill(0, page_bg);
}
} while(GetNextParam());
if (opened) && (cur_encoding==CH_NULL) {
cur_encoding = CH_CP866;
//BufEncode(CH_UTF8);
debugln("Document has no information about encoding!");
if (tag.is("body")) {
t_body = tag.opened;
if (value = tag.get_value_of("link=")) link_color_inactive = 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("bgcolor=")) {
style.bg_color = page_bg = GetColor(value);
DrawBuf.Fill(0, page_bg);
}
if (opened) {
if (strcmp(#header, #version) != 0) {
if (tag.opened) {
if (cur_encoding==CH_NULL) {
cur_encoding = CH_CP866;
//BufEncode(CH_UTF8);
debugln("Document has no information about encoding!");
}
if (!streq(#header, #version)) {
ChangeCharset(charsets[cur_encoding], "CP866", #header);
sprintf(#header, "%s - %s", #header, #version);
strncat(#header, " - ", sizeof(header)-1);
strncat(#header, #version, sizeof(header)-1);
}
DrawTitle(#header);
}
return;
}
if (istag("a")) {
if (opened)
if (tag.is("a")) {
if (tag.opened)
{
if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
do{
if (isattr("href=")) && (!strstr(#val,"javascript:"))
{
text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1];
link = 1;
text_colors[text_color_index] = link_color_inactive;
PageLinks.AddLink(#val);
}
} while(GetNextParam());
}
else {
if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
{
text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1];
link = 1;
text_colors[text_color_index] = link_color_inactive;
PageLinks.AddLink(value);
}
} else {
link = 0;
IF(text_color_index > 0) text_color_index--;
}
return;
}
if (istag("font")) {
if (tag.is("font")) {
style.bg_color = page_bg;
if (opened)
if (tag.opened)
{
text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1];
do{
if (isattr("color=")) text_colors[text_color_index] = GetColor(#val);
if (isattr("bg=")) style.bg_color = GetColor(#val);
} while(GetNextParam());
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);
}
else if (text_color_index > 0) text_color_index--;
return;
}
if (istag("div")) {
if (streq(#oldtag,"div")) && (opened) return;
if (tag.is("div")) {
if (streq(#oldtag,"div")) && (tag.opened) return;
NewLine();
//IF (oldtag[0] != 'h')
return;
}
if (istag("header")) || (istag("article")) || (istag("footer")) || (istag("figure")) {
if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
NewLine();
return;
}
if (istag("p")) {
if (tag.is("p")) {
IF (oldtag[0] == 'h') || (streq(#oldtag,"td")) || (streq(#oldtag,"p")) return;
NewLine();
//IF(opened) NewLine();
//IF(tag.opened) NewLine();
return;
}
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")) {
do{
if (isattr("src=")) strlcpy(#img_path, #val, sizeof(img_path)-1);
if (isattr("title=")) && (strlen(#val)<sizeof(line)-3) && (val) sprintf(#line, "[%s]", #val);
if (isattr("alt=")) && (strlen(#val)<sizeof(line)-3) && (val) sprintf(#line, "[%s]", #val);
} while(GetNextParam());
if (tag.is("br")) { NewLine(); return; }
if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { style.b = tag.opened; return; }
if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
if (tag.is("dd")) { stolbec += 5; return; }
if (tag.is("blockquote")) { style.blq = tag.opened; return; }
if (tag.is("pre")) || (tag.is("code")) { style.pre = tag.opened; return; }
if (tag.is("img")) {
if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1);
if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
if (!img_path) { line=0; return; }
style.image = true;
text_color_index++;
@ -427,25 +411,27 @@ void TWebBrowser::SetStyle() {
DrawStyle();
text_color_index--;
style.image = false;
//ImgCache.Images( left1, draw_y, WB1.list.w);
//ImgCache.Images( list.x, draw_y, WB1.list.w);
return;
}
if (istag("h1")) || (istag("h2")) || (istag("h3")) || (istag("caption")) {
style.h = opened;
if (opened)
if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
style.h = tag.opened;
if (tag.opened)
{
NewLine();
draw_y += 10;
WB1.zoom=2;
WB1.list.font_type |= 10011001b;
if (isattr("align=")) && (isval("center")) style.align = ALIGN_CENTER;
if (isattr("align=")) && (isval("right")) style.align = ALIGN_RIGHT;
if (value = tag.get_value_of("align=")) {
if (streq(value, "center")) style.align = ALIGN_CENTER;
if (streq(value, "right")) style.align = ALIGN_RIGHT;
}
list.item_h = basic_line_h * 2;
if (istag("h1")) style.b = true;
if (tag.is("h1")) style.b = true;
}
else
{
if (istag("h1")) style.b = false;
if (tag.is("h1")) style.b = false;
NewLine();
WB1.zoom=1;
WB1.list.font_type = 10011000b;
@ -454,15 +440,15 @@ void TWebBrowser::SetStyle() {
}
return;
}
if (istag("dt")) {
style.li = opened;
if (opened) NewLine();
if (tag.is("dt")) {
style.li = tag.opened;
if (tag.opened) NewLine();
return;
}
if (istag("li")) || (istag("dt"))
if (tag.is("li")) || (tag.is("dt"))
{
style.li = opened;
if (opened)
style.li = tag.opened;
if (tag.opened)
{
NewLine();
stolbec = style.li_tab * 5 - 2;
@ -471,17 +457,17 @@ void TWebBrowser::SetStyle() {
}
return;
}
if (istag("ul")) || (istag("ol")) {
if (!opened)
if (tag.is("ul")) || (tag.is("ol")) {
if (!tag.opened)
{
style.li = opened;
style.li = tag.opened;
style.li_tab--;
NewLine();
}
else style.li_tab++;
}
if (istag("hr")) {
if (isattr("color=")) EDI = GetColor(#val); else EDI = 0x999999;
if (tag.is("hr")) {
if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
$push edi;
NewLine();
$pop edi;
@ -491,20 +477,18 @@ void TWebBrowser::SetStyle() {
draw_y += 10;
return;
}
if (istag("meta")) || (istag("?xml")) {
if (tag.is("meta")) || (tag.is("?xml")) {
meta_encoding = CH_NULL;
do{
if (isattr("charset=")) || (isattr("content=")) || (isattr("encoding="))
{
strcpy(#val, #val[strrchr(#val, '=')]); //search in content=
strlwr(#val);
if (isval("utf-8")) || (isval("utf8")) meta_encoding = CH_UTF8;
else if (isval("koi8-r")) || (isval("koi8-u")) meta_encoding = CH_KOI8;
else if (isval("windows-1251")) || (isval("windows1251")) meta_encoding = CH_CP1251;
else if (isval("iso-8859-5")) || (isval("iso8859-5")) meta_encoding = CH_ISO8859_5;
else if (isval("dos")) || (isval("cp-866")) meta_encoding = CH_CP866;
}
} while(GetNextParam());
if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
{
value += strrchr(value, '='); //search in content=
strlwr(value);
if (streq(value,"utf-8")) || (streq(value,"utf8")) meta_encoding = CH_UTF8;
else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251;
else if (streq(value,"dos")) || (streq(value,"cp-866")) meta_encoding = CH_CP866;
else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) meta_encoding = CH_ISO8859_5;
else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) meta_encoding = CH_KOI8;
}
if (meta_encoding!=CH_NULL) BufEncode(meta_encoding);
return;
}
@ -513,13 +497,10 @@ void TWebBrowser::SetStyle() {
void TWebBrowser::BufEncode(dword set_new_encoding)
{
if (cur_encoding == set_new_encoding) return;
if (o_bufpointer==0)
{
if (o_bufpointer==0) {
o_bufpointer = malloc(bufsize);
strcpy(o_bufpointer, bufpointer);
}
else
{
} else {
strcpy(bufpointer, o_bufpointer);
}
//debugval("cur_encoding ", cur_encoding);
@ -566,10 +547,6 @@ void TWebBrowser::NewLine()
if (debug_mode) debugln(NULL);
}
//============================================================================================
bool istag(dword text) { if (!strcmp(#tag,text)) return true; else return false; }
bool isattr(dword text) { if (!strcmp(#attr,text)) return true; else return false; }
bool isval(dword text) { if (!strcmp(#val,text)) return true; else return false; }
//============================================================================================
void TWebBrowser::DrawPage()
{
PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);

View File

@ -3,7 +3,7 @@ void GetAbsoluteURL(dword in_URL)
{
int i;
dword orig_URL = in_URL;
char newurl[sizeof(URL)];
char newurl[URL_SIZE];
while (i=strstr(in_URL, "&amp;"))
{

View File

@ -1,9 +1,11 @@
struct _anchors {
char current_anchor_name[100];
collection anchor_name;
collection anchor_position;
void add();
int get_anchor_pos();
int get_pos_by_name();
void clear();
} anchors;
void _anchors::add(dword _name, _pos)
@ -12,10 +14,20 @@ void _anchors::add(dword _name, _pos)
anchor_position.add(itoa(_pos));
}
int _anchors::get_anchor_pos(dword _get_name)
int _anchors::get_pos_by_name(dword _get_name)
{
dword pos_name = anchor_name.get_pos_by_name(_get_name);
if (pos_name==-1) return -1;
return atoi(anchor_position.get(pos_name));
if (ESBYTE[_get_name]==NULL) return 0;
if (pos_name==-1) {
return -1;
} else {
return atoi(anchor_position.get(pos_name));
}
}
void _anchors::clear()
{
anchor_name.drop();
anchor_position.drop();
}

View File

@ -6,6 +6,9 @@ struct color_spec {
int rgb;
};
dword text_colors[300];
dword text_color_index;
struct color_spec color_specs[] = {
"aliceblue", 0xF0F8FF,
"antiquewhite", 0xFAEBD7,

View File

@ -5,7 +5,7 @@ dword CursorFile = FROM "../TWB/pointer.cur";
#define NOLINE 0
#define UNDERLINE 1
#define MAXLINKS 400
#define MAXLINKS 2000
struct array_link {
dword link;
@ -58,7 +58,7 @@ void LinksArray::Clear()
CursorPointer.Restore();
}
char temp[sizeof(URL)];
char temp[URL_SIZE];
PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, #temp, 0};
bool LinksArray::HoverAndProceed(dword mx, my)

View File

@ -1,55 +1,106 @@
bool GetNextParam()
struct _tag
{
char name[32];
char params[5000];
bool opened;
collection attributes;
collection values;
bool is();
bool reset();
bool parse_params();
bool get_next_param();
dword get_value_of();
} tag;
bool _tag::is(dword _text)
{
if ( !strcmp(#tag.name, _text) ) {
return true;
} else {
return false;
}
}
bool _tag::reset()
{
if (!name) return false;
name = NULL;
opened = true;
attributes.drop();
values.drop();
attributes.add("ZERO");
values.add("NULL");
return true;
}
bool _tag::parse_params()
{
bool result = false;
if (!name) return false;
if (debug_mode) {
debugln(" ");
debugln(" ");
debug("tag: "); debugln(#name);
debug("params: "); debugln(#params);
debugln(" ");
}
while (get_next_param()) {
result = true;
if (debug_mode) {
debug("attribute: "); debugln(attributes.get(attributes.count-1));
debug("value: "); debugln(values.get(values.count-1));
debugln(" ");
}
};
return result;
}
bool _tag::get_next_param()
{
byte quotes = NULL;
int i;
unsigned char val[4000];
unsigned char attr[4000];
if (!params) return false;
if (!tagparam) return false;
i = strlen(#params) - 1;
if (params[i] == '/') i--;
while (i>0) && (__isWhite(params[i])) i--;
if (debug_mode) {
debug("tag: "); debugln(#tag);
debug("tagparam: "); debugln(#tagparam);
}
i = strlen(#tagparam) - 1;
if (tagparam[i] == '/') i--;
while (i>0) && (__isWhite(tagparam[i])) i--;
if (tagparam[i] == '"') || (tagparam[i] == '\'')
if (params[i] == '"') || (params[i] == '\'')
{
//find VAL end
quotes = tagparam[i];
tagparam[i] = '\0'; i--;
//remove quotes
quotes = params[i];
params[i] = EOS;
i--;
//find VAL start and copy
i = strrchr(#tagparam, quotes);
strlcpy(#val, #tagparam + i, sizeof(val)-1);
tagparam[i] = '\0'; i--;
i = strrchr(#params, quotes);
strlcpy(#val, #params + i, sizeof(val)-1);
params[i] = EOS;
i--;
//find ATTR end
while (i > 0) && (tagparam[i] != '=') i--;
tagparam[i+1] = '\0';
while (i > 0) && (params[i] != '=') i--;
params[i+1] = EOS;
}
else
{
//find VAL end
//already have
//find VAL start and copy
while (i > 0) && (tagparam[i] != '=') i--;
while (i > 0) && (params[i] != '=') i--;
i++;
strlcpy(#val, #tagparam + i, sizeof(val)-1);
// tagparam[i] = '\0';
strlcpy(#val, #params + i, sizeof(val)-1);
//find ATTR end
//already have
//already have ATTR end
}
//find ATTR start and copy
while (i>0) && (!__isWhite(tagparam[i])) i--;
strlcpy(#attr, #tagparam + i + 1, sizeof(attr)-1);
tagparam[i] = '\0';
while (i>0) && (!__isWhite(params[i])) i--;
strlcpy(#attr, #params + i + 1, sizeof(attr)-1);
strlwr(#attr);
params[i] = '\0';
//fix case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
i = strchr(#attr,'=');
@ -58,15 +109,18 @@ bool GetNextParam()
ESBYTE[i+1] = '\0';
}
strlwr(#attr);
if (debug_mode) {
debug("val: "); debugln(#val);
debug("attr: "); debugln(#attr);
debugln(" ");
}
attributes.add(#attr);
values.add(#val);
return true;
}
dword _tag::get_value_of(dword _attr_name)
{
int pos = attributes.get_pos_by_name(_attr_name);
if (pos == -1) {
return 0;
} else {
return values.get(pos);
}
}

View File

@ -1,67 +1,53 @@
char *unicode_tags[]={
"nbsp", " ",
"#38", " ",
"#160", " ",
"copy", "(c)",
"#169", "(c)",
char *unicode_symbols[]={
"#32", " ",
"#34", "\"", "quot","\"",
"#38", "&", "amp", "&",
"#39", "'",
"#039","'",
"#60", "<", "lt", "<",
"#62", ">", "gt", ">",
"#91", "[",
"#93", "]",
"#96", "'",
"#149","-",
"#151","-",
"#160"," ", "nbsp", " ",
"#169","(c)", "copy", "(c)",
"#171","<<", "laquo","<<",
"#174","(r)", "reg", "(r)",
"#187",">>", "raquo",">>",
"trade", "[TM]",
"reg", "(r)",
"#174", "(r)",
"bdquo", ",,",
"amp", "&",
"#38", "&",
"lt", "<",
"#60", "<",
"gt", ">",
"#62", ">",
"minus", "-",
"ndash", "-",
"mdash", "-", //--
"#8722", "-",
"#8211", "-",
"#151", "-",
"#149", "-",
"#9642", "-", //square in the middle of the line
"rsquo", "'",
"#39", "'",
"#039", "'",
"#96", "'",
"#1028", "\242",
"#1030", "I",
"#1031", "\244",
"#8211", "-",
"#8217", "'",
"quot", "\"",
"#34", "\"",
"ldquo", "\"",
"rdquo", "\"",
"#8222", "\"",
"#8221", "\"",
"laquo", "<<",
"#171", "<<",
"raquo", ">>",
"#187", ">>",
"#8222", "\"", "ldquo", "\"",
"#8221", "\"", "rdquo", "\"",
"#8470", "N",
"#8722", "-",
"#9642", "-", //square in the middle of the line
"uarr", "\24",
"darr", "\25",
"rarr", "\26",
"larr", "\27",
"#1028", "\242",
"#1030", "I",
"#1031", "\244",
"#8470", "N",
"bull", "\31", //âîîáùå çäåñü òî÷êà
"bull", "\31",
"percnt","%",
"#xfeff", "",
0};
@ -71,18 +57,18 @@ bool GetUnicodeSymbol(dword in_tag)
{
int j, specia1040;
for (j=0; unicode_tags[j]!=0; j+=2;)
for (j=0; unicode_symbols[j]!=0; j+=2;)
{
if (!strcmp(in_tag, unicode_tags[j]))
if (!strcmp(in_tag, unicode_symbols[j]))
{
strcat(#line, unicode_tags[j+1]);
strcat(#line, unicode_symbols[j+1]);
return true;
}
}
specia1040 = atoi(in_tag + 1) - 1040;
if (tag[1] == '1') && (specia1040>=0)
if (ESBYTE[in_tag+1] == '1') && (specia1040>=0)
&& (specia1040<=72) && (strlen(in_tag) == 5)
{
if (strlen(#line)<sizeof(line)-2) {

View File

@ -29,7 +29,7 @@
#include "..\lib\patterns\simple_open_dialog.h"
#ifdef LANG_RUS
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.94";
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 2.0 beta1";
#define T_LOADING "‡ £à㧪  áâà ­¨æë..."
#define T_RENDERING "<22>¥­¤¥à¨­£..."
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
@ -45,7 +45,7 @@ char link_menu[] =
"Š®¯¨à®¢ âì áá뫪ã
ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
#else
char version[]="Text-based Browser 1.94";
char version[]="Text-based Browser 2.0 beta1";
#define T_LOADING "Loading..."
#define T_RENDERING "Rendering..."
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
@ -62,6 +62,8 @@ char link_menu[] =
Download link contents";
#endif
#define URL_SIZE 4000;
dword col_bg = 0xE3E2E2;
dword panel_color = 0xE3E2E2;
dword border_color = 0x8C8C8C;
@ -108,8 +110,9 @@ enum {
char default_dir[] = "/rd/1";
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
char editURL[sizeof(URL)];
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,NULL,19,19};
char URL[URL_SIZE];
char editURL[URL_SIZE];
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,URL_SIZE-2,#editURL,0,NULL,19,19};
#define SKIN_Y 24
@ -181,17 +184,17 @@ void main()
case evKey:
GetKeys();
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_U) EventViewSource();
if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;}
if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;}
if (key_scancode == SCAN_CODE_KEY_T)
|| (key_scancode == SCAN_CODE_KEY_N) RunProgram(#program_path, NULL);
if (key_scancode == SCAN_CODE_KEY_W) ExitProcess();
if (key_scancode == SCAN_CODE_KEY_J) ProcessEvent(DOWNLOAD_MANAGER);
if (key_scancode == SCAN_CODE_KEY_R) ProcessEvent(REFRESH_BUTTON);
if (key_scancode == SCAN_CODE_ENTER) EventSeachWeb();
if (key_scancode == SCAN_CODE_LEFT) ProcessEvent(BACK_BUTTON);
if (key_scancode == SCAN_CODE_RIGHT) ProcessEvent(FORWARD_BUTTON);
|| (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;}
if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;}
if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;}
if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;}
if (key_scancode == SCAN_CODE_LEFT) {ProcessEvent(BACK_BUTTON);break;}
if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;}
if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;}
}
if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
@ -268,7 +271,6 @@ void main()
bufpointer = http.content_pointer;
bufsize = http.content_received;
http.free();
SetPageDefaults();
DrawStatusBar(T_RENDERING);
ShowPage();
DrawStatusBar(NULL);
@ -310,8 +312,10 @@ void draw_window()
img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 102, SKIN_Y);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
if (!header)
if (!header) {
OpenPage();
WB1.DrawScroller();
}
else {
WB1.DrawPage();
DrawOmnibox();
@ -414,14 +418,6 @@ void StopLoading()
DrawOmnibox();
}
void SetPageDefaults()
{
strcpy(#header, #version);
WB1.list.count = WB1.list.first = 0;
cur_encoding = CH_NULL;
if (o_bufpointer) o_bufpointer = free(o_bufpointer);
}
void ReplaceSpaceInUrl() {
int i;
strcpy(#editURL, #URL);
@ -444,9 +440,8 @@ void OpenPage()
history.add(#URL);
if (!strncmp(#URL,"WebView:",8))
{
SetPageDefaults();
if (!strcmp(#URL, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage)-1);
else if (!strcmp(#URL, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help)-1);
if (!strcmp(#URL, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
else if (!strcmp(#URL, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
else {bufsize=0; ShowPage();} //page not found
DrawOmnibox();
@ -459,12 +454,11 @@ void OpenPage()
if (!strncmp(#URL,"http:",5)) {
http.get(#URL);
}
if (!strncmp(#URL,"https://",8)) {
} else if (!strncmp(#URL,"https://",8)) {
sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
http.get(#getUrl);
}
//http.get(#URL);
if (!http.transfer)
{
StopLoading();
@ -477,13 +471,13 @@ void OpenPage()
else
{
file_size stdcall (#URL);
if (EBX)
{
if (EBX) {
bufsize = EBX;
free(bufpointer);
bufpointer = malloc(bufsize);
SetPageDefaults();
ReadFile(0, bufsize, bufpointer, #URL);
} else {
bufsize = bufpointer = 0;
}
ShowPage();
}
@ -492,29 +486,20 @@ void OpenPage()
void ProcessAnchor()
{
char anchor[256];
int anchor_pos;
dword anchor_pos;
anchor_pos = strrchr(#URL, '#')-1;
strlcpy(#anchor, #URL+anchor_pos, sizeof(anchor)-1);
strlcpy(#anchors.current_anchor_name, #URL+anchor_pos, sizeof(anchor)-1);
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);
}
if (URL[0] == NULL) {
//case when URL consists of anchor only
if (anchors.get_pos_by_name(#anchor+1)!=-1) WB1.list.first = anchors.get_pos_by_name(#anchor+1);
strcpy(#URL, history.current());
}
//liner.ru#1
else
{
} else {
GetAbsoluteURL(#URL);
OpenPage();
if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
if (anchors.get_pos_by_name(#anchor+1)!=-1) WB1.list.first = anchors.get_pos_by_name(#anchor+1);
}
WB1.DrawPage();
@ -536,7 +521,7 @@ void EventSubmitOmnibox()
strlcpy(#URL,"http://",7);
strcat(#URL, #editURL);
}
ProcessLink();
OpenPage();
}
void EventClickLink()
@ -628,19 +613,22 @@ void DrawOmnibox()
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 LoadInternalPage(dword bufpos, in_filesize){
bufsize = in_filesize;
bufpointer = bufpos;
void LoadInternalPage(dword _bufpos, _in_filesize){
bufsize = _in_filesize;
if (bufpointer!=_bufpos) free(bufpointer);
bufpointer = malloc(bufsize);
memmov(bufpointer, _bufpos, bufsize);
ShowPage();
}
void ShowPage()
{
WB1.list.first = 0; //scroll page to the top
DrawOmnibox();
if (!bufsize) || (!bufpointer) {
LoadInternalPage(#page_not_found, sizeof(page_not_found)-1);
LoadInternalPage(#page_not_found, sizeof(page_not_found));
}
WB1.Prepare();
WB1.ParseHtml();
if (source_mode) {
source_mode = false;
ShowSource();

View File

@ -36,6 +36,7 @@ proc_info Form;
dword TOOLBAR_H = 40;
dword STATUSBAR_H = 0;
dword col_bg = 0xE3E2E2;
dword panel_color = 0xE3E2E2;
dword border_color = 0x8C8C8C;
@ -49,12 +50,14 @@ enum {
EDIT_SOURCE,
};
#define URL_SIZE 4000;
#include "..\TWB\TWB.c"
#include "show_src.h"
char editURL[sizeof(URL)];
char URL[URL_SIZE];
char editURL[URL_SIZE];
int mouse_twb;
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,URL_SIZE-2,#editURL,#mouse_twb,2,19,19};
#define SKIN_Y 24
@ -179,15 +182,14 @@ void EventGoToPage()
void SetPageDefaults()
{
strcpy(#header, #version);
strncpy(#header, #version, sizeof(header)-1);
WB1.list.count = WB1.list.first = 0;
cur_encoding = CH_NULL;
if (o_bufpointer) o_bufpointer = free(o_bufpointer);
}
void OpenPage()
{
char getUrl[sizeof(URL)];
char getUrl[URL_SIZE];
strcpy(#editURL, #URL);
history.add(#URL);
if (!strncmp(#URL,"CodeView:",8))
@ -236,7 +238,7 @@ void ShowPage()
{
DrawEditBoxWebView();
if (!bufsize) LoadInternalPage(#page_not_found, sizeof(page_not_found));
WB1.Prepare();
WB1.ParseHtml();
}
void DrawStatusBar() {return;};

View File

@ -397,13 +397,17 @@ inline fastcall void strcat( EDI, ESI)
:void strncat(dword dst, src, dword len)
{
while (ESBYTE[dst]) dst++;
while (ESBYTE[dst]) && (len) {
dst++;
len--;
}
while (ESBYTE[src]) && (len) {
ESBYTE[dst] = ESBYTE[src];
dst++;
src++;
len--;
}
ESBYTE[dst] = 0;
}
inline fastcall void chrcat(ESI, DI)

View File

@ -98,6 +98,8 @@ bool open_in_a_new_window = false;
progress_bar wv_progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
#define URL_SIZE 4000;
int http_transfer;
char version[]=" WebView 0.1";
#include "..\TWB\TWB.c"

View File

@ -362,7 +362,7 @@ void InitTWB() {
void DrawLetter() {
bufsize = strlen(mdata);
bufpointer = mdata;
if (bufsize) && (bufpointer) WB1.Prepare();
if (bufsize) && (bufpointer) WB1.ParseHtml();
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff);
}