summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c81
1 files changed, 51 insertions, 30 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 452e5508..337e2a03 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -976,7 +976,7 @@ iBool isPinned_DocumentWidget_(const iDocumentWidget *d) {
976 976
977static void showOrHidePinningIndicator_DocumentWidget_(iDocumentWidget *d) { 977static void showOrHidePinningIndicator_DocumentWidget_(iDocumentWidget *d) {
978 iWidget *w = as_Widget(d); 978 iWidget *w = as_Widget(d);
979 showCollapsed_Widget(findChild_Widget(root_Widget(as_Widget(d)), "document.pinned"), 979 showCollapsed_Widget(findChild_Widget(root_Widget(w), "document.pinned"),
980 isPinned_DocumentWidget_(d)); 980 isPinned_DocumentWidget_(d));
981} 981}
982 982
@@ -1214,7 +1214,9 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
1214 setRange_String(&d->sourceMime, param); 1214 setRange_String(&d->sourceMime, param);
1215 } 1215 }
1216 else if (startsWith_Rangecc(param, "text/") || 1216 else if (startsWith_Rangecc(param, "text/") ||
1217 equal_Rangecc(param, "application/json")) { 1217 equal_Rangecc(param, "application/json") ||
1218 equal_Rangecc(param, "application/x-pem-file") ||
1219 equal_Rangecc(param, "application/pem-certificate-chain")) {
1218 docFormat = plainText_GmDocumentFormat; 1220 docFormat = plainText_GmDocumentFormat;
1219 setRange_String(&d->sourceMime, param); 1221 setRange_String(&d->sourceMime, param);
1220 } 1222 }
@@ -1383,37 +1385,42 @@ static void cacheDocumentGlyphs_DocumentWidget_(const iDocumentWidget *d) {
1383 } 1385 }
1384} 1386}
1385 1387
1388static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float normScrollY,
1389 const iGmResponse *resp) {
1390 setLinkNumberMode_DocumentWidget_(d, iFalse);
1391 clear_ObjectList(d->media);
1392 delete_Gempub(d->sourceGempub);
1393 d->sourceGempub = NULL;
1394 reset_GmDocument(d->doc);
1395 resetWideRuns_DocumentWidget_(d);
1396 d->state = fetching_RequestState;
1397 /* Do the fetch. */ {
1398 d->initNormScrollY = normScrollY;
1399 /* Use the cached response data. */
1400 updateTrust_DocumentWidget_(d, resp);
1401 d->sourceTime = resp->when;
1402 d->sourceStatus = success_GmStatusCode;
1403 format_String(&d->sourceHeader, cstr_Lang("pageinfo.header.cached"));
1404 set_Block(&d->sourceContent, &resp->body);
1405 updateDocument_DocumentWidget_(d, resp, iTrue);
1406 postProcessRequestContent_DocumentWidget_(d, iTrue);
1407 }
1408 d->state = ready_RequestState;
1409 init_Anim(&d->altTextOpacity, 0);
1410 reset_SmoothScroll(&d->scrollY);
1411 init_Anim(&d->scrollY.pos, d->initNormScrollY * size_GmDocument(d->doc).y);
1412 updateSideOpacity_DocumentWidget_(d, iFalse);
1413 updateVisible_DocumentWidget_(d);
1414 moveSpan_SmoothScroll(&d->scrollY, 0, 0); /* clamp position to new max */
1415 cacheDocumentGlyphs_DocumentWidget_(d);
1416 d->drawBufs->flags |= updateTimestampBuf_DrawBufsFlag | updateSideBuf_DrawBufsFlag;
1417 postCommandf_Root(as_Widget(d)->root, "document.changed doc:%p url:%s", d, cstr_String(d->mod.url));
1418}
1419
1386static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { 1420static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
1387 const iRecentUrl *recent = findUrl_History(d->mod.history, d->mod.url); 1421 const iRecentUrl *recent = findUrl_History(d->mod.history, d->mod.url);
1388 if (recent && recent->cachedResponse) { 1422 if (recent && recent->cachedResponse) {
1389 const iGmResponse *resp = recent->cachedResponse; 1423 updateFromCachedResponse_DocumentWidget_(d, recent->normScrollY, recent->cachedResponse);
1390 clear_ObjectList(d->media);
1391 delete_Gempub(d->sourceGempub);
1392 d->sourceGempub = NULL;
1393 reset_GmDocument(d->doc);
1394 resetWideRuns_DocumentWidget_(d);
1395 d->state = fetching_RequestState;
1396 /* Do the fetch. */ {
1397 d->initNormScrollY = recent->normScrollY;
1398 /* Use the cached response data. */
1399 updateTrust_DocumentWidget_(d, resp);
1400 d->sourceTime = resp->when;
1401 d->sourceStatus = success_GmStatusCode;
1402 format_String(&d->sourceHeader, cstr_Lang("pageinfo.header.cached"));
1403 set_Block(&d->sourceContent, &resp->body);
1404 updateDocument_DocumentWidget_(d, resp, iTrue);
1405 postProcessRequestContent_DocumentWidget_(d, iTrue);
1406 }
1407 d->state = ready_RequestState;
1408 init_Anim(&d->altTextOpacity, 0);
1409 reset_SmoothScroll(&d->scrollY);
1410 init_Anim(&d->scrollY.pos, d->initNormScrollY * size_GmDocument(d->doc).y);
1411 updateSideOpacity_DocumentWidget_(d, iFalse);
1412 updateVisible_DocumentWidget_(d);
1413 moveSpan_SmoothScroll(&d->scrollY, 0, 0); /* clamp position to new max */
1414 cacheDocumentGlyphs_DocumentWidget_(d);
1415 d->drawBufs->flags |= updateTimestampBuf_DrawBufsFlag | updateSideBuf_DrawBufsFlag;
1416 postCommandf_Root(as_Widget(d)->root, "document.changed doc:%p url:%s", d, cstr_String(d->mod.url));
1417 return iTrue; 1424 return iTrue;
1418 } 1425 }
1419 else if (!isEmpty_String(d->mod.url)) { 1426 else if (!isEmpty_String(d->mod.url)) {
@@ -4413,6 +4420,20 @@ void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBoo
4413 } 4420 }
4414} 4421}
4415 4422
4423void setUrlAndSource_DocumentWidget(iDocumentWidget *d, const iString *url, const iString *mime,
4424 const iBlock *source) {
4425 setLinkNumberMode_DocumentWidget_(d, iFalse);
4426 set_String(d->mod.url, url);
4427 parseUser_DocumentWidget_(d);
4428 iGmResponse *resp = new_GmResponse();
4429 resp->statusCode = success_GmStatusCode;
4430 initCurrent_Time(&resp->when);
4431 set_String(&resp->meta, mime);
4432 set_Block(&resp->body, source);
4433 updateFromCachedResponse_DocumentWidget_(d, 0, resp);
4434 delete_GmResponse(resp);
4435}
4436
4416iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) { 4437iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) {
4417 iDocumentWidget *d = new_DocumentWidget(); 4438 iDocumentWidget *d = new_DocumentWidget();
4418 delete_History(d->mod.history); 4439 delete_History(d->mod.history);