NetSurf
html.c
Go to the documentation of this file.
1/*
2 * Copyright 2007 James Bursa <bursa@users.sourceforge.net>
3 * Copyright 2010 Michael Drake <tlsa@netsurf-browser.org>
4 *
5 * This file is part of NetSurf, http://www.netsurf-browser.org/
6 *
7 * NetSurf is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * NetSurf is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * \file
22 * Implementation of HTML content handling.
23 */
24
25#include <assert.h>
26#include <stdint.h>
27#include <string.h>
28#include <strings.h>
29#include <stdlib.h>
30#include <nsutils/time.h>
31
32#include "utils/utils.h"
33#include "utils/config.h"
34#include "utils/corestrings.h"
35#include "utils/http.h"
36#include "utils/libdom.h"
37#include "utils/log.h"
38#include "utils/messages.h"
39#include "utils/talloc.h"
40#include "utils/utf8.h"
41#include "utils/nsoption.h"
42#include "utils/string.h"
43#include "utils/ascii.h"
44#include "netsurf/content.h"
46#include "netsurf/utf8.h"
47#include "netsurf/keypress.h"
48#include "netsurf/layout.h"
49#include "netsurf/misc.h"
50#include "content/hlcache.h"
52#include "content/textsearch.h"
53#include "desktop/selection.h"
54#include "desktop/scrollbar.h"
55#include "desktop/textarea.h"
56#include "netsurf/bitmap.h"
57#include "javascript/js.h"
59
60#include "html/html.h"
61#include "html/private.h"
62#include "html/dom_event.h"
63#include "html/css.h"
64#include "html/object.h"
65#include "html/html_save.h"
66#include "html/interaction.h"
67#include "html/box.h"
68#include "html/box_construct.h"
69#include "html/box_inspect.h"
70#include "html/form_internal.h"
71#include "html/imagemap.h"
72#include "html/layout.h"
73#include "html/textselection.h"
74
75#define CHUNK 4096
76
77/* Change these to 1 to cause a dump to stderr of the frameset or box
78 * when the trees have been built.
79 */
80#define ALWAYS_DUMP_FRAMESET 0
81#define ALWAYS_DUMP_BOX 0
82
83static const char *html_types[] = {
84 "application/xhtml+xml",
85 "text/html"
86};
87
88/**
89 * Fire an event at the DOM
90 *
91 * Helper that swallows DOM errors.
92 *
93 * \param[in] event the event to fire at the DOM
94 * \param[in] target the event target
95 * \return true on success
96 */
97static bool fire_dom_event(dom_event *event, dom_node *target)
98{
99 dom_exception exc;
100 bool result;
101
102 exc = dom_event_target_dispatch_event(target, event, &result);
103 if (exc != DOM_NO_ERR) {
104 return false;
105 }
106
107 return result;
108}
109
110/* Exported interface, see html_internal.h */
111bool fire_generic_dom_event(dom_string *type, dom_node *target,
112 bool bubbles, bool cancelable)
113{
114 dom_exception exc;
115 dom_event *evt;
116 bool result;
117
118 exc = dom_event_create(&evt);
119 if (exc != DOM_NO_ERR) return false;
120 exc = dom_event_init(evt, type, bubbles, cancelable);
121 if (exc != DOM_NO_ERR) {
122 dom_event_unref(evt);
123 return false;
124 }
125 NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
126 (int)dom_string_length(type), dom_string_data(type), target);
127 result = fire_dom_event(evt, target);
128 dom_event_unref(evt);
129 return result;
130}
131
132/* Exported interface, see html_internal.h */
133bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
134 bool bubbles, bool cancelable, uint32_t key)
135{
136 bool is_special = key <= 0x001F || (0x007F <= key && key <= 0x009F);
137 dom_string *dom_key = NULL;
138 dom_keyboard_event *evt;
139 dom_exception exc;
140 bool result;
141
142 if (is_special) {
143 switch (key) {
144 case NS_KEY_ESCAPE:
145 dom_key = dom_string_ref(corestring_dom_Escape);
146 break;
147 case NS_KEY_LEFT:
148 dom_key = dom_string_ref(corestring_dom_ArrowLeft);
149 break;
150 case NS_KEY_RIGHT:
151 dom_key = dom_string_ref(corestring_dom_ArrowRight);
152 break;
153 case NS_KEY_UP:
154 dom_key = dom_string_ref(corestring_dom_ArrowUp);
155 break;
156 case NS_KEY_DOWN:
157 dom_key = dom_string_ref(corestring_dom_ArrowDown);
158 break;
159 case NS_KEY_PAGE_UP:
160 dom_key = dom_string_ref(corestring_dom_PageUp);
161 break;
162 case NS_KEY_PAGE_DOWN:
163 dom_key = dom_string_ref(corestring_dom_PageDown);
164 break;
166 dom_key = dom_string_ref(corestring_dom_Home);
167 break;
168 case NS_KEY_TEXT_END:
169 dom_key = dom_string_ref(corestring_dom_End);
170 break;
171 default:
172 dom_key = NULL;
173 break;
174 }
175 } else {
176 char utf8[6];
177 size_t length = utf8_from_ucs4(key, utf8);
178 utf8[length] = '\0';
179
180 exc = dom_string_create((const uint8_t *)utf8, strlen(utf8),
181 &dom_key);
182 if (exc != DOM_NO_ERR) {
183 return exc;
184 }
185 }
186
187 exc = dom_keyboard_event_create(&evt);
188 if (exc != DOM_NO_ERR) {
189 dom_string_unref(dom_key);
190 return false;
191 }
192
193 exc = dom_keyboard_event_init(evt, type, bubbles, cancelable, NULL,
194 dom_key, NULL, DOM_KEY_LOCATION_STANDARD, false,
195 false, false, false, false, false);
196 dom_string_unref(dom_key);
197 if (exc != DOM_NO_ERR) {
198 dom_event_unref(evt);
199 return false;
200 }
201
202 NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
203 (int)dom_string_length(type), dom_string_data(type), target);
204
205 result = fire_dom_event((dom_event *) evt, target);
206 dom_event_unref(evt);
207 return result;
208}
209
210/**
211 * Perform post-box-creation conversion of a document
212 *
213 * \param c HTML content to complete conversion of
214 * \param success Whether box tree construction was successful
215 */
216static void html_box_convert_done(html_content *c, bool success)
217{
218 nserror err;
219 dom_exception exc; /* returned by libdom functions */
220 dom_node *html;
221
222 NSLOG(netsurf, INFO, "DOM to box conversion complete (content %p)", c);
223
224 c->box_conversion_context = NULL;
225
226 /* Clean up and report error if unsuccessful or aborted */
227 if ((success == false) || (c->aborted)) {
229
230 if (success == false) {
232 } else {
234 }
235
237 return;
238 }
239
240
241#if ALWAYS_DUMP_BOX
242 box_dump(stderr, c->layout->children, 0, true);
243#endif
244#if ALWAYS_DUMP_FRAMESET
245 if (c->frameset)
246 html_dump_frameset(c->frameset, 0);
247#endif
248
249 exc = dom_document_get_document_element(c->document, (void *) &html);
250 if ((exc != DOM_NO_ERR) || (html == NULL)) {
251 /** @todo should this call html_object_free_objects(c);
252 * like the other error paths
253 */
254 NSLOG(netsurf, INFO, "error retrieving html element from dom");
257 return;
258 }
259
260 /* extract image maps - can't do this sensibly in dom_to_box */
261 err = imagemap_extract(c);
262 if (err != NSERROR_OK) {
263 NSLOG(netsurf, INFO, "imagemap extraction failed");
265 content_broadcast_error(&c->base, err, NULL);
267 dom_node_unref(html);
268 return;
269 }
270 /*imagemap_dump(c);*/
271
272 /* Destroy the parser binding */
273 dom_hubbub_parser_destroy(c->parser);
274 c->parser = NULL;
275
277
279
280 dom_node_unref(html);
281}
282
283/* Documented in html_internal.h */
286{
287 switch (content__get_status(&html->base)) {
289 if (html->base.active == 0) {
290 content_set_done(&html->base);
291 return NSERROR_OK;
292 }
293 break;
295 /* fallthrough */
297 return NSERROR_OK;
298 default:
299 NSLOG(netsurf, ERROR, "Content status unexpectedly not LOADING/READY/DONE");
300 break;
301 }
302 return NSERROR_UNKNOWN;
303}
304
305
307{
308 css_fixed device_dpi = nscss_screen_dpi;
309 unsigned f_size;
310 unsigned f_min;
311 unsigned w;
312 unsigned h;
313 union content_msg_data msg_data = {
314 .getdims = {
315 .viewport_width = &w,
316 .viewport_height = &h,
317 },
318 };
319
320 content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
321
322
323 w = css_unit_device2css_px(INTTOFIX(w), device_dpi);
324 h = css_unit_device2css_px(INTTOFIX(h), device_dpi);
325
326 htmlc->media.width = w;
327 htmlc->media.height = h;
328 htmlc->unit_len_ctx.viewport_width = w;
329 htmlc->unit_len_ctx.viewport_height = h;
330 htmlc->unit_len_ctx.device_dpi = device_dpi;
331
332 /** \todo Change nsoption font sizes to px. */
333 f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72);
334 f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);
335
336 htmlc->unit_len_ctx.font_size_default = f_size;
337 htmlc->unit_len_ctx.font_size_minimum = f_min;
338}
339
340/* exported function documented in html/html_internal.h */
342{
343 union content_msg_data msg_data;
344 dom_exception exc; /* returned by libdom functions */
345 dom_node *html;
346 nserror error;
347
348 /* Bail out if we've been aborted */
349 if (htmlc->aborted) {
351 content_set_error(&htmlc->base);
352 return;
353 }
354
355 /* If we already have a selection context, then we have already
356 * "finished" conversion. We can get here twice if e.g. some JS
357 * adds a new stylesheet, and the stylesheet gets added after
358 * the HTML content is initially finished.
359 *
360 * If we didn't do this, the HTML content would try to rebuild the
361 * box tree for the html content when this new stylesheet is ready.
362 * NetSurf has no concept of dynamically changing documents, so this
363 * would break badly.
364 */
365 if (htmlc->select_ctx != NULL) {
366 NSLOG(netsurf, INFO,
367 "Ignoring style change: NS layout is static.");
368 return;
369 }
370
371 /* create new css selection context */
372 error = html_css_new_selection_context(htmlc, &htmlc->select_ctx);
373 if (error != NSERROR_OK) {
374 content_broadcast_error(&htmlc->base, error, NULL);
375 content_set_error(&htmlc->base);
376 return;
377 }
378
379
380 /* fire a simple event named load at the Document's Window
381 * object, but with its target set to the Document object (and
382 * the currentTarget set to the Window object)
383 */
384 if (htmlc->jsthread != NULL) {
385 js_fire_event(htmlc->jsthread, "load", htmlc->document, NULL);
386 }
387
388 /* convert dom tree to box tree */
389 NSLOG(netsurf, INFO, "DOM to box (%p)", htmlc);
390 content_set_status(&htmlc->base, messages_get("Processing"));
391 msg_data.explicit_status_text = NULL;
392 content_broadcast(&htmlc->base, CONTENT_MSG_STATUS, &msg_data);
393
394 exc = dom_document_get_document_element(htmlc->document, (void *) &html);
395 if ((exc != DOM_NO_ERR) || (html == NULL)) {
396 NSLOG(netsurf, INFO, "error retrieving html element from dom");
398 content_set_error(&htmlc->base);
399 return;
400 }
401
402 html_get_dimensions(htmlc);
403
404 error = dom_to_box(html, htmlc, html_box_convert_done, &htmlc->box_conversion_context);
405 if (error != NSERROR_OK) {
406 NSLOG(netsurf, INFO, "box conversion failed");
407 dom_node_unref(html);
409 content_broadcast_error(&htmlc->base, error, NULL);
410 content_set_error(&htmlc->base);
411 return;
412 }
413
414 dom_node_unref(html);
415}
416
417
418static void
419html_document_user_data_handler(dom_node_operation operation,
420 dom_string *key, void *data,
421 struct dom_node *src,
422 struct dom_node *dst)
423{
424 if (dom_string_isequal(corestring_dom___ns_key_html_content_data,
425 key) == false || data == NULL) {
426 return;
427 }
428
429 switch (operation) {
430 case DOM_NODE_CLONED:
431 NSLOG(netsurf, INFO, "Cloned");
432 break;
433 case DOM_NODE_RENAMED:
434 NSLOG(netsurf, INFO, "Renamed");
435 break;
436 case DOM_NODE_IMPORTED:
437 NSLOG(netsurf, INFO, "imported");
438 break;
439 case DOM_NODE_ADOPTED:
440 NSLOG(netsurf, INFO, "Adopted");
441 break;
442 case DOM_NODE_DELETED:
443 /* This is the only path I expect */
444 break;
445 default:
446 NSLOG(netsurf, INFO, "User data operation not handled.");
447 assert(0);
448 }
449}
450
451
452static nserror
454{
455 lwc_string *charset;
456 nserror nerror;
457 dom_hubbub_parser_params parse_params;
458 dom_hubbub_error error;
459 dom_exception err;
460 void *old_node_data;
461 const char *prefer_color_mode = (nsoption_bool(prefer_dark_mode)) ?
462 "dark" : "light";
463
464 c->parser = NULL;
465 c->parse_completed = false;
466 c->conversion_begun = false;
467 c->document = NULL;
468 c->quirks = DOM_DOCUMENT_QUIRKS_MODE_NONE;
469 c->encoding = NULL;
471 c->base_target = NULL;
472 c->aborted = false;
473 c->refresh = false;
474 c->reflowing = false;
475 c->title = NULL;
476 c->bctx = NULL;
477 c->layout = NULL;
479 c->stylesheet_count = 0;
480 c->stylesheets = NULL;
481 c->select_ctx = NULL;
482 c->media.type = CSS_MEDIA_SCREEN;
483 c->universal = NULL;
484 c->num_objects = 0;
485 c->object_list = NULL;
486 c->forms = NULL;
487 c->imagemaps = NULL;
488 c->bw = NULL;
489 c->frameset = NULL;
490 c->iframe = NULL;
491 c->page = NULL;
492 c->font_func = guit->layout;
494 c->drag_owner.no_owner = true;
496 c->selection_owner.none = true;
498 c->focus_owner.self = true;
499 c->scripts_count = 0;
500 c->scripts = NULL;
501 c->jsthread = NULL;
502
503 c->enable_scripting = nsoption_bool(enable_javascript);
504 c->base.active = 1; /* The html content itself is active */
505
506 if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
507 return NSERROR_NOMEM;
508 }
509
510 if (lwc_intern_string(prefer_color_mode, strlen(prefer_color_mode),
511 &c->media.prefers_color_scheme) != lwc_error_ok) {
512 lwc_string_unref(c->universal);
513 c->universal = NULL;
514 return NSERROR_NOMEM;
515 }
516
517 c->sel = selection_create((struct content *)c);
518
519 nerror = http_parameter_list_find_item(params, corestring_lwc_charset, &charset);
520 if (nerror == NSERROR_OK) {
521 c->encoding = strdup(lwc_string_data(charset));
522
523 lwc_string_unref(charset);
524
525 if (c->encoding == NULL) {
526 lwc_string_unref(c->universal);
527 c->universal = NULL;
528 lwc_string_unref(c->media.prefers_color_scheme);
529 c->media.prefers_color_scheme = NULL;
530 return NSERROR_NOMEM;
531
532 }
533 c->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_HEADER;
534 }
535
536 /* Create the parser binding */
537 parse_params.enc = c->encoding;
538 parse_params.fix_enc = true;
539 parse_params.enable_script = c->enable_scripting;
540 parse_params.msg = NULL;
541 parse_params.script = html_process_script;
542 parse_params.ctx = c;
543 parse_params.daf = html_dom_event_fetcher;
544
545 error = dom_hubbub_parser_create(&parse_params,
546 &c->parser,
547 &c->document);
548 if ((error != DOM_HUBBUB_OK) && (c->encoding != NULL)) {
549 /* Ok, we don't support the declared encoding. Bailing out
550 * isn't exactly user-friendly, so fall back to autodetect */
551 free(c->encoding);
552 c->encoding = NULL;
553
554 parse_params.enc = c->encoding;
555
556 error = dom_hubbub_parser_create(&parse_params,
557 &c->parser,
558 &c->document);
559 }
560 if (error != DOM_HUBBUB_OK) {
562 c->base_url = NULL;
563
564 lwc_string_unref(c->universal);
565 c->universal = NULL;
566 lwc_string_unref(c->media.prefers_color_scheme);
567 c->media.prefers_color_scheme = NULL;
568
569 return libdom_hubbub_error_to_nserror(error);
570 }
571
572 err = dom_node_set_user_data(c->document,
573 corestring_dom___ns_key_html_content_data,
575 (void *) &old_node_data);
576 if (err != DOM_NO_ERR) {
577 dom_hubbub_parser_destroy(c->parser);
578 c->parser = NULL;
580 c->base_url = NULL;
581
582 lwc_string_unref(c->universal);
583 c->universal = NULL;
584 lwc_string_unref(c->media.prefers_color_scheme);
585 c->media.prefers_color_scheme = NULL;
586
587 NSLOG(netsurf, INFO, "Unable to set user data.");
588 return NSERROR_DOM;
589 }
590
591 assert(old_node_data == NULL);
592
593 return NSERROR_OK;
594
595}
596
597/**
598 * Create a CONTENT_HTML.
599 *
600 * The content_html_data structure is initialized and the HTML parser is
601 * created.
602 */
603
604static nserror
606 lwc_string *imime_type,
607 const http_parameter *params,
609 const char *fallback_charset,
610 bool quirks,
611 struct content **c)
612{
613 html_content *html;
614 nserror error;
615
616 html = calloc(1, sizeof(html_content));
617 if (html == NULL)
618 return NSERROR_NOMEM;
619
620 error = content__init(&html->base, handler, imime_type, params,
621 llcache, fallback_charset, quirks);
622 if (error != NSERROR_OK) {
623 free(html);
624 return error;
625 }
626
627 error = html_create_html_data(html, params);
628 if (error != NSERROR_OK) {
629 content_broadcast_error(&html->base, error, NULL);
630 free(html);
631 return error;
632 }
633
634 error = html_css_new_stylesheets(html);
635 if (error != NSERROR_OK) {
636 content_broadcast_error(&html->base, error, NULL);
637 free(html);
638 return error;
639 }
640
641 *c = (struct content *) html;
642
643 return NSERROR_OK;
644}
645
646
647
648static nserror
650 const char *data,
651 unsigned int size)
652{
653 html_content *html = (html_content *) c;
654 dom_hubbub_parser_params parse_params;
655 dom_hubbub_error error;
656 const char *encoding;
657 const uint8_t *source_data;
658 size_t source_size;
659
660 /* Retrieve new encoding */
661 encoding = dom_hubbub_parser_get_encoding(html->parser,
662 &html->encoding_source);
663 if (encoding == NULL) {
664 return NSERROR_NOMEM;
665 }
666
667 if (html->encoding != NULL) {
668 free(html->encoding);
669 html->encoding = NULL;
670 }
671
672 html->encoding = strdup(encoding);
673 if (html->encoding == NULL) {
674 return NSERROR_NOMEM;
675 }
676
677 /* Destroy binding */
678 dom_hubbub_parser_destroy(html->parser);
679 html->parser = NULL;
680
681 if (html->document != NULL) {
682 dom_node_unref(html->document);
683 }
684
685 parse_params.enc = html->encoding;
686 parse_params.fix_enc = true;
687 parse_params.enable_script = html->enable_scripting;
688 parse_params.msg = NULL;
689 parse_params.script = html_process_script;
690 parse_params.ctx = html;
691 parse_params.daf = html_dom_event_fetcher;
692
693 /* Create new binding, using the new encoding */
694 error = dom_hubbub_parser_create(&parse_params,
695 &html->parser,
696 &html->document);
697 if (error != DOM_HUBBUB_OK) {
698 /* Ok, we don't support the declared encoding. Bailing out
699 * isn't exactly user-friendly, so fall back to Windows-1252 */
700 free(html->encoding);
701 html->encoding = strdup("Windows-1252");
702 if (html->encoding == NULL) {
703 return NSERROR_NOMEM;
704 }
705 parse_params.enc = html->encoding;
706
707 error = dom_hubbub_parser_create(&parse_params,
708 &html->parser,
709 &html->document);
710
711 if (error != DOM_HUBBUB_OK) {
712 return libdom_hubbub_error_to_nserror(error);
713 }
714
715 }
716
717 source_data = content__get_source_data(c, &source_size);
718
719 /* Reprocess all the data. This is safe because
720 * the encoding is now specified at parser start which means
721 * it cannot be changed again.
722 */
723 error = dom_hubbub_parser_parse_chunk(html->parser,
724 source_data,
725 source_size);
726
727 return libdom_hubbub_error_to_nserror(error);
728}
729
730
731/**
732 * Process data for CONTENT_HTML.
733 */
734
735static bool
736html_process_data(struct content *c, const char *data, unsigned int size)
737{
738 html_content *html = (html_content *) c;
739 dom_hubbub_error dom_ret;
740 nserror err = NSERROR_OK; /* assume its all going to be ok */
741
742 dom_ret = dom_hubbub_parser_parse_chunk(html->parser,
743 (const uint8_t *) data,
744 size);
745
746 err = libdom_hubbub_error_to_nserror(dom_ret);
747
748 /* deal with encoding change */
749 if (err == NSERROR_ENCODING_CHANGE) {
750 err = html_process_encoding_change(c, data, size);
751 }
752
753 /* broadcast the error if necessary */
754 if (err != NSERROR_OK) {
755 content_broadcast_error(c, err, NULL);
756 return false;
757 }
758
759 return true;
760}
761
762
763/**
764 * Convert a CONTENT_HTML for display.
765 *
766 * The following steps are carried out in order:
767 *
768 * - parsing to an XML tree is completed
769 * - stylesheets are fetched
770 * - the XML tree is converted to a box tree and object fetches are started
771 *
772 * On exit, the content status will be either CONTENT_STATUS_DONE if the
773 * document is completely loaded or CONTENT_STATUS_READY if objects are still
774 * being fetched.
775 */
776
777static bool html_convert(struct content *c)
778{
779 html_content *htmlc = (html_content *) c;
780 dom_exception exc; /* returned by libdom functions */
781
782 /* The quirk check and associated stylesheet fetch is "safe"
783 * once the root node has been inserted into the document
784 * which must have happened by this point in the parse.
785 *
786 * faliure to retrive the quirk mode or to start the
787 * stylesheet fetch is non fatal as this "only" affects the
788 * render and it would annoy the user to fail the entire
789 * render for want of a quirks stylesheet.
790 */
791 exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
792 if (exc == DOM_NO_ERR) {
794 NSLOG(netsurf, INFO, "quirks set to %d", htmlc->quirks);
795 }
796
797 htmlc->base.active--; /* the html fetch is no longer active */
798 NSLOG(netsurf, INFO, "%d fetches active (%p)", htmlc->base.active, c);
799
800 /* The parse cannot be completed here because it may be paused
801 * untill all the resources being fetched have completed.
802 */
803
804 /* if there are no active fetches in progress no scripts are
805 * being fetched or they completed already.
806 */
807 if (html_can_begin_conversion(htmlc)) {
808 return html_begin_conversion(htmlc);
809 }
810 return true;
811}
812
813/* Exported interface documented in html_internal.h */
815{
816 unsigned int i;
817
818 /* Cannot begin conversion if we're still fetching stuff */
819 if (htmlc->base.active != 0)
820 return false;
821
822 for (i = 0; i != htmlc->stylesheet_count; i++) {
823 /* Cannot begin conversion if the stylesheets are modified */
824 if (htmlc->stylesheets[i].modified)
825 return false;
826 }
827
828 /* All is good, begin */
829 return true;
830}
831
832bool
834{
835 dom_node *html;
836 nserror ns_error;
837 struct form *f;
838 dom_exception exc; /* returned by libdom functions */
839 dom_string *node_name = NULL;
840 dom_hubbub_error error;
841
842 /* The act of completing the parse can result in additional data
843 * being flushed through the parser. This may result in new style or
844 * script nodes, upon which the conversion depends. Thus, once we
845 * have completed the parse, we must check again to see if we can
846 * begin the conversion. If we can't, we must stop and wait for the
847 * new styles/scripts to be processed. Once they have been processed,
848 * we will be called again to begin the conversion for real. Thus,
849 * we must also ensure that we don't attempt to complete the parse
850 * multiple times, so store a flag to indicate that parsing is
851 * complete to avoid repeating the completion pointlessly.
852 */
853 if (htmlc->parse_completed == false) {
854 NSLOG(netsurf, INFO, "Completing parse (%p)", htmlc);
855 /* complete parsing */
856 error = dom_hubbub_parser_completed(htmlc->parser);
857 if (error == DOM_HUBBUB_HUBBUB_ERR_PAUSED && htmlc->base.active > 0) {
858 /* The act of completing the parse failed because we've
859 * encountered a sync script which needs to run
860 */
861 NSLOG(netsurf, INFO, "Completing parse brought synchronous JS to light, cannot complete yet");
862 return true;
863 }
864 if (error != DOM_HUBBUB_OK) {
865 NSLOG(netsurf, INFO, "Parsing failed");
866
869 NULL);
870
871 return false;
872 }
873 htmlc->parse_completed = true;
874 }
875
876 if (html_can_begin_conversion(htmlc) == false) {
877 NSLOG(netsurf, INFO, "Can't begin conversion (%p)", htmlc);
878 /* We can't proceed (see commentary above) */
879 return true;
880 }
881
882 /* Give up processing if we've been aborted */
883 if (htmlc->aborted) {
884 NSLOG(netsurf, INFO, "Conversion aborted (%p) (active: %u)",
885 htmlc, htmlc->base.active);
886 content_set_error(&htmlc->base);
888 return false;
889 }
890
891 /* Conversion begins proper at this point */
892 htmlc->conversion_begun = true;
893
894 /* complete script execution, including deferred scripts */
895 html_script_exec(htmlc, true);
896
897 /* fire a simple event that bubbles named DOMContentLoaded at
898 * the Document.
899 */
900
901 /* get encoding */
902 if (htmlc->encoding == NULL) {
903 const char *encoding;
904
905 encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
906 &htmlc->encoding_source);
907 if (encoding == NULL) {
910 NULL);
911 return false;
912 }
913
914 htmlc->encoding = strdup(encoding);
915 if (htmlc->encoding == NULL) {
918 NULL);
919 return false;
920 }
921 }
922
923 /* locate root element and ensure it is html */
924 exc = dom_document_get_document_element(htmlc->document, (void *) &html);
925 if ((exc != DOM_NO_ERR) || (html == NULL)) {
926 NSLOG(netsurf, INFO, "error retrieving html element from dom");
928 return false;
929 }
930
931 exc = dom_node_get_node_name(html, &node_name);
932 if ((exc != DOM_NO_ERR) ||
933 (node_name == NULL) ||
934 (!dom_string_caseless_lwc_isequal(node_name,
935 corestring_lwc_html))) {
936 NSLOG(netsurf, INFO, "root element not html");
938 dom_node_unref(html);
939 return false;
940 }
941 dom_string_unref(node_name);
942
943 /* Retrieve forms from parser */
944 htmlc->forms = html_forms_get_forms(htmlc->encoding,
945 (dom_html_document *) htmlc->document);
946 for (f = htmlc->forms; f != NULL; f = f->prev) {
947 nsurl *action;
948
949 /* Make all actions absolute */
950 if (f->action == NULL || f->action[0] == '\0') {
951 /* HTML5 4.10.22.3 step 9 */
952 nsurl *doc_addr = content_get_url(&htmlc->base);
953 ns_error = nsurl_join(htmlc->base_url,
954 nsurl_access(doc_addr),
955 &action);
956 } else {
957 ns_error = nsurl_join(htmlc->base_url,
958 f->action,
959 &action);
960 }
961
962 if (ns_error != NSERROR_OK) {
963 content_broadcast_error(&htmlc->base, ns_error, NULL);
964
965 dom_node_unref(html);
966 return false;
967 }
968
969 free(f->action);
970 f->action = strdup(nsurl_access(action));
972 if (f->action == NULL) {
975 NULL);
976
977 dom_node_unref(html);
978 return false;
979 }
980
981 /* Ensure each form has a document encoding */
982 if (f->document_charset == NULL) {
983 f->document_charset = strdup(htmlc->encoding);
984 if (f->document_charset == NULL) {
987 NULL);
988 dom_node_unref(html);
989 return false;
990 }
991 }
992 }
993
994 dom_node_unref(html);
995
996 if (htmlc->base.active == 0) {
998 }
999
1000 return true;
1001}
1002
1003
1004/**
1005 * Stop loading a CONTENT_HTML.
1006 *
1007 * called when the content is aborted. This must clean up any state
1008 * created during the fetch.
1009 */
1010
1011static void html_stop(struct content *c)
1012{
1013 html_content *htmlc = (html_content *) c;
1014
1015 switch (c->status) {
1017 /* Still loading; simply flag that we've been aborted
1018 * html_convert/html_finish_conversion will do the rest */
1019 htmlc->aborted = true;
1020 if (htmlc->jsthread != NULL) {
1021 /* Close the JS thread to cancel out any callbacks */
1022 js_closethread(htmlc->jsthread);
1023 }
1024 break;
1025
1028
1029 /* If there are no further active fetches and we're still
1030 * in the READY state, transition to the DONE state. */
1031 if (c->status == CONTENT_STATUS_READY && c->active == 0) {
1033 }
1034
1035 break;
1036
1038 /* Nothing to do */
1039 break;
1040
1041 default:
1042 NSLOG(netsurf, INFO, "Unexpected status %d (%p)", c->status,
1043 c);
1044 assert(0);
1045 }
1046}
1047
1048
1049/**
1050 * Reformat a CONTENT_HTML to a new width.
1051 */
1052
1053static void html_reformat(struct content *c, int width, int height)
1054{
1055 html_content *htmlc = (html_content *) c;
1056 struct box *layout;
1057 uint64_t ms_before;
1058 uint64_t ms_after;
1059 uint64_t ms_interval;
1060
1061 nsu_getmonotonic_ms(&ms_before);
1062
1063 htmlc->reflowing = true;
1064
1065 htmlc->unit_len_ctx.viewport_width = css_unit_device2css_px(
1066 INTTOFIX(width), htmlc->unit_len_ctx.device_dpi);
1067 htmlc->unit_len_ctx.viewport_height = css_unit_device2css_px(
1068 INTTOFIX(height), htmlc->unit_len_ctx.device_dpi);
1069 htmlc->unit_len_ctx.root_style = htmlc->layout->style;
1070
1071 layout_document(htmlc, width, height);
1072 layout = htmlc->layout;
1073
1074 /* width and height are at least margin box of document */
1075 c->width = layout->x + layout->padding[LEFT] + layout->width +
1076 layout->padding[RIGHT] + layout->border[RIGHT].width +
1077 layout->margin[RIGHT];
1078 c->height = layout->y + layout->padding[TOP] + layout->height +
1079 layout->padding[BOTTOM] + layout->border[BOTTOM].width +
1080 layout->margin[BOTTOM];
1081
1082 /* if boxes overflow right or bottom edge, expand to contain it */
1083 if (c->width < layout->x + layout->descendant_x1)
1084 c->width = layout->x + layout->descendant_x1;
1085 if (c->height < layout->y + layout->descendant_y1)
1086 c->height = layout->y + layout->descendant_y1;
1087
1088 selection_reinit(htmlc->sel);
1089
1090 htmlc->reflowing = false;
1091 htmlc->had_initial_layout = true;
1092
1093 /* calculate next reflow time at three times what it took to reflow */
1094 nsu_getmonotonic_ms(&ms_after);
1095
1096 ms_interval = (ms_after - ms_before) * 3;
1097 if (ms_interval < (nsoption_uint(min_reflow_period) * 10)) {
1098 ms_interval = nsoption_uint(min_reflow_period) * 10;
1099 }
1100 c->reformat_time = ms_after + ms_interval;
1101}
1102
1103
1104/**
1105 * Redraw a box.
1106 *
1107 * \param h content containing the box, of type CONTENT_HTML
1108 * \param box box to redraw
1109 */
1110
1112{
1113 int x, y;
1114
1115 box_coords(box, &x, &y);
1116
1120}
1121
1122
1123/**
1124 * Redraw a box.
1125 *
1126 * \param html content containing the box, of type CONTENT_HTML
1127 * \param box box to redraw.
1128 */
1129
1130void html__redraw_a_box(struct html_content *html, struct box *box)
1131{
1132 int x, y;
1133
1134 box_coords(box, &x, &y);
1135
1136 content__request_redraw((struct content *)html, x, y,
1139}
1140
1141static void html_destroy_frameset(struct content_html_frames *frameset)
1142{
1143 int i;
1144
1145 if (frameset->name) {
1146 talloc_free(frameset->name);
1147 frameset->name = NULL;
1148 }
1149 if (frameset->url) {
1150 talloc_free(frameset->url);
1151 frameset->url = NULL;
1152 }
1153 if (frameset->children) {
1154 for (i = 0; i < (frameset->rows * frameset->cols); i++) {
1155 if (frameset->children[i].name) {
1156 talloc_free(frameset->children[i].name);
1157 frameset->children[i].name = NULL;
1158 }
1159 if (frameset->children[i].url) {
1160 nsurl_unref(frameset->children[i].url);
1161 frameset->children[i].url = NULL;
1162 }
1163 if (frameset->children[i].children)
1164 html_destroy_frameset(&frameset->children[i]);
1165 }
1166 talloc_free(frameset->children);
1167 frameset->children = NULL;
1168 }
1169}
1170
1172{
1173 struct content_html_iframe *next;
1174 next = iframe;
1175 while ((iframe = next) != NULL) {
1176 next = iframe->next;
1177 if (iframe->name)
1178 talloc_free(iframe->name);
1179 if (iframe->url) {
1180 nsurl_unref(iframe->url);
1181 iframe->url = NULL;
1182 }
1183 talloc_free(iframe);
1184 }
1185}
1186
1187
1189{
1190 if (htmlc->bctx != NULL) {
1191 /* freeing talloc context should let the entire box
1192 * set be destroyed
1193 */
1194 talloc_free(htmlc->bctx);
1195 }
1196}
1197
1198/**
1199 * Destroy a CONTENT_HTML and free all resources it owns.
1200 */
1201
1202static void html_destroy(struct content *c)
1203{
1204 html_content *html = (html_content *) c;
1205 struct form *f, *g;
1206
1207 NSLOG(netsurf, INFO, "content %p", c);
1208
1209 /* If we're still converting a layout, cancel it */
1210 if (html->box_conversion_context != NULL) {
1212 NSLOG(netsurf, CRITICAL, "WARNING, Unable to cancel conversion context, browser may crash");
1213 }
1214 }
1215
1216 selection_destroy(html->sel);
1217
1218 /* Destroy forms */
1219 for (f = html->forms; f != NULL; f = g) {
1220 g = f->prev;
1221
1222 form_free(f);
1223 }
1224
1225 imagemap_destroy(html);
1226
1227 if (c->refresh)
1228 nsurl_unref(c->refresh);
1229
1230 if (html->base_url)
1231 nsurl_unref(html->base_url);
1232
1233 /* At this point we can be moderately confident the JS is offline
1234 * so we destroy the JS thread.
1235 */
1236 if (html->jsthread != NULL) {
1238 html->jsthread = NULL;
1239 }
1240
1241 if (html->parser != NULL) {
1242 dom_hubbub_parser_destroy(html->parser);
1243 html->parser = NULL;
1244 }
1245
1246 if (html->document != NULL) {
1247 dom_node_unref(html->document);
1248 html->document = NULL;
1249 }
1250
1251 if (html->title != NULL) {
1252 dom_node_unref(html->title);
1253 html->title = NULL;
1254 }
1255
1256 /* Free encoding */
1257 if (html->encoding != NULL) {
1258 free(html->encoding);
1259 html->encoding = NULL;
1260 }
1261
1262 /* Free base target */
1263 if (html->base_target != NULL) {
1264 free(html->base_target);
1265 html->base_target = NULL;
1266 }
1267
1268 /* Free frameset */
1269 if (html->frameset != NULL) {
1271 talloc_free(html->frameset);
1272 html->frameset = NULL;
1273 }
1274
1275 /* Free iframes */
1276 if (html->iframe != NULL) {
1278 html->iframe = NULL;
1279 }
1280
1281 /* Destroy selection context */
1282 if (html->select_ctx != NULL) {
1283 css_select_ctx_destroy(html->select_ctx);
1284 html->select_ctx = NULL;
1285 }
1286
1287 if (html->universal != NULL) {
1288 lwc_string_unref(html->universal);
1289 html->universal = NULL;
1290 }
1291
1292 if (html->media.prefers_color_scheme != NULL) {
1293 lwc_string_unref(html->media.prefers_color_scheme);
1294 html->media.prefers_color_scheme = NULL;
1295 }
1296
1297 /* Free stylesheets */
1299
1300 /* Free scripts */
1301 html_script_free(html);
1302
1303 /* Free objects */
1305
1306 /* free layout */
1307 html_free_layout(html);
1308}
1309
1310
1311static nserror html_clone(const struct content *old, struct content **newc)
1312{
1313 /** \todo Clone HTML specifics */
1314
1315 /* In the meantime, we should never be called, as HTML contents
1316 * cannot be shared and we're not intending to fix printing's
1317 * cloning of documents. */
1318 assert(0 && "html_clone should never be called");
1319
1320 return true;
1321}
1322
1323
1324/**
1325 * Handle a window containing a CONTENT_HTML being opened.
1326 */
1327
1328static nserror
1330 struct browser_window *bw,
1331 struct content *page,
1332 struct object_params *params)
1333{
1334 html_content *html = (html_content *) c;
1335
1336 html->bw = bw;
1337 html->page = (html_content *) page;
1338
1339 html->drag_type = HTML_DRAG_NONE;
1340 html->drag_owner.no_owner = true;
1341
1342 /* text selection */
1343 selection_init(html->sel);
1345 html->selection_owner.none = true;
1346
1347 html_object_open_objects(html, bw);
1348
1349 return NSERROR_OK;
1350}
1351
1352
1353/**
1354 * Handle a window containing a CONTENT_HTML being closed.
1355 */
1356
1357static nserror html_close(struct content *c)
1358{
1359 html_content *htmlc = (html_content *) c;
1360 nserror ret = NSERROR_OK;
1361
1362 selection_clear(htmlc->sel, false);
1363
1364 /* clear the html content reference to the browser window */
1365 htmlc->bw = NULL;
1366
1367 /* remove all object references from the html content */
1369
1370 if (htmlc->jsthread != NULL) {
1371 /* Close, but do not destroy (yet) the JS thread */
1372 ret = js_closethread(htmlc->jsthread);
1373 }
1374
1375 return ret;
1376}
1377
1378
1379/**
1380 * Return an HTML content's selection context
1381 */
1382
1383static void html_clear_selection(struct content *c)
1384{
1385 html_content *html = (html_content *) c;
1386
1387 switch (html->selection_type) {
1389 /* Nothing to do */
1390 assert(html->selection_owner.none == true);
1391 break;
1394 gadget->data.text.ta);
1395 break;
1397 assert(html->selection_owner.none == false);
1398 selection_clear(html->sel, true);
1399 break;
1402 break;
1403 default:
1404 break;
1405 }
1406
1407 /* There is no selection now. */
1409 html->selection_owner.none = true;
1410}
1411
1412
1413/**
1414 * Return an HTML content's selection context
1415 */
1416
1417static char *html_get_selection(struct content *c)
1418{
1419 html_content *html = (html_content *) c;
1420
1421 switch (html->selection_type) {
1424 gadget->data.text.ta);
1426 assert(html->selection_owner.none == false);
1427 return selection_get_copy(html->sel);
1429 return content_get_selection(
1432 /* Nothing to do */
1433 assert(html->selection_owner.none == true);
1434 break;
1435 default:
1436 break;
1437 }
1438
1439 return NULL;
1440}
1441
1442
1443/**
1444 * Get access to any content, link URLs and objects (images) currently
1445 * at the given (x, y) coordinates.
1446 *
1447 * \param[in] c html content to look inside
1448 * \param[in] x x-coordinate of point of interest
1449 * \param[in] y y-coordinate of point of interest
1450 * \param[out] data Positional features struct to be updated with any
1451 * relevent content, or set to NULL if none.
1452 * \return NSERROR_OK on success else appropriate error code.
1453 */
1454static nserror
1455html_get_contextual_content(struct content *c, int x, int y,
1456 struct browser_window_features *data)
1457{
1458 html_content *html = (html_content *) c;
1459
1460 struct box *box = html->layout;
1461 struct box *next;
1462 int box_x = 0, box_y = 0;
1463
1464 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1465 &box_x, &box_y)) != NULL) {
1466 box = next;
1467
1468 /* hidden boxes are ignored */
1469 if ((box->style != NULL) &&
1470 css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) {
1471 continue;
1472 }
1473
1474 if (box->iframe) {
1475 float scale = browser_window_get_scale(box->iframe);
1477 (x - box_x) * scale,
1478 (y - box_y) * scale,
1479 data);
1480 }
1481
1482 if (box->object)
1484 x - box_x, y - box_y, data);
1485
1486 if (box->object)
1487 data->object = box->object;
1488
1489 if (box->href)
1490 data->link = box->href;
1491
1492 if (box->usemap) {
1493 const char *target = NULL;
1494 nsurl *url = imagemap_get(html, box->usemap, box_x,
1495 box_y, x, y, &target);
1496 /* Box might have imagemap, but no actual link area
1497 * at point */
1498 if (url != NULL)
1499 data->link = url;
1500 }
1501 if (box->gadget) {
1502 switch (box->gadget->type) {
1503 case GADGET_TEXTBOX:
1504 case GADGET_TEXTAREA:
1505 case GADGET_PASSWORD:
1506 data->form_features = CTX_FORM_TEXT;
1507 break;
1508
1509 case GADGET_FILE:
1510 data->form_features = CTX_FORM_FILE;
1511 break;
1512
1513 default:
1514 data->form_features = CTX_FORM_NONE;
1515 break;
1516 }
1517 }
1518 }
1519 return NSERROR_OK;
1520}
1521
1522
1523/**
1524 * Scroll deepest thing within the content which can be scrolled at given point
1525 *
1526 * \param c html content to look inside
1527 * \param x x-coordinate of point of interest
1528 * \param y y-coordinate of point of interest
1529 * \param scrx number of px try to scroll something in x direction
1530 * \param scry number of px try to scroll something in y direction
1531 * \return true iff scroll was consumed by something in the content
1532 */
1533static bool
1534html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
1535{
1536 html_content *html = (html_content *) c;
1537
1538 struct box *box = html->layout;
1539 struct box *next;
1540 int box_x = 0, box_y = 0;
1541 bool handled_scroll = false;
1542
1543 /* TODO: invert order; visit deepest box first */
1544
1545 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1546 &box_x, &box_y)) != NULL) {
1547 box = next;
1548
1549 if (box->style && css_computed_visibility(box->style) ==
1550 CSS_VISIBILITY_HIDDEN)
1551 continue;
1552
1553 /* Pass into iframe */
1554 if (box->iframe) {
1555 float scale = browser_window_get_scale(box->iframe);
1556
1558 (x - box_x) * scale,
1559 (y - box_y) * scale,
1560 scrx, scry) == true)
1561 return true;
1562 }
1563
1564 /* Pass into textarea widget */
1565 if (box->gadget && (box->gadget->type == GADGET_TEXTAREA ||
1567 box->gadget->type == GADGET_TEXTBOX) &&
1568 textarea_scroll(box->gadget->data.text.ta,
1569 scrx, scry) == true)
1570 return true;
1571
1572 /* Pass into object */
1573 if (box->object != NULL && content_scroll_at_point(
1574 box->object, x - box_x, y - box_y,
1575 scrx, scry) == true)
1576 return true;
1577
1578 /* Handle box scrollbars */
1579 if (box->scroll_y && scrollbar_scroll(box->scroll_y, scry))
1580 handled_scroll = true;
1581
1582 if (box->scroll_x && scrollbar_scroll(box->scroll_x, scrx))
1583 handled_scroll = true;
1584
1585 if (handled_scroll == true)
1586 return true;
1587 }
1588
1589 return false;
1590}
1591
1592/** Helper for file gadgets to store their filename unencoded on the
1593 * dom node associated with the gadget.
1594 *
1595 * \todo Get rid of this crap eventually
1596 */
1597static void html__dom_user_data_handler(dom_node_operation operation,
1598 dom_string *key, void *_data, struct dom_node *src,
1599 struct dom_node *dst)
1600{
1601 char *oldfile;
1602 char *data = (char *)_data;
1603
1604 if (!dom_string_isequal(corestring_dom___ns_key_file_name_node_data,
1605 key) || data == NULL) {
1606 return;
1607 }
1608
1609 switch (operation) {
1610 case DOM_NODE_CLONED:
1611 if (dom_node_set_user_data(dst,
1612 corestring_dom___ns_key_file_name_node_data,
1613 strdup(data), html__dom_user_data_handler,
1614 &oldfile) == DOM_NO_ERR) {
1615 if (oldfile != NULL)
1616 free(oldfile);
1617 }
1618 break;
1619
1620 case DOM_NODE_RENAMED:
1621 case DOM_NODE_IMPORTED:
1622 case DOM_NODE_ADOPTED:
1623 break;
1624
1625 case DOM_NODE_DELETED:
1626 free(data);
1627 break;
1628 default:
1629 NSLOG(netsurf, INFO, "User data operation not handled.");
1630 assert(0);
1631 }
1632}
1633
1635 struct form_control *gadget, const char *fn)
1636{
1637 nserror ret;
1638 char *utf8_fn, *oldfile = NULL;
1639 html_content *html = (html_content *)c;
1640 struct box *file_box = gadget->box;
1641
1642 ret = guit->utf8->local_to_utf8(fn, 0, &utf8_fn);
1643 if (ret != NSERROR_OK) {
1644 assert(ret != NSERROR_BAD_ENCODING);
1645 NSLOG(netsurf, INFO,
1646 "utf8 to local encoding conversion failed");
1647 /* Load was for us - just no memory */
1648 return;
1649 }
1650
1652
1653 /* corestring_dom___ns_key_file_name_node_data */
1654 if (dom_node_set_user_data((dom_node *)file_box->gadget->node,
1655 corestring_dom___ns_key_file_name_node_data,
1656 strdup(fn), html__dom_user_data_handler,
1657 &oldfile) == DOM_NO_ERR) {
1658 if (oldfile != NULL)
1659 free(oldfile);
1660 }
1661
1662 /* Redraw box. */
1663 html__redraw_a_box(html, file_box);
1664}
1665
1667 struct form_control *gadget, const char *fn)
1668{
1670 gadget, fn);
1671}
1672
1673/**
1674 * Drop a file onto a content at a particular point, or determine if a file
1675 * may be dropped onto the content at given point.
1676 *
1677 * \param c html content to look inside
1678 * \param x x-coordinate of point of interest
1679 * \param y y-coordinate of point of interest
1680 * \param file path to file to be dropped, or NULL to know if drop allowed
1681 * \return true iff file drop has been handled, or if drop possible (NULL file)
1682 */
1683static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
1684{
1685 html_content *html = (html_content *) c;
1686
1687 struct box *box = html->layout;
1688 struct box *next;
1689 struct box *file_box = NULL;
1690 struct box *text_box = NULL;
1691 int box_x = 0, box_y = 0;
1692
1693 /* Scan box tree for boxes that can handle drop */
1694 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1695 &box_x, &box_y)) != NULL) {
1696 box = next;
1697
1698 if (box->style &&
1699 css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
1700 continue;
1701
1702 if (box->iframe) {
1703 float scale = browser_window_get_scale(box->iframe);
1705 box->iframe,
1706 (x - box_x) * scale,
1707 (y - box_y) * scale,
1708 file);
1709 }
1710
1711 if (box->object &&
1713 x - box_x, y - box_y, file) == true)
1714 return true;
1715
1716 if (box->gadget) {
1717 switch (box->gadget->type) {
1718 case GADGET_FILE:
1719 file_box = box;
1720 break;
1721
1722 case GADGET_TEXTBOX:
1723 case GADGET_TEXTAREA:
1724 case GADGET_PASSWORD:
1725 text_box = box;
1726 break;
1727
1728 default: /* appease compiler */
1729 break;
1730 }
1731 }
1732 }
1733
1734 if (!file_box && !text_box)
1735 /* No box capable of handling drop */
1736 return false;
1737
1738 if (file == NULL)
1739 /* There is a box capable of handling drop here */
1740 return true;
1741
1742 /* Handle the drop */
1743 if (file_box) {
1744 /* File dropped on file input */
1745 html__set_file_gadget_filename(c, file_box->gadget, file);
1746
1747 } else {
1748 /* File dropped on text input */
1749
1750 size_t file_len;
1751 FILE *fp = NULL;
1752 char *buffer;
1753 char *utf8_buff;
1754 nserror ret;
1755 unsigned int size;
1756 int bx, by;
1757
1758 /* Open file */
1759 fp = fopen(file, "rb");
1760 if (fp == NULL) {
1761 /* Couldn't open file, but drop was for us */
1762 return true;
1763 }
1764
1765 /* Get filesize */
1766 fseek(fp, 0, SEEK_END);
1767 file_len = ftell(fp);
1768 fseek(fp, 0, SEEK_SET);
1769
1770 if ((long)file_len == -1) {
1771 /* unable to get file length, but drop was for us */
1772 fclose(fp);
1773 return true;
1774 }
1775
1776 /* Allocate buffer for file data */
1777 buffer = malloc(file_len + 1);
1778 if (buffer == NULL) {
1779 /* No memory, but drop was for us */
1780 fclose(fp);
1781 return true;
1782 }
1783
1784 /* Stick file into buffer */
1785 if (file_len != fread(buffer, 1, file_len, fp)) {
1786 /* Failed, but drop was for us */
1787 free(buffer);
1788 fclose(fp);
1789 return true;
1790 }
1791
1792 /* Done with file */
1793 fclose(fp);
1794
1795 /* Ensure buffer's string termination */
1796 buffer[file_len] = '\0';
1797
1798 /* TODO: Sniff for text? */
1799
1800 /* Convert to UTF-8 */
1801 ret = guit->utf8->local_to_utf8(buffer, file_len, &utf8_buff);
1802 if (ret != NSERROR_OK) {
1803 /* bad encoding shouldn't happen */
1804 NSLOG(netsurf, ERROR,
1805 "local to utf8 encoding failed (%s)",
1807 assert(ret != NSERROR_BAD_ENCODING);
1808 free(buffer);
1809 return true;
1810 }
1811
1812 /* Done with buffer */
1813 free(buffer);
1814
1815 /* Get new length */
1816 size = strlen(utf8_buff);
1817
1818 /* Simulate a click over the input box, to place caret */
1819 box_coords(text_box, &bx, &by);
1820 textarea_mouse_action(text_box->gadget->data.text.ta,
1821 BROWSER_MOUSE_PRESS_1, x - bx, y - by);
1822
1823 /* Paste the file as text */
1824 textarea_drop_text(text_box->gadget->data.text.ta,
1825 utf8_buff, size);
1826
1827 free(utf8_buff);
1828 }
1829
1830 return true;
1831}
1832
1833
1834/**
1835 * set debug status.
1836 *
1837 * \param c The content to debug
1838 * \param op The debug operation type
1839 */
1840static nserror
1842{
1844
1845 return NSERROR_OK;
1846}
1847
1848
1849/**
1850 * Dump debug info concerning the html_content
1851 *
1852 * \param c The content to debug
1853 * \param f The file to dump to
1854 * \param op The debug dump type
1855 */
1856static nserror
1857html_debug_dump(struct content *c, FILE *f, enum content_debug op)
1858{
1859 html_content *htmlc = (html_content *)c;
1860 dom_node *html;
1861 dom_exception exc; /* returned by libdom functions */
1862 nserror ret;
1863
1864 assert(htmlc != NULL);
1865
1866 if (op == CONTENT_DEBUG_RENDER) {
1867 assert(htmlc->layout != NULL);
1868 box_dump(f, htmlc->layout, 0, true);
1869 ret = NSERROR_OK;
1870 } else {
1871 if (htmlc->document == NULL) {
1872 NSLOG(netsurf, INFO, "No document to dump");
1873 return NSERROR_DOM;
1874 }
1875
1876 exc = dom_document_get_document_element(htmlc->document, (void *) &html);
1877 if ((exc != DOM_NO_ERR) || (html == NULL)) {
1878 NSLOG(netsurf, INFO, "Unable to obtain root node");
1879 return NSERROR_DOM;
1880 }
1881
1882 ret = libdom_dump_structure(html, f, 0);
1883
1884 NSLOG(netsurf, INFO, "DOM structure dump returning %d", ret);
1885
1886 dom_node_unref(html);
1887 }
1888
1889 return ret;
1890}
1891
1892
1893#if ALWAYS_DUMP_FRAMESET
1894/**
1895 * Print a frameset tree to stderr.
1896 */
1897
1898static void
1899html_dump_frameset(struct content_html_frames *frame, unsigned int depth)
1900{
1901 unsigned int i;
1902 int row, col, index;
1903 const char *unit[] = {"px", "%", "*"};
1904 const char *scrolling[] = {"auto", "yes", "no"};
1905
1906 assert(frame);
1907
1908 fprintf(stderr, "%p ", frame);
1909
1910 fprintf(stderr, "(%i %i) ", frame->rows, frame->cols);
1911
1912 fprintf(stderr, "w%g%s ", frame->width.value, unit[frame->width.unit]);
1913 fprintf(stderr, "h%g%s ", frame->height.value,unit[frame->height.unit]);
1914 fprintf(stderr, "(margin w%i h%i) ",
1915 frame->margin_width, frame->margin_height);
1916
1917 if (frame->name)
1918 fprintf(stderr, "'%s' ", frame->name);
1919 if (frame->url)
1920 fprintf(stderr, "<%s> ", frame->url);
1921
1922 if (frame->no_resize)
1923 fprintf(stderr, "noresize ");
1924 fprintf(stderr, "(scrolling %s) ", scrolling[frame->scrolling]);
1925 if (frame->border)
1926 fprintf(stderr, "border %x ",
1927 (unsigned int) frame->border_colour);
1928
1929 fprintf(stderr, "\n");
1930
1931 if (frame->children) {
1932 for (row = 0; row != frame->rows; row++) {
1933 for (col = 0; col != frame->cols; col++) {
1934 for (i = 0; i != depth; i++)
1935 fprintf(stderr, " ");
1936 fprintf(stderr, "(%i %i): ", row, col);
1937 index = (row * frame->cols) + col;
1938 html_dump_frameset(&frame->children[index],
1939 depth + 1);
1940 }
1941 }
1942 }
1943}
1944
1945#endif
1946
1947/**
1948 * Retrieve HTML document tree
1949 *
1950 * \param h HTML content to retrieve document tree from
1951 * \return Pointer to document tree
1952 */
1954{
1956
1957 assert(c != NULL);
1958
1959 return c->document;
1960}
1961
1962/**
1963 * Retrieve box tree
1964 *
1965 * \param h HTML content to retrieve tree from
1966 * \return Pointer to box tree
1967 *
1968 * \todo This API must die, as must all use of the box tree outside of
1969 * HTML content handler
1970 */
1972{
1974
1975 assert(c != NULL);
1976
1977 return c->layout;
1978}
1979
1980/**
1981 * Retrieve the charset of an HTML document
1982 *
1983 * \param c Content to retrieve charset from
1984 * \param op The content encoding operation to perform.
1985 * \return Pointer to charset, or NULL
1986 */
1987static const char *html_encoding(const struct content *c, enum content_encoding_type op)
1988{
1989 html_content *html = (html_content *) c;
1990 static char enc_token[10] = "Encoding0";
1991
1992 assert(html != NULL);
1993
1994 if (op == CONTENT_ENCODING_SOURCE) {
1995 enc_token[8] = '0' + html->encoding_source;
1996 return messages_get(enc_token);
1997 }
1998
1999 return html->encoding;
2000}
2001
2002
2003/**
2004 * Retrieve framesets used in an HTML document
2005 *
2006 * \param h Content to inspect
2007 * \return Pointer to framesets, or NULL if none
2008 */
2010{
2012
2013 assert(c != NULL);
2014
2015 return c->frameset;
2016}
2017
2018/**
2019 * Retrieve iframes used in an HTML document
2020 *
2021 * \param h Content to inspect
2022 * \return Pointer to iframes, or NULL if none
2023 */
2025{
2027
2028 assert(c != NULL);
2029
2030 return c->iframe;
2031}
2032
2033/**
2034 * Retrieve an HTML content's base URL
2035 *
2036 * \param h Content to retrieve base target from
2037 * \return Pointer to URL
2038 */
2040{
2042
2043 assert(c != NULL);
2044
2045 return c->base_url;
2046}
2047
2048/**
2049 * Retrieve an HTML content's base target
2050 *
2051 * \param h Content to retrieve base target from
2052 * \return Pointer to target, or NULL if none
2053 */
2055{
2057
2058 assert(c != NULL);
2059
2060 return c->base_target;
2061}
2062
2063
2064/**
2065 * Retrieve layout coordinates of box with given id
2066 *
2067 * \param h HTML document to search
2068 * \param frag_id String containing an element id
2069 * \param x Updated to global x coord iff id found
2070 * \param y Updated to global y coord iff id found
2071 * \return true iff id found
2072 */
2073bool html_get_id_offset(hlcache_handle *h, lwc_string *frag_id, int *x, int *y)
2074{
2075 struct box *pos;
2076 struct box *layout;
2077
2079 return false;
2080
2081 layout = html_get_box_tree(h);
2082
2083 if ((pos = box_find_by_id(layout, frag_id)) != 0) {
2084 box_coords(pos, x, y);
2085 return true;
2086 }
2087 return false;
2088}
2089
2090bool html_exec(struct content *c, const char *src, size_t srclen)
2091{
2092 html_content *htmlc = (html_content *)c;
2093 bool result = false;
2094 dom_exception err;
2095 dom_html_body_element *body_node;
2096 dom_string *dom_src;
2097 dom_text *text_node;
2098 dom_node *spare_node;
2099 dom_html_script_element *script_node;
2100
2101 if (htmlc->document == NULL) {
2102 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no document");
2103 goto out_no_string;
2104 }
2105
2106 err = dom_string_create((const uint8_t *)src, srclen, &dom_src);
2107 if (err != DOM_NO_ERR) {
2108 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create string");
2109 goto out_no_string;
2110 }
2111
2112 err = dom_html_document_get_body(htmlc->document, &body_node);
2113 if (err != DOM_NO_ERR) {
2114 NSLOG(netsurf, DEEPDEBUG, "Unable to retrieve body element");
2115 goto out_no_body;
2116 }
2117
2118 err = dom_document_create_text_node(htmlc->document, dom_src, &text_node);
2119 if (err != DOM_NO_ERR) {
2120 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create text node");
2121 goto out_no_text_node;
2122 }
2123
2124 err = dom_document_create_element(htmlc->document, corestring_dom_SCRIPT, &script_node);
2125 if (err != DOM_NO_ERR) {
2126 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create script node");
2127 goto out_no_script_node;
2128 }
2129
2130 err = dom_node_append_child(script_node, text_node, &spare_node);
2131 if (err != DOM_NO_ERR) {
2132 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not insert code node into script node");
2133 goto out_unparented;
2134 }
2135 dom_node_unref(spare_node); /* We do not need the spare ref at all */
2136
2137 err = dom_node_append_child(body_node, script_node, &spare_node);
2138 if (err != DOM_NO_ERR) {
2139 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not insert script node into document body");
2140 goto out_unparented;
2141 }
2142 dom_node_unref(spare_node); /* Again no need for the spare ref */
2143
2144 /* We successfully inserted the node into the DOM */
2145
2146 result = true;
2147
2148 /* Now we unwind, starting by removing the script from wherever it
2149 * ended up parented
2150 */
2151
2152 err = dom_node_get_parent_node(script_node, &spare_node);
2153 if (err == DOM_NO_ERR && spare_node != NULL) {
2154 dom_node *second_spare;
2155 err = dom_node_remove_child(spare_node, script_node, &second_spare);
2156 if (err == DOM_NO_ERR) {
2157 dom_node_unref(second_spare);
2158 }
2159 dom_node_unref(spare_node);
2160 }
2161
2162out_unparented:
2163 dom_node_unref(script_node);
2164out_no_script_node:
2165 dom_node_unref(text_node);
2166out_no_text_node:
2167 dom_node_unref(body_node);
2168out_no_body:
2169 dom_string_unref(dom_src);
2170out_no_string:
2171 return result;
2172}
2173
2174/* See \ref content_saw_insecure_objects */
2175static bool
2177{
2178 html_content *htmlc = (html_content *)c;
2179 struct content_html_object *obj = htmlc->object_list;
2180
2181 /* Check through the object list */
2182 while (obj != NULL) {
2183 if (obj->content != NULL) {
2185 return true;
2186 }
2187 obj = obj->next;
2188 }
2189
2190 /* Now check the script list */
2191 if (html_saw_insecure_scripts(htmlc)) {
2192 return true;
2193 }
2194
2195 /* Now check stylesheets */
2197 return true;
2198 }
2199
2200 return false;
2201}
2202
2203/**
2204 * Compute the type of a content
2205 *
2206 * \return CONTENT_HTML
2207 */
2209{
2210 return CONTENT_HTML;
2211}
2212
2213
2214static void html_fini(void)
2215{
2216 html_css_fini();
2217}
2218
2219/**
2220 * Finds all occurrences of a given string in an html box
2221 *
2222 * \param pattern the string pattern to search for
2223 * \param p_len pattern length
2224 * \param cur pointer to the current box
2225 * \param case_sens whether to perform a case sensitive search
2226 * \param context The search context to add the entry to.
2227 * \return true on success, false on memory allocation failure
2228 */
2229static nserror
2230find_occurrences_html_box(const char *pattern,
2231 int p_len,
2232 struct box *cur,
2233 bool case_sens,
2234 struct textsearch_context *context)
2235{
2236 struct box *a;
2237 nserror res = NSERROR_OK;
2238
2239 /* ignore this box, if there's no visible text */
2240 if (!cur->object && cur->text) {
2241 const char *text = cur->text;
2242 unsigned length = cur->length;
2243
2244 while (length > 0) {
2245 unsigned match_length;
2246 unsigned match_offset;
2247 const char *new_text;
2248 const char *pos;
2249
2251 length,
2252 pattern,
2253 p_len,
2254 case_sens,
2255 &match_length);
2256 if (!pos)
2257 break;
2258
2259 /* found string in box => add to list */
2260 match_offset = pos - cur->text;
2261
2262 res = content_textsearch_add_match(context,
2263 cur->byte_offset + match_offset,
2264 cur->byte_offset + match_offset + match_length,
2265 cur,
2266 cur);
2267 if (res != NSERROR_OK) {
2268 return res;
2269 }
2270
2271 new_text = pos + match_length;
2272 length -= (new_text - text);
2273 text = new_text;
2274 }
2275 }
2276
2277 /* and recurse */
2278 for (a = cur->children; a; a = a->next) {
2279 res = find_occurrences_html_box(pattern,
2280 p_len,
2281 a,
2282 case_sens,
2283 context);
2284 if (res != NSERROR_OK) {
2285 return res;
2286 }
2287 }
2288
2289 return res;
2290}
2291
2292/**
2293 * Finds all occurrences of a given string in the html box tree
2294 *
2295 * \param pattern the string pattern to search for
2296 * \param p_len pattern length
2297 * \param c The content to search
2298 * \param csens whether to perform a case sensitive search
2299 * \param context The search context to add the entry to.
2300 * \return true on success, false on memory allocation failure
2301 */
2302static nserror
2304 struct textsearch_context *context,
2305 const char *pattern,
2306 int p_len,
2307 bool csens)
2308{
2309 html_content *html = (html_content *)c;
2310
2311 if (html->layout == NULL) {
2312 return NSERROR_INVALID;
2313 }
2314
2315 return find_occurrences_html_box(pattern,
2316 p_len,
2317 html->layout,
2318 csens,
2319 context);
2320}
2321
2322
2323static nserror
2325 unsigned start_idx,
2326 unsigned end_idx,
2327 struct box *start_box,
2328 struct box *end_box,
2329 struct rect *bounds)
2330{
2331 /* get box position and jump to it */
2332 box_coords(start_box, &bounds->x0, &bounds->y0);
2333 /* \todo: move x0 in by correct idx */
2334 box_coords(end_box, &bounds->x1, &bounds->y1);
2335 /* \todo: move x1 in by correct idx */
2336 bounds->x1 += end_box->width;
2337 bounds->y1 += end_box->height;
2338
2339 return NSERROR_OK;
2340}
2341
2342
2343/**
2344 * HTML content handler function table
2345 */
2347 .fini = html_fini,
2348 .create = html_create,
2349 .process_data = html_process_data,
2350 .data_complete = html_convert,
2351 .reformat = html_reformat,
2352 .destroy = html_destroy,
2353 .stop = html_stop,
2354 .mouse_track = html_mouse_track,
2355 .mouse_action = html_mouse_action,
2356 .keypress = html_keypress,
2357 .redraw = html_redraw,
2358 .open = html_open,
2359 .close = html_close,
2360 .get_selection = html_get_selection,
2361 .clear_selection = html_clear_selection,
2362 .get_contextual_content = html_get_contextual_content,
2363 .scroll_at_point = html_scroll_at_point,
2364 .drop_file_at_point = html_drop_file_at_point,
2365 .debug_dump = html_debug_dump,
2366 .debug = html_debug,
2367 .clone = html_clone,
2368 .get_encoding = html_encoding,
2369 .type = html_content_type,
2370 .exec = html_exec,
2371 .saw_insecure_objects = html_saw_insecure_objects,
2372 .textsearch_find = html_textsearch_find,
2373 .textsearch_bounds = html_textsearch_bounds,
2374 .textselection_redraw = html_textselection_redraw,
2375 .textselection_copy = html_textselection_copy,
2376 .textselection_get_end = html_textselection_get_end,
2377 .no_share = true,
2378};
2379
2380
2381/* exported function documented in html/html.h */
2383{
2384 uint32_t i;
2385 nserror error;
2386
2387 error = html_css_init();
2388 if (error != NSERROR_OK)
2389 goto error;
2390
2391 for (i = 0; i < NOF_ELEMENTS(html_types); i++) {
2394 if (error != NSERROR_OK)
2395 goto error;
2396 }
2397
2398 return NSERROR_OK;
2399
2400error:
2401 html_fini();
2402
2403 return error;
2404}
STATIC char result[100]
Definition: arexx.c:77
Helpers for ASCII string handling.
Box interface.
@ TOP
Definition: box.h:98
@ BOTTOM
Definition: box.h:98
@ LEFT
Definition: box.h:98
@ RIGHT
Definition: box.h:98
nserror dom_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb, void **box_conversion_context)
Construct a box tree from a dom and html content.
nserror cancel_dom_to_box(void *box_conversion_context)
aborts any ongoing box construction
HTML Box tree construction interface.
struct box * box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y)
Find the boxes at a point.
Definition: box_inspect.c:583
void box_coords(struct box *box, int *x, int *y)
Find the absolute coordinates of a box.
Definition: box_inspect.c:549
struct box * box_find_by_id(struct box *box, lwc_string *id)
Find a box based upon its id attribute.
Definition: box_inspect.c:614
void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style)
Print a box tree to a file.
Definition: box_inspect.c:649
HTML Box tree inspection interface.
Browser window creation and manipulation interface.
nserror browser_window_get_features(struct browser_window *bw, int x, int y, struct browser_window_features *data)
Get access to any page features at the given coordinates.
float browser_window_get_scale(struct browser_window *bw)
Gets the scale of a browser window.
bool browser_window_scroll_at_point(struct browser_window *bw, int x, int y, int scrx, int scry)
Send a scroll request to a browser window at a particular point.
bool browser_window_drop_file_at_point(struct browser_window *bw, int x, int y, char *file)
Drop a file onto a browser window at a particular point, or determine if a file may be dropped onto t...
static osspriteop_area * buffer
The buffer characteristics.
Definition: buffer.c:55
HTML content handler CSS interface.
bool layout_document(html_content *content, int width, int height)
Calculate positions of boxes in a document.
Definition: layout.c:5396
interface to HTML layout.
nserror html_object_abort_objects(html_content *htmlc)
abort any content objects that have not completed fetching.
Definition: object.c:621
nserror html_object_close_objects(html_content *html)
close content of content objects associated with a HTML content
Definition: object.c:663
nserror html_object_free_objects(html_content *html)
release memory of content objects associated with a HTML content
Definition: object.c:687
nserror html_object_open_objects(html_content *html, struct browser_window *bw)
open content of content objects associated with a HTML content
Definition: object.c:598
HTML content object interface.
nserror html_textselection_get_end(struct content *c, unsigned *end_idx)
get maximum index of text section.
nserror html_textselection_copy(struct content *c, unsigned start_idx, unsigned end_idx, struct selection_string *selstr)
nserror html_textselection_redraw(struct content *c, unsigned start_idx, unsigned end_idx)
HTML text selection handling.
char * content_get_selection(hlcache_handle *h)
Get a text selection from a content.
Definition: content.c:858
void content_broadcast(struct content *c, content_msg msg, const union content_msg_data *data)
Send a message to all users.
Definition: content.c:752
void content_request_redraw(struct hlcache_handle *h, int x, int y, int width, int height)
Request a redraw of an area of a content.
Definition: content.c:450
void content_clear_selection(hlcache_handle *h)
Tell a content that any selection it has, or one of its objects has, must be cleared.
Definition: content.c:847
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
Definition: content.c:299
bool content_saw_insecure_objects(struct hlcache_handle *h)
Determine if the content referred to any insecure objects.
Definition: content.c:500
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks)
Definition: content.c:190
bool content_scroll_at_point(struct hlcache_handle *h, int x, int y, int scrx, int scry)
scroll content at coordnate
Definition: content.c:890
nserror content_get_contextual_content(struct hlcache_handle *h, int x, int y, struct browser_window_features *data)
Get positional contextural information for a content.
Definition: content.c:872
void content_set_error(struct content *c)
Put a content in status CONTENT_STATUS_ERROR and unlock the content.
Definition: content.c:313
void content__request_redraw(struct content *c, int x, int y, int width, int height)
Request a redraw of an area of a content.
Definition: content.c:459
content_status content__get_status(struct content *c)
Retrieve status of content.
Definition: content.c:1131
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
Definition: content.c:1051
const uint8_t * content__get_source_data(struct content *c, size_t *size)
Retrieve source of content.
Definition: content.c:1216
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
Definition: content.c:285
bool content_drop_file_at_point(struct hlcache_handle *h, int x, int y, char *file)
Drag and drop a file at coordinate.
Definition: content.c:906
void content_set_status(struct content *c, const char *status_message)
Updates content with new status.
Definition: content.c:270
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
Definition: content.c:769
nserror content_factory_register_handler(const char *mime_type, const content_handler *handler)
Register a handler with the content factory.
@ CONTENT_STATUS_READY
Some parts of content still being loaded, but can be displayed.
Definition: content_type.h:92
@ CONTENT_STATUS_DONE
Content has completed all processing.
Definition: content_type.h:95
@ CONTENT_STATUS_LOADING
Content is being fetched or converted and is not safe to display.
Definition: content_type.h:89
content_type
The type of a content.
Definition: content_type.h:53
@ CONTENT_HTML
content is HTML
Definition: content_type.h:58
@ CONTENT_MSG_GETDIMS
Get viewport dimensions.
Definition: content_type.h:149
@ CONTENT_MSG_STATUS
new status string
Definition: content_type.h:128
content_debug
Debugging dump operations.
Definition: content_type.h:30
@ CONTENT_DEBUG_RENDER
Debug the contents rendering.
Definition: content_type.h:32
content_encoding_type
Content encoding information types.
Definition: content_type.h:43
@ CONTENT_ENCODING_SOURCE
The content encoding source.
Definition: content_type.h:48
Useful interned string pointers (interface).
css_fixed nscss_screen_dpi
Screen DPI in fixed point units: defaults to 90, which RISC OS uses.
Definition: css.c:44
bool html_redraw_debug
Definition: redraw.c:68
void selection_reinit(struct selection *s)
Initialise the selection object to use the given box subtree as its root, ie.
Definition: selection.c:281
bool selection_clear(struct selection *s, bool redraw)
Clears the current selection, optionally causing the screen to be updated.
Definition: selection.c:518
struct selection * selection_create(struct content *c)
Creates a new selection object associated with a browser window.
Definition: selection.c:253
void selection_init(struct selection *s)
Initialise the selection object to use the given box subtree as its root, ie.
Definition: selection.c:302
void selection_destroy(struct selection *s)
Destroys a selection object clearing it if nesessary.
Definition: selection.c:269
char * selection_get_copy(struct selection *s)
Get copy of selection as string.
Definition: selection.c:457
Text selection within browser windows (interface).
bool textarea_scroll(struct textarea *ta, int scrx, int scry)
Scroll a textarea by an amount.
Definition: textarea.c:3367
bool textarea_clear_selection(struct textarea *ta)
Clear any selection in the textarea.
Definition: textarea.c:3205
textarea_mouse_status textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: textarea.c:3069
bool textarea_drop_text(struct textarea *ta, const char *text, size_t text_length)
Insert the text in a text area at the caret, replacing any selection.
Definition: textarea.c:2032
char * textarea_get_selection(struct textarea *ta)
Get selected text.
Definition: textarea.c:3278
Single/Multi-line UTF-8 text area interface.
dom_default_action_callback html_dom_event_fetcher(dom_string *type, dom_default_action_phase phase, void **pw)
html content DOM action callback function selector
Definition: dom_event.c:770
HTML content DOM event handling interface.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_BAD_ENCODING
The character set is unknown.
Definition: errors.h:45
@ NSERROR_BOX_CONVERT
Box conversion failed.
Definition: errors.h:50
@ NSERROR_DOM
DOM call returned error.
Definition: errors.h:52
@ NSERROR_UNKNOWN
Unknown error - DO NOT USE.
Definition: errors.h:31
@ NSERROR_STOPPED
Content conversion stopped.
Definition: errors.h:51
@ NSERROR_ENCODING_CHANGE
The character changed.
Definition: errors.h:47
@ NSERROR_INVALID
Invalid data.
Definition: errors.h:49
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
const char * type
Definition: filetype.cpp:44
void form_free(struct form *form)
Free a form and any controls it owns.
Definition: form.c:2329
void form_gadget_update_value(struct form_control *control, char *value)
Update gadget value.
Definition: form.c:2128
Interface to form handling functions internal to HTML content handler.
@ GADGET_TEXTAREA
Definition: form_internal.h:53
@ GADGET_PASSWORD
Definition: form_internal.h:55
@ GADGET_FILE
Definition: form_internal.h:58
@ GADGET_TEXTBOX
Definition: form_internal.h:49
struct form * html_forms_get_forms(const char *docenc, dom_html_document *doc)
Definition: forms.c:126
#define NOF_ELEMENTS(array)
Definition: search.c:67
struct atari_hotlist hl
Definition: hotlist.c:47
struct netsurf_table * guit
The global interface table.
Definition: gui_factory.c:50
Interface to core interface table.
struct content * hlcache_handle_get_content(const hlcache_handle *handle)
Retrieve a content object from a cache handle.
Definition: hlcache.c:776
High-level resource cache interface.
nserror html_css_init(void)
Initialise html content css handling.
Definition: css.c:716
nserror html_css_new_selection_context(html_content *c, css_select_ctx **ret_select_ctx)
create a new css selection context for an html content.
Definition: css.c:653
void html_css_fini(void)
Finalise html content css handling.
Definition: css.c:747
bool html_css_saw_insecure_stylesheets(html_content *html)
determine if any of the stylesheets were loaded insecurely
Definition: css.c:512
nserror html_css_free_stylesheets(html_content *html)
Free all css stylesheets associated with an HTML content.
Definition: css.c:531
nserror html_css_new_stylesheets(html_content *c)
Initialise core stylesheets for a content.
Definition: css.c:581
nserror html_css_quirks_stylesheets(html_content *c)
Initialise quirk stylesheets for a content.
Definition: css.c:552
static const content_handler html_content_handler
HTML content handler function table.
Definition: html.c:2346
static void html_fini(void)
Definition: html.c:2214
static nserror html_get_contextual_content(struct content *c, int x, int y, struct browser_window_features *data)
Get access to any content, link URLs and objects (images) currently at the given (x,...
Definition: html.c:1455
static nserror find_occurrences_html_box(const char *pattern, int p_len, struct box *cur, bool case_sens, struct textsearch_context *context)
Finds all occurrences of a given string in an html box.
Definition: html.c:2230
static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
Drop a file onto a content at a particular point, or determine if a file may be dropped onto the cont...
Definition: html.c:1683
bool html_exec(struct content *c, const char *src, size_t srclen)
execute some text as a script element
Definition: html.c:2090
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:133
bool html_begin_conversion(html_content *htmlc)
Begin conversion of an HTML document.
Definition: html.c:833
static content_type html_content_type(void)
Compute the type of a content.
Definition: html.c:2208
static nserror html_textsearch_find(struct content *c, struct textsearch_context *context, const char *pattern, int p_len, bool csens)
Finds all occurrences of a given string in the html box tree.
Definition: html.c:2303
static void html_document_user_data_handler(dom_node_operation operation, dom_string *key, void *data, struct dom_node *src, struct dom_node *dst)
Definition: html.c:419
void html_redraw_a_box(hlcache_handle *h, struct box *box)
Redraw a box.
Definition: html.c:1111
static void html_destroy(struct content *c)
Destroy a CONTENT_HTML and free all resources it owns.
Definition: html.c:1202
void html_finish_conversion(html_content *htmlc)
Complete conversion of an HTML document.
Definition: html.c:341
void html__redraw_a_box(struct html_content *html, struct box *box)
Redraw a box.
Definition: html.c:1130
nserror html_init(void)
initialise content handler
Definition: html.c:2382
static bool html_saw_insecure_objects(struct content *c)
Definition: html.c:2176
static nserror html_process_encoding_change(struct content *c, const char *data, unsigned int size)
Definition: html.c:649
static nserror html_open(struct content *c, struct browser_window *bw, struct content *page, struct object_params *params)
Handle a window containing a CONTENT_HTML being opened.
Definition: html.c:1329
static bool html_convert(struct content *c)
Convert a CONTENT_HTML for display.
Definition: html.c:777
static nserror html_clone(const struct content *old, struct content **newc)
Definition: html.c:1311
static void html_box_convert_done(html_content *c, bool success)
Perform post-box-creation conversion of a document.
Definition: html.c:216
static const char * html_types[]
Definition: html.c:83
static bool html_process_data(struct content *c, const char *data, unsigned int size)
Process data for CONTENT_HTML.
Definition: html.c:736
struct content_html_iframe * html_get_iframe(hlcache_handle *h)
Retrieve iframes used in an HTML document.
Definition: html.c:2024
static void html_clear_selection(struct content *c)
Return an HTML content's selection context.
Definition: html.c:1383
nsurl * html_get_base_url(hlcache_handle *h)
Retrieve an HTML content's base URL.
Definition: html.c:2039
static void html_stop(struct content *c)
Stop loading a CONTENT_HTML.
Definition: html.c:1011
static nserror html_create(const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Create a CONTENT_HTML.
Definition: html.c:605
static void html__dom_user_data_handler(dom_node_operation operation, dom_string *key, void *_data, struct dom_node *src, struct dom_node *dst)
Helper for file gadgets to store their filename unencoded on the dom node associated with the gadget.
Definition: html.c:1597
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:111
static void html_free_layout(html_content *htmlc)
Definition: html.c:1188
static void html_get_dimensions(html_content *htmlc)
Definition: html.c:306
dom_document * html_get_document(hlcache_handle *h)
Retrieve HTML document tree.
Definition: html.c:1953
static void html__set_file_gadget_filename(struct content *c, struct form_control *gadget, const char *fn)
Definition: html.c:1634
struct box * html_get_box_tree(hlcache_handle *h)
Retrieve box tree.
Definition: html.c:1971
const char * html_get_base_target(hlcache_handle *h)
Retrieve an HTML content's base target.
Definition: html.c:2054
bool html_get_id_offset(hlcache_handle *h, lwc_string *frag_id, int *x, int *y)
Retrieve layout coordinates of box with given id.
Definition: html.c:2073
static nserror html_create_html_data(html_content *c, const http_parameter *params)
Definition: html.c:453
static void html_reformat(struct content *c, int width, int height)
Reformat a CONTENT_HTML to a new width.
Definition: html.c:1053
static nserror html_debug_dump(struct content *c, FILE *f, enum content_debug op)
Dump debug info concerning the html_content.
Definition: html.c:1857
static void html_destroy_frameset(struct content_html_frames *frameset)
Definition: html.c:1141
static char * html_get_selection(struct content *c)
Return an HTML content's selection context.
Definition: html.c:1417
nserror html_proceed_to_done(html_content *html)
Complete the HTML content state machine iff all scripts are finished.
Definition: html.c:285
static void html_destroy_iframe(struct content_html_iframe *iframe)
Definition: html.c:1171
static const char * html_encoding(const struct content *c, enum content_encoding_type op)
Retrieve the charset of an HTML document.
Definition: html.c:1987
bool html_can_begin_conversion(html_content *htmlc)
Test if an HTML content conversion can begin.
Definition: html.c:814
static nserror html_close(struct content *c)
Handle a window containing a CONTENT_HTML being closed.
Definition: html.c:1357
static nserror html_textsearch_bounds(struct content *c, unsigned start_idx, unsigned end_idx, struct box *start_box, struct box *end_box, struct rect *bounds)
Definition: html.c:2324
struct content_html_frames * html_get_frameset(hlcache_handle *h)
Retrieve framesets used in an HTML document.
Definition: html.c:2009
static bool html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
Scroll deepest thing within the content which can be scrolled at given point.
Definition: html.c:1534
static bool fire_dom_event(dom_event *event, dom_node *target)
Fire an event at the DOM.
Definition: html.c:97
void html_set_file_gadget_filename(struct hlcache_handle *hl, struct form_control *gadget, const char *fn)
set filename on a file gadget
Definition: html.c:1666
static nserror html_debug(struct content *c, enum content_debug op)
set debug status.
Definition: html.c:1841
Interface to text/html content handler.
Interface to HTML content handler to save documents.
HTTP header parsing functions.
nsurl * imagemap_get(struct html_content *c, const char *key, unsigned long x, unsigned long y, unsigned long click_x, unsigned long click_y, const char **target)
Retrieve url associated with imagemap entry.
Definition: imagemap.c:737
void imagemap_destroy(html_content *c)
Destroy hashtable of imagemaps.
Definition: imagemap.c:200
nserror imagemap_extract(html_content *c)
Extract all imagemaps from a document tree.
Definition: imagemap.c:603
Interface to HTML imagemap.
Generic bitmap handling interface.
Public content interface.
content_type content_get_type(struct hlcache_handle *h)
Retrieve computed type of content.
Definition: content.c:1061
Interface to platform-specific layout operation table.
Interface to platform-specific miscellaneous browser operation table.
@ BROWSER_MOUSE_PRESS_1
button 1 pressed
Definition: mouse.h:50
Interface to platform-specific utf8 operations.
nserror html_mouse_track(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse tracking (including drags) in an HTML content window.
Definition: interaction.c:1451
bool html_keypress(struct content *c, uint32_t key)
Handle keypresses.
Definition: interaction.c:1519
nserror html_mouse_action(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse clicks and movements in an HTML content window.
Definition: interaction.c:1462
HTML content user interaction handling.
Interface to javascript engine functions.
void js_destroythread(jsthread *thread)
Destroy a javascript thread.
Definition: dukky.c:815
bool js_fire_event(jsthread *thread, const char *type, struct dom_document *doc, struct dom_node *target)
fire an event at a dom node
Definition: dukky.c:1567
nserror js_closethread(jsthread *thread)
Close a javascript thread.
Definition: dukky.c:761
Interface to key press operations.
@ NS_KEY_RIGHT
Definition: keypress.h:51
@ NS_KEY_LEFT
Definition: keypress.h:50
@ NS_KEY_DOWN
Definition: keypress.h:53
@ NS_KEY_PAGE_UP
Definition: keypress.h:65
@ NS_KEY_PAGE_DOWN
Definition: keypress.h:66
@ NS_KEY_TEXT_START
Definition: keypress.h:59
@ NS_KEY_TEXT_END
Definition: keypress.h:60
@ NS_KEY_UP
Definition: keypress.h:52
@ NS_KEY_ESCAPE
Definition: keypress.h:47
nserror libdom_hubbub_error_to_nserror(dom_hubbub_error error)
Convert libdom hubbub binding errors to nserrors.
Definition: libdom.c:122
nserror libdom_dump_structure(dom_node *node, FILE *f, int depth)
Walk though a DOM (sub)tree, in depth first order, printing DOM structure.
Definition: libdom.c:331
libdom utilities (implementation).
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
nsurl * nsurl_ref(nsurl *url)
Increment the reference count to a NetSurf URL object.
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
Join a base url to a relative link part, creating a new NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
nserror http_parameter_list_find_item(const http_parameter *list, lwc_string *name, lwc_string **value)
Find a named item in an HTTP parameter list.
Definition: parameter.c:114
#define NS_TRANSPARENT
Transparent colour value.
Definition: plot_style.h:39
Private data for text/html content.
dom_hubbub_error html_process_script(void *ctx, dom_node *node)
process script node parser callback
Definition: script.c:566
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:1944
@ HTML_DRAG_NONE
Definition: private.h:40
bool html_saw_insecure_scripts(html_content *htmlc)
Check if any of the scripts loaded were insecure.
Definition: script.c:611
nserror html_script_free(html_content *htmlc)
Free all script resources and references for a html content.
Definition: script.c:636
@ HTML_FOCUS_SELF
Focus is our own.
Definition: private.h:76
@ HTML_SELECTION_SELF
Selection in one of our textareas.
Definition: private.h:62
@ HTML_SELECTION_NONE
Definition: private.h:60
@ HTML_SELECTION_TEXTAREA
No selection.
Definition: private.h:61
@ HTML_SELECTION_CONTENT
Selection in this html content.
Definition: private.h:63
nserror html_script_exec(html_content *htmlc, bool allow_defer)
Attempt script execution for defer and async scripts.
Definition: script.c:59
int width
Definition: gui.c:160
int height
Definition: gui.c:161
bool scrollbar_scroll(struct scrollbar *s, int change)
Scroll the scrollbar by given amount.
Definition: scrollbar.c:562
Scrollbar widget interface.
static css_error node_name(void *pw, void *node, css_qname *qname)
Callback to retrieve a node's name.
Definition: select.c:373
Interface to utility string handling.
int width
border-width (pixels)
Definition: box.h:107
Node in box tree.
Definition: box.h:177
int descendant_y1
bottom edge of descendants
Definition: box.h:312
struct box_border border[4]
Border: TOP, RIGHT, BOTTOM, LEFT.
Definition: box.h:327
int width
Width of content box (excluding padding etc.).
Definition: box.h:289
struct scrollbar * scroll_x
Horizontal scroll.
Definition: box.h:332
size_t byte_offset
Byte offset within a textual representation of this content.
Definition: box.h:370
struct column * col
Array of table column data for TABLE only.
Definition: box.h:407
struct box * children
First child box, or NULL.
Definition: box.h:226
int height
Height of content box (excluding padding etc.).
Definition: box.h:293
int margin[4]
Margin: TOP, RIGHT, BOTTOM, LEFT.
Definition: box.h:317
char * usemap
(Image)map to use with this object, or NULL if none
Definition: box.h:429
const char * target
Link target, or NULL.
Definition: box.h:381
struct box * next
Next sibling box, or NULL.
Definition: box.h:216
struct scrollbar * scroll_y
Vertical scroll.
Definition: box.h:337
struct nsurl * href
Link, or NULL.
Definition: box.h:376
int descendant_x1
right edge of descendants
Definition: box.h:311
struct browser_window * iframe
Iframe's browser_window, or NULL if none.
Definition: box.h:452
css_computed_style * style
Style for this box.
Definition: box.h:205
size_t length
Length of text.
Definition: box.h:360
struct hlcache_handle * object
Object in this box (usually an image), or NULL if none.
Definition: box.h:441
char * text
Text, or NULL if none.
Definition: box.h:355
int padding[4]
Padding: TOP, RIGHT, BOTTOM, LEFT.
Definition: box.h:322
int x
Coordinate of left padding edge relative to parent box, or relative to ancestor that contains this bo...
Definition: box.h:280
struct form_control * gadget
Form control data, or NULL if not a form control.
Definition: box.h:423
int y
Coordinate of top padding edge, relative as for x.
Definition: box.h:284
Page features at a specific spatial location.
struct hlcache_handle * object
Object at position or NULL.
enum browser_window_features::@56 form_features
type of form feature.
struct nsurl * link
URL of a link or NULL.
Browser window data.
Content operation function table.
void(* fini)(void)
Frame tree (frameset or frame tag)
Definition: html.h:108
char * name
frame margin height
Definition: html.h:117
int rows
number of columns in frameset
Definition: html.h:110
struct content_html_frames * children
frame border colour
Definition: html.h:125
bool no_resize
frame url
Definition: html.h:120
int margin_width
frame width
Definition: html.h:114
struct nsurl * url
frame name (for targetting)
Definition: html.h:118
browser_scrolling scrolling
frame is not resizable
Definition: html.h:121
bool border
scrolling characteristics
Definition: html.h:122
colour border_colour
frame has a border
Definition: html.h:123
int margin_height
frame margin width
Definition: html.h:115
struct frame_dimension width
number of rows in frameset
Definition: html.h:112
struct frame_dimension height
frame width
Definition: html.h:113
Inline frame list (iframe tag)
Definition: html.h:131
struct content_html_iframe * next
frame border colour
Definition: html.h:144
struct nsurl * url
frame name (for targetting)
Definition: html.h:138
char * name
frame margin height
Definition: html.h:137
An object (img, object, etc.
Definition: html.h:93
struct content_html_object * next
Next in chain.
Definition: html.h:95
struct hlcache_handle * content
Content, or 0.
Definition: html.h:97
Content which corresponds to a single URL.
int height
Height dimension, if applicable.
int width
Width dimension, if applicable.
unsigned int active
Number of child fetches or conversions currently in progress.
content_status status
Current status.
unsigned int size
Estimated size of all data associated with this content.
uint64_t reformat_time
Earliest time to attempt a period reflow while fetching a page's objects.
struct nsurl * refresh
URL for refresh request.
Form control.
Definition: form_internal.h:73
struct form_textarea_data data
form_control_type type
Type of control.
Definition: form_internal.h:79
void * node
Corresponding DOM node.
Definition: form_internal.h:74
struct box * box
Box for control.
Definition: form_internal.h:89
HTML form.
char * action
Absolute URL to submit to.
struct form * prev
Previous form in doc.
char * document_charset
Charset of document containing form.
enum frame_dimension::@63 unit
nserror(* local_to_utf8)(const char *string, size_t len, char **result)
Convert a string encoded in the system local encoding to UTF-8.
Definition: utf8.h:50
High-level cache handle.
Definition: hlcache.c:66
Data specific to CONTENT_HTML.
Definition: private.h:93
dom_document_quirks_mode quirks
Quirkyness of document.
Definition: private.h:103
struct imagemap ** imagemaps
Hash table of imagemaps.
Definition: private.h:174
struct selection * sel
HTML content's own text selection object.
Definition: private.h:205
int * bctx
A talloc context purely for the render box tree.
Definition: private.h:134
struct content_html_object * object_list
List of objects.
Definition: private.h:170
struct content_html_frames * frameset
Frameset information.
Definition: private.h:180
union html_drag_owner drag_owner
Widget capturing all mouse events.
Definition: private.h:192
bool refresh
Whether a meta refresh has been handled.
Definition: private.h:119
dom_hubbub_parser * parser
Parser object handle.
Definition: private.h:96
colour background_colour
Document background colour.
Definition: private.h:142
html_focus_type focus_type
Current input focus target type.
Definition: private.h:200
char * encoding
Encoding of source, NULL if unknown.
Definition: private.h:106
struct browser_window * bw
Browser window containing this document, or NULL if not open.
Definition: private.h:177
unsigned int num_objects
Number of entries in object_list.
Definition: private.h:168
dom_document * document
Document tree.
Definition: private.h:101
struct nsurl * base_url
Base URL (may be a copy of content->url).
Definition: private.h:111
struct html_stylesheet * stylesheets
Stylesheets.
Definition: private.h:157
bool conversion_begun
Whether or not the conversion has begun.
Definition: private.h:98
struct form * forms
Forms, in reverse order to document.
Definition: private.h:172
html_drag_type drag_type
Current drag type.
Definition: private.h:190
union html_focus_owner focus_owner
Current input focus target.
Definition: private.h:202
char * base_target
Base target.
Definition: private.h:113
css_select_ctx * select_ctx
Style selection media specification.
Definition: private.h:159
css_media media
Definition: private.h:161
const struct gui_layout_table * font_func
Font callback table.
Definition: private.h:145
struct jsthread * jsthread
javascript thread in use
Definition: private.h:152
struct html_content * page
Content of type CONTENT_HTML containing this, or NULL if not an object within a page.
Definition: private.h:187
struct content_html_iframe * iframe
Inline frame information.
Definition: private.h:183
html_selection_type selection_type
Current selection state.
Definition: private.h:195
void * box_conversion_context
A context pointer for the box conversion, NULL if no conversion is in progress.
Definition: private.h:138
dom_hubbub_encoding_source encoding_source
Source of encoding information.
Definition: private.h:108
bool parse_completed
Whether the parse has been completed.
Definition: private.h:97
unsigned int scripts_count
Number of entries in scripts.
Definition: private.h:148
union html_selection_owner selection_owner
Current selection owner.
Definition: private.h:197
bool enable_scripting
Whether scripts are enabled for this content.
Definition: private.h:128
struct content base
Definition: private.h:94
bool aborted
Content has been aborted in the LOADING state.
Definition: private.h:116
bool had_initial_layout
Whether an initial layout has been done.
Definition: private.h:125
css_unit_ctx unit_len_ctx
CSS length conversion context for document.
Definition: private.h:163
dom_node * title
Definition: private.h:131
struct box * layout
Box tree, or NULL.
Definition: private.h:140
unsigned int stylesheet_count
Number of entries in stylesheet_content.
Definition: private.h:155
bool reflowing
Whether a layout (reflow) is in progress.
Definition: private.h:122
lwc_string * universal
Definition: private.h:165
struct html_script * scripts
Scripts.
Definition: private.h:150
bool modified
Definition: html.h:61
Representation of an HTTP parameter.
Definition: parameter.c:31
Handle to low-level cache object.
Definition: llcache.c:76
struct gui_layout_table * layout
Layout table.
Definition: gui_table.h:163
struct gui_utf8_table * utf8
UTF8 table.
Definition: gui_table.h:115
Parameters for object element and similar elements.
Definition: box.h:164
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
The context for a free text search.
Definition: textsearch.c:84
int talloc_free(void *ptr)
Definition: talloc.c:760
const char * content_textsearch_find_pattern(const char *string, int s_len, const char *pattern, int p_len, bool case_sens, unsigned int *m_len)
Find the first occurrence of 'match' in 'string' and return its index.
Definition: textsearch.c:475
nserror content_textsearch_add_match(struct textsearch_context *context, unsigned start_idx, unsigned end_idx, struct box *start_box, struct box *end_box)
Add a new entry to the list of matches.
Definition: textsearch.c:586
Interface to HTML searching.
Extra data for some content_msg messages.
Definition: content.h:60
unsigned * viewport_width
Definition: content.h:150
browser_window_console_source src
The source of the logging.
Definition: content.h:66
struct content_msg_data::@102 getdims
CONTENT_MSG_GETDIMS - Get the viewport dimensions.
const char * explicit_status_text
CONTENT_MSG_STATUS - Status message update.
Definition: content.h:128
bool no_owner
Definition: private.h:53
struct box * content
Definition: private.h:72
struct box * textarea
Definition: private.h:71
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_uint(OPTION)
Get the value of an unsigned integer option.
Definition: nsoption.h:322
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
size_t utf8_from_ucs4(uint32_t c, char *s)
Convert a single UCS4 character into a UTF-8 multibyte sequence.
Definition: utf8.c:56
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.
#define SLEN(x)
Calculate length of constant C string.
Definition: utils.h:88
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978