|
|
@@ -2058,6 +2058,15 @@ static int parse_svg_viewbox(const char *s, unsigned int len,
|
|
|
i++;
|
|
|
any = 1;
|
|
|
}
|
|
|
+ /* viewBox values are commonly fractional ("0 0 340.16
|
|
|
+ * 340.16"). Consume the fraction so it is not mistaken for
|
|
|
+ * the next number; the integer part is enough for the aspect
|
|
|
+ * ratio used by the renderer. */
|
|
|
+ if (i < len && s[i] == '.') {
|
|
|
+ i++;
|
|
|
+ while (i < len && s[i] >= '0' && s[i] <= '9')
|
|
|
+ i++;
|
|
|
+ }
|
|
|
if (!any) {
|
|
|
if (i < len)
|
|
|
i++;
|
|
|
@@ -2307,6 +2316,83 @@ static int str_eq(const char *a, const char *b)
|
|
|
|
|
|
/* ---- CSS ---- */
|
|
|
|
|
|
+static int parse_color(const char *s, unsigned int len, unsigned short *out);
|
|
|
+
|
|
|
+int br_parse_color(const char *s, unsigned int len, unsigned short *out)
|
|
|
+{
|
|
|
+ return parse_color(s, len, out);
|
|
|
+}
|
|
|
+
|
|
|
+/* SVG paint value -> BR_PAINT_* (0 when unrecognised). */
|
|
|
+static int paint_mode(const char *s, unsigned int len, unsigned short *c)
|
|
|
+{
|
|
|
+ while (len && is_space(*s)) {
|
|
|
+ s++;
|
|
|
+ len--;
|
|
|
+ }
|
|
|
+ while (len && is_space(s[len - 1]))
|
|
|
+ len--;
|
|
|
+ if (!len)
|
|
|
+ return 0;
|
|
|
+ if (len == 4 && ci_eq_n(s, "none", 4))
|
|
|
+ return BR_PAINT_NONE;
|
|
|
+ if (len == 12 && ci_eq_n(s, "currentcolor", 12))
|
|
|
+ return BR_PAINT_CURRENT;
|
|
|
+ if (len > 4 && ci_eq_n(s, "url(", 4))
|
|
|
+ return BR_PAINT_URL;
|
|
|
+ if (len == 11 && ci_eq_n(s, "transparent", 11))
|
|
|
+ return BR_PAINT_NONE;
|
|
|
+ if (parse_color(s, len, c))
|
|
|
+ return BR_PAINT_COLOR;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/* A plain SVG length ("1.5", "2px") in 1/16 units; -1 when not a number. */
|
|
|
+static int svg_len16(const char *s, unsigned int len)
|
|
|
+{
|
|
|
+ unsigned int i = 0;
|
|
|
+ int v = 0, frac = 0, digits = 0;
|
|
|
+
|
|
|
+ while (i < len && is_space(s[i]))
|
|
|
+ i++;
|
|
|
+ while (i < len && s[i] >= '0' && s[i] <= '9') {
|
|
|
+ if (v < 4000)
|
|
|
+ v = v * 10 + (s[i] - '0');
|
|
|
+ i++;
|
|
|
+ digits++;
|
|
|
+ }
|
|
|
+ if (i < len && s[i] == '.') {
|
|
|
+ int scale = 1;
|
|
|
+
|
|
|
+ i++;
|
|
|
+ while (i < len && s[i] >= '0' && s[i] <= '9') {
|
|
|
+ if (scale < 10000) {
|
|
|
+ frac = frac * 10 + (s[i] - '0');
|
|
|
+ scale *= 10;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ digits++;
|
|
|
+ }
|
|
|
+ frac = frac * 16 / scale;
|
|
|
+ }
|
|
|
+ if (!digits)
|
|
|
+ return -1;
|
|
|
+ return v * 16 + frac;
|
|
|
+}
|
|
|
+
|
|
|
+/* Inside an <svg> subtree (including the <svg> element itself). */
|
|
|
+static int in_svg(const struct br_doc *d, unsigned int node)
|
|
|
+{
|
|
|
+ unsigned int k;
|
|
|
+
|
|
|
+ for (k = 0; node && node < d->nnode && k < 64; k++) {
|
|
|
+ if (d->nodes[node].tag == BR_TAG_SVG)
|
|
|
+ return 1;
|
|
|
+ node = d->nodes[node].parent;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
enum {
|
|
|
PROP_COLOR, PROP_BG, PROP_BG_IMAGE, PROP_BG_REPEAT,
|
|
|
PROP_BG_POS_X_KIND, PROP_BG_POS_X, PROP_BG_POS_Y_KIND, PROP_BG_POS_Y,
|
|
|
@@ -2322,6 +2408,7 @@ enum {
|
|
|
PROP_BW_T, PROP_BW_R, PROP_BW_B, PROP_BW_L,
|
|
|
PROP_BC_T, PROP_BC_R, PROP_BC_B, PROP_BC_L,
|
|
|
PROP_BS_T, PROP_BS_R, PROP_BS_B, PROP_BS_L,
|
|
|
+ PROP_BT_T, PROP_BT_R, PROP_BT_B, PROP_BT_L,
|
|
|
PROP_RADIUS_TL, PROP_RADIUS_TR, PROP_RADIUS_BR, PROP_RADIUS_BL,
|
|
|
PROP_LIST_NONE, PROP_LIST_STYLE, PROP_NOWRAP,
|
|
|
PROP_WIDTH, PROP_WIDTH_KIND, PROP_MAXW, PROP_MAXW_KIND,
|
|
|
@@ -2346,6 +2433,8 @@ enum {
|
|
|
PROP_TRANSFORM_PAINT, PROP_SCALE_X, PROP_SCALE_Y, PROP_ROTATE,
|
|
|
PROP_ORIGIN_X_KIND, PROP_ORIGIN_X, PROP_ORIGIN_Y_KIND, PROP_ORIGIN_Y,
|
|
|
PROP_VIS_HIDDEN, PROP_OPACITY_HIDDEN, PROP_OVERFLOW_HIDDEN,
|
|
|
+ PROP_FILL_MODE, PROP_FILL, PROP_STROKE_MODE, PROP_STROKE,
|
|
|
+ PROP_STROKE_W, PROP_FILL_RULE,
|
|
|
PROP_COUNT
|
|
|
};
|
|
|
|
|
|
@@ -2531,6 +2620,40 @@ static int parse_color(const char *s, unsigned int len, unsigned short *out)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/* Fully transparent colours have no RGB565 representation. They are common
|
|
|
+ * as pre-allocated borders ("border:.1rem solid #0000") that become visible
|
|
|
+ * only on hover; painting them black would draw an outline around every
|
|
|
+ * pill and card. */
|
|
|
+static int color_is_transparent(const char *s, unsigned int len)
|
|
|
+{
|
|
|
+ unsigned int i = 0, n = 0;
|
|
|
+ int last = 0, prev = 0, d;
|
|
|
+
|
|
|
+ while (i < len && is_space(s[i]))
|
|
|
+ i++;
|
|
|
+ if (i + 11 <= len && ci_eq_n(s + i, "transparent", 11))
|
|
|
+ return 1;
|
|
|
+ if (i >= len || s[i] != '#')
|
|
|
+ return 0;
|
|
|
+ i++;
|
|
|
+ while (i < len && hexval(s[i]) >= 0) {
|
|
|
+ d = hexval(s[i]);
|
|
|
+ prev = last;
|
|
|
+ last = d;
|
|
|
+ n++;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ while (i < len && is_space(s[i]))
|
|
|
+ i++;
|
|
|
+ if (i != len)
|
|
|
+ return 0;
|
|
|
+ if (n == 4)
|
|
|
+ return last == 0;
|
|
|
+ if (n == 8)
|
|
|
+ return prev == 0 && last == 0;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
static int register_bg_url(const char *s, unsigned int len)
|
|
|
{
|
|
|
unsigned int i, j, n;
|
|
|
@@ -2587,10 +2710,12 @@ static int parse_len(const char *s, unsigned int len, unsigned int *pos)
|
|
|
}
|
|
|
if (i < len && s[i] == '.') {
|
|
|
i++;
|
|
|
+ /* Minified CSS writes ".5rem" without a leading zero. */
|
|
|
while (i < len && s[i] >= '0' && s[i] <= '9') {
|
|
|
if (frac < 2) {
|
|
|
v = v * 10 + (s[i] - '0');
|
|
|
frac++;
|
|
|
+ digits = 1;
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
@@ -2663,10 +2788,13 @@ static int parse_css_len(const char *s, unsigned int len,
|
|
|
}
|
|
|
if (i < len && s[i] == '.') {
|
|
|
i++;
|
|
|
+ /* Leading-dot fractions are common in minified CSS
|
|
|
+ * (".5rem", ".3rem"). */
|
|
|
while (i < len && s[i] >= '0' && s[i] <= '9') {
|
|
|
if (frac < 2) {
|
|
|
v = v * 10 + (s[i] - '0');
|
|
|
frac++;
|
|
|
+ digits = 1;
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
@@ -2838,6 +2966,7 @@ static int parse_size(const char *s, unsigned int len, unsigned short *val,
|
|
|
if (frac < 2) {
|
|
|
v = v * 10 + (unsigned int)(s[i] - '0');
|
|
|
frac++;
|
|
|
+ digits = 1;
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
@@ -2919,6 +3048,7 @@ static int parse_font_px(const char *s, unsigned int len)
|
|
|
frac = frac * 10 + (s[i] - '0');
|
|
|
fscale *= 10;
|
|
|
}
|
|
|
+ digits = 1;
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
@@ -3004,7 +3134,9 @@ static int parse_font_size(const char *s, unsigned int len,
|
|
|
*raw = (unsigned short)v100;
|
|
|
*unit = 2;
|
|
|
} else if (i < len && s[i] == '%') {
|
|
|
- *raw = (unsigned short)(v100 / 100);
|
|
|
+ /* Keep hundredths: 62.5% is a common root size and truncating
|
|
|
+ * it to 62% makes every rem 1px too small. */
|
|
|
+ *raw = (unsigned short)v100;
|
|
|
*unit = 4;
|
|
|
} else {
|
|
|
*raw = (unsigned short)(v100 / 100);
|
|
|
@@ -3037,6 +3169,7 @@ static int parse_line_height(const char *s, unsigned int len,
|
|
|
while (i < len && s[i] >= '0' && s[i] <= '9' && fscale < 1000) {
|
|
|
frac = frac * 10 + (s[i] - '0');
|
|
|
fscale *= 10;
|
|
|
+ digits = 1;
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
@@ -3049,6 +3182,12 @@ static int parse_line_height(const char *s, unsigned int len,
|
|
|
else if (i < len && s[i] == '%')
|
|
|
is_pct = 1;
|
|
|
v1000 = whole * 1000 + frac * 1000 / fscale;
|
|
|
+ /* rem is an absolute length (the root font is known by the time
|
|
|
+ * rules are parsed, as for font-size); em behaves like a multiplier. */
|
|
|
+ if (i + 3 <= len && ci_eq_n(s + i, "rem", 3)) {
|
|
|
+ v1000 = v1000 * root_font_px;
|
|
|
+ is_px = 1;
|
|
|
+ }
|
|
|
if (is_px) {
|
|
|
int v = v1000 / 1000;
|
|
|
|
|
|
@@ -3064,8 +3203,8 @@ static int parse_line_height(const char *s, unsigned int len,
|
|
|
v = v1000 / 1000;
|
|
|
if (v < 50)
|
|
|
v = 50;
|
|
|
- if (v > 400)
|
|
|
- v = 400;
|
|
|
+ if (v > 255) /* stored in an unsigned char */
|
|
|
+ v = 255;
|
|
|
*pct = (unsigned char)v;
|
|
|
}
|
|
|
return 1;
|
|
|
@@ -3145,6 +3284,14 @@ static int parse_display(const char *s, unsigned int len)
|
|
|
if (i == 4 && ci_eq_n(s, "flex", 4))
|
|
|
return BR_DISPLAY_FLEX;
|
|
|
if (i == 11 && ci_eq_n(s, "inline-flex", 11))
|
|
|
+ return BR_DISPLAY_FLEX | BR_DISPLAY_INLINE_FLAG;
|
|
|
+ /* Legacy -webkit-box is the line-clamp idiom; render it as a normal
|
|
|
+ * block instead of an inline box. */
|
|
|
+ if (i == 11 && ci_eq_n(s, "-webkit-box", 11))
|
|
|
+ return BR_DISPLAY_BLOCK;
|
|
|
+ if (i == 8 && ci_eq_n(s, "-moz-box", 8))
|
|
|
+ return BR_DISPLAY_BLOCK;
|
|
|
+ if (i == 11 && ci_eq_n(s, "-ms-flexbox", 11))
|
|
|
return BR_DISPLAY_FLEX;
|
|
|
if (i == 5 && ci_eq_n(s, "table", 5))
|
|
|
return BR_DISPLAY_BLOCK;
|
|
|
@@ -3207,8 +3354,10 @@ static int bg_number(const char *s, unsigned int len, signed short *val,
|
|
|
}
|
|
|
if (i < len && s[i] == '.') {
|
|
|
i++;
|
|
|
- while (i < len && s[i] >= '0' && s[i] <= '9')
|
|
|
+ while (i < len && s[i] >= '0' && s[i] <= '9') {
|
|
|
+ digits = 1;
|
|
|
i++;
|
|
|
+ }
|
|
|
}
|
|
|
if (!digits)
|
|
|
return 0;
|
|
|
@@ -3477,6 +3626,7 @@ static int parse_fixed_100(const char *s, unsigned int len,
|
|
|
if (fd < 2) {
|
|
|
frac = frac * 10 + (s[i] - '0');
|
|
|
fd++;
|
|
|
+ digits = 1;
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
@@ -4432,34 +4582,32 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
unsigned short c;
|
|
|
if (parse_color(s + vstart, vend - vstart, &c))
|
|
|
decl_add(out, nout, PROP_COLOR, c, important);
|
|
|
- } else if (str_eq(prop, "fill")) {
|
|
|
- unsigned short c;
|
|
|
-
|
|
|
- if (parse_color(s + vstart, vend - vstart, &c)) {
|
|
|
- decl_add(out, nout, PROP_BG, c, important);
|
|
|
- decl_add(out, nout, PROP_COLOR, c, important);
|
|
|
- }
|
|
|
- } else if (str_eq(prop, "stroke")) {
|
|
|
+ } else if (str_eq(prop, "fill") || str_eq(prop, "stroke")) {
|
|
|
+ /* SVG paint only: an HTML element's fill never paints
|
|
|
+ * its background (tagesschau sets fill on buttons). */
|
|
|
+ int is_fill = prop[0] == 'f';
|
|
|
unsigned short c;
|
|
|
-
|
|
|
- if (parse_color(s + vstart, vend - vstart, &c)) {
|
|
|
- decl_add(out, nout, PROP_BORDER_COLOR, c,
|
|
|
- important);
|
|
|
- decl_add(out, nout, PROP_BORDER_W, 1, important);
|
|
|
+ int mode = paint_mode(s + vstart, vend - vstart, &c);
|
|
|
+
|
|
|
+ if (mode) {
|
|
|
+ decl_add(out, nout, is_fill ? PROP_FILL_MODE :
|
|
|
+ PROP_STROKE_MODE, mode, important);
|
|
|
+ if (mode == BR_PAINT_COLOR)
|
|
|
+ decl_add(out, nout, is_fill ? PROP_FILL :
|
|
|
+ PROP_STROKE, (short)c,
|
|
|
+ important);
|
|
|
}
|
|
|
} else if (str_eq(prop, "stroke-width")) {
|
|
|
- unsigned int j = vstart;
|
|
|
- int sw = 0;
|
|
|
+ int sw = svg_len16(s + vstart, vend - vstart);
|
|
|
|
|
|
- while (j < vend && s[j] >= '0' && s[j] <= '9') {
|
|
|
- sw = sw * 10 + (s[j] - '0');
|
|
|
- j++;
|
|
|
- }
|
|
|
- if (sw < 1)
|
|
|
- sw = 1;
|
|
|
- if (sw > 3)
|
|
|
- sw = 3;
|
|
|
- decl_add(out, nout, PROP_BORDER_W, sw, important);
|
|
|
+ if (sw >= 0)
|
|
|
+ decl_add(out, nout, PROP_STROKE_W, sw,
|
|
|
+ important);
|
|
|
+ } else if (str_eq(prop, "fill-rule")) {
|
|
|
+ decl_add(out, nout, PROP_FILL_RULE,
|
|
|
+ contains_ci_len(s + vstart, vend - vstart,
|
|
|
+ "evenodd") ? 1 : 0,
|
|
|
+ important);
|
|
|
} else if (str_eq(prop, "text-anchor")) {
|
|
|
int a = BR_ALIGN_LEFT;
|
|
|
|
|
|
@@ -5209,7 +5357,7 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
const char *v = s + vstart;
|
|
|
unsigned int vl = vend - vstart;
|
|
|
unsigned int pos = 0, ts, te;
|
|
|
- int widths[4], colors[4], styles[4];
|
|
|
+ int widths[4], colors[4], styles[4], trans[4];
|
|
|
int nw = 0, nc = 0, ns = 0;
|
|
|
int side = -1;
|
|
|
int is_wl = str_eq(prop, "border-width");
|
|
|
@@ -5274,26 +5422,42 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
}
|
|
|
} else if (is_cl) {
|
|
|
unsigned short c;
|
|
|
+ int t;
|
|
|
|
|
|
while (nc < 4 && next_token(v, vl, &pos,
|
|
|
&ts, &te)) {
|
|
|
- if (!parse_color(v + ts, te - ts, &c))
|
|
|
+ t = color_is_transparent(v + ts,
|
|
|
+ te - ts);
|
|
|
+ if (!t && !parse_color(v + ts,
|
|
|
+ te - ts, &c))
|
|
|
break;
|
|
|
- colors[nc++] = c;
|
|
|
+ colors[nc] = t ? 0 : c;
|
|
|
+ trans[nc] = t;
|
|
|
+ nc++;
|
|
|
}
|
|
|
if (nc) {
|
|
|
- if (is_cl == 1)
|
|
|
+ if (is_cl == 1) {
|
|
|
expand_four(colors, nc);
|
|
|
+ expand_four(trans, nc);
|
|
|
+ }
|
|
|
if (side >= 0 && is_cl == 2) {
|
|
|
decl_add(out, nout,
|
|
|
PROP_BC_T + side,
|
|
|
colors[0], important);
|
|
|
+ decl_add(out, nout,
|
|
|
+ PROP_BT_T + side,
|
|
|
+ trans[0], important);
|
|
|
} else {
|
|
|
- for (i = 0; i < 4; i++)
|
|
|
+ for (i = 0; i < 4; i++) {
|
|
|
decl_add(out, nout,
|
|
|
PROP_BC_T + i,
|
|
|
colors[i],
|
|
|
important);
|
|
|
+ decl_add(out, nout,
|
|
|
+ PROP_BT_T + i,
|
|
|
+ trans[i],
|
|
|
+ important);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else if (is_sl) {
|
|
|
@@ -5348,7 +5512,7 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
}
|
|
|
} else {
|
|
|
int bw = -1, bc = -1, style_none = 0;
|
|
|
- int bstyle = -1;
|
|
|
+ int bstyle = -1, btrans = 0;
|
|
|
|
|
|
while (next_token(v, vl, &pos, &ts, &te)) {
|
|
|
unsigned short c;
|
|
|
@@ -5371,9 +5535,14 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
} else if (parse_len_token(v + ts,
|
|
|
te - ts, &x)) {
|
|
|
bw = x;
|
|
|
+ } else if (color_is_transparent(v + ts,
|
|
|
+ te - ts)) {
|
|
|
+ bc = 0;
|
|
|
+ btrans = 1;
|
|
|
} else if (parse_color(v + ts,
|
|
|
te - ts, &c)) {
|
|
|
bc = c;
|
|
|
+ btrans = 0;
|
|
|
}
|
|
|
}
|
|
|
if (style_none)
|
|
|
@@ -5389,6 +5558,12 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
decl_add(out, nout,
|
|
|
PROP_BORDER_COLOR, bc,
|
|
|
important);
|
|
|
+ if (bc >= 0)
|
|
|
+ for (i = 0; i < 4; i++)
|
|
|
+ decl_add(out, nout,
|
|
|
+ PROP_BT_T + i,
|
|
|
+ btrans,
|
|
|
+ important);
|
|
|
if (bstyle >= 0)
|
|
|
for (i = 0; i < 4; i++)
|
|
|
decl_add(out, nout,
|
|
|
@@ -5404,6 +5579,10 @@ static void parse_decls(struct br_doc *d, const char *s,
|
|
|
decl_add(out, nout,
|
|
|
PROP_BC_T + side, bc,
|
|
|
important);
|
|
|
+ if (bc >= 0)
|
|
|
+ decl_add(out, nout,
|
|
|
+ PROP_BT_T + side,
|
|
|
+ btrans, important);
|
|
|
if (bstyle >= 0)
|
|
|
decl_add(out, nout,
|
|
|
PROP_BS_T + side,
|
|
|
@@ -5774,6 +5953,70 @@ static unsigned int selector_specificity(const char *s, unsigned int len);
|
|
|
|
|
|
static int css_collect_only;
|
|
|
|
|
|
+/* Simple structural pseudo-classes that can be answered from the node tree.
|
|
|
+ * Returns the token length or 0. Kept in sync with compound_match(). */
|
|
|
+static unsigned int structural_pseudo_len(const char *s, unsigned int i,
|
|
|
+ unsigned int end)
|
|
|
+{
|
|
|
+ static const struct {
|
|
|
+ const char *name;
|
|
|
+ unsigned char len;
|
|
|
+ } p[] = {
|
|
|
+ { ":first-child", 12 }, { ":last-child", 11 },
|
|
|
+ { ":first-of-type", 14 }, { ":last-of-type", 13 },
|
|
|
+ { ":only-child", 11 }, { ":only-of-type", 13 },
|
|
|
+ };
|
|
|
+ unsigned int k;
|
|
|
+
|
|
|
+ for (k = 0; k < sizeof(p) / sizeof(p[0]); k++) {
|
|
|
+ unsigned int l = p[k].len;
|
|
|
+
|
|
|
+ if (i + l <= end && ci_eq_n(s + i, p[k].name, l) &&
|
|
|
+ (i + l == end || !is_ident(s[i + l])))
|
|
|
+ return l;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static int structural_pseudo_match(struct br_doc *d, unsigned int node,
|
|
|
+ const char *name, unsigned int len)
|
|
|
+{
|
|
|
+ unsigned int parent = d->nodes[node].parent;
|
|
|
+ unsigned int c;
|
|
|
+ int before = 0, after = 0;
|
|
|
+ int of_type = contains_ci_len(name, len, "of-type");
|
|
|
+ unsigned int tag = d->nodes[node].tag;
|
|
|
+
|
|
|
+ if (!parent)
|
|
|
+ /* The root element is the only element child of the
|
|
|
+ * document node. */
|
|
|
+ return 1;
|
|
|
+ for (c = d->nodes[parent].first; c && c != node;
|
|
|
+ c = d->nodes[c].next) {
|
|
|
+ if (d->nodes[c].type != BR_NODE_ELEM)
|
|
|
+ continue;
|
|
|
+ if (of_type && d->nodes[c].tag != tag)
|
|
|
+ continue;
|
|
|
+ before = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (c = d->nodes[node].next; c; c = d->nodes[c].next) {
|
|
|
+ if (d->nodes[c].type != BR_NODE_ELEM)
|
|
|
+ continue;
|
|
|
+ if (of_type && d->nodes[c].tag != tag)
|
|
|
+ continue;
|
|
|
+ after = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (contains_ci_len(name, len, "first"))
|
|
|
+ return !before;
|
|
|
+ if (contains_ci_len(name, len, "last"))
|
|
|
+ return !after;
|
|
|
+ if (contains_ci_len(name, len, "only"))
|
|
|
+ return !before && !after;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
static void parse_css(struct br_doc *d, const char *s, unsigned int len)
|
|
|
{
|
|
|
unsigned int i = 0;
|
|
|
@@ -5897,6 +6140,16 @@ static void parse_css(struct br_doc *d, const char *s, unsigned int len)
|
|
|
k = n;
|
|
|
continue;
|
|
|
}
|
|
|
+ {
|
|
|
+ unsigned int sl =
|
|
|
+ structural_pseudo_len(
|
|
|
+ s, k, e);
|
|
|
+
|
|
|
+ if (sl) {
|
|
|
+ k += sl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
k++;
|
|
|
@@ -6279,7 +6532,16 @@ static int compound_match(struct br_doc *d, unsigned int node, const char *s,
|
|
|
i = e + 1;
|
|
|
got = 1;
|
|
|
} else {
|
|
|
- return 0; /* other pseudo-classes are not modelled */
|
|
|
+ unsigned int sl = structural_pseudo_len(s, i,
|
|
|
+ len);
|
|
|
+
|
|
|
+ if (!sl)
|
|
|
+ return 0; /* other pseudo-classes are
|
|
|
+ * not modelled */
|
|
|
+ if (!structural_pseudo_match(d, node, s + i, sl))
|
|
|
+ return 0;
|
|
|
+ i += sl;
|
|
|
+ got = 1;
|
|
|
}
|
|
|
} else {
|
|
|
i++;
|
|
|
@@ -6574,7 +6836,9 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
|
|
|
st->overline = (unsigned char)(dcl->val != 0);
|
|
|
break;
|
|
|
case PROP_DISPLAY:
|
|
|
- st->display = (unsigned char)dcl->val;
|
|
|
+ st->display = (unsigned char)(dcl->val &
|
|
|
+ ~BR_DISPLAY_INLINE_FLAG);
|
|
|
+ st->inline_flex = (dcl->val & BR_DISPLAY_INLINE_FLAG) != 0;
|
|
|
st->list_item = 0;
|
|
|
break;
|
|
|
case PROP_VIS_HIDDEN:
|
|
|
@@ -6583,6 +6847,24 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
|
|
|
case PROP_OPACITY_HIDDEN:
|
|
|
st->opacity_hidden = (unsigned char)(dcl->val != 0);
|
|
|
break;
|
|
|
+ case PROP_FILL_MODE:
|
|
|
+ st->fill_mode = (unsigned char)dcl->val;
|
|
|
+ break;
|
|
|
+ case PROP_FILL:
|
|
|
+ st->fill = (unsigned short)dcl->val;
|
|
|
+ break;
|
|
|
+ case PROP_STROKE_MODE:
|
|
|
+ st->stroke_mode = (unsigned char)dcl->val;
|
|
|
+ break;
|
|
|
+ case PROP_STROKE:
|
|
|
+ st->stroke = (unsigned short)dcl->val;
|
|
|
+ break;
|
|
|
+ case PROP_STROKE_W:
|
|
|
+ st->stroke_w = (unsigned short)dcl->val;
|
|
|
+ break;
|
|
|
+ case PROP_FILL_RULE:
|
|
|
+ st->fill_evenodd = (unsigned char)(dcl->val != 0);
|
|
|
+ break;
|
|
|
case PROP_OVERFLOW_HIDDEN:
|
|
|
st->overflow_hidden = (unsigned char)(dcl->val != 0);
|
|
|
break;
|
|
|
@@ -6641,6 +6923,10 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
|
|
|
case PROP_BS_R: st->border_s[1] = (unsigned char)dcl->val; break;
|
|
|
case PROP_BS_B: st->border_s[2] = (unsigned char)dcl->val; break;
|
|
|
case PROP_BS_L: st->border_s[3] = (unsigned char)dcl->val; break;
|
|
|
+ case PROP_BT_T: st->border_t[0] = (unsigned char)dcl->val; break;
|
|
|
+ case PROP_BT_R: st->border_t[1] = (unsigned char)dcl->val; break;
|
|
|
+ case PROP_BT_B: st->border_t[2] = (unsigned char)dcl->val; break;
|
|
|
+ case PROP_BT_L: st->border_t[3] = (unsigned char)dcl->val; break;
|
|
|
case PROP_RADIUS_TL:
|
|
|
case PROP_RADIUS_TR:
|
|
|
case PROP_RADIUS_BR:
|
|
|
@@ -6924,6 +7210,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
|
|
|
out->origin_x = out->origin_y = 50;
|
|
|
out->origin_x_kind = out->origin_y_kind = 1;
|
|
|
out->vis_hidden = out->opacity_hidden = 0;
|
|
|
+ out->inline_flex = 0;
|
|
|
out->overflow_hidden = 0;
|
|
|
tag = d->nodes[node].tag;
|
|
|
out->display = br_tag_is_block(tag) ? BR_DISPLAY_BLOCK :
|
|
|
@@ -7021,6 +7308,12 @@ void br_style_for(struct br_doc *d, unsigned int node,
|
|
|
case BR_TAG_VIDEO:
|
|
|
out->display = BR_DISPLAY_BLOCK;
|
|
|
break;
|
|
|
+ case BR_TAG_SVG:
|
|
|
+ /* The renderer treats an SVG as one replaced box; keeping it
|
|
|
+ * block-level also gives it a usable intrinsic width inside
|
|
|
+ * flex items such as a header logo. */
|
|
|
+ out->display = BR_DISPLAY_BLOCK;
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -7054,6 +7347,47 @@ void br_style_for(struct br_doc *d, unsigned int node,
|
|
|
if (parse_color(v, s_len(v), &c))
|
|
|
out->color = c;
|
|
|
}
|
|
|
+ /* SVG presentation attributes; CSS declarations still win below. */
|
|
|
+ if (in_svg(d, node)) {
|
|
|
+ const char *fa = br_find_attr(d, node, "fill");
|
|
|
+ const char *sa = br_find_attr(d, node, "stroke");
|
|
|
+ const char *wa = br_find_attr(d, node, "stroke-width");
|
|
|
+ const char *ra = br_find_attr(d, node, "fill-rule");
|
|
|
+ const char *ca = br_find_attr(d, node, "color");
|
|
|
+ unsigned short c;
|
|
|
+ int mode;
|
|
|
+
|
|
|
+ if (ca && parse_color(ca, s_len(ca), &c))
|
|
|
+ out->color = c;
|
|
|
+ if (fa && (mode = paint_mode(fa, s_len(fa), &c)) != 0) {
|
|
|
+ out->fill_mode = (unsigned char)mode;
|
|
|
+ if (mode == BR_PAINT_COLOR)
|
|
|
+ out->fill = c;
|
|
|
+ }
|
|
|
+ if (sa && (mode = paint_mode(sa, s_len(sa), &c)) != 0) {
|
|
|
+ out->stroke_mode = (unsigned char)mode;
|
|
|
+ if (mode == BR_PAINT_COLOR)
|
|
|
+ out->stroke = c;
|
|
|
+ }
|
|
|
+ if (wa) {
|
|
|
+ int sw = svg_len16(wa, s_len(wa));
|
|
|
+
|
|
|
+ if (sw >= 0)
|
|
|
+ out->stroke_w = (unsigned short)sw;
|
|
|
+ }
|
|
|
+ if (ra)
|
|
|
+ out->fill_evenodd = same_string(ra, "evenodd");
|
|
|
+ }
|
|
|
+
|
|
|
+ /* UA behaviour for a closed <details>: only its <summary> is shown.
|
|
|
+ * Author CSS below can still override this. */
|
|
|
+ if (tag != BR_TAG_SUMMARY && d->nodes[node].parent) {
|
|
|
+ unsigned int p = d->nodes[node].parent;
|
|
|
+
|
|
|
+ if (p < d->nnode && d->nodes[p].tag == BR_TAG_DETAILS &&
|
|
|
+ !br_find_attr(d, p, "open"))
|
|
|
+ out->display = BR_DISPLAY_NONE;
|
|
|
+ }
|
|
|
|
|
|
rule_collect(d, node);
|
|
|
for (i = 0; i < nrule_matches; i++) {
|
|
|
@@ -7083,7 +7417,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
|
|
|
else if (out->font_unit == 3)
|
|
|
px = root_font_px * out->font_raw / 100;
|
|
|
else if (out->font_unit == 4)
|
|
|
- px = parent->font_px * out->font_raw / 100;
|
|
|
+ px = parent->font_px * out->font_raw / 10000;
|
|
|
if (px < 8)
|
|
|
px = 8;
|
|
|
if (px > 72)
|
|
|
@@ -7484,16 +7818,10 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
|
|
|
i = skip_element(html, len, i, name, n);
|
|
|
continue;
|
|
|
}
|
|
|
- if (tag == BR_TAG_DETAILS && !selfclose &&
|
|
|
- !has_attr_token(html + attr_start,
|
|
|
- attr_end - attr_start, "open")) {
|
|
|
- /* Closed <details> is collapsed (and this browser has
|
|
|
- * no script to open it); skipping the subtree keeps
|
|
|
- * mobile mega-menus out of the node arena. */
|
|
|
- int p = find_ci(html, len, "</details>", 10, i);
|
|
|
- i = p >= 0 ? (unsigned int)p + 10 : len;
|
|
|
- continue;
|
|
|
- }
|
|
|
+ /* A closed <details> is collapsed at style time, not
|
|
|
+ * parse time: the <summary> (the hamburger button on
|
|
|
+ * tagesschau and many mobile menus) must stay in the
|
|
|
+ * DOM. */
|
|
|
if (tag == BR_TAG_STYLE) {
|
|
|
int p = find_ci(html, len, "</style", 7, i);
|
|
|
unsigned int end = p >= 0 ? (unsigned int)p : len;
|