summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/documentwidget.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index e0415f6c..232b4140 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -133,6 +133,7 @@ enum iDocumentWidgetFlag {
133 showLinkNumbers_DocumentWidgetFlag = iBit(3), 133 showLinkNumbers_DocumentWidgetFlag = iBit(3),
134 setHoverViaKeys_DocumentWidgetFlag = iBit(4), 134 setHoverViaKeys_DocumentWidgetFlag = iBit(4),
135 newTabViaHomeKeys_DocumentWidgetFlag = iBit(5), 135 newTabViaHomeKeys_DocumentWidgetFlag = iBit(5),
136 centerVertically_DocumentWidgetFlag = iBit(6),
136}; 137};
137 138
138enum iDocumentLinkOrdinalMode { 139enum iDocumentLinkOrdinalMode {
@@ -151,6 +152,7 @@ struct Impl_DocumentWidget {
151 iGmRequest * request; 152 iGmRequest * request;
152 iAtomicInt isRequestUpdated; /* request has new content, need to parse it */ 153 iAtomicInt isRequestUpdated; /* request has new content, need to parse it */
153 iObjectList * media; 154 iObjectList * media;
155 enum iGmStatusCode sourceStatus;
154 iString sourceHeader; 156 iString sourceHeader;
155 iString sourceMime; 157 iString sourceMime;
156 iBlock sourceContent; /* original content as received, for saving */ 158 iBlock sourceContent; /* original content as received, for saving */
@@ -231,6 +233,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
231 init_Array(&d->outline, sizeof(iOutlineItem)); 233 init_Array(&d->outline, sizeof(iOutlineItem));
232 init_Anim(&d->sideOpacity, 0); 234 init_Anim(&d->sideOpacity, 0);
233 init_Anim(&d->outlineOpacity, 0); 235 init_Anim(&d->outlineOpacity, 0);
236 d->sourceStatus = none_GmStatusCode;
234 init_String(&d->sourceHeader); 237 init_String(&d->sourceHeader);
235 init_String(&d->sourceMime); 238 init_String(&d->sourceMime);
236 init_Block(&d->sourceContent, 0); 239 init_Block(&d->sourceContent, 0);
@@ -332,7 +335,7 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
332 rect.pos.y += margin; 335 rect.pos.y += margin;
333 rect.size.y -= margin; 336 rect.size.y -= margin;
334 } 337 }
335 if (prefs_App()->centerShortDocs) { 338 if (d->flags & centerVertically_DocumentWidgetFlag) {
336 const iInt2 docSize = size_GmDocument(d->doc); 339 const iInt2 docSize = size_GmDocument(d->doc);
337 if (docSize.y < rect.size.y) { 340 if (docSize.y < rect.size.y) {
338 /* Center vertically if short. There is one empty paragraph line's worth of margin 341 /* Center vertically if short. There is one empty paragraph line's worth of margin
@@ -592,6 +595,10 @@ static iRangecc currentHeading_DocumentWidget_(const iDocumentWidget *d) {
592} 595}
593 596
594static void updateVisible_DocumentWidget_(iDocumentWidget *d) { 597static void updateVisible_DocumentWidget_(iDocumentWidget *d) {
598 iChangeFlags(d->flags,
599 centerVertically_DocumentWidgetFlag,
600 prefs_App()->centerShortDocs || startsWithCase_String(d->mod.url, "about:") ||
601 !isSuccess_GmStatusCode(d->sourceStatus));
595 const iRangei visRange = visibleRange_DocumentWidget_(d); 602 const iRangei visRange = visibleRange_DocumentWidget_(d);
596 const iRect bounds = bounds_Widget(as_Widget(d)); 603 const iRect bounds = bounds_Widget(as_Widget(d));
597 setRange_ScrollWidget(d->scroll, (iRangei){ 0, scrollMax_DocumentWidget_(d) }); 604 setRange_ScrollWidget(d->scroll, (iRangei){ 0, scrollMax_DocumentWidget_(d) });
@@ -1038,6 +1045,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
1038 /* Use the cached response data. */ 1045 /* Use the cached response data. */
1039 updateTrust_DocumentWidget_(d, resp); 1046 updateTrust_DocumentWidget_(d, resp);
1040 d->sourceTime = resp->when; 1047 d->sourceTime = resp->when;
1048 d->sourceStatus = success_GmStatusCode;
1041 format_String(&d->sourceHeader, "(cached content)"); 1049 format_String(&d->sourceHeader, "(cached content)");
1042 updateTimestampBuf_DocumentWidget_(d); 1050 updateTimestampBuf_DocumentWidget_(d);
1043 set_Block(&d->sourceContent, &resp->body); 1051 set_Block(&d->sourceContent, &resp->body);
@@ -1195,6 +1203,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
1195 updateTrust_DocumentWidget_(d, resp); 1203 updateTrust_DocumentWidget_(d, resp);
1196 init_Anim(&d->sideOpacity, 0); 1204 init_Anim(&d->sideOpacity, 0);
1197 format_String(&d->sourceHeader, "%d %s", statusCode, get_GmError(statusCode)->title); 1205 format_String(&d->sourceHeader, "%d %s", statusCode, get_GmError(statusCode)->title);
1206 d->sourceStatus = statusCode;
1198 switch (category_GmStatusCode(statusCode)) { 1207 switch (category_GmStatusCode(statusCode)) {
1199 case categoryInput_GmStatusCode: { 1208 case categoryInput_GmStatusCode: {
1200 iUrl parts; 1209 iUrl parts;
@@ -1576,7 +1585,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1576 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { 1585 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) {
1577 /* Alt/Option key may be involved in window size changes. */ 1586 /* Alt/Option key may be involved in window size changes. */
1578 iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse); 1587 iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse);
1579 const iBool keepCenter = equal_Command(cmd, "font.changed"); 1588 const iBool keepCenter = equal_Command(cmd, "font.changed");
1580 updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, keepCenter); 1589 updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, keepCenter);
1581 updateSideIconBuf_DocumentWidget_(d); 1590 updateSideIconBuf_DocumentWidget_(d);
1582 updateOutline_DocumentWidget_(d); 1591 updateOutline_DocumentWidget_(d);
@@ -1599,6 +1608,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1599 } 1608 }
1600 else if (equal_Command(cmd, "theme.changed") && document_App() == d) { 1609 else if (equal_Command(cmd, "theme.changed") && document_App() == d) {
1601 updateTheme_DocumentWidget_(d); 1610 updateTheme_DocumentWidget_(d);
1611 updateVisible_DocumentWidget_(d);
1602 updateTrust_DocumentWidget_(d, NULL); 1612 updateTrust_DocumentWidget_(d, NULL);
1603 updateSideIconBuf_DocumentWidget_(d); 1613 updateSideIconBuf_DocumentWidget_(d);
1604 invalidate_DocumentWidget_(d); 1614 invalidate_DocumentWidget_(d);