NetSurf
Data Structures | Typedefs | Enumerations | Functions
form_internal.h File Reference

Interface to form handling functions internal to HTML content handler. More...

#include <stdbool.h>
#include "netsurf/form.h"
Include dependency graph for form_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  form_textarea_data
 Data for textarea. More...
 
struct  image_input_coords
 
struct  form_control
 Form control. More...
 
struct  form
 HTML form. More...
 

Typedefs

typedef void(* select_menu_redraw_callback) (void *client_data, int x, int y, int width, int height)
 Called by the select menu when it wants an area to be redrawn. More...
 

Enumerations

enum  form_control_type {
  GADGET_HIDDEN , GADGET_TEXTBOX , GADGET_RADIO , GADGET_CHECKBOX ,
  GADGET_SELECT , GADGET_TEXTAREA , GADGET_IMAGE , GADGET_PASSWORD ,
  GADGET_SUBMIT , GADGET_RESET , GADGET_FILE , GADGET_BUTTON
}
 Type of a struct form_control. More...
 
enum  form_method { method_GET , method_POST_URLENC , method_POST_MULTIPART }
 Form submit method. More...
 

Functions

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...
 
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 redraw_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...
 
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. More...
 
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. 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 (struct 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...
 

Detailed Description

Interface to form handling functions internal to HTML content handler.

Definition in file form_internal.h.

Typedef Documentation

◆ select_menu_redraw_callback

typedef void(* select_menu_redraw_callback) (void *client_data, int x, int y, int width, int height)

Called by the select menu when it wants an area to be redrawn.

The coordinates are menu origin relative.

Parameters
client_datadata which was passed to form_open_select_menu
xX coordinate of redraw rectangle
yY coordinate of redraw rectangle
widthwidth of redraw rectangle
heightheight of redraw rectangle

Definition at line 152 of file form_internal.h.

Enumeration Type Documentation

◆ form_control_type

Type of a struct form_control.

Enumerator
GADGET_HIDDEN 
GADGET_TEXTBOX 
GADGET_RADIO 
GADGET_CHECKBOX 
GADGET_SELECT 
GADGET_TEXTAREA 
GADGET_IMAGE 
GADGET_PASSWORD 
GADGET_SUBMIT 
GADGET_RESET 
GADGET_FILE 
GADGET_BUTTON 

Definition at line 47 of file form_internal.h.

◆ form_method

Form submit method.

Enumerator
method_GET 

GET, always url encoded.

method_POST_URLENC 

POST, url encoded.

method_POST_MULTIPART 

POST, multipart/form-data.

Definition at line 121 of file form_internal.h.

Function Documentation

◆ 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_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_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_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_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: