diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-16 08:08:40 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-16 08:08:40 +0200 |
commit | 0d0de1248767931523c93212bbcae4e311929403 (patch) | |
tree | 0584429362c37b5ea97aa494d1c44d6250849f01 | |
parent | 6b2f1ac9c2109a237efff88c544e729445ad09f8 (diff) |
DocumentWidget: Only center normal pages
`about:` and error pages are centered as they are "internal" pages.
-rw-r--r-- | src/ui/documentwidget.c | 14 |
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 | ||
138 | enum iDocumentLinkOrdinalMode { | 139 | enum 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 | ||
594 | static void updateVisible_DocumentWidget_(iDocumentWidget *d) { | 597 | static 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); |