libcss
Loading...
Searching...
No Matches
Macros | Functions
stylesheet.c File Reference
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include "stylesheet.h"
#include "bytecode/bytecode.h"
#include "parse/language.h"
#include "parse/mq.h"
#include "utils/parserutilserror.h"
#include "utils/utils.h"
#include "select/dispatch.h"
#include "select/font_face.h"

Macros

#define CSS_STYLE_DEFAULT_SIZE   16
 

Functions

css_error css__stylesheet_string_add (css_stylesheet *sheet, lwc_string *string, uint32_t *string_number)
 
css_error css__stylesheet_string_get (css_stylesheet *sheet, uint32_t string_number, lwc_string **string)
 
css_error css_stylesheet_create (const css_stylesheet_params *params, css_stylesheet **stylesheet)
 
css_error css_stylesheet_destroy (css_stylesheet *sheet)
 
css_error css_stylesheet_append_data (css_stylesheet *sheet, const uint8_t *data, size_t len)
 
css_error css_stylesheet_data_done (css_stylesheet *sheet)
 
css_error css_stylesheet_next_pending_import (css_stylesheet *parent, lwc_string **url)
 
css_error css_stylesheet_register_import (css_stylesheet *parent, css_stylesheet *import)
 
css_error css_stylesheet_get_language_level (css_stylesheet *sheet, css_language_level *level)
 
css_error css_stylesheet_get_url (css_stylesheet *sheet, const char **url)
 
css_error css_stylesheet_get_title (css_stylesheet *sheet, const char **title)
 
css_error css_stylesheet_quirks_allowed (css_stylesheet *sheet, bool *allowed)
 
css_error css_stylesheet_used_quirks (css_stylesheet *sheet, bool *quirks)
 
css_error css_stylesheet_get_disabled (css_stylesheet *sheet, bool *disabled)
 
css_error css_stylesheet_set_disabled (css_stylesheet *sheet, bool disabled)
 
css_error css_stylesheet_size (css_stylesheet *sheet, size_t *size)
 
css_error css__stylesheet_style_create (css_stylesheet *sheet, css_style **style)
 
css_error css__stylesheet_merge_style (css_style *target, css_style *style)
 
css_error css__stylesheet_style_vappend (css_style *style, uint32_t style_count,...)
 
css_error css__stylesheet_style_append (css_style *style, css_code_t css_code)
 
css_error css__stylesheet_style_destroy (css_style *style)
 
css_error css__stylesheet_selector_create (css_stylesheet *sheet, css_qname *qname, css_selector **selector)
 
css_error css__stylesheet_selector_destroy (css_stylesheet *sheet, css_selector *selector)
 
css_error css__stylesheet_selector_detail_init (css_stylesheet *sheet, css_selector_type type, css_qname *qname, css_selector_detail_value value, css_selector_detail_value_type value_type, bool negate, css_selector_detail *detail)
 
css_error css__stylesheet_selector_append_specific (css_stylesheet *sheet, css_selector **parent, const css_selector_detail *detail)
 
css_error css__stylesheet_selector_combine (css_stylesheet *sheet, css_combinator type, css_selector *a, css_selector *b)
 
css_error css__stylesheet_rule_create (css_stylesheet *sheet, css_rule_type type, css_rule **rule)
 
css_error css__stylesheet_rule_destroy (css_stylesheet *sheet, css_rule *rule)
 
css_error css__stylesheet_rule_add_selector (css_stylesheet *sheet, css_rule *rule, css_selector *selector)
 
css_error css__stylesheet_rule_append_style (css_stylesheet *sheet, css_rule *rule, css_style *style)
 
css_error css__stylesheet_rule_set_charset (css_stylesheet *sheet, css_rule *rule, lwc_string *charset)
 
css_error css__stylesheet_rule_set_nascent_import (css_stylesheet *sheet, css_rule *rule, lwc_string *url, css_mq_query *media)
 
css_error css__stylesheet_rule_set_media (css_stylesheet *sheet, css_rule *rule, css_mq_query *media)
 
css_error css__stylesheet_rule_set_page_selector (css_stylesheet *sheet, css_rule *rule, css_selector *selector)
 
css_error css__stylesheet_add_rule (css_stylesheet *sheet, css_rule *rule, css_rule *parent)
 
css_error css__stylesheet_remove_rule (css_stylesheet *sheet, css_rule *rule)
 

Macro Definition Documentation

◆ CSS_STYLE_DEFAULT_SIZE

#define CSS_STYLE_DEFAULT_SIZE   16

