diff options
-rw-r--r-- | src/ui/documentwidget.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 9bf40e5c..4e53ba44 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -216,7 +216,7 @@ static void updateHover_DocumentWidget_(iDocumentWidget *d, iInt2 mouse) { | |||
216 | const iGmRun *oldHoverLink = d->hoverLink; | 216 | const iGmRun *oldHoverLink = d->hoverLink; |
217 | d->hoverLink = NULL; | 217 | d->hoverLink = NULL; |
218 | const iInt2 hoverPos = addY_I2(sub_I2(mouse, topLeft_Rect(docBounds)), d->scrollY); | 218 | const iInt2 hoverPos = addY_I2(sub_I2(mouse, topLeft_Rect(docBounds)), d->scrollY); |
219 | if (d->state == ready_DocumentState) { | 219 | if (d->state == ready_DocumentState || d->state == receivedPartialResponse_DocumentState) { |
220 | iConstForEach(PtrArray, i, &d->visibleLinks) { | 220 | iConstForEach(PtrArray, i, &d->visibleLinks) { |
221 | const iGmRun *run = i.ptr; | 221 | const iGmRun *run = i.ptr; |
222 | if (contains_Rect(run->bounds, hoverPos)) { | 222 | if (contains_Rect(run->bounds, hoverPos)) { |
@@ -266,9 +266,9 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) { | |||
266 | static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { | 266 | static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { |
267 | setUrl_GmDocument(d->doc, d->url); | 267 | setUrl_GmDocument(d->doc, d->url); |
268 | setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d)); | 268 | setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d)); |
269 | d->foundMark = iNullRange; | 269 | d->foundMark = iNullRange; |
270 | d->selectMark = iNullRange; | 270 | d->selectMark = iNullRange; |
271 | d->hoverLink = NULL; | 271 | d->hoverLink = NULL; |
272 | updateWindowTitle_DocumentWidget_(d); | 272 | updateWindowTitle_DocumentWidget_(d); |
273 | updateVisible_DocumentWidget_(d); | 273 | updateVisible_DocumentWidget_(d); |
274 | refresh_Widget(as_Widget(d)); | 274 | refresh_Widget(as_Widget(d)); |
@@ -411,14 +411,15 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | |||
411 | if (!d->request) { | 411 | if (!d->request) { |
412 | return; | 412 | return; |
413 | } | 413 | } |
414 | enum iGmStatusCode statusCode = status_GmRequest(d->request); | ||
414 | if (d->state == fetching_DocumentState) { | 415 | if (d->state == fetching_DocumentState) { |
415 | d->state = receivedPartialResponse_DocumentState; | 416 | d->state = receivedPartialResponse_DocumentState; |
416 | d->scrollY = 0; | ||
417 | reset_GmDocument(d->doc); /* new content incoming */ | ||
418 | enum iGmStatusCode statusCode = status_GmRequest(d->request); | ||
419 | switch (statusCode) { | 417 | switch (statusCode) { |
420 | case none_GmStatusCode: | 418 | case none_GmStatusCode: |
421 | case success_GmStatusCode: | 419 | case success_GmStatusCode: |
420 | d->scrollY = 0; | ||
421 | reset_GmDocument(d->doc); /* new content incoming */ | ||
422 | updateSource_DocumentWidget_(d); | ||
422 | break; | 423 | break; |
423 | case input_GmStatusCode: | 424 | case input_GmStatusCode: |
424 | case sensitiveInput_GmStatusCode: { | 425 | case sensitiveInput_GmStatusCode: { |
@@ -456,6 +457,16 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | |||
456 | break; | 457 | break; |
457 | } | 458 | } |
458 | } | 459 | } |
460 | else if (d->state == receivedPartialResponse_DocumentState) { | ||
461 | switch (statusCode) { | ||
462 | case success_GmStatusCode: | ||
463 | /* More content available. */ | ||
464 | updateSource_DocumentWidget_(d); | ||
465 | break; | ||
466 | default: | ||
467 | break; | ||
468 | } | ||
469 | } | ||
459 | } | 470 | } |
460 | 471 | ||
461 | static const char *sourceLoc_DocumentWidget_(const iDocumentWidget *d, iInt2 pos) { | 472 | static const char *sourceLoc_DocumentWidget_(const iDocumentWidget *d, iInt2 pos) { |
@@ -578,13 +589,13 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
578 | } | 589 | } |
579 | else if (isCommand_Widget(w, ev, "document.request.updated") && | 590 | else if (isCommand_Widget(w, ev, "document.request.updated") && |
580 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { | 591 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { |
581 | updateSource_DocumentWidget_(d); | ||
582 | checkResponseCode_DocumentWidget_(d); | 592 | checkResponseCode_DocumentWidget_(d); |
593 | // updateSource_DocumentWidget_(d); | ||
583 | return iFalse; | 594 | return iFalse; |
584 | } | 595 | } |
585 | else if (isCommand_Widget(w, ev, "document.request.finished") && | 596 | else if (isCommand_Widget(w, ev, "document.request.finished") && |
586 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { | 597 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { |
587 | updateSource_DocumentWidget_(d); | 598 | // updateSource_DocumentWidget_(d); |
588 | checkResponseCode_DocumentWidget_(d); | 599 | checkResponseCode_DocumentWidget_(d); |
589 | d->state = ready_DocumentState; | 600 | d->state = ready_DocumentState; |
590 | iReleasePtr(&d->request); | 601 | iReleasePtr(&d->request); |
@@ -894,11 +905,11 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
894 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); | 905 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); |
895 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; | 906 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; |
896 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | 907 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; |
908 | iString str; | ||
909 | init_String(&str); | ||
897 | if (run->flags & endOfLine_GmRunFlag && | 910 | if (run->flags & endOfLine_GmRunFlag && |
898 | (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || | 911 | (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || |
899 | showHost)) { | 912 | showHost)) { |
900 | iString str; | ||
901 | init_String(&str); | ||
902 | format_String(&str, " \u2014%s%s%s\r%c%s", | 913 | format_String(&str, " \u2014%s%s%s\r%c%s", |
903 | showHost ? " " : "", | 914 | showHost ? " " : "", |
904 | showHost ? cstr_String(host) : "", | 915 | showHost ? cstr_String(host) : "", |
@@ -906,6 +917,15 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
906 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), | 917 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), |
907 | showImage ? " View Image \U0001f5bc" | 918 | showImage ? " View Image \U0001f5bc" |
908 | : showAudio ? " Play Audio \U0001f3b5" : ""); | 919 | : showAudio ? " Play Audio \U0001f3b5" : ""); |
920 | } | ||
921 | if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) { | ||
922 | iDate date; | ||
923 | init_Date(&date, linkTime_GmDocument(doc, run->linkId)); | ||
924 | appendFormat_String(&str, | ||
925 | " \u2014 %s", | ||
926 | cstr_String(collect_String(format_Date(&date, "%b %d")))); | ||
927 | } | ||
928 | if (!isEmpty_String(&str)) { | ||
909 | const iInt2 textSize = measure_Text(default_FontId, cstr_String(&str)); | 929 | const iInt2 textSize = measure_Text(default_FontId, cstr_String(&str)); |
910 | int tx = topRight_Rect(linkRect).x; | 930 | int tx = topRight_Rect(linkRect).x; |
911 | const char *msg = cstr_String(&str); | 931 | const char *msg = cstr_String(&str); |
@@ -914,6 +934,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
914 | fillRect_Paint(&d->paint, (iRect){ init_I2(tx, top_Rect(linkRect)), textSize }, | 934 | fillRect_Paint(&d->paint, (iRect){ init_I2(tx, top_Rect(linkRect)), textSize }, |
915 | black_ColorId); | 935 | black_ColorId); |
916 | msg += 4; /* skip the space and dash */ | 936 | msg += 4; /* skip the space and dash */ |
937 | tx += measure_Text(default_FontId, " \u2014").x / 2; | ||
917 | } | 938 | } |
918 | drawAlign_Text(default_FontId, | 939 | drawAlign_Text(default_FontId, |
919 | init_I2(tx, top_Rect(linkRect)), | 940 | init_I2(tx, top_Rect(linkRect)), |
@@ -924,17 +945,6 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
924 | deinit_String(&str); | 945 | deinit_String(&str); |
925 | } | 946 | } |
926 | } | 947 | } |
927 | else if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) { | ||
928 | iDate date; | ||
929 | init_Date(&date, linkTime_GmDocument(doc, run->linkId)); | ||
930 | draw_Text(default_FontId, | ||
931 | topRight_Rect(linkRect), | ||
932 | linkColor_GmDocument(doc, run->linkId) - 1, | ||
933 | " \u2014 Visited on %04d-%02d-%02d", | ||
934 | date.year, | ||
935 | date.month, | ||
936 | date.day); | ||
937 | } | ||
938 | } | 948 | } |
939 | 949 | ||
940 | // drawRect_Paint(&d->paint, (iRect){ visPos, run->bounds.size }, green_ColorId); | 950 | // drawRect_Paint(&d->paint, (iRect){ visPos, run->bounds.size }, green_ColorId); |