NetSurf
Data Structures | Macros | Functions | Variables
form.c File Reference

Form handling functions (implementation). More...

#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <dom/dom.h>
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/talloc.h"
#include "utils/url.h"
#include "utils/utf8.h"
#include "utils/ascii.h"
#include "netsurf/browser_window.h"
#include "netsurf/inttypes.h"
#include "netsurf/mouse.h"
#include "netsurf/plotters.h"
#include "netsurf/misc.h"
#include "content/fetch.h"
#include "content/hlcache.h"
#include "css/utils.h"
#include "desktop/knockout.h"
#include "desktop/scrollbar.h"
#include "desktop/textarea.h"
#include "html/html.h"
#include "html/private.h"
#include "html/layout.h"
#include "html/box.h"
#include "html/box_inspect.h"
#include "html/font.h"
#include "html/form_internal.h"
Include dependency graph for form.c:

Go to the source code of this file.

Data Structures

struct  form_select_menu
 

Macros

#define MAX_SELECT_HEIGHT   210
 
#define SELECT_LINE_SPACING   0.2
 
#define SELECT_BORDER_WIDTH   1
 
#define SELECT_SELECTED_COLOUR   0xDB9370
 
#define FETCH_DATA_INT_VALUE_SIZE   20
 string allocation size for numeric values in multipart data More...
 

Functions

static char * form_encode_item (const char *item, uint32_t len, const char *charset, const char *fallback)
 Convert a string from UTF-8 to the specified charset As a final fallback, this will attempt to convert to ISO-8859-1. More...
 
static nserror fetch_data_list_add_sname (const char *name, const char *ksfx, int value, struct fetch_multipart_data ***fetch_data_next_ptr)
 append split key name and integer value to a multipart data list More...
 
