summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-13 10:58:59 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-23 13:34:57 +0200
commite39721581f082a20f1ef3a6f81b83c5e489cf7c7 (patch)
treece16e9a85d344d21eaa146f49e237eeaa3d1a1b9 /src/ui/documentwidget.c
parent74de1ab589b80b7719e97341ec98869ecf3da8aa (diff)
Android: Various fixes to get things up and running
Resource paths, runtime data, ignore mouse events. Assume that the Java side tells us the display pixel density via a command line argument.
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index e93fb586..b20ae672 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -225,7 +225,7 @@ enum iDocumentWidgetFlag {
225 animationPlaceholder_DocumentWidgetFlag = iBit(16), /* avoid slow operations */ 225 animationPlaceholder_DocumentWidgetFlag = iBit(16), /* avoid slow operations */
226 invalidationPending_DocumentWidgetFlag = iBit(17), /* invalidate as soon as convenient */ 226 invalidationPending_DocumentWidgetFlag = iBit(17), /* invalidate as soon as convenient */
227 leftWheelSwipe_DocumentWidgetFlag = iBit(18), /* swipe state flags are used on desktop */ 227 leftWheelSwipe_DocumentWidgetFlag = iBit(18), /* swipe state flags are used on desktop */
228 rightWheelSwipe_DocumentWidgetFlag = iBit(19), 228 rightWheelSwipe_DocumentWidgetFlag = iBit(19),
229 eitherWheelSwipe_DocumentWidgetFlag = leftWheelSwipe_DocumentWidgetFlag | 229 eitherWheelSwipe_DocumentWidgetFlag = leftWheelSwipe_DocumentWidgetFlag |
230 rightWheelSwipe_DocumentWidgetFlag, 230 rightWheelSwipe_DocumentWidgetFlag,
231}; 231};
@@ -242,8 +242,8 @@ enum iWheelSwipeState {
242 242
243/* TODO: DocumentView is supposed to be useful on its own; move to a separate source file. */ 243/* TODO: DocumentView is supposed to be useful on its own; move to a separate source file. */
244iDeclareType(DocumentView) 244iDeclareType(DocumentView)
245 245
246struct Impl_DocumentView { 246struct Impl_DocumentView {
247 iDocumentWidget *owner; /* TODO: Convert to an abstract provider of metrics? */ 247 iDocumentWidget *owner; /* TODO: Convert to an abstract provider of metrics? */
248 iGmDocument * doc; 248 iGmDocument * doc;
249 int pageMargin; 249 int pageMargin;
@@ -253,7 +253,7 @@ struct Impl_DocumentView {
253 iGmRunRange visibleRuns; 253 iGmRunRange visibleRuns;
254 iPtrArray visibleLinks; 254 iPtrArray visibleLinks;
255 iPtrArray visiblePre; 255 iPtrArray visiblePre;
256 iPtrArray visibleMedia; /* currently playing audio / ongoing downloads */ 256 iPtrArray visibleMedia; /* currently playing audio / ongoing downloads */
257 iPtrArray visibleWideRuns; /* scrollable blocks; TODO: merge into `visiblePre` */ 257 iPtrArray visibleWideRuns; /* scrollable blocks; TODO: merge into `visiblePre` */
258 const iGmRun * hoverPre; /* for clicking */ 258 const iGmRun * hoverPre; /* for clicking */
259 const iGmRun * hoverAltPre; /* for drawing alt text */ 259 const iGmRun * hoverAltPre; /* for drawing alt text */
@@ -263,7 +263,7 @@ struct Impl_DocumentView {
263 uint16_t animWideRunId; 263 uint16_t animWideRunId;
264 iGmRunRange animWideRunRange; 264 iGmRunRange animWideRunRange;
265 iDrawBufs * drawBufs; /* dynamic state for drawing */ 265 iDrawBufs * drawBufs; /* dynamic state for drawing */
266 iVisBuf * visBuf; 266 iVisBuf * visBuf;
267 iVisBufMeta * visBufMeta; 267 iVisBufMeta * visBufMeta;
268 iGmRunRange renderRuns; 268 iGmRunRange renderRuns;
269 iPtrSet * invalidRuns; 269 iPtrSet * invalidRuns;
@@ -272,7 +272,7 @@ struct Impl_DocumentView {
272struct Impl_DocumentWidget { 272struct Impl_DocumentWidget {
273 iWidget widget; 273 iWidget widget;
274 int flags; /* internal behavior, see enum iDocumentWidgetFlag */ 274 int flags; /* internal behavior, see enum iDocumentWidgetFlag */
275 275
276 /* User interface: */ 276 /* User interface: */
277 enum iDocumentLinkOrdinalMode ordinalMode; 277 enum iDocumentLinkOrdinalMode ordinalMode;
278 size_t ordinalBase; 278 size_t ordinalBase;
@@ -293,7 +293,7 @@ struct Impl_DocumentWidget {
293 enum iWheelSwipeState wheelSwipeState; 293 enum iWheelSwipeState wheelSwipeState;
294 iString pendingGotoHeading; 294 iString pendingGotoHeading;
295 iString linePrecedingLink; 295 iString linePrecedingLink;
296 296
297 /* Network request: */ 297 /* Network request: */
298 enum iRequestState state; 298 enum iRequestState state;
299 iGmRequest * request; 299 iGmRequest * request;
@@ -304,7 +304,7 @@ struct Impl_DocumentWidget {
304 iString * certSubject; 304 iString * certSubject;
305 int redirectCount; 305 int redirectCount;
306 iObjectList * media; /* inline media requests */ 306 iObjectList * media; /* inline media requests */
307 307
308 /* Document: */ 308 /* Document: */
309 iPersistentDocumentState mod; 309 iPersistentDocumentState mod;
310 iString * titleUser; 310 iString * titleUser;
@@ -316,12 +316,12 @@ struct Impl_DocumentWidget {
316 iGempub * sourceGempub; /* NULL unless the page is Gempub content */ 316 iGempub * sourceGempub; /* NULL unless the page is Gempub content */
317 iBanner * banner; 317 iBanner * banner;
318 float initNormScrollY; 318 float initNormScrollY;
319 319
320 /* Rendering: */ 320 /* Rendering: */
321 iDocumentView view; 321 iDocumentView view;
322 iLinkInfo * linkInfo; 322 iLinkInfo * linkInfo;
323 323
324 /* Widget structure: */ 324 /* Widget structure: */
325 iScrollWidget *scroll; 325 iScrollWidget *scroll;
326 iWidget * footerButtons; 326 iWidget * footerButtons;
327 iWidget * menu; 327 iWidget * menu;
@@ -332,7 +332,7 @@ struct Impl_DocumentWidget {
332}; 332};
333 333
334iDefineObjectConstruction(DocumentWidget) 334iDefineObjectConstruction(DocumentWidget)
335 335
336/* Sorted by proximity to F and J. */ 336/* Sorted by proximity to F and J. */
337static const int homeRowKeys_[] = { 337static const int homeRowKeys_[] = {
338 'f', 'd', 's', 'a', 338 'f', 'd', 's', 'a',
@@ -344,7 +344,7 @@ static const int homeRowKeys_[] = {
344 'g', 'h', 344 'g', 'h',
345 'b', 345 'b',
346 't', 'y', 346 't', 'y',
347}; 347};
348static int docEnum_ = 0; 348static int docEnum_ = 0;
349 349
350static void animate_DocumentWidget_ (void *ticker); 350static void animate_DocumentWidget_ (void *ticker);
@@ -909,7 +909,7 @@ static void updateTimestampBuf_DocumentView_(const iDocumentView *d) {
909 909
910static void invalidate_DocumentView_(iDocumentView *d) { 910static void invalidate_DocumentView_(iDocumentView *d) {
911 invalidate_VisBuf(d->visBuf); 911 invalidate_VisBuf(d->visBuf);
912 clear_PtrSet(d->invalidRuns); 912 clear_PtrSet(d->invalidRuns);
913} 913}
914 914
915static void documentRunsInvalidated_DocumentView_(iDocumentView *d) { 915static void documentRunsInvalidated_DocumentView_(iDocumentView *d) {
@@ -928,11 +928,11 @@ static void resetScroll_DocumentView_(iDocumentView *d) {
928} 928}
929 929
930static void updateWidth_DocumentView_(iDocumentView *d) { 930static void updateWidth_DocumentView_(iDocumentView *d) {
931 updateWidth_GmDocument(d->doc, documentWidth_DocumentView_(d), width_Widget(d->owner)); 931 updateWidth_GmDocument(d->doc, documentWidth_DocumentView_(d), width_Widget(d->owner));
932} 932}
933 933
934static void updateWidthAndRedoLayout_DocumentView_(iDocumentView *d) { 934static void updateWidthAndRedoLayout_DocumentView_(iDocumentView *d) {
935 setWidth_GmDocument(d->doc, documentWidth_DocumentView_(d), width_Widget(d->owner)); 935 setWidth_GmDocument(d->doc, documentWidth_DocumentView_(d), width_Widget(d->owner));
936} 936}
937 937
938static void clampScroll_DocumentView_(iDocumentView *d) { 938static void clampScroll_DocumentView_(iDocumentView *d) {
@@ -1025,7 +1025,7 @@ static iRangecc sourceLoc_DocumentView_(const iDocumentView *d, iInt2 pos) {
1025} 1025}
1026 1026
1027iDeclareType(MiddleRunParams) 1027iDeclareType(MiddleRunParams)
1028 1028
1029struct Impl_MiddleRunParams { 1029struct Impl_MiddleRunParams {
1030 int midY; 1030 int midY;
1031 const iGmRun *closest; 1031 const iGmRun *closest;
@@ -1126,7 +1126,7 @@ static iRect runRect_DocumentView_(const iDocumentView *d, const iGmRun *run) {
1126} 1126}
1127 1127
1128iDeclareType(DrawContext) 1128iDeclareType(DrawContext)
1129 1129
1130struct Impl_DrawContext { 1130struct Impl_DrawContext {
1131 const iDocumentView *view; 1131 const iDocumentView *view;
1132 iRect widgetBounds; 1132 iRect widgetBounds;
@@ -1260,7 +1260,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
1260 isInlineImageCaption = iFalse; 1260 isInlineImageCaption = iFalse;
1261 } 1261 }
1262#endif 1262#endif
1263 /* While this is consistent, it's a bit excessive to indicate that an inlined image 1263 /* While this is consistent, it's a bit excessive to indicate that an inlined image
1264 is open: the image itself is the indication. */ 1264 is open: the image itself is the indication. */
1265 const iBool isInlineImageCaption = iFalse; 1265 const iBool isInlineImageCaption = iFalse;
1266 if (run->linkId && (linkFlags & isOpen_GmLinkFlag || isInlineImageCaption)) { 1266 if (run->linkId && (linkFlags & isOpen_GmLinkFlag || isInlineImageCaption)) {
@@ -1285,7 +1285,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
1285 } 1285 }
1286 fillRect_Paint(&d->paint, wideRect, bg); 1286 fillRect_Paint(&d->paint, wideRect, bg);
1287 } 1287 }
1288 else { 1288 else {
1289 /* Normal background for other runs. There are cases when runs get drawn multiple times, 1289 /* Normal background for other runs. There are cases when runs get drawn multiple times,
1290 e.g., at the buffer boundary, and there are slightly overlapping characters in 1290 e.g., at the buffer boundary, and there are slightly overlapping characters in
1291 monospace blocks. Clearing the background here ensures a cleaner visual appearance 1291 monospace blocks. Clearing the background here ensures a cleaner visual appearance
@@ -2095,7 +2095,7 @@ static void invalidate_DocumentWidget_(iDocumentWidget *d) {
2095} 2095}
2096 2096
2097static iRangecc siteText_DocumentWidget_(const iDocumentWidget *d) { 2097static iRangecc siteText_DocumentWidget_(const iDocumentWidget *d) {
2098 return isEmpty_String(d->titleUser) ? urlHost_String(d->mod.url) 2098 return isEmpty_String(d->titleUser) ? urlHost_String(d->mod.url)
2099 : range_String(d->titleUser); 2099 : range_String(d->titleUser);
2100} 2100}
2101 2101
@@ -2161,7 +2161,7 @@ static void updateBanner_DocumentWidget_(iDocumentWidget *d) {
2161static void updateTheme_DocumentWidget_(iDocumentWidget *d) { 2161static void updateTheme_DocumentWidget_(iDocumentWidget *d) {
2162 if (document_App() != d || category_GmStatusCode(d->sourceStatus) == categoryInput_GmStatusCode) { 2162 if (document_App() != d || category_GmStatusCode(d->sourceStatus) == categoryInput_GmStatusCode) {
2163 return; 2163 return;
2164 } 2164 }
2165 d->view.drawBufs->flags |= updateTimestampBuf_DrawBufsFlag; 2165 d->view.drawBufs->flags |= updateTimestampBuf_DrawBufsFlag;
2166 updateBanner_DocumentWidget_(d); 2166 updateBanner_DocumentWidget_(d);
2167} 2167}
@@ -2620,7 +2620,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d,
2620 appendFormat_String(&str, 2620 appendFormat_String(&str,
2621 cstr_Lang("doc.archive"), 2621 cstr_Lang("doc.archive"),
2622 cstr_Rangecc(baseName_Path(d->mod.url))); 2622 cstr_Rangecc(baseName_Path(d->mod.url)));
2623 appendCStr_String(&str, "\n"); 2623 appendCStr_String(&str, "\n");
2624 } 2624 }
2625 appendCStr_String(&str, "\n"); 2625 appendCStr_String(&str, "\n");
2626 iString *localPath = localFilePathFromUrl_String(d->mod.url); 2626 iString *localPath = localFilePathFromUrl_String(d->mod.url);
@@ -2768,7 +2768,7 @@ static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *r
2768 } 2768 }
2769 else if (~d->certFlags & timeVerified_GmCertFlag) { 2769 else if (~d->certFlags & timeVerified_GmCertFlag) {
2770 updateTextCStr_LabelWidget(lock, isDarkMode ? orange_ColorEscape warning_Icon 2770 updateTextCStr_LabelWidget(lock, isDarkMode ? orange_ColorEscape warning_Icon
2771 : black_ColorEscape warning_Icon); 2771 : black_ColorEscape warning_Icon);
2772 } 2772 }
2773 else { 2773 else {
2774 updateTextCStr_LabelWidget(lock, green_ColorEscape closedLock_Icon); 2774 updateTextCStr_LabelWidget(lock, green_ColorEscape closedLock_Icon);
@@ -3067,7 +3067,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
3067 it is only displayed as an input dialog. */ 3067 it is only displayed as an input dialog. */
3068 visitUrl_Visited(visited_App(), d->mod.url, transient_VisitedUrlFlag); 3068 visitUrl_Visited(visited_App(), d->mod.url, transient_VisitedUrlFlag);
3069 iUrl parts; 3069 iUrl parts;
3070 init_Url(&parts, d->mod.url); 3070 init_Url(&parts, d->mod.url);
3071 iWidget *dlg = makeValueInput_Widget( 3071 iWidget *dlg = makeValueInput_Widget(
3072 as_Widget(d), 3072 as_Widget(d),
3073 NULL, 3073 NULL,
@@ -3132,7 +3132,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
3132 setFont_LabelWidget(menu, font_LabelWidget((iLabelWidget *) lastChild_Widget(buttons))); 3132 setFont_LabelWidget(menu, font_LabelWidget((iLabelWidget *) lastChild_Widget(buttons)));
3133 setTextColor_LabelWidget(menu, uiTextAction_ColorId); 3133 setTextColor_LabelWidget(menu, uiTextAction_ColorId);
3134 } 3134 }
3135 } 3135 }
3136 setValidator_InputWidget(findChild_Widget(dlg, "input"), inputQueryValidator_, d); 3136 setValidator_InputWidget(findChild_Widget(dlg, "input"), inputQueryValidator_, d);
3137 setSensitiveContent_InputWidget(findChild_Widget(dlg, "input"), 3137 setSensitiveContent_InputWidget(findChild_Widget(dlg, "input"),
3138 statusCode == sensitiveInput_GmStatusCode); 3138 statusCode == sensitiveInput_GmStatusCode);
@@ -3491,7 +3491,7 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
3491 } 3491 }
3492 /* The temporary "swipein" will display the previous page until the finger is lifted. */ 3492 /* The temporary "swipein" will display the previous page until the finger is lifted. */
3493 iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein"); 3493 iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein");
3494 if (!swipeIn) { 3494 if (!swipeIn) {
3495 swipeIn = new_DocumentWidget(); 3495 swipeIn = new_DocumentWidget();
3496 swipeIn->flags |= animationPlaceholder_DocumentWidgetFlag; 3496 swipeIn->flags |= animationPlaceholder_DocumentWidgetFlag;
3497 setId_Widget(as_Widget(swipeIn), "swipein"); 3497 setId_Widget(as_Widget(swipeIn), "swipein");
@@ -3531,7 +3531,7 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
3531 iWidget *swipeParent = swipeParent_DocumentWidget_(d); 3531 iWidget *swipeParent = swipeParent_DocumentWidget_(d);
3532 if (findChild_Widget(swipeParent, "swipeout")) { 3532 if (findChild_Widget(swipeParent, "swipeout")) {
3533 return iTrue; /* too fast, previous animation hasn't finished */ 3533 return iTrue; /* too fast, previous animation hasn't finished */
3534 } 3534 }
3535 /* Setup the drag. `d` will be moving with the finger. */ 3535 /* Setup the drag. `d` will be moving with the finger. */
3536 animSpan = 0; 3536 animSpan = 0;
3537 postCommand_Widget(d, "navigate.forward"); 3537 postCommand_Widget(d, "navigate.forward");
@@ -3694,7 +3694,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3694 else if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed") || 3694 else if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed") ||
3695 equal_Command(cmd, "keyroot.changed")) { 3695 equal_Command(cmd, "keyroot.changed")) {
3696 if (equal_Command(cmd, "font.changed")) { 3696 if (equal_Command(cmd, "font.changed")) {
3697 invalidateCachedLayout_History(d->mod.history); 3697 invalidateCachedLayout_History(d->mod.history);
3698 } 3698 }
3699 /* Alt/Option key may be involved in window size changes. */ 3699 /* Alt/Option key may be involved in window size changes. */
3700 setLinkNumberMode_DocumentWidget_(d, iFalse); 3700 setLinkNumberMode_DocumentWidget_(d, iFalse);
@@ -4056,7 +4056,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
4056 } 4056 }
4057 return wasHandled; 4057 return wasHandled;
4058 } 4058 }
4059 else if (equal_Command(cmd, "document.upload") && d == document_App()) { 4059 else if (equal_Command(cmd, "document.upload") && d == document_App()) {
4060 if (findChild_Widget(root_Widget(w), "upload")) { 4060 if (findChild_Widget(root_Widget(w), "upload")) {
4061 return iTrue; /* already open */ 4061 return iTrue; /* already open */
4062 } 4062 }
@@ -4124,7 +4124,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
4124 if (equalCase_Rangecc(urlScheme_String(d->mod.url), "titan")) { 4124 if (equalCase_Rangecc(urlScheme_String(d->mod.url), "titan")) {
4125 /* Reopen so the Upload dialog gets shown. */ 4125 /* Reopen so the Upload dialog gets shown. */
4126 postCommandf_App("open url:%s", cstr_String(d->mod.url)); 4126 postCommandf_App("open url:%s", cstr_String(d->mod.url));
4127 return iTrue; 4127 return iTrue;
4128 } 4128 }
4129 fetch_DocumentWidget_(d); 4129 fetch_DocumentWidget_(d);
4130 return iTrue; 4130 return iTrue;
@@ -4416,7 +4416,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
4416 if (argLabel_Command(cmd, "ttf")) { 4416 if (argLabel_Command(cmd, "ttf")) {
4417 iAssert(!cmp_String(&d->sourceMime, "font/ttf")); 4417 iAssert(!cmp_String(&d->sourceMime, "font/ttf"));
4418 installFontFile_Fonts(collect_String(suffix_Command(cmd, "name")), &d->sourceContent); 4418 installFontFile_Fonts(collect_String(suffix_Command(cmd, "name")), &d->sourceContent);
4419 postCommand_App("open url:about:fonts"); 4419 postCommand_App("open url:about:fonts");
4420 } 4420 }
4421 else { 4421 else {
4422 const iString *id = idFromUrl_FontPack(d->mod.url); 4422 const iString *id = idFromUrl_FontPack(d->mod.url);
@@ -5435,7 +5435,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
5435 init_Widget(w); 5435 init_Widget(w);
5436 setId_Widget(w, format_CStr("document%03d", ++docEnum_)); 5436 setId_Widget(w, format_CStr("document%03d", ++docEnum_));
5437 setFlags_Widget(w, hover_WidgetFlag | noBackground_WidgetFlag, iTrue); 5437 setFlags_Widget(w, hover_WidgetFlag | noBackground_WidgetFlag, iTrue);
5438#if defined (iPlatformAppleDesktop) 5438#if defined (iPlatformAppleDesktop)
5439 iBool enableSwipeNavigation = iTrue; /* swipes on the trackpad */ 5439 iBool enableSwipeNavigation = iTrue; /* swipes on the trackpad */
5440#else 5440#else
5441 iBool enableSwipeNavigation = (deviceType_App() != desktop_AppDeviceType); 5441 iBool enableSwipeNavigation = (deviceType_App() != desktop_AppDeviceType);
@@ -5671,7 +5671,7 @@ iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) {
5671void takeRequest_DocumentWidget(iDocumentWidget *d, iGmRequest *finishedRequest) { 5671void takeRequest_DocumentWidget(iDocumentWidget *d, iGmRequest *finishedRequest) {
5672 cancelRequest_DocumentWidget_(d, iFalse /* don't post anything */); 5672 cancelRequest_DocumentWidget_(d, iFalse /* don't post anything */);
5673 const iString *url = url_GmRequest(finishedRequest); 5673 const iString *url = url_GmRequest(finishedRequest);
5674 5674
5675 add_History(d->mod.history, url); 5675 add_History(d->mod.history, url);
5676 setUrl_DocumentWidget_(d, url); 5676 setUrl_DocumentWidget_(d, url);
5677 d->state = fetching_RequestState; 5677 d->state = fetching_RequestState;