NetSurf
Functions | Variables
select.c File Reference
#include <assert.h>
#include <string.h>
#include <strings.h>
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "netsurf/plot_style.h"
#include "netsurf/url_db.h"
#include "desktop/system_colour.h"
#include "css/internal.h"
#include "css/hints.h"
#include "css/select.h"
Include dependency graph for select.c:

Go to the source code of this file.

Functions

static css_error node_name (void *pw, void *node, css_qname *qname)
 Callback to retrieve a node's name. More...
 
static css_error node_classes (void *pw, void *node, lwc_string ***classes, uint32_t *n_classes)
 Callback to retrieve a node's classes. More...
 
static css_error node_id (void *pw, void *node, lwc_string **id)
 Callback to retrieve a node's ID. More...
 
static css_error named_parent_node (void *pw, void *node, const css_qname *qname, void **parent)
 Callback to find a named parent node. More...
 
static css_error named_sibling_node (void *pw, void *node, const css_qname *qname, void **sibling)
 Callback to find a named sibling node. More...
 
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. More...
 
static css_error parent_node (void *pw, void *node, void **parent)
 Callback to retrieve the parent of a node. More...
 
static css_error sibling_node (void *pw, void *node, void **sibling)
 Callback to retrieve the preceding sibling of a node. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static css_error node_is_empty (void *pw, void *node, bool *match)
 Callback to determine if a node is empty. More...
 
static css_error node_is_link (void *pw, void *n, bool *match)
 Callback to determine if a node is a linking element. More...
 
static css_error node_is_hover (void *pw, void *node, bool *match)
 Callback to determine if a node is currently being hovered over. More...
 
static css_error node_is_active (void *pw, void *node, bool *match)
 Callback to determine if a node is currently activated. More...
 
static css_error node_is_focus (void *pw, void *node, bool *match)
 Callback to determine if a node has the input focus. More...
 
static css_error node_is_enabled (void *pw, void *node, bool *match)
 Callback to determine if a node is enabled. More...
 
static css_error node_is_disabled (void *pw, void *node, bool *match)
 Callback to determine if a node is disabled. More...
 
static css_error node_is_checked (void *pw, void *node, bool *match)
 Callback to determine if a node is checked. More...
 
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. More...
 
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. More...
 
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. More...
 
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)
 
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. More...
 
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. More...
 
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. More...
 
css_error named_ancestor_node (void *pw, void *node, const css_qname *qname, void **ancestor)
 Callback to find a named ancestor node. More...
 
static int node_count_siblings_check (dom_node *node, bool check_name, dom_string *name)
 
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. More...
 

Variables

static css_select_handler selection_handler
 Selection callback table for libcss. More...
 

Function Documentation

◆ get_libcss_node_data()

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

Definition at line 1752 of file select.c.

◆ named_ancestor_node()

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

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

Definition at line 471 of file select.c.

Referenced by css_hint_anchor_color(), and css_hint_table_cell_border_padding().

Here is the caller graph for this function:

◆ 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

Definition at line 581 of file select.c.

References type.

◆ 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

Definition at line 492 of file select.c.

References parent.

◆ 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

Definition at line 513 of file select.c.

References type.

◆ 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.

Definition at line 410 of file select.c.

◆ 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

Definition at line 1319 of file select.c.

References count(), node_count_siblings_check(), and node_name().

Here is the call graph for this function:

◆ node_count_siblings_check()

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

Definition at line 1272 of file select.c.

References node_name(), and type.

Referenced by node_count_siblings().

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

◆ 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.

Definition at line 814 of file select.c.

◆ 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.

Definition at line 903 of file select.c.

◆ 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.

Definition at line 851 of file select.c.

◆ 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.

Definition at line 968 of file select.c.

◆ 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.

Definition at line 1039 of file select.c.

◆ 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.

Definition at line 1171 of file select.c.

◆ 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.

Definition at line 1103 of file select.c.

◆ 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

Definition at line 753 of file select.c.

◆ 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

Definition at line 779 of file select.c.

◆ 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.

Definition at line 718 of file select.c.

References nscss_select_ctx::universal.

◆ 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

Definition at line 435 of file select.c.

◆ 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

Definition at line 1559 of file select.c.

◆ 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

Definition at line 1635 of file select.c.

◆ 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

Definition at line 1616 of file select.c.

◆ 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.

Definition at line 1383 of file select.c.

◆ 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

Definition at line 1597 of file select.c.

◆ 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

Definition at line 1578 of file select.c.

◆ 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

Definition at line 1540 of file select.c.

◆ 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

Definition at line 1674 of file select.c.

◆ 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.

Definition at line 1432 of file select.c.

References node_name().

Here is the call graph for this function:

◆ 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.

Definition at line 1240 of file select.c.

References parent, and type.

◆ 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

Definition at line 1654 of file select.c.

◆ node_is_visited()

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.

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.

Definition at line 1471 of file select.c.

References nscss_select_ctx::base_url, NSERROR_OK, nsurl_join(), nsurl_unref(), urldb_get_url_data(), and url_data::visits.

Referenced by css_hint_anchor_color().

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

◆ 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.

Definition at line 373 of file select.c.

Referenced by dump_dom_element(), html_begin_conversion(), libdom_find_first_element(), node_count_siblings(), node_count_siblings_check(), node_is_link(), save_complete_handle_attr(), save_complete_handle_attr_value(), and save_complete_handle_attrs().

Here is the caller graph for this function:

◆ 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.

Definition at line 148 of file select.c.

References ns_system_colour(), nscss_resolve_url(), and NSLOG.

Referenced by box_get_style().

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

◆ nscss_dom_user_data_handler()

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

Definition at line 195 of file select.c.

References NSLOG, and selection_handler.

Referenced by set_libcss_node_data().

Here is the caller graph for this function:

◆ 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
unit_unit_len_ctxUnit length conversion context
parentParent style to cascade inherited properties from
Returns
Pointer to blank style, or NULL on failure

Definition at line 334 of file select.c.

References nscss_select_ctx::ctx, parent, and selection_handler.

Referenced by box_normalise_block(), box_normalise_flex(), box_normalise_table(), box_normalise_table_row(), box_normalise_table_row_group(), and box_normalise_table_spans().

Here is the caller graph for this function:

◆ 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
unit_unit_len_ctxUnit length conversion context
inline_styleInline style associated with element, or NULL
Returns
Pointer to selection results (containing computed styles), or NULL on failure

Definition at line 253 of file select.c.

References nscss_select_ctx::ctx, nscss_select_ctx::parent_style, and selection_handler.

Referenced by box_get_style().

Here is the caller graph for this function:

◆ 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

Definition at line 644 of file select.c.

References parent.

Referenced by box_extract_properties().

Here is the caller graph for this function:

◆ set_libcss_node_data()

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

Definition at line 1732 of file select.c.

References nscss_dom_user_data_handler().

Here is the call graph for this function:

◆ 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

Definition at line 662 of file select.c.

References type.

◆ 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:
Not exactly useful :)
Todo:
Fix this when we have voice-family done

Definition at line 1693 of file select.c.

References nsoption_int, PLOT_FONT_FAMILY_CURSIVE, PLOT_FONT_FAMILY_FANTASY, PLOT_FONT_FAMILY_MONOSPACE, PLOT_FONT_FAMILY_SANS_SERIF, and PLOT_FONT_FAMILY_SERIF.

Variable Documentation

◆ selection_handler

css_select_handler selection_handler
static

Selection callback table for libcss.

Definition at line 97 of file select.c.

Referenced by nscss_dom_user_data_handler(), nscss_get_blank_style(), and nscss_get_style().