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.c90
1 files changed, 48 insertions, 42 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 638906cf..5c1e473f 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -750,7 +750,7 @@ static uint32_t mediaUpdateInterval_DocumentWidget_(const iDocumentWidget *d) {
750 if (document_App() != d) { 750 if (document_App() != d) {
751 return 0; 751 return 0;
752 } 752 }
753 if (get_Window()->isDrawFrozen) { 753 if (as_MainWindow(window_Widget(d))->isDrawFrozen) {
754 return 0; 754 return 0;
755 } 755 }
756 static const uint32_t invalidInterval_ = ~0u; 756 static const uint32_t invalidInterval_ = ~0u;
@@ -934,7 +934,7 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) {
934 iString *text = collect_String(joinCStr_StringArray(title, " \u2014 ")); 934 iString *text = collect_String(joinCStr_StringArray(title, " \u2014 "));
935 if (setWindow) { 935 if (setWindow) {
936 /* Longest version for the window title, and omit the icon. */ 936 /* Longest version for the window title, and omit the icon. */
937 setTitle_Window(get_Window(), text); 937 setTitle_MainWindow(get_MainWindow(), text);
938 setWindow = iFalse; 938 setWindow = iFalse;
939 } 939 }
940 const iChar siteIcon = siteIcon_GmDocument(d->doc); 940 const iChar siteIcon = siteIcon_GmDocument(d->doc);
@@ -1010,6 +1010,9 @@ static void documentRunsInvalidated_DocumentWidget_(iDocumentWidget *d) {
1010} 1010}
1011 1011
1012iBool isPinned_DocumentWidget_(const iDocumentWidget *d) { 1012iBool isPinned_DocumentWidget_(const iDocumentWidget *d) {
1013 if (deviceType_App() == phone_AppDeviceType) {
1014 return iFalse;
1015 }
1013 if (d->flags & otherRootByDefault_DocumentWidgetFlag) { 1016 if (d->flags & otherRootByDefault_DocumentWidgetFlag) {
1014 return iTrue; 1017 return iTrue;
1015 } 1018 }
@@ -1054,9 +1057,12 @@ static void documentWasChanged_DocumentWidget_(iDocumentWidget *d) {
1054 1057
1055void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { 1058void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) {
1056 setUrl_GmDocument(d->doc, d->mod.url); 1059 setUrl_GmDocument(d->doc, d->mod.url);
1060 const int docWidth = documentWidth_DocumentWidget_(d);
1061 const int outsideMargin = (width_Widget(d) - docWidth) / 2;
1057 setSource_GmDocument(d->doc, 1062 setSource_GmDocument(d->doc,
1058 source, 1063 source,
1059 documentWidth_DocumentWidget_(d), 1064 docWidth,
1065 outsideMargin,
1060 isFinished_GmRequest(d->request) ? final_GmDocumentUpdate 1066 isFinished_GmRequest(d->request) ? final_GmDocumentUpdate
1061 : partial_GmDocumentUpdate); 1067 : partial_GmDocumentUpdate);
1062 documentWasChanged_DocumentWidget_(d); 1068 documentWasChanged_DocumentWidget_(d);
@@ -1165,13 +1171,25 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode
1165 iString *key = collectNew_String(); 1171 iString *key = collectNew_String();
1166 toString_Sym(SDLK_s, KMOD_PRIMARY, key); 1172 toString_Sym(SDLK_s, KMOD_PRIMARY, key);
1167 appendFormat_String(src, "\n```\n%s\n```\n", cstr_String(meta)); 1173 appendFormat_String(src, "\n```\n%s\n```\n", cstr_String(meta));
1168 makeFooterButtons_DocumentWidget_( 1174 const char *mtype = mediaTypeFromFileExtension_String(d->mod.url);
1169 d, 1175 iArray items;
1170 (iMenuItem[]){ { translateCStr_Lang(download_Icon " " saveToDownloads_Label), 1176 init_Array(&items, sizeof(iMenuItem));
1171 0, 1177 if (iCmpStr(mtype, "application/octet-stream")) {
1172 0, 1178 pushBack_Array(
1173 "document.save" } }, 1179 &items,
1174 1); 1180 &(iMenuItem){ translateCStr_Lang(format_CStr("View as \"%s\"", mtype)),
1181 SDLK_RETURN,
1182 0,
1183 format_CStr("document.setmediatype mime:%s", mtype) });
1184 }
1185 pushBack_Array(
1186 &items,
1187 &(iMenuItem){ translateCStr_Lang(download_Icon " " saveToDownloads_Label),
1188 0,
1189 0,
1190 "document.save" });
1191 makeFooterButtons_DocumentWidget_(d, data_Array(&items), size_Array(&items));
1192 deinit_Array(&items);
1175 break; 1193 break;
1176 } 1194 }
1177 default: 1195 default:
@@ -2254,7 +2272,7 @@ static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumen
2254 /* TODO: First *fully* visible run? */ 2272 /* TODO: First *fully* visible run? */
2255 voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); 2273 voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds);
2256 } 2274 }
2257 setWidth_GmDocument(d->doc, newWidth); 2275 setWidth_GmDocument(d->doc, newWidth, (width_Widget(d) - newWidth) / 2);
2258 documentRunsInvalidated_DocumentWidget_(d); 2276 documentRunsInvalidated_DocumentWidget_(d);
2259 if (runLoc && !keepCenter) { 2277 if (runLoc && !keepCenter) {
2260 run = findRunAtLoc_GmDocument(d->doc, runLoc); 2278 run = findRunAtLoc_GmDocument(d->doc, runLoc);
@@ -2834,7 +2852,8 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2834 setUrl_UploadWidget(upload, d->mod.url); 2852 setUrl_UploadWidget(upload, d->mod.url);
2835 setResponseViewer_UploadWidget(upload, d); 2853 setResponseViewer_UploadWidget(upload, d);
2836 addChild_Widget(get_Root()->widget, iClob(upload)); 2854 addChild_Widget(get_Root()->widget, iClob(upload));
2837 finalizeSheet_Mobile(as_Widget(upload)); 2855// finalizeSheet_Mobile(as_Widget(upload));
2856 setupSheetTransition_Mobile(as_Widget(upload), iTrue);
2838 postRefresh_App(); 2857 postRefresh_App();
2839 } 2858 }
2840 return iTrue; 2859 return iTrue;
@@ -3109,7 +3128,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3109 makeQuestion_Widget( 3128 makeQuestion_Widget(
3110 uiHeading_ColorEscape "${heading.import.bookmarks}", 3129 uiHeading_ColorEscape "${heading.import.bookmarks}",
3111 formatCStrs_Lang("dlg.import.found.n", count), 3130 formatCStrs_Lang("dlg.import.found.n", count),
3112 (iMenuItem[]){ { "${cancel}", 0, 0, NULL }, 3131 (iMenuItem[]){ { "${cancel}" },
3113 { format_CStr(cstrCount_Lang("dlg.import.add.n", (int) count), 3132 { format_CStr(cstrCount_Lang("dlg.import.add.n", (int) count),
3114 uiTextAction_ColorEscape, 3133 uiTextAction_ColorEscape,
3115 count), 3134 count),
@@ -3173,6 +3192,10 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3173 document_App() == d) { 3192 document_App() == d) {
3174 return handleSwipe_DocumentWidget_(d, cmd); 3193 return handleSwipe_DocumentWidget_(d, cmd);
3175 } 3194 }
3195 else if (equal_Command(cmd, "document.setmediatype") && document_App() == d) {
3196 setUrlAndSource_DocumentWidget(d, d->mod.url, string_Command(cmd, "mime"), &d->sourceContent);
3197 return iTrue;
3198 }
3176 return iFalse; 3199 return iFalse;
3177} 3200}
3178 3201
@@ -3277,7 +3300,7 @@ static iBool processMediaEvents_DocumentWidget_(iDocumentWidget *d, const SDL_Ev
3277 d->playerMenu = makeMenu_Widget( 3300 d->playerMenu = makeMenu_Widget(
3278 as_Widget(d), 3301 as_Widget(d),
3279 (iMenuItem[]){ 3302 (iMenuItem[]){
3280 { cstrCollect_String(metadataLabel_Player(plr)), 0, 0, NULL }, 3303 { cstrCollect_String(metadataLabel_Player(plr)) },
3281 }, 3304 },
3282 1); 3305 1);
3283 openMenu_Widget(d->playerMenu, bottomLeft_Rect(ui.menuRect)); 3306 openMenu_Widget(d->playerMenu, bottomLeft_Rect(ui.menuRect));
@@ -3582,7 +3605,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3582 pushBackN_Array( 3605 pushBackN_Array(
3583 &items, 3606 &items,
3584 (iMenuItem[]){ 3607 (iMenuItem[]){
3585 { "---", 0, 0, NULL }, 3608 { "---" },
3586 { isGemini ? "${link.noproxy}" : openExt_Icon " ${link.browser}", 3609 { isGemini ? "${link.noproxy}" : openExt_Icon " ${link.browser}",
3587 0, 3610 0,
3588 0, 3611 0,
@@ -3593,7 +3616,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3593 linkLabel_GmDocument(d->doc, d->contextLink->linkId)); 3616 linkLabel_GmDocument(d->doc, d->contextLink->linkId));
3594 urlEncodeSpaces_String(linkLabel); 3617 urlEncodeSpaces_String(linkLabel);
3595 pushBackN_Array(&items, 3618 pushBackN_Array(&items,
3596 (iMenuItem[]){ { "---", 0, 0, NULL }, 3619 (iMenuItem[]){ { "---" },
3597 { "${link.copy}", 0, 0, "document.copylink" }, 3620 { "${link.copy}", 0, 0, "document.copylink" },
3598 { bookmark_Icon " ${link.bookmark}", 3621 { bookmark_Icon " ${link.bookmark}",
3599 0, 3622 0,
@@ -3605,7 +3628,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3605 3); 3628 3);
3606 if (isNative && d->contextLink->mediaType != download_GmRunMediaType) { 3629 if (isNative && d->contextLink->mediaType != download_GmRunMediaType) {
3607 pushBackN_Array(&items, (iMenuItem[]){ 3630 pushBackN_Array(&items, (iMenuItem[]){
3608 { "---", 0, 0, NULL }, 3631 { "---" },
3609 { download_Icon " ${link.download}", 0, 0, "document.downloadlink" }, 3632 { download_Icon " ${link.download}", 0, 0, "document.downloadlink" },
3610 }, 2); 3633 }, 2);
3611 } 3634 }
@@ -3648,17 +3671,17 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3648 { "${menu.forward}", navigateForward_KeyShortcut, "navigate.forward" }, 3671 { "${menu.forward}", navigateForward_KeyShortcut, "navigate.forward" },
3649 { upArrow_Icon " ${menu.parent}", navigateParent_KeyShortcut, "navigate.parent" }, 3672 { upArrow_Icon " ${menu.parent}", navigateParent_KeyShortcut, "navigate.parent" },
3650 { upArrowBar_Icon " ${menu.root}", navigateRoot_KeyShortcut, "navigate.root" }, 3673 { upArrowBar_Icon " ${menu.root}", navigateRoot_KeyShortcut, "navigate.root" },
3651 { "---", 0, 0, NULL }, 3674 { "---" },
3652 { reload_Icon " ${menu.reload}", reload_KeyShortcut, "navigate.reload" }, 3675 { reload_Icon " ${menu.reload}", reload_KeyShortcut, "navigate.reload" },
3653 { timer_Icon " ${menu.autoreload}", 0, 0, "document.autoreload.menu" }, 3676 { timer_Icon " ${menu.autoreload}", 0, 0, "document.autoreload.menu" },
3654 { "---", 0, 0, NULL }, 3677 { "---" },
3655 { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, 3678 { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
3656 { star_Icon " ${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" }, 3679 { star_Icon " ${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" },
3657 { "---", 0, 0, NULL }, 3680 { "---" },
3658 { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" }, 3681 { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" },
3659 { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" }, 3682 { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" },
3660 { upload_Icon " ${menu.page.upload}", 0, 0, "document.upload" }, 3683 { upload_Icon " ${menu.page.upload}", 0, 0, "document.upload" },
3661 { "---", 0, 0, NULL }, 3684 { "---" },
3662 { "${menu.page.copyurl}", 0, 0, "document.copylink" } }, 3685 { "${menu.page.copyurl}", 0, 0, "document.copylink" } },
3663 15); 3686 15);
3664 if (isEmpty_Range(&d->selectMark)) { 3687 if (isEmpty_Range(&d->selectMark)) {
@@ -3834,7 +3857,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3834 } 3857 }
3835 d->copyMenu = makeMenu_Widget(w, (iMenuItem[]){ 3858 d->copyMenu = makeMenu_Widget(w, (iMenuItem[]){
3836 { clipCopy_Icon " ${menu.copy}", 0, 0, "copy" }, 3859 { clipCopy_Icon " ${menu.copy}", 0, 0, "copy" },
3837 { "---", 0, 0, NULL }, 3860 { "---" },
3838 { close_Icon " ${menu.select.clear}", 0, 0, "document.select arg:0" }, 3861 { close_Icon " ${menu.select.clear}", 0, 0, "document.select arg:0" },
3839 }, 3); 3862 }, 3);
3840 setFlags_Widget(d->copyMenu, noFadeBackground_WidgetFlag, iTrue); 3863 setFlags_Widget(d->copyMenu, noFadeBackground_WidgetFlag, iTrue);
@@ -3927,7 +3950,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3927 uiTextAction_ColorEscape, 3950 uiTextAction_ColorEscape,
3928 cstr_String(url)), 3951 cstr_String(url)),
3929 (iMenuItem[]){ 3952 (iMenuItem[]){
3930 { "${cancel}", 0, 0, NULL }, 3953 { "${cancel}" },
3931 { uiTextCaution_ColorEscape "${dlg.openlink}", 3954 { uiTextCaution_ColorEscape "${dlg.openlink}",
3932 0, 0, format_CStr("!open default:1 url:%s", cstr_String(url)) } }, 3955 0, 0, format_CStr("!open default:1 url:%s", cstr_String(url)) } },
3933 2); 3956 2);
@@ -4574,23 +4597,6 @@ static void drawMedia_DocumentWidget_(const iDocumentWidget *d, iPaint *p) {
4574 } 4597 }
4575} 4598}
4576 4599
4577static void drawPin_(iPaint *p, iRect rangeRect, int dir) {
4578 const int pinColor = tmQuote_ColorId;
4579 const int height = height_Rect(rangeRect);
4580 iRect pin;
4581 if (dir == 0) {
4582 pin = (iRect){ add_I2(topLeft_Rect(rangeRect), init_I2(-gap_UI / 4, -gap_UI)),
4583 init_I2(gap_UI / 2, height + gap_UI) };
4584 }
4585 else {
4586 pin = (iRect){ addX_I2(topRight_Rect(rangeRect), -gap_UI / 4),
4587 init_I2(gap_UI / 2, height + gap_UI) };
4588 }
4589 fillRect_Paint(p, pin, pinColor);
4590 fillRect_Paint(p, initCentered_Rect(dir == 0 ? topMid_Rect(pin) : bottomMid_Rect(pin),
4591 init1_I2(gap_UI * 2)), pinColor);
4592}
4593
4594static void extend_GmRunRange_(iGmRunRange *runs) { 4600static void extend_GmRunRange_(iGmRunRange *runs) {
4595 if (runs->start) { 4601 if (runs->start) {
4596 runs->start--; 4602 runs->start--;
@@ -4834,8 +4840,8 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
4834 SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE); 4840 SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE);
4835 /* Selection range pins. */ 4841 /* Selection range pins. */
4836 if (isTouchSelecting) { 4842 if (isTouchSelecting) {
4837 drawPin_(&ctx.paint, ctx.firstMarkRect, 0); 4843 drawPin_Paint(&ctx.paint, ctx.firstMarkRect, 0, tmQuote_ColorId);
4838 drawPin_(&ctx.paint, ctx.lastMarkRect, 1); 4844 drawPin_Paint(&ctx.paint, ctx.lastMarkRect, 1, tmQuote_ColorId);
4839 } 4845 }
4840 } 4846 }
4841 drawMedia_DocumentWidget_(d, &ctx.paint); 4847 drawMedia_DocumentWidget_(d, &ctx.paint);