summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-11-13 21:52:08 +0000
committerVincent Sanders <vince@kyllikki.org>2014-11-13 21:52:08 +0000
commit79e501075a0c301f435cf579518900e393be6fbf (patch)
tree2a75077894650e493c95d1062cc4945980985309 /render
parent9fde3502b659d3858cd1978d2c6535c57efbe924 (diff)
downloadnetsurf-79e501075a0c301f435cf579518900e393be6fbf.tar.gz
netsurf-79e501075a0c301f435cf579518900e393be6fbf.tar.bz2
make the form select menu API smaller.
By hiding all but the form selection menu option structure from code outside of render this reduces the API to the absolute minimum to support this feature.
Diffstat (limited to 'render')
-rw-r--r--render/form.c20
-rw-r--r--render/form.h112
-rw-r--r--render/form_internal.h88
-rw-r--r--render/layout.c2
4 files changed, 129 insertions, 93 deletions
diff --git a/render/form.c b/render/form.c
index 94cbcfcd3..7c90a5250 100644
--- a/render/form.c
+++ b/render/form.c
@@ -1332,6 +1332,26 @@ nserror form_select_process_selection(struct form_control *control, int item)
return form__select_process_selection(control->html, control, item);
}
+/* exported interface documented in render/form.h */
+struct form_option *
+form_select_get_option(struct form_control *control, int item)
+{
+ struct form_option *opt;
+
+ opt = control->data.select.items;
+ while ((opt != NULL) && (item > 0)) {
+ opt = opt->next;
+ item--;
+ }
+ return opt;
+}
+
+/* exported interface documented in render/form.h */
+char *form_control_get_name(struct form_control *control)
+{
+ return control->name;
+}
+
/**
* Handle a click on the area of the currently opened select menu.
*
diff --git a/render/form.h b/render/form.h
index eefa5ae37..82e02f61a 100644
--- a/render/form.h
+++ b/render/form.h
@@ -25,49 +25,11 @@
#ifndef _NETSURF_RENDER_FORM_H_
#define _NETSURF_RENDER_FORM_H_
-#include <stdbool.h>
-
-struct box;
struct form_control;
-struct form_option;
-struct form_select_menu;
-struct form;
-struct html_content;
-struct dom_string;
-struct content;
-struct nsurl;
-struct fetch_multipart_data;
-struct redraw_context;
-struct browser_window;
-
-enum browser_mouse_state;
-
-
-
-/** 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,
- GADGET_FILE,
- GADGET_BUTTON
-} form_control_type;
-
-/** Data for textarea */
-struct form_textarea_data {
- struct form_control *gadget;
-};
/** Option in a select. */
struct form_option {
- void *node; /**< Corresponding DOM node */
+ void *node; /**< Corresponding DOM node */
bool selected;
bool initial_selected;
char *value;
@@ -75,63 +37,29 @@ struct form_option {
struct form_option* next;
};
-struct image_input_coords {
- int x;
- int y;
-};
-
-/** Form control. */
-struct form_control {
- void *node; /**< Corresponding DOM node */
- struct html_content *html; /**< HTML content containing control */
-
- 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 */
-
- union {
- struct {
- int mx, my;
- } 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;
- struct form_select_menu *menu;
- } select;
- struct {
- struct textarea *ta;
- struct dom_string *initial;
- struct form_textarea_data data;
- } text; /**< input type=text or textarea */
- } data;
-
- struct form_control *prev; /**< Previous control in this form */
- struct form_control *next; /**< Next control in this form. */
-};
-
-
/**
* Process a selection from a form select menu.
*
- * \param control form control with menu
- * \param item index of item selected from the menu
+ * \param control form control with menu.
+ * \param item index of item selected from the menu.
*/
nserror form_select_process_selection(struct form_control *control, int item);
+/**
+ * get a form select menus option.
+ *
+ * \param control The form control.
+ * \param item The index of the menu entry to return.
+ * \return The form option at that index.
+ */
+struct form_option *form_select_get_option(struct form_control *control, int item);
+
+/**
+ * Get a form control name
+ *
+ * \param control The form control
+ * \return The form control name
+ */
+char *form_control_get_name(struct form_control *control);
+
#endif
diff --git a/render/form_internal.h b/render/form_internal.h
index 07512b508..ea46b6a78 100644
--- a/render/form_internal.h
+++ b/render/form_internal.h
@@ -26,6 +26,94 @@
#include "render/form.h"
+#include <stdbool.h>
+
+struct box;
+struct form_control;
+struct form_option;
+struct form_select_menu;
+struct form;
+struct html_content;
+struct dom_string;
+struct content;
+struct nsurl;
+struct fetch_multipart_data;
+struct redraw_context;
+struct browser_window;
+
+enum browser_mouse_state;
+
+/** 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,
+ GADGET_FILE,
+ GADGET_BUTTON
+} form_control_type;
+
+/** Data for textarea */
+struct form_textarea_data {
+ struct form_control *gadget;
+};
+
+struct image_input_coords {
+ int x;
+ int y;
+};
+
+/** Form control. */
+struct form_control {
+ void *node; /**< Corresponding DOM node */
+ struct html_content *html; /**< HTML content containing control */
+
+ 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 */
+
+ union {
+ struct {
+ int mx, my;
+ } 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;
+ struct form_select_menu *menu;
+ } select;
+ struct {
+ struct textarea *ta;
+ struct dom_string *initial;
+ struct form_textarea_data data;
+ } text; /**< input type=text or textarea */
+ } data;
+
+ struct form_control *prev; /**< Previous control in this form */
+ struct form_control *next; /**< Next control in this form. */
+};
+
/** Form submit method. */
typedef enum {
method_GET, /**< GET, always url encoded. */
diff --git a/render/layout.c b/render/layout.c
index 888c2f70a..67e3219ca 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -56,7 +56,7 @@
#include "render/box.h"
#include "render/font.h"
-#include "render/form.h"
+#include "render/form_internal.h"
#include "render/html_internal.h"
#include "render/layout.h"
#include "render/table.h"