From 3d60806534f5fd20e321a1290f3942215dcf1121 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 26 Jul 2020 14:49:06 +0300 Subject: Asking for sensitive input --- src/ui/documentwidget.c | 29 ++++++++++++----------------- src/ui/inputwidget.c | 27 ++++++++++++++++++++++++--- src/ui/inputwidget.h | 1 + 3 files changed, 37 insertions(+), 20 deletions(-) (limited to 'src') 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 @@ #include "documentwidget.h" #include "scrollwidget.h" +#include "inputwidget.h" #include "paint.h" #include "command.h" #include "util.h" @@ -38,7 +39,6 @@ struct Impl_DocumentWidget { iClick click; iScrollWidget *scroll; iWidget *menu; -// iWidget *userInput; }; iDefineObjectConstruction(DocumentWidget) @@ -65,7 +65,6 @@ void init_DocumentWidget(iDocumentWidget *d) { { "---", 0, 0, NULL }, { "Reload", 'r', KMOD_PRIMARY, "navigate.reload" } }, 4); -// setFlags_Widget(d->userInput, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); } void deinit_DocumentWidget(iDocumentWidget *d) { @@ -293,10 +292,14 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode } static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { + if (!d->request) { + return; + } if (d->state == fetching_DocumentState) { d->state = receivedPartialResponse_DocumentState; d->scrollY = 0; - switch (status_GmRequest(d->request)) { + enum iGmStatusCode statusCode = status_GmRequest(d->request); + switch (statusCode) { case none_GmStatusCode: case success_GmStatusCode: break; @@ -304,7 +307,7 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { case sensitiveInput_GmStatusCode: { iUrl parts; init_Url(&parts, d->url); - makeValueInput_Widget( + iWidget *dlg = makeValueInput_Widget( as_Widget(d), NULL, cstrFormat_String(cyan_ColorEscape "%s", @@ -316,6 +319,8 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { : cstr_String(meta_GmRequest(d->request)), orange_ColorEscape "Send \u21d2", "document.input.submit"); + setSensitive_InputWidget(findChild_Widget(dlg, "input"), + statusCode == sensitiveInput_GmStatusCode); break; } case redirectTemporary_GmStatusCode: @@ -324,12 +329,13 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode); } else { - postCommandf_App("open redirect:1 url:%s", cstr_String(meta_GmRequest(d->request))); + postCommandf_App("open redirect:1 url:%s", + cstr_String(meta_GmRequest(d->request))); iReleasePtr(&d->request); } break; default: - showErrorPage_DocumentWidget_(d, status_GmRequest(d->request)); + showErrorPage_DocumentWidget_(d, statusCode); break; } } @@ -411,17 +417,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e updateVisible_DocumentWidget_(d); refresh_Widget(w); return iTrue; -#if 0 - case 't': - if (mods == KMOD_PRIMARY) { - makeValueInput_Widget(get_Window()->root, - NULL, - cyan_ColorEscape "Input Needed", - "Give it!", - "document.input.submit"); - } - return iTrue; -#endif case SDLK_END: d->scrollY = scrollMax_DocumentWidget_(d); 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; struct Impl_InputWidget { iWidget widget; enum iInputMode mode; + iBool isSensitive; size_t maxLen; iArray text; /* iChar[] */ iArray oldText; /* iChar[] */ @@ -30,6 +31,7 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { init_Array(&d->oldText, sizeof(iChar)); d->font = uiInput_FontId; d->cursor = 0; + d->isSensitive = iFalse; setMaxLen_InputWidget(d, maxLen); if (maxLen == 0) { /* Caller must arrange the width. */ @@ -52,6 +54,10 @@ void setMode_InputWidget(iInputWidget *d, enum iInputMode mode) { d->mode = mode; } +void setSensitive_InputWidget(iInputWidget *d, iBool isSensitive) { + d->isSensitive = isSensitive; +} + const iString *text_InputWidget(const iInputWidget *d) { return collect_String(newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text))); } @@ -277,17 +283,27 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { return processEvent_Widget(w, ev); } +static const iChar sensitiveChar_ = 0x25cf; /* black circle */ + static void draw_InputWidget_(const iInputWidget *d) { const uint32_t time = frameTime_Window(get_Window()); const iInt2 padding = init_I2(gap_UI / 2, gap_UI / 2); iRect bounds = adjusted_Rect(bounds_Widget(constAs_Widget(d)), padding, neg_I2(padding)); const iBool isFocused = isFocused_Widget(constAs_Widget(d)); const iBool isHover = isHover_Widget(constAs_Widget(d)) && - contains_Widget(constAs_Widget(d), mouseCoord_Window(get_Window())); + contains_Widget(constAs_Widget(d), mouseCoord_Window(get_Window())); iPaint p; init_Paint(&p); iString text; - initUnicodeN_String(&text, constData_Array(&d->text), size_Array(&d->text)); + if (!d->isSensitive) { + initUnicodeN_String(&text, constData_Array(&d->text), size_Array(&d->text)); + } + else { + init_String(&text); + for (size_t i = 0; i < size_Array(&d->text); ++i) { + appendChar_String(&text, sensitiveChar_); + } + } fillRect_Paint(&p, bounds, black_ColorId); drawRect_Paint(&p, adjusted_Rect(bounds, neg_I2(one_I2()), zero_I2()), @@ -322,7 +338,12 @@ static void draw_InputWidget_(const iInputWidget *d) { const iRect curRect = { curPos, addX_I2(emSize, 1) }; iString cur; if (d->cursor < size_Array(&d->text)) { - initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); + if (!d->isSensitive) { + initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); + } + else { + initUnicodeN_String(&cur, &sensitiveChar_, 1); + } } else { 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 { overwrite_InputMode, }; +void setSensitive_InputWidget(iInputWidget *, iBool isSensitive); void setMode_InputWidget (iInputWidget *, enum iInputMode mode); void setMaxLen_InputWidget (iInputWidget *, size_t maxLen); void setText_InputWidget (iInputWidget *, const iString *text); -- cgit v1.2.3