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.c60
1 files changed, 44 insertions, 16 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index a61d5b88..dbcf57eb 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -157,7 +157,7 @@ static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {
157 const iWidget *w = constAs_Widget(d); 157 const iWidget *w = constAs_Widget(d);
158 const iRect bounds = bounds_Widget(w); 158 const iRect bounds = bounds_Widget(w);
159 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2, 159 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2,
160 fontSize_UI * 40 * d->textSizePercent / 100); 160 fontSize_UI * 38 * d->textSizePercent / 100); /* TODO: Add user preference .*/
161} 161}
162 162
163static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { 163static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
@@ -168,11 +168,12 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
168 rect.pos.x = bounds.size.x / 2 - rect.size.x / 2; 168 rect.pos.x = bounds.size.x / 2 - rect.size.x / 2;
169 rect.pos.y = top_Rect(bounds) + margin; 169 rect.pos.y = top_Rect(bounds) + margin;
170 rect.size.y = height_Rect(bounds) - 2 * margin; 170 rect.size.y = height_Rect(bounds) - 2 * margin;
171 if (size_GmDocument(d->doc).y < rect.size.y) { 171 iInt2 docSize = addY_I2(size_GmDocument(d->doc), 0 /*-lineHeight_Text(banner_FontId) * 2*/);
172 if (docSize.y < rect.size.y) {
172 /* Center vertically if short. */ 173 /* Center vertically if short. */
173 int offset = (rect.size.y - size_GmDocument(d->doc).y) / 2; 174 int offset = (rect.size.y - docSize.y) / 2;
174 rect.pos.y += offset; 175 rect.pos.y += offset;
175 rect.size.y = size_GmDocument(d->doc).y; 176 rect.size.y = docSize.y;
176 } 177 }
177 return rect; 178 return rect;
178} 179}
@@ -324,11 +325,19 @@ static void updateSource_DocumentWidget_(iDocumentWidget *d) {
324 /* TODO: Do this in the background. However, that requires a text metrics calculator 325 /* TODO: Do this in the background. However, that requires a text metrics calculator
325 that does not try to cache the glyph bitmaps. */ 326 that does not try to cache the glyph bitmaps. */
326 const enum iGmStatusCode statusCode = status_GmRequest(d->request); 327 const enum iGmStatusCode statusCode = status_GmRequest(d->request);
327 if (statusCode != input_GmStatusCode && 328 if (category_GmStatusCode(statusCode) != categoryInput_GmStatusCode) {
328 statusCode != sensitiveInput_GmStatusCode) {
329 iString str; 329 iString str;
330 /* Theming. */ {
331 if (isEmpty_String(d->titleUser)) {
332 setThemeSeed_GmDocument(d->doc,
333 collect_Block(newRange_Block(urlHost_String(d->url))));
334 }
335 else {
336 setThemeSeed_GmDocument(d->doc, &d->titleUser->chars);
337 }
338 }
330 initBlock_String(&str, body_GmRequest(d->request)); 339 initBlock_String(&str, body_GmRequest(d->request));
331 if (statusCode == success_GmStatusCode) { 340 if (category_GmStatusCode(statusCode) == categorySuccess_GmStatusCode) {
332 /* Check the MIME type. */ 341 /* Check the MIME type. */
333 const iString *mime = meta_GmRequest(d->request); 342 const iString *mime = meta_GmRequest(d->request);
334 if (startsWith_String(mime, "text/plain")) { 343 if (startsWith_String(mime, "text/plain")) {
@@ -997,14 +1006,11 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
997 } 1006 }
998 return; 1007 return;
999 } 1008 }
1000 iString text;
1001 /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */
1002 initRange_String(&text, run->text);
1003 enum iColorId fg = run->color; 1009 enum iColorId fg = run->color;
1004 const iGmDocument *doc = d->widget->doc; 1010 const iGmDocument *doc = d->widget->doc;
1005 const iBool isHover = 1011 const iBool isHover =
1006 run->linkId != 0 && d->widget->hoverLink && run->linkId == d->widget->hoverLink->linkId && 1012 (run->linkId != 0 && d->widget->hoverLink && run->linkId == d->widget->hoverLink->linkId &&
1007 !isEmpty_Rect(run->bounds); 1013 !isEmpty_Rect(run->bounds));
1008 const iInt2 visPos = add_I2(run->visBounds.pos, origin); 1014 const iInt2 visPos = add_I2(run->visBounds.pos, origin);
1009 /* Text markers. */ 1015 /* Text markers. */
1010 fillRange_DrawContext_(d, run, teal_ColorId, d->widget->foundMark, &d->inFoundMark); 1016 fillRange_DrawContext_(d, run, teal_ColorId, d->widget->foundMark, &d->inFoundMark);
@@ -1016,8 +1022,30 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
1016 fg = linkColor_GmDocument(doc, run->linkId); 1022 fg = linkColor_GmDocument(doc, run->linkId);
1017 } 1023 }
1018 } 1024 }
1019 drawString_Text(run->font, visPos, fg, &text); 1025 if (run->flags & siteBanner_GmRunFlag) {
1020 deinit_String(&text); 1026 fillRect_Paint(
1027 &d->paint,
1028 initCorners_Rect(topLeft_Rect(d->widgetBounds),
1029 init_I2(right_Rect(bounds_Widget(constAs_Widget(d->widget))),
1030 visPos.y + height_Rect(run->visBounds))),
1031 black_ColorId);
1032 const iChar icon = siteIcon_GmDocument(doc);
1033 iString bannerText;
1034 init_String(&bannerText);
1035 format_String(&bannerText, "%lc", (int) icon);
1036 //appendRange_String(&bannerText, run->text);
1037 const iInt2 iconSize = advanceN_Text(banner_FontId, cstr_String(&bannerText), 2);
1038 iInt2 bpos = add_I2(visPos, init_I2(0, lineHeight_Text(banner_FontId) / 2));
1039// draw_Text(run->font, bpos, fg, "%s", buf);
1040// bpos.x += iconSize.x;
1041 drawRange_Text(run->font, bpos, fg, range_String(&bannerText));
1042 bpos.x += iconSize.x + 3 * gap_Text;
1043 drawRange_Text(run->font, bpos, fg, run->text);
1044 deinit_String(&bannerText);
1045 }
1046 else {
1047 drawRange_Text(run->font, visPos, fg, run->text);
1048 }
1021 /* Presentation of links. */ 1049 /* Presentation of links. */
1022 if (run->linkId) { 1050 if (run->linkId) {
1023 const int metaFont = paragraph_FontId; 1051 const int metaFont = paragraph_FontId;
@@ -1124,7 +1152,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
1124 .bounds = documentBounds_DocumentWidget_(d) 1152 .bounds = documentBounds_DocumentWidget_(d)
1125 }; 1153 };
1126 init_Paint(&ctx.paint); 1154 init_Paint(&ctx.paint);
1127 fillRect_Paint(&ctx.paint, bounds, gray15_ColorId); 1155 fillRect_Paint(&ctx.paint, bounds, black_ColorId);
1128 setClip_Paint(&ctx.paint, bounds); 1156 setClip_Paint(&ctx.paint, bounds);
1129 render_GmDocument(d->doc, visibleRange_DocumentWidget_(d), drawRun_DrawContext_, &ctx); 1157 render_GmDocument(d->doc, visibleRange_DocumentWidget_(d), drawRun_DrawContext_, &ctx);
1130 clearClip_Paint(&ctx.paint); 1158 clearClip_Paint(&ctx.paint);