ELinks 0.18.0
css.c File Reference
#include "elinks.h"
#include <stdio.h>
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
#include <libcss/libcss.h>
#include "cache/cache.h"
#include "document/html/internal.h"
#include "document/libdom/css.h"
#include "document/libdom/mapa.h"
#include "document/libdom/corestrings.h"
#include "util/string.h"
Include dependency graph for css.c:

Macros

#define UNUSED(a)

Functions

static css_error node_name (void *pw, void *node, css_qname *qname)
 Callback to retrieve a node's name.
static css_error node_classes (void *pw, void *node, lwc_string ***classes, uint32_t *n_classes)
 Callback to retrieve a node's classes.
static css_error node_id (void *pw, void *node, lwc_string **id)
 Callback to retrieve a node's ID.
static css_error named_parent_node (void *pw, void *node, const css_qname *qname, void **parent)
 Callback to find a named parent node.
static css_error named_sibling_node (void *pw, void *node, const css_qname *qname, void **sibling)
 Callback to find a named sibling node.
static css_error named_generic_sibling_node (void *pw, void *node, const css_qname *qname, void **sibling)
 Callback to find a named generic sibling node.
static css_error parent_node (void *pw, void *node, void **parent)
 Callback to retrieve the parent of a node.
static css_error sibling_node (void *pw, void *node, void **sibling)
 Callback to retrieve the preceding sibling of a node.
static css_error node_has_name (void *pw, void *node, const css_qname *qname, bool *match)
 Callback to determine if a node has the given name.
static css_error node_has_class (void *pw, void *node, lwc_string *name, bool *match)
 Callback to determine if a node has the given class.
static css_error node_has_id (void *pw, void *node, lwc_string *name, bool *match)
 Callback to determine if a node has the given id.
static css_error node_has_attribute (void *pw, void *node, const css_qname *qname, bool *match)
 Callback to determine if a node has an attribute with the given name.
static css_error node_has_attribute_equal (void *pw, void *node, const css_qname *qname, lwc_string *value, bool *match)
 Callback to determine if a node has an attribute with given name and value.
static css_error node_has_attribute_dashmatch (void *pw, void *node, const css_qname *qname, lwc_string *value, bool *match)
 Callback to determine if a node has an attribute with the given name whose value dashmatches that given.
static css_error node_has_attribute_includes (void *pw, void *node, const css_qname *qname, lwc_string *value, bool *match)
 Callback to determine if a node has an attribute with the given name whose value includes that given.
static css_error node_has_attribute_prefix (void *pw, void *node, const css_qname *qname, lwc_string *value, bool *match)
 Callback to determine if a node has an attribute with the given name whose value has the prefix given.
static css_error node_has_attribute_suffix (void *pw, void *node, const css_qname *qname, lwc_string *value, bool *match)
 Callback to determine if a node has an attribute with the given name whose value has the suffix given.
static css_error node_has_attribute_substring (void *pw, void *node, const css_qname *qname, lwc_string *value, bool *match)
 Callback to determine if a node has an attribute with the given name whose value contains the substring given.
static css_error node_is_root (void *pw, void *node, bool *match)
 Callback to determine if a node is the root node of the document.
static css_error node_count_siblings (void *pw, void *n, bool same_name, bool after, int32_t *count)
 Callback to count a node's siblings.
static css_error node_is_empty (void *pw, void *node, bool *match)
 Callback to determine if a node is empty.
static css_error node_is_link (void *pw, void *n, bool *match)
 Callback to determine if a node is a linking element.
static css_error node_is_hover (void *pw, void *node, bool *match)
 Callback to determine if a node is currently being hovered over.
static css_error node_is_active (void *pw, void *node, bool *match)
 Callback to determine if a node is currently activated.
static css_error node_is_focus (void *pw, void *node, bool *match)
 Callback to determine if a node has the input focus.
static css_error node_is_enabled (void *pw, void *node, bool *match)
 Callback to determine if a node is enabled.
static css_error node_is_disabled (void *pw, void *node, bool *match)
 Callback to determine if a node is disabled.
