21#include <libwapcaplet/libwapcaplet.h>
41#undef NSCSS_IMPORT_TRACE
96 const char *url,
const char *
charset,
bool quirks,
132 lwc_string *imime_type,
135 const char *fallback_charset,
141 const char *xnsbase = NULL;
142 lwc_string *charset_value = NULL;
150 params,
llcache, fallback_charset, quirks);
159 if (error !=
NSERROR_OK || lwc_string_length(charset_value) == 0) {
164 charset = lwc_string_data(charset_value);
169 if (xnsbase == NULL) {
178 if (charset_value != NULL)
179 lwc_string_unref(charset_value);
184 if (charset_value != NULL)
185 lwc_string_unref(charset_value);
204 const char *url,
const char *charset,
bool quirks,
208 css_stylesheet_params params;
220 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
221 params.level = CSS_LEVEL_DEFAULT;
222 params.charset = charset;
225 params.allow_quirks =
quirks;
226 params.inline_style =
false;
228 params.resolve_pw = NULL;
230 params.import_pw = c;
232 params.color_pw = NULL;
234 params.font_pw = NULL;
236 error = css_stylesheet_create(¶ms, &c->
sheet);
237 if (error != CSS_OK) {
259 if (error != CSS_OK && error != CSS_NEEDDATA) {
263 return (error == CSS_OK || error == CSS_NEEDDATA);
275 const char *data,
unsigned int size)
277 return css_stylesheet_append_data(c->
sheet,
278 (
const uint8_t *) data,
size);
293 if (error != CSS_OK) {
311 error = css_stylesheet_data_done(c->
sheet);
314 if (error == CSS_IMPORTS_PENDING) {
322 }
else if (error == CSS_OK) {
328 if (css_stylesheet_get_url(c->
sheet, &url) == CSS_OK) {
329 NSLOG(netsurf, INFO,
"Failed converting %p %s (%d)",
332 NSLOG(netsurf, INFO,
"Failed converting %p (%d)", c,
370 if (c->
sheet != NULL) {
371 css_stylesheet_destroy(c->
sheet);
412 (
unsigned int)
size) ==
false) {
426 *newc = (
struct content *) new_css;
454 *n =
c->data.import_count;
456 return c->data.imports;
487 error = css_stylesheet_size(css->
sheet, &
size);
488 if (error != CSS_OK) {
501 if (
import != NULL) {
502 c->
size +=
import->size;
541 error = css_stylesheet_get_url(
c->sheet, &referer);
542 if (error != CSS_OK) {
546 ctx = malloc(
sizeof(*ctx));
551 ctx->
index =
c->import_count;
554 imports = realloc(
c->imports, (
c->import_count + 1) *
556 if (imports == NULL) {
560 c->imports = imports;
564 error = css_stylesheet_quirks_allowed(
c->sheet, &child.
quirks);
565 if (error != CSS_OK) {
589 c->imports[
c->import_count].c = NULL;
597 &
c->imports[
c->import_count].c);
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);
630 css_error error = CSS_OK;
632#ifdef NSCSS_IMPORT_TRACE
633 NSLOG(netsurf, INFO,
"Event %d for %p (%p)", event->
type, handle, ctx);
638 switch (event->
type) {
666 css_error error = CSS_OK;
672#ifdef NSCSS_IMPORT_TRACE
673 NSLOG(netsurf, INFO,
"Destroying import context %p for %d", ctx,
698 assert(
c->next_to_register != (uint32_t) -1);
699 assert(
c->next_to_register <
c->import_count);
702 for (index =
c->next_to_register; index < c->import_count; index++) {
707 if (
c->imports[index].c != NULL &&
719 c->next_to_register = (uint32_t) index;
721 if (
c->next_to_register ==
c->import_count) {
740 css_stylesheet *sheet;
743 if (
import != NULL) {
750 css_stylesheet_params params;
752 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
753 params.level = CSS_LEVEL_DEFAULT;
754 params.charset = NULL;
757 params.allow_quirks =
false;
758 params.inline_style =
false;
760 params.resolve_pw = NULL;
761 params.import = NULL;
762 params.import_pw = NULL;
764 params.color_pw = NULL;
766 params.font_pw = NULL;
769 if (error != CSS_OK) {
774 if (error != CSS_OK) {
783 error = css_stylesheet_register_import(
c->sheet, sheet);
784 if (error != CSS_OK) {
Fetching of data from a URL (interface).
void content_destroy(struct content *c)
Destroy and free a content.
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
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)
void content_set_error(struct content *c)
Put a content in status CONTENT_STATUS_ERROR and unlock the content.
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
const uint8_t * content__get_source_data(struct content *c, size_t *size)
Retrieve source of content.
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
content_status content_get_status(hlcache_handle *h)
Retrieve status of content.
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
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.
@ CONTENT_STATUS_DONE
Content has completed all processing.
content_type
The type of a content.
@ CONTENT_CSS
content is CSS
@ CONTENT_MSG_DONE
content has finished processing
@ CONTENT_MSG_ERROR
error occurred
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.
static void nscss_destroy(struct content *c)
Clean up a CSS content.
static void nscss_destroy_css_data(struct content_css_data *c)
Clean up CSS data.
struct nscss_import * nscss_get_imports(hlcache_handle *h, uint32_t *n)
Retrieve imported stylesheets.
nserror nscss_init(void)
Initialise the CSS content handler.
static nserror nscss_clone(const struct content *old, struct content **newc)
static bool nscss_matches_quirks(const struct content *c, bool quirks)
css_fixed nscss_screen_dpi
Screen DPI in fixed point units: defaults to 90, which RISC OS uses.
static css_error nscss_register_imports(struct content_css_data *c)
Register imports with a stylesheet.
static nserror nscss_import(hlcache_handle *handle, const hlcache_event *event, void *pw)
Handler for imported stylesheet events.
static css_error nscss_process_css_data(struct content_css_data *c, const char *data, unsigned int size)
Process CSS data.
static content_type nscss_content_type(void)
Compute the type of a content.
static css_error nscss_handle_import(void *pw, css_stylesheet *parent, lwc_string *url)
Handle notification of the need for an imported stylesheet.
static css_stylesheet * blank_import
static const content_handler css_content_handler
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.
void(* nscss_done_callback)(struct content_css_data *css, void *pw)
Type of callback called when a CSS object has finished.
static void nscss_content_done(struct content_css_data *css, void *pw)
Handle notification that a CSS object is done.
static css_error nscss_convert_css_data(struct content_css_data *c)
Convert CSS data ready for use.
static void nscss_fini(void)
Clean up after the CSS content handler.
static bool nscss_process_data(struct content *c, const char *data, unsigned int size)
Process CSS source data.
static css_error nscss_import_complete(nscss_import_ctx *ctx)
Handle an imported stylesheet completing.
static css_error nscss_register_import(struct content_css_data *c, const hlcache_handle *import)
Register an import with a stylesheet.
css_stylesheet * nscss_get_stylesheet(struct hlcache_handle *h)
Retrieve the stylesheet object associated with a CSS content.
static bool nscss_convert(struct content *c)
Convert a CSS content ready for use.
nserror
Enumeration of error codes.
@ NSERROR_CSS
CSS call returned error.
@ NSERROR_NOMEM
Memory exhaustion.
@ NSERROR_CLONE_FAILED
Failed to clone handle.
nserror css_hint_init(void)
struct content * hlcache_handle_get_content(const hlcache_handle *handle)
Retrieve a content object from a cache handle.
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
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.
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.
static struct llcache_s * llcache
low level cache state
const char * llcache_handle_get_header(const llcache_handle *handle, const char *key)
Retrieve a header value associated with a low-level cache object.
#define NSLOG(catname, level, logmsg, args...)
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.
struct nsurl nsurl
NetSurf URL object.
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.
Interface to utility string handling.
css_stylesheet * sheet
Stylesheet object.
char * charset
Character set of stylesheet.
struct nscss_import * imports
Array of imported sheets.
uint32_t import_count
Number of sheets imported.
uint32_t next_to_register
Index of next import to register.
nscss_done_callback done
Completion callback.
Content operation function table.
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.
bool quirks
Whether parent is quirky.
const char * charset
Charset of parent.
content_msg type
Event type.
Representation of an HTTP parameter.
Handle to low-level cache object.
struct content_css_data data
CSS data.
struct content base
Underlying content object.
Context for import fetches.
uint32_t index
Index into parent sheet's imports array.
struct content_css_data * css
Object containing import.
Imported stylesheet record.
struct hlcache_handle * c
Content containing sheet.
css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
css callback to obtain named system colour.
Interface to system colour values.
Interface to a number of general purpose functionality.