31#define MSG_CSS(A, ...) do {} while(0)
32#define DEBUG_TOKEN_LEVEL 0
33#define DEBUG_PARSE_LEVEL 0
34#define DEBUG_CREATE_LEVEL 0
39#define CSS_NUM_INTERNAL_PROPERTIES 3
40#define CSS_NUM_PARSED_PROPERTIES \
41 (CSS_PROPERTY_LAST - CSS_NUM_INTERNAL_PROPERTIES)
47 const char *
const *enum_symbols;
51 "scroll",
"fixed", NULL
55 "repeat",
"repeat-x",
"repeat-y",
"no-repeat", NULL
59 "separate",
"collapse", NULL
67 "none",
"hidden",
"dotted",
"dashed",
"solid",
"double",
"groove",
68 "ridge",
"inset",
"outset", NULL
72 "thin",
"medium",
"thick", NULL
76 "left",
"right",
"both",
"none", NULL
80 "crosshair",
"default",
"pointer",
"move",
"e-resize",
"ne-resize",
81 "nw-resize",
"n-resize",
"se-resize",
"sw-resize",
"s-resize",
82 "w-resize",
"text",
"wait",
"help", NULL
86 "block",
"inline",
"inline-block",
"list-item",
"none",
"table",
87 "table-row-group",
"table-header-group",
"table-footer-group",
"table-row",
92 "none",
"left",
"right", NULL
96 "large",
"larger",
"medium",
"small",
"smaller",
"xx-large",
"xx-small",
97 "x-large",
"x-small", NULL
101 "normal",
"italic",
"oblique", NULL
105 "normal",
"small-caps", NULL
109 "bold",
"bolder",
"light",
"lighter",
"normal", NULL
117 "inside",
"outside", NULL
125 "disc",
"circle",
"square",
"decimal",
"decimal-leading-zero",
126 "lower-roman",
"upper-roman",
"lower-greek",
"lower-alpha",
127 "lower-latin",
"upper-alpha",
"upper-latin",
"hebrew",
"armenian",
128 "georgian",
"cjk-ideographic",
"hiragana",
"katakana",
"hiragana-iroha",
129 "katakana-iroha",
"none", NULL
133 "visible",
"hidden",
"scroll",
"auto", NULL
137 "static",
"relative",
"absolute",
"fixed", NULL
141 "left",
"right",
"center",
"justify",
"string", NULL
145 "underline",
"overline",
"line-through",
"blink", NULL
149 "none",
"capitalize",
"uppercase",
"lowercase", NULL
153 "top",
"bottom",
"middle",
"baseline",
"sub",
"super",
"text-top",
158 "normal",
"pre",
"nowrap",
"pre-wrap",
"pre-line", NULL
292 CSS_SHORTHAND_MULTIPLE,
294 CSS_SHORTHAND_DIRECTIONS,
295 CSS_SHORTHAND_BORDER,
420 {
"background", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
422 {
"border", CssShorthandInfo::CSS_SHORTHAND_BORDER,
424 {
"border-bottom", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
426 {
"border-color", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
428 {
"border-left", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
430 {
"border-right", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
432 {
"border-style", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
434 {
"border-top", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
436 {
"border-width", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
438 {
"font", CssShorthandInfo::CSS_SHORTHAND_FONT,
440 {
"list-style", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
442 {
"margin", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
444 {
"outline", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE,
446 {
"padding", CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS,
450#define CSS_SHORTHAND_NUM \
451 (sizeof(Css_shorthand_info) / sizeof(Css_shorthand_info[0]))
459 const char *buf,
int buflen)
507 for (
int n = 0; str[n]; n++) {
560 }
while (isdigit(c));
578 }
while (isdigit(c));
606 if (isalpha(c) || c ==
'_' || c ==
'-') {
612 while (isalnum(c) || c ==
'_' || c ==
'-') {
625 if (c ==
'"' || c ==
'\'') {
632 while (c != EOF && c != c1) {
641 while (j < 4 && isxdigit(d)) {
648 c = strtol(hexbuf, NULL, 16);
676 while (isxdigit(c)) {
783 i = strtol(
tval, NULL, 10);
784 if (i >= 100 && i <= 900)
814 MSG_CSS(
"expected integer not found in %s color\n",
"rgb");
818 *cc = strtol(
tval, NULL, 10);
822 if (*percentage == 0) {
823 MSG_CSS(
"'%s' unexpected in rgb color\n",
"%");
827 *cc = *cc * 255 / 100;
830 if (*percentage == 1) {
831 MSG_CSS(
"expected '%s' not found in rgb color\n",
"%");
852 MSG_CSS(
"expected '%s' not found in rgb color\n",
"(");
862 MSG_CSS(
"expected '%s' not found in rgb color\n",
",");
872 MSG_CSS(
"expected '%s' not found in rgb color\n",
",");
882 MSG_CSS(
"expected '%s' not found in rgb color\n",
")");
894 bool found, ret =
false;
896 int i, ival, err = 1;
919 for (i = 0, found =
false;
1006 MSG_CSS(
"color is not in \"%s\" format\n",
"#RRGGBB");
1016 MSG_CSS(
"Failed to parse %s color\n",
"rgb(r,g,b)");
1020 MSG_CSS(
"color is not in \"%s\" format\n",
"#RRGGBB");
1059 ival = strtol(
tval, NULL, 10);
1060 if (ival < 100 || ival > 900)
1095 h[0] = v[0] = h[1] = v[1] =
false;
1100 for (i = 0; i < 2; i++) {
1114 h[i] = v[i] =
false;
1144 h[i] = v[i] =
false;
1157 if (!h[1] && !v[1]) {
1163 if ((h[0] && v[1]) || (v[0] && h[1])) {
1219 ((CssPropertyInfo *) b)->symbol);
1229 ((CssShorthandInfo *) b)->symbol);
1236 CssShorthandInfo *sip;
1243 int sh_index, i, j, n;
1244 int dir_set[4][4] = {
1256 sizeof(CssPropertyInfo),
1266 if (weight && importantProps)
1267 importantProps->
set(prop, type, val);
1269 props->
set(prop, type, val);
1277 sizeof(CssShorthandInfo),
1287 case CssShorthandInfo::CSS_SHORTHAND_FONT:
1289 case CssShorthandInfo::CSS_SHORTHAND_MULTIPLE:
1291 for (found =
false, i = 0;
1297 properties[i], &type)) {
1300 "will assign to '%s'\n",
1303 .properties[i]].symbol);
1305 .properties[i], type, &val)) {
1307 if (weight && importantProps)
1310 properties[i], type, val);
1313 properties[i], type, val);
1319 case CssShorthandInfo::CSS_SHORTHAND_DIRECTIONS:
1323 properties[0], &type) &&
1325 .properties[0], type, &val)) {
1327 dir_types[n] = type;
1335 for (i = 0; i < 4; i++)
1336 if (weight && importantProps)
1339 dir_types[dir_set[n - 1][i]],
1340 dir_vals[dir_set[n - 1][i]]);
1344 dir_types[dir_set[n - 1][i]],
1345 dir_vals[dir_set[n - 1][i]]);
1347 MSG_CSS(
"no values for shorthand property '%s'\n",
1352 case CssShorthandInfo::CSS_SHORTHAND_BORDER:
1354 for (found =
false, i = 0;
1358 properties[i], &type)) {
1361 .properties[i], type, &val)) {
1363 for (j = 0; j < 4; j++)
1364 if (weight && importantProps)
1367 properties[j * 3 + i], type, val);
1370 properties[j * 3 + i], type, val);
1384 (
tval[0] ==
';' ||
tval[0] ==
'}'))))
1454 selector->
id, selector->
klass,
1472 (
tval[0] ==
',' ||
tval[0] ==
'{')) {
1491 (
tval[0] !=
',' &&
tval[0] !=
'{')))
1499 lout::misc::SimpleVector < CssSelector * >*list;
1503 list =
new lout::misc::SimpleVector < CssSelector * >(1);
1511 list->
set(list->
size() - 1, selector);
1531 importantProps->
ref();
1544 for (
int i = 0; i < list->
size(); i++) {
1561 importantProps->
unref();
1571 Dstr *urlStr = NULL;
1614 char *urlStr = NULL;
1615 bool importSyntaxIsOK =
false;
1616 bool mediaSyntaxIsOK =
true;
1617 bool mediaIsSelected =
true;
1631 mediaSyntaxIsOK =
false;
1632 mediaIsSelected =
false;
1636 mediaIsSelected =
true;
1641 mediaSyntaxIsOK =
true;
1647 if (mediaSyntaxIsOK &&
1650 importSyntaxIsOK =
true;
1656 if (importSyntaxIsOK && mediaIsSelected) {
1657 MSG(
"CssParser::parseImport(): @import %s\n", urlStr);
1669 bool mediaSyntaxIsOK =
false;
1670 bool mediaIsSelected =
false;
1678 mediaIsSelected =
true;
1683 mediaSyntaxIsOK =
true;
1689 if (!(mediaSyntaxIsOK &&
1697 if (mediaIsSelected) {
1721 if (
tval[0] ==
'{') {
1723 }
else if (
tval[0] ==
'}') {
1739 if (
tval[0] ==
';') {
1742 }
else if (
tval[0] ==
'{') {
1757 bool importsAreAllowed =
true;
1761 parser.
tval[0] ==
'@') {
1766 importsAreAllowed) {
1777 importsAreAllowed =
false;
1784 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
@ 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.