|
|
@@ -2331,6 +2331,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,
|
|
|
@@ -2540,6 +2541,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;
|
|
|
@@ -2596,10 +2631,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++;
|
|
|
}
|
|
|
@@ -2672,10 +2709,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++;
|
|
|
}
|
|
|
@@ -2847,6 +2887,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++;
|
|
|
}
|
|
|
@@ -2928,6 +2969,7 @@ static int parse_font_px(const char *s, unsigned int len)
|
|
|
frac = frac * 10 + (s[i] - '0');
|
|
|
fscale *= 10;
|
|
|
}
|
|
|
+ digits = 1;
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
@@ -3013,7 +3055,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);
|
|
|
@@ -3046,6 +3090,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++;
|
|
|
}
|
|
|
}
|
|
|
@@ -3224,8 +3269,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;
|
|
|
@@ -3494,6 +3541,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++;
|
|
|
}
|
|
|
@@ -5226,7 +5274,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");
|
|
|
@@ -5291,26 +5339,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) {
|
|
|
@@ -5365,7 +5429,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;
|
|
|
@@ -5388,9 +5452,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)
|
|
|
@@ -5406,6 +5475,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,
|
|
|
@@ -5421,6 +5496,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,
|
|
|
@@ -5791,6 +5870,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;
|
|
|
@@ -5914,6 +6057,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++;
|
|
|
@@ -6296,7 +6449,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++;
|
|
|
@@ -6658,6 +6820,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:
|
|
|
@@ -7132,7 +7298,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)
|