diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-21 11:48:07 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-21 11:48:07 +0200 |
commit | 0b2b40a233c014e684f6efed0298efda02e7abf4 (patch) | |
tree | a1bc3a095b57279cd27b5ef65498b7c9a0fcf457 /src/ui/documentwidget.c | |
parent | c651680715f7549a0cdbdbb10d535cba2272d9d0 (diff) |
Added option to load image instead of scrolling
One can now read through a page and load all inline images simply by repeatedly pressing Space or cursor down.
Key repeat events do not trigger image loads.
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 59f5a92c..0fc969ba 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1151,10 +1151,8 @@ static iMediaRequest *findMediaRequest_DocumentWidget_(const iDocumentWidget *d, | |||
1151 | 1151 | ||
1152 | static iBool requestMedia_DocumentWidget_(iDocumentWidget *d, iGmLinkId linkId) { | 1152 | static iBool requestMedia_DocumentWidget_(iDocumentWidget *d, iGmLinkId linkId) { |
1153 | if (!findMediaRequest_DocumentWidget_(d, linkId)) { | 1153 | if (!findMediaRequest_DocumentWidget_(d, linkId)) { |
1154 | pushBack_ObjectList( | 1154 | const iString *imageUrl = absoluteUrl_String(d->mod.url, linkUrl_GmDocument(d->doc, linkId)); |
1155 | d->media, | 1155 | pushBack_ObjectList(d->media, iClob(new_MediaRequest(d, linkId, imageUrl))); |
1156 | iClob(new_MediaRequest( | ||
1157 | d, linkId, absoluteUrl_String(d->mod.url, linkUrl_GmDocument(d->doc, linkId))))); | ||
1158 | invalidate_DocumentWidget_(d); | 1156 | invalidate_DocumentWidget_(d); |
1159 | return iTrue; | 1157 | return iTrue; |
1160 | } | 1158 | } |
@@ -1235,6 +1233,22 @@ static void allocVisBuffer_DocumentWidget_(const iDocumentWidget *d) { | |||
1235 | } | 1233 | } |
1236 | } | 1234 | } |
1237 | 1235 | ||
1236 | static iBool fetchNextUnfetchedImage_DocumentWidget_(iDocumentWidget *d) { | ||
1237 | iConstForEach(PtrArray, i, &d->visibleLinks) { | ||
1238 | const iGmRun *run = i.ptr; | ||
1239 | if (run->linkId && !run->imageId && ~run->flags & decoration_GmRunFlag) { | ||
1240 | const int linkFlags = linkFlags_GmDocument(d->doc, run->linkId); | ||
1241 | if (isMediaLink_GmDocument(d->doc, run->linkId) && | ||
1242 | ~linkFlags & content_GmLinkFlag && ~linkFlags & permanent_GmLinkFlag ) { | ||
1243 | if (requestMedia_DocumentWidget_(d, run->linkId)) { | ||
1244 | return iTrue; | ||
1245 | } | ||
1246 | } | ||
1247 | } | ||
1248 | } | ||
1249 | return iFalse; | ||
1250 | } | ||
1251 | |||
1238 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | 1252 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { |
1239 | iWidget *w = as_Widget(d); | 1253 | iWidget *w = as_Widget(d); |
1240 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { | 1254 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { |
@@ -1572,13 +1586,16 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1572 | return iTrue; | 1586 | return iTrue; |
1573 | } | 1587 | } |
1574 | else if (equal_Command(cmd, "scroll.page") && document_App() == d) { | 1588 | else if (equal_Command(cmd, "scroll.page") && document_App() == d) { |
1575 | if (argLabel_Command(cmd, "repeat")) { | 1589 | const int dir = arg_Command(cmd); |
1576 | /* TODO: Adjust scroll animation to be linear during repeated scroll? */ | 1590 | if (!argLabel_Command(cmd, "repeat") && prefs_App()->loadImageInsteadOfScrolling && |
1591 | dir > 0) { | ||
1592 | if (fetchNextUnfetchedImage_DocumentWidget_(d)) { | ||
1593 | return iTrue; | ||
1594 | } | ||
1577 | } | 1595 | } |
1578 | smoothScroll_DocumentWidget_(d, | 1596 | smoothScroll_DocumentWidget_(d, |
1579 | arg_Command(cmd) * | 1597 | dir * (0.5f * height_Rect(documentBounds_DocumentWidget_(d)) - |
1580 | (0.5f * height_Rect(documentBounds_DocumentWidget_(d)) - | 1598 | 0 * lineHeight_Text(paragraph_FontId)), |
1581 | 0 * lineHeight_Text(paragraph_FontId)), | ||
1582 | smoothDuration_DocumentWidget_); | 1599 | smoothDuration_DocumentWidget_); |
1583 | return iTrue; | 1600 | return iTrue; |
1584 | } | 1601 | } |
@@ -1599,8 +1616,15 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1599 | return iTrue; | 1616 | return iTrue; |
1600 | } | 1617 | } |
1601 | else if (equal_Command(cmd, "scroll.step") && document_App() == d) { | 1618 | else if (equal_Command(cmd, "scroll.step") && document_App() == d) { |
1619 | const int dir = arg_Command(cmd); | ||
1620 | if (!argLabel_Command(cmd, "repeat") && prefs_App()->loadImageInsteadOfScrolling && | ||
1621 | dir > 0) { | ||
1622 | if (fetchNextUnfetchedImage_DocumentWidget_(d)) { | ||
1623 | return iTrue; | ||
1624 | } | ||
1625 | } | ||
1602 | smoothScroll_DocumentWidget_(d, | 1626 | smoothScroll_DocumentWidget_(d, |
1603 | 3 * lineHeight_Text(paragraph_FontId) * arg_Command(cmd), | 1627 | 3 * lineHeight_Text(paragraph_FontId) * dir, |
1604 | smoothDuration_DocumentWidget_); | 1628 | smoothDuration_DocumentWidget_); |
1605 | return iTrue; | 1629 | return iTrue; |
1606 | } | 1630 | } |