static nserror fetch_data_list_add (dom_string *name, dom_string *value, const char *rawfile, const char *form_charset, const char *docu_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 append DOM string name/value pair to a multipart data list More...
 
static nserror form_dom_to_data_textarea (dom_html_text_area_element *text_area_element, const char *form_charset, const char *doc_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 process form HTMLTextAreaElement into multipart data. More...
 
static nserror form_dom_to_data_select_option (dom_html_option_element *option_element, dom_string *keyname, const char *form_charset, const char *docu_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 
static nserror form_dom_to_data_select (dom_html_select_element *select_element, const char *form_charset, const char *doc_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 process form HTMLSelectElement into multipart data. More...
 
static nserror form_dom_to_data_input_submit (dom_html_input_element *input_element, dom_string *inputname, const char *charset, const char *document_charset, dom_html_element **submit_button, struct fetch_multipart_data ***fetch_data_next_ptr)
 
static nserror form_dom_to_data_input_image (dom_html_input_element *input_element, dom_string *inputname, const char *charset, const char *document_charset, dom_html_element **submit_button, struct fetch_multipart_data ***fetch_data_next_ptr)
 
static nserror form_dom_to_data_input_checkbox (dom_html_input_element *input_element, dom_string *inputname, const char *charset, const char *document_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 
static nserror form_dom_to_data_input_file (dom_html_input_element *input_element, dom_string *inputname, const char *charset, const char *document_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 
static nserror form_dom_to_data_input_text (dom_html_input_element *input_element, dom_string *inputname, const char *charset, const char *document_charset, struct fetch_multipart_data ***fetch_data_next_ptr)
 
static nserror form_dom_to_data_input (dom_html_input_element *input_element, const char *charset, const char *document_charset, dom_html_element **submit_button, struct fetch_multipart_data ***fetch_data_next_ptr)
 process form input element into multipart data. More...
 
static nserror form_dom_to_data_button (dom_html_button_element *button_element, const char *form_charset, const char *doc_charset, dom_html_element **submit_button, struct fetch_multipart_data ***fetch_data_next_ptr)
 process form HTMLButtonElement into multipart data. More...
 
static char * form_acceptable_charset (struct form *form)
 Find an acceptable character set encoding with which to submit the form. More...
 
static nserror form_dom_to_data (struct form *form, struct form_control *submit_control, struct fetch_multipart_data **fetch_data_out)
 Construct multipart data list from 'successful' controls via the DOM. More...
 
static nserror form_url_encode (struct form *form, struct fetch_multipart_data *control, char **encoded_out)
 Encode controls using application/x-www-form-urlencoded. More...
 
static void form_select_menu_scroll_callback (void *client_data, struct scrollbar_msg_data *scrollbar_data)
 Callback for the select menus scroll. More...
 
static nserror form__select_process_selection (html_content *html, struct form_control *control, int item)
 Process a selection from a form select menu. More...
 
static void form_select_menu_clicked (struct form_control *control, int x, int y)
 Handle a click on the area of the currently opened select menu. More...
 
void form_add_control (struct form *form, struct form_control *control)
 Add a control to the list of controls in a form. More...
 
void form_free_control (struct form_control *control)
 Free a struct form_control. More...
 
bool form_add_option (struct form_control *control, char *value, char *text, bool selected, void *node)
 Add an option to a form select control. More...
 
nserror form_open_select_menu (void *client_data, struct form_control *control, select_menu_redraw_callback callback, struct content *c)
 Open a select menu for a select form control, creating it if necessary. More...
 
void form_free_select_menu (struct form_control *control)
 Destroy a select menu and free allocated memory. More...
 
bool form_redraw_select_menu (struct form_control *control, int x, int y, float scale, const struct rect *clip, const struct redraw_context *ctx)
 Redraw an opened select menu. More...
 
bool form_clip_inside_select_menu (struct form_control *control, float scale, const struct rect *clip)
 Check whether a clipping rectangle is completely contained in the select menu. More...
 
nserror form_select_process_selection (struct form_control *control, int item)
 Process a selection from a form select menu. More...
 
struct form_optionform_select_get_option (struct form_control *control, int item)
 get a form select menus option. More...
 
char * form_control_get_name (struct form_control *control)
 Get a form control name. More...
 
nserror form_control_bounding_rect (struct form_control *control, struct rect *r)
 Get a form control bounding rectangle. More...
 
const char * form_select_mouse_action (struct form_control *control, browser_mouse_state mouse, int x, int y)
 Handle mouse action for the currently opened select menu. More...
 
void form_select_mouse_drag_end (struct form_control *control, browser_mouse_state mouse, int x, int y)
 Handle mouse drag end for the currently opened select menu. More...
 
void form_select_get_dimensions (struct form_control *control, int *width, int *height)
 Get the dimensions of a select menu. More...
 
void form_select_menu_callback (void *client_data, int x, int y, int width, int height)
 Callback for the core select menu. More...
 
void form_radio_set (struct form_control *radio)
 Set a radio form control and clear the others in the group. More...
 
nserror form_submit (nsurl *page_url, struct browser_window *target, struct form *form, struct form_control *submit_button)
 navigate browser window based on form submission. More...
 
void form_gadget_update_value (struct form_control *control, char *value)
 Update gadget value. More...
 
void form_gadget_sync_with_dom (struct form_control *control)
 Synchronise this gadget with its associated DOM node. More...
 
struct formform_new (void *node, const char *action, const char *target, form_method method, const char *charset, const char *doc_charset)
 Create a struct form. More...
 
void form_free (struct form *form)
 Free a form and any controls it owns. More...
 
struct form_controlform_new_control (void *node, form_control_type type)
 Create a struct form_control. More...
 

Variables

static plot_style_t plot_style_fill_selected
 
static plot_font_style_t plot_fstyle_entry
 

Detailed Description

Form handling functions (implementation).

Definition in file form.c.

Macro Definition Documentation

◆ FETCH_DATA_INT_VALUE_SIZE

#define FETCH_DATA_INT_VALUE_SIZE   20

string allocation size for numeric values in multipart data

Definition at line 165 of file form.c.

◆ MAX_SELECT_HEIGHT

#define MAX_SELECT_HEIGHT   210

Definition at line 63 of file form.c.

◆ SELECT_BORDER_WIDTH

#define SELECT_BORDER_WIDTH   1

Definition at line 65 of file form.c.

◆ SELECT_LINE_SPACING

#define SELECT_LINE_SPACING   0.2

Definition at line 64 of file form.c.

◆ SELECT_SELECTED_COLOUR

#define SELECT_SELECTED_COLOUR   0xDB9370

Definition at line 66 of file form.c.

Function Documentation

◆ fetch_data_list_add()

static nserror fetch_data_list_add ( dom_string *  name,
dom_string *  value,
const char *  rawfile,
const char *  form_charset,
const char *  docu_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

append DOM string name/value pair to a multipart data list

Parameters
namekey name
valuethe value to associate with the key
rawfilethe raw file value to associate with the key.
form_charsetThe form character set
docu_charsetThe document character set for fallback
fetch_data_next_ptrThe multipart data list being constructed.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 232 of file form.c.

References fetch_multipart_data::file, form_encode_item(), fetch_multipart_data::name, fetch_multipart_data::next, NSERROR_NOMEM, NSERROR_OK, NSLOG, fetch_multipart_data::rawfile, and fetch_multipart_data::value.

Referenced by form_dom_to_data_button(), form_dom_to_data_input_checkbox(), form_dom_to_data_input_file(), form_dom_to_data_input_submit(), form_dom_to_data_input_text(), form_dom_to_data_select_option(), and form_dom_to_data_textarea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_data_list_add_sname()

static nserror fetch_data_list_add_sname ( const char *  name,
const char *  ksfx,
int  value,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

append split key name and integer value to a multipart data list

Parameters
namekey name
ksfxkey name suffix
valueThe value to encode
fetch_data_next_ptrThe multipart data list to append to.

Definition at line 177 of file form.c.

References FETCH_DATA_INT_VALUE_SIZE, fetch_multipart_data::name, fetch_multipart_data::next, NSERROR_NOMEM, NSERROR_OK, NSLOG, and fetch_multipart_data::value.

Referenced by form_dom_to_data_input_image().

Here is the caller graph for this function:

◆ form__select_process_selection()

static nserror form__select_process_selection ( html_content html,
struct form_control control,
int  item 
)
static

Process a selection from a form select menu.

Parameters
htmlThe html content handle for the form
controlform control with menu
itemindex of item selected from the menu
Returns
NSERROR_OK or appropriate error code.
Todo:
Even though the form code is effectively part of the html content handler, poking around inside contents is not good

Definition at line 1313 of file form.c.

References html_content::bctx, form_control::box, box::children, count(), form_control::data, html__redraw_a_box(), box::length, messages_get(), form_option::next, form_option::node, NSERROR_NOMEM, NSERROR_OK, form_option::selected, talloc_free(), talloc_strdup(), box::text, and box::width.

Referenced by form_select_menu_clicked(), and form_select_process_selection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_acceptable_charset()

static char * form_acceptable_charset ( struct form form)
static

Find an acceptable character set encoding with which to submit the form.

Parameters
formThe form
Returns
Pointer to charset name (on heap, caller should free) or NULL
Todo:
an improvement would be to choose an encoding acceptable to the server which covers as much of the input values as possible. Additionally, we need to handle the case where none of the acceptable encodings cover all the textual input values. For now, we just extract the first element of the charset list

Definition at line 976 of file form.c.

References form::accept_charsets, ascii_is_space(), ascii_to_upper(), form::document_charset, and strndup().

Referenced by form_dom_to_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_add_control()

void form_add_control ( struct form form,
struct form_control control 
)

Add a control to the list of controls in a form.

Parameters
formThe form to add the control to
controlThe control to add

Definition at line 1433 of file form.c.

References form::controls, form_control::form, form::last_control, form_control::next, and form_control::prev.

Referenced by parse_button_element(), parse_input_element(), parse_select_element(), and parse_textarea_element().

Here is the caller graph for this function:

◆ form_add_option()

bool form_add_option ( struct form_control control,
char *  value,
char *  text,
bool  selected,
void *  node 
)

Add an option to a form select control.

Parameters
controlform control of type GADGET_SELECT
valuevalue of option, used directly (not copied)
texttext for option, used directly (not copied)
selectedthis option is selected
nodethe DOM node this option is associated with
Returns
true on success, false on memory exhaustion

Definition at line 1529 of file form.c.

References form_control::data, GADGET_SELECT, form_option::initial_selected, form_option::node, form_option::selected, text(), form_option::text, form_control::type, and form_option::value.

Referenced by box_select_add_option().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_clip_inside_select_menu()

bool form_clip_inside_select_menu ( struct form_control control,
float  scale,
const struct rect clip 
)

Check whether a clipping rectangle is completely contained in the select menu.

Parameters
controlthe select menu to check the clipping rectangle for
scalethe current browser window scale
clipthe clipping rectangle
Returns
true if inside false otherwise

Definition at line 1807 of file form.c.

References clip(), form_control::data, form_select_menu::height, height, form_select_menu::width, and width.

Referenced by html_redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_control_bounding_rect()

nserror form_control_bounding_rect ( struct form_control control,
struct rect r 
)

Get a form control bounding rectangle.

Parameters
[in]controlThe form control
[out]rThe rectangle to place the bounds in.
Returns
NSERROR_OK on success or error code.

Definition at line 1865 of file form.c.

References form_control::box, box_bounds(), and NSERROR_OK.

Here is the call graph for this function:

◆ form_control_get_name()

char * form_control_get_name ( struct form_control control)

Get a form control name.

Parameters
controlThe form control
Returns
The form control name

Definition at line 1858 of file form.c.

References form_control::name.

◆ form_dom_to_data()

static nserror form_dom_to_data ( struct form form,
struct form_control submit_control,
struct fetch_multipart_data **  fetch_data_out 
)
static

Construct multipart data list from 'successful' controls via the DOM.

All text strings in the successful controls list will be in the charset most appropriate for submission. Therefore, no utf8_to_* processing should be performed upon them.

Todo:
The chosen charset needs to be made available such that it can be included in the submission request (e.g. in the fetch's Content-Type header)

See HTML 4.01 section 17.13.2.

Note
care is taken to abort even if the error is recoverable as it is not desirable to submit incomplete form data.
Parameters
[in]formform to search for successful controls
[in]submit_buttoncontrol used to submit the form, if any
[out]fetch_data_outupdated to point to linked list of fetch_multipart_data, NULL if no controls
Returns
NSERROR_OK on success or appropriate error code
Todo:
Replace this call with something DOMish

Definition at line 1054 of file form.c.

References form::document_charset, fetch_multipart_data_destroy(), form_acceptable_charset(), form_dom_to_data_button(), form_dom_to_data_input(), form_dom_to_data_select(), form_dom_to_data_textarea(), form_control::node, form::node, NSERROR_DOM, NSERROR_NOMEM, NSERROR_OK, and NSLOG.

Referenced by form_submit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_button()

static nserror form_dom_to_data_button ( dom_html_button_element *  button_element,
const char *  form_charset,
const char *  doc_charset,
dom_html_element **  submit_button,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

process form HTMLButtonElement into multipart data.

https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element

Parameters
button_elementThe form button DOM element to convert.
form_charsetThe form character set
doc_charsetThe document character set for fallback
submit_buttonThe DOM element of the button submitting the form
fetch_data_next_ptrThe multipart data list being constructed.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 875 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, NSERROR_OK, and NSLOG.

Referenced by form_dom_to_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_input()

static nserror form_dom_to_data_input ( dom_html_input_element *  input_element,
const char *  charset,
const char *  document_charset,
dom_html_element **  submit_button,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

process form input element into multipart data.

Parameters
input_elementThe form input DOM element to convert.
charsetThe form character set
document_charsetThe document character set for fallback
submit_buttonThe DOM element of the button submitting the form
had_submitA boolean value indicating if the submit button has already been processed in the form element enumeration.
fetch_data_next_ptrThe multipart data list being constructed.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 750 of file form.c.

References form_dom_to_data_input_checkbox(), form_dom_to_data_input_file(), form_dom_to_data_input_image(), form_dom_to_data_input_submit(), form_dom_to_data_input_text(), NSERROR_DOM, NSERROR_OK, and NSLOG.

Referenced by form_dom_to_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_input_checkbox()

static nserror form_dom_to_data_input_checkbox ( dom_html_input_element *  input_element,
dom_string *  inputname,
const char *  charset,
const char *  document_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

Definition at line 613 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, NSERROR_OK, and NSLOG.

Referenced by form_dom_to_data_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_input_file()

static nserror form_dom_to_data_input_file ( dom_html_input_element *  input_element,
dom_string *  inputname,
const char *  charset,
const char *  document_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

Definition at line 663 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, and NSLOG.

Referenced by form_dom_to_data_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_input_image()

static nserror form_dom_to_data_input_image ( dom_html_input_element *  input_element,
dom_string *  inputname,
const char *  charset,
const char *  document_charset,
dom_html_element **  submit_button,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

Definition at line 556 of file form.c.

References fetch_data_list_add_sname(), form_encode_item(), NSERROR_DOM, NSERROR_NOMEM, NSERROR_OK, NSLOG, image_input_coords::x, and image_input_coords::y.

Referenced by form_dom_to_data_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_input_submit()

static nserror form_dom_to_data_input_submit ( dom_html_input_element *  input_element,
dom_string *  inputname,
const char *  charset,
const char *  document_charset,
dom_html_element **  submit_button,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

Definition at line 516 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, NSERROR_OK, and NSLOG.

Referenced by form_dom_to_data_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_input_text()

static nserror form_dom_to_data_input_text ( dom_html_input_element *  input_element,
dom_string *  inputname,
const char *  charset,
const char *  document_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

Definition at line 707 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, and NSLOG.

Referenced by form_dom_to_data_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_select()

static nserror form_dom_to_data_select ( dom_html_select_element *  select_element,
const char *  form_charset,
const char *  doc_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

process form HTMLSelectElement into multipart data.

Parameters
select_elementThe form select DOM element to convert.
form_charsetThe form character set
doc_charsetThe document character set for fallback
fetch_data_next_ptrThe multipart data list being constructed.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 423 of file form.c.

References form_dom_to_data_select_option(), NSERROR_DOM, NSERROR_OK, NSLOG, and options.

Referenced by form_dom_to_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_select_option()

static nserror form_dom_to_data_select_option ( dom_html_option_element *  option_element,
dom_string *  keyname,
const char *  form_charset,
const char *  docu_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

Definition at line 371 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, NSERROR_OK, NSLOG, and fetch_multipart_data::value.

Referenced by form_dom_to_data_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_dom_to_data_textarea()

static nserror form_dom_to_data_textarea ( dom_html_text_area_element *  text_area_element,
const char *  form_charset,
const char *  doc_charset,
struct fetch_multipart_data ***  fetch_data_next_ptr 
)
static

process form HTMLTextAreaElement into multipart data.

Parameters
text_area_elementThe form select DOM element to convert.
form_charsetThe form character set
doc_charsetThe document character set for fallback
fetch_data_next_ptrThe multipart data list being constructed.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 306 of file form.c.

References fetch_data_list_add(), NSERROR_DOM, NSERROR_OK, and NSLOG.

Referenced by form_dom_to_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_encode_item()

static char * form_encode_item ( const char *  item,
uint32_t  len,
const char *  charset,
const char *  fallback 
)
static

Convert a string from UTF-8 to the specified charset As a final fallback, this will attempt to convert to ISO-8859-1.

Todo:
Return charset used?
Parameters
itemString to convert
lenLength of string to convert
charsetDestination charset
fallbackFallback charset (may be NULL), used iff converting to charset fails
Returns
Pointer to converted string (on heap, caller frees), or NULL

Definition at line 107 of file form.c.

References NSERROR_BAD_ENCODING, NSERROR_NOMEM, and utf8_to_enc().

Referenced by fetch_data_list_add(), and form_dom_to_data_input_image().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_free()

void form_free ( struct form form)

Free a form and any controls it owns.

Note
There may exist controls attached to box tree nodes which are not associated with any form. These will leak at present. Ideally, they will be cleaned up when the box tree is destroyed. As that currently happens via talloc, this won't happen. These controls are distinguishable, as their form field will be NULL.
Parameters
formThe form to free

Definition at line 2329 of file form.c.

References form::accept_charsets, form::action, form::controls, form::document_charset, form_free_control(), form_control::next, and form::target.

Referenced by html_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_free_control()

void form_free_control ( struct form_control control)

Free a struct form_control.

Parameters
controlstructure to free

Definition at line 1455 of file form.c.

References form::controls, form_control::data, form_control::form, form_free_select_menu(), GADGET_PASSWORD, GADGET_SELECT, GADGET_TEXTAREA, GADGET_TEXTBOX, form_control::initial_value, form::last_control, form_control::last_synced_value, form_control::name, form_control::next, form_option::next, form_control::node_value, NSLOG, form_option::text, textarea_destroy(), form_control::type, form_control::value, and form_option::value.

Referenced by box_free_box(), box_select(), form_free(), invent_fake_gadget(), parse_button_element(), and parse_input_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_free_select_menu()

void form_free_select_menu ( struct form_control control)

Destroy a select menu and free allocated memory.

Parameters
controlthe select form control owning the select menu being destroyed.

Definition at line 1645 of file form.c.

References form_control::data, and scrollbar_destroy().

Referenced by form_free_control().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_gadget_sync_with_dom()

void form_gadget_sync_with_dom ( struct form_control control)

Synchronise this gadget with its associated DOM node.

If the DOM has changed and the gadget has not, the DOM's new value is imported into the gadget. If the gadget's value has changed and the DOM's has not, the gadget's value is pushed into the DOM. If both have changed, the gadget's value wins.

Parameters
controlThe form gadget to synchronise
Note
Currently this will only synchronise input gadgets (text/password)

Definition at line 2170 of file form.c.

References form_control::data, GADGET_HIDDEN, GADGET_PASSWORD, GADGET_TEXTAREA, GADGET_TEXTBOX, form_control::last_synced_value, form_control::node, form_control::node_value, strndup(), form_control::syncing, textarea_set_text(), form_control::type, fetch_multipart_data::value, and form_control::value.

Referenced by form_gadget_update_value(), html_texty_element_update(), and parse_input_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_gadget_update_value()

void form_gadget_update_value ( struct form_control control,
char *  value 
)

Update gadget value.

Definition at line 2128 of file form.c.

References form_gadget_sync_with_dom(), GADGET_FILE, GADGET_HIDDEN, GADGET_PASSWORD, GADGET_TEXTAREA, GADGET_TEXTBOX, form_control::node, form_control::type, fetch_multipart_data::value, and form_control::value.

Referenced by box_textarea_callback(), and html__set_file_gadget_filename().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_new()

struct form * form_new ( void *  node,
const char *  action,
const char *  target,
form_method  method,
const char *  charset,
const char *  doc_charset 
)

Create a struct form.

Parameters
nodeDOM node associated with form
actionURL to submit form to, or NULL for default
targetTarget frame of form, or NULL for default
methodmethod and enctype
charsetacceptable encodings for form submission, or NULL
doc_charsetencoding of containing document, or NULL
Returns
A new form or NULL on memory exhaustion

Definition at line 2276 of file form.c.

References form::accept_charsets, form::action, form::document_charset, form::method, form::node, and form::target.

Referenced by parse_form_element().

Here is the caller graph for this function:

◆ form_new_control()

struct form_control * form_new_control ( void *  node,
form_control_type  type 
)

Create a struct form_control.

Parameters
nodeAssociated DOM node
typecontrol type
Returns
a new structure, or NULL on memory exhaustion

Definition at line 2349 of file form.c.

References form_control::node, form_control::type, and type.

Referenced by invent_fake_gadget(), parse_button_element(), parse_input_element(), parse_select_element(), and parse_textarea_element().

Here is the caller graph for this function:

◆ form_open_select_menu()

nserror form_open_select_menu ( void *  client_data,
struct form_control control,
select_menu_redraw_callback  redraw_callback,
struct content c 
)

Open a select menu for a select form control, creating it if necessary.

Parameters
client_datadata passed to the redraw callback
controlThe select form control for which the menu is being opened
redraw_callbackThe callback to redraw the select menu.
cThe content the select menu is opening for.
Returns
NSERROR_OK on sucess else error code.

Definition at line 1569 of file form.c.

References box::border, form_control::box, form_select_menu::c, form_select_menu::callback, form_select_menu::client_data, form_control::data, form_select_menu::f_size, font_plot_style_from_css(), form_select_menu_scroll_callback(), form_select_menu::height, LEFT, form_select_menu::line_height, MAX_SELECT_HEIGHT, NSERROR_NOMEM, NSERROR_OK, box::padding, PLOT_STYLE_SCALE, RIGHT, form_select_menu::scrollbar, scrollbar_create(), SELECT_LINE_SPACING, plot_font_style::size, box::style, html_content::unit_len_ctx, box_border::width, box::width, and form_select_menu::width.

Referenced by gadget_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_radio_set()

void form_radio_set ( struct form_control radio)

Set a radio form control and clear the others in the group.

Parameters
radioform control of type GADGET_RADIO

Definition at line 1994 of file form.c.

References form_control::box, form::controls, form_control::form, GADGET_RADIO, form_control::html, html__redraw_a_box(), form_control::name, form_control::next, form_control::node, form_control::selected, and form_control::type.

Referenced by gadget_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_redraw_select_menu()

bool form_redraw_select_menu ( struct form_control control,
int  x,
int  y,
float  scale,
const struct rect clip,
const struct redraw_context ctx 
)

Redraw an opened select menu.

Parameters
controlthe select menu being redrawn
xthe X coordinate to draw the menu at
ythe Y coordinate to draw the menu at
scalecurrent redraw scale
clipclipping rectangle
ctxcurrent redraw context
Returns
true on success, false otherwise

Definition at line 1656 of file form.c.

References box::border, form_control::box, clip(), plotter_table::clip, form_control::data, form_select_menu::f_size, form_select_menu::height, height, LEFT, form_select_menu::line_height, line_height(), form_option::next, NSERROR_OK, box::padding, redraw_context::plot, plot_fstyle_entry, plot_style_fill_lightwbasec, plot_style_fill_selected, plot_style_stroke_darkwbasec, plotter_table::rectangle, form_select_menu::scrollbar, scrollbar_get_offset(), scrollbar_redraw(), SCROLLBAR_WIDTH, SELECT_BORDER_WIDTH, SELECT_LINE_SPACING, form_option::selected, plot_font_style::size, form_option::text, plotter_table::text, box_border::width, form_select_menu::width, width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by html_redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_select_get_dimensions()

void form_select_get_dimensions ( struct form_control control,
int *  width,
int *  height 
)

Get the dimensions of a select menu.

Parameters
controlthe select menu to get the dimensions of
widthgets updated to menu width
heightgets updated to menu height

Definition at line 1965 of file form.c.

References form_control::data, height, and width.

Referenced by mouse_action_select_menu().

Here is the caller graph for this function:

◆ form_select_get_option()

struct form_option * form_select_get_option ( struct form_control control,
int  item 
)

get a form select menus option.

Parameters
controlThe form control.
itemThe index of the menu entry to return.
Returns
The form option at that index.

Definition at line 1844 of file form.c.

References form_control::data, and form_option::next.

Referenced by gui_window_create_form_select_menu(), and ro_gui_window_prepare_form_select_menu().

Here is the caller graph for this function:

◆ form_select_menu_callback()

void form_select_menu_callback ( void *  client_data,
int  x,
int  y,
int  width,
int  height 
)

Callback for the core select menu.

Definition at line 1974 of file form.c.

References box::border, BOTTOM, form_control::box, box_coords(), form_select_menu::client_data, content__request_redraw(), box::height, height, LEFT, box::padding, TOP, html_content::visible_select_menu, box_border::width, width, box::x, and box::y.

Referenced by gadget_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_select_menu_clicked()

static void form_select_menu_clicked ( struct form_control control,
int  x,
int  y 
)
static

Handle a click on the area of the currently opened select menu.

Parameters
controlthe select menu which received the click
xX coordinate of click
yY coordinate of click

Definition at line 1400 of file form.c.

References form_select_menu::c, form_select_menu::callback, form_select_menu::client_data, form_control::data, form__select_process_selection(), form_select_menu::height, form_select_menu::line_height, line_height(), form_option::next, form_select_menu::scrollbar, scrollbar_get_offset(), SELECT_LINE_SPACING, and form_select_menu::width.

Referenced by form_select_mouse_action(), and form_select_mouse_drag_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_select_menu_scroll_callback()

static void form_select_menu_scroll_callback ( void *  client_data,
struct scrollbar_msg_data scrollbar_data 
)
static

Callback for the select menus scroll.

Definition at line 1263 of file form.c.

References browser_window_set_drag_type(), html_content::bw, form_select_menu::c, form_select_menu::callback, form_select_menu::client_data, form_control::data, DRAGGING_CONTENT_SCROLLBAR, DRAGGING_NONE, form_select_menu::height, scrollbar_msg_data::msg, form_select_menu::scroll_capture, SCROLLBAR_MSG_MOVED, SCROLLBAR_MSG_SCROLL_FINISHED, SCROLLBAR_MSG_SCROLL_START, form_select_menu::width, scrollbar_msg_data::x0, rect::x0, scrollbar_msg_data::x1, scrollbar_msg_data::y0, and scrollbar_msg_data::y1.

Referenced by form_open_select_menu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_select_mouse_action()

const char * form_select_mouse_action ( struct form_control control,
enum browser_mouse_state  mouse,
int  x,
int  y 
)

Handle mouse action for the currently opened select menu.

Parameters
controlthe select menu which received the mouse action
mousecurrent mouse state
xX coordinate of click
yY coordinate of click
Returns
text for the browser status bar or NULL if the menu has to be closed

Definition at line 1874 of file form.c.

References BROWSER_MOUSE_CLICK_1, BROWSER_MOUSE_CLICK_2, form_control::data, form_select_menu_clicked(), form_select_menu::height, messages_get(), form_select_menu::scroll_capture, form_select_menu::scrollbar, scrollbar_mouse_action(), scrollbar_mouse_status_to_message(), SCROLLBAR_WIDTH, and form_select_menu::width.

Referenced by mouse_action_select_menu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_select_mouse_drag_end()

void form_select_mouse_drag_end ( struct form_control control,
enum browser_mouse_state  mouse,
int  x,
int  y 
)

Handle mouse drag end for the currently opened select menu.

Parameters
controlthe select menu which received the mouse drag end
mousecurrent mouse state
xX coordinate of drag end
yY coordinate of drag end

Definition at line 1924 of file form.c.

References box::border, BOTTOM, form_control::box, box_coords(), form_control::data, form_select_menu_clicked(), box::height, form_select_menu::height, LEFT, box::padding, form_select_menu::scroll_capture, form_select_menu::scrollbar, scrollbar_mouse_drag_end(), SCROLLBAR_WIDTH, TOP, box_border::width, and form_select_menu::width.

Referenced by mouse_action_select_menu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_select_process_selection()

nserror form_select_process_selection ( struct form_control control,
int  item 
)

Process a selection from a form select menu.

Parameters
controlform control with menu.
itemindex of item selected from the menu.

Definition at line 1834 of file form.c.

References form__select_process_selection(), and form_control::html.

Referenced by nsgtk_select_menu_clicked(), and ro_gui_window_process_form_select_menu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_submit()

nserror form_submit ( struct nsurl page_url,
struct browser_window target,
struct form form,
struct form_control submit_button 
)

navigate browser window based on form submission.

Parameters
page_urlcontent url
targetThe browsing context in which the navigation will occour.
formThe form to submit.
submit_buttonThe control used to submit the form.

Definition at line 2047 of file form.c.

References form::action, browser_window_navigate(), BW_NAVIGATE_HISTORY, form_control::data, fetch_multipart_data_destroy(), form_dom_to_data(), form_url_encode(), form::method, method_GET, method_POST_MULTIPART, method_POST_URLENC, NSERROR_OK, nsurl_create(), nsurl_replace_query(), and nsurl_unref().

Referenced by box_textarea_keypress(), and mouse_action_drag_none().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_url_encode()

static nserror form_url_encode ( struct form form,
struct fetch_multipart_data control,
char **  encoded_out 
)
static

Encode controls using application/x-www-form-urlencoded.

Parameters
[in]formform to which successful controls relate
[in]controllinked list of fetch_multipart_data
[out]encoded_outURL-encoded form data
Returns
NSERROR_OK on success and encoded_out updated else appropriate error code

Definition at line 1197 of file form.c.

References fetch_multipart_data::name, fetch_multipart_data::next, NSERROR_NOMEM, NSERROR_OK, url_escape(), and fetch_multipart_data::value.

Referenced by form_submit().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ plot_fstyle_entry

plot_font_style_t plot_fstyle_entry
static
Initial value:
= {
.weight = 400,
.flags = FONTF_NONE,
.background = 0xffffff,
.foreground = 0x000000,
}
@ FONTF_NONE
Definition: plot_style.h:102
@ PLOT_FONT_FAMILY_SANS_SERIF
Definition: plot_style.h:89

Definition at line 84 of file form.c.

Referenced by form_redraw_select_menu().

◆ plot_style_fill_selected

plot_style_t plot_style_fill_selected
static
Initial value:
= {
.fill_type = PLOT_OP_TYPE_SOLID,
.fill_colour = SELECT_SELECTED_COLOUR,
}
#define SELECT_SELECTED_COLOUR
Definition: form.c:66
@ PLOT_OP_TYPE_SOLID
Solid colour.
Definition: plot_style.h:67

Definition at line 79 of file form.c.

Referenced by form_redraw_select_menu().