diff --git a/programs/cmm/browser/TWB/TWB.c b/programs/cmm/browser/TWB/TWB.c index 102e321eb1..a9e388a267 100644 --- a/programs/cmm/browser/TWB/TWB.c +++ b/programs/cmm/browser/TWB/TWB.c @@ -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; diff --git a/programs/cmm/browser/TWB/parse_tag.h b/programs/cmm/browser/TWB/parse_tag.h index 14c49c17eb..7fa07b6b55 100644 --- a/programs/cmm/browser/TWB/parse_tag.h +++ b/programs/cmm/browser/TWB/parse_tag.h @@ -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; +} diff --git a/programs/cmm/browser/TWB/render.h b/programs/cmm/browser/TWB/render.h index 231f141b87..c1bf268b51 100644 --- a/programs/cmm/browser/TWB/render.h +++ b/programs/cmm/browser/TWB/render.h @@ -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) diff --git a/programs/cmm/browser/TWB/set_style.h b/programs/cmm/browser/TWB/set_style.h index 4976a3f63d..0904c2a3f1 100644 --- a/programs/cmm/browser/TWB/set_style.h +++ b/programs/cmm/browser/TWB/set_style.h @@ -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(); - } } diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 1169c39129..d1bd48eee2 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -149,9 +149,10 @@ void main() } } - if (links.hover(WB1.list.y, WB1.list.first)) + if (WB1.list.MouseOver(mouse.x, mouse.y)) && (links.hover(WB1.list.y, WB1.list.first)) { if (mouse.key&MOUSE_MIDDLE) && (mouse.up) { + GetKeyModifier(); if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { EventClickLink(TARGET_NEW_WINDOW); } else { @@ -298,29 +299,30 @@ void ProcessButtonClick(dword id__) } } -bool ProcessKeyEvent() +void ProcessKeyEvent() { if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();return;} + if (key_scancode == SCAN_CODE_KEY_T) {EventOpenNewTab(URL_SERVICE_TEST);return;} } if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) { - case SCAN_CODE_KEY_O: EventOpenDialog(); return true; - case SCAN_CODE_KEY_H: ProcessButtonClick(VIEW_HISTORY); return true; - case SCAN_CODE_KEY_U: EventViewSource(); return true; - case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return true; - case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return true; - case SCAN_CODE_KEY_J: ProcessButtonClick(DOWNLOAD_MANAGER); return true; - case SCAN_CODE_KEY_R: ProcessButtonClick(REFRESH_BUTTON); return true; - case SCAN_CODE_ENTER: EventSeachWeb(); return true; - case SCAN_CODE_LEFT: ProcessButtonClick(BACK_BUTTON); return true; - 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_KEY_O: EventOpenDialog(); return; + case SCAN_CODE_KEY_H: ProcessButtonClick(VIEW_HISTORY); return; + case SCAN_CODE_KEY_U: EventViewSource(); return; + case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return; + case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return; + case SCAN_CODE_KEY_J: ProcessButtonClick(DOWNLOAD_MANAGER); return; + case SCAN_CODE_KEY_R: ProcessButtonClick(REFRESH_BUTTON); return; + case SCAN_CODE_ENTER: EventSeachWeb(); return; + case SCAN_CODE_LEFT: ProcessButtonClick(BACK_BUTTON); return; + case SCAN_CODE_RIGHT: ProcessButtonClick(FORWARD_BUTTON); return; + case SCAN_CODE_KEY_W: EventCloseActiveTab(); return; + case SCAN_CODE_TAB: EventActivateNextTab(); return; case SCAN_CODE_F5: EventClearCache(); return; - default: return false; + default: return; } switch(key_scancode) @@ -371,7 +373,7 @@ void draw_window() WB1.list.h-1, scroll_wv.bckg_col); if (!canvas.bufw) { - OpenPage(history.current()); + EventOpenFirstPage(); } else { WB1.DrawPage(); DrawOmnibox(); @@ -381,6 +383,11 @@ void draw_window() DrawTabsBar(); } +void EventOpenFirstPage() +{ + OpenPage(history.current()); +} + void EventManuallyChangeEncoding(int _new_encoding) { dword newbuf, newsize; @@ -921,12 +928,13 @@ void EventDownloadAndOpenImage(dword _url) void HandleRedirect() { - char redirect_url[URL_SIZE]; - http.header_field("location", #redirect_url, URL_SIZE); - get_absolute_url(#redirect_url, http.cur_url); + dword redirect_url = malloc(URL_SIZE); + http.header_field("location", redirect_url, URL_SIZE); + get_absolute_url(redirect_url, http.cur_url); http.hfree(); - if (http_get_type==PAGE) OpenPage(#redirect_url); - else if (http_get_type==IMG) GetUrl(#redirect_url); + if (http_get_type==PAGE) OpenPage(redirect_url); + else if (http_get_type==IMG) GetUrl(redirect_url); + free(redirect_url); } dword GetImg(bool _new) @@ -948,7 +956,7 @@ dword GetImg(bool _new) if (_new) return; DrawOmnibox(); DrawStatusBar(T_RENDERING); - WB1.ParseHtml(WB1.bufpointer, WB1.bufsize); + WB1.Reparse(); WB1.DrawPage(); debugln(sprintf(#param, T_DONE_IN_SEC, GetStartTime()-render_start_time/100)); DrawStatusBar(NULL); diff --git a/programs/cmm/browser/const.h b/programs/cmm/browser/const.h index ba4ea2b957..310e11d300 100644 --- a/programs/cmm/browser/const.h +++ b/programs/cmm/browser/const.h @@ -107,4 +107,4 @@ char editbox_icons[] = FROM "res/editbox_icons.raw"; #define DEFAULT_URL URL_SERVICE_HOMEPAGE -char version[]="WebView 3.30"; \ No newline at end of file +char version[]="WebView 3.31"; \ No newline at end of file diff --git a/programs/cmm/browser/res/help_en.htm b/programs/cmm/browser/res/help_en.htm index 8d7a0d27d0..41ad6cb5be 100644 --- a/programs/cmm/browser/res/help_en.htm +++ b/programs/cmm/browser/res/help_en.htm @@ -1,8 +1,8 @@ -WebView Help +WebView Help

WebView Text-Based Browser

-It is free and open-source. If you have any suggestions or want to help improving it please visit its topic at board.kolibrios.org
+It is free and open-source. If you have any suggestions or want to help improving it please visit its topic at board.kolibrios.org
 
 Shortcut keys
 
diff --git a/programs/cmm/browser/res/help_ru.htm b/programs/cmm/browser/res/help_ru.htm
index e17e3c346d..97b81c0680 100644
--- a/programs/cmm/browser/res/help_ru.htm
+++ b/programs/cmm/browser/res/help_ru.htm
@@ -1,10 +1,7 @@
 
-
 
 Справка WebView
-
 

Справка WebView

- Клавиши быстрого вызова [CTRL + N или CTRL + T] Новое окно diff --git a/programs/cmm/browser/res/homepage_en.htm b/programs/cmm/browser/res/homepage_en.htm index 10570f2255..892228fe99 100644 --- a/programs/cmm/browser/res/homepage_en.htm +++ b/programs/cmm/browser/res/homepage_en.htm @@ -1,12 +1,11 @@ - Homepage
Bookmarks:
-1. KolibriOS homepage
-2. KolibriN homepage
-3. Kolibri Stuff
+1. KolibriOS homepage
+2. KolibriN homepage
+3. Kolibri Stuff
 
 By the way, 
 • You can check for browser updates from the main menu.
diff --git a/programs/cmm/browser/res/homepage_ru.htm b/programs/cmm/browser/res/homepage_ru.htm
index f43364dc26..0c120c4252 100644
--- a/programs/cmm/browser/res/homepage_ru.htm
+++ b/programs/cmm/browser/res/homepage_ru.htm
@@ -4,9 +4,9 @@
 Домашняя страница
 
 
Закладки:
-1. Домашняя страница KolibriOS
-2. KolibriN10
-3. Kolibri Store
+1. Домашняя страница KolibriOS
+2. KolibriN10
+3. Kolibri Store
 
 Кстати, 
 • Из главного меню можно проверить наличие обновлений
diff --git a/programs/cmm/browser/res/test.htm b/programs/cmm/browser/res/test.htm
index 12fff5693b..588656f2c2 100644
--- a/programs/cmm/browser/res/test.htm
+++ b/programs/cmm/browser/res/test.htm
@@ -1,27 +1,27 @@
 
-WebView Test Page
+TEST
 
 
-KolibriOS 
-KolibriN10
-Kolibri Store
+KolibriOS 
+KolibriN10
+Kolibri Store
 
-os-menuet.narod.ru
-coolthemes.narod.ru
-fdd5-25.net
-mestack.narod.ru
-dgmag.in
-http://baravy.by/me/b.html
+os-menuet.narod.ru
+coolthemes.narod.ru
+fdd5-25.net
+mestack.narod.ru
+dgmag.in
+baravy.by/me/b.html
 
-artcon.ru
-acmp.ru
-cnn 1996
-vetusware.com
-old-dos.ru
-nubo.ru
-samlib.ru/b
+artcon.ru
+acmp.ru
+cnn 1996
+vetusware.com
+old-dos.ru
+nubo.ru
+samlib.ru/b
 
-UmVirt Conis
-LOR
-opennet
-bash.im 
\ No newline at end of file
+UmVirt Conis
+LOR
+opennet
+bash.im 
\ No newline at end of file
diff --git a/programs/cmm/browser/tabs.h b/programs/cmm/browser/tabs.h
index 2de08c43da..9b33216821 100644
--- a/programs/cmm/browser/tabs.h
+++ b/programs/cmm/browser/tabs.h
@@ -147,7 +147,7 @@ void EventTabClose(int _id)
 		tab.close(_id);
 		tab.restore(tab.active);
 		SetElementSizes();
-		WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
+		WB1.Reparse();
 		WB1.DrawPage();
 		SetOmniboxText(history.current());
 	} else {
@@ -170,7 +170,7 @@ void EventTabClick(int _id)
 	tab.restore(_id);
 	DrawTabsBar();
 	SetElementSizes();
-	WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
+	WB1.Reparse();
 	WB1.DrawPage();		
 	SetOmniboxText(history.current());
 	DrawStatusBar(NULL);