summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/documentwidget.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 5b4af4dd..8b769cf8 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -711,14 +711,17 @@ static void updateFetchProgress_DocumentWidget_(iDocumentWidget *d) {
711 } 711 }
712} 712}
713 713
714static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse *response) { 714static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse *response,
715 const iBool isInitialUpdate) {
715 if (d->state == ready_RequestState) { 716 if (d->state == ready_RequestState) {
716 return; 717 return;
717 } 718 }
719 const iBool isRequestFinished = !d->request || isFinished_GmRequest(d->request);
718 /* TODO: Do document update in the background. However, that requires a text metrics calculator 720 /* TODO: Do document update in the background. However, that requires a text metrics calculator
719 that does not try to cache the glyph bitmaps. */ 721 that does not try to cache the glyph bitmaps. */
720 const enum iGmStatusCode statusCode = response->statusCode; 722 const enum iGmStatusCode statusCode = response->statusCode;
721 if (category_GmStatusCode(statusCode) != categoryInput_GmStatusCode) { 723 if (category_GmStatusCode(statusCode) != categoryInput_GmStatusCode) {
724 iBool setSource = iTrue;
722 iString str; 725 iString str;
723 invalidate_DocumentWidget_(d); 726 invalidate_DocumentWidget_(d);
724 if (document_App() == d) { 727 if (document_App() == d) {
@@ -748,10 +751,11 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
748 } 751 }
749 else if (startsWith_Rangecc(param, "image/") || 752 else if (startsWith_Rangecc(param, "image/") ||
750 startsWith_Rangecc(param, "audio/")) { 753 startsWith_Rangecc(param, "audio/")) {
754 const iBool isAudio = startsWith_Rangecc(param, "audio/");
755 /* Make a simple document with an image or audio player. */
751 docFormat = gemini_GmDocumentFormat; 756 docFormat = gemini_GmDocumentFormat;
752 setRange_String(&d->sourceMime, param); 757 setRange_String(&d->sourceMime, param);
753 if (!d->request || isFinished_GmRequest(d->request)) { 758 if ((isAudio && isInitialUpdate) || (!isAudio && isRequestFinished)) {
754 /* Make a simple document with an image or audio player. */
755 const char *linkTitle = 759 const char *linkTitle =
756 startsWith_String(mimeStr, "image/") ? "Image" : "Audio"; 760 startsWith_String(mimeStr, "image/") ? "Image" : "Audio";
757 iUrl parts; 761 iUrl parts;
@@ -765,9 +769,19 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
765 1, 769 1,
766 mimeStr, 770 mimeStr,
767 &response->body, 771 &response->body,
768 0); 772 !isRequestFinished ? partialData_MediaFlag : 0);
769 redoLayout_GmDocument(d->doc); 773 redoLayout_GmDocument(d->doc);
770 } 774 }
775 else if (isAudio && !isInitialUpdate) {
776 /* Update the audio content. */
777 setData_Media(media_GmDocument(d->doc),
778 1,
779 mimeStr,
780 &response->body,
781 !isRequestFinished ? partialData_MediaFlag : 0);
782 refresh_Widget(d);
783 setSource = iFalse;
784 }
771 else { 785 else {
772 clear_String(&str); 786 clear_String(&str);
773 } 787 }
@@ -793,7 +807,9 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
793 collect_String(decode_Block(&str.chars, cstr_Rangecc(charset)))); 807 collect_String(decode_Block(&str.chars, cstr_Rangecc(charset))));
794 } 808 }
795 } 809 }
796 setSource_DocumentWidget_(d, &str); 810 if (setSource) {
811 setSource_DocumentWidget_(d, &str);
812 }
797 deinit_String(&str); 813 deinit_String(&str);
798 } 814 }
799} 815}
@@ -879,7 +895,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
879 d->initNormScrollY = recent->normScrollY; 895 d->initNormScrollY = recent->normScrollY;
880 /* Use the cached response data. */ 896 /* Use the cached response data. */
881 updateTrust_DocumentWidget_(d, resp); 897 updateTrust_DocumentWidget_(d, resp);
882 updateDocument_DocumentWidget_(d, resp); 898 updateDocument_DocumentWidget_(d, resp, iTrue);
883 d->scrollY = d->initNormScrollY * size_GmDocument(d->doc).y; 899 d->scrollY = d->initNormScrollY * size_GmDocument(d->doc).y;
884 d->state = ready_RequestState; 900 d->state = ready_RequestState;
885 updateSideOpacity_DocumentWidget_(d, iFalse); 901 updateSideOpacity_DocumentWidget_(d, iFalse);
@@ -1038,7 +1054,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
1038 d->scrollY = 0; 1054 d->scrollY = 0;
1039 resetSmoothScroll_DocumentWidget_(d); 1055 resetSmoothScroll_DocumentWidget_(d);
1040 reset_GmDocument(d->doc); /* new content incoming */ 1056 reset_GmDocument(d->doc); /* new content incoming */
1041 updateDocument_DocumentWidget_(d, response_GmRequest(d->request)); 1057 updateDocument_DocumentWidget_(d, response_GmRequest(d->request), iTrue);
1042 break; 1058 break;
1043 case categoryRedirect_GmStatusCode: 1059 case categoryRedirect_GmStatusCode:
1044 if (isEmpty_String(meta_GmRequest(d->request))) { 1060 if (isEmpty_String(meta_GmRequest(d->request))) {
@@ -1081,7 +1097,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
1081 switch (category_GmStatusCode(statusCode)) { 1097 switch (category_GmStatusCode(statusCode)) {
1082 case categorySuccess_GmStatusCode: 1098 case categorySuccess_GmStatusCode:
1083 /* More content available. */ 1099 /* More content available. */
1084 updateDocument_DocumentWidget_(d, response_GmRequest(d->request)); 1100 updateDocument_DocumentWidget_(d, response_GmRequest(d->request), iFalse);
1085 break; 1101 break;
1086 default: 1102 default:
1087 break; 1103 break;