From 47bf797864c07bf2f64bfea5a7ec56d45445e83e Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Sun, 7 Jun 2015 00:29:29 +0200
Subject: [PATCH] Added support for form with multiple submit buttons.
Forms with multiple submit buttons are rather rare but nevertheless the most popular web page (www.google.com) contains one with the two submit buttons "Google Search" and "I'm Feeling Lucky". So we want to support that - incl. the usual feature to the interpret first button as default button used when the user presses the ENTER key.
---
apps/webbrowser/www.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/apps/webbrowser/www.c b/apps/webbrowser/www.c
index 0aa433e85..3e84c7cb9 100644
--- a/apps/webbrowser/www.c
+++ b/apps/webbrowser/www.c
@@ -196,7 +196,7 @@ PROCESS(www_process, "Web browser");
AUTOSTART_PROCESSES(&www_process);
-static void CC_FASTCALL formsubmit(struct formattrib *form);
+static void CC_FASTCALL formsubmit(struct inputattrib *trigger);
/*-----------------------------------------------------------------------------------*/
/* make_window()
@@ -564,9 +564,8 @@ PROCESS_THREAD(www_process, ev, data)
#if WWW_CONF_FORMS
} else {
/* Assume form widget. */
- struct inputattrib *input = (struct inputattrib *)
- (((char *)w) - offsetof(struct inputattrib, widget));
- formsubmit(input->formptr);
+ formsubmit((struct inputattrib *)
+ (((char *)w) - offsetof(struct inputattrib, widget)));
#endif /* WWW_CONF_FORMS */
}
} else if(ev == ctk_signal_hyperlink_activate) {
@@ -964,23 +963,36 @@ add_query(char delimiter, char *string)
}
/*-----------------------------------------------------------------------------------*/
static void CC_FASTCALL
-formsubmit(struct formattrib *form)
+formsubmit(struct inputattrib *trigger)
{
- struct inputattrib *inputptr;
+ struct inputattrib *input;
+ struct formattrib *form = trigger->formptr;
char delimiter = ISO_questionmark;
set_link(form->action);
- for(inputptr = form->nextptr; inputptr != NULL; inputptr = inputptr->nextptr) {
+ /* No button pressed so prepare to look for default button. */
+ if(trigger->widget.type == CTK_WIDGET_TEXTENTRY) {
+ trigger = NULL;
+ }
+
+ for(input = form->nextptr; input != NULL; input = input->nextptr) {
char *name;
char *value;
- if(inputptr->widget.type == CTK_WIDGET_BUTTON) {
- name = ((struct submitattrib *)inputptr)->name;
- value = ((struct submitattrib *)inputptr)->button.text;
+ if(input->widget.type == CTK_WIDGET_TEXTENTRY) {
+ name = ((struct textattrib *)input)->name;
+ value = ((struct textattrib *)input)->textentry.text;
} else {
- name = ((struct textattrib *)inputptr)->name;
- value = ((struct textattrib *)inputptr)->textentry.text;
+ /* Consider first button as default button. */
+ if(trigger == NULL) {
+ trigger = input;
+ }
+ if(input != trigger) {
+ continue;
+ }
+ name = ((struct submitattrib *)input)->name;
+ value = ((struct submitattrib *)input)->button.text;
}
add_query(delimiter, name);