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 lwc_string_unref(charset_value);
183 lwc_string_unref(charset_value);
202 const char *url,
const char *charset,
bool quirks,
206 css_stylesheet_params params;
218 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
219 params.level = CSS_LEVEL_DEFAULT;
220 params.charset = charset;
223 params.allow_quirks =
quirks;
224 params.inline_style =
false;
226 params.resolve_pw = NULL;
228 params.import_pw = c;
230 params.color_pw = NULL;
232 params.font_pw = NULL;
234 error = css_stylesheet_create(¶ms, &c->
sheet);
235 if (error != CSS_OK) {
257 if (error != CSS_OK && error != CSS_NEEDDATA) {
261 return (error == CSS_OK || error == CSS_NEEDDATA);
273 const char *data,
unsigned int size)
275 return css_stylesheet_append_data(c->
sheet,
276 (
const uint8_t *) data,
size);
291 if (error != CSS_OK) {
309 error = css_stylesheet_data_done(c->
sheet);
312 if (error == CSS_IMPORTS_PENDING) {
320 }
else if (error == CSS_OK) {
326 if (css_stylesheet_get_url(c->
sheet, &url) == CSS_OK) {
327 NSLOG(netsurf, INFO,
"Failed converting %p %s (%d)",
330 NSLOG(netsurf, INFO,
"Failed converting %p (%d)", c,
368 if (c->
sheet != NULL) {
369 css_stylesheet_destroy(c->
sheet);
410 (
unsigned int)
size) ==
false) {
424 *newc = (
struct content *) new_css;
452 *n =
c->data.import_count;
454 return c->data.imports;
485 error = css_stylesheet_size(css->
sheet, &
size);
486 if (error != CSS_OK) {
499 if (
import != NULL) {
500 c->
size +=
import->size;
539 error = css_stylesheet_get_url(
c->sheet, &referer);
540 if (error != CSS_OK) {
544 ctx = malloc(
sizeof(*ctx));
549 ctx->
index =
c->import_count;
552 imports = realloc(
c->imports, (
c->import_count + 1) *
554 if (imports == NULL) {
558 c->imports = imports;
562 error = css_stylesheet_quirks_allowed(
c->sheet, &child.
quirks);
563 if (error != CSS_OK) {
587 c->imports[
c->import_count].c = NULL;
595 &
c->imports[
c->import_count].c);
605#ifdef NSCSS_IMPORT_TRACE
606 NSLOG(netsurf, INFO,
"Import %d '%s' -> (handle: %p ctx: %p)",
607 c->import_count, lwc_string_data(url),
608 c->imports[
c->import_count].c, ctx);
628 css_error error = CSS_OK;
630#ifdef NSCSS_IMPORT_TRACE
631 NSLOG(netsurf, INFO,
"Event %d for %p (%p)", event->
type, handle, ctx);
636 switch (event->
type) {
664 css_error error = CSS_OK;
670#ifdef NSCSS_IMPORT_TRACE
671 NSLOG(netsurf, INFO,
"Destroying import context %p for %d", ctx,
696 assert(
c->next_to_register != (uint32_t) -1);
697 assert(
c->next_to_register <
c->import_count);
700 for (index =
c->next_to_register; index < c->import_count; index++) {
705 if (
c->imports[index].c != NULL &&
717 c->next_to_register = (uint32_t) index;
719 if (
c->next_to_register ==
c->import_count) {
738 css_stylesheet *sheet;
741 if (
import != NULL) {
748 css_stylesheet_params params;
750 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
751 params.level = CSS_LEVEL_DEFAULT;
752 params.charset = NULL;
755 params.allow_quirks =
false;
756 params.inline_style =
false;
758 params.resolve_pw = NULL;
759 params.import = NULL;
760 params.import_pw = NULL;
762 params.color_pw = NULL;
764 params.font_pw = NULL;
767 if (error != CSS_OK) {
772 if (error != CSS_OK) {
781 error = css_stylesheet_register_import(
c->sheet, sheet);
782 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.