Function Documentation

◆ css__stylesheet_add_rule()

css_error css__stylesheet_add_rule ( css_stylesheet sheet,
css_rule rule,
css_rule parent 
)

Add a rule to a stylesheet

Parameters
sheetThe stylesheet to add to
ruleThe rule to add
parentThe parent rule, or NULL for a top-level rule
Returns
CSS_OK on success, appropriate error otherwise
Todo:
needs to trigger some event announcing styles have changed

◆ css__stylesheet_merge_style()

css_error css__stylesheet_merge_style ( css_style target,
css_style style 
)

◆ css__stylesheet_remove_rule()

css_error css__stylesheet_remove_rule ( css_stylesheet sheet,
css_rule rule 
)

Remove a rule from a stylesheet

Parameters
sheetThe sheet to remove from
ruleThe rule to remove
Returns
CSS_OK on success, appropriate error otherwise

\ todo renumber subsequent rules? may not be necessary, as there's only an expectation that rules which occur later in the stylesheet have a higher index than those that appear earlier. There's no guarantee that the number space is continuous.

Todo:
needs to trigger some event announcing styles have changed

◆ css__stylesheet_rule_add_selector()

css_error css__stylesheet_rule_add_selector ( css_stylesheet sheet,
css_rule rule,
css_selector selector 
)

Add a selector to a CSS rule

Parameters
sheetThe stylesheet context
ruleThe rule to add to (must be of type CSS_RULE_SELECTOR)
selectorThe selector to add
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_rule_append_style()

css_error css__stylesheet_rule_append_style ( css_stylesheet sheet,
css_rule rule,
css_style style 
)

Append a style to a CSS rule

Parameters
sheetThe stylesheet context
ruleThe rule to add to (must be CSS_RULE_SELECTOR or CSS_RULE_PAGE)
styleThe style to add
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_rule_create()

css_error css__stylesheet_rule_create ( css_stylesheet sheet,
css_rule_type  type,
css_rule **  rule 
)

Create a CSS rule

Parameters
sheetThe stylesheet context
typeThe rule type
rulePointer to location to receive rule object
Returns
CSS_OK on success, CSS_BADPARM on bad parameters, CSS_NOMEM on memory exhaustion

◆ css__stylesheet_rule_destroy()

css_error css__stylesheet_rule_destroy ( css_stylesheet sheet,
css_rule rule 
)

Destroy a CSS rule

Parameters
sheetThe stylesheet context
ruleThe rule to destroy
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_rule_set_charset()

css_error css__stylesheet_rule_set_charset ( css_stylesheet sheet,
css_rule rule,
lwc_string *  charset 
)

Set the charset of a CSS rule

Parameters
sheetThe stylesheet context
ruleThe rule to add to (must be of type CSS_RULE_CHARSET)
charsetThe charset
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_rule_set_media()

css_error css__stylesheet_rule_set_media ( css_stylesheet sheet,
css_rule rule,
css_mq_query media 
)

Set the media of an @media rule

Parameters
sheetThe stylesheet context
ruleThe rule to add to (must be of type CSS_RULE_MEDIA)
mediaThe applicable media types for the rule
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_rule_set_nascent_import()

css_error css__stylesheet_rule_set_nascent_import ( css_stylesheet sheet,
css_rule rule,
lwc_string *  url,
css_mq_query media 
)

Set the necessary data to import a stylesheet associated with a rule

Parameters
sheetThe stylesheet context
ruleThe rule to add to (must be of type CSS_RULE_IMPORT)
urlThe URL of the imported stylesheet
mediaThe applicable media types for the imported stylesheet
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_rule_set_page_selector()

css_error css__stylesheet_rule_set_page_selector ( css_stylesheet sheet,
css_rule rule,
css_selector selector 
)
Todo:
validate selector

◆ css__stylesheet_selector_append_specific()

css_error css__stylesheet_selector_append_specific ( css_stylesheet sheet,
css_selector **  parent,
const css_selector_detail detail 
)

Append a selector to the specifics chain of another selector

Parameters
sheetThe stylesheet context
parentPointer to pointer to the parent selector (updated on exit)
specificThe selector to append (copied)
Returns
CSS_OK on success, appropriate error otherwise.
Todo:
this may want optimising – counting blocks is O(n) In practice, however, n isn't likely to be large, so may be fine

◆ css__stylesheet_selector_combine()

css_error css__stylesheet_selector_combine ( css_stylesheet sheet,
css_combinator  type,
css_selector a,
css_selector b 
)

