Subversion Repositories Kolibri OS

Rev

Rev 3584 | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
  3.  * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
  4.  * Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
  5.  *
  6.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  7.  *
  8.  * NetSurf is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; version 2 of the License.
  11.  *
  12.  * NetSurf is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  */
  20.  
  21. /** \file
  22.  * Form handling functions (interface).
  23.  */
  24.  
  25. #ifndef _NETSURF_RENDER_FORM_H_
  26. #define _NETSURF_RENDER_FORM_H_
  27.  
  28. #include <stdbool.h>
  29. #include "desktop/browser.h"
  30. #include "utils/config.h"
  31.  
  32. struct box;
  33. struct form_control;
  34. struct form_option;
  35. struct form_select_menu;
  36. struct html_content;
  37.  
  38. /** Form submit method. */
  39. typedef enum {
  40.         method_GET,             /**< GET, always url encoded. */
  41.         method_POST_URLENC,     /**< POST, url encoded. */
  42.         method_POST_MULTIPART   /**< POST, multipart/form-data. */
  43. } form_method;
  44.  
  45. /** HTML form. */
  46. struct form {
  47.         void *node;                     /**< Corresponding DOM node */
  48.  
  49.         char *action;                   /**< Absolute URL to submit to. */
  50.         char *target;                   /**< Target to submit to. */
  51.         form_method method;             /**< Method and enctype. */
  52.         char *accept_charsets;          /**< Charset to submit form in */
  53.         char *document_charset;         /**< Charset of document containing form */
  54.         struct form_control *controls;  /**< Linked list of controls. */
  55.         struct form_control *last_control;      /**< Last control in list. */
  56.  
  57.         struct form *prev;              /**< Previous form in doc. */
  58. };
  59.  
  60. /** Type of a struct form_control. */
  61. typedef enum {
  62.         GADGET_HIDDEN,
  63.         GADGET_TEXTBOX,
  64.         GADGET_RADIO,
  65.         GADGET_CHECKBOX,
  66.         GADGET_SELECT,
  67.         GADGET_TEXTAREA,
  68.         GADGET_IMAGE,
  69.         GADGET_PASSWORD,
  70.         GADGET_SUBMIT,
  71.         GADGET_RESET,
  72.         GADGET_FILE,
  73.         GADGET_BUTTON
  74. } form_control_type;
  75.  
  76. /** Form control. */
  77. struct form_control {
  78.         void *node;                     /**< Corresponding DOM node */
  79.  
  80.         form_control_type type;         /**< Type of control */
  81.  
  82.         struct form *form;              /**< Containing form */
  83.  
  84.         char *name;                     /**< Control name */
  85.         char *value;                    /**< Current value of control */
  86.         char *initial_value;            /**< Initial value of control */
  87.         bool disabled;                  /**< Whether control is disabled */
  88.  
  89.         struct box *box;                /**< Box for control */
  90.         /** Caret details. */
  91.         struct box *caret_inline_container;
  92.         struct box *caret_text_box;
  93.         size_t caret_box_offset, caret_form_offset;
  94.         int caret_pixel_offset;
  95.  
  96.         unsigned int length;            /**< Number of characters in control */
  97.         unsigned int maxlength;         /**< Maximum characters permitted */
  98.  
  99.         bool selected;                  /**< Whether control is selected */
  100.  
  101.         union {
  102.                 struct {
  103.                         int mx, my;
  104.                 } image;
  105.                 struct {
  106.                         int num_items;
  107.                         struct form_option *items, *last_item;
  108.                         bool multiple;
  109.                         int num_selected;
  110.                         /** Currently selected item, if num_selected == 1. */
  111.                         struct form_option *current;
  112.                         struct form_select_menu *menu;
  113.                 } select;
  114.         } data;
  115.  
  116.         struct form_control *prev;      /**< Previous control in this form */
  117.         struct form_control *next;      /**< Next control in this form. */
  118. };
  119.  
  120. /** Option in a select. */
  121. struct form_option {
  122.         bool selected;
  123.         bool initial_selected;
  124.         char *value;
  125.         char *text; /**< NUL terminated. */
  126.         struct form_option* next;
  127. };
  128.  
  129. /**
  130.  * Called by the select menu when it wants an area to be redrawn. The
  131.  * coordinates are menu origin relative.
  132.  *
  133.  * \param client_data   data which was passed to form_open_select_menu
  134.  * \param x             X coordinate of redraw rectangle
  135.  * \param y             Y coordinate of redraw rectangle
  136.  * \param width         width of redraw rectangle
  137.  * \param height        height of redraw rectangle
  138.  */
  139. typedef void(*select_menu_redraw_callback)(void *client_data,
  140.                 int x, int y, int width, int height);
  141.  
  142. struct form *form_new(void *node, const char *action, const char *target,
  143.                 form_method method, const char *charset,
  144.                 const char *doc_charset);
  145. void form_free(struct form *form);
  146. struct form_control *form_new_control(void *node, form_control_type type);
  147. void form_add_control(struct form *form, struct form_control *control);
  148. void form_free_control(struct form_control *control);
  149. bool form_add_option(struct form_control *control, char *value, char *text,
  150.                 bool selected);
  151. bool form_successful_controls(struct form *form,
  152.                 struct form_control *submit_button,
  153.                 struct fetch_multipart_data **successful_controls);
  154.  
  155. bool form_open_select_menu(void *client_data,
  156.                 struct form_control *control,
  157.                 select_menu_redraw_callback redraw_callback,
  158.                 struct content *c);
  159. void form_select_menu_callback(void *client_data,
  160.                 int x, int y, int width, int height);
  161. void form_free_select_menu(struct form_control *control);
  162. bool form_redraw_select_menu(struct form_control *control, int x, int y,
  163.                 float scale, const struct rect *clip,
  164.                 const struct redraw_context *ctx);
  165. bool form_clip_inside_select_menu(struct form_control *control, float scale,
  166.                 const struct rect *clip);
  167. const char *form_select_mouse_action(struct form_control *control,
  168.                 browser_mouse_state mouse, int x, int y);
  169. void form_select_mouse_drag_end(struct form_control *control,
  170.                 browser_mouse_state mouse, int x, int y);
  171. void form_select_get_dimensions(struct form_control *control,
  172.                 int *width, int *height);
  173. void form_select_process_selection(hlcache_handle *h,
  174.                 struct form_control *control, int item);
  175. void form_submit(nsurl *page_url, struct browser_window *target,
  176.                 struct form *form, struct form_control *submit_button);
  177. void form_radio_set(struct html_content *html, struct form_control *radio);
  178.  
  179. #endif
  180.