diff options
-rw-r--r-- | src/ui/documentwidget.c | 29 | ||||
-rw-r--r-- | src/ui/inputwidget.c | 27 | ||||
-rw-r--r-- | src/ui/inputwidget.h | 1 |
3 files changed, 37 insertions, 20 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 9fdadc4c..29f880ee 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "documentwidget.h" | 1 | #include "documentwidget.h" |
2 | #include "scrollwidget.h" | 2 | #include "scrollwidget.h" |
3 | #include "inputwidget.h" | ||
3 | #include "paint.h" | 4 | #include "paint.h" |
4 | #include "command.h" | 5 | #include "command.h" |
5 | #include "util.h" | 6 | #include "util.h" |
@@ -38,7 +39,6 @@ struct Impl_DocumentWidget { | |||
38 | iClick click; | 39 | iClick click; |
39 | iScrollWidget *scroll; | 40 | iScrollWidget *scroll; |
40 | iWidget *menu; | 41 | iWidget *menu; |
41 | // iWidget *userInput; | ||
42 | }; | 42 | }; |
43 | 43 | ||
44 | iDefineObjectConstruction(DocumentWidget) | 44 | iDefineObjectConstruction(DocumentWidget) |
@@ -65,7 +65,6 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
65 | { "---", 0, 0, NULL }, | 65 | { "---", 0, 0, NULL }, |
66 | { "Reload", 'r', KMOD_PRIMARY, "navigate.reload" } }, | 66 | { "Reload", 'r', KMOD_PRIMARY, "navigate.reload" } }, |
67 | 4); | 67 | 4); |
68 | // setFlags_Widget(d->userInput, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); | ||
69 | } | 68 | } |
70 | 69 | ||
71 | void deinit_DocumentWidget(iDocumentWidget *d) { | 70 | void deinit_DocumentWidget(iDocumentWidget *d) { |
@@ -293,10 +292,14 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode | |||
293 | } | 292 | } |
294 | 293 | ||
295 | static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | 294 | static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { |
295 | if (!d->request) { | ||
296 | return; | ||
297 | } | ||
296 | if (d->state == fetching_DocumentState) { | 298 | if (d->state == fetching_DocumentState) { |
297 | d->state = receivedPartialResponse_DocumentState; | 299 | d->state = receivedPartialResponse_DocumentState; |
298 | d->scrollY = 0; | 300 | d->scrollY = 0; |
299 | switch (status_GmRequest(d->request)) { | 301 | enum iGmStatusCode statusCode = status_GmRequest(d->request); |
302 | switch (statusCode) { | ||
300 | case none_GmStatusCode: | 303 | case none_GmStatusCode: |
301 | case success_GmStatusCode: | 304 | case success_GmStatusCode: |
302 | break; | 305 | break; |
@@ -304,7 +307,7 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | |||
304 | case sensitiveInput_GmStatusCode: { | 307 | case sensitiveInput_GmStatusCode: { |
305 | iUrl parts; | 308 | iUrl parts; |
306 | init_Url(&parts, d->url); | 309 | init_Url(&parts, d->url); |
307 | makeValueInput_Widget( | 310 | iWidget *dlg = makeValueInput_Widget( |
308 | as_Widget(d), | 311 | as_Widget(d), |
309 | NULL, | 312 | NULL, |
310 | cstrFormat_String(cyan_ColorEscape "%s", | 313 | cstrFormat_String(cyan_ColorEscape "%s", |
@@ -316,6 +319,8 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | |||
316 | : cstr_String(meta_GmRequest(d->request)), | 319 | : cstr_String(meta_GmRequest(d->request)), |
317 | orange_ColorEscape "Send \u21d2", | 320 | orange_ColorEscape "Send \u21d2", |
318 | "document.input.submit"); | 321 | "document.input.submit"); |
322 | setSensitive_InputWidget(findChild_Widget(dlg, "input"), | ||
323 | statusCode == sensitiveInput_GmStatusCode); | ||
319 | break; | 324 | break; |
320 | } | 325 | } |
321 | case redirectTemporary_GmStatusCode: | 326 | case redirectTemporary_GmStatusCode: |
@@ -324,12 +329,13 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | |||
324 | showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode); | 329 | showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode); |
325 | } | 330 | } |
326 | else { | 331 | else { |
327 | postCommandf_App("open redirect:1 url:%s", cstr_String(meta_GmRequest(d->request))); | 332 | postCommandf_App("open redirect:1 url:%s", |
333 | cstr_String(meta_GmRequest(d->request))); | ||
328 | iReleasePtr(&d->request); | 334 | iReleasePtr(&d->request); |
329 | } | 335 | } |
330 | break; | 336 | break; |
331 | default: | 337 | default: |
332 | showErrorPage_DocumentWidget_(d, status_GmRequest(d->request)); | 338 | showErrorPage_DocumentWidget_(d, statusCode); |
333 | break; | 339 | break; |
334 | } | 340 | } |
335 | } | 341 | } |
@@ -411,17 +417,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
411 | updateVisible_DocumentWidget_(d); | 417 | updateVisible_DocumentWidget_(d); |
412 | refresh_Widget(w); | 418 | refresh_Widget(w); |
413 | return iTrue; | 419 | return iTrue; |
414 | #if 0 | ||
415 | case 't': | ||
416 | if (mods == KMOD_PRIMARY) { | ||
417 | makeValueInput_Widget(get_Window()->root, | ||
418 | NULL, | ||
419 | cyan_ColorEscape "Input Needed", | ||
420 | "Give it!", | ||
421 | "document.input.submit"); | ||
422 | } | ||
423 | return iTrue; | ||
424 | #endif | ||
425 | case SDLK_END: | 420 | case SDLK_END: |
426 | d->scrollY = scrollMax_DocumentWidget_(d); | 421 | d->scrollY = scrollMax_DocumentWidget_(d); |
427 | updateVisible_DocumentWidget_(d); | 422 | updateVisible_DocumentWidget_(d); |
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 6c05dbd1..19623d74 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -11,6 +11,7 @@ static const int REFRESH_INTERVAL = 256; | |||
11 | struct Impl_InputWidget { | 11 | struct Impl_InputWidget { |
12 | iWidget widget; | 12 | iWidget widget; |
13 | enum iInputMode mode; | 13 | enum iInputMode mode; |
14 | iBool isSensitive; | ||
14 | size_t maxLen; | 15 | size_t maxLen; |
15 | iArray text; /* iChar[] */ | 16 | iArray text; /* iChar[] */ |
16 | iArray oldText; /* iChar[] */ | 17 | iArray oldText; /* iChar[] */ |
@@ -30,6 +31,7 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { | |||
30 | init_Array(&d->oldText, sizeof(iChar)); | 31 | init_Array(&d->oldText, sizeof(iChar)); |
31 | d->font = uiInput_FontId; | 32 | d->font = uiInput_FontId; |
32 | d->cursor = 0; | 33 | d->cursor = 0; |
34 | d->isSensitive = iFalse; | ||
33 | setMaxLen_InputWidget(d, maxLen); | 35 | setMaxLen_InputWidget(d, maxLen); |
34 | if (maxLen == 0) { | 36 | if (maxLen == 0) { |
35 | /* Caller must arrange the width. */ | 37 | /* Caller must arrange the width. */ |
@@ -52,6 +54,10 @@ void setMode_InputWidget(iInputWidget *d, enum iInputMode mode) { | |||
52 | d->mode = mode; | 54 | d->mode = mode; |
53 | } | 55 | } |
54 | 56 | ||
57 | void setSensitive_InputWidget(iInputWidget *d, iBool isSensitive) { | ||
58 | d->isSensitive = isSensitive; | ||
59 | } | ||
60 | |||
55 | const iString *text_InputWidget(const iInputWidget *d) { | 61 | const iString *text_InputWidget(const iInputWidget *d) { |
56 | return collect_String(newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text))); | 62 | return collect_String(newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text))); |
57 | } | 63 | } |
@@ -277,17 +283,27 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
277 | return processEvent_Widget(w, ev); | 283 | return processEvent_Widget(w, ev); |
278 | } | 284 | } |
279 | 285 | ||
286 | static const iChar sensitiveChar_ = 0x25cf; /* black circle */ | ||
287 | |||
280 | static void draw_InputWidget_(const iInputWidget *d) { | 288 | static void draw_InputWidget_(const iInputWidget *d) { |
281 | const uint32_t time = frameTime_Window(get_Window()); | 289 | const uint32_t time = frameTime_Window(get_Window()); |
282 | const iInt2 padding = init_I2(gap_UI / 2, gap_UI / 2); | 290 | const iInt2 padding = init_I2(gap_UI / 2, gap_UI / 2); |
283 | iRect bounds = adjusted_Rect(bounds_Widget(constAs_Widget(d)), padding, neg_I2(padding)); | 291 | iRect bounds = adjusted_Rect(bounds_Widget(constAs_Widget(d)), padding, neg_I2(padding)); |
284 | const iBool isFocused = isFocused_Widget(constAs_Widget(d)); | 292 | const iBool isFocused = isFocused_Widget(constAs_Widget(d)); |
285 | const iBool isHover = isHover_Widget(constAs_Widget(d)) && | 293 | const iBool isHover = isHover_Widget(constAs_Widget(d)) && |
286 | contains_Widget(constAs_Widget(d), mouseCoord_Window(get_Window())); | 294 | contains_Widget(constAs_Widget(d), mouseCoord_Window(get_Window())); |
287 | iPaint p; | 295 | iPaint p; |
288 | init_Paint(&p); | 296 | init_Paint(&p); |
289 | iString text; | 297 | iString text; |
290 | initUnicodeN_String(&text, constData_Array(&d->text), size_Array(&d->text)); | 298 | if (!d->isSensitive) { |
299 | initUnicodeN_String(&text, constData_Array(&d->text), size_Array(&d->text)); | ||
300 | } | ||
301 | else { | ||
302 | init_String(&text); | ||
303 | for (size_t i = 0; i < size_Array(&d->text); ++i) { | ||
304 | appendChar_String(&text, sensitiveChar_); | ||
305 | } | ||
306 | } | ||
291 | fillRect_Paint(&p, bounds, black_ColorId); | 307 | fillRect_Paint(&p, bounds, black_ColorId); |
292 | drawRect_Paint(&p, | 308 | drawRect_Paint(&p, |
293 | adjusted_Rect(bounds, neg_I2(one_I2()), zero_I2()), | 309 | adjusted_Rect(bounds, neg_I2(one_I2()), zero_I2()), |
@@ -322,7 +338,12 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
322 | const iRect curRect = { curPos, addX_I2(emSize, 1) }; | 338 | const iRect curRect = { curPos, addX_I2(emSize, 1) }; |
323 | iString cur; | 339 | iString cur; |
324 | if (d->cursor < size_Array(&d->text)) { | 340 | if (d->cursor < size_Array(&d->text)) { |
325 | initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); | 341 | if (!d->isSensitive) { |
342 | initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); | ||
343 | } | ||
344 | else { | ||
345 | initUnicodeN_String(&cur, &sensitiveChar_, 1); | ||
346 | } | ||
326 | } | 347 | } |
327 | else { | 348 | else { |
328 | initCStr_String(&cur, " "); | 349 | initCStr_String(&cur, " "); |
diff --git a/src/ui/inputwidget.h b/src/ui/inputwidget.h index 6ee2760d..903e428a 100644 --- a/src/ui/inputwidget.h +++ b/src/ui/inputwidget.h | |||
@@ -10,6 +10,7 @@ enum iInputMode { | |||
10 | overwrite_InputMode, | 10 | overwrite_InputMode, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | void setSensitive_InputWidget(iInputWidget *, iBool isSensitive); | ||
13 | void setMode_InputWidget (iInputWidget *, enum iInputMode mode); | 14 | void setMode_InputWidget (iInputWidget *, enum iInputMode mode); |
14 | void setMaxLen_InputWidget (iInputWidget *, size_t maxLen); | 15 | void setMaxLen_InputWidget (iInputWidget *, size_t maxLen); |
15 | void setText_InputWidget (iInputWidget *, const iString *text); | 16 | void setText_InputWidget (iInputWidget *, const iString *text); |