Combine a pair of selectors

Parameters
sheetThe stylesheet context
typeThe combinator type
aThe first operand
bThe second operand
Returns
CSS_OK on success, appropriate error otherwise.

For example, given A + B, the combinator field of B would point at A, with a combinator type of CSS_COMBINATOR_SIBLING. Thus, given B, we can find its combinator. It is not possible to find B given A.

◆ css__stylesheet_selector_create()

css_error css__stylesheet_selector_create ( css_stylesheet sheet,
css_qname qname,
css_selector **  selector 
)

Create an element selector

Parameters
sheetThe stylesheet context
qnameQualified name of selector
selectorPointer to location to receive selector object
Returns
CSS_OK on success, CSS_BADPARM on bad parameters, CSS_NOMEM on memory exhaustion

◆ css__stylesheet_selector_destroy()

css_error css__stylesheet_selector_destroy ( css_stylesheet sheet,
css_selector selector 
)

Destroy a selector object

Parameters
sheetThe stylesheet context
selectorThe selector to destroy
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_selector_detail_init()

css_error css__stylesheet_selector_detail_init ( css_stylesheet sheet,
css_selector_type  type,
css_qname qname,
css_selector_detail_value  value,
css_selector_detail_value_type  value_type,
bool  negate,
css_selector_detail detail 
)

Initialise a selector detail

Parameters
sheetThe stylesheet context
typeThe type of selector to create
qnameQualified name of selector
valueValue of selector
value_typeType of value
negateWhether the detail match should be negated
detailPointer to detail object to initialise
Returns
CSS_OK on success, CSS_BADPARM on bad parameters
Note
No strings are referenced at this point: they will be referenced when appending the detail to a selector.

◆ css__stylesheet_string_add()

css_error css__stylesheet_string_add ( css_stylesheet sheet,
lwc_string *  string,
uint32_t *  string_number 
)

Add a string to a stylesheet's string vector.

Parameters
sheetThe stylesheet to add string to.
stringThe string to add.
string_numberPointer to location to receive string number.
Returns
CSS_OK on success, CSS_BADPARM on bad parameters, CSS_NOMEM on memory exhaustion
Postcondition
Ownership of string reference is passed to the stylesheet (even on failure)
Note
The returned string number is guaranteed to be non-zero

◆ css__stylesheet_string_get()

css_error css__stylesheet_string_get ( css_stylesheet sheet,
uint32_t  string_number,
lwc_string **  string 
)

Get a string from a stylesheet's string vector.

Parameters
sheetThe stylesheet to retrive string from.
string_numberThe string number to retrive.
stringPointer to location to receive string.
Returns
CSS_OK on success, CSS_BADPARM on bad parameters,

◆ css__stylesheet_style_append()

css_error css__stylesheet_style_append ( css_style style,
css_code_t  css_code 
)

append a css code entry to a style

◆ css__stylesheet_style_create()

css_error css__stylesheet_style_create ( css_stylesheet sheet,
css_style **  style 
)

Create a style

Parameters
sheetThe stylesheet context
lenThe required length of the style
stylePointer to location to receive style
Returns
CSS_OK on success, CSS_BADPARM on bad parameters, CSS_NOMEM on memory exhaustion

◆ css__stylesheet_style_destroy()

css_error css__stylesheet_style_destroy ( css_style style)

Destroy a style

Parameters
sheetThe stylesheet context
styleThe style to destroy
Returns
CSS_OK on success, appropriate error otherwise

◆ css__stylesheet_style_vappend()

css_error css__stylesheet_style_vappend ( css_style style,
uint32_t  style_count,
  ... 
)

append one or more css code entries to a style

◆ css_stylesheet_append_data()

css_error css_stylesheet_append_data ( css_stylesheet sheet,
const uint8_t *  data,
size_t  len 
)

Append source data to a stylesheet

Parameters
sheetThe stylesheet to append data to
dataPointer to data to append
lenLength, in bytes, of data to append
Returns
CSS_OK on success, appropriate error otherwise

◆ css_stylesheet_create()

css_error css_stylesheet_create ( const css_stylesheet_params params,
css_stylesheet **  stylesheet 
)

Create a stylesheet

Parameters
paramsStylesheet parameters
stylesheetPointer to location to receive stylesheet
Returns
CSS_OK on success, CSS_BADPARM on bad parameters, CSS_NOMEM on memory exhaustion

◆ css_stylesheet_data_done()

css_error css_stylesheet_data_done ( css_stylesheet sheet)