static css_error node_is_checked (void *pw, void *node, bool *match)
 Callback to determine if a node is checked.
static css_error node_is_target (void *pw, void *node, bool *match)
 Callback to determine if a node is the target of the document URL.
static css_error node_is_lang (void *pw, void *node, lwc_string *lang, bool *match)
 Callback to determine if a node has the given language.
static css_error ua_default_for_property (void *pw, uint32_t property, css_hint *hint)
 Callback to retrieve the User-Agent defaults for a CSS property.
static css_error set_libcss_node_data (void *pw, void *node, void *libcss_node_data)
static css_error get_libcss_node_data (void *pw, void *node, void **libcss_node_data)
static css_error named_ancestor_node (void *pw, void *node, const css_qname *qname, void **ancestor)
 Callback to find a named ancestor node.
static css_error node_is_visited (void *pw, void *node, bool *match)
 Callback to determine if a node is a linking element whose target has been visited.
static css_error node_presentational_hint (void *pw, void *node, uint32_t *nhints, css_hint **hints)
static css_error resolve_url_empty (void *pw, const char *base, lwc_string *rel, lwc_string **abs)
css_error resolve_url (void *pw, const char *base, lwc_string *rel, lwc_string **abs)
css_stylesheetnscss_create_inline_style (const uint8_t *data, size_t len, const char *charset, const char *url, bool allow_quirks)
 Create an inline style.
static void nscss_dom_user_data_handler (dom_node_operation operation, dom_string *key, void *data, struct dom_node *src, struct dom_node *dst)
css_select_results * nscss_get_style (nscss_select_ctx *ctx, dom_node *n, const css_media *media, const css_unit_ctx *unit_len_ctx, const css_stylesheet *inline_style)
 Get style selection results for an element.
css_computed_style * nscss_get_blank_style (nscss_select_ctx *ctx, const css_unit_ctx *unit_len_ctx, const css_computed_style *parent)
 Get a blank style.
static int node_count_siblings_check (dom_node *node, bool check_name, dom_string *name)
static void apply_color (struct html_context *html_context, struct html_element *html_element, css_color color_shade)
static void apply_background_color (struct html_context *html_context, struct html_element *html_element, css_color color_shade)
static void apply_font_attribute (struct html_context *html_context, struct html_element *element, bool underline, bool bold, bool strike)
static void apply_list_style (struct html_context *html_context, struct html_element *element, uint8_t list_type)
static void apply_display (struct html_context *html_context, struct html_element *element, uint8_t display)
static void apply_text_align (struct html_context *html_context, struct html_element *element, uint8_t text_align)
static void apply_font_style (struct html_context *html_context, struct html_element *element, uint8_t font_style)
static bool is_bold (int val)
void select_css (struct html_context *html_context, struct html_element *html_element)
static css_error handle_import (void *pw, css_stylesheet *parent, lwc_string *url)
static void parse_css_common (struct html_context *html_context, const char *text, int length, struct uri *uri)
void parse_css (struct html_context *html_context, char *name)
void import_css2 (struct html_context *html_context, struct uri *uri)
void * el_match_selector (const char *selector, void *node)

Variables

static css_select_handler selection_handler
 Selection callback table for libcss.

Macro Definition Documentation

◆ UNUSED

#define UNUSED ( a)

Function Documentation

◆ apply_background_color()

void apply_background_color ( struct html_context * html_context,
struct html_element * html_element,
css_color color_shade )
static

◆ apply_color()

void apply_color ( struct html_context * html_context,
struct html_element * html_element,
css_color color_shade )
static

◆ apply_display()

void apply_display ( struct html_context * html_context,
struct html_element * element,
uint8_t display )
static

◆ apply_font_attribute()

void apply_font_attribute ( struct html_context * html_context,
struct html_element * element,
bool underline,
bool bold,
bool strike )
static

◆ apply_font_style()

void apply_font_style ( struct html_context * html_context,
struct html_element * element,
uint8_t font_style )
static

◆ apply_list_style()

