WebView 2.8 beta

git-svn-id: svn://kolibrios.org@8336 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-12-07 18:19:13 +00:00
parent 60c3243924
commit 7a2c280f29
5 changed files with 137 additions and 131 deletions

View File

@ -31,7 +31,7 @@ struct _style {
struct TWebBrowser {
llist list;
_style style;
_img page_img;
_img img;
dword draw_y, stolbec;
int zoom;
dword o_bufpointer;
@ -129,7 +129,7 @@ void TWebBrowser::SetPageDefaults()
DrawBuf.Fill(0, page_bg);
links.clear();
anchors.clear();
page_img.clear();
img.clear();
text_colors.drop();
text_colors.add(0);
header = NULL;
@ -254,10 +254,11 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
ignor_param=false;
while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
//&& (!chrnum(#tag.params,'\"') % 2) //<a title="<small>ATI</small><br>9800xt" href="vgamuseum.ru/9800xt">
{
bukva = ESBYTE[bufpos];
if (__isWhite(bukva)) bukva = ' ';
if (!ignor_param) && (bukva <>' ') {
if (!ignor_param) && (bukva!=' ') {
if (strlen(#tag.name)+1<sizeof(tag.name)) chrcat(#tag.name, bukva);
} else {
ignor_param = true;
@ -450,6 +451,50 @@ void TWebBrowser::SetStyle() {
}
if (tag.is("img")) {
value = tag.get_value_of("src=");
if (!value) goto NOIMG;
strlcpy(#img_path, value, sizeof(img_path)-1);
get_absolute_url(#img_path, history.current());
if (cache.has(#img_path))
{
img_decode stdcall (cache.current_buf, cache.current_size, 0);
if (!EAX) goto NOIMG;
EDI = EAX;
img.w.add(ESDWORD[EDI+4]);
img.h.add(ESDWORD[EDI+8]);
free(EDI);
img.url.add(#img_path);
if (img.w.get_last() / 6 + 1 + stolbec > list.column_max) {
NewLine();
}
img.x.add(stolbec*list.font_w+3);
img.y.add(draw_y);
stolbec += img.w.get_last() / 6 + 1;
if (img.h.get_last() > list.item_h) {
draw_y += img.h.get_last() - list.item_h;
NewLine();
}
if (link) links.add_text(
img.x.get_last() + list.x,
img.y.get_last() + list.y,
img.w.get_last(),
img.h.get_last(),
0);
//debugval(img.url.get_last(), img.y.get_last());
return;
} else {
img.url.add(#img_path);
}
NOIMG:
/*
if (streqrp(value, "data:")) {
@ -460,30 +505,6 @@ void TWebBrowser::SetStyle() {
base64_decode stdcall (#pass_b64, value, strlen(value));
} else
*/
strlcpy(#img_path, value, sizeof(img_path)-1);
if (!img_path) { line=0; return; }
value = page_img.add_pos(#img_path, stolbec+1*list.font_w+3, draw_y);
if (cache.has(value)) {
if (page_img.set_size(page_img.url.count-1, cache.current_buf, cache.current_size)) {
if (link) links.add_text(
stolbec * list.font_w + BODY_MARGIN + list.x,
draw_y + list.y,
page_img.xywh.get(page_img.url.count-1*4+2),
page_img.xywh.get(page_img.url.count-1*4+3),
0);
stolbec += page_img.xywh.get(page_img.url.count-1*4+2) / 6 + 1;
//if (stolbec > 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)<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);
@ -587,7 +608,7 @@ void TWebBrowser::SetStyle() {
value += strrchr(value, '='); //search in content=
if (ESBYTE[value] == '"') value++;
strlwr(value);
if (streqrp(value,"utf-8")) || (streqrp(value,"utf8")) { ChangeEncoding(CH_UTF8); debugln("UTF"); }
if (streqrp(value,"utf-8")) || (streqrp(value,"utf8")) ChangeEncoding(CH_UTF8);
else if (streqrp(value,"windows-1251")) || (streqrp(value,"windows1251")) ChangeEncoding(CH_CP1251);
else if (streqrp(value,"dos")) || (streqrp(value,"cp-866")) ChangeEncoding(CH_CP866);
else if (streqrp(value,"iso-8859-5")) || (streqrp(value,"iso8859-5")) ChangeEncoding(CH_ISO8859_5);
@ -648,7 +669,16 @@ void TWebBrowser::NewLine()
//============================================================================================
void TWebBrowser::DrawPage()
{
int i, img_y;
PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);
page_img.draw_all(list.x, list.y, list.w, list.h, list.first);
DrawScroller();
//img.draw_all(list.x, list.y, list.w, list.h, list.first);
for (i=0; i<img.url.count; i++)
{
img_y = img.y.get(i);
if (img_y + img.h.get(i) > list.first) && (img_y - list.h < list.first)
&& (cache.has(img.url.get(i))) img.draw(list.x, list.y, list.w, list.h, list.first, i);
}
}

View File

@ -2,15 +2,10 @@
struct _img
{
collection url;
collection_int xywh;
int getid;
collection_int x,y,w,h;
void clear();
dword add_pos();
bool set_size();
dword current_url();
bool next_url();
void add();
void draw_all();
bool draw();
@ -19,80 +14,55 @@ struct _img
void _img::clear()
{
url.drop();
xywh.drop();
getid = 0;
x.drop();
y.drop();
w.drop();
h.drop();
}
dword _img::add_pos(dword _path, _x, _y)
void _img::add(dword _path, _x, _y, _w, _h)
{
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 _id, _buf, _size)
{
img_decode stdcall (_buf, _size, 0);
if (EAX) {
EDI = EAX;
xywh.set(_id*4+2, ESDWORD[EDI+4]);
xywh.set(_id*4+3, ESDWORD[EDI+8]);
free(EDI);
return true;
}
return false;
}
//DELTE!!!!!11111111111111111111111111111111111111
dword _img::current_url()
{
return url.get(getid);
}
//DELTE!!!!!11111111111111111111111111111111111111
bool _img::next_url()
{
if (getid < url.count-1) {
getid++;
return 1;
}
return 0;
url.add(_path);
x.add(_x);
y.add(_y);
w.add(_w);
h.add(_h);
}
/*
void _img::draw_all(int _x, _y, _w, _h, _start)
{
int i, img_y;
for (i=0; i<url.count; i++)
{
img_y = xywh.get(i*4 + 1);
img_y = y.get(i);
if (img_y > _start) && (img_y < _start + _h)
if (img_y + h.get(i) > _start) && (img_y - _h < _start)
&& (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;
int img_x, img_y, img_w, img_h, invisible_h=0;
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_x = x.get(i);
img_y = y.get(i);
img_w = math.min(w.set(i, ESDWORD[EDI+4]), _w - img_x);
img_h = math.min(h.set(i, ESDWORD[EDI+8]), _h + _start - img_y);
if (_start > img_y) {
invisible_h = _start - img_y;
img_y = _start;
}
img_draw stdcall(EDI, img_x + _x, img_y - _start + _y, img_w, img_h, 0, 0);
img_draw stdcall(EDI, img_x + _x, img_y - _start + _y, img_w, img_h - invisible_h, 0, invisible_h);
free(EDI);
}
}

View File

@ -33,17 +33,18 @@
#include "..\lib\patterns\toolbar_button.h"
#include "..\lib\patterns\restart_process.h"
#include "const.h"
#include "cache.h"
#include "show_src.h"
//===================================================//
// //
// DATA //
// //
//===================================================//
char version[]="WebView 2.8 BETA";
char version[]="WebView 2.8 ALPHA PREVIEW";
#include "const.h"
#include "cache.h"
#include "show_src.h"
#define DEFAULT_URL URL_SERVICE_HOMEPAGE
bool debug_mode = false;
bool show_images = false;
@ -72,10 +73,13 @@ progress_bar prbar;
char stak[4096];
proc_info Form;
int menu_id=NULL;
#include "tabs.h"
dword cur_img_url;
dword shared_url;
dword http_get_type;
int menu_id=NULL;
char default_dir[] = "/rd/1";
od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" };
@ -83,10 +87,6 @@ char editURL[URL_SIZE+1];
edit_box omnibox_edit = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff,
0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19};
dword shared_url;
dword http_get_type;
//===================================================//
// //
// CODE //
@ -108,7 +108,7 @@ void LoadLibraries()
void HandleParam()
{
if (!param) {
history.add(URL_SERVICE_HOMEPAGE);
history.add(DEFAULT_URL);
} else {
if (!strncmp(#param, "-source ", 8)) {
source_mode = true;
@ -203,8 +203,16 @@ void main()
case evNetwork:
if (http.transfer <= 0) break;
http.receive();
if (http_get_type==PAGE) CheckContentType();
EventUpdateProgressBar();
if (http_get_type==PAGE) {
CheckContentType();
prbar.max = http.content_length;
if (prbar.value != http.content_received) {
prbar.value = http.content_received;
DrawProgress();
}
}
if (http.receive_result != 0) break;
if (http.status_code >= 300) && (http.status_code < 400)
{
@ -226,9 +234,8 @@ void main()
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_size(WB1.page_img.getid, http.content_pointer, http.content_received);
GetImg();
cache.add(cur_img_url, http.content_pointer, http.content_received, IMG);
GetImg(false);
}
}
break;
@ -300,6 +307,7 @@ bool ProcessKeyEvent()
case SCAN_CODE_RIGHT: ProcessButtonClick(FORWARD_BUTTON); return true;
case SCAN_CODE_KEY_W: EventCloseActiveTab(); return true;
case SCAN_CODE_TAB: EventActivateNextTab(); return true;
case SCAN_CODE_F5: EventClearCache(); return;
default: return false;
}
@ -493,17 +501,20 @@ bool GetLocalFileData(dword _path)
return true;
}
void GetUrl(dword _http_url)
bool GetUrl(dword _http_url)
{
char new_url_full[URL_SIZE+1];
if (!strncmp(_http_url,"http:",5)) {
http.get(_http_url);
return true;
} 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);
return true;
}
return false;
}
void OpenPage(dword _open_URL)
@ -537,7 +548,8 @@ void OpenPage(dword _open_URL)
if (cache.has(#new_url)) {
//CACHED PAGE
LoadInternalPage(cache.current_buf, cache.current_size);
if (cache.current_type==PAGE) LoadInternalPage(cache.current_buf, cache.current_size);
else {EventOpenDownloader(#new_url);return;}
} else if (!strncmp(#new_url,"WebView:",8)) {
//INTERNAL PAGE
@ -708,7 +720,7 @@ void LoadInternalPage(dword _bufdata, _in_bufsize){
} else {
WB1.DrawPage();
}
GetImg();
GetImg(true);
}
}
@ -723,7 +735,7 @@ void DrawProgress()
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;
if (http_get_type==IMG) pct = prbar.value * 70 / prbar.max + 30;
DrawBar(omnibox_edit.left-1, omnibox_edit.top+20, pct*omnibox_edit.width+16/100, 2, 0x72B7EB);
}
@ -766,16 +778,6 @@ void ProcessMenuClick()
}
}
void EventUpdateProgressBar()
{
prbar.max = http.content_length;
if (prbar.value != http.content_received)
{
prbar.value = http.content_received;
DrawProgress();
}
}
void EventSeachWeb()
{
char new_url[URL_SIZE+1];
@ -890,9 +892,7 @@ void DrawOmnibox()
void SetOmniboxText(dword _text)
{
strcpy(#editURL, _text);
omnibox_edit.flags=0;
DrawOmnibox();
edit_box_set_text stdcall (#omnibox_edit, _text);
}
dword GetAbsoluteActiveURL()
@ -929,16 +929,22 @@ void HandleRedirect()
else if (http_get_type==IMG) GetUrl(#redirect_url);
}
dword GetImg()
dword GetImg(bool _new)
{
int i;
if (!show_images) return;
while (WB1.page_img.next_url()) {
DrawProgress();
if (cache.has(WB1.page_img.current_url())) continue;
http_get_type = IMG;
GetUrl(WB1.page_img.current_url());
return;
http_get_type = IMG;
for (i = 0; i < WB1.img.url.count; i++)
{
cur_img_url = WB1.img.url.get(i);
if (cache.has(cur_img_url)==false) {
prbar.max = WB1.img.url.count;
prbar.value = i;
if (GetUrl(cur_img_url)) {DrawProgress(); return;}
}
}
if (_new) return;
DrawOmnibox();
WB1.ParseHtml(WB1.o_bufpointer, WB1.bufsize);
WB1.DrawPage();

View File

@ -6,6 +6,7 @@ struct _cache
{
dword current_buf;
dword current_size;
dword current_type;
collection url;
collection_int data;
collection_int size;
@ -34,6 +35,7 @@ bool _cache::has(dword _link)
if (pos != -1) {
current_buf = data.get(pos);
current_size = size.get(pos);
current_type = type.get(pos);
return true;
}
return false;

View File

@ -188,15 +188,13 @@ void properties_dialog()
else
{
GetFileInfo(#file_path, #file_info_general);
strcpy(#file_name2, #file_name);
EditBox_UpdateText(#file_name_ed, 0);
edit_box_set_text stdcall (#file_name_ed, #file_name);
if(itdir) dir_size.get(#file_path);
ch_read_only.checked = file_info_general.readonly;
ch_hidden.checked = file_info_general.hidden;
ch_system.checked = file_info_general.system;
}
strcpy(#path_to_file, #path);
path_to_file_ed.size = strlen(#path_to_file);
edit_box_set_text stdcall (#path_to_file_ed, #path);
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
loop() switch(WaitEvent())