46 return c ==
' ' || c ==
'\t' || c ==
'\f' || c ==
'\r' || c ==
'\n';
57 return (
'0' <= c && c <=
'9') ||
58 (
'A' <= (c & ~0x20) && (c & ~0x20) <=
'F');
101static bool parse_number(
const char *data,
bool maybe_negative,
bool real,
102 css_fixed *value,
size_t *consumed)
107 int32_t fracpart = 0;
114 ptr = (
const uint8_t *) data;
132 }
else if (ptr[0] ==
'-' && maybe_negative) {
142 if (
'0' > ptr[0] || ptr[0] >
'9')
148 if (ptr[0] <
'0' ||
'9' < ptr[0])
152 if (intpart < (1 << 22)) {
154 intpart += ptr[0] -
'0';
161 if (real && len > 1 && ptr[0] ==
'.' &&
162 (
'0' <= ptr[1] && ptr[1] <=
'9')) {
167 if (ptr[0] <
'0' ||
'9' < ptr[0])
173 fracpart += ptr[0] -
'0';
179 fracpart = ((1 << 10) * fracpart + pwr/2) / pwr;
180 if (fracpart >= (1 << 10)) {
182 fracpart &= (1 << 10) - 1;
189 if (intpart >= (1 << 21)) {
190 intpart = (1 << 21) - 1;
191 fracpart = (1 << 10) - 1;
196 if (intpart >= (1 << 21)) {
197 intpart = -(1 << 21);
202 fracpart = (1 << 10) - fracpart;
208 *value = (intpart << 10) | fracpart;
210 *consumed = ptr - (
const uint8_t *) data;
233 if (
parse_number(data,
false,
true, &value, &read) ==
false)
236 if (strict && value < INTTOFIX(1))
241 if (len > read && data[read] ==
'%')
242 *unit = CSS_UNIT_PCT;
271 return strcasecmp(aa, bb->
name);
283 static const struct colour_map named_colours[] = {
284 {
"aliceblue", 0xfff0f8ff },
285 {
"antiquewhite", 0xfffaebd7 },
286 {
"aqua", 0xff00ffff },
287 {
"aquamarine", 0xff7fffd4 },
288 {
"azure", 0xfff0ffff },
289 {
"beige", 0xfff5f5dc },
290 {
"bisque", 0xffffe4c4 },
291 {
"black", 0xff000000 },
292 {
"blanchedalmond", 0xffffebcd },
293 {
"blue", 0xff0000ff },
294 {
"blueviolet", 0xff8a2be2 },
295 {
"brown", 0xffa52a2a },
296 {
"burlywood", 0xffdeb887 },
297 {
"cadetblue", 0xff5f9ea0 },
298 {
"chartreuse", 0xff7fff00 },
299 {
"chocolate", 0xffd2691e },
300 {
"coral", 0xffff7f50 },
301 {
"cornflowerblue", 0xff6495ed },
302 {
"cornsilk", 0xfffff8dc },
303 {
"crimson", 0xffdc143c },
304 {
"cyan", 0xff00ffff },
305 {
"darkblue", 0xff00008b },
306 {
"darkcyan", 0xff008b8b },
307 {
"darkgoldenrod", 0xffb8860b },
308 {
"darkgray", 0xffa9a9a9 },
309 {
"darkgreen", 0xff006400 },
310 {
"darkgrey", 0xffa9a9a9 },
311 {
"darkkhaki", 0xffbdb76b },
312 {
"darkmagenta", 0xff8b008b },
313 {
"darkolivegreen", 0xff556b2f },
314 {
"darkorange", 0xffff8c00 },
315 {
"darkorchid", 0xff9932cc },
316 {
"darkred", 0xff8b0000 },
317 {
"darksalmon", 0xffe9967a },
318 {
"darkseagreen", 0xff8fbc8f },
319 {
"darkslateblue", 0xff483d8b },
320 {
"darkslategray", 0xff2f4f4f },
321 {
"darkslategrey", 0xff2f4f4f },
322 {
"darkturquoise", 0xff00ced1 },
323 {
"darkviolet", 0xff9400d3 },
324 {
"deeppink", 0xffff1493 },
325 {
"deepskyblue", 0xff00bfff },
326 {
"dimgray", 0xff696969 },
327 {
"dimgrey", 0xff696969 },
328 {
"dodgerblue", 0xff1e90ff },
329 {
"feldspar", 0xffd19275 },
330 {
"firebrick", 0xffb22222 },
331 {
"floralwhite", 0xfffffaf0 },
332 {
"forestgreen", 0xff228b22 },
333 {
"fuchsia", 0xffff00ff },
334 {
"gainsboro", 0xffdcdcdc },
335 {
"ghostwhite", 0xfff8f8ff },
336 {
"gold", 0xffffd700 },
337 {
"goldenrod", 0xffdaa520 },
338 {
"gray", 0xff808080 },
339 {
"green", 0xff008000 },
340 {
"greenyellow", 0xffadff2f },
341 {
"grey", 0xff808080 },
342 {
"honeydew", 0xfff0fff0 },
343 {
"hotpink", 0xffff69b4 },
344 {
"indianred", 0xffcd5c5c },
345 {
"indigo", 0xff4b0082 },
346 {
"ivory", 0xfffffff0 },
347 {
"khaki", 0xfff0e68c },
348 {
"lavender", 0xffe6e6fa },
349 {
"lavenderblush", 0xfffff0f5 },
350 {
"lawngreen", 0xff7cfc00 },
351 {
"lemonchiffon", 0xfffffacd },
352 {
"lightblue", 0xffadd8e6 },
353 {
"lightcoral", 0xfff08080 },
354 {
"lightcyan", 0xffe0ffff },
355 {
"lightgoldenrodyellow", 0xfffafad2 },
356 {
"lightgray", 0xffd3d3d3 },
357 {
"lightgreen", 0xff90ee90 },
358 {
"lightgrey", 0xffd3d3d3 },
359 {
"lightpink", 0xffffb6c1 },
360 {
"lightsalmon", 0xffffa07a },
361 {
"lightseagreen", 0xff20b2aa },
362 {
"lightskyblue", 0xff87cefa },
363 {
"lightslateblue", 0xff8470ff },
364 {
"lightslategray", 0xff778899 },
365 {
"lightslategrey", 0xff778899 },
366 {
"lightsteelblue", 0xffb0c4de },
367 {
"lightyellow", 0xffffffe0 },
368 {
"lime", 0xff00ff00 },
369 {
"limegreen", 0xff32cd32 },
370 {
"linen", 0xfffaf0e6 },
371 {
"magenta", 0xffff00ff },
372 {
"maroon", 0xff800000 },
373 {
"mediumaquamarine", 0xff66cdaa },
374 {
"mediumblue", 0xff0000cd },
375 {
"mediumorchid", 0xffba55d3 },
376 {
"mediumpurple", 0xff9370db },
377 {
"mediumseagreen", 0xff3cb371 },
378 {
"mediumslateblue", 0xff7b68ee },
379 {
"mediumspringgreen", 0xff00fa9a },
380 {
"mediumturquoise", 0xff48d1cc },
381 {
"mediumvioletred", 0xffc71585 },
382 {
"midnightblue", 0xff191970 },
383 {
"mintcream", 0xfff5fffa },
384 {
"mistyrose", 0xffffe4e1 },
385 {
"moccasin", 0xffffe4b5 },
386 {
"navajowhite", 0xffffdead },
387 {
"navy", 0xff000080 },
388 {
"oldlace", 0xfffdf5e6 },
389 {
"olive", 0xff808000 },
390 {
"olivedrab", 0xff6b8e23 },
391 {
"orange", 0xffffa500 },
392 {
"orangered", 0xffff4500 },
393 {
"orchid", 0xffda70d6 },
394 {
"palegoldenrod", 0xffeee8aa },
395 {
"palegreen", 0xff98fb98 },
396 {
"paleturquoise", 0xffafeeee },
397 {
"palevioletred", 0xffdb7093 },
398 {
"papayawhip", 0xffffefd5 },
399 {
"peachpuff", 0xffffdab9 },
400 {
"peru", 0xffcd853f },
401 {
"pink", 0xffffc0cb },
402 {
"plum", 0xffdda0dd },
403 {
"powderblue", 0xffb0e0e6 },
404 {
"purple", 0xff800080 },
405 {
"red", 0xffff0000 },
406 {
"rosybrown", 0xffbc8f8f },
407 {
"royalblue", 0xff4169e1 },
408 {
"saddlebrown", 0xff8b4513 },
409 {
"salmon", 0xfffa8072 },
410 {
"sandybrown", 0xfff4a460 },
411 {
"seagreen", 0xff2e8b57 },
412 {
"seashell", 0xfffff5ee },
413 {
"sienna", 0xffa0522d },
414 {
"silver", 0xffc0c0c0 },
415 {
"skyblue", 0xff87ceeb },
416 {
"slateblue", 0xff6a5acd },
417 {
"slategray", 0xff708090 },
418 {
"slategrey", 0xff708090 },
419 {
"snow", 0xfffffafa },
420 {
"springgreen", 0xff00ff7f },
421 {
"steelblue", 0xff4682b4 },
422 {
"tan", 0xffd2b48c },
423 {
"teal", 0xff008080 },
424 {
"thistle", 0xffd8bfd8 },
425 {
"tomato", 0xffff6347 },
426 {
"turquoise", 0xff40e0d0 },
427 {
"violet", 0xffee82ee },
428 {
"violetred", 0xffd02090 },
429 {
"wheat", 0xfff5deb3 },
430 {
"white", 0xffffffff },
431 {
"whitesmoke", 0xfff5f5f5 },
432 {
"yellow", 0xffffff00 },
433 {
"yellowgreen", 0xff9acd32 }
437 entry = bsearch(
name, named_colours,
438 sizeof(named_colours) /
sizeof(named_colours[0]),
439 sizeof(named_colours[0]),
445 return entry != NULL;
451 size_t len = strlen(data);
459 if (len ==
SLEN(
"transparent") && strcasecmp(data,
"transparent") == 0)
468 if (data[0] ==
'#') {
482 *
result = (0xff << 24) | (r << 16) | (g << 8) | b;
485 }
else if (len == 6 &&
isHex(data[0]) &&
isHex(data[1]) &&
492 *
result = (0xff << 24) | (r << 16) | (g << 8) | b;
510 css_fixed *len, css_unit *unit)
512 static const uint8_t size_map[] = {
513 CSS_FONT_SIZE_XX_SMALL,
515 CSS_FONT_SIZE_MEDIUM,
517 CSS_FONT_SIZE_X_LARGE,
518 CSS_FONT_SIZE_XX_LARGE,
519 CSS_FONT_SIZE_DIMENSION
522 const char *p = size;
537 if (*p < '0' || *p >
'9') {
542 while (
'0' <= *p && *p <=
'9') {
543 value = value * 10 + (*p -
'0');
550 else if (
mode ==
'-')
561 *len = FDIV(FMUL(INTTOFIX(3), INTTOFIX(
nsoption_int(font_size))),
569 *val = size_map[value - 1];
579#define MAX_HINTS_PER_ELEMENT 32
635 dom_string *attr = NULL;
636 dom_node *tablenode = NULL;
640 qs.name = lwc_string_ref(corestring_lwc_table);
642 (
void *)&tablenode) != CSS_OK) {
644 lwc_string_unref(qs.name);
647 lwc_string_unref(qs.name);
649 if (tablenode == NULL) {
656 exc = dom_element_get_attribute(tablenode,
657 corestring_dom_border, &attr);
659 if (exc == DOM_NO_ERR && attr != NULL) {
661 css_hint_length hint_length;
664 dom_string_data(attr),
false,
666 &hint_length.unit) &&
667 INTTOFIX(0) != hint_length.value) {
669 for (hint_prop = CSS_PROP_BORDER_TOP_STYLE;
670 hint_prop <= CSS_PROP_BORDER_LEFT_STYLE;
672 hint->prop = hint_prop;
673 hint->status = CSS_BORDER_STYLE_INSET;
677 for (hint_prop = CSS_PROP_BORDER_TOP_WIDTH;
678 hint_prop <= CSS_PROP_BORDER_LEFT_WIDTH;
680 hint->prop = hint_prop;
681 hint->data.length.value = INTTOFIX(1);
682 hint->data.length.unit = CSS_UNIT_PX;
683 hint->status = CSS_BORDER_WIDTH_WIDTH;
687 dom_string_unref(attr);
690 exc = dom_element_get_attribute(tablenode,
691 corestring_dom_bordercolor, &attr);
693 if (exc == DOM_NO_ERR && attr != NULL) {
695 css_color hint_color;
698 (
const char *)dom_string_data(attr),
701 for (hint_prop = CSS_PROP_BORDER_TOP_COLOR;
702 hint_prop <= CSS_PROP_BORDER_LEFT_COLOR;
704 hint->prop = hint_prop;
705 hint->data.color = hint_color;
706 hint->status = CSS_BORDER_COLOR_COLOR;
710 dom_string_unref(attr);
713 exc = dom_element_get_attribute(tablenode,
714 corestring_dom_cellpadding, &attr);
716 if (exc == DOM_NO_ERR && attr != NULL) {
718 css_hint_length hint_length;
721 dom_string_data(attr),
false,
723 &hint_length.unit)) {
725 for (hint_prop = CSS_PROP_PADDING_TOP;
726 hint_prop <= CSS_PROP_PADDING_LEFT;
728 hint->prop = hint_prop;
729 hint->data.length.value = hint_length.value;
730 hint->data.length.unit = hint_length.unit;
731 hint->status = CSS_PADDING_SET;
735 dom_string_unref(attr);
744 dom_string *attr = NULL;
747 err = dom_element_get_attribute(node,
748 corestring_dom_valign, &attr);
750 if (err == DOM_NO_ERR && attr != NULL) {
751 hint->data.length.value = 0;
752 hint->data.length.unit = CSS_UNIT_PX;
753 if (dom_string_caseless_lwc_isequal(attr,
754 corestring_lwc_top)) {
755 hint->prop = CSS_PROP_VERTICAL_ALIGN;
756 hint->status = CSS_VERTICAL_ALIGN_TOP;
759 }
else if (dom_string_caseless_lwc_isequal(attr,
760 corestring_lwc_middle)) {
761 hint->prop = CSS_PROP_VERTICAL_ALIGN;
762 hint->status = CSS_VERTICAL_ALIGN_MIDDLE;
765 }
else if (dom_string_caseless_lwc_isequal(attr,
766 corestring_lwc_bottom)) {
767 hint->prop = CSS_PROP_VERTICAL_ALIGN;
768 hint->status = CSS_VERTICAL_ALIGN_BOTTOM;
771 }
else if (dom_string_caseless_lwc_isequal(attr,
772 corestring_lwc_baseline)) {
773 hint->prop = CSS_PROP_VERTICAL_ALIGN;
774 hint->status = CSS_VERTICAL_ALIGN_BASELINE;
777 dom_string_unref(attr);
786 dom_string *attr = NULL;
789 err = dom_element_get_attribute(node,
790 corestring_dom_valign, &attr);
792 if (err == DOM_NO_ERR && attr != NULL) {
793 if (dom_string_caseless_lwc_isequal(attr,
794 corestring_lwc_top)) {
795 hint->prop = CSS_PROP_VERTICAL_ALIGN;
796 hint->status = CSS_VERTICAL_ALIGN_TOP;
799 }
else if (dom_string_caseless_lwc_isequal(attr,
800 corestring_lwc_bottom) ||
801 dom_string_caseless_lwc_isequal(attr,
802 corestring_lwc_baseline)) {
803 hint->prop = CSS_PROP_VERTICAL_ALIGN;
804 hint->status = CSS_VERTICAL_ALIGN_BASELINE;
807 }
else if (dom_string_caseless_lwc_isequal(attr,
808 corestring_lwc_texttop)) {
809 hint->prop = CSS_PROP_VERTICAL_ALIGN;
810 hint->status = CSS_VERTICAL_ALIGN_TEXT_TOP;
813 }
else if (dom_string_caseless_lwc_isequal(attr,
814 corestring_lwc_absmiddle) ||
815 dom_string_caseless_lwc_isequal(attr,
816 corestring_lwc_abscenter)) {
817 hint->prop = CSS_PROP_VERTICAL_ALIGN;
818 hint->status = CSS_VERTICAL_ALIGN_MIDDLE;
821 dom_string_unref(attr);
830 dom_string *align = NULL;
833 err = dom_element_get_attribute(node,
834 corestring_dom_align, &align);
835 if (err == DOM_NO_ERR && align != NULL) {
836 if (dom_string_caseless_lwc_isequal(align,
837 corestring_lwc_left)) {
838 hint->prop = CSS_PROP_TEXT_ALIGN;
839 hint->status = CSS_TEXT_ALIGN_LEFT;
842 }
else if (dom_string_caseless_lwc_isequal(align,
843 corestring_lwc_center)) {
844 hint->prop = CSS_PROP_TEXT_ALIGN;
845 hint->status = CSS_TEXT_ALIGN_CENTER;
848 }
else if (dom_string_caseless_lwc_isequal(align,
849 corestring_lwc_right)) {
850 hint->prop = CSS_PROP_TEXT_ALIGN;
851 hint->status = CSS_TEXT_ALIGN_RIGHT;
854 }
else if (dom_string_caseless_lwc_isequal(align,
855 corestring_lwc_justify)) {
856 hint->prop = CSS_PROP_TEXT_ALIGN;
857 hint->status = CSS_TEXT_ALIGN_JUSTIFY;
860 dom_string_unref(align);
870 hint->prop = CSS_PROP_TEXT_ALIGN;
871 hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
883 exc = dom_element_get_attribute(node,
884 corestring_dom_align, &attr);
886 if (exc == DOM_NO_ERR && attr != NULL) {
887 memset(hint, 0,
sizeof(*hint) * 2);
888 if (dom_string_caseless_lwc_isequal(attr,
889 corestring_lwc_center) ||
890 dom_string_caseless_lwc_isequal(attr,
891 corestring_lwc_abscenter) ||
892 dom_string_caseless_lwc_isequal(attr,
893 corestring_lwc_middle) ||
894 dom_string_caseless_lwc_isequal(attr,
895 corestring_lwc_absmiddle)) {
896 hint->prop = CSS_PROP_MARGIN_LEFT;
897 hint->status = CSS_MARGIN_AUTO;
900 hint->prop = CSS_PROP_MARGIN_RIGHT;
901 hint->status = CSS_MARGIN_AUTO;
904 dom_string_unref(attr);
913 dom_string *align = NULL;
916 err = dom_element_get_attribute(node,
917 corestring_dom_align, &align);
919 if (err == DOM_NO_ERR && align != NULL) {
920 if (dom_string_caseless_lwc_isequal(align,
921 corestring_lwc_center)) {
922 hint->prop = CSS_PROP_TEXT_ALIGN;
923 hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
926 }
else if (dom_string_caseless_lwc_isequal(align,
927 corestring_lwc_left)) {
928 hint->prop = CSS_PROP_TEXT_ALIGN;
929 hint->status = CSS_TEXT_ALIGN_LIBCSS_LEFT;
932 }
else if (dom_string_caseless_lwc_isequal(align,
933 corestring_lwc_right)) {
934 hint->prop = CSS_PROP_TEXT_ALIGN;
935 hint->status = CSS_TEXT_ALIGN_LIBCSS_RIGHT;
938 }
else if (dom_string_caseless_lwc_isequal(align,
939 corestring_lwc_justify)) {
940 hint->prop = CSS_PROP_TEXT_ALIGN;
941 hint->status = CSS_TEXT_ALIGN_JUSTIFY;
944 dom_string_unref(align);
954 hint->prop = CSS_PROP_TEXT_ALIGN;
955 hint->status = CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC;
964 dom_string *attr = NULL;
967 exc = dom_element_get_attribute(node,
968 corestring_dom_vspace, &attr);
970 if (exc == DOM_NO_ERR && attr != NULL) {
971 css_hint_length hint_length;
973 dom_string_data(attr),
false,
975 &hint_length.unit)) {
976 hint->prop = CSS_PROP_MARGIN_TOP;
977 hint->data.length.value = hint_length.value;
978 hint->data.length.unit = hint_length.unit;
979 hint->status = CSS_MARGIN_SET;
982 hint->prop = CSS_PROP_MARGIN_BOTTOM;
983 hint->data.length.value = hint_length.value;
984 hint->data.length.unit = hint_length.unit;
985 hint->status = CSS_MARGIN_SET;
988 dom_string_unref(attr);
991 exc = dom_element_get_attribute(node,
992 corestring_dom_hspace, &attr);
994 if (exc == DOM_NO_ERR && attr != NULL) {
995 css_hint_length hint_length;
997 dom_string_data(attr),
false,
999 &hint_length.unit)) {
1000 hint->prop = CSS_PROP_MARGIN_LEFT;
1001 hint->data.length.value = hint_length.value;
1002 hint->data.length.unit = hint_length.unit;
1003 hint->status = CSS_MARGIN_SET;
1006 hint->prop = CSS_PROP_MARGIN_RIGHT;
1007 hint->data.length.value = hint_length.value;
1008 hint->data.length.unit = hint_length.unit;
1009 hint->status = CSS_MARGIN_SET;
1012 dom_string_unref(attr);
1024 exc = dom_element_get_attribute(node,
1025 corestring_dom_align, &attr);
1027 if (exc == DOM_NO_ERR && attr != NULL) {
1028 memset(hint, 0,
sizeof(*hint) * 2);
1029 if (dom_string_caseless_lwc_isequal(attr,
1030 corestring_lwc_left)) {
1031 hint->prop = CSS_PROP_MARGIN_LEFT;
1032 hint->data.length.value = 0;
1033 hint->data.length.unit = CSS_UNIT_PX;
1034 hint->status = CSS_MARGIN_SET;
1037 hint->prop = CSS_PROP_MARGIN_RIGHT;
1038 hint->status = CSS_MARGIN_AUTO;
1041 }
else if (dom_string_caseless_lwc_isequal(attr,
1042 corestring_lwc_center)) {
1043 hint->prop = CSS_PROP_MARGIN_LEFT;
1044 hint->status = CSS_MARGIN_AUTO;
1047 hint->prop = CSS_PROP_MARGIN_RIGHT;
1048 hint->status = CSS_MARGIN_AUTO;
1051 }
else if (dom_string_caseless_lwc_isequal(attr,
1052 corestring_lwc_right)) {
1053 hint->prop = CSS_PROP_MARGIN_LEFT;
1054 hint->status = CSS_MARGIN_AUTO;
1057 hint->prop = CSS_PROP_MARGIN_RIGHT;
1058 hint->data.length.value = 0;
1059 hint->data.length.unit = CSS_UNIT_PX;
1060 hint->status = CSS_MARGIN_SET;
1063 dom_string_unref(attr);
1073 dom_string *attr = NULL;
1075 exc = dom_element_get_attribute(node, corestring_dom_border, &attr);
1077 if (exc == DOM_NO_ERR && attr != NULL) {
1079 css_hint_length hint_length;
1081 for (hint_prop = CSS_PROP_BORDER_TOP_STYLE;
1082 hint_prop <= CSS_PROP_BORDER_LEFT_STYLE;
1084 hint->prop = hint_prop;
1085 hint->status = CSS_BORDER_STYLE_OUTSET;
1090 dom_string_data(attr),
false,
1092 &hint_length.unit)) {
1094 for (hint_prop = CSS_PROP_BORDER_TOP_WIDTH;
1095 hint_prop <= CSS_PROP_BORDER_LEFT_WIDTH;
1097 hint->prop = hint_prop;
1098 hint->data.length.value = hint_length.value;
1099 hint->data.length.unit = hint_length.unit;
1100 hint->status = CSS_BORDER_WIDTH_WIDTH;
1104 dom_string_unref(attr);
1107 exc = dom_element_get_attribute(node,
1108 corestring_dom_bordercolor, &attr);
1110 if (exc == DOM_NO_ERR && attr != NULL) {
1112 css_color hint_color;
1115 (
const char *)dom_string_data(attr),
1118 for (hint_prop = CSS_PROP_BORDER_TOP_COLOR;
1119 hint_prop <= CSS_PROP_BORDER_LEFT_COLOR;
1121 hint->prop = hint_prop;
1122 hint->data.color = hint_color;
1123 hint->status = CSS_BORDER_COLOR_COLOR;
1127 dom_string_unref(attr);
1130 exc = dom_element_get_attribute(node,
1131 corestring_dom_cellspacing, &attr);
1133 if (exc == DOM_NO_ERR && attr != NULL) {
1135 (
const char *)dom_string_data(attr),
false,
1136 &hint->data.position.h.value,
1137 &hint->data.position.h.unit)) {
1138 hint->prop = CSS_PROP_BORDER_SPACING;
1139 hint->data.position.v = hint->data.position.h;
1140 hint->status = CSS_BORDER_SPACING_SET;
1143 dom_string_unref(attr);
1152 dom_string *attr = NULL;
1155 err = dom_element_get_attribute(node,
1156 corestring_dom_height, &attr);
1158 if (err == DOM_NO_ERR && attr != NULL) {
1160 (
const char *)dom_string_data(attr),
false,
1161 &hint->data.length.value,
1162 &hint->data.length.unit)) {
1163 hint->prop = CSS_PROP_HEIGHT;
1164 hint->status = CSS_HEIGHT_SET;
1167 dom_string_unref(attr);
1176 dom_string *attr = NULL;
1179 err = dom_element_get_attribute(node,
1180 corestring_dom_width, &attr);
1182 if (err == DOM_NO_ERR && attr != NULL) {
1184 (
const char *)dom_string_data(attr),
false,
1185 &hint->data.length.value,
1186 &hint->data.length.unit)) {
1187 hint->prop = CSS_PROP_WIDTH;
1188 hint->status = CSS_WIDTH_SET;
1191 dom_string_unref(attr);
1200 dom_string *attr = NULL;
1203 err = dom_element_get_attribute(node,
1204 corestring_dom_rows, &attr);
1206 if (err == DOM_NO_ERR && attr != NULL) {
1208 (
const char *)dom_string_data(attr),
false,
1209 &hint->data.length.value,
1210 &hint->data.length.unit)) {
1211 hint->prop = CSS_PROP_HEIGHT;
1212 hint->data.length.unit = CSS_UNIT_EM;
1213 hint->status = CSS_HEIGHT_SET;
1216 dom_string_unref(attr);
1219 err = dom_element_get_attribute(node,
1220 corestring_dom_cols, &attr);
1222 if (err == DOM_NO_ERR && attr != NULL) {
1224 (
const char *)dom_string_data(attr),
false,
1225 &hint->data.length.value,
1226 &hint->data.length.unit)) {
1227 hint->prop = CSS_PROP_WIDTH;
1228 hint->data.length.unit = CSS_UNIT_EX;
1229 hint->status = CSS_WIDTH_SET;
1232 dom_string_unref(attr);
1241 dom_string *attr = NULL;
1243 bool set_dim =
false;
1245 err = dom_element_get_attribute(node,
1246 corestring_dom_height, &attr);
1248 if (err == DOM_NO_ERR && attr != NULL) {
1250 (
const char *)dom_string_data(attr),
true,
1251 &hint->data.length.value,
1252 &hint->data.length.unit)) {
1253 hint->prop = CSS_PROP_HEIGHT;
1254 hint->data.length.unit = CSS_UNIT_PX;
1255 hint->status = CSS_HEIGHT_SET;
1259 dom_string_unref(attr);
1261 if (set_dim ==
false) {
1263 hint->prop = CSS_PROP_HEIGHT;
1264 hint->data.length.unit = CSS_UNIT_PX;
1265 hint->data.length.value = INTTOFIX(150);
1266 hint->status = CSS_HEIGHT_SET;
1272 err = dom_element_get_attribute(node,
1273 corestring_dom_width, &attr);
1275 if (err == DOM_NO_ERR && attr != NULL) {
1277 (
const char *)dom_string_data(attr),
true,
1278 &hint->data.length.value,
1279 &hint->data.length.unit)) {
1280 hint->prop = CSS_PROP_WIDTH;
1281 hint->data.length.unit = CSS_UNIT_PX;
1282 hint->status = CSS_WIDTH_SET;
1286 dom_string_unref(attr);
1288 if (set_dim ==
false) {
1290 hint->prop = CSS_PROP_WIDTH;
1291 hint->data.length.unit = CSS_UNIT_PX;
1292 hint->data.length.value = INTTOFIX(300);
1293 hint->status = CSS_WIDTH_SET;
1303 dom_string *attr = NULL;
1306 err = dom_element_get_attribute(node,
1307 corestring_dom_size, &attr);
1309 if (err == DOM_NO_ERR && attr != NULL) {
1311 (
const char *)dom_string_data(attr),
false,
1312 &hint->data.length.value,
1313 &hint->data.length.unit)) {
1314 dom_string *attr2 = NULL;
1316 err = dom_element_get_attribute(node,
1317 corestring_dom_type, &attr2);
1318 if (err == DOM_NO_ERR) {
1320 hint->prop = CSS_PROP_WIDTH;
1321 hint->status = CSS_WIDTH_SET;
1323 if (attr2 == NULL ||
1324 dom_string_caseless_lwc_isequal(
1326 corestring_lwc_text) ||
1327 dom_string_caseless_lwc_isequal(
1329 corestring_lwc_search) ||
1330 dom_string_caseless_lwc_isequal(
1332 corestring_lwc_password) ||
1333 dom_string_caseless_lwc_isequal(
1335 corestring_lwc_file)) {
1336 hint->data.length.unit = CSS_UNIT_EX;
1338 if (attr2 != NULL) {
1339 dom_string_unref(attr2);
1344 dom_string_unref(attr);
1356 dom_node *bodynode = NULL;
1363 qs.name = lwc_string_ref(corestring_lwc_body);
1365 (
void *)&bodynode) != CSS_OK) {
1367 lwc_string_unref(qs.name);
1370 lwc_string_unref(qs.name);
1372 if (bodynode == NULL) {
1377 if (error != CSS_OK)
1381 err = dom_element_get_attribute(bodynode,
1382 corestring_dom_vlink, &color);
1384 err = dom_element_get_attribute(bodynode,
1385 corestring_dom_link, &color);
1388 if (err == DOM_NO_ERR && color != NULL) {
1390 (
const char *)dom_string_data(color),
1391 &hint->data.color)) {
1392 hint->prop = CSS_PROP_COLOR;
1393 hint->status = CSS_COLOR_COLOR;
1396 dom_string_unref(color);
1408 err = dom_element_get_attribute(node, corestring_dom_text, &color);
1410 if (err == DOM_NO_ERR && color != NULL) {
1412 (
const char *)dom_string_data(color),
1413 &hint->data.color)) {
1414 hint->prop = CSS_PROP_COLOR;
1415 hint->status = CSS_COLOR_COLOR;
1418 dom_string_unref(color);
1430 err = dom_element_get_attribute(node, corestring_dom_color, &color);
1432 if (err == DOM_NO_ERR && color != NULL) {
1434 (
const char *)dom_string_data(color),
1435 &hint->data.color)) {
1436 hint->prop = CSS_PROP_COLOR;
1437 hint->status = CSS_COLOR_COLOR;
1440 dom_string_unref(color);
1452 err = dom_element_get_attribute(node, corestring_dom_size, &size);
1453 if (err == DOM_NO_ERR && size != NULL) {
1455 (
const char *)dom_string_data(size),
1457 &hint->data.length.value,
1458 &hint->data.length.unit)) {
1459 hint->prop = CSS_PROP_FONT_SIZE;
1462 dom_string_unref(size);
1474 err = dom_element_get_attribute(node, corestring_dom_align, &align);
1475 if (err == DOM_NO_ERR && align != NULL) {
1476 if (dom_string_caseless_lwc_isequal(align,
1477 corestring_lwc_left)) {
1478 hint->prop = CSS_PROP_FLOAT;
1479 hint->status = CSS_FLOAT_LEFT;
1482 }
else if (dom_string_caseless_lwc_isequal(align,
1483 corestring_lwc_right)) {
1484 hint->prop = CSS_PROP_FLOAT;
1485 hint->status = CSS_FLOAT_RIGHT;
1488 dom_string_unref(align);
1498 dom_string *align = NULL;
1500 err = dom_element_get_attribute(node, corestring_dom_align, &align);
1501 if (err == DOM_NO_ERR && align != NULL) {
1502 if (dom_string_caseless_lwc_isequal(align,
1503 corestring_lwc_bottom)) {
1504 hint->prop = CSS_PROP_CAPTION_SIDE;
1505 hint->status = CSS_CAPTION_SIDE_BOTTOM;
1508 dom_string_unref(align);
1518 dom_string *bgcolor;
1520 err = dom_element_get_attribute(node,
1521 corestring_dom_bgcolor, &bgcolor);
1522 if (err == DOM_NO_ERR && bgcolor != NULL) {
1524 (
const char *)dom_string_data(bgcolor),
1525 &hint->data.color)) {
1526 hint->prop = CSS_PROP_BACKGROUND_COLOR;
1527 hint->status = CSS_BACKGROUND_COLOR_COLOR;
1530 dom_string_unref(bgcolor);
1542 err = dom_element_get_attribute(node,
1543 corestring_dom_background, &attr);
1544 if (err == DOM_NO_ERR && attr != NULL) {
1547 (
const char *)dom_string_data(attr), &url);
1548 dom_string_unref(attr);
1552 lwc_error lerror = lwc_intern_string(
nsurl_access(url),
1556 if (lerror == lwc_error_ok) {
1557 hint->prop = CSS_PROP_BACKGROUND_IMAGE;
1558 hint->data.string = iurl;
1559 hint->status = CSS_BACKGROUND_IMAGE_IMAGE;
1574 err = dom_element_has_attribute(node, corestring_dom_nowrap, &nowrap);
1575 if (err == DOM_NO_ERR && nowrap ==
true) {
1576 hint->prop = CSS_PROP_WHITE_SPACE;
1577 hint->status = CSS_WHITE_SPACE_NOWRAP;
1590 err = dom_element_get_attribute(node, corestring_dom_type, &attr);
1591 if (err == DOM_NO_ERR && attr != NULL) {
1592 const char *attr_str = dom_string_data(attr);
1593 size_t attr_len = dom_string_byte_length(attr);
1594 enum css_list_style_type_e
type = CSS_LIST_STYLE_TYPE_INHERIT;
1596 if (attr_len == 1) {
1597 switch (attr_str[0]) {
1599 type = CSS_LIST_STYLE_TYPE_LOWER_ALPHA;
1602 type = CSS_LIST_STYLE_TYPE_UPPER_ALPHA;
1605 type = CSS_LIST_STYLE_TYPE_LOWER_ROMAN;
1608 type = CSS_LIST_STYLE_TYPE_UPPER_ROMAN;
1611 type = CSS_LIST_STYLE_TYPE_DECIMAL;
1616 if (
type != CSS_LIST_STYLE_TYPE_INHERIT) {
1617 hint->prop = CSS_PROP_LIST_STYLE_TYPE;
1618 hint->status =
type;
1622 dom_string_unref(attr);
1629 uint32_t *nhints, css_hint **hints)
1632 dom_html_element_type tag_type;
1642 exc = dom_html_element_get_tag_type(node, &tag_type);
1643 if (exc != DOM_NO_ERR) {
1644 tag_type = DOM_HTML_ELEMENT_TYPE__UNKNOWN;
1648 case DOM_HTML_ELEMENT_TYPE_TH:
1649 case DOM_HTML_ELEMENT_TYPE_TD:
1654 case DOM_HTML_ELEMENT_TYPE_TR:
1657 case DOM_HTML_ELEMENT_TYPE_THEAD:
1658 case DOM_HTML_ELEMENT_TYPE_TBODY:
1659 case DOM_HTML_ELEMENT_TYPE_TFOOT:
1662 case DOM_HTML_ELEMENT_TYPE_COL:
1665 case DOM_HTML_ELEMENT_TYPE_APPLET:
1666 case DOM_HTML_ELEMENT_TYPE_IMG:
1669 case DOM_HTML_ELEMENT_TYPE_EMBED:
1670 case DOM_HTML_ELEMENT_TYPE_IFRAME:
1671 case DOM_HTML_ELEMENT_TYPE_OBJECT:
1677 case DOM_HTML_ELEMENT_TYPE_P:
1678 case DOM_HTML_ELEMENT_TYPE_H1:
1679 case DOM_HTML_ELEMENT_TYPE_H2:
1680 case DOM_HTML_ELEMENT_TYPE_H3:
1681 case DOM_HTML_ELEMENT_TYPE_H4:
1682 case DOM_HTML_ELEMENT_TYPE_H5:
1683 case DOM_HTML_ELEMENT_TYPE_H6:
1686 case DOM_HTML_ELEMENT_TYPE_CENTER:
1689 case DOM_HTML_ELEMENT_TYPE_CAPTION:
1692 case DOM_HTML_ELEMENT_TYPE_DIV:
1695 case DOM_HTML_ELEMENT_TYPE_TABLE:
1702 case DOM_HTML_ELEMENT_TYPE_HR:
1706 case DOM_HTML_ELEMENT_TYPE_TEXTAREA:
1709 case DOM_HTML_ELEMENT_TYPE_INPUT:
1712 case DOM_HTML_ELEMENT_TYPE_A:
1715 case DOM_HTML_ELEMENT_TYPE_FONT:
1718 case DOM_HTML_ELEMENT_TYPE_BODY:
1721 case DOM_HTML_ELEMENT_TYPE_CANVAS:
1724 case DOM_HTML_ELEMENT_TYPE_OL:
1731 if (tag_type != DOM_HTML_ELEMENT_TYPE__UNKNOWN) {
static os_mode mode
The current sprite mode.
Useful interned string pointers (interface).
nserror
Enumeration of error codes.
@ NSERROR_NOMEM
Memory exhaustion.
css_error node_presentational_hint(void *pw, void *node, uint32_t *nhints, css_hint **hints)
Callback to retrieve presentational hints for a node.
static void css_hint_advance(struct css_hint **hint)
static void css_hint_margin_hspace_vspace(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_bg_image(nscss_select_ctx *ctx, dom_node *node)
struct css_hint_ctx hint_ctx
static bool parse_dimension(const char *data, bool strict, css_fixed *length, css_unit *unit)
Parse a dimension string.
static void css_hint_table_cell_border_padding(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_height(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_text_align_special(nscss_select_ctx *ctx, dom_node *node)
static bool isWhitespace(char c)
Determine if a given character is whitespace.
static void css_hint_float(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_body_color(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_get_hints(struct css_hint **hints, uint32_t *nhints)
static void css_hint_margin_left_right_hr(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_vertical_align_table_cells(nscss_select_ctx *ctx, dom_node *node)
static bool isHex(char c)
Determine if a given character is a valid hex digit.
static void css_hint_margin_left_right_align_center(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_color(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_table_spacing_border(nscss_select_ctx *ctx, dom_node *node)
bool nscss_parse_colour(const char *data, css_color *result)
Parser for colours specified in attribute values.
static void css_hint_caption_side(nscss_select_ctx *ctx, dom_node *node)
static uint8_t charToHex(char c)
Convert a character representing a hex digit to the corresponding hex value.
static bool parse_number(const char *data, bool maybe_negative, bool real, css_fixed *value, size_t *consumed)
Parse a number string.
static void css_hint_vertical_align_replaced(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_clean(void)
static void css_hint_list(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_anchor_color(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_bg_color(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_height_width_textarea(nscss_select_ctx *ctx, dom_node *node)
#define MAX_HINTS_PER_ELEMENT
static void css_hint_width(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_font_size(nscss_select_ctx *ctx, dom_node *node)
static void css_hint_text_align_normal(nscss_select_ctx *ctx, dom_node *node)
nserror css_hint_init(void)
static void css_hint_width_input(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_white_space_nowrap(nscss_select_ctx *ctx, dom_node *node)
static bool parse_font_size(const char *size, uint8_t *val, css_fixed *len, css_unit *unit)
Parse a font @size attribute.
static int cmp_colour_name(const void *a, const void *b)
Name comparator for named colour matching.
static bool parse_named_colour(const char *name, css_color *result)
Parse a named colour.
#define NSLOG(catname, level, logmsg, args...)
NetSurf URL handling (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
size_t nsurl_length(const nsurl *url)
Find the length of a NetSurf URL object's URL, as returned by nsurl_access.
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
Join a base url to a relative link part, creating a new NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
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.
css_error named_ancestor_node(void *pw, void *node, const css_qname *qname, void **ancestor)
Callback to find a named ancestor node.
Interface to utility string handling.
Mapping of colour name to CSS color.
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Interface to a number of general purpose functionality.
#define fallthrough
switch fall through
#define SLEN(x)
Calculate length of constant C string.