void apply_list_style ( struct html_context * html_context,
struct html_element * element,
uint8_t list_type )
static

◆ apply_text_align()

void apply_text_align ( struct html_context * html_context,
struct html_element * element,
uint8_t text_align )
static

◆ el_match_selector()

void * el_match_selector ( const char * selector,
void * node )
Todo
Change nsoption font sizes to px.

f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72); f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);

◆ get_libcss_node_data()

css_error get_libcss_node_data ( void * pw,
void * node,
void ** libcss_node_data )
static

◆ handle_import()

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

◆ import_css2()

void import_css2 ( struct html_context * html_context,
struct uri * uri )

◆ is_bold()

bool is_bold ( int val)
static

◆ named_ancestor_node()

css_error named_ancestor_node ( void * pw,
void * node,
const css_qname * qname,
void ** ancestor )
static

Callback to find a named ancestor node.

Parameters
pwHTML document
nodeDOM node
qnameNode name to search for
ancestorPointer to location to receive ancestor
Returns
CSS_OK.
Postcondition
ancestor will contain the result, or NULL if there is no match

◆ named_generic_sibling_node()

css_error named_generic_sibling_node ( void * pw,
void * node,
const css_qname * qname,
void ** sibling )
static

Callback to find a named generic sibling node.

Parameters
pwHTML document
nodeDOM node
qnameNode name to search for
siblingPointer to location to receive ancestor
Returns
CSS_OK.
Postcondition
sibling will contain the result, or NULL if there is no match

◆ named_parent_node()

css_error named_parent_node ( void * pw,
void * node,
const css_qname * qname,
void ** parent )
static

Callback to find a named parent node.

Parameters
pwHTML document
nodeDOM node
qnameNode name to search for
parentPointer to location to receive parent
Returns
CSS_OK.
Postcondition
parent will contain the result, or NULL if there is no match

◆ named_sibling_node()

css_error named_sibling_node ( void * pw,
void * node,
const css_qname * qname,
void ** sibling )
static

Callback to find a named sibling node.

Parameters
pwHTML document
nodeDOM node
qnameNode name to search for
siblingPointer to location to receive sibling
Returns
CSS_OK.
Postcondition
sibling will contain the result, or NULL if there is no match

◆ node_classes()

css_error node_classes ( void * pw,
void * node,
lwc_string *** classes,
uint32_t * n_classes )
static

Callback to retrieve a node's classes.

Parameters
pwHTML document
nodeDOM node
classesPointer to location to receive class name array
n_classesPointer to location to receive length of class name array
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Note
The returned array will be destroyed by libcss. Therefore, it must be allocated using the same allocator as used by libcss during style selection.

◆ node_count_siblings()

css_error node_count_siblings ( void * pw,
void * n,
bool same_name,
bool after,
int32_t * count )
static

Callback to count a node's siblings.

Parameters
pwHTML document
nDOM node
same_nameOnly count siblings with the same name, or all
afterCount anteceding instead of preceding siblings
countPointer to location to receive result
Returns
CSS_OK.
Postcondition
count will contain the number of siblings

◆ node_count_siblings_check()

int node_count_siblings_check ( dom_node * node,
bool check_name,
dom_string * name )
static

◆ node_has_attribute()

css_error node_has_attribute ( void * pw,
void * node,
const css_qname * qname,
bool * match )
static

Callback to determine if a node has an attribute with the given name.

Parameters
pwHTML document
nodeDOM node
qnameName to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_attribute_dashmatch()

css_error node_has_attribute_dashmatch ( void * pw,
void * node,
const css_qname * qname,
lwc_string * value,
bool * match )
static

Callback to determine if a node has an attribute with the given name whose value dashmatches that given.

Parameters
pwHTML document
nodeDOM node
qnameName to match
valueValue to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_attribute_equal()

css_error node_has_attribute_equal ( void * pw,
void * node,
const css_qname * qname,
lwc_string * value,
bool * match )
static

Callback to determine if a node has an attribute with given name and value.

Parameters
pwHTML document
nodeDOM node
qnameName to match
valueValue to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_attribute_includes()

