ELinks 0.18.0
stylesheet.h File Reference
#include "protocol/uri.h"
#include "util/lists.h"
Include dependency graph for stylesheet.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  css_selector_set
 A set of struct css_selector. More...
 
struct  css_selector
 The struct css_selector is used for mapping elements (or nodes) in the document structure to properties. More...
 
struct  css_stylesheet
 The struct css_stylesheet describes all the useful data that was extracted from the CSS source. More...
 

Macros

#define INIT_CSS_SELECTOR_SET(set)   { 0, { D_LIST_HEAD_EL(set.list) } }
 
#define INIT_CSS_STYLESHEET(css, import)    { import, NULL, INIT_CSS_SELECTOR_SET(css.selectors) }
 
#define get_css_base_selector(stylesheet, type, rel, name, namelen)
 
#define find_css_base_selector(stylesheet, type, rel, name, namelen)    find_css_selector(&stylesheet->selectors, rel, type, name, namelen)
 
#define css_selector_set_empty(set)   list_empty((set)->list)
 
#define css_selector_set_front(set)   ((struct css_selector *) ((set)->list.next))
 
#define css_selector_is_in_set(selector)   ((selector)->next != NULL)
 
#define foreach_css_selector(selector, set)   foreach (selector, (set)->list)
 

Typedefs

typedef unsigned char css_selector_type_T
 
typedef void(* css_stylesheet_importer_T) (struct css_stylesheet *, struct uri *, const char *url, int urllen)
 

Enumerations

enum  css_selector_relation { CSR_ROOT , CSR_SPECIFITY , CSR_ANCESTOR , CSR_PARENT }
 
enum  css_selector_type {
  CST_ELEMENT , CST_ID , CST_CLASS , CST_PSEUDO ,
  CST_INVALID
}
 

Functions

struct css_stylesheetinit_css_stylesheet (css_stylesheet_importer_T importer, void *import_data)
 Dynamically allocates a stylesheet.
 
void mirror_css_stylesheet (struct css_stylesheet *css1, struct css_stylesheet *css2)
 Mirror given CSS stylesheet css1 to an identical copy of itself (including all the selectors), css2.
 
void done_css_stylesheet (struct css_stylesheet *css)
 Releases all the content of the stylesheet (but not the stylesheet itself).
 
struct css_selectorget_css_selector (struct css_selector_set *set, css_selector_type_T type, enum css_selector_relation rel, const char *name, int namelen)
 Returns a new freshly made selector adding it to the given selector set, or NULL.
 
struct css_selectorfind_css_selector (struct css_selector_set *set, css_selector_type_T type, enum css_selector_relation rel, const char *name, int namelen)
 Looks up the selector of the name name and length namelen in the given set of selectors.
 
struct css_selectorinit_css_selector (struct css_selector_set *set, css_selector_type_T type, enum css_selector_relation relation, const char *name, int namelen)
 Initialize the selector structure.
 
void add_selector_properties (struct css_selector *selector, struct css_property list *properties)
 Add all properties from the list to the given selector.
 
void merge_css_selectors (struct css_selector *sel1, struct css_selector *sel2)
 Join sel2 to sel1, sel1 taking precedence in all conflicts.
 
void set_css_selector_relation (struct css_selector *, enum css_selector_relation)
 Use this function instead of modifying css_selector.relation directly.
 
void done_css_selector (struct css_selector *selector)
 Destroy a selector.
 
void init_css_selector_set (struct css_selector_set *set)
 
void done_css_selector_set (struct css_selector_set *set)
 
void add_css_selector_to_set (struct css_selector *, struct css_selector_set *)
 
void del_css_selector_from_set (struct css_selector *)
 

Detailed Description

Todo
TODO: We need a memory efficient and fast way to define how properties cascade. What we are interested in is making it fast and easy to find all properties we need.
struct css_cascade {
struct css_cascade *parent;
struct list_head properties;
- Can later be turned into a table to not waste memory:
struct css_property properties[1];
};
The struct css_property describes one CSS declaration in a rule, therefore being basically a parsed i...
Definition property.h:93
Definition lists.h:100
Definition table.h:83

And the selector should then only map a document element into this data structure.

All the CSS applier has to do is require the css_cascade of the current element and it should nicely inherit any style from parent cascades. Question is in what direction to apply. It should be possible for the user to overwrite any document provided stylesheet using "!important" so we need to keep track in some table what properties was already applied so we only overwrite when we have to. –jonas

XXX: This is one of the TODOs where I have no clue what is it talking about in particular. Is it obsolete now when we grok 'td.foo p::x>a:hover' without hesitation? –pasky

Macro Definition Documentation

◆ css_selector_is_in_set

#define css_selector_is_in_set ( selector)    ((selector)->next != NULL)

