WebView 3.31: speed up text rendering (less strcpy, use pointers), fix click on a non-existing link in the toolbar, use // instwead of http:// in buildin pages
git-svn-id: svn://kolibrios.org@8500 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -56,6 +56,7 @@ struct TWebBrowser {
|
||||
|
||||
void SetPageDefaults();
|
||||
void ParseHtml();
|
||||
void Reparse();
|
||||
void NewLine();
|
||||
void ChangeEncoding();
|
||||
void AddCharToTheLine();
|
||||
@@ -110,6 +111,11 @@ void TWebBrowser::SetPageDefaults()
|
||||
tag_table_reset();
|
||||
}
|
||||
//============================================================================================
|
||||
void TWebBrowser::Reparse()
|
||||
{
|
||||
ParseHtml(bufpointer, bufsize);
|
||||
}
|
||||
//============================================================================================
|
||||
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
|
||||
int tab_len;
|
||||
dword bufpos;
|
||||
@@ -223,25 +229,6 @@ void TWebBrowser::AddCharToTheLine(unsigned char _char)
|
||||
}
|
||||
}
|
||||
//============================================================================================
|
||||
void TWebBrowser::NewLine()
|
||||
{
|
||||
static bool empty_line = true;
|
||||
|
||||
if (draw_x==left_gap) && (draw_y==BODY_MARGIN) return;
|
||||
if (t_html) && (!t_body) return;
|
||||
|
||||
if (draw_x == style.tag_list.level * 5 * list.font_w + left_gap) {
|
||||
if (!empty_line) empty_line=true; else return;
|
||||
} else {
|
||||
empty_line = false;
|
||||
}
|
||||
|
||||
draw_y += style.cur_line_h;
|
||||
style.cur_line_h = list.item_h;
|
||||
if (style.blq) draw_x = 6 * list.font_w; else draw_x = 0;
|
||||
draw_x += style.tag_list.level * 5 * list.font_w + left_gap;
|
||||
}
|
||||
//============================================================================================
|
||||
void TWebBrowser::ChangeEncoding(int _new_encoding)
|
||||
{
|
||||
if (cur_encoding == _new_encoding) return;
|
||||
@@ -258,9 +245,7 @@ scroll_bar scroll_wv = { 15,NULL,NULL,NULL,
|
||||
|
||||
void TWebBrowser::DrawPage()
|
||||
{
|
||||
if (list.w!=canvas.bufw) {
|
||||
ParseHtml(bufpointer, bufsize);
|
||||
}
|
||||
if (list.w!=canvas.bufw) Reparse();
|
||||
canvas.Show(list.first, list.h);
|
||||
|
||||
scroll_wv.max_area = list.count;
|
||||
|
@@ -7,11 +7,13 @@ struct _tag
|
||||
collection attributes;
|
||||
collection values;
|
||||
dword value;
|
||||
dword number;
|
||||
bool is();
|
||||
bool parse();
|
||||
void debug_tag();
|
||||
dword get_next_param();
|
||||
dword get_value_of();
|
||||
signed get_number_of();
|
||||
} tag=0;
|
||||
|
||||
bool _tag::is(dword _text)
|
||||
@@ -207,3 +209,13 @@ dword _tag::get_value_of(dword _attr_name)
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
signed _tag::get_number_of(dword _attr_name)
|
||||
{
|
||||
if (get_value_of(_attr_name)) {
|
||||
number = atoi(tag.value);
|
||||
} else {
|
||||
number = 0;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
CANVAS canvas;
|
||||
|
||||
void TWebBrowser::RenderLine()
|
||||
void TWebBrowser::RenderLine(dword _line)
|
||||
{
|
||||
unsigned px; //paint x coordinate
|
||||
unsigned pw; //paint y coordinate
|
||||
@@ -9,22 +9,28 @@ void TWebBrowser::RenderLine()
|
||||
|
||||
if (style.title)
|
||||
{
|
||||
strncpy(#header, #linebuf, sizeof(TWebBrowser.header)-1);
|
||||
strncpy(#header, _line, sizeof(TWebBrowser.header)-1);
|
||||
strncat(#header, " - ", sizeof(TWebBrowser.header)-1);
|
||||
strncat(#header, #version, sizeof(TWebBrowser.header)-1);
|
||||
linebuf = 0;
|
||||
return;
|
||||
}
|
||||
if (t_html) && (!t_body) {
|
||||
linebuf = 0;
|
||||
return;
|
||||
else if (t_html) && (!t_body) {
|
||||
//
|
||||
}
|
||||
|
||||
if (linebuf)
|
||||
else if (ESBYTE[_line])
|
||||
{
|
||||
pw = strlen(#linebuf) * list.font_w;
|
||||
pw = strlen(_line) * list.font_w;
|
||||
zoom = list.font_w / BASIC_CHAR_W;
|
||||
|
||||
if (pw > draw_w) {
|
||||
draw_w = pw;
|
||||
NewLine();
|
||||
}
|
||||
|
||||
if (debug_mode) {
|
||||
canvas.DrawBar(draw_x, draw_y, pw, list.item_h, 0xCCCccc);
|
||||
debugln(_line);
|
||||
}
|
||||
|
||||
style.cur_line_h = math.max(style.cur_line_h, list.item_h);
|
||||
|
||||
if (bg_colors.get_last() - bg_colors.get(0)) {
|
||||
@@ -42,63 +48,81 @@ void TWebBrowser::RenderLine()
|
||||
pc = text_colors.get_last();
|
||||
if (link) && (pc == text_colors.get(0)) pc = link_color_default;
|
||||
|
||||
canvas.WriteText(draw_x, draw_y, list.font_type, pc, #linebuf, NULL);
|
||||
if (style.b) canvas.WriteText(draw_x+1, draw_y, list.font_type, pc, #linebuf, NULL);
|
||||
canvas.WriteText(draw_x, draw_y, list.font_type, pc, _line, NULL);
|
||||
if (style.b) canvas.WriteText(draw_x+1, draw_y, list.font_type, pc, _line, NULL);
|
||||
if (style.s) canvas.DrawBar(draw_x, list.item_h / 2 - zoom + draw_y, pw, zoom, pc);
|
||||
if (style.u) canvas.DrawBar(draw_x, list.item_h - zoom - zoom + draw_y, pw, zoom, pc);
|
||||
if (link) {
|
||||
if (linebuf[0]==' ') && (linebuf[1]==NULL) {} else {
|
||||
if (ESBYTE[_line]==' ') && (ESBYTE[_line+1]==NULL) {} else {
|
||||
canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2)-1, pw, zoom, link_color_default);
|
||||
links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom);
|
||||
}
|
||||
}
|
||||
draw_x += pw;
|
||||
if (debug_mode) debugln(#linebuf);
|
||||
}
|
||||
linebuf = NULL;
|
||||
ESBYTE[_line] = NULL;
|
||||
}
|
||||
|
||||
|
||||
void TWebBrowser::RenderTextbuf()
|
||||
{
|
||||
int break_pos;
|
||||
char next_line[sizeof(TWebBrowser.linebuf)];
|
||||
int zoom = list.font_w / BASIC_CHAR_W;
|
||||
dword lbp = #linebuf;
|
||||
int br; //break position
|
||||
char nul = '\0';
|
||||
int len;
|
||||
|
||||
//Do we need a line break?
|
||||
while (strlen(#linebuf) * list.font_w + draw_x >= draw_w) {
|
||||
while (len = strlen(lbp)) && (len * list.font_w + draw_x >= draw_w) {
|
||||
//Yes, we do. Lets calculate where...
|
||||
break_pos = strrchr(#linebuf, ' ');
|
||||
br = strrchr(lbp, ' ');
|
||||
|
||||
//Is a new line fits in the current line?
|
||||
if (break_pos * list.font_w + draw_x > draw_w) {
|
||||
break_pos = draw_w - draw_x /list.font_w;
|
||||
while(break_pos) {
|
||||
if (linebuf[break_pos]==' ') {
|
||||
break_pos++;
|
||||
if (br * list.font_w + draw_x >= draw_w) {
|
||||
br = draw_w - draw_x /list.font_w;
|
||||
while(br) {
|
||||
if (ESBYTE[lbp + br]==' ') {
|
||||
br++;
|
||||
break;
|
||||
}
|
||||
break_pos--;
|
||||
br--;
|
||||
}
|
||||
}
|
||||
//Maybe a new line is too big for the whole new line? Then we have to split it
|
||||
if (!break_pos) && (style.tag_list.level*5 + strlen(#linebuf) * zoom >= list.column_max) {
|
||||
break_pos = draw_w - draw_x / list.font_w;
|
||||
if (!br) && (len * list.font_w >= draw_w) {
|
||||
br = draw_w - draw_x / list.font_w;
|
||||
}
|
||||
|
||||
|
||||
if (break_pos) {
|
||||
strlcpy(#next_line, #linebuf + break_pos, sizeof(next_line));
|
||||
linebuf[break_pos] = 0x00;
|
||||
RenderLine();
|
||||
strlcpy(#linebuf, #next_line, sizeof(TWebBrowser.linebuf));
|
||||
NewLine();
|
||||
if (br) {
|
||||
ESBYTE[lbp + br] >< nul;
|
||||
RenderLine(lbp);
|
||||
ESBYTE[lbp + br] >< nul;
|
||||
lbp += br;
|
||||
while (ESBYTE[lbp]==' ') && (ESBYTE[lbp]) lbp++;
|
||||
if (ESBYTE[lbp]) NewLine();
|
||||
} else {
|
||||
NewLine();
|
||||
RenderLine();
|
||||
RenderLine(lbp);
|
||||
}
|
||||
}
|
||||
RenderLine();
|
||||
RenderLine(lbp);
|
||||
}
|
||||
|
||||
void TWebBrowser::NewLine()
|
||||
{
|
||||
static bool empty_line = true;
|
||||
|
||||
if (draw_x==left_gap) && (draw_y==BODY_MARGIN) return;
|
||||
if (t_html) && (!t_body) return;
|
||||
|
||||
if (draw_x == style.tag_list.level * 5 * list.font_w + left_gap) {
|
||||
if (!empty_line) empty_line=true; else return;
|
||||
} else {
|
||||
empty_line = false;
|
||||
}
|
||||
|
||||
draw_y += style.cur_line_h;
|
||||
style.cur_line_h = list.item_h;
|
||||
if (style.blq) draw_x = 6 * list.font_w; else draw_x = 0; //left_gap += style.tag_list.level * 5 * list.font_w ???
|
||||
draw_x += style.tag_list.level * 5 * list.font_w + left_gap;
|
||||
}
|
||||
|
||||
bool TWebBrowser::RenderImage(dword cur_img)
|
||||
|
@@ -11,7 +11,7 @@ void TWebBrowser::SetStyle()
|
||||
if (tag.is("p")) { tag_p(); return; }
|
||||
if (tag.is("img")) { tag_img(); return; }
|
||||
if (tag.is("div")) { tag_div(); return; }
|
||||
if (tag.is("br")) { NewLine(); return; }
|
||||
if (tag.is("br")) { /*draw_x++;*/NewLine(); return; }
|
||||
if (tag.is("header")) { NewLine(); return; }
|
||||
if (tag.is("article")) { NewLine(); return; }
|
||||
if (tag.is("footer")) { NewLine(); return; }
|
||||
@@ -202,6 +202,7 @@ void TWebBrowser::tag_hr()
|
||||
if (tag.get_value_of("color")) hrcol = GetColor(tag.value);
|
||||
if (draw_x != left_gap) NewLine();
|
||||
canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol);
|
||||
draw_x++;
|
||||
NewLine();
|
||||
return;
|
||||
}
|
||||
@@ -319,82 +320,101 @@ NOIMG:
|
||||
|
||||
|
||||
|
||||
|
||||
int tdepth;
|
||||
int col_n;
|
||||
|
||||
struct TABLE {
|
||||
int count;
|
||||
int col;
|
||||
collection_int cx;
|
||||
collection_int col_w;
|
||||
collection_int col_span;
|
||||
collection_int row_h;
|
||||
int row_y, next_row_y;
|
||||
} table;
|
||||
int colcount;
|
||||
} t[5];
|
||||
|
||||
void TWebBrowser::tag_table_reset()
|
||||
{
|
||||
table.count = 0;
|
||||
table.cx.drop();
|
||||
table.row_y = 0;
|
||||
table.next_row_y = 0;
|
||||
int i;
|
||||
tdepth = 0;
|
||||
for (i=0; i<5; i++) {
|
||||
t[i].col_w.drop();
|
||||
t[i].row_h.drop();
|
||||
t[i].col_span.drop();
|
||||
t[i].row_y = 0;
|
||||
t[i].next_row_y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TWebBrowser::tag_table()
|
||||
{
|
||||
if (tag.opened) {
|
||||
if (!table.count) {
|
||||
table.next_row_y = table.row_y = draw_y;
|
||||
if (tdepth==0) {
|
||||
t[0].next_row_y = t[0].row_y = draw_y;
|
||||
}
|
||||
table.count++;
|
||||
tdepth++;
|
||||
} else {
|
||||
table.count--;
|
||||
if (!table.count) {
|
||||
draw_y = math.max(draw_y + style.cur_line_h, table.next_row_y);
|
||||
tdepth--;
|
||||
if (tdepth==0) {
|
||||
draw_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y);
|
||||
left_gap = BODY_MARGIN;
|
||||
draw_w = list.w - BODY_MARGIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TWebBrowser::tag_tr()
|
||||
:void TWebBrowser::tag_tr()
|
||||
{
|
||||
if (tag.opened) {
|
||||
if (table.count>1) {
|
||||
if (tdepth>1) {
|
||||
NewLine();
|
||||
} else {
|
||||
table.col = 0;
|
||||
table.row_y = math.max(draw_y + style.cur_line_h, table.next_row_y);
|
||||
t[0].colcount = math.max(t[0].colcount, col_n);
|
||||
col_n = 0;
|
||||
t[0].row_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y);
|
||||
left_gap = BODY_MARGIN;
|
||||
NewLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TWebBrowser::tag_td()
|
||||
:void TWebBrowser::tag_td()
|
||||
{
|
||||
if (table.count>1) return;
|
||||
if (tdepth>1) return;
|
||||
if (tag.opened) {
|
||||
table.next_row_y = math.max(draw_y + style.cur_line_h, table.next_row_y);
|
||||
draw_y = table.row_y;
|
||||
table.cx.set(table.col, math.max(draw_x,table.cx.get(table.col)) );
|
||||
draw_x = left_gap = table.cx.get(table.col);
|
||||
table.col++;
|
||||
if (tag.get_value_of("width")) {
|
||||
draw_w = EAX;
|
||||
//debugval("draw_w", atoi(tag.value));
|
||||
table.cx.set(table.col, draw_x + atoi(tag.value));
|
||||
|
||||
t[0].next_row_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y);
|
||||
style.cur_line_h = list.item_h;
|
||||
t[0].col_w.set(col_n, math.max(draw_x,t[0].col_w.get(col_n)) );
|
||||
draw_x = left_gap = t[0].col_w.get(col_n);
|
||||
draw_w = list.w - left_gap;
|
||||
draw_y = t[0].row_y;
|
||||
if (tag.get_number_of("width")) {
|
||||
if (!strchr(tag.value, '%')) {
|
||||
draw_w = tag.number;
|
||||
} else {
|
||||
if (tag.number < 100) {
|
||||
draw_w = draw_w - left_gap * tag.number / 100;
|
||||
if (draw_w > list.w - left_gap) draw_w = list.w - left_gap;
|
||||
}
|
||||
}
|
||||
}
|
||||
col_n++;
|
||||
t[0].col_w.set(col_n, draw_x + draw_w);
|
||||
|
||||
if (left_gap >= list.w - list.font_w - 10) {
|
||||
debugln("left_gap overflow");
|
||||
draw_x = left_gap = BODY_MARGIN;
|
||||
t[0].col_w.drop();
|
||||
NewLine();
|
||||
canvas.WriteText(draw_x, draw_y, 10011001b, 0xFE0000, "lgo", NULL);
|
||||
}
|
||||
|
||||
if (draw_w < 0) || (draw_w >= list.w) {
|
||||
debugln("draw_w overflow");
|
||||
draw_x = left_gap = BODY_MARGIN;
|
||||
draw_w = list.w - left_gap;
|
||||
NewLine();
|
||||
canvas.WriteText(draw_x, draw_y, 10011001b, 0x0000FE, "drwo", NULL);
|
||||
}
|
||||
//if (tag.get_value_of("height")) table.next_row_y = draw_y + atoi(tag.value);
|
||||
}
|
||||
|
||||
if (left_gap >= list.w - list.font_w - 10) {
|
||||
debugln("left_gap overflow");
|
||||
draw_x = left_gap = BODY_MARGIN;
|
||||
table.cx.drop();
|
||||
table.count = 999;
|
||||
NewLine();
|
||||
}
|
||||
|
||||
if (draw_w < 0) || (draw_w >= list.w) {
|
||||
debugln("draw_w overflow");
|
||||
draw_x = left_gap = BODY_MARGIN;
|
||||
draw_w = list.w - left_gap;
|
||||
NewLine();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user