32#define MSG_CSS(A, ...) do {} while(0)
33#define DEBUG_TOKEN_LEVEL 0
34#define DEBUG_PARSE_LEVEL 0
35#define DEBUG_CREATE_LEVEL 0
40#define CSS_NUM_INTERNAL_PROPERTIES 3
41#define CSS_NUM_PARSED_PROPERTIES \
42 (CSS_PROPERTY_LAST - CSS_NUM_INTERNAL_PROPERTIES)
48 const char *
const *enum_symbols;
52 "scroll",
"fixed", NULL
56 "repeat",
"repeat-x",
"repeat-y",
"no-repeat", NULL
60 "separate",
"collapse", NULL
68 "none",
"hidden",
"dotted",
"dashed",
"solid",
"double",
"groove",
69 "ridge",
"inset",
"outset", NULL
73 "thin",
"medium",
"thick", NULL
77 "left",
"right",
"both",
"none", NULL
81 "crosshair",
"default",
"pointer",
"move",
"e-resize",
"ne-resize",
82 "nw-resize",
"n-resize",
"se-resize",
"sw-resize",
"s-resize",
83 "w-resize",
"text",
"wait",
"help", NULL
87 "block",
"inline",
"inline-block",
"list-item",
"none",
"table",
88 "table-row-group",
"table-header-group",
"table-footer-group",
"table-row",
93 "none",
"left",
"right", NULL
97 "large",
"larger",
"medium",
"small",
"smaller",
"xx-large",
"xx-small",
98 "x-large",
"x-small", NULL
102 "normal",
"italic",
"oblique", NULL
106 "normal",
"small-caps", NULL
110 "bold",
"bolder",
"light",
"lighter",
"normal", NULL
118 "inside",
"outside", NULL
126 "disc",
"circle",
"square",
"decimal",
"decimal-leading-zero",
127 "lower-roman",
"upper-roman",
"lower-greek",
"lower-alpha",
128 "lower-latin",
"upper-alpha",
"upper-latin",
"hebrew",
"armenian",
129 "georgian",
"cjk-ideographic",
"hiragana",
"katakana",
"hiragana-iroha",
130 "katakana-iroha",
"none", NULL
134 "visible",
"hidden",
"scroll",
"auto", NULL
138 "static",
"relative",
"absolute",
"fixed", NULL
142 "left",
"right",
"center",
"justify",
"string", NULL
146 "underline",
"overline",
"line-through",
"blink", NULL
150 "none",
"capitalize",
"uppercase",
"lowercase", NULL
154 "top",
"bottom",
"middle",
"baseline",
"sub",
"super",
"text-top",
159 "normal",
"pre",
"nowrap",
"pre-wrap",
"pre-line", NULL
293 CSS_SHORTHAND_MULTIPLE,
295 CSS_SHORTHAND_DIRECTIONS,
296 CSS_SHORTHAND_BORDER,
421 {
"background", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
423 {
"border", CssShorthandInfo::CSS_SHORTHAND_BORDER,
425 {
"border-bottom", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
427 {
"border-color", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
429 {
"border-left", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
431 {
"border-right", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
433 {
"border-style", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
435 {
"border-top", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
437 {
"border-width", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
439 {
"font", CssShorthandInfo::CSS_SHORTHAND_FONT,
441 {
"list-style", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
443 {
"margin", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
445 {
"outline", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
447 {
"padding", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
451#define CSS_SHORTHAND_NUM \
452 (sizeof(Css_shorthand_info) / sizeof(Css_shorthand_info[0]))
460 const char *buf,
int buflen)
508 for (
int n = 0; str[n]; n++) {
561 }
while (isdigit(c));
579 }
while (isdigit(c));
607 if (isalpha(c) || c ==
'_' || c ==
'-') {
613 while (isalnum(c) || c ==
'_' || c ==
'-') {
626 if (c ==
'"' || c ==
'\'') {
633 while (c != EOF && c != c1) {
642 while (j < 4 && isxdigit(d)) {
649 c = strtol(hexbuf, NULL, 16);
677 while (isxdigit(c)) {
784 i = strtol(
tval, NULL, 10);
785 if (i >= 100 && i <= 900)
815 MSG_CSS(
"expected integer not found in %s color\n",
"rgb");
819 *cc = strtol(
tval, NULL, 10);
823 if (*percentage == 0) {
824 MSG_CSS(
"'%s' unexpected in rgb color\n",
"%");
828 *cc = *cc * 255 / 100;
831 if (*percentage == 1) {
832 MSG_CSS(
"expected '%s' not found in rgb color\n",
"%");
853 MSG_CSS(
"expected '%s' not found in rgb color\n",
"(");
863 MSG_CSS(
"expected '%s' not found in rgb color\n",
",");
873 MSG_CSS(
"expected '%s' not found in rgb color\n",
",");
883 MSG_CSS(
"expected '%s' not found in rgb color\n",
")");
895 bool found, ret =
false;
897 int i, ival, err = 1;
920 for (i = 0, found =
false;
1025 MSG_CSS(
"color is not in \"%s\" format\n",
"#RRGGBB");
1035 MSG_CSS(
"Failed to parse %s color\n",
"rgb(r,g,b)");
1039 MSG_CSS(
"color is not in \"%s\" format\n",
"#RRGGBB");
1078 ival = strtol(
tval, NULL, 10);
1079 if (ival < 100 || ival > 900)
1114 h[0] = v[0] = h[1] = v[1] =
false;
1119 for (i = 0; i < 2; i++) {
1133 h[i] = v[i] =
false;
1163 h[i] = v[i] =
false;
1176 if (!h[1] && !v[1]) {
1182 if ((h[0] && v[1]) || (v[0] && h[1])) {
1238 ((CssPropertyInfo *) b)->symbol);
1248 ((CssShorthandInfo *) b)->symbol);
1255 CssShorthandInfo *sip;
1262 int sh_index, i, j, n;
1263 int dir_set[4][4] = {
1275 sizeof(CssPropertyInfo),
1285 if (weight && importantProps)
1286 importantProps->
set(prop, type, val);
1288 props->
set(prop, type, val);
1296 sizeof(CssShorthandInfo),
1306 case CssShorthandInfo::CSS_SHORTHAND_FONT:
1308 case CssShorthandInfo::CSS_SHORTHAND_MULTIPLE:
1310 for (found =
false, i = 0;
1316 properties[i], &type)) {
1319 "will assign to '%s'\n",
1322 .properties[i]].symbol);
1324 .properties[i], type, &val)) {
1326 if (weight && importantProps)
1329 properties[i], type, val);
1332 properties[i], type, val);
1338 case CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS:
1342 properties[0], &type) &&
1344 .properties[0], type, &val)) {
1346 dir_types[n] = type;
1354 for (i = 0; i < 4; i++)
1355 if (weight && importantProps)
1358 dir_types[dir_set[n - 1][i]],
1359 dir_vals[dir_set[n - 1][i]]);
1363 dir_types[dir_set[n - 1][i]],
1364 dir_vals[dir_set[n - 1][i]]);
1366 MSG_CSS(
"no values for shorthand property '%s'\n",
1371 case CssShorthandInfo::CSS_SHORTHAND_BORDER:
1373 for (found =
false, i = 0;
1377 properties[i], &type)) {
1380 .properties[i], type, &val)) {
1382 for (j = 0; j < 4; j++)
1383 if (weight && importantProps)
1386 properties[j * 3 + i], type, val);
1389 properties[j * 3 + i], type, val);
1403 (
tval[0] ==
';' ||
tval[0] ==
'}'))))
1473 selector->
id, selector->
klass,
1491 (
tval[0] ==
',' ||
tval[0] ==
'{')) {
1510 (
tval[0] !=
',' &&
tval[0] !=
'{')))
1518 lout::misc::SimpleVector < CssSelector * >*list;
1522 list =
new lout::misc::SimpleVector < CssSelector * >(1);
1530 list->
set(list->
size() - 1, selector);
1550 importantProps->
ref();
1563 for (
int i = 0; i < list->
size(); i++) {
1580 importantProps->
unref();
1590 Dstr *urlStr = NULL;
1633 char *urlStr = NULL;
1634 bool importSyntaxIsOK =
false;
1635 bool mediaSyntaxIsOK =
true;
1636 bool mediaIsSelected =
true;
1650 mediaSyntaxIsOK =
false;
1651 mediaIsSelected =
false;
1655 mediaIsSelected =
true;
1660 mediaSyntaxIsOK =
true;
1666 if (mediaSyntaxIsOK &&
1669 importSyntaxIsOK =
true;
1675 if (importSyntaxIsOK && mediaIsSelected) {
1676 MSG(
"CssParser::parseImport(): @import %s\n", urlStr);
1688 bool mediaSyntaxIsOK =
false;
1689 bool mediaIsSelected =
false;
1697 mediaIsSelected =
true;
1702 mediaSyntaxIsOK =
true;
1708 if (!(mediaSyntaxIsOK &&
1716 if (mediaIsSelected) {
1740 if (
tval[0] ==
'{') {
1742 }
else if (
tval[0] ==
'}') {
1758 if (
tval[0] ==
';') {
1761 }
else if (
tval[0] ==
'{') {
1776 bool importsAreAllowed =
true;
1780 parser.
tval[0] ==
'@') {
1785 importsAreAllowed) {
1796 importsAreAllowed =
false;
1803 const char *buf,
int buflen,
void addRule(CssSelector *sel, CssPropertyList *props, CssPrimaryOrder order)
bool parseValue(CssPropertyName prop, CssValueType type, CssPropertyValue *val)
bool skipString(int c, const char *string)
Skip string str if it is found in the input buffer.
bool tokenMatchesProperty(CssPropertyName prop, CssValueType *type)
bool parseSimpleSelector(CssSimpleSelector *selector)
bool parseRgbColorComponent(int32_t *cc, int *percentage)
void parseDeclaration(CssPropertyList *props, CssPropertyList *importantProps)
static void parseDeclarationBlock(const DilloUrl *baseUrl, const char *buf, int buflen, CssPropertyList *props, CssPropertyList *propsImortant)
void parseImport(DilloHtml *html)
bool parseRgbColor(int32_t *c)
static const int maxStrLen
void ungetChar()
Undoes the last getChar().
static void parse(DilloHtml *html, const DilloUrl *baseUrl, CssContext *context, const char *buf, int buflen, CssOrigin origin)
int getChar()
Gets the next character from the buffer, or EOF.
static const char * propertyNameString(CssPropertyName name)
CssSelector * parseSelector()
CssParser(CssContext *context, CssOrigin origin, const DilloUrl *baseUrl, const char *buf, int buflen)
A list of CssProperty objects.
void set(CssPropertyName name, CssValueType type, CssPropertyValue value)
Set property to a given name and type.
CssSimpleSelector * top()
void addSimpleSelector(Combinator c)
const char * getPseudoClass()
void setSelect(SelectType t, const char *v)
lout::misc::SimpleVector< char * > klass
void increase()
Increase the vector size by one.
void set(int i, T t)
Store an object in the vector.
T get(int i) const
Return the one element, explicitly.
int size() const
Return the number of elements put into this vector.
int32_t a_Color_parse(const char *str, int32_t default_color, int *err)
Parse a color string.
@ CSS_PROPERTY_PADDING_TOP
@ CSS_PROPERTY_LIST_STYLE_TYPE
@ CSS_PROPERTY_MARGIN_BOTTOM
@ CSS_PROPERTY_BORDER_RIGHT_STYLE
@ CSS_PROPERTY_BORDER_BOTTOM_COLOR
@ CSS_PROPERTY_MARGIN_RIGHT
@ CSS_PROPERTY_BORDER_TOP_COLOR
@ CSS_PROPERTY_BORDER_LEFT_COLOR
@ CSS_PROPERTY_LIST_STYLE_POSITION
@ CSS_PROPERTY_BORDER_RIGHT_WIDTH
@ CSS_PROPERTY_BACKGROUND_REPEAT
@ CSS_PROPERTY_FONT_VARIANT
@ CSS_PROPERTY_BORDER_LEFT_WIDTH
@ CSS_PROPERTY_PADDING_BOTTOM
@ CSS_PROPERTY_BACKGROUND_ATTACHMENT
@ CSS_PROPERTY_OUTLINE_STYLE
@ CSS_PROPERTY_OUTLINE_WIDTH
@ CSS_PROPERTY_LIST_STYLE_IMAGE
@ CSS_PROPERTY_MARGIN_LEFT
@ CSS_PROPERTY_BORDER_RIGHT_COLOR
@ CSS_PROPERTY_OUTLINE_COLOR
@ CSS_PROPERTY_BORDER_TOP_WIDTH
@ CSS_PROPERTY_MARGIN_TOP
@ CSS_PROPERTY_PADDING_RIGHT
@ CSS_PROPERTY_PADDING_LEFT
@ CSS_PROPERTY_BORDER_LEFT_STYLE
@ CSS_PROPERTY_BACKGROUND_IMAGE
@ CSS_PROPERTY_BORDER_TOP_STYLE
@ CSS_PROPERTY_FONT_STYLE
@ CSS_PROPERTY_BACKGROUND_COLOR
@ CSS_PROPERTY_BORDER_BOTTOM_STYLE
@ CSS_PROPERTY_BORDER_BOTTOM_WIDTH
@ CSS_PROPERTY_BACKGROUND_POSITION
@ CSS_PROPERTY_FONT_FAMILY
@ CSS_PROPERTY_FONT_WEIGHT
@ CSS_TYPE_UNUSED
Not yet used.
@ CSS_TYPE_ENUM
Value is i, if represented by enum_symbols[i].
@ CSS_TYPE_INTEGER
This type is only used internally, for x-* properties.
@ CSS_TYPE_LENGTH_PERCENTAGE_NUMBER
@ CSS_TYPE_SIGNED_LENGTH
As CSS_TYPE_LENGTH but may be negative.
@ CSS_TYPE_MULTI_ENUM
For all enum_symbols[i], 1 << i are combined.
@ CSS_TYPE_LENGTH_PERCENTAGE
<length> or <percentage>.
@ CSS_TYPE_LENGTH
<length>, represented as CssLength.
@ CSS_TYPE_STRING
<string>
@ CSS_TYPE_SYMBOL
Symbols, which are directly copied (as opposed to CSS_TYPE_ENUM and CSS_TYPE_MULTI_ENUM).
@ CSS_TYPE_FONT_WEIGHT
this very special and only used by 'font-weight'
@ CSS_TYPE_COLOR
Represented as integer.
@ CSS_TYPE_BACKGROUND_POSITION
@ CSS_TYPE_AUTO
Represented as CssLength of type CSS_LENGTH_TYPE_AUTO.
CssLength CSS_CREATE_LENGTH(float v, CssLengthType t)
@ CSS_PRIMARY_USER_IMPORTANT
@ CSS_PRIMARY_AUTHOR_IMPORTANT
CssLengthType
CSS lengths are represented by the CssLength struct, which can hold different types of values.
@ CSS_LENGTH_TYPE_MM
"cm", "in", "pt" and "pc" are converted into millimeters.
@ CSS_LENGTH_TYPE_PERCENTAGE
@ CSS_LENGTH_TYPE_AUTO
This can be used as a simple value.
static const char *const Css_border_width_enum_vals[]
const CssPropertyName Css_font_properties[]
static const char *const Css_background_repeat_enum_vals[]
static const char *const Css_white_space_vals[]
static const char *const Css_text_align_enum_vals[]
static const CssShorthandInfo Css_shorthand_info[]
static const char *const Css_list_style_type_enum_vals[]
#define DEBUG_TOKEN_LEVEL
const CssPropertyName Css_border_top_properties[]
static const char *const Css_word_spacing_enum_vals[]
static const char *const Css_text_transform_enum_vals[]
#define DEBUG_PARSE_LEVEL
static const char *const Css_overflow_enum_vals[]
static const char *const Css_background_attachment_enum_vals[]
const CssPropertyName Css_background_properties[]
static const char *const Css_font_size_enum_vals[]
static const char *const Css_vertical_align_vals[]
static const char *const Css_font_variant_enum_vals[]
static const char *const Css_cursor_enum_vals[]
static const char *const Css_clear_enum_vals[]
const CssPropertyName Css_padding_properties[]
const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST]
static const char *const Css_font_weight_enum_vals[]
const CssPropertyName Css_outline_properties[]
const CssPropertyName Css_border_properties[]
static const char *const Css_display_enum_vals[]
static int Css_property_info_cmp(const void *a, const void *b)
bsearch(3) compare function for searching properties
const CssPropertyName Css_border_right_properties[]
const CssPropertyName Css_border_bottom_properties[]
static const char *const Css_line_height_enum_vals[]
const CssPropertyName Css_border_color_properties[4]
static const char *const Css_position_enum_vals[]
static const char *const Css_list_style_position_enum_vals[]
const CssPropertyName Css_border_style_properties[]
static int Css_shorthand_info_cmp(const void *a, const void *b)
bsearch(3) compare function for searching shorthands
#define CSS_SHORTHAND_NUM
static const char *const Css_border_collapse_enum_vals[]
static const char *const Css_text_decoration_enum_vals[]
static const char *const Css_letter_spacing_enum_vals[]
static const char *const Css_font_style_enum_vals[]
const CssPropertyName Css_border_left_properties[]
const CssPropertyName Css_margin_properties[]
static const char *const Css_border_style_enum_vals[]
const CssPropertyName Css_border_width_properties[]
#define CSS_NUM_PARSED_PROPERTIES
static const char *const Css_border_color_enum_vals[]
const CssPropertyName Css_list_style_properties[]
static const char *const Css_float_enum_vals[]
#define DEBUG_MSG(level,...)
int dStrAsciiCasecmp(const char *s1, const char *s2)
char * dStrstrip(char *s)
Remove leading and trailing whitespace.
void dStr_append(Dstr *ds, const char *s)
Append a C string to a Dstr.
char * dStrdup(const char *s)
void dStr_free(Dstr *ds, int all)
Free a dillo string.
void dStr_append_c(Dstr *ds, int c)
Append one character.
Dstr * dStr_new(const char *s)
Create a new string.
#define dNew(type, count)
DilloUrl * a_Html_url_new(DilloHtml *html, const char *url_str, const char *base_url, int use_base_url)
Wrapper for a_Url_new that adds an error detection message.
int a_Html_tag_index(const char *tag)
Get 'tag' index.
void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url)
Tell cache to retrieve a stylesheet.
Anything related to Dillo Widget styles is defined here.
CssBackgroundPosition * posVal
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
DilloUrl * a_Url_new(const char *url_str, const char *base_url)
Transform (and resolve) an URL string into the respective DilloURL.
char * a_Url_str(const DilloUrl *u)
Return the url as a string.