◆ css_selector_set_empty

#define css_selector_set_empty ( set)    list_empty((set)->list)

◆ css_selector_set_front

#define css_selector_set_front ( set)    ((struct css_selector *) ((set)->list.next))

◆ find_css_base_selector

#define find_css_base_selector ( stylesheet,
type,
rel,
name,
namelen )    find_css_selector(&stylesheet->selectors, rel, type, name, namelen)

◆ foreach_css_selector

#define foreach_css_selector ( selector,
set )   foreach (selector, (set)->list)

◆ get_css_base_selector

#define get_css_base_selector ( stylesheet,
type,
rel,
name,
namelen )
Value:
get_css_selector((stylesheet) ? &(stylesheet)->selectors : NULL, \
type, rel, name, namelen)
#define NULL
Definition explodename.c:35
const char * type
Definition download.c:1899
struct css_selector * get_css_selector(struct css_selector_set *set, css_selector_type_T type, enum css_selector_relation rel, const char *name, int namelen)
Returns a new freshly made selector adding it to the given selector set, or NULL.
Definition stylesheet.c:98

◆ INIT_CSS_SELECTOR_SET

#define INIT_CSS_SELECTOR_SET ( set)    { 0, { D_LIST_HEAD_EL(set.list) } }

◆ INIT_CSS_STYLESHEET

#define INIT_CSS_STYLESHEET ( css,
import )    { import, NULL, INIT_CSS_SELECTOR_SET(css.selectors) }

Typedef Documentation

◆ css_selector_type_T

typedef unsigned char css_selector_type_T

◆ css_stylesheet_importer_T

typedef void(* css_stylesheet_importer_T) (struct css_stylesheet *, struct uri *, const char *url, int urllen)

Enumeration Type Documentation

◆ css_selector_relation

Enumerator
CSR_ROOT 

First class stylesheet member.

CSR_SPECIFITY 

Narrowing-down, i.e.

the "x" in "foo#x".

CSR_ANCESTOR 

Ancestor, i.e.

the "p" in "p a".

CSR_PARENT 

Direct parent, i.e.

the "div" in "div>img".

◆ css_selector_type

Enumerator
CST_ELEMENT 
CST_ID 
CST_CLASS 
CST_PSEUDO 
CST_INVALID 

Auxiliary for the parser.

Function Documentation

◆ add_css_selector_to_set()

void add_css_selector_to_set ( struct css_selector * selector,
struct css_selector_set * set )

◆ add_selector_properties()

void add_selector_properties ( struct css_selector * selector,
struct css_property list * properties )

Add all properties from the list to the given selector.

◆ del_css_selector_from_set()

void del_css_selector_from_set ( struct css_selector * selector)

◆ done_css_selector()

void done_css_selector ( struct css_selector * selector)

Destroy a selector.

done_css_stylesheet() normally does that for you.

◆ done_css_selector_set()

void done_css_selector_set ( struct css_selector_set * set)

◆ done_css_stylesheet()

void done_css_stylesheet ( struct css_stylesheet * css)

Releases all the content of the stylesheet (but not the stylesheet itself).

◆ find_css_selector()

struct css_selector * find_css_selector ( struct css_selector_set * set,
css_selector_type_T type,
enum css_selector_relation rel,
const char * name,
int namelen )

Looks up the selector of the name name and length namelen in the given set of selectors.

◆ get_css_selector()

struct css_selector * get_css_selector ( struct css_selector_set * set,
css_selector_type_T type,
enum css_selector_relation rel,
const char * name,
int namelen )

Returns a new freshly made selector adding it to the given selector set, or NULL.

◆ init_css_selector()

struct css_selector * init_css_selector ( struct css_selector_set * set,
css_selector_type_T type,
enum css_selector_relation relation,
const char * name,
int namelen )

Initialize the selector structure.

This is a rather low-level function from your POV.

◆ init_css_selector_set()

void init_css_selector_set ( struct css_selector_set * set)

◆ init_css_stylesheet()

struct css_stylesheet * init_css_stylesheet ( css_stylesheet_importer_T importer,
void * import_data )

Dynamically allocates a stylesheet.

◆ merge_css_selectors()

void merge_css_selectors ( struct css_selector * sel1,
struct css_selector * sel2 )

Join sel2 to sel1, sel1 taking precedence in all conflicts.

◆ mirror_css_stylesheet()

void mirror_css_stylesheet ( struct css_stylesheet * css1,
struct css_stylesheet * css2 )

Mirror given CSS stylesheet css1 to an identical copy of itself (including all the selectors), css2.

◆ set_css_selector_relation()

void set_css_selector_relation ( struct css_selector * selector,
enum css_selector_relation )

Use this function instead of modifying css_selector.relation directly.