NetSurf
Data Structures | Typedefs | Functions | Variables
css.c File Reference
#include <string.h>
#include <assert.h>
#include <libwapcaplet/libwapcaplet.h>
#include <dom/dom.h>
#include "utils/errors.h"
#include "utils/corestrings.h"
#include "utils/utils.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "content/content_protected.h"
#include "content/content_factory.h"
#include "content/fetch.h"
#include "content/hlcache.h"
#include "desktop/system_colour.h"
#include "css/css.h"
#include "css/hints.h"
#include "css/internal.h"
Include dependency graph for css.c:

Go to the source code of this file.

Data Structures

struct  content_css_data
 CSS content data. More...
 
struct  nscss_content
 CSS content data. More...
 
struct  nscss_import_ctx
 Context for import fetches. More...
 

Typedefs

typedef void(* nscss_done_callback) (struct content_css_data *css, void *pw)
 Type of callback called when a CSS object has finished. More...
 
typedef struct nscss_content nscss_content
 CSS content data. More...
 

Functions

static bool nscss_convert (struct content *c)
 Convert a CSS content ready for use. More...
 
static void nscss_destroy (struct content *c)
 Clean up a CSS content. More...
 
static nserror nscss_clone (const struct content *old, struct content **newc)
 
static bool nscss_matches_quirks (const struct content *c, bool quirks)
 
static content_type nscss_content_type (void)
 Compute the type of a content. More...
 
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. More...
 
static css_error nscss_process_css_data (struct content_css_data *c, const char *data, unsigned int size)
 Process CSS data. More...
 
static css_error nscss_convert_css_data (struct content_css_data *c)
 Convert CSS data ready for use. More...
 
static void nscss_destroy_css_data (struct content_css_data *c)
 Clean up CSS data. More...
 
static void nscss_content_done (struct content_css_data *css, void *pw)
 Handle notification that a CSS object is done. More...
 
static css_error nscss_handle_import (void *pw, css_stylesheet *parent, lwc_string *url)
 Handle notification of the need for an imported stylesheet. More...
 
static nserror nscss_import (hlcache_handle *handle, const hlcache_event *event, void *pw)
 Handler for imported stylesheet events. More...
 
static css_error nscss_import_complete (nscss_import_ctx *ctx)
 Handle an imported stylesheet completing. More...
 
static css_error nscss_register_imports (struct content_css_data *c)
 Register imports with a stylesheet. More...
 
static css_error nscss_register_import (struct content_css_data *c, const hlcache_handle *import)
 Register an import with a stylesheet. More...
 
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. More...
 
static bool nscss_process_data (struct content *c, const char *data, unsigned int size)
 Process CSS source data. More...
 
css_stylesheet * nscss_get_stylesheet (struct hlcache_handle *h)
 Retrieve the stylesheet object associated with a CSS content. More...
 
struct nscss_importnscss_get_imports (hlcache_handle *h, uint32_t *n)
 Retrieve imported stylesheets. More...
 
static void nscss_fini (void)
 Clean up after the CSS content handler. More...
 
nserror nscss_init (void)
 Initialise the CSS content handler. More...
 

Variables

css_fixed nscss_screen_dpi = F_90
 Screen DPI in fixed point units: defaults to 90, which RISC OS uses. More...
 
static css_stylesheet * blank_import
 
static const content_handler css_content_handler
 

Typedef Documentation

◆ nscss_content

typedef struct nscss_content nscss_content

CSS content data.

◆ nscss_done_callback

typedef void(* nscss_done_callback) (struct content_css_data *css, void *pw)

Type of callback called when a CSS object has finished.

Parameters
cssCSS object that has completed
pwClient-specific data

Definition at line 54 of file css.c.

Function Documentation

◆ nscss_clone()

nserror nscss_clone ( const struct content old,
struct content **  newc 
)
static

◆ nscss_content_done()

void nscss_content_done ( struct content_css_data css,
void *  pw 
)
static

Handle notification that a CSS object is done.

Parameters
cssCSS object
pwPrivate data

Definition at line 479 of file css.c.

References nscss_import::c, content_broadcast_error(), content_set_done(), content_set_error(), content_set_ready(), hlcache_handle_get_content(), content_css_data::import_count, content_css_data::imports, NSERROR_CSS, content_css_data::sheet, and content::size.

Referenced by nscss_clone(), and nscss_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_content_type()

content_type nscss_content_type ( void  )
static

Compute the type of a content.

Returns
CONTENT_CSS

Definition at line 464 of file css.c.

References CONTENT_CSS.

◆ nscss_convert()

bool nscss_convert ( struct content c)
static

Convert a CSS content ready for use.

