NetSurf
css.c
Go to the documentation of this file.
1/*
2 * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <string.h>
20#include <assert.h>
21#include <libwapcaplet/libwapcaplet.h>
22#include <dom/dom.h>
23
24#include "utils/errors.h"
25#include "utils/corestrings.h"
26#include "utils/utils.h"
27#include "utils/http.h"
28#include "utils/log.h"
29#include "utils/messages.h"
32#include "content/fetch.h"
33#include "content/hlcache.h"
35
36#include "css/css.h"
37#include "css/hints.h"
38#include "css/internal.h"
39
40/* Define to trace import fetches */
41#undef NSCSS_IMPORT_TRACE
42
43/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
44css_fixed nscss_screen_dpi = F_90;
45
46struct content_css_data;
47
48/**
49 * Type of callback called when a CSS object has finished
50 *
51 * \param css CSS object that has completed
52 * \param pw Client-specific data
53 */
54typedef void (*nscss_done_callback)(struct content_css_data *css, void *pw);
55
56/**
57 * CSS content data
58 */
60{
61 css_stylesheet *sheet; /**< Stylesheet object */
62 char *charset; /**< Character set of stylesheet */
63 struct nscss_import *imports; /**< Array of imported sheets */
64 uint32_t import_count; /**< Number of sheets imported */
65 uint32_t next_to_register; /**< Index of next import to register */
66 nscss_done_callback done; /**< Completion callback */
67 void *pw; /**< Client data */
68};
69
70/**
71 * CSS content data
72 */
73typedef struct nscss_content
74{
75 struct content base; /**< Underlying content object */
76
77 struct content_css_data data; /**< CSS data */
79
80/**
81 * Context for import fetches
82 */
83typedef struct {
84 struct content_css_data *css; /**< Object containing import */
85 uint32_t index; /**< Index into parent sheet's
86 * imports array */
88
89static bool nscss_convert(struct content *c);
90static void nscss_destroy(struct content *c);
91static nserror nscss_clone(const struct content *old, struct content **newc);
92static bool nscss_matches_quirks(const struct content *c, bool quirks);
94
96 const char *url, const char *charset, bool quirks,
98static css_error nscss_process_css_data(struct content_css_data *c, const char *data,
99 unsigned int size);
100static css_error nscss_convert_css_data(struct content_css_data *c);
101static void nscss_destroy_css_data(struct content_css_data *c);
102
103static void nscss_content_done(struct content_css_data *css, void *pw);
104static css_error nscss_handle_import(void *pw, css_stylesheet *parent,
105 lwc_string *url);
106static nserror nscss_import(hlcache_handle *handle,
107 const hlcache_event *event, void *pw);
108static css_error nscss_import_complete(nscss_import_ctx *ctx);
109
110static css_error nscss_register_imports(struct content_css_data *c);
111static css_error nscss_register_import(struct content_css_data *c,
112 const hlcache_handle *import);
113
114
115static css_stylesheet *blank_import;
116
117
118/**
119 * Initialise a CSS content
120 *
121 * \param handler content handler
122 * \param imime_type mime-type
123 * \param params Content-Type parameters
124 * \param llcache handle to content
125 * \param fallback_charset The character set to fallback to.
126 * \param quirks allow quirks
127 * \param c Content to initialise
128 * \return NSERROR_OK or error cod eon faliure
129 */
130static nserror
132 lwc_string *imime_type,
133 const http_parameter *params,
135 const char *fallback_charset,
136 bool quirks,
137 struct content **c)
138{
140 const char *charset = NULL;
141 const char *xnsbase = NULL;
142 lwc_string *charset_value = NULL;
143 nserror error;
144
145 result = calloc(1, sizeof(nscss_content));
146 if (result == NULL)
147 return NSERROR_NOMEM;
148
149 error = content__init(&result->base, handler, imime_type,
150 params, llcache, fallback_charset, quirks);
151 if (error != NSERROR_OK) {
152 free(result);
153 return error;
154 }
155
156 /* Find charset specified on HTTP layer, if any */
157 error = http_parameter_list_find_item(params, corestring_lwc_charset,
158 &charset_value);
159 if (error != NSERROR_OK || lwc_string_length(charset_value) == 0) {
160 /* No charset specified, use fallback, if any */
161 /** \todo libcss will take this as gospel, which is wrong */
162 charset = fallback_charset;
163 } else {
164 charset = lwc_string_data(charset_value);
165 }
166
167 /* Compute base URL for stylesheet */
168 xnsbase = llcache_handle_get_header(llcache, "X-NS-Base");
169 if (xnsbase == NULL) {
170 xnsbase = nsurl_access(content_get_url(&result->base));
171 }
172
173 error = nscss_create_css_data(&result->data,
174 xnsbase, charset, result->base.quirks,
176 if (error != NSERROR_OK) {
178 if (charset_value != NULL)
179 lwc_string_unref(charset_value);
180 free(result);
181 return error;
182 }
183
184 if (charset_value != NULL)
185 lwc_string_unref(charset_value);
186
187 *c = (struct content *) result;
188
189 return NSERROR_OK;
190}
191
192/**
193 * Create a struct content_css_data, creating a stylesheet object
194 *
195 * \param c Struct to populate
196 * \param url URL of stylesheet
197 * \param charset Stylesheet charset
198 * \param quirks Stylesheet quirks mode
199 * \param done Callback to call when content has completed
200 * \param pw Client data for \a done
201 * \return NSERROR_OK on success, NSERROR_NOMEM on memory exhaustion
202 */
204 const char *url, const char *charset, bool quirks,
205 nscss_done_callback done, void *pw)
206{
207 css_error error;
208 css_stylesheet_params params;
209
210 c->pw = pw;
211 c->done = done;
212 c->next_to_register = (uint32_t) -1;
213 c->import_count = 0;
214 c->imports = NULL;
215 if (charset != NULL)
216 c->charset = strdup(charset);
217 else
218 c->charset = NULL;
219
220 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
221 params.level = CSS_LEVEL_DEFAULT;
222 params.charset = charset;
223 params.url = url;
224 params.title = NULL;
225 params.allow_quirks = quirks;
226 params.inline_style = false;
227 params.resolve = nscss_resolve_url;
228 params.resolve_pw = NULL;
229 params.import = nscss_handle_import;
230 params.import_pw = c;
231 params.color = ns_system_colour;
232 params.color_pw = NULL;
233 params.font = NULL;
234 params.font_pw = NULL;
235
236 error = css_stylesheet_create(&params, &c->sheet);
237 if (error != CSS_OK) {
238 return NSERROR_NOMEM;
239 }
240
241 return NSERROR_OK;
242}
243
244/**
245 * Process CSS source data
246 *
247 * \param c Content structure
248 * \param data Data to process
249 * \param size Number of bytes to process
250 * \return true on success, false on failure
251 */
252static bool
253nscss_process_data(struct content *c, const char *data, unsigned int size)
254{
255 nscss_content *css = (nscss_content *) c;
256 css_error error;
257
258 error = nscss_process_css_data(&css->data, data, size);
259 if (error != CSS_OK && error != CSS_NEEDDATA) {
261 }
262
263 return (error == CSS_OK || error == CSS_NEEDDATA);
264}
265
266/**
267 * Process CSS data
268 *
269 * \param c CSS content object
270 * \param data Data to process
271 * \param size Number of bytes to process
272 * \return CSS_OK on success, appropriate error otherwise
273 */
274static css_error nscss_process_css_data(struct content_css_data *c,
275 const char *data, unsigned int size)
276{
277 return css_stylesheet_append_data(c->sheet,
278 (const uint8_t *) data, size);
279}
280
281/**
282 * Convert a CSS content ready for use
283 *
284 * \param c Content to convert
285 * \return true on success, false on failure
286 */
287bool nscss_convert(struct content *c)
288{
289 nscss_content *css = (nscss_content *) c;
290 css_error error;
291
292 error = nscss_convert_css_data(&css->data);
293 if (error != CSS_OK) {
295 return false;
296 }
297
298 return true;
299}
300
301/**
302 * Convert CSS data ready for use
303 *
304 * \param c CSS data to convert
305 * \return CSS error
306 */
307static css_error nscss_convert_css_data(struct content_css_data *c)
308{
309 css_error error;
310
311 error = css_stylesheet_data_done(c->sheet);
312
313 /* Process pending imports */
314 if (error == CSS_IMPORTS_PENDING) {
315 /* We must not have registered any imports yet */
316 assert(c->next_to_register == (uint32_t) -1);
317
318 /* Start registering, until we find one that
319 * hasn't finished fetching */
320 c->next_to_register = 0;
321 error = nscss_register_imports(c);
322 } else if (error == CSS_OK) {
323 /* No imports, and no errors, so complete conversion */
324 c->done(c, c->pw);
325 } else {
326 const char *url;
327
328 if (css_stylesheet_get_url(c->sheet, &url) == CSS_OK) {
329 NSLOG(netsurf, INFO, "Failed converting %p %s (%d)",
330 c, url, error);
331 } else {
332 NSLOG(netsurf, INFO, "Failed converting %p (%d)", c,
333 error);
334 }
335 }
336
337 return error;
338}
339
340/**
341 * Clean up a CSS content
342 *
343 * \param c Content to clean up
344 */
345void nscss_destroy(struct content *c)
346{
347 nscss_content *css = (nscss_content *) c;
348
350}
351
352/**
353 * Clean up CSS data
354 *
355 * \param c CSS data to clean up
356 */
358{
359 uint32_t i;
360
361 for (i = 0; i < c->import_count; i++) {
362 if (c->imports[i].c != NULL) {
364 }
365 c->imports[i].c = NULL;
366 }
367
368 free(c->imports);
369
370 if (c->sheet != NULL) {
371 css_stylesheet_destroy(c->sheet);
372 c->sheet = NULL;
373 }
374
375 free(c->charset);
376}
377
378nserror nscss_clone(const struct content *old, struct content **newc)
379{
380 const nscss_content *old_css = (const nscss_content *) old;
381 nscss_content *new_css;
382 const uint8_t *data;
383 size_t size;
384 nserror error;
385
386 new_css = calloc(1, sizeof(nscss_content));
387 if (new_css == NULL)
388 return NSERROR_NOMEM;
389
390 /* Clone content */
391 error = content__clone(old, &new_css->base);
392 if (error != NSERROR_OK) {
393 content_destroy(&new_css->base);
394 return error;
395 }
396
397 /* Simply replay create/process/convert */
398 error = nscss_create_css_data(&new_css->data,
400 old_css->data.charset,
401 new_css->base.quirks,
402 nscss_content_done, new_css);
403 if (error != NSERROR_OK) {
404 content_destroy(&new_css->base);
405 return error;
406 }
407
408 data = content__get_source_data(&new_css->base, &size);
409 if (size > 0) {
410 if (nscss_process_data(&new_css->base,
411 (char *)data,
412 (unsigned int)size) == false) {
413 content_destroy(&new_css->base);
415 }
416 }
417
418 if (old->status == CONTENT_STATUS_READY ||
419 old->status == CONTENT_STATUS_DONE) {
420 if (nscss_convert(&new_css->base) == false) {
421 content_destroy(&new_css->base);
423 }
424 }
425
426 *newc = (struct content *) new_css;
427
428 return NSERROR_OK;
429}
430
431bool nscss_matches_quirks(const struct content *c, bool quirks)
432{
433 return c->quirks == quirks;
434}
435
436/* exported interface documented in netsurf/css.h */
437css_stylesheet *nscss_get_stylesheet(struct hlcache_handle *h)
438{
440
441 assert(c != NULL);
442
443 return c->data.sheet;
444}
445
446/* exported interface documented in netsurf/css.h */
448{
450
451 assert(c != NULL);
452 assert(n != NULL);
453
454 *n = c->data.import_count;
455
456 return c->data.imports;
457}
458
459/**
460 * Compute the type of a content
461 *
462 * \return CONTENT_CSS
463 */
465{
466 return CONTENT_CSS;
467}
468
469/*****************************************************************************
470 * Object completion *
471 *****************************************************************************/
472
473/**
474 * Handle notification that a CSS object is done
475 *
476 * \param css CSS object
477 * \param pw Private data
478 */
479void nscss_content_done(struct content_css_data *css, void *pw)
480{
481 struct content *c = pw;
482 uint32_t i;
483 size_t size;
484 css_error error;
485
486 /* Retrieve the size of this sheet */
487 error = css_stylesheet_size(css->sheet, &size);
488 if (error != CSS_OK) {
491 return;
492 }
493 c->size += size;
494
495 /* Add on the size of the imported sheets */
496 for (i = 0; i < css->import_count; i++) {
497 if (css->imports[i].c != NULL) {
498 struct content *import = hlcache_handle_get_content(
499 css->imports[i].c);
500
501 if (import != NULL) {
502 c->size += import->size;
503 }
504 }
505 }
506
507 /* Finally, catch the content's users up with reality */
510}
511
512/*****************************************************************************
513 * Import handling *
514 *****************************************************************************/
515
516/**
517 * Handle notification of the need for an imported stylesheet
518 *
519 * \param pw CSS object requesting the import
520 * \param parent Stylesheet requesting the import
521 * \param url URL of the imported sheet
522 * \return CSS_OK on success, appropriate error otherwise
523 */
524css_error nscss_handle_import(void *pw, css_stylesheet *parent,
525 lwc_string *url)
526{
527 content_type accept = CONTENT_CSS;
528 struct content_css_data *c = pw;
529 nscss_import_ctx *ctx;
531 struct nscss_import *imports;
532 const char *referer;
533 css_error error;
534 nserror nerror;
535
536 nsurl *ns_url;
537 nsurl *ns_ref;
538
539 assert(parent == c->sheet);
540
541 error = css_stylesheet_get_url(c->sheet, &referer);
542 if (error != CSS_OK) {
543 return error;
544 }
545
546 ctx = malloc(sizeof(*ctx));
547 if (ctx == NULL)
548 return CSS_NOMEM;
549
550 ctx->css = c;
551 ctx->index = c->import_count;
552
553 /* Increase space in table */
554 imports = realloc(c->imports, (c->import_count + 1) *
555 sizeof(struct nscss_import));
556 if (imports == NULL) {
557 free(ctx);
558 return CSS_NOMEM;
559 }
560 c->imports = imports;
561
562 /** \todo fallback charset */
563 child.charset = NULL;
564 error = css_stylesheet_quirks_allowed(c->sheet, &child.quirks);
565 if (error != CSS_OK) {
566 free(ctx);
567 return error;
568 }
569
570 /* Create content */
571
572 /** \todo Why aren't we getting a relative url part, to join? */
573 nerror = nsurl_create(lwc_string_data(url), &ns_url);
574 if (nerror != NSERROR_OK) {
575 free(ctx);
576 return CSS_NOMEM;
577 }
578
579 /** \todo Constructing nsurl for referer here is silly, avoid */
580 nerror = nsurl_create(referer, &ns_ref);
581 if (nerror != NSERROR_OK) {
582 nsurl_unref(ns_url);
583 free(ctx);
584 return CSS_NOMEM;
585 }
586
587 /* Avoid importing ourself */
588 if (nsurl_compare(ns_url, ns_ref, NSURL_COMPLETE)) {
589 c->imports[c->import_count].c = NULL;
590 /* No longer require context as we're not fetching anything */
591 free(ctx);
592 ctx = NULL;
593 } else {
594 nerror = hlcache_handle_retrieve(ns_url,
595 0, ns_ref, NULL, nscss_import, ctx,
596 &child, accept,
597 &c->imports[c->import_count].c);
598 if (nerror != NSERROR_OK) {
599 free(ctx);
600 return CSS_NOMEM;
601 }
602 }
603
604 nsurl_unref(ns_url);
605 nsurl_unref(ns_ref);
606
607#ifdef NSCSS_IMPORT_TRACE
608 NSLOG(netsurf, INFO, "Import %d '%s' -> (handle: %p ctx: %p)",
609 c->import_count, lwc_string_data(url),
610 c->imports[c->import_count].c, ctx);
611#endif
612
613 c->import_count++;
614
615 return CSS_OK;
616}
617
618/**
619 * Handler for imported stylesheet events
620 *
621 * \param handle Handle for stylesheet
622 * \param event Event object
623 * \param pw Callback context
624 * \return NSERROR_OK on success, appropriate error otherwise
625 */
627 const hlcache_event *event, void *pw)
628{
629 nscss_import_ctx *ctx = pw;
630 css_error error = CSS_OK;
631
632#ifdef NSCSS_IMPORT_TRACE
633 NSLOG(netsurf, INFO, "Event %d for %p (%p)", event->type, handle, ctx);
634#endif
635
636 assert(ctx->css->imports[ctx->index].c == handle);
637
638 switch (event->type) {
639 case CONTENT_MSG_DONE:
640 error = nscss_import_complete(ctx);
641 break;
642
645 ctx->css->imports[ctx->index].c = NULL;
646
647 error = nscss_import_complete(ctx);
648 /* Already released handle */
649 break;
650 default:
651 break;
652 }
653
654 /* Preserve out-of-memory. Anything else is OK */
655 return error == CSS_NOMEM ? NSERROR_NOMEM : NSERROR_OK;
656}
657
658/**
659 * Handle an imported stylesheet completing
660 *
661 * \param ctx Import context
662 * \return CSS_OK on success, appropriate error otherwise
663 */
665{
666 css_error error = CSS_OK;
667
668 /* If this import is the next to be registered, do so */
669 if (ctx->css->next_to_register == ctx->index)
670 error = nscss_register_imports(ctx->css);
671
672#ifdef NSCSS_IMPORT_TRACE
673 NSLOG(netsurf, INFO, "Destroying import context %p for %d", ctx,
674 ctx->index);
675#endif
676
677 /* No longer need import context */
678 free(ctx);
679
680 return error;
681}
682
683/*****************************************************************************
684 * Import registration *
685 *****************************************************************************/
686
687/**
688 * Register imports with a stylesheet
689 *
690 * \param c CSS object containing the imports
691 * \return CSS_OK on success, appropriate error otherwise
692 */
694{
695 uint32_t index;
696 css_error error;
697
698 assert(c->next_to_register != (uint32_t) -1);
699 assert(c->next_to_register < c->import_count);
700
701 /* Register imported sheets */
702 for (index = c->next_to_register; index < c->import_count; index++) {
703 /* Stop registering if we encounter one whose fetch hasn't
704 * completed yet. We'll resume at this point when it has
705 * completed.
706 */
707 if (c->imports[index].c != NULL &&
708 content_get_status(c->imports[index].c) !=
710 break;
711 }
712
713 error = nscss_register_import(c, c->imports[index].c);
714 if (error != CSS_OK)
715 return error;
716 }
717
718 /* Record identity of the next import to register */
719 c->next_to_register = (uint32_t) index;
720
721 if (c->next_to_register == c->import_count) {
722 /* No more imports: notify parent that we're DONE */
723 c->done(c, c->pw);
724 }
725
726 return CSS_OK;
727}
728
729
730/**
731 * Register an import with a stylesheet
732 *
733 * \param c CSS object that requested the import
734 * \param import Cache handle of import, or NULL for blank
735 * \return CSS_OK on success, appropriate error otherwise
736 */
738 const hlcache_handle *import)
739{
740 css_stylesheet *sheet;
741 css_error error;
742
743 if (import != NULL) {
744 nscss_content *s =
746 sheet = s->data.sheet;
747 } else {
748 /* Create a blank sheet if needed. */
749 if (blank_import == NULL) {
750 css_stylesheet_params params;
751
752 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
753 params.level = CSS_LEVEL_DEFAULT;
754 params.charset = NULL;
755 params.url = "";
756 params.title = NULL;
757 params.allow_quirks = false;
758 params.inline_style = false;
759 params.resolve = nscss_resolve_url;
760 params.resolve_pw = NULL;
761 params.import = NULL;
762 params.import_pw = NULL;
763 params.color = ns_system_colour;
764 params.color_pw = NULL;
765 params.font = NULL;
766 params.font_pw = NULL;
767
768 error = css_stylesheet_create(&params, &blank_import);
769 if (error != CSS_OK) {
770 return error;
771 }
772
773 error = css_stylesheet_data_done(blank_import);
774 if (error != CSS_OK) {
775 css_stylesheet_destroy(blank_import);
776 return error;
777 }
778 }
779
780 sheet = blank_import;
781 }
782
783 error = css_stylesheet_register_import(c->sheet, sheet);
784 if (error != CSS_OK) {
785 return error;
786 }
787
788 return error;
789}
790
791/**
792 * Clean up after the CSS content handler
793 */
794static void nscss_fini(void)
795{
796 if (blank_import != NULL) {
797 css_stylesheet_destroy(blank_import);
798 blank_import = NULL;
799 }
801}
802
804 .fini = nscss_fini,
805 .create = nscss_create,
806 .process_data = nscss_process_data,
807 .data_complete = nscss_convert,
808 .destroy = nscss_destroy,
809 .clone = nscss_clone,
810 .matches_quirks = nscss_matches_quirks,
811 .type = nscss_content_type,
812 .no_share = false,
813};
814
815/* exported interface documented in netsurf/css.h */
817{
818 nserror error;
819
820 error = content_factory_register_handler("text/css",
822 if (error != NSERROR_OK)
823 goto error;
824
825 error = css_hint_init();
826 if (error != NSERROR_OK)
827 goto error;
828
829 return NSERROR_OK;
830
831error:
832 nscss_fini();
833
834 return error;
835}
STATIC char result[100]
Definition: arexx.c:77
Fetching of data from a URL (interface).
void content_destroy(struct content *c)
Destroy and free a content.
Definition: content.c:354
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
Definition: content.c:299
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
void content_set_error(struct content *c)
Put a content in status CONTENT_STATUS_ERROR and unlock the content.
Definition: content.c:313
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
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
Definition: content.c:1382
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
Definition: content.c:285
content_status content_get_status(hlcache_handle *h)
Retrieve status of content.
Definition: content.c:1124
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.
Protected interface to Content handling.
@ 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_type
The type of a content.
Definition: content_type.h:53
@ CONTENT_CSS
content is CSS
Definition: content_type.h:64
@ CONTENT_MSG_DONE
content has finished processing
Definition: content_type.h:119
@ CONTENT_MSG_ERROR
error occurred
Definition: content_type.h:122
Useful interned string pointers (interface).
static nserror nscss_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)
Initialise a CSS content.
Definition: css.c:131
static void nscss_destroy(struct content *c)
Clean up a CSS content.
Definition: css.c:345
static void nscss_destroy_css_data(struct content_css_data *c)
Clean up CSS data.
Definition: css.c:357
struct nscss_import * nscss_get_imports(hlcache_handle *h, uint32_t *n)
Retrieve imported stylesheets.
Definition: css.c:447
nserror nscss_init(void)
Initialise the CSS content handler.
Definition: css.c:816
static nserror nscss_clone(const struct content *old, struct content **newc)
Definition: css.c:378
static bool nscss_matches_quirks(const struct content *c, bool quirks)
Definition: css.c:431
css_fixed nscss_screen_dpi
Screen DPI in fixed point units: defaults to 90, which RISC OS uses.
Definition: css.c:44
static css_error nscss_register_imports(struct content_css_data *c)
Register imports with a stylesheet.
Definition: css.c:693
static nserror nscss_import(hlcache_handle *handle, const hlcache_event *event, void *pw)
Handler for imported stylesheet events.
Definition: css.c:626
static css_error nscss_process_css_data(struct content_css_data *c, const char *data, unsigned int size)
Process CSS data.
Definition: css.c:274
static content_type nscss_content_type(void)
Compute the type of a content.
Definition: css.c:464
static css_error nscss_handle_import(void *pw, css_stylesheet *parent, lwc_string *url)
Handle notification of the need for an imported stylesheet.
Definition: css.c:524
static css_stylesheet * blank_import
Definition: css.c:115
static const content_handler css_content_handler
Definition: css.c:803
struct nscss_content nscss_content
CSS content data.
static nserror nscss_create_css_data(struct content_css_data *c, const char *url, const char *charset, bool quirks, nscss_done_callback done, void *pw)
Create a struct content_css_data, creating a stylesheet object.
Definition: css.c:203
void(* nscss_done_callback)(struct content_css_data *css, void *pw)
Type of callback called when a CSS object has finished.
Definition: css.c:54
static void nscss_content_done(struct content_css_data *css, void *pw)
Handle notification that a CSS object is done.
Definition: css.c:479
static css_error nscss_convert_css_data(struct content_css_data *c)
Convert CSS data ready for use.
Definition: css.c:307
static void nscss_fini(void)
Clean up after the CSS content handler.
Definition: css.c:794
static bool nscss_process_data(struct content *c, const char *data, unsigned int size)
Process CSS source data.
Definition: css.c:253
static css_error nscss_import_complete(nscss_import_ctx *ctx)
Handle an imported stylesheet completing.
Definition: css.c:664
static css_error nscss_register_import(struct content_css_data *c, const hlcache_handle *import)
Register an import with a stylesheet.
Definition: css.c:737
css_stylesheet * nscss_get_stylesheet(struct hlcache_handle *h)
Retrieve the stylesheet object associated with a CSS content.
Definition: css.c:437
static bool nscss_convert(struct content *c)
Convert a CSS content ready for use.
Definition: css.c:287
wimp_w parent
Definition: dialog.c:88
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_CSS
CSS call returned error.
Definition: errors.h:53
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_CLONE_FAILED
Failed to clone handle.
Definition: errors.h:37
@ NSERROR_OK
No error.
Definition: errors.h:30
void css_hint_fini(void)
Definition: hints.c:599
nserror css_hint_init(void)
Definition: hints.c:588
struct content * hlcache_handle_get_content(const hlcache_handle *handle)
Retrieve a content object from a cache handle.
Definition: hlcache.c:776
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
Definition: hlcache.c:740
nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags, nsurl *referer, llcache_post_data *post, hlcache_handle_callback cb, void *pw, hlcache_child_context *child, content_type accepted_types, hlcache_handle **result)
Retrieve a high-level cache handle for an object.
Definition: hlcache.c:679
High-level resource cache interface.
HTTP header parsing functions.
css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs)
URL resolution callback for libcss.
Definition: internal.c:27
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
const char * llcache_handle_get_header(const llcache_handle *handle, const char *key)
Retrieve a header value associated with a low-level cache object.
Definition: llcache.c:4210
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
Localised message support (interface).
bool nsurl_compare(const nsurl *url1, const nsurl *url2, nsurl_component parts)
Compare two URLs.
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
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_COMPLETE
Definition: nsurl.h:54
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
Interface to utility string handling.
CSS content data.
Definition: css.c:60
css_stylesheet * sheet
Stylesheet object.
Definition: css.c:61
char * charset
Character set of stylesheet.
Definition: css.c:62
void * pw
Client data.
Definition: css.c:67
struct nscss_import * imports
Array of imported sheets.
Definition: css.c:63
uint32_t import_count
Number of sheets imported.
Definition: css.c:64
uint32_t next_to_register
Index of next import to register.
Definition: css.c:65
nscss_done_callback done
Completion callback.
Definition: css.c:66
Content operation function table.
void(* fini)(void)
Content which corresponds to a single URL.
bool quirks
Content is in quirks mode.
content_status status
Current status.
unsigned int size
Estimated size of all data associated with this content.
Context for retrieving a child object.
Definition: hlcache.h:37
bool quirks
Whether parent is quirky.
Definition: hlcache.h:39
const char * charset
Charset of parent.
Definition: hlcache.h:38
High-level cache event.
Definition: hlcache.h:43
content_msg type
Event type.
Definition: hlcache.h:44
High-level cache handle.
Definition: hlcache.c:66
void * pw
Client data.
Definition: hlcache.c:70
Representation of an HTTP parameter.
Definition: parameter.c:31
Handle to low-level cache object.
Definition: llcache.c:76
CSS content data.
Definition: css.c:74
struct content_css_data data
CSS data.
Definition: css.c:77
struct content base
Underlying content object.
Definition: css.c:75
Context for import fetches.
Definition: css.c:83
uint32_t index
Index into parent sheet's imports array.
Definition: css.c:85
struct content_css_data * css
Object containing import.
Definition: css.c:84
Imported stylesheet record.
Definition: css.h:33
struct hlcache_handle * c
Content containing sheet.
Definition: css.h:34
css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
css callback to obtain named system colour.
Definition: system_colour.c:95
Interface to system colour values.
Interface to a number of general purpose functionality.