NetSurf
Data Structures | Macros | Functions | Variables
hints.c File Reference
#include <string.h>
#include <strings.h>
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "utils/utils.h"
#include "css/hints.h"
#include "css/select.h"
Include dependency graph for hints.c:

Go to the source code of this file.

Data Structures

struct  colour_map
 Mapping of colour name to CSS color. More...
 
struct  css_hint_ctx
 

Macros

#define LOG_STATS
 
#define MAX_HINTS_PER_ELEMENT   32
 

Functions

static bool isWhitespace (char c)
 Determine if a given character is whitespace. More...
 
static bool isHex (char c)
 Determine if a given character is a valid hex digit. More...
 
static uint8_t charToHex (char c)
 Convert a character representing a hex digit to the corresponding hex value. More...
 
static bool parse_number (const char *data, bool maybe_negative, bool real, css_fixed *value, size_t *consumed)
 Parse a number string. More...
 
static bool parse_dimension (const char *data, bool strict, css_fixed *length, css_unit *unit)
 Parse a dimension string. More...
 
static int cmp_colour_name (const void *a, const void *b)
 Name comparator for named colour matching. More...
 
static bool parse_named_colour (const char *name, css_color *result)
 Parse a named colour. More...
 
bool nscss_parse_colour (const char *data, css_color *result)
 Parser for colours specified in attribute values. More...
 
static bool parse_font_size (const char *size, uint8_t *val, css_fixed *len, css_unit *unit)
 Parse a font @size attribute. More...
 
nserror css_hint_init (void)
 
void css_hint_fini (void)
 
static void css_hint_clean (void)
 
static void css_hint_advance (struct css_hint **hint)
 
static void css_hint_get_hints (struct css_hint **hints, uint32_t *nhints)
 
