summaryrefslogtreecommitdiff
path: root/src/html.hh
blob: 2d9202e6cb8974ac4e865ef393fe7a1c05fd2013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#ifndef __HTML_HH__
#define __HTML_HH__

#include "d_size.h"            // for uchar_t
#include "bw.h"                // for BrowserWindow

#include "dw/core.hh"
#include "lout/misc.hh"        // For SimpleVector

//#include "dw_image.h"        // for DwImageMapList

#include "form.hh"             // For receiving the "clicked" signal

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/*
 * First, the html linkblock. For now, this mostly has forms, although
 * pointers to actual links will go here soon, if for no other reason
 * than to implement history-sensitive link colors. Also, it seems
 * likely that imagemaps will go here.
 */

typedef struct _DilloHtmlLB      DilloHtmlLB;

typedef struct _DilloHtml        DilloHtml;
typedef struct _DilloHtmlClass   DilloHtmlClass;
typedef struct _DilloHtmlState   DilloHtmlState;
typedef struct _DilloHtmlForm    DilloHtmlForm;
typedef struct _DilloHtmlOption  DilloHtmlOption;
typedef struct _DilloHtmlSelect  DilloHtmlSelect;
typedef struct _DilloHtmlInput   DilloHtmlInput;


struct _DilloHtmlLB {
   class HtmlLinkReceiver: public dw::core::Widget::LinkReceiver
   {
   private:
      DilloHtmlLB *lb;

   public:
      inline HtmlLinkReceiver (DilloHtmlLB *lb) { this->lb = lb; }

      bool enter (dw::core::Widget *widget, int link, int x, int y);
      bool press (dw::core::Widget *widget, int link, int x, int y,
                  dw::core::EventButton *event);
      bool click (dw::core::Widget *widget, int link, int x, int y,
                  dw::core::EventButton *event);
   };

   // Since DilloHtmlLB is a struct, not a class, a simple
   // "HtmlLinkReceiver linkReceiver" (see signal documentation) would not
   // work, therefore the pointer.
   HtmlLinkReceiver *linkReceiver;

   BrowserWindow *bw;
   DilloUrl *base_url;

   misc::SimpleVector<DilloHtmlForm> *forms;

   misc::SimpleVector<DilloUrl*> *links;

   //DwImageMapList maps;

   int32_t link_color;
   int32_t visited_color;
};


typedef enum {
   DT_NONE,           
   DT_HTML,           
   DT_XHTML
} DilloHtmlDocumentType;

typedef enum {
   DILLO_HTML_PARSE_MODE_INIT = 0,
   DILLO_HTML_PARSE_MODE_STASH,
   DILLO_HTML_PARSE_MODE_STASH_AND_BODY,
   DILLO_HTML_PARSE_MODE_VERBATIM,
   DILLO_HTML_PARSE_MODE_BODY,
   DILLO_HTML_PARSE_MODE_PRE
} DilloHtmlParseMode;

typedef enum {
   SEEK_ATTR_START,
   MATCH_ATTR_NAME,
   SEEK_TOKEN_START,
   SEEK_VALUE_START,
   SKIP_VALUE,
   GET_VALUE,
   FINISHED
} DilloHtmlTagParsingState;

typedef enum {
   HTML_LeftTrim      = 1 << 0,
   HTML_RightTrim     = 1 << 1,
   HTML_ParseEntities = 1 << 2
} DilloHtmlTagParsingFlags;

typedef enum {
   DILLO_HTML_TABLE_MODE_NONE,  /* no table at all */
   DILLO_HTML_TABLE_MODE_TOP,   /* outside of <tr> */
   DILLO_HTML_TABLE_MODE_TR,    /* inside of <tr>, outside of <td> */
   DILLO_HTML_TABLE_MODE_TD     /* inside of <td> */
} DilloHtmlTableMode;

typedef enum {
   HTML_LIST_NONE,
   HTML_LIST_UNORDERED,
   HTML_LIST_ORDERED
} DilloHtmlListMode;

enum DilloHtmlProcessingState {
   IN_NONE        = 0,
   IN_HTML        = 1 << 0,
   IN_HEAD        = 1 << 1,
   IN_BODY        = 1 << 2,
   IN_FORM        = 1 << 3,
   IN_SELECT      = 1 << 4,
   IN_TEXTAREA    = 1 << 5,
   IN_MAP         = 1 << 6,
   IN_PRE         = 1 << 7,
   IN_BUTTON      = 1 << 8
};


struct _DilloHtmlState {
   char *tag_name;
   //DwStyle *style, *table_cell_style;
   dw::core::style::Style *style, *table_cell_style;
   DilloHtmlParseMode parse_mode;
   DilloHtmlTableMode table_mode;
   bool_t cell_text_align_set;
   DilloHtmlListMode list_type;
   int list_number;

