ELinks 0.18.0
apply.c File Reference

CSS style applier. More...

#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "document/css/apply.h"
#include "document/css/css.h"
#include "document/css/parser.h"
#include "document/css/property.h"
#include "document/css/scanner.h"
#include "document/css/stylesheet.h"
#include "document/format.h"
#include "document/html/parser/parse.h"
#include "document/options.h"
#include "util/align.h"
#include "util/color.h"
#include "util/lists.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
#include "document/html/internal.h"
Include dependency graph for apply.c:

Macros

#define dbginfo(sel, type, base)
#define process_found_selector(sel, type, base)

Typedefs

typedef void(* css_applier_T) (struct html_context *html_context, struct html_element *element, struct css_property *prop)

Functions

static void css_apply_color (struct html_context *html_context, struct html_element *element, struct css_property *prop)
static void css_apply_background_color (struct html_context *html_context, struct html_element *element, struct css_property *prop)
static void css_apply_display (struct html_context *html_context, struct html_element *element, struct css_property *prop)
static void css_apply_font_attribute (struct html_context *html_context, struct html_element *element, struct css_property *prop)
static void css_apply_list_style (struct html_context *html_context, struct html_element *element, struct css_property *prop)
static void css_apply_text_align (struct html_context *html_context, struct html_element *element, struct css_property *prop)
static void examine_element (struct html_context *html_context, struct css_selector *base, css_selector_type_T seltype, enum css_selector_relation rel, struct css_selector_set *selectors, struct html_element *element)
 This looks for a match in list of selectors.
struct css_selectorget_css_selector_for_element (struct html_context *html_context, struct html_element *element, struct css_stylesheet *css, struct html_element list *html_stack)
 Gather all style information for the given element, so it can later be applied.
void apply_css_selector_style (struct html_context *html_context, struct html_element *element, struct css_selector *selector)
 Apply properties from an existing selector.
void css_apply (struct html_context *html_context, struct html_element *element, struct css_stylesheet *css, struct html_element list *html_stack)
 This function takes element and applies its 'style' attribute onto its attributes (if it contains such an attribute).

Variables

static const css_applier_T css_appliers [CSS_PT_LAST]

Detailed Description

CSS style applier.

Todo
TODO: A way to disable CSS completely, PLUS a way to stop various property groups from taking effect. (Ie. way to turn out effect of 'display: none' or aligning or colors but keeping all the others.) –pasky

Macro Definition Documentation

◆ dbginfo

#define dbginfo ( sel,
type,
base )

◆ process_found_selector

#define process_found_selector ( sel,
type,
base )
Value:
if (selector) { \
dbginfo(sel, type, base); \
merge_css_selectors(base, sel); \
/* Ancestor matches? */ \
if (sel->leaves.may_contain_rel_ancestor_or_parent \
&& (LIST_OF(struct html_element) *) element->next \
!= &html_context->stack) { \
struct html_element *ancestor; \
/* This is less effective than doing reverse iterations,
* first over sel->leaves and then over the HTML stack,
* which shines in the most common case where there are
* no CSR_ANCESTOR selector leaves. However we would
* have to duplicate the whole examine_element(), so if
* profiles won't show it really costs... */ \
for (ancestor = element->next; \
(LIST_OF(struct html_element) *) ancestor \
ancestor = ancestor->next) \
examine_element(html_context, base, \
&sel->leaves, ancestor); \
examine_element(html_context, base, \
&sel->leaves, element->next); \
} \
/* More specific matches? */ \
examine_element(html_context, base, type + 1, \
&sel->leaves, element); \
}
#define LIST_OF(element_T)
A list intended to contain elements of a specific type.
Definition lists.h:127
const char * type
Definition download.c:1899
Definition internal.h:69
struct html_element list stack
Definition internal.h:96
Definition parser.h:147
@ CSR_SPECIFITY
Narrowing-down, i.e.
Definition stylesheet.h:73
@ CSR_ANCESTOR
Ancestor, i.e.
Definition stylesheet.h:74
@ CSR_PARENT
Direct parent, i.e.
Definition stylesheet.h:75
@ CST_ELEMENT
Definition stylesheet.h:79

Typedef Documentation

◆ css_applier_T

typedef void(* css_applier_T) (struct html_context *html_context, struct html_element *element, struct css_property *prop)

Function Documentation

◆ apply_css_selector_style()

void apply_css_selector_style ( struct html_context * html_context,
struct html_element * element,
struct css_selector * selector )

Apply properties from an existing selector.

◆ css_apply()

void css_apply ( struct html_context * html_context,
struct html_element * element,
struct css_stylesheet * css,
struct html_element list * html_stack )

This function takes element and applies its 'style' attribute onto its attributes (if it contains such an attribute).

◆ css_apply_background_color()

void css_apply_background_color ( struct html_context * html_context,
struct html_element * element,
struct css_property * prop )
static

◆ css_apply_color()

void css_apply_color ( struct html_context * html_context,
struct html_element * element,
struct css_property * prop )
static

◆ css_apply_display()

void css_apply_display ( struct html_context * html_context,
struct html_element * element,
struct css_property * prop )
static

◆ css_apply_font_attribute()

void css_apply_font_attribute ( struct html_context * html_context,
struct html_element * element,
struct css_property * prop )
static

◆ css_apply_list_style()

void css_apply_list_style ( struct html_context * html_context,
struct html_element * element,
struct css_property * prop )
static

◆ css_apply_text_align()

void css_apply_text_align ( struct html_context * html_context,
struct html_element * element,
struct css_property * prop )
static
Bug
FIXME: Because the current CSS doesn't provide reasonable defaults for each HTML element this applier will cause bad rendering of <pre> tags.

◆ examine_element()

void examine_element ( struct html_context * html_context,
struct css_selector * base,
css_selector_type_T seltype,
enum css_selector_relation rel,
struct css_selector_set * selectors,
struct html_element * element )
static

This looks for a match in list of selectors.

◆ get_css_selector_for_element()

struct css_selector * get_css_selector_for_element ( struct html_context * html_context,
struct html_element * element,
struct css_stylesheet * css,
struct html_element list * html_stack )

Gather all style information for the given element, so it can later be applied.

Returned value should be freed using done_css_selector().

Variable Documentation

◆ css_appliers

const css_applier_T css_appliers[CSS_PT_LAST]
static
Initial value:
= {
}
static void css_apply_list_style(struct html_context *html_context, struct html_element *element, struct css_property *prop)
Definition apply.c:99
static void css_apply_font_attribute(struct html_context *html_context, struct html_element *element, struct css_property *prop)
Definition apply.c:90
static void css_apply_background_color(struct html_context *html_context, struct html_element *element, struct css_property *prop)
Definition apply.c:53
static void css_apply_color(struct html_context *html_context, struct html_element *element, struct css_property *prop)
Definition apply.c:43
static void css_apply_text_align(struct html_context *html_context, struct html_element *element, struct css_property *prop)
Definition apply.c:135
static void css_apply_display(struct html_context *html_context, struct html_element *element, struct css_property *prop)
Definition apply.c:64
#define NULL
Definition explodename.c:35

XXX: Sort like the css_property_type