static void css_hint_table_cell_border_padding (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_vertical_align_table_cells (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_vertical_align_replaced (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_text_align_normal (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_text_align_center (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_margin_left_right_align_center (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_text_align_special (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_text_align_table_special (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_margin_hspace_vspace (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_margin_left_right_hr (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_table_spacing_border (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_height (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_width (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_height_width_textarea (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_height_width_canvas (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_width_input (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_anchor_color (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_body_color (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_color (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_font_size (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_float (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_caption_side (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_bg_color (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_bg_image (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_white_space_nowrap (nscss_select_ctx *ctx, dom_node *node)
 
static void css_hint_list (nscss_select_ctx *ctx, dom_node *node)
 
css_error node_presentational_hint (void *pw, void *node, uint32_t *nhints, css_hint **hints)
 Callback to retrieve presentational hints for a node. More...
 

Variables

struct css_hint_ctx hint_ctx
 

Macro Definition Documentation

◆ LOG_STATS

#define LOG_STATS

Definition at line 31 of file hints.c.

◆ MAX_HINTS_PER_ELEMENT

#define MAX_HINTS_PER_ELEMENT   32

Definition at line 579 of file hints.c.

Function Documentation

◆ charToHex()

static uint8_t charToHex ( char  c)
static

Convert a character representing a hex digit to the corresponding hex value.

Parameters
cCharacter to convert
Returns
Hex value represented by character
Note
This function assumes an ASCII-compatible character set

Definition at line 69 of file hints.c.

Referenced by nscss_parse_colour().

Here is the caller graph for this function:

◆ cmp_colour_name()

static int cmp_colour_name ( const void *  a,
const void *  b 
)
static

Name comparator for named colour matching.

Parameters
aName to match
bColour map entry to consider
Returns
0 on match, < 0 if a < b, > 0 if b > a.

Definition at line 266 of file hints.c.

References colour_map::name.

Referenced by parse_named_colour().

Here is the caller graph for this function:

◆ css_hint_advance()

static void css_hint_advance ( struct css_hint **  hint)
inlinestatic

◆ css_hint_anchor_color()

static void css_hint_anchor_color ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1348 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, named_ancestor_node(), node_is_visited(), and nscss_parse_colour().

Referenced by node_presentational_hint().

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

◆ css_hint_bg_color()

static void css_hint_bg_color ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1512 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and nscss_parse_colour().

Referenced by node_presentational_hint().

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

◆ css_hint_bg_image()

static void css_hint_bg_image ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1534 of file hints.c.

References nscss_select_ctx::base_url, css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, NSERROR_OK, nsurl_access(), nsurl_join(), nsurl_length(), and nsurl_unref().

Referenced by node_presentational_hint().

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

◆ css_hint_body_color()

static void css_hint_body_color ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1400 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and nscss_parse_colour().

Referenced by node_presentational_hint().

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

◆ css_hint_caption_side()

static void css_hint_caption_side ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1492 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_clean()

static void css_hint_clean ( void  )
static

Definition at line 605 of file hints.c.

References hint_ctx, and css_hint_ctx::len.

Referenced by node_presentational_hint().

Here is the caller graph for this function:

◆ css_hint_color()

static void css_hint_color ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1422 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and nscss_parse_colour().

Referenced by node_presentational_hint().

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

◆ css_hint_fini()

void css_hint_fini ( void  )

Definition at line 599 of file hints.c.

References hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by nscss_fini().

Here is the caller graph for this function:

◆ css_hint_float()

static void css_hint_float ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1466 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_font_size()

static void css_hint_font_size ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1444 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_font_size().

Referenced by node_presentational_hint().

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

◆ css_hint_get_hints()

static void css_hint_get_hints ( struct css_hint **  hints,
uint32_t *  nhints 
)
static

Definition at line 618 of file hints.c.

References hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

Here is the caller graph for this function:

◆ css_hint_height()

static void css_hint_height ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1147 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_height_width_canvas()

static void css_hint_height_width_canvas ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1236 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_height_width_textarea()

static void css_hint_height_width_textarea ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1195 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_init()

nserror css_hint_init ( void  )

Definition at line 588 of file hints.c.

References hint_ctx, css_hint_ctx::hints, MAX_HINTS_PER_ELEMENT, NSERROR_NOMEM, and NSERROR_OK.

Referenced by nscss_init().

Here is the caller graph for this function:

◆ css_hint_list()

static void css_hint_list ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1582 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and type.

Referenced by node_presentational_hint().

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

◆ css_hint_margin_hspace_vspace()

static void css_hint_margin_hspace_vspace ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 959 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_margin_left_right_align_center()

static void css_hint_margin_left_right_align_center ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 875 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_margin_left_right_hr()

static void css_hint_margin_left_right_hr ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1016 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_table_cell_border_padding()

static void css_hint_table_cell_border_padding ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 629 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, named_ancestor_node(), nscss_parse_colour(), and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_table_spacing_border()

static void css_hint_table_spacing_border ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1067 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, nscss_parse_colour(), and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_text_align_center()

static void css_hint_text_align_center ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 864 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_text_align_normal()

static void css_hint_text_align_normal ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 825 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_text_align_special()

static void css_hint_text_align_special ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 908 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_text_align_table_special()

static void css_hint_text_align_table_special ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 948 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_vertical_align_replaced()

static void css_hint_vertical_align_replaced ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 781 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_vertical_align_table_cells()

static void css_hint_vertical_align_table_cells ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 739 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_white_space_nowrap()

static void css_hint_white_space_nowrap ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1566 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, and css_hint_ctx::len.

Referenced by node_presentational_hint().

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

◆ css_hint_width()

static void css_hint_width ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1171 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_dimension().

Referenced by node_presentational_hint().

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

◆ css_hint_width_input()

static void css_hint_width_input ( nscss_select_ctx ctx,
dom_node *  node 
)
static

Definition at line 1298 of file hints.c.

References css_hint_advance(), hint_ctx, css_hint_ctx::hints, css_hint_ctx::len, and parse_dimension().

Referenced by node_presentational_hint().

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

◆ isHex()

static bool isHex ( char  c)
static

Determine if a given character is a valid hex digit.

Parameters
cCharacter to consider
Returns
true if character is a valid hex digit, false otherwise

Definition at line 55 of file hints.c.

Referenced by nscss_parse_colour().

Here is the caller graph for this function:

◆ isWhitespace()

static bool isWhitespace ( char  c)
static

Determine if a given character is whitespace.

Parameters
cCharacter to consider
Returns
true if character is whitespace, false otherwise

Definition at line 44 of file hints.c.

Referenced by parse_font_size(), and parse_number().

Here is the caller graph for this function:

◆ node_presentational_hint()

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

Callback to retrieve presentational hints for a node.

Parameters
[in]pwHTML document
[in]nodeDOM node
[out]nhintsnumber of hints retrieved
[out]hintsretrieved hints
Returns
CSS_OK on success, CSS_PROPERTY_NOT_SET if there is no hint for the requested property, CSS_NOMEM on memory exhaustion.

Definition at line 1628 of file hints.c.

References css_hint_anchor_color(), css_hint_bg_color(), css_hint_bg_image(), css_hint_body_color(), css_hint_caption_side(), css_hint_clean(), css_hint_color(), css_hint_float(), css_hint_font_size(), css_hint_get_hints(), css_hint_height(), css_hint_height_width_canvas(), css_hint_height_width_textarea(), css_hint_list(), css_hint_margin_hspace_vspace(), css_hint_margin_left_right_align_center(), css_hint_margin_left_right_hr(), css_hint_table_cell_border_padding(), css_hint_table_spacing_border(), css_hint_text_align_center(), css_hint_text_align_normal(), css_hint_text_align_special(), css_hint_text_align_table_special(), css_hint_vertical_align_replaced(), css_hint_vertical_align_table_cells(), css_hint_white_space_nowrap(), css_hint_width(), css_hint_width_input(), fallthrough, hint_ctx, css_hint_ctx::len, NSLOG, and nsoption_bool.

Here is the call graph for this function:

◆ nscss_parse_colour()

bool nscss_parse_colour ( const char *  data,
css_color *  result 
)

Parser for colours specified in attribute values.

Parameters
dataData to parse (NUL-terminated)
resultPointer to location to receive resulting css_color
Returns
true on success, false on invalid input
Todo:
Implement HTML5's utterly insane legacy colour parsing

Definition at line 449 of file hints.c.

References charToHex(), isHex(), parse_named_colour(), result, and SLEN.

Referenced by box_create_frameset(), box_iframe(), css_hint_anchor_color(), css_hint_bg_color(), css_hint_body_color(), css_hint_color(), css_hint_table_cell_border_padding(), and css_hint_table_spacing_border().

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

◆ parse_dimension()

static bool parse_dimension ( const char *  data,
bool  strict,
css_fixed *  length,
css_unit *  unit 
)
static

Parse a dimension string.

Parameters
dataData to parse (NUL-terminated)
strictWhether to enforce strict parsing rules
lengthPointer to location to receive dimension's length
unitPointer to location to receive dimension's unit
Returns
true on success, false on invalid input

Definition at line 224 of file hints.c.

References parse_number().

Referenced by css_hint_height(), css_hint_height_width_canvas(), css_hint_height_width_textarea(), css_hint_margin_hspace_vspace(), css_hint_table_cell_border_padding(), css_hint_table_spacing_border(), css_hint_width(), and css_hint_width_input().

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

◆ parse_font_size()

static bool parse_font_size ( const char *  size,
uint8_t *  val,
css_fixed *  len,
css_unit *  unit 
)
static

Parse a font @size attribute.

Parameters
sizeData to parse (NUL-terminated)
valPointer to location to receive enum value
lenPointer to location to receive length
unitPointer to location to receive unit
Returns
True on success, false on failure

Definition at line 509 of file hints.c.

References isWhitespace(), mode, and nsoption_int.

Referenced by css_hint_font_size().

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

◆ parse_named_colour()

static bool parse_named_colour ( const char *  name,
css_color *  result 
)
static

Parse a named colour.

Parameters
nameName to parse
resultPointer to location to receive css_color
Returns
true on success, false on invalid input

Definition at line 281 of file hints.c.

References cmp_colour_name(), colour_map::color, colour_map::name, and result.

Referenced by nscss_parse_colour().

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

◆ parse_number()

static bool parse_number ( const char *  data,
bool  maybe_negative,
bool  real,
css_fixed *  value,
size_t *  consumed 
)
static

Parse a number string.

Parameters
dataData to parse (NUL-terminated)
maybe_negativeNegative numbers permitted
realFloating point numbers permitted
valuePointer to location to receive numeric value
consumedPointer to location to receive number of input bytes consumed
Returns
true on success, false on invalid input

Definition at line 101 of file hints.c.

References isWhitespace().

Referenced by parse_dimension().

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

Variable Documentation

◆ hint_ctx

struct css_hint_ctx hint_ctx