Parameters
cContent to convert
Returns
true on success, false on failure

Definition at line 287 of file css.c.

References content_broadcast_error(), nscss_content::data, nscss_convert_css_data(), and NSERROR_CSS.

Referenced by nscss_clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_convert_css_data()

static css_error nscss_convert_css_data ( struct content_css_data c)
static

Convert CSS data ready for use.

Parameters
cCSS data to convert
Returns
CSS error

Definition at line 307 of file css.c.

References content_css_data::done, content_css_data::next_to_register, nscss_register_imports(), NSLOG, content_css_data::pw, and content_css_data::sheet.

Referenced by nscss_convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_create()

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 
)
static

Initialise a CSS content.

Parameters
handlercontent handler
imime_typemime-type
paramsContent-Type parameters
llcachehandle to content
fallback_charsetThe character set to fallback to.
quirksallow quirks
cContent to initialise
Returns
NSERROR_OK or error cod eon faliure
Todo:
libcss will take this as gospel, which is wrong

Definition at line 131 of file css.c.

References content_css_data::charset, content__init(), content_broadcast_error(), content_get_url(), http_parameter_list_find_item(), llcache, llcache_handle_get_header(), nscss_content_done(), nscss_create_css_data(), NSERROR_NOMEM, NSERROR_OK, nsurl_access(), and result.

Here is the call graph for this function:

◆ nscss_create_css_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 
)
static

Create a struct content_css_data, creating a stylesheet object.

Parameters
cStruct to populate
urlURL of stylesheet
charsetStylesheet charset
quirksStylesheet quirks mode
doneCallback to call when content has completed
pwClient data for done
Returns
NSERROR_OK on success, NSERROR_NOMEM on memory exhaustion

Definition at line 203 of file css.c.

References content_css_data::charset, content_css_data::done, content_css_data::import_count, content_css_data::imports, content_css_data::next_to_register, ns_system_colour(), nscss_handle_import(), nscss_resolve_url(), NSERROR_NOMEM, NSERROR_OK, content_css_data::pw, content::quirks, and content_css_data::sheet.

Referenced by nscss_clone(), and nscss_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_destroy()

void nscss_destroy ( struct content c)
static

Clean up a CSS content.

Parameters
cContent to clean up

Definition at line 345 of file css.c.

References nscss_content::data, and nscss_destroy_css_data().

Here is the call graph for this function:

◆ nscss_destroy_css_data()

static void nscss_destroy_css_data ( struct content_css_data c)
static

Clean up CSS data.

Parameters
cCSS data to clean up

Definition at line 357 of file css.c.

References nscss_import::c, content_css_data::charset, hlcache_handle_release(), content_css_data::import_count, content_css_data::imports, and content_css_data::sheet.

Referenced by nscss_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_fini()

static void nscss_fini ( void  )
static

Clean up after the CSS content handler.

Definition at line 794 of file css.c.

References blank_import, and css_hint_fini().

Referenced by nscss_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_get_imports()

struct nscss_import * nscss_get_imports ( struct hlcache_handle h,
uint32_t *  n 
)

Retrieve imported stylesheets.

Parameters
hStylesheet containing imports
nPointer to location to receive number of imports
Returns
Pointer to array of imported stylesheets

Definition at line 447 of file css.c.

References nscss_import::c, and hlcache_handle_get_content().

Referenced by save_complete_save_stylesheet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_get_stylesheet()

css_stylesheet * nscss_get_stylesheet ( struct hlcache_handle h)

Retrieve the stylesheet object associated with a CSS content.

Parameters
hStylesheet content
Returns
Pointer to stylesheet object

Definition at line 437 of file css.c.

References nscss_content::data, hlcache_handle_get_content(), and content_css_data::sheet.

Referenced by html_css_new_selection_context().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_handle_import()

css_error nscss_handle_import ( void *  pw,
css_stylesheet *  parent,
lwc_string *  url 
)
static

Handle notification of the need for an imported stylesheet.

Parameters
pwCSS object requesting the import
parentStylesheet requesting the import
urlURL of the imported sheet
Returns
CSS_OK on success, appropriate error otherwise
Todo:
fallback charset
Todo:
Why aren't we getting a relative url part, to join?
Todo:
Constructing nsurl for referer here is silly, avoid

Definition at line 524 of file css.c.

References nscss_import::c, hlcache_child_context::charset, CONTENT_CSS, nscss_import_ctx::css, hlcache_handle_retrieve(), nscss_import_ctx::index, NSERROR_OK, NSLOG, nsurl_compare(), NSURL_COMPLETE, nsurl_create(), nsurl_unref(), parent, content_css_data::pw, and hlcache_child_context::quirks.

