summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c17
-rw-r--r--src/ui/documentwidget.h3
-rw-r--r--src/ui/labelwidget.c2
-rw-r--r--src/ui/window.c26
4 files changed, 46 insertions, 2 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 4cd0ac18..030a323b 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -148,6 +148,7 @@ static void fetch_DocumentWidget_(iDocumentWidget *d) {
148 iRelease(d->request); 148 iRelease(d->request);
149 d->request = NULL; 149 d->request = NULL;
150 } 150 }
151 postCommand_Widget(as_Widget(d), "document.request.started");
151 d->state = fetching_DocumentState; 152 d->state = fetching_DocumentState;
152 set_Atomic(&d->isSourcePending, iFalse); 153 set_Atomic(&d->isSourcePending, iFalse);
153 d->request = new_GmRequest(); 154 d->request = new_GmRequest();
@@ -171,6 +172,10 @@ void setUrl_DocumentWidget(iDocumentWidget *d, const iString *url) {
171 delete_String(newUrl); 172 delete_String(newUrl);
172} 173}
173 174
175iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) {
176 return d->state == fetching_DocumentState || d->state == receivedPartialResponse_DocumentState;
177}
178
174static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) { 179static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) {
175 d->scrollY += offset; 180 d->scrollY += offset;
176 if (d->scrollY < 0) { 181 if (d->scrollY < 0) {
@@ -278,6 +283,18 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
278 postCommandf_App("document.changed url:%s", cstr_String(d->url)); 283 postCommandf_App("document.changed url:%s", cstr_String(d->url));
279 return iTrue; 284 return iTrue;
280 } 285 }
286 else if (isCommand_UserEvent(ev, "document.stop")) {
287 if (d->request) {
288 postCommandf_App("document.request.cancelled url:%s", cstr_String(d->url));
289 iReleasePtr(&d->request);
290 d->state = ready_DocumentState;
291 }
292 return iTrue;
293 }
294 else if (isCommand_UserEvent(ev, "document.reload")) {
295 fetch_DocumentWidget_(d);
296 return iTrue;
297 }
281 else if (isCommand_Widget(w, ev, "scroll.moved")) { 298 else if (isCommand_Widget(w, ev, "scroll.moved")) {
282 d->scrollY = arg_Command(command_UserEvent(ev)); 299 d->scrollY = arg_Command(command_UserEvent(ev));
283 updateVisible_DocumentWidget_(d); 300 updateVisible_DocumentWidget_(d);
diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h
index 02b75e69..dfd342af 100644
--- a/src/ui/documentwidget.h
+++ b/src/ui/documentwidget.h
@@ -5,4 +5,5 @@
5iDeclareWidgetClass(DocumentWidget) 5iDeclareWidgetClass(DocumentWidget)
6iDeclareObjectConstruction(DocumentWidget) 6iDeclareObjectConstruction(DocumentWidget)
7 7
8void setUrl_DocumentWidget (iDocumentWidget *d, const iString *url); 8void setUrl_DocumentWidget (iDocumentWidget *, const iString *url);
9iBool isRequestOngoing_DocumentWidget (const iDocumentWidget *);
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index 341c2f0e..f24e2573 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -264,10 +264,12 @@ void setText_LabelWidget(iLabelWidget *d, const iString *text) {
264 264
265void updateText_LabelWidget(iLabelWidget *d, const iString *text) { 265void updateText_LabelWidget(iLabelWidget *d, const iString *text) {
266 set_String(&d->label, text); 266 set_String(&d->label, text);
267 refresh_Widget(&d->widget);
267} 268}
268 269
269void updateTextCStr_LabelWidget(iLabelWidget *d, const char *text) { 270void updateTextCStr_LabelWidget(iLabelWidget *d, const char *text) {
270 setCStr_String(&d->label, text); 271 setCStr_String(&d->label, text);
272 refresh_Widget(&d->widget);
271} 273}
272 274
273void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) { 275void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) {
diff --git a/src/ui/window.c b/src/ui/window.c
index 8236b9e6..6196a638 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -74,6 +74,9 @@ static const iMenuItem editMenuItems[] = {
74static const iMenuItem viewMenuItems[] = { 74static const iMenuItem viewMenuItems[] = {
75}; 75};
76 76
77static const char *reloadCStr_ = "\u25cb";
78static const char *stopCStr_ = orange_ColorEscape "\u00d7";
79
77static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { 80static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
78 if (equal_Command(cmd, "input.ended")) { 81 if (equal_Command(cmd, "input.ended")) {
79 iInputWidget *url = findChild_Widget(navBar, "url"); 82 iInputWidget *url = findChild_Widget(navBar, "url");
@@ -88,8 +91,27 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
88 iInputWidget *url = findWidget_App("url"); 91 iInputWidget *url = findWidget_App("url");
89 setTextCStr_InputWidget(url, valuePtr_Command(cmd, "url")); 92 setTextCStr_InputWidget(url, valuePtr_Command(cmd, "url"));
90 setTitle_Window(get_Window(), text_InputWidget(url)); 93 setTitle_Window(get_Window(), text_InputWidget(url));
94 updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), reloadCStr_);
95 return iFalse;
96 }
97 else if (equal_Command(cmd, "document.request.cancelled")) {
98 updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), reloadCStr_);
91 return iFalse; 99 return iFalse;
92 } 100 }
101 else if (equal_Command(cmd, "document.request.started")) {
102 updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), stopCStr_);
103 return iFalse;
104 }
105 else if (equal_Command(cmd, "navigate.reload")) {
106 iDocumentWidget *doc = findWidget_App("document");
107 if (isRequestOngoing_DocumentWidget(doc)) {
108 postCommand_App("document.stop");
109 }
110 else {
111 postCommand_App("document.reload");
112 }
113 return iTrue;
114 }
93 return iFalse; 115 return iFalse;
94} 116}
95 117
@@ -120,7 +142,9 @@ static void setupUserInterface_Window(iWindow *d) {
120 setId_Widget(as_Widget(url), "url"); 142 setId_Widget(as_Widget(url), "url");
121 setTextCStr_InputWidget(url, "gemini://"); 143 setTextCStr_InputWidget(url, "gemini://");
122 addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); 144 addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag);
123 addChild_Widget(navBar, iClob(new_LabelWidget("x", 0, 0, "navigate.reload"))); 145 setId_Widget(
146 addChild_Widget(navBar, iClob(new_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))),
147 "reload");
124 } 148 }
125 149
126 addChildFlags_Widget(div, iClob(new_DocumentWidget()), expand_WidgetFlag); 150 addChildFlags_Widget(div, iClob(new_DocumentWidget()), expand_WidgetFlag);