summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2008-12-21 08:39:20 -0300
committercorvid <corvid@lavabit.com>2008-12-21 08:39:20 -0300
commit1e1f9f423355b880238b2b2b65e53221c66ecea2 (patch)
tree392ccb9839e791c0c8f257d13146b79d963c4b94 /src
parent197c6074b6b7ca6932e98872f412c3aa1bf550e4 (diff)
Added a popup menu to form's submit button
Diffstat (limited to 'src')
-rw-r--r--src/form.cc17
-rw-r--r--src/form.hh3
-rw-r--r--src/html.cc39
-rw-r--r--src/html.hh2
-rw-r--r--src/menu.cc63
-rw-r--r--src/menu.hh2
-rw-r--r--src/uicmd.cc8
-rw-r--r--src/uicmd.hh1
8 files changed, 132 insertions, 3 deletions
diff --git a/src/form.cc b/src/form.cc
index a36cd13a..219b3b5d 100644
--- a/src/form.cc
+++ b/src/form.cc
@@ -76,7 +76,6 @@ class DilloHtmlForm {
DilloHtml *html;
void eventHandler(Resource *resource, EventButton *event);
- void submit(DilloHtmlInput *active_input, EventButton *event);
DilloUrl *buildQueryUrl(DilloHtmlInput *active_input);
Dstr *buildQueryData(DilloHtmlInput *active_submit);
char *makeMultipartBoundary(iconv_t char_encoder,
@@ -113,6 +112,7 @@ public:
~DilloHtmlForm ();
DilloHtmlInput *getInput (Resource *resource);
DilloHtmlInput *getRadioInput (const char *name);
+ void submit(DilloHtmlInput *active_input, EventButton *event);
void reset ();
void addInput(DilloHtmlInput *input, DilloHtmlInputType type);
};
@@ -206,6 +206,16 @@ void a_Html_input_delete (DilloHtmlInput *input)
delete input;
}
+void a_Html_form_submit2(void *vform)
+{
+ ((DilloHtmlForm *)vform)->submit(NULL, NULL);
+}
+
+void a_Html_form_reset2(void *vform)
+{
+ ((DilloHtmlForm *)vform)->reset();
+}
+
/*
* Form parsing functions
*/
@@ -945,7 +955,7 @@ void DilloHtmlForm::eventHandler(Resource *resource, EventButton *event)
{
MSG("DilloHtmlForm::eventHandler\n");
if (event && (event->button == 3)) {
- MSG("Form menu\n");
+ a_UIcmd_form_popup(html->bw, html->page_url, this);
} else {
DilloHtmlInput *input = getInput(resource);
if (input) {
@@ -996,7 +1006,7 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input)
_MSG("DilloHtmlForm::buildQueryUrl: action=%s\n",URL_STR_(action));
- if (num_submit_buttons > 0) {
+ if (active_input && num_submit_buttons > 0) {
if ((active_input->type == DILLO_HTML_INPUT_SUBMIT) ||
(active_input->type == DILLO_HTML_INPUT_IMAGE) ||
(active_input->type == DILLO_HTML_INPUT_BUTTON_SUBMIT)) {
@@ -1727,6 +1737,7 @@ void DilloHtmlInput::reset ()
switch (type) {
case DILLO_HTML_INPUT_TEXT:
case DILLO_HTML_INPUT_PASSWORD:
+ case DILLO_HTML_INPUT_INDEX:
{
EntryResource *entryres = (EntryResource*)embed->getResource();
entryres->setText(init_str ? init_str : "");
diff --git a/src/form.hh b/src/form.hh
index 36616466..910efe20 100644
--- a/src/form.hh
+++ b/src/form.hh
@@ -38,6 +38,9 @@ DilloHtmlForm *a_Html_form_new(DilloHtml *html,
void a_Html_form_delete(DilloHtmlForm* form);
void a_Html_input_delete(DilloHtmlInput* input);
+void a_Html_form_submit2(void *v_form);
+void a_Html_form_reset2(void *v_form);
+
/*
* Form parsing functions
diff --git a/src/html.cc b/src/html.cc
index 1a252055..1c3652ba 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -219,6 +219,45 @@ void a_Html_load_images(void *v_html, DilloUrl *pattern)
}
/*
+ * Search for form
+ */
+static bool Html_contains_form(DilloHtml *html, void *v_form)
+{
+ for (int i = 0; i < html->forms->size(); i++) {
+ if (html->forms->get(i) == v_form) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/*
+ * Used by the "Submit form" form menuitem.
+ */
+void a_Html_form_submit(void *v_html, void *v_form)
+{
+ DilloHtml *html = (DilloHtml*)v_html;
+
+ if (Html_contains_form(html, v_form)) {
+ /* it's still valid */
+ a_Html_form_submit2(v_form);
+ }
+}
+
+/*
+ * Used by the "Reset form" form menuitem.
+ */
+void a_Html_form_reset(void *v_html, void *v_form)
+{
+ DilloHtml *html = (DilloHtml*)v_html;
+
+ if (Html_contains_form(html, v_form)) {
+ /* it's still valid */
+ a_Html_form_reset2(v_form);
+ }
+}
+
+/*
* Set the URL data for image maps.
*/
static void Html_set_link_coordinates(DilloHtml *html, int link, int x, int y)
diff --git a/src/html.hh b/src/html.hh
index 3e08f37a..b742261c 100644
--- a/src/html.hh
+++ b/src/html.hh
@@ -11,6 +11,8 @@ extern "C" {
* Exported functions
*/
void a_Html_load_images(void *v_html, DilloUrl *pattern);
+void a_Html_form_submit(void *v_html, void *v_form);
+void a_Html_form_reset(void *v_html, void *v_form);
#ifdef __cplusplus
}
diff --git a/src/menu.cc b/src/menu.cc
index ac23117d..9b75c422 100644
--- a/src/menu.cc
+++ b/src/menu.cc
@@ -212,6 +212,44 @@ static void Menu_load_images_cb(Widget*, void *user_data)
}
}
+/*
+ * Submit form
+ */
+static void Menu_form_submit_cb(Widget*, void *v_form)
+{
+ if (popup_bw && popup_bw->Docs) {
+ if (dList_find_custom(popup_bw->PageUrls, popup_url,
+ (dCompareFunc)a_Url_cmp)){
+ /* HTML page is still there */
+ int n = dList_length(popup_bw->Docs);
+ if (n == 1) {
+ a_Html_form_submit(dList_nth_data(popup_bw->Docs, 0), v_form);
+ } else if (n > 1) {
+ MSG ("Menu_form_submit_cb multiple Docs not implemented\n");
+ }
+ }
+ }
+}
+
+/*
+ * Reset form
+ */
+static void Menu_form_reset_cb(Widget*, void *v_form)
+{
+ if (popup_bw && popup_bw->Docs) {
+ if (dList_find_custom(popup_bw->PageUrls, popup_url,
+ (dCompareFunc)a_Url_cmp)){
+ /* HTML page is still there */
+ int n = dList_length(popup_bw->Docs);
+ if (n == 1) {
+ a_Html_form_reset(dList_nth_data(popup_bw->Docs, 0), v_form);
+ } else if (n > 1) {
+ MSG ("Menu_form_reset_cb multiple Docs not implemented\n");
+ }
+ }
+ }
+}
+
/*
* Validate URL with the W3C
*/
@@ -452,6 +490,31 @@ void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,
}
/*
+ * Form popup menu (construction & popup)
+ */
+void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url,
+ void *formptr)
+{
+ static PopupMenu *pm = 0;
+
+ popup_bw = bw;
+ a_Url_free(popup_url);
+ popup_url = a_Url_dup(page_url);
+ if (!pm) {
+ Item *i;
+ pm = new PopupMenu(0,0,0,0,"FORM OPTIONS");
+ pm->add(i = new Item("Submit form"));
+ i->callback(Menu_form_submit_cb);
+ pm->add(i = new Item("Reset form"));
+ i->callback(Menu_form_reset_cb);
+ pm->type(PopupMenu::POPUP123);
+ }
+ pm->user_data(formptr);
+
+ a_Timeout_add(0.0, Menu_popup_cb, (void *)pm);
+}
+
+/*
* File popup menu (construction & popup)
*/
void a_Menu_file_popup(BrowserWindow *bw, void *v_wid)
diff --git a/src/menu.hh b/src/menu.hh
index 9e8a73c6..2b30e47d 100644
--- a/src/menu.hh
+++ b/src/menu.hh
@@ -12,6 +12,8 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url,
void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url);
void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,
bool_t loaded_img, DilloUrl *link_url);
+void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url,
+ void *vform);
void a_Menu_file_popup(BrowserWindow *bw, void *v_wid);
void a_Menu_bugmeter_popup(BrowserWindow *bw, const DilloUrl *url);
void a_Menu_history_popup(BrowserWindow *bw, int direction);
diff --git a/src/uicmd.cc b/src/uicmd.cc
index 4484f059..f8869129 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -666,6 +666,14 @@ void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img,
}
/*
+ * Pop up the form menu
+ */
+void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform)
+{
+ a_Menu_form_popup((BrowserWindow*)vbw, url, vform);
+}
+
+/*
* Pop up the file menu
*/
void a_UIcmd_file_popup(void *vbw, void *v_wid)
diff --git a/src/uicmd.hh b/src/uicmd.hh
index c4e34736..3b5dc27e 100644
--- a/src/uicmd.hh
+++ b/src/uicmd.hh
@@ -41,6 +41,7 @@ void a_UIcmd_page_popup(void *vbw, const DilloUrl *url,
void a_UIcmd_link_popup(void *vbw, const DilloUrl *url);
void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img,
DilloUrl *link_url);
+void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform);
void a_UIcmd_file_popup(void *vbw, void *v_wid);
void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr);
void a_UIcmd_view_page_source(const DilloUrl *url);