---
frontends/visurf/commands.c | 5 ++-
frontends/visurf/window.c | 68 +++++++++++++++++++++++++++++++++----
frontends/visurf/window.h | 2 +-
3 files changed, 64 insertions(+), 11 deletions(-)
diff --git a/frontends/visurf/commands.c b/frontends/visurf/commands.c
index 22d1cb46e..2541d7fbe 100644
--- a/frontends/visurf/commands.c
+++ b/frontends/visurf/commands.c
@@ -169,9 +169,8 @@ cmd_exline(struct nsvi_state *state, int argc, char *argv[])
static void
follow_collect_hints(struct gui_window *win, struct box *node, int x, int y)
{
- // TODO: Collect <input>, <button>, etc
struct follow_state *follow = &win->follow;
- if (node->href && node->width > 0 && node->height > 0) {
+ if ((node->href || node->gadget) && node->width > 0 && node->height > 0) {
if (!follow->hints) {
follow->hints = calloc(64, sizeof(struct link_hint));
follow->nhint = 0;
@@ -186,7 +185,7 @@ follow_collect_hints(struct gui_window *win, struct box *node, int x, int y)
hint->x = lroundf(scale * (x + node->x));
hint->y = lroundf(scale * (y + node->y));
hint->width = node->width, hint->height = node->height;
- hint->url = node->href;
+ hint->node = node;
++follow->nhint;
}
for (struct box *child = node->children; child; child = child->next) {
diff --git a/frontends/visurf/window.c b/frontends/visurf/window.c
index 3680ed43c..0aae8643d 100644
--- a/frontends/visurf/window.c
+++ b/frontends/visurf/window.c
@@ -27,6 +27,13 @@
#include "visurf/window.h"
#include "xdg-shell.h"
#include "xdg-decoration.h"
+#include "desktop/textarea.h"
+#include "content/handlers/html/form_internal.h"
+#include "content/handlers/html/private.h"
+#include "content/handlers/html/box.h"
+#include "content/handlers/html/interaction.h"
+
+#include <dom/dom.h>
struct pool_buffer *activebuffer;
@@ -1442,7 +1449,6 @@ nsvi_window_finish_hints(struct gui_window *gw)
free(follow->hintbuf);
follow->hints = NULL;
follow->nhint = 0;
- gw->window->mode = NORMAL;
request_frame(gw->window);
}
@@ -1452,24 +1458,71 @@ nsvi_window_follow_hint(struct nsvi_window *win, struct link_hint *hint)
nserror error = NSERROR_OK;
enum browser_window_create_flags flags = BW_CREATE_HISTORY | BW_CREATE_TAB;
struct gui_window *gw = win->tabs[win->tab];
- switch (gw->follow.mode) {
+ win->mode = NORMAL;
+ struct form_control *gadget = hint->node->gadget;
+ nsurl *url = hint->node->href;
+ assert(gadget || url);
+ if (gadget) {
+ switch (gadget->type) {
+ case GADGET_SELECT:
+ /* TODO select elements unimplemented in visurf */
+ break;
+ case GADGET_CHECKBOX:
+ gadget->selected = !gadget->selected;
+ dom_html_input_element_set_checked(
+ (dom_html_input_element *)(gadget->node),
+ gadget->selected);
+ break;
+ case GADGET_RADIO:
+ form_radio_set(gadget);
+ break;
+ case GADGET_IMAGE:
+ case GADGET_SUBMIT:
+ error = form_submit(content_get_url(
+ (struct content *) gadget->html),
+ gw->bw, gadget->form, gadget);
+ break;
+ case GADGET_TEXTBOX:
+ case GADGET_PASSWORD:
+ case GADGET_TEXTAREA:
+ html_set_focus(gadget->html, HTML_FOCUS_TEXTAREA,
+ (union html_focus_owner) hint->node,
+ false, 0, 0, 0, NULL);
+ textarea_set_caret(
+ gadget->data.text.ta, textarea_get_text(
+ gadget->data.text.ta, NULL, 0) - 1);
+ break;
+ case GADGET_HIDDEN:
+ /* not possible */
+ break;
+ case GADGET_RESET:
+ break;
+ case GADGET_FILE:
+ /* TODO file elements unimplemented in visurf */
+ break;
+ case GADGET_BUTTON:
+ /* This gadget cannot be activated */
+ break;
+ }
+
+ } else if (url) switch (gw->follow.mode) {
case FOLLOW_OPEN:
- error = browser_window_navigate(gw->bw, hint->url, NULL,
+ error = browser_window_navigate(gw->bw, url, NULL,
BW_NAVIGATE_HISTORY, NULL, NULL, NULL);
break;
case FOLLOW_OPEN_TAB:
if (!gw->follow.background) {
flags |= BW_CREATE_FOREGROUND;
}
- error = browser_window_create(flags, hint->url, NULL, gw->bw, NULL);
+ error = browser_window_create(flags, url, NULL, gw->bw, NULL);
break;
case FOLLOW_OPEN_WINDOW:
error = browser_window_create(BW_CREATE_HISTORY,
- hint->url, NULL, NULL, NULL);
+ url, NULL, NULL, NULL);
break;
case FOLLOW_YANK:
nsvi_set_clipboard(win->state, "text/plain",
- nsurl_access(hint->url), strlen(nsurl_access(hint->url)));
+ nsurl_access(url), strlen(nsurl_access(url)));
break;
case FOLLOW_YANK_PRIMARY:
// TODO
@@ -1478,7 +1531,7 @@ nsvi_window_follow_hint(struct nsvi_window *win, struct link_hint *hint)
if (error != NSERROR_OK) {
// TODO: Display error
- NSLOG(netsurf, ERROR, "Error navigating to URL");
+ NSLOG(netsurf, ERROR, "Error following hint");
}
nsvi_window_finish_hints(gw);
@@ -1497,6 +1550,7 @@ nsvi_window_handle_follow_key(struct nsvi_window *win,
win->state->xkb_state, keycode);
switch (sym) {
case XKB_KEY_Escape:
+ win->mode = NORMAL;
nsvi_window_finish_hints(win->tabs[win->tab]);
return;
}
diff --git a/frontends/visurf/window.h b/frontends/visurf/window.h
index 931786a08..63b088b17 100644
--- a/frontends/visurf/window.h
+++ b/frontends/visurf/window.h
@@ -121,7 +121,7 @@ struct link_hint {
int x, y;
int width, height;
char *hint;
- nsurl *url;
+ struct box *node;
};
struct follow_state {
--
2.35.1
Nice work, thanks!
To git@git.sr.ht:~sircmpwn/visurf
7de863576..14d9df0a4 master -> master