summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c61
1 files changed, 39 insertions, 22 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 5ff8c72f..a85e4b71 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -333,13 +333,14 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
333 link->urlRange = capturedRange_RegExpMatch(&m, 1); 333 link->urlRange = capturedRange_RegExpMatch(&m, 1);
334 setRange_String(&link->url, link->urlRange); 334 setRange_String(&link->url, link->urlRange);
335 set_String(&link->url, canonicalUrl_String(absoluteUrl_String(&d->url, &link->url))); 335 set_String(&link->url, canonicalUrl_String(absoluteUrl_String(&d->url, &link->url)));
336 if (startsWithCase_String(&link->url, "about:command")) { 336 /* If invalid, disregard the link. */
337 /* This is a special internal page that allows submitting UI events. */ 337 if ((d->format == gemini_SourceFormat && size_String(&link->url) > prefs_App()->maxUrlSize) ||
338 if (!d->enableCommandLinks) { 338 (startsWithCase_String(&link->url, "about:command")
339 delete_GmLink(link); 339 /* this is a special internal page that allows submitting UI events */
340 *linkId = 0; 340 && !d->enableCommandLinks)) {
341 return line; 341 delete_GmLink(link);
342 } 342 *linkId = 0;
343 return line;
343 } 344 }
344 /* Check the URL. */ { 345 /* Check the URL. */ {
345 iUrl parts; 346 iUrl parts;
@@ -370,6 +371,13 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
370 } 371 }
371 else if (equalCase_Rangecc(parts.scheme, "data")) { 372 else if (equalCase_Rangecc(parts.scheme, "data")) {
372 setScheme_GmLink_(link, data_GmLinkScheme); 373 setScheme_GmLink_(link, data_GmLinkScheme);
374 if (startsWith_Rangecc(parts.path, "image/png") ||
375 startsWith_Rangecc(parts.path, "image/jpg") ||
376 startsWith_Rangecc(parts.path, "image/jpeg") ||
377 startsWith_Rangecc(parts.path, "image/webp") ||
378 startsWith_Rangecc(parts.path, "image/gif")) {
379 link->flags |= imageFileExtension_GmLinkFlag;
380 }
373 } 381 }
374 else if (equalCase_Rangecc(parts.scheme, "about")) { 382 else if (equalCase_Rangecc(parts.scheme, "about")) {
375 setScheme_GmLink_(link, about_GmLinkScheme); 383 setScheme_GmLink_(link, about_GmLinkScheme);
@@ -382,7 +390,7 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
382 iString *path = newRange_String(parts.path); 390 iString *path = newRange_String(parts.path);
383 if (endsWithCase_String(path, ".gif") || endsWithCase_String(path, ".jpg") || 391 if (endsWithCase_String(path, ".gif") || endsWithCase_String(path, ".jpg") ||
384 endsWithCase_String(path, ".jpeg") || endsWithCase_String(path, ".png") || 392 endsWithCase_String(path, ".jpeg") || endsWithCase_String(path, ".png") ||
385 endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") || 393 endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") ||
386#if defined (LAGRANGE_ENABLE_WEBP) 394#if defined (LAGRANGE_ENABLE_WEBP)
387 endsWithCase_String(path, ".webp") || 395 endsWithCase_String(path, ".webp") ||
388#endif 396#endif
@@ -483,8 +491,7 @@ static iBool isNormalized_GmDocument_(const iGmDocument *d) {
483} 491}
484 492
485static enum iGmDocumentTheme currentTheme_(void) { 493static enum iGmDocumentTheme currentTheme_(void) {
486 return (isDark_ColorTheme(colorTheme_App()) ? prefs_App()->docThemeDark 494 return docTheme_Prefs(prefs_App());
487 : prefs_App()->docThemeLight);
488} 495}
489 496
490static void alignDecoration_GmRun_(iGmRun *run, iBool isCentered) { 497static void alignDecoration_GmRun_(iGmRun *run, iBool isCentered) {
@@ -904,6 +911,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
904 : scheme == titan_GmLinkScheme ? uploadArrow 911 : scheme == titan_GmLinkScheme ? uploadArrow
905 : scheme == finger_GmLinkScheme ? pointingFinger 912 : scheme == finger_GmLinkScheme ? pointingFinger
906 : scheme == mailto_GmLinkScheme ? envelope 913 : scheme == mailto_GmLinkScheme ? envelope
914 : scheme == data_GmLinkScheme ? paperclip_Icon
907 : link->flags & remote_GmLinkFlag ? globe 915 : link->flags & remote_GmLinkFlag ? globe
908 : link->flags & imageFileExtension_GmLinkFlag ? image 916 : link->flags & imageFileExtension_GmLinkFlag ? image
909 : link->flags & fontpackFileExtension_GmLinkFlag ? fontpack_Icon 917 : link->flags & fontpackFileExtension_GmLinkFlag ? fontpack_Icon
@@ -1283,7 +1291,7 @@ static void updateIconBasedOnUrl_GmDocument_(iGmDocument *d) {
1283 } 1291 }
1284} 1292}
1285 1293
1286void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { 1294void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *paletteSeed, const iBlock *iconSeed) {
1287 const iPrefs * prefs = prefs_App(); 1295 const iPrefs * prefs = prefs_App();
1288 enum iGmDocumentTheme theme = currentTheme_(); 1296 enum iGmDocumentTheme theme = currentTheme_();
1289 static const iChar siteIcons[] = { 1297 static const iChar siteIcons[] = {
@@ -1294,6 +1302,16 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1294 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531, 1302 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531,
1295 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c, 1303 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c,
1296 }; 1304 };
1305 if (!iconSeed) {
1306 iconSeed = paletteSeed;
1307 }
1308 if (iconSeed && !isEmpty_Block(iconSeed)) {
1309 const uint32_t seedHash = themeHash_(iconSeed);
1310 d->siteIcon = siteIcons[(seedHash >> 7) % iElemCount(siteIcons)];
1311 }
1312 else {
1313 d->siteIcon = 0;
1314 }
1297 /* Default colors. These are used on "about:" pages and local files, for example. */ { 1315 /* Default colors. These are used on "about:" pages and local files, for example. */ {
1298 /* Link colors are generally the same in all themes. */ 1316 /* Link colors are generally the same in all themes. */
1299 set_Color(tmBadLink_ColorId, get_Color(red_ColorId)); 1317 set_Color(tmBadLink_ColorId, get_Color(red_ColorId));
@@ -1495,13 +1513,11 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1495 } 1513 }
1496 } 1514 }
1497 } 1515 }
1498 if (seed && !isEmpty_Block(seed)) { 1516 if (paletteSeed && !isEmpty_Block(paletteSeed)) {
1499 d->themeSeed = themeHash_(seed); 1517 d->themeSeed = themeHash_(paletteSeed);
1500 d->siteIcon = siteIcons[(d->themeSeed >> 7) % iElemCount(siteIcons)];
1501 } 1518 }
1502 else { 1519 else {
1503 d->themeSeed = 0; 1520 d->themeSeed = 0;
1504 d->siteIcon = 0;
1505 } 1521 }
1506 /* Set up colors. */ 1522 /* Set up colors. */
1507 if (d->themeSeed) { 1523 if (d->themeSeed) {
@@ -1552,7 +1568,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1552 1568
1553 if (theme == colorfulDark_GmDocumentTheme) { 1569 if (theme == colorfulDark_GmDocumentTheme) {
1554 iHSLColor base = { hues[primIndex], 1570 iHSLColor base = { hues[primIndex],
1555 0.8f * (d->themeSeed >> 24) / 255.0f, 1571 0.8f * (d->themeSeed >> 24) / 255.0f + minSat_HSLColor,
1556 0.06f + 0.09f * ((d->themeSeed >> 5) & 0x7) / 7.0f, 1572 0.06f + 0.09f * ((d->themeSeed >> 5) & 0x7) / 7.0f,
1557 1.0f }; 1573 1.0f };
1558 iHSLColor altBase = { altHue, base.sat, base.lum, 1 }; 1574 iHSLColor altBase = { altHue, base.sat, base.lum, 1 };
@@ -1562,13 +1578,13 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1562 setHsl_Color(tmBannerBackground_ColorId, addSatLum_HSLColor(base, 0.1f, 0.04f * (isBannerLighter ? 1 : -1))); 1578 setHsl_Color(tmBannerBackground_ColorId, addSatLum_HSLColor(base, 0.1f, 0.04f * (isBannerLighter ? 1 : -1)));
1563 setHsl_Color(tmBannerTitle_ColorId, setLum_HSLColor(addSatLum_HSLColor(base, 0.1f, 0), 0.55f)); 1579 setHsl_Color(tmBannerTitle_ColorId, setLum_HSLColor(addSatLum_HSLColor(base, 0.1f, 0), 0.55f));
1564 setHsl_Color(tmBannerIcon_ColorId, setLum_HSLColor(addSatLum_HSLColor(base, 0.35f, 0), 0.65f)); 1580 setHsl_Color(tmBannerIcon_ColorId, setLum_HSLColor(addSatLum_HSLColor(base, 0.35f, 0), 0.65f));
1565 1581
1566// printf("primHue: %zu alts: %d %d isDarkBgSat: %d\n", 1582// printf("primHue: %zu alts: %d %d isDarkBgSat: %d\n",
1567// primIndex, 1583// primIndex,
1568// altHues[primIndex].index[altIndex[0]], 1584// altHues[primIndex].index[altIndex[0]],
1569// altHues[primIndex].index[altIndex[1]], 1585// altHues[primIndex].index[altIndex[1]],
1570// isDarkBgSat); 1586// isDarkBgSat);
1571 1587
1572 const float titleLum = 0.2f * ((d->themeSeed >> 17) & 0x7) / 7.0f; 1588 const float titleLum = 0.2f * ((d->themeSeed >> 17) & 0x7) / 7.0f;
1573 setHsl_Color(tmHeading1_ColorId, setLum_HSLColor(altBase, titleLum + 0.80f)); 1589 setHsl_Color(tmHeading1_ColorId, setLum_HSLColor(altBase, titleLum + 0.80f));
1574 setHsl_Color(tmHeading2_ColorId, setLum_HSLColor(altBase, titleLum + 0.70f)); 1590 setHsl_Color(tmHeading2_ColorId, setLum_HSLColor(altBase, titleLum + 0.70f));
@@ -1730,8 +1746,8 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1730 /* Derived colors. */ 1746 /* Derived colors. */
1731 setDerivedThemeColors_(theme); 1747 setDerivedThemeColors_(theme);
1732 /* Special exceptions. */ 1748 /* Special exceptions. */
1733 if (seed) { 1749 if (iconSeed) {
1734 if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) { 1750 if (equal_CStr(cstr_Block(iconSeed), "gemini.circumlunar.space")) {
1735 d->siteIcon = 0x264a; /* gemini symbol */ 1751 d->siteIcon = 0x264a; /* gemini symbol */
1736 } 1752 }
1737 updateIconBasedOnUrl_GmDocument_(d); 1753 updateIconBasedOnUrl_GmDocument_(d);
@@ -1752,7 +1768,8 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1752void makePaletteGlobal_GmDocument(const iGmDocument *d) { 1768void makePaletteGlobal_GmDocument(const iGmDocument *d) {
1753 if (!d->isPaletteValid) { 1769 if (!d->isPaletteValid) {
1754 /* Recompute the palette since it's needed now. */ 1770 /* Recompute the palette since it's needed now. */
1755 setThemeSeed_GmDocument((iGmDocument *) d, urlThemeSeed_String(&d->url)); 1771 setThemeSeed_GmDocument(
1772 (iGmDocument *) d, urlPaletteSeed_String(&d->url), urlThemeSeed_String(&d->url));
1756 } 1773 }
1757 iAssert(d->isPaletteValid); 1774 iAssert(d->isPaletteValid);
1758 memcpy(get_Root()->tmPalette, d->palette, sizeof(d->palette)); 1775 memcpy(get_Root()->tmPalette, d->palette, sizeof(d->palette));
@@ -1929,7 +1946,7 @@ static void normalize_GmDocument(iGmDocument *d) {
1929void setUrl_GmDocument(iGmDocument *d, const iString *url) { 1946void setUrl_GmDocument(iGmDocument *d, const iString *url) {
1930 url = canonicalUrl_String(url); 1947 url = canonicalUrl_String(url);
1931 set_String(&d->url, url); 1948 set_String(&d->url, url);
1932 setThemeSeed_GmDocument(d, urlThemeSeed_String(url)); 1949 setThemeSeed_GmDocument(d, urlPaletteSeed_String(url), urlThemeSeed_String(url));
1933 iUrl parts; 1950 iUrl parts;
1934 init_Url(&parts, url); 1951 init_Url(&parts, url);
1935 setRange_String(&d->localHost, parts.host); 1952 setRange_String(&d->localHost, parts.host);