diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 97 |
1 files changed, 68 insertions, 29 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index cffd284f..f63e98bf 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -497,13 +497,15 @@ static iMediaRequest *findMediaRequest_DocumentWidget_(const iDocumentWidget *d, | |||
497 | return NULL; | 497 | return NULL; |
498 | } | 498 | } |
499 | 499 | ||
500 | static void requestMedia_DocumentWidget_(iDocumentWidget *d, iGmLinkId linkId) { | 500 | static iBool requestMedia_DocumentWidget_(iDocumentWidget *d, iGmLinkId linkId) { |
501 | if (!findMediaRequest_DocumentWidget_(d, linkId)) { | 501 | if (!findMediaRequest_DocumentWidget_(d, linkId)) { |
502 | pushBack_ObjectList( | 502 | pushBack_ObjectList( |
503 | d->media, | 503 | d->media, |
504 | iClob(new_MediaRequest( | 504 | iClob(new_MediaRequest( |
505 | d, linkId, absoluteUrl_DocumentWidget_(d, linkUrl_GmDocument(d->doc, linkId))))); | 505 | d, linkId, absoluteUrl_DocumentWidget_(d, linkUrl_GmDocument(d->doc, linkId))))); |
506 | return iTrue; | ||
506 | } | 507 | } |
508 | return iFalse; | ||
507 | } | 509 | } |
508 | 510 | ||
509 | static iBool handleMediaEvent_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | 511 | static iBool handleMediaEvent_DocumentWidget_(iDocumentWidget *d, const char *cmd) { |
@@ -777,7 +779,26 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
777 | iAssert(linkId); | 779 | iAssert(linkId); |
778 | /* Media links are opened inline by default. */ | 780 | /* Media links are opened inline by default. */ |
779 | if (isMediaLink_GmDocument(d->doc, linkId)) { | 781 | if (isMediaLink_GmDocument(d->doc, linkId)) { |
780 | requestMedia_DocumentWidget_(d, linkId); | 782 | if (!requestMedia_DocumentWidget_(d, linkId)) { |
783 | if (linkFlags_GmDocument(d->doc, linkId) & content_GmLinkFlag) { | ||
784 | setImage_GmDocument(d->doc, linkId, NULL, NULL); | ||
785 | d->hoverLink = NULL; | ||
786 | updateVisible_DocumentWidget_(d); | ||
787 | refresh_Widget(w); | ||
788 | return iTrue; | ||
789 | } | ||
790 | else { | ||
791 | /* Show the existing content again if we have it. */ | ||
792 | iMediaRequest *req = findMediaRequest_DocumentWidget_(d, linkId); | ||
793 | if (req) { | ||
794 | setImage_GmDocument(d->doc, linkId, meta_GmRequest(req->req), | ||
795 | body_GmRequest(req->req)); | ||
796 | updateVisible_DocumentWidget_(d); | ||
797 | refresh_Widget(w); | ||
798 | return iTrue; | ||
799 | } | ||
800 | } | ||
801 | } | ||
781 | } | 802 | } |
782 | else { | 803 | else { |
783 | postCommandf_App("open url:%s", | 804 | postCommandf_App("open url:%s", |
@@ -840,8 +861,8 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol | |||
840 | } | 861 | } |
841 | 862 | ||
842 | static void drawRun_DrawContext_(void *context, const iGmRun *run) { | 863 | static void drawRun_DrawContext_(void *context, const iGmRun *run) { |
843 | iDrawContext *d = context; | 864 | iDrawContext *d = context; |
844 | const iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); | 865 | const iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); |
845 | if (run->imageId) { | 866 | if (run->imageId) { |
846 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); | 867 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); |
847 | if (tex) { | 868 | if (tex) { |
@@ -854,32 +875,50 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
854 | iString text; | 875 | iString text; |
855 | /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */ | 876 | /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */ |
856 | initRange_String(&text, run->text); | 877 | initRange_String(&text, run->text); |
857 | enum iColorId fg = run->color; | 878 | enum iColorId fg = run->color; |
858 | if (run == d->widget->hoverLink) { | 879 | const iGmDocument *doc = d->widget->doc; |
859 | const iGmDocument *doc = d->widget->doc; | 880 | if (run->linkId) { |
860 | const iGmLinkId linkId = d->widget->hoverLink->linkId; | 881 | /* TODO: Visualize an ongoing media request. */ |
861 | const iString * url = linkUrl_GmDocument(doc, linkId); | 882 | const int flags = linkFlags_GmDocument(doc, run->linkId); |
862 | const int flags = linkFlags_GmDocument(doc, linkId); | 883 | if (flags & content_GmLinkFlag) { |
863 | iUrl parts; | 884 | fg = linkColor_GmDocument(doc, run->linkId); |
864 | init_Url(&parts, url); | 885 | if (!isEmpty_Rect(run->bounds)) { |
865 | const iString *host = collect_String(newRange_String(parts.host)); | 886 | iGmImageInfo info; |
866 | fg = linkColor_GmDocument(doc, linkId); | 887 | imageInfo_GmDocument(doc, linkImage_GmDocument(doc, run->linkId), &info); |
867 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); | 888 | drawAlign_Text(default_FontId, |
868 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; | 889 | add_I2(topRight_Rect(run->bounds), origin), |
869 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | 890 | fg, |
870 | if (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || showHost) { | 891 | right_Alignment, |
892 | "%s \u2014 %d x %d \u2014 %.1fMB %s \u2715", | ||
893 | info.mime, info.size.x, info.size.y, info.numBytes / 1.0e6f, | ||
894 | run == d->widget->hoverLink ? white_ColorEscape : ""); | ||
895 | } | ||
896 | } | ||
897 | else if (run == d->widget->hoverLink) { | ||
898 | const iGmLinkId linkId = d->widget->hoverLink->linkId; | ||
899 | const iString * url = linkUrl_GmDocument(doc, linkId); | ||
900 | const int flags = linkFlags_GmDocument(doc, linkId); | ||
901 | iUrl parts; | ||
902 | init_Url(&parts, url); | ||
903 | const iString *host = collect_String(newRange_String(parts.host)); | ||
904 | fg = linkColor_GmDocument(doc, linkId); | ||
905 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); | ||
906 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; | ||
907 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | ||
871 | iRect linkRect = moved_Rect(run->visBounds, origin); | 908 | iRect linkRect = moved_Rect(run->visBounds, origin); |
872 | drawAlign_Text(default_FontId, | 909 | if (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || showHost) { |
873 | topRight_Rect(linkRect), | 910 | drawAlign_Text(default_FontId, |
874 | fg - 1, | 911 | topRight_Rect(linkRect), |
875 | left_Alignment, | 912 | fg - 1, |
876 | " \u2014%s%s%s\r%c%s", | 913 | left_Alignment, |
877 | showHost ? " " : "", | 914 | " \u2014%s%s%s\r%c%s", |
878 | showHost ? cstr_String(host) : "", | 915 | showHost ? " " : "", |
879 | showHost && (showImage || showAudio) ? " \u2014" : "", | 916 | showHost ? cstr_String(host) : "", |
880 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), | 917 | showHost && (showImage || showAudio) ? " \u2014" : "", |
881 | showImage ? " View Image \U0001f5bc" | 918 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), |
882 | : showAudio ? " Play Audio \U0001f3b5" : ""); | 919 | showImage ? " View Image \U0001f5bc" |
920 | : showAudio ? " Play Audio \U0001f3b5" : ""); | ||
921 | } | ||
883 | } | 922 | } |
884 | } | 923 | } |
885 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); | 924 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); |