   /* TagInfo index for the tag that's being processed */
   int tag_idx;

   dw::core::Widget *textblock, *table;

   /* This is used to align list items (especially in enumerated lists) */
   dw::core::Widget *ref_list_item;

   /* This makes image processing faster than a function
      a_Dw_widget_get_background_color. */
   int32_t current_bg_color;

   /* This is used for list items etc; if it is set to TRUE, breaks
      have to be "handed over" (see Html_add_indented and
      Html_eventually_pop_dw). */
   bool_t hand_over_break;
};

typedef enum {
   DILLO_HTML_METHOD_UNKNOWN,
   DILLO_HTML_METHOD_GET,
   DILLO_HTML_METHOD_POST
} DilloHtmlMethod;

typedef enum {
   DILLO_HTML_ENC_URLENCODING
} DilloHtmlEnc;

struct _DilloHtmlForm {
   DilloHtmlMethod method;
   DilloUrl *action;
   DilloHtmlEnc enc;

   misc::SimpleVector<DilloHtmlInput> *inputs;

   int num_entry_fields;
   int num_submit_buttons;

   form::Form *form_receiver;
};

struct _DilloHtmlOption {
   //GtkWidget *menuitem;
   char *value;
   bool_t init_val;
};

struct _DilloHtmlSelect {
   //GtkWidget *menu;
   int size;

   DilloHtmlOption *options;
   int num_options;
   int num_options_max;
};

typedef enum {
   DILLO_HTML_INPUT_UNKNOWN,
   DILLO_HTML_INPUT_TEXT,
   DILLO_HTML_INPUT_PASSWORD,
   DILLO_HTML_INPUT_CHECKBOX,
   DILLO_HTML_INPUT_RADIO,
   DILLO_HTML_INPUT_IMAGE,
   DILLO_HTML_INPUT_FILE,
   DILLO_HTML_INPUT_BUTTON,
   DILLO_HTML_INPUT_HIDDEN,
   DILLO_HTML_INPUT_SUBMIT,
   DILLO_HTML_INPUT_RESET,
   DILLO_HTML_INPUT_BUTTON_SUBMIT,
   DILLO_HTML_INPUT_BUTTON_RESET,
   DILLO_HTML_INPUT_SELECT,
   DILLO_HTML_INPUT_SEL_LIST,
   DILLO_HTML_INPUT_TEXTAREA,
   DILLO_HTML_INPUT_INDEX
} DilloHtmlInputType;

struct _DilloHtmlInput {
   DilloHtmlInputType type;
   void *widget;      /* May be a FLTKWidget or a Dw Widget. */
   void *embed;       /* May be NULL */
   char *name;
   char *init_str;    /* note: some overloading - for buttons, init_str
                         is simply the value of the button; for text
                         entries, it is the initial value */
   DilloHtmlSelect *select;
   bool_t init_val;   /* only meaningful for buttons */
};

struct _DilloHtml {
   dw::core::Widget *dw;    /* this is duplicated in the stack (page) */

   DilloHtmlLB *linkblock;
   char *Start_Buf;
   size_t Start_Ofs;
   size_t CurrTagOfs;
   size_t OldTagOfs, OldTagLine;

   DilloHtmlDocumentType DocType; /* as given by DOCTYPE tag */
   float DocTypeVersion;          /* HTML or XHTML version number */

   misc::SimpleVector<DilloHtmlState> *stack;

   int InFlags; /* tracks which tags we are in */

   Dstr *Stash;
   bool_t StashSpace;

   char *SPCBuf;           /* Buffer for white space */

   int pre_column;         /* current column, used in PRE tags with tabs */
   bool_t PreFirstChar;   /* used to skip the first CR or CRLF in PRE tags */
   bool_t PrevWasCR;      /* Flag to help parsing of "\r\n" in PRE tags */
   bool_t PrevWasOpenTag; /* Flag to help deferred parsing of white space */
   bool_t SPCPending;     /* Flag to help deferred parsing of white space */
   bool_t InVisitedLink;  /* used to 'contrast_visited_colors' */
   bool_t ReqTagClose;    /* Flag to help handling bad-formed HTML */
   bool_t CloseOneTag;    /* Flag to help Html_tag_cleanup_at_close() */
   bool_t TagSoup;        /* Flag to enable the parser's cleanup functions */
   char *NameVal;          /* used for validation of "NAME" and "ID" in <A> */

   /* element counters: used for validation purposes */
   uchar_t Num_HTML, Num_HEAD, Num_BODY, Num_TITLE;

   Dstr *attr_data;

   BrowserWindow *bw;
};

/*
 * Exported functions
 */
void a_Html_form_event_handler(void *data,
                               form::Form *form_receiver,
                               void *v_resource);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __HTML_HH__ */