Flag that the last of a stylesheet's data has been seen

Parameters
sheetThe stylesheet in question
Returns
CSS_OK on success, CSS_IMPORTS_PENDING if there are imports pending, appropriate error otherwise

◆ css_stylesheet_destroy()

css_error css_stylesheet_destroy ( css_stylesheet sheet)

Destroy a stylesheet

Parameters
sheetThe stylesheet to destroy
Returns
CSS_OK on success, appropriate error otherwise

◆ css_stylesheet_get_disabled()

css_error css_stylesheet_get_disabled ( css_stylesheet sheet,
bool *  disabled 
)

Get disabled status of a stylesheet

Parameters
sheetThe stylesheet to consider
disabledPointer to location to receive disabled state
Returns
CSS_OK on success, appropriate error otherwise

◆ css_stylesheet_get_language_level()

css_error css_stylesheet_get_language_level ( css_stylesheet sheet,
css_language_level level 
)

Retrieve the language level of a stylesheet

Parameters
sheetThe stylesheet to retrieve the language level of
levelPointer to location to receive language level
Returns
CSS_OK on success, appropriate error otherwise

◆ css_stylesheet_get_title()

css_error css_stylesheet_get_title ( css_stylesheet sheet,
const char **  title 
)

Retrieve the title associated with a stylesheet

Parameters
sheetThe stylesheet to retrieve the title from
titlePointer to location to receive pointer to title
Returns
CSS_Ok on success, appropriate error otherwise

◆ css_stylesheet_get_url()

css_error css_stylesheet_get_url ( css_stylesheet sheet,
const char **  url 
)

Retrieve the URL associated with a stylesheet

Parameters
sheetThe stylesheet to retrieve the URL from
urlPointer to location to receive pointer to URL
Returns
CSS_OK on success, appropriate error otherwise

◆ css_stylesheet_next_pending_import()

css_error css_stylesheet_next_pending_import ( css_stylesheet parent,
lwc_string **  url 
)

Retrieve the next pending import for the parent stylesheet

Parameters
parentParent stylesheet
urlPointer to object to be populated with details of URL of imported stylesheet (potentially relative)
Returns
CSS_OK on success, CSS_INVALID if there are no pending imports remaining

The client must resolve the absolute URL of the imported stylesheet, using the parent's URL as the base. It must then fetch the imported stylesheet, and parse it to completion, including fetching any stylesheets it may import. The resultant sheet must then be registered with the parent using css_stylesheet_register_import().

The client must then call this function again, to determine if there are any further imports for the parent stylesheet, and, if so, process them as described above.

If the client is unable to fetch an imported stylesheet, it must register an empty stylesheet with the parent in its place.

◆ css_stylesheet_quirks_allowed()

css_error css_stylesheet_quirks_allowed ( css_stylesheet sheet,
bool *  allowed 
)

Determine whether quirky parsing was permitted on a stylesheet

Parameters
sheetThe stylesheet to consider
quirksPointer to location to receive quirkyness
Returns
CSS_OK on success, appropriate error otherwise

◆ css_stylesheet_register_import()

css_error css_stylesheet_register_import ( css_stylesheet parent,
css_stylesheet import 
)

Register an imported stylesheet with its parent

Parameters
parentParent stylesheet
importImported sheet
Returns
CSS_OK on success, CSS_INVALID if there are no outstanding imports, appropriate error otherwise.

Ownership of the imported stylesheet is retained by the client.

◆ css_stylesheet_set_disabled()

css_error css_stylesheet_set_disabled ( css_stylesheet sheet,
bool  disabled 
)

Set a stylesheet's disabled state

Parameters
sheetThe stylesheet to modify
disabledThe new disabled state
Returns
CSS_OK on success, appropriate error otherwise
Todo:
needs to trigger some event announcing styles have changed

◆ css_stylesheet_size()

css_error css_stylesheet_size ( css_stylesheet sheet,
size_t *  size 
)

Determine the memory-resident size of a stylesheet

Parameters
sheetSheet to consider
sizePointer to location to receive byte count
Returns
CSS_OK on success.
Note
The returned size will not include the size of interned strings or imported stylesheets.

◆ css_stylesheet_used_quirks()

css_error css_stylesheet_used_quirks ( css_stylesheet sheet,
bool *  quirks 
)

Determine whether quirky parsing was used on a stylesheet

Parameters
sheetThe stylesheet to consider
quirksPointer to location to receive quirkyness
Returns
CSS_OK on success, appropriate error otherwise