NetSurf
html_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
3  *
4  * This file is part of NetSurf, http://www.netsurf-browser.org/
5  *
6  * NetSurf is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * NetSurf is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /**
20  * \file
21  * Private data for text/html content.
22  */
23 
24 #ifndef NETSURF_HTML_HTML_INTERNAL_H
25 #define NETSURF_HTML_HTML_INTERNAL_H
26 
27 #include <libcss/libcss.h>
28 #include <dom/bindings/hubbub/parser.h>
29 
30 #include "netsurf/types.h"
32 #include "desktop/selection.h"
33 
34 
35 struct gui_layout_table;
36 struct scrollbar_msg_data;
37 struct content_redraw_data;
38 
39 typedef enum {
40  HTML_DRAG_NONE, /** No drag */
41  HTML_DRAG_SELECTION, /** Own; Text selection */
42  HTML_DRAG_SCROLLBAR, /** Not own; drag in scrollbar widget */
43  HTML_DRAG_TEXTAREA_SELECTION, /** Not own; drag in textarea widget */
44  HTML_DRAG_TEXTAREA_SCROLLBAR, /** Not own; drag in textarea widget */
45  HTML_DRAG_CONTENT_SELECTION, /** Not own; drag in child content */
46  HTML_DRAG_CONTENT_SCROLL /** Not own; drag in child content */
48 
49 /**
50  * For drags we don't own
51  */
53  bool no_owner;
54  struct box *content;
56  struct box *textarea;
57 };
58 
59 typedef enum {
60  HTML_SELECTION_NONE, /** No selection */
61  HTML_SELECTION_TEXTAREA, /** Selection in one of our textareas */
62  HTML_SELECTION_SELF, /** Selection in this html content */
63  HTML_SELECTION_CONTENT /** Selection in child content */
65 
66 /**
67  * For getting at selections in this content or things in this content
68  */
70  bool none;
71  struct box *textarea;
72  struct box *content;
73 };
74 
75 typedef enum {
76  HTML_FOCUS_SELF, /**< Focus is our own */
77  HTML_FOCUS_CONTENT, /**< Focus belongs to child content */
78  HTML_FOCUS_TEXTAREA /**< Focus belongs to textarea */
80 
81 /**
82  * For directing input
83  */
85  bool self;
86  struct box *textarea;
87  struct box *content;
88 };
89 
90 /**
91  * Data specific to CONTENT_HTML.
92  */
93 typedef struct html_content {
94  struct content base;
95 
96  dom_hubbub_parser *parser; /**< Parser object handle */
97  bool parse_completed; /**< Whether the parse has been completed */
98  bool conversion_begun; /**< Whether or not the conversion has begun */
99 
100  /** Document tree */
101  dom_document *document;
102  /** Quirkyness of document */
103  dom_document_quirks_mode quirks;
104 
105  /** Encoding of source, NULL if unknown. */
106  char *encoding;
107  /** Source of encoding information. */
108  dom_hubbub_encoding_source encoding_source;
109 
110  /** Base URL (may be a copy of content->url). */
112  /** Base target */
113  char *base_target;
114 
115  /** CSS length conversion context for document. */
117 
118  /** Content has been aborted in the LOADING state */
119  bool aborted;
120 
121  /** Whether a meta refresh has been handled */
122  bool refresh;
123 
124  /** Whether a layout (reflow) is in progress */
125  bool reflowing;
126 
127  /** Whether an initial layout has been done */
129 
130  /** Whether scripts are enabled for this content */
132 
133  /* Title element node */
134  dom_node *title;
135 
136  /** A talloc context purely for the render box tree */
137  int *bctx;
138  /** A context pointer for the box conversion, NULL if no conversion
139  * is in progress.
140  */
142  /** Box tree, or NULL. */
143  struct box *layout;
144  /** Document background colour. */
146 
147  /** Font callback table */
149 
150  /** Number of entries in scripts */
151  unsigned int scripts_count;
152  /** Scripts */
154  /** javascript thread in use */
156 
157  /** Number of entries in stylesheet_content. */
158  unsigned int stylesheet_count;
159  /** Stylesheets. Each may be NULL. */
161  /**< Style selection context */
162  css_select_ctx *select_ctx;
163  /**< Style selection media specification */
164  css_media media;
165  /**< Universal selector */
166  lwc_string *universal;
167 
168  /** Number of entries in object_list. */
169  unsigned int num_objects;
170  /** List of objects. */
172  /** Forms, in reverse order to document. */
173  struct form *forms;
174  /** Hash table of imagemaps. */
175  struct imagemap **imagemaps;
176 
177  /** Browser window containing this document, or NULL if not open. */
179 
180  /** Frameset information */
182 
183  /** Inline frame information */
185 
186  /** Content of type CONTENT_HTML containing this, or NULL if not an
187  * object within a page. */
189 
190  /** Current drag type */
192  /** Widget capturing all mouse events */
193  union html_drag_owner drag_owner;
194 
195  /** Current selection state */
197  /** Current selection owner */
198  union html_selection_owner selection_owner;
199 
200  /** Current input focus target type */
202  /** Current input focus target */
203  union html_focus_owner focus_owner;
204 
205  /** HTML content's own text selection object */
206  struct selection sel;
207 
208  /** Open core-handled form SELECT menu,
209  * or NULL if none currently open. */
211 
212  /** Context for free text search, or NULL if none */
214  /** Search string or NULL */
216 
217 } html_content;
218 
219 /** Render padding and margin box outlines in html_redraw(). */
220 extern bool html_redraw_debug;
221 
222 void html__redraw_a_box(html_content *html, struct box *box);
223 
224 /**
225  * Set our drag status, and inform whatever owns the content
226  *
227  * \param html HTML content
228  * \param drag_type Type of drag
229  * \param drag_owner What owns the drag
230  * \param rect Pointer movement bounds
231  */
232 void html_set_drag_type(html_content *html, html_drag_type drag_type,
233  union html_drag_owner drag_owner, const struct rect *rect);
234 
235 /**
236  * Set our selection status, and inform whatever owns the content
237  *
238  * \param html HTML content
239  * \param selection_type Type of selection
240  * \param selection_owner What owns the selection
241  * \param read_only True iff selection is read only
242  */
243 void html_set_selection(html_content *html, html_selection_type selection_type,
244  union html_selection_owner selection_owner, bool read_only);
245 
246 /**
247  * Set our input focus, and inform whatever owns the content
248  *
249  * \param html HTML content
250  * \param focus_type Type of input focus
251  * \param focus_owner What owns the focus
252  * \param hide_caret True iff caret to be hidden
253  * \param x Carret x-coord rel to owner
254  * \param y Carret y-coord rel to owner
255  * \param height Carret height
256  * \param clip Carret clip rect
257  */
258 void html_set_focus(html_content *html, html_focus_type focus_type,
259  union html_focus_owner focus_owner, bool hide_caret,
260  int x, int y, int height, const struct rect *clip);
261 
262 
264 
265 /**
266  * Complete conversion of an HTML document
267  *
268  * \param htmlc Content to convert
269  */
271 
272 /**
273  * Test if an HTML content conversion can begin
274  *
275  * \param htmlc html content to test
276  * \return true iff the html content conversion can begin
277  */
279 
280 /**
281  * Begin conversion of an HTML document
282  *
283  * \param htmlc Content to convert
284  */
286 
287 /* in html/html_redraw.c */
288 bool html_redraw(struct content *c, struct content_redraw_data *data,
289  const struct rect *clip, const struct redraw_context *ctx);
290 
291 /* in html/html_redraw_border.c */
292 bool html_redraw_borders(struct box *box, int x_parent, int y_parent,
293  int p_width, int p_height, const struct rect *clip, float scale,
294  const struct redraw_context *ctx);
295 
296 bool html_redraw_inline_borders(struct box *box, struct rect b,
297  const struct rect *clip, float scale, bool first, bool last,
298  const struct redraw_context *ctx);
299 
300 /* in html/html_script.c */
301 dom_hubbub_error html_process_script(void *ctx, dom_node *node);
302 
303 /* in html/html.c */
304 bool html_exec(struct content *c, const char *src, size_t srclen);
305 
306 /**
307  * Attempt script execution for defer and async scripts
308  *
309  * execute scripts using algorithm found in:
310  * http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element
311  *
312  * \param htmlc html content.
313  * \param allow_defer allow deferred execution, if not, only async scripts.
314  * \return NSERROR_OK error code.
315  */
316 nserror html_script_exec(html_content *htmlc, bool allow_defer);
317 
318 /**
319  * Free all script resources and references for a html content.
320  *
321  * \param htmlc html content.
322  * \return NSERROR_OK or error code.
323  */
325 
326 /**
327  * Check if any of the scripts loaded were insecure
328  */
330 
331 /* in html/html_forms.c */
332 struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
334  dom_node *node);
335 
336 /* in html/html_css.c */
337 nserror html_css_init(void);
338 void html_css_fini(void);
339 
340 /**
341  * Initialise core stylesheets for a content
342  *
343  * \param c content structure to update
344  * \return nserror
345  */
349 
350 /** Return if any of the stylesheets were loaded insecurely */
352 
353 bool html_css_process_link(html_content *htmlc, dom_node *node);
354 bool html_css_process_style(html_content *htmlc, dom_node *node);
355 bool html_css_update_style(html_content *c, dom_node *style);
356 
358  css_select_ctx **ret_select_ctx);
359 
360 /* in html/html_css_fetcher.c */
361 /**
362  * Register the fetcher for the pseudo x-ns-css scheme.
363  *
364  * \return NSERROR_OK on successful registration or error code on failure.
365  */
367 nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url,
368  uint32_t *key);
369 
370 /**
371  * Complete the HTML content state machine *iff* all scripts are finished
372  */
374 
375 
376 /* Events */
377 /**
378  * Construct an event and fire it at the DOM
379  *
380  */
381 bool fire_generic_dom_event(dom_string *type, dom_node *target,
382  bool bubbles, bool cancelable);
383 
384 /**
385  * Construct a keyboard event and fire it at the DOM
386  */
387 bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
388  bool bubbles, bool cancelable, uint32_t key);
389 
390 /* Useful dom_string pointers */
391 struct dom_string;
392 
393 extern struct dom_string *html_dom_string_map;
394 extern struct dom_string *html_dom_string_id;
395 extern struct dom_string *html_dom_string_name;
396 extern struct dom_string *html_dom_string_area;
397 extern struct dom_string *html_dom_string_a;
398 extern struct dom_string *html_dom_string_nohref;
399 extern struct dom_string *html_dom_string_href;
400 extern struct dom_string *html_dom_string_target;
401 extern struct dom_string *html_dom_string_shape;
402 extern struct dom_string *html_dom_string_default;
403 extern struct dom_string *html_dom_string_rect;
404 extern struct dom_string *html_dom_string_rectangle;
405 extern struct dom_string *html_dom_string_coords;
406 extern struct dom_string *html_dom_string_circle;
407 extern struct dom_string *html_dom_string_poly;
408 extern struct dom_string *html_dom_string_polygon;
409 extern struct dom_string *html_dom_string_text_javascript;
410 extern struct dom_string *html_dom_string_type;
411 extern struct dom_string *html_dom_string_src;
412 
413 #endif
bool html_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Draw a CONTENT_HTML using the current set of plotters (plot).
Definition: redraw.c:1904
struct dom_string * html_dom_string_area
Focus is our own.
Definition: html_internal.h:76
nserror html_css_fetcher_register(void)
Register the fetcher for the pseudo x-ns-css scheme.
Definition: css_fetcher.c:286
struct box * content
Definition: html_internal.h:54
nserror html_script_free(html_content *htmlc)
Free all script resources and references for a html content.
Definition: script.c:637
bool fire_dom_keyboard_event(dom_string *type, dom_node *target, bool bubbles, bool cancelable, uint32_t key)
Construct a keyboard event and fire it at the DOM.
Definition: html.c:129
struct dom_string * html_dom_string_text_javascript
NetSurf types.
struct imagemap ** imagemaps
Hash table of imagemaps.
unsigned int num_objects
Number of entries in object_list.
void html_set_focus(html_content *html, html_focus_type focus_type, union html_focus_owner focus_owner, bool hide_caret, int x, int y, int height, const struct rect *clip)
Set our input focus, and inform whatever owns the content.
Definition: interaction.c:1763
struct dom_string * html_dom_string_name
css_media media
Universal selector.
const struct gui_layout_table * font_func
Font callback table.
Inline frame list (iframe tag)
Definition: html.h:131
bool html_saw_insecure_stylesheets(html_content *html)
Return if any of the stylesheets were loaded insecurely.
Definition: css.c:492
struct dom_string * html_dom_string_nohref
Not own; drag in textarea widget.
Definition: html_internal.h:44
nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url, uint32_t *key)
Definition: css_fetcher.c:305
struct form_textarea_data data
nserror html_css_free_stylesheets(html_content *html)
Definition: css.c:510
struct form_control * visible_select_menu
Open core-handled form SELECT menu, or NULL if none currently open.
struct dom_string * html_dom_string_map
nserror html_proceed_to_done(html_content *html)
Complete the HTML content state machine iff all scripts are finished.
Definition: html.c:281
html_drag_type drag_type
Current drag type.
struct html_stylesheet * stylesheets
Stylesheets.
struct form * forms
Forms, in reverse order to document.
bool conversion_begun
Whether or not the conversion has begun.
Definition: html_internal.h:98
Focus belongs to child content.
Definition: html_internal.h:77
Own; Text selection.
Definition: html_internal.h:42
struct box * content
Definition: html_internal.h:87
nserror html_css_quirks_stylesheets(html_content *c)
Definition: css.c:530
struct jsthread * jsthread
javascript thread in use
struct box * layout
Box tree, or NULL.
Length conversion context data.
Definition: utils.h:35
struct dom_string * html_dom_string_circle
struct form * html_forms_get_forms(const char *docenc, dom_html_document *doc)
Definition: forms.c:124
html_focus_type focus_type
Current input focus target type.
scrollbar message context data
Definition: scrollbar.h:59
const char * type
Definition: filetype.cpp:44
void html_set_drag_type(html_content *html, html_drag_type drag_type, union html_drag_owner drag_owner, const struct rect *rect)
Set our drag status, and inform whatever owns the content.
Definition: interaction.c:1726
bool fire_generic_dom_event(dom_string *type, dom_node *target, bool bubbles, bool cancelable)
Construct an event and fire it at the DOM.
Definition: html.c:107
bool html_begin_conversion(html_content *htmlc)
Begin conversion of an HTML document.
Definition: html.c:1461
struct dom_string * html_dom_string_href
struct form_control * html_forms_get_control_for_node(struct form *forms, dom_node *node)
Definition: forms.c:542
bool html_css_process_link(html_content *htmlc, dom_node *node)
Definition: css.c:371
bool html_css_update_style(html_content *c, dom_node *style)
Definition: css.c:313
int * bctx
A talloc context purely for the render box tree.
bool html_exec(struct content *c, const char *src, size_t srclen)
Definition: html.c:2713
nserror
Enumeration of error codes.
Definition: errors.h:29
bool html_redraw_inline_borders(struct box *box, struct rect b, const struct rect *clip, float scale, bool first, bool last, const struct redraw_context *ctx)
Draw an inline&#39;s borders.
dom_hubbub_encoding_source encoding_source
Source of encoding information.
struct dom_string * html_dom_string_rectangle
void html_set_selection(html_content *html, html_selection_type selection_type, union html_selection_owner selection_owner, bool read_only)
Set our selection status, and inform whatever owns the content.
Definition: interaction.c:1821
HTML form.
nserror html_css_init(void)
Definition: css.c:689
Corresponds to a single URL.
html_selection_type
Definition: html_internal.h:59
dom_document * document
Document tree.
bool reflowing
Whether a layout (reflow) is in progress.
Selection in one of our textareas.
Definition: html_internal.h:62
nserror html_css_new_selection_context(html_content *c, css_select_ctx **ret_select_ctx)
Definition: css.c:628
struct dom_string * html_dom_string_a
html_selection_type selection_type
Current selection state.
dom_hubbub_error html_process_script(void *ctx, dom_node *node)
process script node parser callback
Definition: script.c:567
struct dom_string * html_dom_string_shape
dom_node * title
Not own; drag in child content.
Definition: html_internal.h:46
bool refresh
Whether a meta refresh has been handled.
Selection in this html content.
Definition: html_internal.h:63
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
lwc_string * universal
bool html_redraw_borders(struct box *box, int x_parent, int y_parent, int p_width, int p_height, const struct rect *clip, float scale, const struct redraw_context *ctx)
Draw borders for a box.
char * search_string
Search string or NULL.
Focus belongs to textarea.
Definition: html_internal.h:78
Not own; drag in scrollbar widget.
Definition: html_internal.h:43
nserror html_script_exec(html_content *htmlc, bool allow_defer)
Attempt script execution for defer and async scripts.
Definition: script.c:58
html_focus_type
Definition: html_internal.h:75
struct dom_string * html_dom_string_type
For drags we don&#39;t own.
Definition: html_internal.h:52
struct dom_string * html_dom_string_src
For directing input.
Definition: html_internal.h:84
struct box * textarea
Definition: html_internal.h:86
struct search_context * search
Context for free text search, or NULL if none.
Redraw context.
Definition: plotters.h:51
Form control.
Definition: form_internal.h:73
parameters to content redraw
Definition: content.h:40
void * box_conversion_context
A context pointer for the box conversion, NULL if no conversion is in progress.
bool html_css_process_style(html_content *htmlc, dom_node *node)
Definition: css.c:340
Container for stylesheets used by an HTML document.
Definition: html.h:58
struct content_html_iframe * iframe
Inline frame information.
int height
Definition: gui.c:180
void html_css_fini(void)
Definition: css.c:718
dukky javascript thread
Definition: dukky.c:70
dom_hubbub_parser * parser
Parser object handle.
Definition: html_internal.h:96
Not own; drag in textarea widget.
Definition: html_internal.h:45
void html_finish_conversion(html_content *htmlc)
Complete conversion of an HTML document.
Definition: html.c:720
nsurl * base_url
Base URL (may be a copy of content->url).
Rectangle coordinates.
Definition: types.h:40
struct html_content * page
Content of type CONTENT_HTML containing this, or NULL if not an object within a page.
struct html_content html_content
Data specific to CONTENT_HTML.
struct browser_window * bw
Browser window containing this document, or NULL if not open.
Scrollbar context.
Definition: scrollbar.c:44
bool html_redraw_debug
Render padding and margin box outlines in html_redraw().
Definition: redraw.c:66
unsigned int stylesheet_count
Number of entries in stylesheet_content.
struct dom_string * html_dom_string_coords
Frame tree (frameset or frame tag)
Definition: html.h:108
struct dom_string * html_dom_string_default
bool aborted
Content has been aborted in the LOADING state.
bool html_can_begin_conversion(html_content *htmlc)
Test if an HTML content conversion can begin.
Definition: html.c:1442
An object (img, object, etc.
Definition: html.h:93
struct html_script * scripts
Scripts.
bool html_saw_insecure_scripts(html_content *htmlc)
Check if any of the scripts loaded were insecure.
Definition: script.c:612
float scale
scale of window contents
char * base_target
Base target.
struct dom_string * html_dom_string_poly
Text selection within browser windows (interface).
void * node
Corresponding DOM node.
Definition: form_internal.h:74
struct dom_string * html_dom_string_id
struct box * content
Definition: html_internal.h:72
struct box * textarea
Definition: html_internal.h:71
nscss_len_ctx len_ctx
CSS length conversion context for document.
Browser window data.
struct box * textarea
Definition: html_internal.h:56
char * encoding
Encoding of source, NULL if unknown.
bool enable_scripting
Whether scripts are enabled for this content.
css_select_ctx * select_ctx
Style selection media specification.
struct browser_window * html_get_browser_window(struct content *c)
Get the browser window containing an HTML content.
Definition: html.c:2903
struct dom_string * html_dom_string_rect
Data specific to CONTENT_HTML.
Definition: html_internal.h:93
struct scrollbar * scrollbar
Definition: html_internal.h:55
struct html_content * html
HTML content containing control.
Definition: form_internal.h:77
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357
dom_document_quirks_mode quirks
Quirkyness of document.
unsigned int scripts_count
Number of entries in scripts.
colour background_colour
Document background colour.
struct dom_string * html_dom_string_target
Container for scripts used by an HTML document.
Definition: html.h:69
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Protected interface to Content handling.
For getting at selections in this content or things in this content.
Definition: html_internal.h:69
struct content_html_frames * frameset
Frameset information.
struct content_html_object * object_list
List of objects.
bool parse_completed
Whether the parse has been completed.
Definition: html_internal.h:97
html_drag_type
Definition: html_internal.h:39
struct dom_string * html_dom_string_polygon
void html__redraw_a_box(html_content *html, struct box *box)
Redraw a box.
Definition: html.c:1756
Definition: punycode.c:19
bool had_initial_layout
Whether an initial layout has been done.
Node in box tree.
Definition: box.h:175
nserror html_css_new_stylesheets(html_content *c)
Initialise core stylesheets for a content.
Definition: css.c:558