Referenced by nscss_create_css_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_import()

nserror nscss_import ( hlcache_handle handle,
const hlcache_event event,
void *  pw 
)
static

Handler for imported stylesheet events.

Parameters
handleHandle for stylesheet
eventEvent object
pwCallback context
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 626 of file css.c.

References nscss_import::c, CONTENT_MSG_DONE, CONTENT_MSG_ERROR, nscss_import_ctx::css, hlcache_handle_release(), content_css_data::imports, nscss_import_ctx::index, nscss_import_complete(), NSERROR_NOMEM, NSERROR_OK, NSLOG, and hlcache_event::type.

Here is the call graph for this function:

◆ nscss_import_complete()

css_error nscss_import_complete ( nscss_import_ctx ctx)
static

Handle an imported stylesheet completing.

Parameters
ctxImport context
Returns
CSS_OK on success, appropriate error otherwise

Definition at line 664 of file css.c.

References nscss_import_ctx::css, nscss_import_ctx::index, content_css_data::next_to_register, nscss_register_imports(), and NSLOG.

Referenced by nscss_import().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_init()

nserror nscss_init ( void  )

Initialise the CSS content handler.

Returns
NSERROR_OK on success or error code on faliure

Definition at line 816 of file css.c.

References content_factory_register_handler(), css_content_handler, css_hint_init(), nscss_fini(), and NSERROR_OK.

Referenced by netsurf_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_matches_quirks()

bool nscss_matches_quirks ( const struct content c,
bool  quirks 
)
static

Definition at line 431 of file css.c.

References content::quirks.

◆ nscss_process_css_data()

static css_error nscss_process_css_data ( struct content_css_data c,
const char *  data,
unsigned int  size 
)
static

Process CSS data.

Parameters
cCSS content object
dataData to process
sizeNumber of bytes to process
Returns
CSS_OK on success, appropriate error otherwise

Definition at line 274 of file css.c.

References content_css_data::sheet, and content::size.

Referenced by nscss_process_data().

Here is the caller graph for this function:

◆ nscss_process_data()

static bool nscss_process_data ( struct content c,
const char *  data,
unsigned int  size 
)
static

Process CSS source data.

Parameters
cContent structure
dataData to process
sizeNumber of bytes to process
Returns
true on success, false on failure

Definition at line 253 of file css.c.

References content_broadcast_error(), nscss_content::data, nscss_process_css_data(), NSERROR_CSS, and content::size.

Referenced by nscss_clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_register_import()

css_error nscss_register_import ( struct content_css_data c,
const hlcache_handle import 
)
static

Register an import with a stylesheet.

Parameters
cCSS object that requested the import
importCache handle of import, or NULL for blank
Returns
CSS_OK on success, appropriate error otherwise

Definition at line 737 of file css.c.

References blank_import, nscss_import::c, nscss_content::data, hlcache_handle_get_content(), ns_system_colour(), nscss_resolve_url(), and content_css_data::sheet.

Referenced by nscss_register_imports().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nscss_register_imports()

css_error nscss_register_imports ( struct content_css_data c)
static

Register imports with a stylesheet.

Parameters
cCSS object containing the imports
Returns
CSS_OK on success, appropriate error otherwise

Definition at line 693 of file css.c.

References nscss_import::c, content_get_status(), CONTENT_STATUS_DONE, nscss_register_import(), and hlcache_handle::pw.

Referenced by nscss_convert_css_data(), and nscss_import_complete().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ blank_import

css_stylesheet* blank_import
static

Definition at line 115 of file css.c.

Referenced by nscss_fini(), and nscss_register_import().

◆ css_content_handler

const content_handler css_content_handler
static
Initial value:
= {
.fini = nscss_fini,
.create = nscss_create,
.process_data = nscss_process_data,
.data_complete = nscss_convert,
.destroy = nscss_destroy,
.clone = nscss_clone,
.matches_quirks = nscss_matches_quirks,
.no_share = false,
}
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 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
static content_type nscss_content_type(void)
Compute the type of a content.
Definition: css.c:464
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 bool nscss_convert(struct content *c)
Convert a CSS content ready for use.
Definition: css.c:287

Definition at line 803 of file css.c.

Referenced by nscss_init().

◆ nscss_screen_dpi

css_fixed nscss_screen_dpi = F_90

Screen DPI in fixed point units: defaults to 90, which RISC OS uses.

DPI of the screen, in fixed point units.

Definition at line 44 of file css.c.

Referenced by browser_get_dpi(), browser_set_dpi(), html_get_dimensions(), page_info__measure_text_entry(), textarea_create(), textarea_setup_text_offsets(), textplain_line_height(), and treeview_init().