css_error node_has_attribute_includes ( void * pw,
void * node,
const css_qname * qname,
lwc_string * value,
bool * match )
static

Callback to determine if a node has an attribute with the given name whose value includes that given.

Parameters
pwHTML document
nodeDOM node
qnameName to match
valueValue to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_attribute_prefix()

css_error node_has_attribute_prefix ( void * pw,
void * node,
const css_qname * qname,
lwc_string * value,
bool * match )
static

Callback to determine if a node has an attribute with the given name whose value has the prefix given.

Parameters
pwHTML document
nodeDOM node
qnameName to match
valueValue to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_attribute_substring()

css_error node_has_attribute_substring ( void * pw,
void * node,
const css_qname * qname,
lwc_string * value,
bool * match )
static

Callback to determine if a node has an attribute with the given name whose value contains the substring given.

Parameters
pwHTML document
nodeDOM node
qnameName to match
valueValue to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_attribute_suffix()

css_error node_has_attribute_suffix ( void * pw,
void * node,
const css_qname * qname,
lwc_string * value,
bool * match )
static

Callback to determine if a node has an attribute with the given name whose value has the suffix given.

Parameters
pwHTML document
nodeDOM node
qnameName to match
valueValue to match
matchPointer to location to receive result
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_has_class()

css_error node_has_class ( void * pw,
void * node,
lwc_string * name,
bool * match )
static

Callback to determine if a node has the given class.

Parameters
pwHTML document
nodeDOM node
nameName to match
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.
Todo
: Ensure that libdom performs case-insensitive matching in quirks mode

◆ node_has_id()

css_error node_has_id ( void * pw,
void * node,
lwc_string * name,
bool * match )
static

Callback to determine if a node has the given id.

Parameters
pwHTML document
nodeDOM node
nameName to match
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.
Todo
Assumes an HTML DOM

◆ node_has_name()

css_error node_has_name ( void * pw,
void * node,
const css_qname * qname,
bool * match )
static

Callback to determine if a node has the given name.

Parameters
pwHTML document
nodeDOM node
qnameName to match
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_id()

css_error node_id ( void * pw,
void * node,
lwc_string ** id )
static

Callback to retrieve a node's ID.

Parameters
pwHTML document
nodeDOM node
idPointer to location to receive id value
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.
Todo
Assumes an HTML DOM

◆ node_is_active()

css_error node_is_active ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is currently activated.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.
Todo
Support active nodes

◆ node_is_checked()

css_error node_is_checked ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is checked.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match with contain true if the node is checked and false otherwise.
Todo
Support checked nodes

◆ node_is_disabled()

css_error node_is_disabled ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is disabled.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match with contain true if the node is disabled and false otherwise.
Todo
Support disabled nodes

◆ node_is_empty()

css_error node_is_empty ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is empty.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node is empty and false otherwise.

◆ node_is_enabled()

css_error node_is_enabled ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is enabled.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match with contain true if the node is enabled and false otherwise.
Todo
Support enabled nodes

◆ node_is_focus()

css_error node_is_focus ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node has the input focus.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.
Todo
Support focussed nodes

◆ node_is_hover()

css_error node_is_hover ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is currently being hovered over.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.
Todo
Support hovering

◆ node_is_lang()

css_error node_is_lang ( void * pw,
void * node,
lwc_string * lang,
bool * match )
static

Callback to determine if a node has the given language.

Parameters
pwHTML document
nodeDOM node
langLanguage specifier to match
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.
Todo
Support languages

◆ node_is_link()

css_error node_is_link ( void * pw,
void * n,
bool * match )
static

Callback to determine if a node is a linking element.

Parameters
pwHTML document
nDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_is_root()

css_error node_is_root ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is the root node of the document.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_is_target()

css_error node_is_target ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is the target of the document URL.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match with contain true if the node matches and false otherwise.
Todo
Support target

◆ node_is_visited()

css_error node_is_visited ( void * pw,
void * node,
bool * match )
static

Callback to determine if a node is a linking element whose target has been visited.

