libcss
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
stylesheet.h File Reference
#include <inttypes.h>
#include <stdio.h>
#include <libwapcaplet/libwapcaplet.h>
#include <libcss/errors.h>
#include <libcss/functypes.h>
#include <libcss/stylesheet.h>
#include <libcss/types.h>
#include "bytecode/bytecode.h"
#include "parse/parse.h"
#include "parse/mq.h"
#include "select/hash.h"

Go to the source code of this file.

Classes

struct  css_style
 
union  css_selector_detail_value
 
struct  css_selector_detail
 
struct  css_selector
 
struct  css_rule
 
struct  css_rule_selector
 
struct  css_rule_media
 
struct  css_rule_font_face
 
struct  css_rule_page
 
struct  css_rule_import
 
struct  css_rule_charset
 
struct  css_stylesheet
 

Macros

#define CSS_SPECIFICITY_A   0x01000000
 
#define CSS_SPECIFICITY_B   0x00010000
 
#define CSS_SPECIFICITY_C   0x00000100
 
#define CSS_SPECIFICITY_D   0x00000001
 

Typedefs

typedef struct css_rule css_rule
 
typedef struct css_selector css_selector
 
typedef struct css_style css_style
 
typedef enum css_selector_type css_selector_type
 
typedef enum css_combinator css_combinator
 
typedef enum css_selector_detail_value_type css_selector_detail_value_type
 
typedef union css_selector_detail_value css_selector_detail_value
 
typedef struct css_selector_detail css_selector_detail
 
typedef enum css_rule_type css_rule_type
 
typedef enum css_rule_parent_type css_rule_parent_type
 
typedef struct css_rule_selector css_rule_selector
 
typedef struct css_rule_media css_rule_media
 
typedef struct css_rule_font_face css_rule_font_face
 
typedef struct css_rule_page css_rule_page
 
typedef struct css_rule_import css_rule_import
 
typedef struct css_rule_charset css_rule_charset
 

Enumerations

enum  css_selector_type {
  CSS_SELECTOR_ELEMENT , CSS_SELECTOR_CLASS , CSS_SELECTOR_ID , CSS_SELECTOR_PSEUDO_CLASS ,
  CSS_SELECTOR_PSEUDO_ELEMENT , CSS_SELECTOR_ATTRIBUTE , CSS_SELECTOR_ATTRIBUTE_EQUAL , CSS_SELECTOR_ATTRIBUTE_DASHMATCH ,
  CSS_SELECTOR_ATTRIBUTE_INCLUDES , CSS_SELECTOR_ATTRIBUTE_PREFIX , CSS_SELECTOR_ATTRIBUTE_SUFFIX , CSS_SELECTOR_ATTRIBUTE_SUBSTRING
}
 
enum  css_combinator {
  CSS_COMBINATOR_NONE , CSS_COMBINATOR_ANCESTOR , CSS_COMBINATOR_PARENT , CSS_COMBINATOR_SIBLING ,
  CSS_COMBINATOR_GENERIC_SIBLING
}
 
enum  css_selector_detail_value_type { CSS_SELECTOR_DETAIL_VALUE_STRING , CSS_SELECTOR_DETAIL_VALUE_NTH }
 
enum  css_rule_type {
  CSS_RULE_UNKNOWN , CSS_RULE_SELECTOR , CSS_RULE_CHARSET , CSS_RULE_IMPORT ,
  CSS_RULE_MEDIA , CSS_RULE_FONT_FACE , CSS_RULE_PAGE
}
 
enum  css_rule_parent_type { CSS_RULE_PARENT_STYLESHEET , CSS_RULE_PARENT_RULE }
 

Functions

css_error css__stylesheet_style_create (css_stylesheet *sheet, css_style **style)
 
css_error css__stylesheet_style_append (css_style *style, css_code_t code)
 
css_error css__stylesheet_style_vappend (css_style *style, uint32_t style_count,...)
 
css_error css__stylesheet_style_destroy (css_style *style)
 
css_error css__stylesheet_merge_style (css_style *target, 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 *specific)
 
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 *sel)
 
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)
 
css_error css__stylesheet_string_get (css_stylesheet *sheet, uint32_t string_number, lwc_string **string)
 
css_error css__stylesheet_string_add (css_stylesheet *sheet, lwc_string *string, uint32_t *string_number)
 

Variables

struct css_rule _ALIGNED
 

Macro Definition Documentation

◆ CSS_SPECIFICITY_A

#define CSS_SPECIFICITY_A   0x01000000

◆ CSS_SPECIFICITY_B

#define CSS_SPECIFICITY_B   0x00010000

◆ CSS_SPECIFICITY_C

#define CSS_SPECIFICITY_C   0x00000100

◆ CSS_SPECIFICITY_D

#define CSS_SPECIFICITY_D   0x00000001

Typedef Documentation

◆ css_combinator

◆ css_rule

typedef struct css_rule css_rule

◆ css_rule_charset

◆ css_rule_font_face

◆ css_rule_import

◆ css_rule_media

◆ css_rule_page

typedef struct css_rule_page css_rule_page

◆ css_rule_parent_type

◆ css_rule_selector

◆ css_rule_type

◆ css_selector

typedef struct css_selector css_selector

◆ css_selector_detail

◆ css_selector_detail_value

◆ css_selector_detail_value_type

◆ css_selector_type

◆ css_style

typedef struct css_style css_style

Enumeration Type Documentation

◆ css_combinator

Enumerator
CSS_COMBINATOR_NONE 
CSS_COMBINATOR_ANCESTOR 
CSS_COMBINATOR_PARENT 
CSS_COMBINATOR_SIBLING 
CSS_COMBINATOR_GENERIC_SIBLING 

◆ css_rule_parent_type

Enumerator
CSS_RULE_PARENT_STYLESHEET 
CSS_RULE_PARENT_RULE 

◆ css_rule_type

Enumerator
CSS_RULE_UNKNOWN 
CSS_RULE_SELECTOR 
CSS_RULE_CHARSET 
CSS_RULE_IMPORT 
CSS_RULE_MEDIA 
CSS_RULE_FONT_FACE 
CSS_RULE_PAGE 

◆ css_selector_detail_value_type

Enumerator
CSS_SELECTOR_DETAIL_VALUE_STRING 
CSS_SELECTOR_DETAIL_VALUE_NTH 

◆ css_selector_type

Enumerator
CSS_SELECTOR_ELEMENT 
CSS_SELECTOR_CLASS 
CSS_SELECTOR_ID 
CSS_SELECTOR_PSEUDO_CLASS 
CSS_SELECTOR_PSEUDO_ELEMENT 
CSS_SELECTOR_ATTRIBUTE 
CSS_SELECTOR_ATTRIBUTE_EQUAL 
CSS_SELECTOR_ATTRIBUTE_DASHMATCH 
CSS_SELECTOR_ATTRIBUTE_INCLUDES 
CSS_SELECTOR_ATTRIBUTE_PREFIX 
CSS_SELECTOR_ATTRIBUTE_SUFFIX 
CSS_SELECTOR_ATTRIBUTE_SUBSTRING 

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

Variable Documentation

◆ _ALIGNED

struct css_rule _ALIGNED