summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-08 08:06:22 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-08 08:06:22 +0300
commitd6875fba63cc674d2d9cac64a66c3b4c9f3eaba1 (patch)
treea12111a19b594fc17792a7a851d1526597470121 /src/ui/documentwidget.c
parent9abe27c63e088bf1e139d108cbc29ac39222d74c (diff)
Moved recent URLs history to DocumentWidget
App maintains the visited URLs database, but each DocumentWidget has its own stack of recent URLs for timeline navigation.
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 661a9d46..a1299727 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -76,6 +76,7 @@ iDefineClass(MediaRequest)
76 76
77struct Impl_DocumentWidget { 77struct Impl_DocumentWidget {
78 iWidget widget; 78 iWidget widget;
79 iHistory *history;
79 enum iDocumentState state; 80 enum iDocumentState state;
80 iString *url; 81 iString *url;
81 iString *titleUser; 82 iString *titleUser;
@@ -98,7 +99,7 @@ struct Impl_DocumentWidget {
98 int initialScrollY; 99 int initialScrollY;
99 iScrollWidget *scroll; 100 iScrollWidget *scroll;
100 iWidget *menu; 101 iWidget *menu;
101 SDL_Cursor *arrowCursor; 102 SDL_Cursor *arrowCursor; /* TODO: cursors belong in Window */
102 SDL_Cursor *beamCursor; 103 SDL_Cursor *beamCursor;
103 SDL_Cursor *handCursor; 104 SDL_Cursor *handCursor;
104}; 105};
@@ -110,6 +111,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
110 init_Widget(w); 111 init_Widget(w);
111 setId_Widget(w, "document"); 112 setId_Widget(w, "document");
112 iZap(d->certExpiry); 113 iZap(d->certExpiry);
114 d->history = new_History();
113 d->state = blank_DocumentState; 115 d->state = blank_DocumentState;
114 d->url = new_String(); 116 d->url = new_String();
115 d->titleUser = new_String(); 117 d->titleUser = new_String();
@@ -153,6 +155,7 @@ void deinit_DocumentWidget(iDocumentWidget *d) {
153 SDL_FreeCursor(d->arrowCursor); 155 SDL_FreeCursor(d->arrowCursor);
154 SDL_FreeCursor(d->beamCursor); 156 SDL_FreeCursor(d->beamCursor);
155 SDL_FreeCursor(d->handCursor); 157 SDL_FreeCursor(d->handCursor);
158 delete_History(d->history);
156} 159}
157 160
158static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { 161static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {
@@ -258,7 +261,7 @@ static void updateVisible_DocumentWidget_(iDocumentWidget *d) {
258 render_GmDocument(d->doc, visRange, addVisibleLink_DocumentWidget_, d); 261 render_GmDocument(d->doc, visRange, addVisibleLink_DocumentWidget_, d);
259 updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window())); 262 updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window()));
260 /* Remember scroll positions of recently visited pages. */ { 263 /* Remember scroll positions of recently visited pages. */ {
261 iRecentUrl *recent = mostRecentUrl_History(history_App()); 264 iRecentUrl *recent = mostRecentUrl_History(d->history);
262 if (recent) { 265 if (recent) {
263 recent->scrollY = d->scrollY / gap_UI; 266 recent->scrollY = d->scrollY / gap_UI;
264 } 267 }
@@ -424,6 +427,10 @@ static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *r
424 } 427 }
425} 428}
426 429
430iHistory *history_DocumentWidget(iDocumentWidget *d) {
431 return d->history;
432}
433
427void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) { 434void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) {
428 if (cmpStringSc_String(d->url, url, &iCaseInsensitive)) { 435 if (cmpStringSc_String(d->url, url, &iCaseInsensitive)) {
429 set_String(d->url, url); 436 set_String(d->url, url);
@@ -439,7 +446,7 @@ void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBoo
439 iRelease(userPats[i]); 446 iRelease(userPats[i]);
440 } 447 }
441 } 448 }
442 const iRecentUrl *recent = mostRecentUrl_History(history_App()); 449 const iRecentUrl *recent = mostRecentUrl_History(d->history);
443 if (isFromCache && recent && recent->cachedResponse) { 450 if (isFromCache && recent && recent->cachedResponse) {
444 const iGmResponse *resp = recent->cachedResponse; 451 const iGmResponse *resp = recent->cachedResponse;
445 d->state = fetching_DocumentState; 452 d->state = fetching_DocumentState;
@@ -764,7 +771,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
764 pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { 771 pointerLabel_Command(command_UserEvent(ev), "request") == d->request) {
765 checkResponse_DocumentWidget_(d); 772 checkResponse_DocumentWidget_(d);
766 d->state = ready_DocumentState; 773 d->state = ready_DocumentState;
767 setCachedResponse_History(history_App(), response_GmRequest(d->request)); 774 setCachedResponse_History(d->history, response_GmRequest(d->request));
768 iReleasePtr(&d->request); 775 iReleasePtr(&d->request);
769 postCommandf_App("document.changed url:%s", cstr_String(d->url)); 776 postCommandf_App("document.changed url:%s", cstr_String(d->url));
770 return iFalse; 777 return iFalse;
@@ -788,6 +795,14 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
788 fetch_DocumentWidget_(d); 795 fetch_DocumentWidget_(d);
789 return iTrue; 796 return iTrue;
790 } 797 }
798 else if (isCommand_UserEvent(ev, "navigate.back")) {
799 goBack_History(d->history);
800 return iTrue;
801 }
802 else if (isCommand_UserEvent(ev, "navigate.forward")) {
803 goForward_History(d->history);
804 return iTrue;
805 }
791 else if (isCommand_Widget(w, ev, "scroll.moved")) { 806 else if (isCommand_Widget(w, ev, "scroll.moved")) {
792 d->scrollY = arg_Command(command_UserEvent(ev)); 807 d->scrollY = arg_Command(command_UserEvent(ev));
793 updateVisible_DocumentWidget_(d); 808 updateVisible_DocumentWidget_(d);