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.c86
1 files changed, 47 insertions, 39 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 70e66180..69dde8c7 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -60,8 +60,8 @@ struct Impl_MediaRequest {
60 60
61static void updated_MediaRequest_(iAnyObject *obj) { 61static void updated_MediaRequest_(iAnyObject *obj) {
62 iMediaRequest *d = obj; 62 iMediaRequest *d = obj;
63 postCommandf_App("media.updated link:%u request:%p", d->linkId, d); 63 postCommandf_App("media.updated link:%u request:%p", d->linkId, d);
64 } 64}
65 65
66static void finished_MediaRequest_(iAnyObject *obj) { 66static void finished_MediaRequest_(iAnyObject *obj) {
67 iMediaRequest *d = obj; 67 iMediaRequest *d = obj;
@@ -243,10 +243,11 @@ static void resetSmoothScroll_DocumentWidget_(iDocumentWidget *d) {
243} 243}
244 244
245static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { 245static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {
246 const iWidget *w = constAs_Widget(d); 246 const iWidget *w = constAs_Widget(d);
247 const iRect bounds = bounds_Widget(w); 247 const iRect bounds = bounds_Widget(w);
248 const iPrefs * prefs = prefs_App();
248 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2, 249 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2,
249 fontSize_UI * 40 * zoom_App() / 100); /* TODO: Add user preference .*/ 250 fontSize_UI * prefs->lineWidth * prefs->zoomPercent / 100);
250} 251}
251 252
252static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { 253static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
@@ -369,9 +370,9 @@ static void updateHover_DocumentWidget_(iDocumentWidget *d, iInt2 mouse) {
369 if (d->hoverLink && 370 if (d->hoverLink &&
370 linkFlags_GmDocument(d->doc, d->hoverLink->linkId) & permanent_GmLinkFlag) { 371 linkFlags_GmDocument(d->doc, d->hoverLink->linkId) & permanent_GmLinkFlag) {
371 setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_ARROW); /* not dismissable */ 372 setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_ARROW); /* not dismissable */
373 }
372 } 374 }
373} 375}
374}
375 376
376static void updateVisible_DocumentWidget_(iDocumentWidget *d) { 377static void updateVisible_DocumentWidget_(iDocumentWidget *d) {
377 const iRangei visRange = visibleRange_DocumentWidget_(d); 378 const iRangei visRange = visibleRange_DocumentWidget_(d);
@@ -573,7 +574,9 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
573 if (category_GmStatusCode(statusCode) != categoryInput_GmStatusCode) { 574 if (category_GmStatusCode(statusCode) != categoryInput_GmStatusCode) {
574 iString str; 575 iString str;
575 invalidate_DocumentWidget_(d); 576 invalidate_DocumentWidget_(d);
576 updateTheme_DocumentWidget_(d); 577 if (document_App() == d) {
578 updateTheme_DocumentWidget_(d);
579 }
577 clear_String(&d->sourceMime); 580 clear_String(&d->sourceMime);
578// set_Block(&d->sourceContent, &response->body); 581// set_Block(&d->sourceContent, &response->body);
579 initBlock_String(&str, &response->body); 582 initBlock_String(&str, &response->body);
@@ -1208,7 +1211,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1208 "document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url)); 1211 "document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url));
1209 iReleasePtr(&d->request); 1212 iReleasePtr(&d->request);
1210 if (d->state != ready_RequestState) { 1213 if (d->state != ready_RequestState) {
1211 d->state = ready_RequestState; 1214 d->state = ready_RequestState;
1212 postCommand_App("navigate.back"); 1215 postCommand_App("navigate.back");
1213 } 1216 }
1214 updateFetchProgress_DocumentWidget_(d); 1217 updateFetchProgress_DocumentWidget_(d);
@@ -1256,9 +1259,9 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1256 } 1259 }
1257 else if (startsWith_String(&d->sourceMime, "image/")) { 1260 else if (startsWith_String(&d->sourceMime, "image/")) {
1258 appendCStr_String(savePath, cstr_String(&d->sourceMime) + 6); 1261 appendCStr_String(savePath, cstr_String(&d->sourceMime) + 6);
1262 }
1263 }
1259 if (fileExists_FileInfo(savePath)) { 1264 if (fileExists_FileInfo(savePath)) {
1260 }
1261 }
1262 /* Make it unique. */ 1265 /* Make it unique. */
1263 iDate now; 1266 iDate now;
1264 initCurrent_Date(&now); 1267 initCurrent_Date(&now);
@@ -1550,38 +1553,39 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1550 iArray items; 1553 iArray items;
1551 init_Array(&items, sizeof(iMenuItem)); 1554 init_Array(&items, sizeof(iMenuItem));
1552 if (d->contextLink) { 1555 if (d->contextLink) {
1556 const iString *linkUrl = linkUrl_GmDocument(d->doc, d->contextLink->linkId);
1553 pushBackN_Array( 1557 pushBackN_Array(
1554 &items, 1558 &items,
1555 (iMenuItem[]){ { "Open Link in New Tab", 1559 (iMenuItem[]){
1560 { "Open Link in New Tab",
1556 0, 1561 0,
1557 0, 1562 0,
1558 format_CStr("!open newtab:1 url:%s", 1563 format_CStr("!open newtab:1 url:%s", cstr_String(linkUrl)) },
1559 cstr_String(linkUrl_GmDocument( 1564 { "Open Link in Background Tab",
1560 d->doc, d->contextLink->linkId))) },
1561 { "---", 0, 0, NULL },
1562 { "Copy Link",
1563 0, 1565 0,
1564 0, 1566 0,
1565 "document.copylink" }}, 1567 format_CStr("!open newtab:2 url:%s", cstr_String(linkUrl)) },
1566 3); 1568 { "---", 0, 0, NULL },
1569 { "Copy Link", 0, 0, "document.copylink" } },
1570 4);
1567 } 1571 }
1568 else { 1572 else {
1569 if (!isEmpty_Range(&d->selectMark)) { 1573 if (!isEmpty_Range(&d->selectMark)) {
1570 pushBackN_Array( 1574 pushBackN_Array(
1571 &items, 1575 &items,
1572 (iMenuItem[]){ { "Copy", 0, 0, "copy" }, { "---", 0, 0, NULL } }, 1576 (iMenuItem[]){ { "Copy", 0, 0, "copy" }, { "---", 0, 0, NULL } },
1573 2); 1577 2);
1574 } 1578 }
1575 pushBackN_Array( 1579 pushBackN_Array(
1576 &items, 1580 &items,
1577 (iMenuItem[]){ 1581 (iMenuItem[]){
1578 { "Go Back", navigateBack_KeyShortcut, "navigate.back" }, 1582 { "Go Back", navigateBack_KeyShortcut, "navigate.back" },
1579 { "Go Forward", navigateForward_KeyShortcut, "navigate.forward" }, 1583 { "Go Forward", navigateForward_KeyShortcut, "navigate.forward" },
1580 { "Reload Page", reload_KeyShortcut, "navigate.reload" }, 1584 { "Reload Page", reload_KeyShortcut, "navigate.reload" },
1581 { "---", 0, 0, NULL }, 1585 { "---", 0, 0, NULL },
1582 { "Copy Page URL", 0, 0, "document.copylink" }, 1586 { "Copy Page URL", 0, 0, "document.copylink" },
1583 { "---", 0, 0, NULL } }, 1587 { "---", 0, 0, NULL } },
1584 6); 1588 6);
1585 if (isEmpty_Range(&d->selectMark)) { 1589 if (isEmpty_Range(&d->selectMark)) {
1586 pushBackN_Array( 1590 pushBackN_Array(
1587 &items, 1591 &items,
@@ -1617,6 +1621,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1617 else if (loc) { 1621 else if (loc) {
1618 d->selectMark.end = loc; 1622 d->selectMark.end = loc;
1619 } 1623 }
1624// printf("mark %zu ... %zu\n", d->selectMark.start - cstr_String(source_GmDocument(d->doc)),
1625// d->selectMark.end - cstr_String(source_GmDocument(d->doc)));
1626// fflush(stdout);
1620 refresh_Widget(w); 1627 refresh_Widget(w);
1621 return iTrue; 1628 return iTrue;
1622 } 1629 }
@@ -1702,7 +1709,8 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol
1702 /* Selection may be done in either direction. */ 1709 /* Selection may be done in either direction. */
1703 iSwap(const char *, mark.start, mark.end); 1710 iSwap(const char *, mark.start, mark.end);
1704 } 1711 }
1705 if ((!*isInside && contains_Range(&run->text, mark.start)) || *isInside) { 1712 if ((!*isInside && (contains_Range(&run->text, mark.start) || mark.start == run->text.end)) ||
1713 *isInside) {
1706 int x = 0; 1714 int x = 0;
1707 if (!*isInside) { 1715 if (!*isInside) {
1708 x = advanceRange_Text(run->font, (iRangecc){ run->text.start, mark.start }).x; 1716 x = advanceRange_Text(run->font, (iRangecc){ run->text.start, mark.start }).x;
@@ -1873,23 +1881,23 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
1873 (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || 1881 (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) ||
1874 showHost)) { 1882 showHost)) {
1875 format_String(&str, 1883 format_String(&str,
1876 " \u2014%s%s%s\r%c%s", 1884 " \u2014%s%s%s\r%c%s",
1877 showHost ? " " : "", 1885 showHost ? " " : "",
1878 showHost ? (flags & mailto_GmLinkFlag 1886 showHost ? (flags & mailto_GmLinkFlag
1879 ? cstr_String(url) 1887 ? cstr_String(url)
1880 : ~flags & gemini_GmLinkFlag 1888 : ~flags & gemini_GmLinkFlag
1881 ? format_CStr("%s://%s", 1889 ? format_CStr("%s://%s",
1882 cstr_Rangecc(parts.scheme), 1890 cstr_Rangecc(parts.scheme),
1883 cstr_Rangecc(parts.host)) 1891 cstr_Rangecc(parts.host))
1884 : cstr_Rangecc(parts.host)) 1892 : cstr_Rangecc(parts.host))
1885 : "", 1893 : "",
1886 showHost && (showImage || showAudio) ? " \u2014" : "", 1894 showHost && (showImage || showAudio) ? " \u2014" : "",
1887 showImage || showAudio 1895 showImage || showAudio
1888 ? asciiBase_ColorEscape + fg 1896 ? asciiBase_ColorEscape + fg
1889 : (asciiBase_ColorEscape + 1897 : (asciiBase_ColorEscape +
1890 linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)), 1898 linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)),
1891 showImage ? " View Image \U0001f5bc" 1899 showImage ? " View Image \U0001f5bc"
1892 : showAudio ? " Play Audio \U0001f3b5" : ""); 1900 : showAudio ? " Play Audio \U0001f3b5" : "");
1893 } 1901 }
1894 if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) { 1902 if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) {
1895 iDate date; 1903 iDate date;