Parameters
pwHTML document
nodeDOM node
matchPointer to location to receive result
Returns
CSS_OK.
Postcondition
match will contain true if the node matches and false otherwise.

◆ node_name()

css_error node_name ( void * pw,
void * node,
css_qname * qname )
static

Callback to retrieve a node's name.

Parameters
pwHTML document
nodeDOM node
qnamePointer to location to receive node name
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion.

◆ node_presentational_hint()

css_error node_presentational_hint ( void * pw,
void * node,
uint32_t * nhints,
css_hint ** hints )
static

◆ nscss_create_inline_style()

css_stylesheet * nscss_create_inline_style ( const uint8_t * data,
size_t len,
const char * charset,
const char * url,
bool allow_quirks )

Create an inline style.

Parameters
dataSource data
lenLength of data in bytes
charsetCharset of data, or NULL if unknown
urlBase URL of document containing data
allow_quirksTrue to permit CSS parsing quirks
Returns
Pointer to stylesheet, or NULL on failure.

◆ nscss_dom_user_data_handler()

void nscss_dom_user_data_handler ( dom_node_operation operation,
dom_string * key,
void * data,
struct dom_node * src,
struct dom_node * dst )
static

◆ nscss_get_blank_style()

css_computed_style * nscss_get_blank_style ( nscss_select_ctx * ctx,
const css_unit_ctx * unit_len_ctx,
const css_computed_style * parent )

Get a blank style.

Parameters
ctxCSS selection context
parentParent style to cascade inherited properties from
Returns
Pointer to blank style, or NULL on failure

◆ nscss_get_style()

css_select_results * nscss_get_style ( nscss_select_ctx * ctx,
dom_node * n,
const css_media * media,
const css_unit_ctx * unit_len_ctx,
const css_stylesheet * inline_style )

Get style selection results for an element.

Parameters
ctxCSS selection context
nElement to select for
mediaPermitted media types
inline_styleInline style associated with element, or NULL
Returns
Pointer to selection results (containing computed styles), or NULL on failure

◆ parent_node()

css_error parent_node ( void * pw,
void * node,
void ** parent )
static

Callback to retrieve the parent of a node.

Parameters
pwHTML document
nodeDOM node
parentPointer to location to receive parent
Returns
CSS_OK.
Postcondition
parent will contain the result, or NULL if there is no match

◆ parse_css()

void parse_css ( struct html_context * html_context,
char * name )

◆ parse_css_common()

void parse_css_common ( struct html_context * html_context,
const char * text,
int length,
struct uri * uri )
static

◆ resolve_url()

css_error resolve_url ( void * pw,
const char * base,
lwc_string * rel,
lwc_string ** abs )

◆ resolve_url_empty()

css_error resolve_url_empty ( void * pw,
const char * base,
lwc_string * rel,
lwc_string ** abs )
static

◆ select_css()

void select_css ( struct html_context * html_context,
struct html_element * html_element )
Todo
Change nsoption font sizes to px.

f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72); f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);

ctx.root_style = root_style; ctx.parent_style = parent_style;

◆ set_libcss_node_data()

css_error set_libcss_node_data ( void * pw,
void * node,
void * libcss_node_data )
static

◆ sibling_node()

css_error sibling_node ( void * pw,
void * node,
void ** sibling )
static

Callback to retrieve the preceding sibling of a node.

Parameters
pwHTML document
nodeDOM node
siblingPointer to location to receive sibling
Returns
CSS_OK.
Postcondition
sibling will contain the result, or NULL if there is no match
Todo
Sort out reference counting

◆ ua_default_for_property()

css_error ua_default_for_property ( void * pw,
uint32_t property,
css_hint * hint )
static

Callback to retrieve the User-Agent defaults for a CSS property.

Parameters
pwHTML document
propertyProperty to retrieve defaults for
hintPointer to hint object to populate
Returns
CSS_OK on success, CSS_INVALID if the property should not have a user-agent default.
Todo
Fix this when we have voice-family done

Variable Documentation

◆ selection_handler

css_select_handler selection_handler
static

Selection callback table for libcss.