WebView: no page scroll to the top when download a file, autoopen images

git-svn-id: svn://kolibrios.org@8413 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-12-15 15:39:54 +00:00
parent 55bacdc367
commit 5b3ac273b6
5 changed files with 62 additions and 45 deletions

View File

@ -91,7 +91,7 @@ bool PAGE_LINKS::hover(dword list_y, list_first)
active_url = link.get(i);
active = i;
DrawStatusBar();
DrawStatusBar(active_url);
}
if (mouse.lkm) && (mouse.down) {
DrawRectangle(x.get(active), -list_first + y.get(active),
@ -105,7 +105,7 @@ bool PAGE_LINKS::hover(dword list_y, list_first)
draw_underline(active, list_first, list_y, link_color_default);
active_url = 0;
active = -1;
DrawStatusBar();
DrawStatusBar(NULL);
}
return false;
}

View File

@ -11,7 +11,7 @@
// //
//===================================================//
#define MEMSIZE 1024 * 200
#define MEMSIZE 1024 * 130
#include "..\lib\gui.h"
#include "..\lib\draw_buf.h"
#include "..\lib\list_box.h"
@ -41,7 +41,7 @@
// DATA //
// //
//===================================================//
char version[]="WebView 3.01";
char version[]="WebView 3.03";
#define DEFAULT_URL URL_SERVICE_HOMEPAGE
@ -69,7 +69,6 @@ _http http = 0;
bool source_mode = false;
progress_bar prbar;
char stak[4096];
proc_info Form;
#include "tabs.h"
@ -213,6 +212,7 @@ void main()
}
if (http.receive_result != 0) break;
if (debug_mode) debugval("HTTP", http.status_code);
if (http.status_code >= 300) && (http.status_code < 400)
{
// Handle redirects
@ -229,7 +229,8 @@ void main()
redirect_count = 0;
http.hfree();
if (http_get_type==PAGE) {
cache.add(history.current(), http.content_pointer, http.content_received, PAGE);
history.add(http.cur_url);
cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE);
LoadInternalPage(http.content_pointer, http.content_received);
}
else if (http_get_type==IMG) {
@ -362,7 +363,7 @@ void draw_window()
DrawOmnibox();
}
DrawProgress();
DrawStatusBar();
DrawStatusBar(NULL);
DrawTabsBar();
}
@ -527,8 +528,6 @@ void OpenPage(dword _open_URL)
anchors.take_anchor_from(#new_url);
}
history.add(#new_url);
/*
There could be several possible types of addresses:
- cached page (only http/https)
@ -541,11 +540,17 @@ void OpenPage(dword _open_URL)
if (cache.has(#new_url)) {
//CACHED PAGE
if (cache.current_type==PAGE) LoadInternalPage(cache.current_buf, cache.current_size);
else {EventOpenDownloader(#new_url);return;}
if (cache.current_type==PAGE) {
history.add(#new_url);
LoadInternalPage(cache.current_buf, cache.current_size);
}
else {
EventDownloadAndOpenImage(#new_url);
}
} else if (!strncmp(#new_url,"WebView:",8)) {
//INTERNAL PAGE
history.add(#new_url);
if (streq(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#buildin_page_home, sizeof(buildin_page_home));
else if (streq(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#buildin_page_help, sizeof(buildin_page_help));
else if (streq(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
@ -563,11 +568,12 @@ void OpenPage(dword _open_URL)
DrawOmnibox();
if (!http.transfer) {
StopLoading();
history.add(#new_url);
LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error));
}
} else {
//LOCAL PAGE
history.add(#new_url);
if (UrlExtIs(#new_url,".docx")) {
DeleteFile("/tmp0/1/temp/word/document.xml");
CreateDir("/tmp0/1/temp");
@ -640,7 +646,6 @@ void EventClickLink(dword _target)
if (http.transfer) {
StopLoading();
history.back();
}
if (strrchr(#new_url, '#')!=0) {
@ -704,7 +709,7 @@ void LoadInternalPage(dword _bufdata, _in_bufsize){
OpenPage(#WB1.redirect);
}
*/
DrawStatusBar();
DrawStatusBar(NULL);
DrawActiveTab();
if (source_mode) {
source_mode = false;
@ -821,15 +826,8 @@ void EventUpdateBrowser()
current_size = get_file_size(#program_path);
new_size = get_file_size("/tmp0/1/Downloads/WebView.com");
if (!new_size) || (new_size<5000) {
notify(#update_download_error);
return;
}
if (current_size == new_size) {
notify(#update_is_current);
return;
}
if (!new_size) || (new_size<5000) { notify(#update_download_error); return; }
if (current_size == new_size) { notify(#update_is_current); return; }
if (CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) {
notify(#update_can_not_copy);
@ -840,17 +838,14 @@ void EventUpdateBrowser()
}
}
void DrawStatusBar()
void DrawStatusBar(dword _msg)
{
dword status_y = Form.cheight - STATUSBAR_H + 4;
dword status_w = Form.cwidth - 90;
DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
if (links.active_url) {
ESI = math.min(status_w/6, strlen(links.active_url));
WriteText(10, status_y, 0, sc.work_text, links.active_url);
}
if (http.transfer>0) && (http_get_type==IMG) {
//
if (_msg) {
ESI = math.min(status_w/6, strlen(_msg));
WriteText(10, status_y, 0, sc.work_text, _msg);
}
DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING);
WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets);
@ -898,20 +893,29 @@ void CheckContentType()
{
char content_type[64];
if (http.header_field("content-type", #content_type, sizeof(content_type))) // application || image
if (content_type[0] == 'a') || (content_type[0] == 'i') {
if (content_type[0] == 'i') {
EventDownloadAndOpenImage(http.cur_url);
StopLoading();
}if (content_type[0] == 'a') {
EventOpenDownloader(history.current());
StopLoading();
history.back();
EventRefreshPage();
}
}
void EventDownloadAndOpenImage(dword _url)
{
char image_download_url[URL_SIZE];
strcpy(#image_download_url, "-eo ");
strncat(#image_download_url, _url, URL_SIZE);
EventOpenDownloader(#image_download_url);
}
void HandleRedirect()
{
char redirect_url[URL_SIZE];
http.header_field("location", #redirect_url, URL_SIZE);
get_absolute_url(#redirect_url, history.current());
if (http_get_type==PAGE) history.back();
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);
@ -929,14 +933,16 @@ dword GetImg(bool _new)
if (cache.has(cur_img_url)==false) {
prbar.max = WB1.img_url.count;
prbar.value = i;
if (GetUrl(cur_img_url)) {DrawProgress(); return;}
if (GetUrl(cur_img_url)) {DrawStatusBar(cur_img_url); DrawProgress(); return;}
}
}
if (_new) return;
DrawOmnibox();
DrawStatusBar(T_RENDERING);
WB1.ParseHtml(WB1.o_bufpointer, WB1.bufsize);
WB1.DrawPage();
debugln(sprintf(#param, "WebView: page rendered in %i sec", GetStartTime()-render_start_time/100));
debugln(sprintf(#param, T_DONE_IN_SEC, GetStartTime()-render_start_time/100));
DrawStatusBar(NULL);
}
stop:

View File

@ -22,12 +22,14 @@ char link_menu[] =
ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
char loading_text[] = "‡ £à㧪 ...";
char update_param[] = "-exit http://builds.kolibrios.org/rus/data/programs/cmm/browser/WebView.com";
char update_param[] = "-e http://builds.kolibrios.org/rus/data/programs/cmm/browser/WebView.com";
char update_download_error[] = "'WebView\nŽè¨¡ª  ¯à¨ ¯®«ã祭¨¨ ®¡­®¢«¥­¨©!' -tE";
char update_ok[] = "'WebView\n<EFBFBD>à ã§¥à ¡ë« ãᯥ譮 ®¡­®¢«¥­!' -tO";
char update_is_current[] = "'WebView\n‚ë 㦥 ¨á¯®«ì§ã¥â¥ ¯®á«¥¤­îî ¢¥àá¨î.' -tI";
char update_can_not_copy[] = "'WebView\n<EFBFBD>¥ ¬®£ã ¯¥à¥¬¥áâ¨âì ­®¢ãî ¢¥àá¨î ¨§ ¯ ¯ª¨ Downloads ­  Ramdisk. ‚®§¬®¦­®, ­¥ ¤®áâ â®ç­® ¬¥áâ .' -tE";
char clear_cache_ok[] = "'WebView\nŠíè ®ç¨é¥­.' -tI";
#define T_RENDERING "<22>¥­¤¥à¨­£ áâà ­¨æë..."
#define T_DONE_IN_SEC "ƒ®â®¢®: %i ᥪ"
#else
char buildin_page_error[] = FROM "res/page_not_found_en.htm""\0";
char buildin_page_home[] = FROM "res/homepage_en.htm""\0";
@ -51,12 +53,14 @@ Open in new window
Copy link
Download link contents";
char loading_text[] = "Loading...";
char update_param[] = "-exit http://builds.kolibrios.org/eng/data/programs/cmm/browser/WebView.com";
char update_param[] = "-e http://builds.kolibrios.org/eng/data/programs/cmm/browser/WebView.com";
char update_download_error[] = "'WebView\nError receiving an up to date information!' -tE";
char update_ok[] = "'WebView\nThe browser has been updated!' -tO";
char update_is_current[] = "'WebView\nThe browser is up to date.' -tI";
char update_can_not_copy[] = "'WebView\nError copying a new version from Downloads folder!\nProbably too litle space on Ramdisk.' -tE";
char clear_cache_ok[] = "'WebView\nThe cache has been cleared.' -tI";
#define T_RENDERING "Rendering..."
#define T_DONE_IN_SEC "Done in %i sec"
#endif
#define URL_SERVICE_HISTORY "WebView:history"

View File

@ -1,4 +1,4 @@
#define MEMSIZE 1024 * 100
#define MEMSIZE 1024 * 40
//Copyright 2020 by Leency
#include "../lib/gui.h"
#include "../lib/random.h"
@ -8,6 +8,7 @@
#include "const.h"
bool exit_param = false;
bool open_file = false;
_http http;
@ -31,9 +32,14 @@ void main()
SetCurDir(#save_dir);
if (param) {
if (!strncmp(#param, "-exit ", 6)) {
if (streqrp(#param, "-e ")) {
exit_param = true;
param += 6;
param += 3;
}
if (streqrp(#param, "-eo ")) {
exit_param = true;
open_file = true;
param += 4;
}
if (!strncmp(#param, "-mem", 5)) {
@ -52,16 +58,15 @@ void main()
loop() switch(@WaitEvent())
{
case evMouse: edit_box_mouse stdcall (#ed); break;
case evButton: ProcessButtonClick(); break;
case evButton: ProcessButtonClick(@GetButtonID()); break;
case evKey: ProcessKeyPress(); break;
case evReDraw: DrawWindow(); break;
default: MonitorProgress();
}
}
void ProcessButtonClick()
void ProcessButtonClick(int id)
{
int id = @GetButtonID();
autoclose.click(id);
if (id==BTN_EXIT) { StopDownloading(); ExitProcess(); }
if (id==BTN_START) StartDownloading();
@ -217,6 +222,7 @@ void SaveFile()
}
if (!exit_param) notify(#notify_message);
if (open_file) ProcessButtonClick(BTN_RUN);
if (autoclose.checked) ExitProcess();
}

View File

@ -99,6 +99,7 @@ struct _http
dword _http::get(dword _url)
{
cur_url = _url;
if (streqrp(cur_url, "http://gate.aspero.pro/?site=")) cur_url += 29;
http_get stdcall (_url, 0, 0, #accept_language);
transfer = EAX;
return EAX;