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.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index d9b78a4d..0b9757d4 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -48,6 +48,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
48#include "visbuf.h" 48#include "visbuf.h"
49#include "visited.h" 49#include "visited.h"
50 50
51#if defined (iPlatformAppleMobile)
52# include "ios.h"
53#endif
54
51#include <the_Foundation/file.h> 55#include <the_Foundation/file.h>
52#include <the_Foundation/fileinfo.h> 56#include <the_Foundation/fileinfo.h>
53#include <the_Foundation/objectlist.h> 57#include <the_Foundation/objectlist.h>
@@ -220,6 +224,7 @@ struct Impl_DocumentWidget {
220 SDL_Texture * sideIconBuf; 224 SDL_Texture * sideIconBuf;
221 iTextBuf * timestampBuf; 225 iTextBuf * timestampBuf;
222 iTranslation * translation; 226 iTranslation * translation;
227 iWidget * phoneToolbar;
223}; 228};
224 229
225iDefineObjectConstruction(DocumentWidget) 230iDefineObjectConstruction(DocumentWidget)
@@ -231,6 +236,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
231 setFlags_Widget(w, hover_WidgetFlag, iTrue); 236 setFlags_Widget(w, hover_WidgetFlag, iTrue);
232 init_PersistentDocumentState(&d->mod); 237 init_PersistentDocumentState(&d->mod);
233 d->flags = 0; 238 d->flags = 0;
239 d->phoneToolbar = NULL;
234 iZap(d->certExpiry); 240 iZap(d->certExpiry);
235 d->certFingerprint = new_Block(0); 241 d->certFingerprint = new_Block(0);
236 d->certFlags = 0; 242 d->certFlags = 0;
@@ -440,8 +446,13 @@ static float normScrollPos_DocumentWidget_(const iDocumentWidget *d) {
440} 446}
441 447
442static int scrollMax_DocumentWidget_(const iDocumentWidget *d) { 448static int scrollMax_DocumentWidget_(const iDocumentWidget *d) {
443 return size_GmDocument(d->doc).y - height_Rect(bounds_Widget(constAs_Widget(d))) + 449 int sm = size_GmDocument(d->doc).y - height_Rect(bounds_Widget(constAs_Widget(d))) +
444 (hasSiteBanner_GmDocument(d->doc) ? 1 : 2) * d->pageMargin * gap_UI; 450 (hasSiteBanner_GmDocument(d->doc) ? 1 : 2) * d->pageMargin * gap_UI;
451 if (d->phoneToolbar) {
452 sm += rootSize_Window(get_Window()).y -
453 top_Rect(boundsWithoutVisualOffset_Widget(d->phoneToolbar));
454 }
455 return sm;
445} 456}
446 457
447static void invalidateLink_DocumentWidget_(iDocumentWidget *d, iGmLinkId id) { 458static void invalidateLink_DocumentWidget_(iDocumentWidget *d, iGmLinkId id) {
@@ -815,9 +826,10 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode
815 appendFormat_String(src, 826 appendFormat_String(src,
816 "\n```\n%s\n```\n" 827 "\n```\n%s\n```\n"
817 "You can save it as a file to your Downloads folder, though. " 828 "You can save it as a file to your Downloads folder, though. "
818 "Press %s or select \"Save to Downloads\" from the menu.", 829 "Press %s or select \"%s\" from the menu.",
819 cstr_String(meta), 830 cstr_String(meta),
820 cstr_String(key)); 831 cstr_String(key),
832 saveToDownloads_Label);
821 break; 833 break;
822 } 834 }
823 case slowDown_GmStatusCode: 835 case slowDown_GmStatusCode:
@@ -1085,6 +1097,14 @@ static void smoothScroll_DocumentWidget_(iDocumentWidget *d, int offset, int dur
1085 const int scrollMax = scrollMax_DocumentWidget_(d); 1097 const int scrollMax = scrollMax_DocumentWidget_(d);
1086 if (scrollMax > 0) { 1098 if (scrollMax > 0) {
1087 destY = iMin(destY, scrollMax); 1099 destY = iMin(destY, scrollMax);
1100 if (deviceType_App() == phone_AppDeviceType) {
1101 if (destY == scrollMax) {
1102 showToolbars_Window(get_Window(), iTrue);
1103 }
1104 else if (prefs_App()->hideToolbarOnScroll && iAbs(offset) > 5) {
1105 showToolbars_Window(get_Window(), offset < 0);
1106 }
1107 }
1088 } 1108 }
1089 else { 1109 else {
1090 destY = 0; 1110 destY = 0;
@@ -1443,12 +1463,17 @@ static void saveToDownloads_(const iString *url, const iString *mime, const iBlo
1443 iFile *f = new_File(savePath); 1463 iFile *f = new_File(savePath);
1444 if (open_File(f, writeOnly_FileMode)) { 1464 if (open_File(f, writeOnly_FileMode)) {
1445 write_File(f, content); 1465 write_File(f, content);
1466 close_File(f);
1446 const size_t size = size_Block(content); 1467 const size_t size = size_Block(content);
1447 const iBool isMega = size >= 1000000; 1468 const iBool isMega = size >= 1000000;
1469#if defined (iPlatformAppleMobile)
1470 exportDownloadedFile_iOS(savePath);
1471#else
1448 makeMessage_Widget(uiHeading_ColorEscape "FILE SAVED", 1472 makeMessage_Widget(uiHeading_ColorEscape "FILE SAVED",
1449 format_CStr("%s\nSize: %.3f %s", cstr_String(path_File(f)), 1473 format_CStr("%s\nSize: %.3f %s", cstr_String(path_File(f)),
1450 isMega ? size / 1.0e6f : (size / 1.0e3f), 1474 isMega ? size / 1.0e6f : (size / 1.0e3f),
1451 isMega ? "MB" : "KB")); 1475 isMega ? "MB" : "KB"));
1476#endif
1452 } 1477 }
1453 else { 1478 else {
1454 makeMessage_Widget(uiTextCaution_ColorEscape "ERROR SAVING FILE", 1479 makeMessage_Widget(uiTextCaution_ColorEscape "ERROR SAVING FILE",
@@ -1496,8 +1521,8 @@ static const int homeRowKeys_[] = {
1496static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d, 1521static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d,
1497 iBool keepCenter) { 1522 iBool keepCenter) {
1498 const int newWidth = documentWidth_DocumentWidget_(d); 1523 const int newWidth = documentWidth_DocumentWidget_(d);
1499 if (newWidth == size_GmDocument(d->doc).x) { 1524 if (newWidth == size_GmDocument(d->doc).x && !keepCenter /* not a font change */) {
1500 return iFalse; /* hasn't changed */ 1525 return iFalse;
1501 } 1526 }
1502 /* Font changes (i.e., zooming) will keep the view centered, otherwise keep the top 1527 /* Font changes (i.e., zooming) will keep the view centered, otherwise keep the top
1503 of the visible area fixed. */ 1528 of the visible area fixed. */
@@ -1526,6 +1551,7 @@ static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumen
1526 scrollTo_DocumentWidget_(d, mid_Rect(run->bounds).y, iTrue); 1551 scrollTo_DocumentWidget_(d, mid_Rect(run->bounds).y, iTrue);
1527 } 1552 }
1528 } 1553 }
1554 return iTrue;
1529} 1555}
1530 1556
1531static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { 1557static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
@@ -1533,6 +1559,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1533 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { 1559 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) {
1534 /* Alt/Option key may be involved in window size changes. */ 1560 /* Alt/Option key may be involved in window size changes. */
1535 iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse); 1561 iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse);
1562 d->phoneToolbar = findWidget_App("toolbar");
1536 const iBool keepCenter = equal_Command(cmd, "font.changed"); 1563 const iBool keepCenter = equal_Command(cmd, "font.changed");
1537 updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, keepCenter); 1564 updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, keepCenter);
1538 updateSideIconBuf_DocumentWidget_(d); 1565 updateSideIconBuf_DocumentWidget_(d);
@@ -2361,36 +2388,16 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2361 } 2388 }
2362 } 2389 }
2363 else if (ev->type == SDL_MOUSEWHEEL && isHover_Widget(w)) { 2390 else if (ev->type == SDL_MOUSEWHEEL && isHover_Widget(w)) {
2364 /* TODO: Maybe clean this up a bit? Wheel events are used for scrolling
2365 but they are calculated differently based on device/mouse/trackpad. */
2366 const iInt2 mouseCoord = mouseCoord_Window(get_Window()); 2391 const iInt2 mouseCoord = mouseCoord_Window(get_Window());
2367 if (isPerPixel_MouseWheelEvent(&ev->wheel)) { 2392 if (isPerPixel_MouseWheelEvent(&ev->wheel)) {
2368 stop_Anim(&d->scrollY); 2393 stop_Anim(&d->scrollY);
2369 iInt2 wheel = init_I2(ev->wheel.x, ev->wheel.y); 2394 iInt2 wheel = init_I2(ev->wheel.x, ev->wheel.y);
2370//# if defined (iPlatformAppleMobile)
2371// wheel.x = -wheel.x;
2372//# else
2373// /* Wheel mounts are in points. */
2374// mulfv_I2(&wheel, get_Window()->pixelRatio);
2375// /* Only scroll on one axis at a time. */
2376// if (iAbs(wheel.x) > iAbs(wheel.y)) {
2377// wheel.y = 0;
2378// }
2379// else {
2380// wheel.x = 0;
2381// }
2382//# endif
2383 scroll_DocumentWidget_(d, -wheel.y); 2395 scroll_DocumentWidget_(d, -wheel.y);
2384 scrollWideBlock_DocumentWidget_(d, mouseCoord, -wheel.x, 0); 2396 scrollWideBlock_DocumentWidget_(d, mouseCoord, -wheel.x, 0);
2385 } 2397 }
2386 else { 2398 else {
2387 /* Traditional mouse wheel. */ 2399 /* Traditional mouse wheel. */
2388//#if defined (iPlatformApple)
2389// /* Disregard wheel acceleration applied by the OS. */
2390// const int amount = iSign(ev->wheel.y);
2391//#else
2392 const int amount = ev->wheel.y; 2400 const int amount = ev->wheel.y;
2393//#endif
2394 if (keyMods_Sym(modState_Keys()) == KMOD_PRIMARY) { 2401 if (keyMods_Sym(modState_Keys()) == KMOD_PRIMARY) {
2395 postCommandf_App("zoom.delta arg:%d", amount > 0 ? 10 : -10); 2402 postCommandf_App("zoom.delta arg:%d", amount > 0 ? 10 : -10);
2396 return iTrue; 2403 return iTrue;
@@ -2513,7 +2520,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2513 d->contextLink->mediaType != download_GmRunMediaType) { 2520 d->contextLink->mediaType != download_GmRunMediaType) {
2514 if (isFinished_GmRequest(mediaReq->req)) { 2521 if (isFinished_GmRequest(mediaReq->req)) {
2515 pushBack_Array(&items, 2522 pushBack_Array(&items,
2516 &(iMenuItem){ download_Icon " Save to Downloads", 2523 &(iMenuItem){ download_Icon " " saveToDownloads_Label,
2517 0, 2524 0,
2518 0, 2525 0,
2519 format_CStr("document.media.save link:%u", 2526 format_CStr("document.media.save link:%u",
@@ -2558,7 +2565,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2558 &items, 2565 &items,
2559 (iMenuItem[]){ 2566 (iMenuItem[]){
2560 { "Copy Page Source", 'c', KMOD_PRIMARY, "copy" }, 2567 { "Copy Page Source", 'c', KMOD_PRIMARY, "copy" },
2561 { download_Icon " Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" } }, 2568 { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" } },
2562 2); 2569 2);
2563 } 2570 }
2564 } 2571 }