diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 03119ca2..97ecb4ba 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
36 | #include "gmdocument.h" | 36 | #include "gmdocument.h" |
37 | #include "gmrequest.h" | 37 | #include "gmrequest.h" |
38 | #include "gmutil.h" | 38 | #include "gmutil.h" |
39 | #include "gopher.h" | ||
39 | #include "history.h" | 40 | #include "history.h" |
40 | #include "indicatorwidget.h" | 41 | #include "indicatorwidget.h" |
41 | #include "inputwidget.h" | 42 | #include "inputwidget.h" |
@@ -921,6 +922,7 @@ static void documentRunsInvalidated_DocumentView_(iDocumentView *d) { | |||
921 | d->hoverPre = NULL; | 922 | d->hoverPre = NULL; |
922 | d->hoverAltPre = NULL; | 923 | d->hoverAltPre = NULL; |
923 | d->hoverLink = NULL; | 924 | d->hoverLink = NULL; |
925 | clear_PtrArray(&d->visibleMedia); | ||
924 | iZap(d->visibleRuns); | 926 | iZap(d->visibleRuns); |
925 | iZap(d->renderRuns); | 927 | iZap(d->renderRuns); |
926 | } | 928 | } |
@@ -2900,10 +2902,14 @@ static void addBannerWarnings_DocumentWidget_(iDocumentWidget *d) { | |||
2900 | add_Banner(d->banner, warning_BannerType, none_GmStatusCode, title, str); | 2902 | add_Banner(d->banner, warning_BannerType, none_GmStatusCode, title, str); |
2901 | } | 2903 | } |
2902 | /* Warnings related to page contents. */ | 2904 | /* Warnings related to page contents. */ |
2903 | const int dismissed = | 2905 | int dismissed = |
2904 | value_SiteSpec(collectNewRange_String(urlRoot_String(d->mod.url)), | 2906 | value_SiteSpec(collectNewRange_String(urlRoot_String(d->mod.url)), |
2905 | dismissWarnings_SiteSpecKey) | | 2907 | dismissWarnings_SiteSpecKey) | |
2906 | (!prefs_App()->warnAboutMissingGlyphs ? missingGlyphs_GmDocumentWarning : 0); | 2908 | (!prefs_App()->warnAboutMissingGlyphs ? missingGlyphs_GmDocumentWarning : 0); |
2909 | /* File pages don't allow dismissing warnings, so skip it. */ | ||
2910 | if (equalCase_Rangecc(urlScheme_String(d->mod.url), "file")) { | ||
2911 | dismissed |= ansiEscapes_GmDocumentWarning; | ||
2912 | } | ||
2907 | const int warnings = warnings_GmDocument(d->view.doc) & ~dismissed; | 2913 | const int warnings = warnings_GmDocument(d->view.doc) & ~dismissed; |
2908 | if (warnings & missingGlyphs_GmDocumentWarning) { | 2914 | if (warnings & missingGlyphs_GmDocumentWarning) { |
2909 | add_Banner(d->banner, warning_BannerType, missingGlyphs_GmStatusCode, NULL, NULL); | 2915 | add_Banner(d->banner, warning_BannerType, missingGlyphs_GmStatusCode, NULL, NULL); |
@@ -4069,14 +4075,12 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
4069 | return iTrue; | 4075 | return iTrue; |
4070 | } | 4076 | } |
4071 | else if (equal_Command(cmd, "valueinput.cancelled") && | 4077 | else if (equal_Command(cmd, "valueinput.cancelled") && |
4072 | equal_Rangecc(range_Command(cmd, "id"), "document.input.submit") && document_App() == d) { | 4078 | equal_Rangecc(range_Command(cmd, "id"), "!document.input.submit") && document_App() == d) { |
4073 | postCommand_Root(get_Root(), "navigate.back"); | 4079 | postCommand_Root(get_Root(), "navigate.back"); |
4074 | return iTrue; | 4080 | return iTrue; |
4075 | } | 4081 | } |
4076 | else if (equalWidget_Command(cmd, w, "document.request.updated") && | 4082 | else if (equalWidget_Command(cmd, w, "document.request.updated") && |
4077 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { | 4083 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { |
4078 | // set_Block(&d->sourceContent, &lockResponse_GmRequest(d->request)->body); | ||
4079 | // unlockResponse_GmRequest(d->request); | ||
4080 | if (document_App() == d) { | 4084 | if (document_App() == d) { |
4081 | updateFetchProgress_DocumentWidget_(d); | 4085 | updateFetchProgress_DocumentWidget_(d); |
4082 | } | 4086 | } |
@@ -4302,6 +4306,9 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
4302 | else if (equal_Command(cmd, "navigate.parent") && document_App() == d) { | 4306 | else if (equal_Command(cmd, "navigate.parent") && document_App() == d) { |
4303 | iUrl parts; | 4307 | iUrl parts; |
4304 | init_Url(&parts, d->mod.url); | 4308 | init_Url(&parts, d->mod.url); |
4309 | if (endsWith_Rangecc(parts.path, "/index.gmi")) { | ||
4310 | parts.path.end -= 9; /* This is the default index page. */ | ||
4311 | } | ||
4305 | /* Remove the last path segment. */ | 4312 | /* Remove the last path segment. */ |
4306 | if (size_Range(&parts.path) > 1) { | 4313 | if (size_Range(&parts.path) > 1) { |
4307 | if (parts.path.end[-1] == '/') { | 4314 | if (parts.path.end[-1] == '/') { |
@@ -4311,14 +4318,42 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
4311 | if (parts.path.end[-1] == '/') break; | 4318 | if (parts.path.end[-1] == '/') break; |
4312 | parts.path.end--; | 4319 | parts.path.end--; |
4313 | } | 4320 | } |
4314 | postCommandf_Root(w->root, | 4321 | iString *parentUrl = collectNewRange_String((iRangecc){ constBegin_String(d->mod.url), |
4315 | "open url:%s", | 4322 | parts.path.end }); |
4316 | cstr_Rangecc((iRangecc){ constBegin_String(d->mod.url), parts.path.end })); | 4323 | /* Always go to a gophermap. */ |
4324 | setUrlItemType_Gopher(parentUrl, '1'); | ||
4325 | /* Hierarchical navigation doesn't make sense with Titan. */ | ||
4326 | if (startsWith_String(parentUrl, "titan://")) { | ||
4327 | /* We have no way of knowing if the corresponding URL is valid for Gemini, | ||
4328 | but let's try anyway. */ | ||
4329 | set_String(parentUrl, withScheme_String(parentUrl, "gemini")); | ||
4330 | stripUrlPort_String(parentUrl); | ||
4331 | } | ||
4332 | if (!cmpCase_String(parentUrl, "about:")) { | ||
4333 | setCStr_String(parentUrl, "about:about"); | ||
4334 | } | ||
4335 | postCommandf_Root(w->root, "open url:%s", cstr_String(parentUrl)); | ||
4317 | } | 4336 | } |
4318 | return iTrue; | 4337 | return iTrue; |
4319 | } | 4338 | } |
4320 | else if (equal_Command(cmd, "navigate.root") && document_App() == d) { | 4339 | else if (equal_Command(cmd, "navigate.root") && document_App() == d) { |
4321 | postCommandf_Root(w->root, "open url:%s/", cstr_Rangecc(urlRoot_String(d->mod.url))); | 4340 | iString *rootUrl = collectNewRange_String(urlRoot_String(d->mod.url)); |
4341 | /* Always go to a gophermap. */ | ||
4342 | setUrlItemType_Gopher(rootUrl, '1'); | ||
4343 | /* Hierarchical navigation doesn't make sense with Titan. */ | ||
4344 | if (startsWith_String(rootUrl, "titan://")) { | ||
4345 | /* We have no way of knowing if the corresponding URL is valid for Gemini, | ||
4346 | but let's try anyway. */ | ||
4347 | set_String(rootUrl, withScheme_String(rootUrl, "gemini")); | ||
4348 | stripUrlPort_String(rootUrl); | ||
4349 | } | ||
4350 | if (!cmpCase_String(rootUrl, "about:")) { | ||
4351 | setCStr_String(rootUrl, "about:about"); | ||
4352 | } | ||
4353 | else { | ||
4354 | appendCStr_String(rootUrl, "/"); | ||
4355 | } | ||
4356 | postCommandf_Root(w->root, "open url:%s", cstr_String(rootUrl)); | ||
4322 | return iTrue; | 4357 | return iTrue; |
4323 | } | 4358 | } |
4324 | else if (equalWidget_Command(cmd, w, "scroll.moved")) { | 4359 | else if (equalWidget_Command(cmd, w, "scroll.moved")) { |
@@ -4341,6 +4376,12 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
4341 | return iTrue; | 4376 | return iTrue; |
4342 | } | 4377 | } |
4343 | else if (equal_Command(cmd, "scroll.top") && document_App() == d) { | 4378 | else if (equal_Command(cmd, "scroll.top") && document_App() == d) { |
4379 | if (argLabel_Command(cmd, "smooth")) { | ||
4380 | stopWidgetMomentum_Touch(w); | ||
4381 | smoothScroll_DocumentView_(&d->view, -pos_SmoothScroll(&d->view.scrollY), 500); | ||
4382 | d->view.scrollY.flags |= muchSofter_AnimFlag; | ||
4383 | return iTrue; | ||
4384 | } | ||
4344 | init_Anim(&d->view.scrollY.pos, 0); | 4385 | init_Anim(&d->view.scrollY.pos, 0); |
4345 | invalidate_VisBuf(d->view.visBuf); | 4386 | invalidate_VisBuf(d->view.visBuf); |
4346 | clampScroll_DocumentView_(&d->view); | 4387 | clampScroll_DocumentView_(&d->view); |