summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/documentwidget.c104
1 files changed, 9 insertions, 95 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 2466675e..3bb66be6 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -47,13 +47,8 @@ void init_DocumentWidget(iDocumentWidget *d) {
47 setId_Widget(w, "document"); 47 setId_Widget(w, "document");
48 d->state = blank_DocumentState; 48 d->state = blank_DocumentState;
49 d->url = new_String(); 49 d->url = new_String();
50// d->statusCode = 0;
51 d->request = NULL; 50 d->request = NULL;
52 d->isSourcePending = iFalse; 51 d->isSourcePending = iFalse;
53// d->requestTimeout = 0;
54// d->readPending = iFalse;
55// d->newSource = new_String();
56// d->needSourceUpdate = iFalse;
57 d->doc = new_GmDocument(); 52 d->doc = new_GmDocument();
58 d->pageMargin = 5; 53 d->pageMargin = 5;
59 d->scrollY = 0; 54 d->scrollY = 0;
@@ -66,7 +61,6 @@ void init_DocumentWidget(iDocumentWidget *d) {
66void deinit_DocumentWidget(iDocumentWidget *d) { 61void deinit_DocumentWidget(iDocumentWidget *d) {
67 deinit_PtrArray(&d->visibleLinks); 62 deinit_PtrArray(&d->visibleLinks);
68 delete_String(d->url); 63 delete_String(d->url);
69// delete_String(d->newSource);
70 iRelease(d->request); 64 iRelease(d->request);
71 iRelease(d->doc); 65 iRelease(d->doc);
72} 66}
@@ -95,38 +89,6 @@ static iRangecc getLine_(iRangecc text) {
95} 89}
96 90
97static void requestUpdated_DocumentWidget_(iAnyObject *obj) { 91static void requestUpdated_DocumentWidget_(iAnyObject *obj) {
98#if 0
99 iDocumentWidget *d = obj;
100 iBlock *response = readAll_TlsRequest(d->request);
101 if (d->state == fetching_DocumentState) {
102 iRangecc responseRange = { constBegin_Block(response), constEnd_Block(response) };
103 iRangecc respLine = getLine_(responseRange);
104 responseRange.start = respLine.end + 1;
105 /* First line is the status code. */ {
106 iString *line = newRange_String(respLine);
107 trim_String(line);
108 d->statusCode = toInt_String(line);
109 printf("response (%02d): %s\n", d->statusCode, cstr_String(line));
110 /* TODO: post a command with the status code */
111 switch (d->statusCode) {
112 case redirectPermanent_GmStatusCode:
113 case redirectTemporary_GmStatusCode:
114 postCommandf_App("open url:%s", cstr_String(line) + 3);
115 break;
116 }
117 delete_String(line);
118 }
119 setCStrN_String(d->newSource, responseRange.start, size_Range(&responseRange));
120 d->requestTimeout = SDL_AddTimer(2000, requestTimedOut_DocumentWidget_, d);
121 d->state = receivedPartialResponse_DocumentState;
122 }
123 else if (d->state == receivedPartialResponse_DocumentState) {
124 appendCStr_String(d->newSource, cstr_Block(response));
125 d->needSourceUpdate = iTrue;
126 }
127 delete_Block(response);
128 refresh_Widget(as_Widget(d));
129#endif
130 iDocumentWidget *d = obj; 92 iDocumentWidget *d = obj;
131 const int wasPending = exchange_Atomic(&d->isSourcePending, iTrue); 93 const int wasPending = exchange_Atomic(&d->isSourcePending, iTrue);
132 if (!wasPending) { 94 if (!wasPending) {
@@ -136,14 +98,6 @@ static void requestUpdated_DocumentWidget_(iAnyObject *obj) {
136 98
137static void requestFinished_DocumentWidget_(iAnyObject *obj) { 99static void requestFinished_DocumentWidget_(iAnyObject *obj) {
138 iDocumentWidget *d = obj; 100 iDocumentWidget *d = obj;
139 /*
140 iReleaseLater(d->request);
141 d->request = NULL;
142 if (d->requestTimeout) {
143 SDL_RemoveTimer(d->requestTimeout);
144 d->requestTimeout = 0;
145 }
146 refresh_Widget(constAs_Widget(d));*/
147 postCommand_Widget(obj, "document.request.finished request:%p", d->request); 101 postCommand_Widget(obj, "document.request.finished request:%p", d->request);
148} 102}
149 103
@@ -178,22 +132,14 @@ static void updateVisible_DocumentWidget_(iDocumentWidget *d) {
178} 132}
179 133
180static void updateSource_DocumentWidget_(iDocumentWidget *d) { 134static void updateSource_DocumentWidget_(iDocumentWidget *d) {
181 /* Update the document? */
182 // if (d->needSourceUpdate) {
183 /* TODO: Do this in the background. However, that requires a text metrics calculator 135 /* TODO: Do this in the background. However, that requires a text metrics calculator
184 that does not try to cache the glyph bitmaps. */ 136 that does not try to cache the glyph bitmaps. */
185 iString str; 137 iString str;
186 initBlock_String(&str, body_GmRequest(d->request)); 138 initBlock_String(&str, body_GmRequest(d->request));
187 setSource_GmDocument(d->doc, &str, documentWidth_DocumentWidget_(d)); 139 setSource_GmDocument(d->doc, &str, documentWidth_DocumentWidget_(d));
188 deinit_String(&str); 140 deinit_String(&str);
189 updateVisible_DocumentWidget_(d); 141 updateVisible_DocumentWidget_(d);
190 refresh_Widget(as_Widget(d)); 142 refresh_Widget(as_Widget(d));
191 // d->state = ready_DocumentState;
192 // if (!d->request) {
193 // d->needSourceUpdate = iFalse;
194 // postCommandf_App("document.changed url:%s", cstr_String(d->url));
195 // }
196 // }
197} 143}
198 144
199static void fetch_DocumentWidget_(iDocumentWidget *d) { 145static void fetch_DocumentWidget_(iDocumentWidget *d) {
@@ -294,45 +240,6 @@ static const iString *absoluteUrl_DocumentWidget_(const iDocumentWidget *d, cons
294 return collect_String(absolute); 240 return collect_String(absolute);
295} 241}
296 242
297static void readResponse_DocumentWidget_(iDocumentWidget *d) {
298#if 0
299 d->readPending = iFalse;
300 iBlock *response = collect_Block(readAll_TlsRequest(d->request));
301 if (isEmpty_Block(response)) {
302 return;
303 }
304 if (d->state == fetching_DocumentState) {
305 /* TODO: Bug here is that the first read may occur before the first line is
306 available, so nothing gets done. Should ensure that the status code is
307 read successully. */
308 iRangecc responseRange = { constBegin_Block(response), constEnd_Block(response) };
309 iRangecc respLine = getLine_(responseRange);
310 responseRange.start = respLine.end + 1;
311 /* First line is the status code. */ {
312 iString *line = collect_String(newRange_String(respLine));
313 trim_String(line);
314 d->statusCode = toInt_String(line);
315 printf("response (%02d): %s\n", d->statusCode, cstr_String(line));
316 /* TODO: post a command with the status code */
317 switch (d->statusCode) {
318 case redirectPermanent_GmStatusCode:
319 case redirectTemporary_GmStatusCode:
320 postCommandf_App("open url:%s", cstr_String(line) + 3);
321 return;
322 }
323 }
324 setCStrN_String(d->newSource, responseRange.start, size_Range(&responseRange));
325 d->requestTimeout = SDL_AddTimer(2000, requestTimedOut_DocumentWidget_, d);
326 d->state = receivedPartialResponse_DocumentState;
327 d->scrollY = 0;
328 }
329 else if (d->state == receivedPartialResponse_DocumentState) {
330 appendCStr_String(d->newSource, cstr_Block(response));
331 }
332#endif
333 updateSource_DocumentWidget_(d);
334}
335
336static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { 243static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) {
337 if (d->state == fetching_DocumentState) { 244 if (d->state == fetching_DocumentState) {
338 d->state = receivedPartialResponse_DocumentState; 245 d->state = receivedPartialResponse_DocumentState;
@@ -395,6 +302,14 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
395 updateVisible_DocumentWidget_(d); 302 updateVisible_DocumentWidget_(d);
396 refresh_Widget(w); 303 refresh_Widget(w);
397 return iTrue; 304 return iTrue;
305 case SDLK_UP:
306 case SDLK_DOWN:
307 if (mods == 0) {
308 scroll_DocumentWidget_(d, 2 * lineHeight_Text(paragraph_FontId) *
309 (key == SDLK_UP ? -1 : 1));
310 return iTrue;
311 }
312 break;
398 case SDLK_PAGEUP: 313 case SDLK_PAGEUP:
399 case SDLK_PAGEDOWN: 314 case SDLK_PAGEDOWN:
400 case ' ': 315 case ' ':
@@ -485,7 +400,6 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
485 iDrawContext ctx = { .widget = d, .bounds = documentBounds_DocumentWidget_(d) }; 400 iDrawContext ctx = { .widget = d, .bounds = documentBounds_DocumentWidget_(d) };
486 init_Paint(&ctx.paint); 401 init_Paint(&ctx.paint);
487 fillRect_Paint(&ctx.paint, bounds, gray25_ColorId); 402 fillRect_Paint(&ctx.paint, bounds, gray25_ColorId);
488// if (d->state != ready_DocumentState) return;
489 setClip_Paint(&ctx.paint, bounds); 403 setClip_Paint(&ctx.paint, bounds);
490 render_GmDocument(d->doc, visibleRange_DocumentWidget_(d), drawRun_DrawContext_, &ctx); 404 render_GmDocument(d->doc, visibleRange_DocumentWidget_(d), drawRun_DrawContext_, &ctx);
491 clearClip_Paint(&ctx.paint); 405 clearClip_Paint(&ctx.paint);