2003-10-25 04:35:49 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
2009-08-14 14:37:33 +04:00
|
|
|
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-25 04:35:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Form handling functions (interface).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETSURF_RENDER_FORM_H_
|
|
|
|
#define _NETSURF_RENDER_FORM_H_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2009-08-14 14:37:33 +04:00
|
|
|
#include "desktop/browser.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2003-10-25 18:13:49 +04:00
|
|
|
struct box;
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_control;
|
|
|
|
struct form_option;
|
2009-08-14 14:37:33 +04:00
|
|
|
struct form_select_menu;
|
2012-08-21 18:27:52 +04:00
|
|
|
struct html_content;
|
2013-02-07 02:39:45 +04:00
|
|
|
struct dom_string;
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2004-12-13 00:51:01 +03:00
|
|
|
/** Form submit method. */
|
|
|
|
typedef enum {
|
|
|
|
method_GET, /**< GET, always url encoded. */
|
|
|
|
method_POST_URLENC, /**< POST, url encoded. */
|
|
|
|
method_POST_MULTIPART /**< POST, multipart/form-data. */
|
|
|
|
} form_method;
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
/** HTML form. */
|
|
|
|
struct form {
|
2009-02-20 14:39:25 +03:00
|
|
|
void *node; /**< Corresponding DOM node */
|
|
|
|
|
|
|
|
char *action; /**< Absolute URL to submit to. */
|
|
|
|
char *target; /**< Target to submit to. */
|
|
|
|
form_method method; /**< Method and enctype. */
|
|
|
|
char *accept_charsets; /**< Charset to submit form in */
|
|
|
|
char *document_charset; /**< Charset of document containing form */
|
|
|
|
struct form_control *controls; /**< Linked list of controls. */
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_control *last_control; /**< Last control in list. */
|
2009-02-20 14:39:25 +03:00
|
|
|
|
|
|
|
struct form *prev; /**< Previous form in doc. */
|
2003-10-25 04:35:49 +04:00
|
|
|
};
|
|
|
|
|
2004-05-21 14:25:42 +04:00
|
|
|
/** Type of a struct form_control. */
|
|
|
|
typedef enum {
|
|
|
|
GADGET_HIDDEN,
|
|
|
|
GADGET_TEXTBOX,
|
|
|
|
GADGET_RADIO,
|
|
|
|
GADGET_CHECKBOX,
|
|
|
|
GADGET_SELECT,
|
|
|
|
GADGET_TEXTAREA,
|
|
|
|
GADGET_IMAGE,
|
|
|
|
GADGET_PASSWORD,
|
|
|
|
GADGET_SUBMIT,
|
|
|
|
GADGET_RESET,
|
2009-02-20 14:39:25 +03:00
|
|
|
GADGET_FILE,
|
|
|
|
GADGET_BUTTON
|
2004-05-21 14:25:42 +04:00
|
|
|
} form_control_type;
|
|
|
|
|
2013-02-07 02:39:45 +04:00
|
|
|
/** Data for textarea */
|
|
|
|
struct form_textarea_data {
|
|
|
|
struct html_content *html;
|
|
|
|
struct form_control *gadget;
|
|
|
|
};
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
/** Form control. */
|
|
|
|
struct form_control {
|
2009-02-20 14:39:25 +03:00
|
|
|
void *node; /**< Corresponding DOM node */
|
|
|
|
|
|
|
|
form_control_type type; /**< Type of control */
|
|
|
|
|
|
|
|
struct form *form; /**< Containing form */
|
|
|
|
|
|
|
|
char *name; /**< Control name */
|
|
|
|
char *value; /**< Current value of control */
|
|
|
|
char *initial_value; /**< Initial value of control */
|
|
|
|
bool disabled; /**< Whether control is disabled */
|
|
|
|
|
|
|
|
struct box *box; /**< Box for control */
|
|
|
|
|
|
|
|
unsigned int length; /**< Number of characters in control */
|
|
|
|
unsigned int maxlength; /**< Maximum characters permitted */
|
|
|
|
|
|
|
|
bool selected; /**< Whether control is selected */
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
union {
|
|
|
|
struct {
|
2004-07-20 00:40:11 +04:00
|
|
|
int mx, my;
|
2003-10-25 04:35:49 +04:00
|
|
|
} image;
|
|
|
|
struct {
|
|
|
|
int num_items;
|
|
|
|
struct form_option *items, *last_item;
|
|
|
|
bool multiple;
|
|
|
|
int num_selected;
|
|
|
|
/** Currently selected item, if num_selected == 1. */
|
|
|
|
struct form_option *current;
|
2009-08-14 14:37:33 +04:00
|
|
|
struct form_select_menu *menu;
|
2003-10-25 04:35:49 +04:00
|
|
|
} select;
|
2013-02-07 02:39:45 +04:00
|
|
|
struct {
|
|
|
|
struct textarea *ta;
|
|
|
|
struct dom_string *initial;
|
|
|
|
struct form_textarea_data data;
|
|
|
|
} text; /**< input type=text or textarea */
|
2003-10-25 04:35:49 +04:00
|
|
|
} data;
|
2009-02-20 14:39:25 +03:00
|
|
|
|
2004-04-09 03:46:41 +04:00
|
|
|
struct form_control *prev; /**< Previous control in this form */
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_control *next; /**< Next control in this form. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Option in a select. */
|
|
|
|
struct form_option {
|
|
|
|
bool selected;
|
|
|
|
bool initial_selected;
|
2004-12-13 00:51:01 +03:00
|
|
|
char *value;
|
|
|
|
char *text; /**< NUL terminated. */
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_option* next;
|
|
|
|
};
|
|
|
|
|
2009-08-14 14:37:33 +04:00
|
|
|
/**
|
|
|
|
* Called by the select menu when it wants an area to be redrawn. The
|
|
|
|
* coordinates are menu origin relative.
|
|
|
|
*
|
|
|
|
* \param client_data data which was passed to form_open_select_menu
|
|
|
|
* \param x X coordinate of redraw rectangle
|
|
|
|
* \param y Y coordinate of redraw rectangle
|
|
|
|
* \param width width of redraw rectangle
|
|
|
|
* \param height height of redraw rectangle
|
|
|
|
*/
|
|
|
|
typedef void(*select_menu_redraw_callback)(void *client_data,
|
|
|
|
int x, int y, int width, int height);
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
struct form *form_new(void *node, const char *action, const char *target,
|
|
|
|
form_method method, const char *charset,
|
|
|
|
const char *doc_charset);
|
|
|
|
void form_free(struct form *form);
|
|
|
|
struct form_control *form_new_control(void *node, form_control_type type);
|
2003-10-25 04:35:49 +04:00
|
|
|
void form_add_control(struct form *form, struct form_control *control);
|
2004-05-21 14:25:42 +04:00
|
|
|
void form_free_control(struct form_control *control);
|
2004-12-13 00:51:01 +03:00
|
|
|
bool form_add_option(struct form_control *control, char *value, char *text,
|
|
|
|
bool selected);
|
2004-08-08 23:13:40 +04:00
|
|
|
bool form_successful_controls(struct form *form,
|
|
|
|
struct form_control *submit_button,
|
2010-03-28 16:56:39 +04:00
|
|
|
struct fetch_multipart_data **successful_controls);
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2009-08-14 14:37:33 +04:00
|
|
|
bool form_open_select_menu(void *client_data,
|
|
|
|
struct form_control *control,
|
|
|
|
select_menu_redraw_callback redraw_callback,
|
2011-06-28 15:15:39 +04:00
|
|
|
struct content *c);
|
2010-06-04 13:35:08 +04:00
|
|
|
void form_select_menu_callback(void *client_data,
|
|
|
|
int x, int y, int width, int height);
|
2009-08-14 14:37:33 +04:00
|
|
|
void form_free_select_menu(struct form_control *control);
|
|
|
|
bool form_redraw_select_menu(struct form_control *control, int x, int y,
|
2011-06-30 19:48:07 +04:00
|
|
|
float scale, const struct rect *clip,
|
|
|
|
const struct redraw_context *ctx);
|
2009-08-14 14:37:33 +04:00
|
|
|
bool form_clip_inside_select_menu(struct form_control *control, float scale,
|
2011-02-15 01:05:39 +03:00
|
|
|
const struct rect *clip);
|
2009-08-14 14:37:33 +04:00
|
|
|
const char *form_select_mouse_action(struct form_control *control,
|
|
|
|
browser_mouse_state mouse, int x, int y);
|
|
|
|
void form_select_mouse_drag_end(struct form_control *control,
|
|
|
|
browser_mouse_state mouse, int x, int y);
|
|
|
|
void form_select_get_dimensions(struct form_control *control,
|
|
|
|
int *width, int *height);
|
2010-06-04 13:35:08 +04:00
|
|
|
void form_select_process_selection(hlcache_handle *h,
|
|
|
|
struct form_control *control, int item);
|
2012-08-17 23:26:00 +04:00
|
|
|
void form_submit(nsurl *page_url, struct browser_window *target,
|
2010-06-04 13:35:08 +04:00
|
|
|
struct form *form, struct form_control *submit_button);
|
2012-08-21 18:27:52 +04:00
|
|
|
void form_radio_set(struct html_content *html, struct form_control *radio);
|
2009-08-14 14:37:33 +04:00
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
#endif
|