|
@@ -992,7 +992,9 @@ static int js_host_computed(unsigned int node, const char *property,
|
|
|
struct br_style st;
|
|
struct br_style st;
|
|
|
char name[40];
|
|
char name[40];
|
|
|
|
|
|
|
|
- if (!buf || cap <= 0 || node >= doc.nnode || node == 0)
|
|
|
|
|
|
|
+ /* Node 0 is a real element when the page starts with <html>. */
|
|
|
|
|
+ if (!buf || cap <= 0 || node >= doc.nnode ||
|
|
|
|
|
+ (node == 0 && doc.nodes[0].type != BR_NODE_ELEM))
|
|
|
return 0;
|
|
return 0;
|
|
|
buf[0] = '\0';
|
|
buf[0] = '\0';
|
|
|
css_computed_name(property, name, sizeof(name));
|
|
css_computed_name(property, name, sizeof(name));
|
|
@@ -4566,6 +4568,8 @@ static void preload_begin(void)
|
|
|
* menu/carousel are never visited and keep img_top == 0. Without this check
|
|
* menu/carousel are never visited and keep img_top == 0. Without this check
|
|
|
* the preloader walks the DOM in node order and spends the whole image
|
|
* the preloader walks the DOM in node order and spends the whole image
|
|
|
* budget on logos and off-canvas thumbnails the reader cannot see. */
|
|
* budget on logos and off-canvas thumbnails the reader cannot see. */
|
|
|
|
|
+static struct br_style base_style(void);
|
|
|
|
|
+
|
|
|
static int node_hidden(unsigned int node)
|
|
static int node_hidden(unsigned int node)
|
|
|
{
|
|
{
|
|
|
unsigned int path[32], n = 0, p = node, i;
|
|
unsigned int path[32], n = 0, p = node, i;
|
|
@@ -4575,9 +4579,17 @@ static int node_hidden(unsigned int node)
|
|
|
path[n++] = p;
|
|
path[n++] = p;
|
|
|
p = doc.nodes[p].parent;
|
|
p = doc.nodes[p].parent;
|
|
|
}
|
|
}
|
|
|
- parent = (struct br_style){0};
|
|
|
|
|
- parent.font_px = 16;
|
|
|
|
|
- parent.display = BR_DISPLAY_BLOCK;
|
|
|
|
|
|
|
+ /* Node 0 is the <html> element when the page starts with one: it
|
|
|
|
|
+ * is an ancestor too. Styles are cached per node, so the chain
|
|
|
|
|
+ * must start from the same base as style_for_node(); seeding it
|
|
|
|
|
+ * with a zeroed style left <body> cached with black text and no
|
|
|
|
|
+ * line-height once an image job ran (docs.cloudron.io). */
|
|
|
|
|
+ if (!p && n && n < sizeof(path) / sizeof(path[0]) &&
|
|
|
|
|
+ doc.nodes[0].type == BR_NODE_ELEM &&
|
|
|
|
|
+ doc.nodes[0].tag == BR_TAG_HTML &&
|
|
|
|
|
+ !(doc.nodes[path[n - 1]].flags & BR_NODE_DETACHED))
|
|
|
|
|
+ path[n++] = 0;
|
|
|
|
|
+ parent = base_style();
|
|
|
for (i = n; i > 0; i--) {
|
|
for (i = n; i > 0; i--) {
|
|
|
br_style_for(&doc, path[i - 1], &parent, &st);
|
|
br_style_for(&doc, path[i - 1], &parent, &st);
|
|
|
if (st.display == BR_DISPLAY_NONE || st.vis_hidden ||
|
|
if (st.display == BR_DISPLAY_NONE || st.vis_hidden ||
|
|
@@ -4597,7 +4609,12 @@ static void style_for_node(unsigned int node, struct br_style *out)
|
|
|
unsigned int p = doc.nodes[node].parent;
|
|
unsigned int p = doc.nodes[node].parent;
|
|
|
struct br_style parent;
|
|
struct br_style parent;
|
|
|
|
|
|
|
|
- if (p) {
|
|
|
|
|
|
|
+ /* Parent index 0 is ambiguous: it is the <html> element when the page
|
|
|
|
|
+ * starts with one (see root_style()), but also the parent field of a
|
|
|
|
|
+ * detached subtree root. */
|
|
|
|
|
+ if (p || (node != 0 && doc.nodes[0].type == BR_NODE_ELEM &&
|
|
|
|
|
+ doc.nodes[0].tag == BR_TAG_HTML &&
|
|
|
|
|
+ !(doc.nodes[node].flags & BR_NODE_DETACHED))) {
|
|
|
style_for_node(p, &parent);
|
|
style_for_node(p, &parent);
|
|
|
br_style_for(&doc, node, &parent, out);
|
|
br_style_for(&doc, node, &parent, out);
|
|
|
} else {
|
|
} else {
|
|
@@ -5930,6 +5947,43 @@ static struct br_style base_style(void)
|
|
|
return s;
|
|
return s;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* The style node 0's children inherit. Node 0 is the first parsed node:
|
|
|
|
|
+ * a minified page that starts `<!doctype html><html ...>` makes it the
|
|
|
|
|
+ * <html> element itself, and the layout walks only its children, so its
|
|
|
|
|
+ * own cascade (html { color; font } -- Docusaurus/Infima put the page
|
|
|
|
|
+ * colour and font there) used to be skipped and the theme defaults showed
|
|
|
|
|
+ * through. Only inherited properties are taken: the root's box (margins,
|
|
|
|
|
+ * display, background) is not a container style for its children here. */
|
|
|
|
|
+static struct br_style root_style(void)
|
|
|
|
|
+{
|
|
|
|
|
+ struct br_style base = base_style(), st;
|
|
|
|
|
+
|
|
|
|
|
+ if (!doc.nnode || doc.nodes[doc.root].type != BR_NODE_ELEM ||
|
|
|
|
|
+ doc.nodes[doc.root].tag != BR_TAG_HTML)
|
|
|
|
|
+ return base;
|
|
|
|
|
+ br_style_for(&doc, doc.root, &base, &st);
|
|
|
|
|
+ base.color = st.color;
|
|
|
|
|
+ base.font_px = st.font_px;
|
|
|
|
|
+ base.bold = st.bold;
|
|
|
|
|
+ base.italic = st.italic;
|
|
|
|
|
+ base.mono = st.mono;
|
|
|
|
|
+ base.font_face = st.font_face;
|
|
|
|
|
+ base.align = st.align;
|
|
|
|
|
+ base.line_h_pct = st.line_h_pct;
|
|
|
|
|
+ base.line_h_px = st.line_h_px;
|
|
|
|
|
+ base.nowrap = st.nowrap;
|
|
|
|
|
+ base.uppercase = st.uppercase;
|
|
|
|
|
+ base.cursor = st.cursor;
|
|
|
|
|
+ base.vis_hidden = st.vis_hidden;
|
|
|
|
|
+ base.fill_mode = st.fill_mode;
|
|
|
|
|
+ base.fill = st.fill;
|
|
|
|
|
+ base.stroke_mode = st.stroke_mode;
|
|
|
|
|
+ base.stroke = st.stroke;
|
|
|
|
|
+ base.stroke_w = st.stroke_w;
|
|
|
|
|
+ base.fill_evenodd = st.fill_evenodd;
|
|
|
|
|
+ return base;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* Resolve a margin/padding raw value. Percentages use the containing
|
|
/* Resolve a margin/padding raw value. Percentages use the containing
|
|
|
* block width for all four sides, as CSS specifies. */
|
|
* block width for all four sides, as CSS specifies. */
|
|
|
static int css_mp_px(const struct br_style *st, int v, int unit, int base)
|
|
static int css_mp_px(const struct br_style *st, int v, int unit, int base)
|
|
@@ -6920,14 +6974,20 @@ static void add_image_run(struct lay *l, unsigned int node,
|
|
|
maxw * (int)st->width / 100 :
|
|
maxw * (int)st->width / 100 :
|
|
|
(int)st->width;
|
|
(int)st->width;
|
|
|
}
|
|
}
|
|
|
- if (st->height_kind) {
|
|
|
|
|
|
|
+ /* Percentage heights resolve against the containing block's
|
|
|
|
|
+ * definite height (Docusaurus' logo: `.navbar__logo { height:
|
|
|
|
|
+ * 2rem }` holding an `img { height: 100% }`), and are auto
|
|
|
|
|
+ * when it has none; they used to use the width. */
|
|
|
|
|
+ if (st->height_kind == 1 ||
|
|
|
|
|
+ ((st->height_kind == 2 || st->height_kind == 3) &&
|
|
|
|
|
+ l->cb_h > 0)) {
|
|
|
css_h = 1;
|
|
css_h = 1;
|
|
|
if (st->height_kind == 3)
|
|
if (st->height_kind == 3)
|
|
|
- dh = maxw * st->height_calc_pct / 100 +
|
|
|
|
|
|
|
+ dh = l->cb_h * st->height_calc_pct / 100 +
|
|
|
st->height_calc_px;
|
|
st->height_calc_px;
|
|
|
else
|
|
else
|
|
|
dh = st->height_kind == 2 ?
|
|
dh = st->height_kind == 2 ?
|
|
|
- maxw * (int)st->height / 100 :
|
|
|
|
|
|
|
+ l->cb_h * (int)st->height / 100 :
|
|
|
(int)st->height;
|
|
(int)st->height;
|
|
|
}
|
|
}
|
|
|
if (css_w && !css_h)
|
|
if (css_w && !css_h)
|
|
@@ -7355,6 +7415,12 @@ static void add_form_run(struct lay *l, unsigned int node,
|
|
|
kind == FORM_RESET) {
|
|
kind == FORM_RESET) {
|
|
|
if (fs->len)
|
|
if (fs->len)
|
|
|
text = fs->value;
|
|
text = fs->value;
|
|
|
|
|
+ else if (doc.nodes[node].tag == BR_TAG_BUTTON)
|
|
|
|
|
+ /* A <button>'s label is its content: an empty one
|
|
|
|
|
+ * (Docusaurus' sidebar caret, drawn by a CSS
|
|
|
|
|
+ * ::before icon) shows none. Only <input> buttons
|
|
|
|
|
+ * get the UA's default label. */
|
|
|
|
|
+ text = "";
|
|
|
else
|
|
else
|
|
|
text = kind == FORM_SUBMIT ? "Submit" :
|
|
text = kind == FORM_SUBMIT ? "Submit" :
|
|
|
kind == FORM_RESET ? "Reset" : "Button";
|
|
kind == FORM_RESET ? "Reset" : "Button";
|
|
@@ -7611,7 +7677,7 @@ static int flex_wants_row(unsigned int parent, const struct br_style *pst)
|
|
|
cs.width_kind || cs.has_bg ||
|
|
cs.width_kind || cs.has_bg ||
|
|
|
cs.border_w[0] || cs.border_w[1] ||
|
|
cs.border_w[0] || cs.border_w[1] ||
|
|
|
cs.border_w[2] || cs.border_w[3] ||
|
|
cs.border_w[2] || cs.border_w[3] ||
|
|
|
- nd->tag == BR_TAG_IMG)
|
|
|
|
|
|
|
+ nd->tag == BR_TAG_IMG || nd->tag == BR_TAG_SVG)
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
@@ -8681,6 +8747,19 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
l->y = flow_y + block_h[parent] - st->bottom -
|
|
l->y = flow_y + block_h[parent] - st->bottom -
|
|
|
style_height_px(st, old_right - old_left);
|
|
style_height_px(st, old_right - old_left);
|
|
|
}
|
|
}
|
|
|
|
|
+ /* `left: 100%` parks a box (Docusaurus' "Skip to main
|
|
|
|
|
+ * content" link) past the containing block's right edge
|
|
|
|
|
+ * until it is focused. An auto width then has no room: it
|
|
|
|
|
+ * used to collapse to 8 px and wrap one word per line into a
|
|
|
|
|
+ * tall column painted over the page. Lay it out at the
|
|
|
|
|
+ * containing block's width so it stays one line and
|
|
|
|
|
+ * overflows (off-screen) like in a real browser. */
|
|
|
|
|
+ if (def_w < 0 && l->right - l->left < 8) {
|
|
|
|
|
+ int avail = st->pos == 2 ? page_rect.w - 12 :
|
|
|
|
|
+ flow_right - flow_left;
|
|
|
|
|
+
|
|
|
|
|
+ l->right = l->left + (avail > 8 ? avail : 8);
|
|
|
|
|
+ }
|
|
|
old_left = l->left;
|
|
old_left = l->left;
|
|
|
old_right = l->right;
|
|
old_right = l->right;
|
|
|
} else if (relative) {
|
|
} else if (relative) {
|
|
@@ -9258,7 +9337,15 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
} else if (nd->height_attr && iw && ih) {
|
|
} else if (nd->height_attr && iw && ih) {
|
|
|
line_w += iw * (int)nd->height_attr / ih;
|
|
line_w += iw * (int)nd->height_attr / ih;
|
|
|
} else if (cs.height_kind && iw && ih) {
|
|
} else if (cs.height_kind && iw && ih) {
|
|
|
- int hh = style_height_px(&cs, base);
|
|
|
|
|
|
|
+ /* A percentage height needs the parent's
|
|
|
|
|
+ * definite height (the logo's 2rem box), as in
|
|
|
|
|
+ * add_image_run(); otherwise it is auto. */
|
|
|
|
|
+ int hh = cs.height_kind == 1 ?
|
|
|
|
|
+ style_height_px(&cs, base) :
|
|
|
|
|
+ cs.height_kind == 2 &&
|
|
|
|
|
+ pst->height_kind == 1 ?
|
|
|
|
|
+ (int)pst->height * (int)cs.height / 100 :
|
|
|
|
|
+ 0;
|
|
|
|
|
|
|
|
line_w += hh > 0 ? iw * hh / ih : iw;
|
|
line_w += hh > 0 ? iw * hh / ih : iw;
|
|
|
} else if (iw) {
|
|
} else if (iw) {
|
|
@@ -9386,10 +9473,23 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
|
|
|
if (nd->tag == BR_TAG_A && nd->href_off)
|
|
if (nd->tag == BR_TAG_A && nd->href_off)
|
|
|
lk = (unsigned short)n;
|
|
lk = (unsigned short)n;
|
|
|
right = cs.float_left == 2;
|
|
right = cs.float_left == 2;
|
|
|
- if (cs.width_kind == 2 || cs.width_kind == 3) {
|
|
|
|
|
- colw = style_width_px(&cs, row_right - row_left);
|
|
|
|
|
- } else if (cs.width_kind == 1) {
|
|
|
|
|
- colw = (int)cs.width;
|
|
|
|
|
|
|
+ if (cs.width_kind == 1 || cs.width_kind == 2 ||
|
|
|
|
|
+ cs.width_kind == 3) {
|
|
|
|
|
+ /* The column is the margin box: `width` is the
|
|
|
|
|
+ * content (or, with border-box, the border) box,
|
|
|
|
|
+ * and layout_block() takes margins, padding and
|
|
|
|
|
+ * borders back out of the column. A 200px float
|
|
|
|
|
+ * with margin-right:20px used to get 180px of
|
|
|
|
|
+ * content. */
|
|
|
|
|
+ int base = row_right - row_left;
|
|
|
|
|
+
|
|
|
|
|
+ colw = cs.width_kind == 1 ? (int)cs.width :
|
|
|
|
|
+ style_width_px(&cs, base);
|
|
|
|
|
+ colw += mp_px(&cs, 3, base) + mp_px(&cs, 1, base);
|
|
|
|
|
+ if (!cs.box_sizing)
|
|
|
|
|
+ colw += mp_px(&cs, 7, base) +
|
|
|
|
|
+ mp_px(&cs, 5, base) +
|
|
|
|
|
+ cs.border_w[1] + cs.border_w[3];
|
|
|
} else {
|
|
} else {
|
|
|
int base = row_right - row_left;
|
|
int base = row_right - row_left;
|
|
|
|
|
|
|
@@ -9611,8 +9711,19 @@ static int inline_block_flows(unsigned int node, const struct br_style *cs,
|
|
|
|
|
|
|
|
if (nd->type != BR_NODE_ELEM)
|
|
if (nd->type != BR_NODE_ELEM)
|
|
|
continue;
|
|
continue;
|
|
|
- if (nd->tag == BR_TAG_IMG || nd->tag == BR_TAG_SVG ||
|
|
|
|
|
- br_tag_is_block(nd->tag))
|
|
|
|
|
|
|
+ if (nd->tag == BR_TAG_SVG) {
|
|
|
|
|
+ /* An icon box (Docusaurus' admonition heading:
|
|
|
|
|
+ * `<span inline-block><svg/></span>Note`): the SVG
|
|
|
|
|
+ * is an inline replaced run, so the box can stay in
|
|
|
|
|
+ * the text line. */
|
|
|
|
|
+ br_style_for(&doc, c, cs, &ch);
|
|
|
|
|
+ if (ch.display == BR_DISPLAY_NONE ||
|
|
|
|
|
+ ch.display == BR_DISPLAY_INLINE ||
|
|
|
|
|
+ ch.display == BR_DISPLAY_INLINE_BLOCK)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (nd->tag == BR_TAG_IMG || br_tag_is_block(nd->tag))
|
|
|
return 0;
|
|
return 0;
|
|
|
br_style_for(&doc, c, cs, &ch);
|
|
br_style_for(&doc, c, cs, &ch);
|
|
|
if (ch.display == BR_DISPLAY_NONE)
|
|
if (ch.display == BR_DISPLAY_NONE)
|
|
@@ -9722,6 +9833,43 @@ struct flex_item {
|
|
|
int w;
|
|
int w;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+/* An item's min-width/max-width as outer (margin-box) widths in the flex
|
|
|
|
|
+ * row, or -1 when unset. Percentages and calc() resolve against the
|
|
|
|
|
+ * container width. */
|
|
|
|
|
+static int flex_limit_w(const struct br_style *cs, int which_max, int avail)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned char kind = which_max ? cs->max_width_kind :
|
|
|
|
|
+ cs->min_width_kind;
|
|
|
|
|
+ int w;
|
|
|
|
|
+
|
|
|
|
|
+ if (kind == 3)
|
|
|
|
|
+ w = which_max ?
|
|
|
|
|
+ avail * cs->max_width_calc_pct / 100 +
|
|
|
|
|
+ cs->max_width_calc_px :
|
|
|
|
|
+ avail * cs->min_width_calc_pct / 100 +
|
|
|
|
|
+ cs->min_width_calc_px;
|
|
|
|
|
+ else
|
|
|
|
|
+ w = css_size(kind, which_max ? cs->max_width : cs->min_width,
|
|
|
|
|
+ avail);
|
|
|
|
|
+ if (w < 0)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ if (!cs->box_sizing)
|
|
|
|
|
+ w += mp_px(cs, 7, avail) + mp_px(cs, 5, avail) +
|
|
|
|
|
+ cs->border_w[1] + cs->border_w[3];
|
|
|
|
|
+ return w + mp_px(cs, 3, avail) + mp_px(cs, 1, avail);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int flex_clamp_w(const struct br_style *cs, int w, int avail)
|
|
|
|
|
+{
|
|
|
|
|
+ int mx = flex_limit_w(cs, 1, avail), mn = flex_limit_w(cs, 0, avail);
|
|
|
|
|
+
|
|
|
|
|
+ if (mx >= 0 && w > mx)
|
|
|
|
|
+ w = mx;
|
|
|
|
|
+ if (mn >= 0 && w < mn)
|
|
|
|
|
+ w = mn;
|
|
|
|
|
+ return w;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
const struct br_style *pst, int depth,
|
|
const struct br_style *pst, int depth,
|
|
|
unsigned short link)
|
|
unsigned short link)
|
|
@@ -9729,6 +9877,7 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
struct flex_item it[32];
|
|
struct flex_item it[32];
|
|
|
unsigned int c;
|
|
unsigned int c;
|
|
|
int nitem = 0, grow_count = 0, fixed = 0, grow_w, gap = pst->grid_gap;
|
|
int nitem = 0, grow_count = 0, fixed = 0, grow_w, gap = pst->grid_gap;
|
|
|
|
|
+ int grow_need = 0; /* growing items at their content width */
|
|
|
int row_left = l->left, row_right = l->right;
|
|
int row_left = l->left, row_right = l->right;
|
|
|
int avail = row_right - row_left;
|
|
int avail = row_right - row_left;
|
|
|
int idx, row_top;
|
|
int idx, row_top;
|
|
@@ -9765,31 +9914,74 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
it[nitem].link = (nd->tag == BR_TAG_A && nd->href_off) ?
|
|
it[nitem].link = (nd->tag == BR_TAG_A && nd->href_off) ?
|
|
|
(unsigned short)c : link;
|
|
(unsigned short)c : link;
|
|
|
it[nitem].w = 0;
|
|
it[nitem].w = 0;
|
|
|
- if (cs.flex_grow && !cs.width_kind)
|
|
|
|
|
|
|
+ if (cs.flex_grow && !cs.width_kind) {
|
|
|
grow_count++;
|
|
grow_count++;
|
|
|
- else
|
|
|
|
|
- fixed += flex_item_width(l, c, &cs, avail);
|
|
|
|
|
|
|
+ grow_need += flex_item_width(l, c, &cs, avail);
|
|
|
|
|
+ } else
|
|
|
|
|
+ fixed += flex_clamp_w(&cs,
|
|
|
|
|
+ flex_item_width(l, c, &cs, avail),
|
|
|
|
|
+ avail);
|
|
|
nitem++;
|
|
nitem++;
|
|
|
}
|
|
}
|
|
|
/* A narrow container (an icon row sized to its content, Google's
|
|
/* A narrow container (an icon row sized to its content, Google's
|
|
|
* mic + lens buttons) is still a row when its items fit; only a
|
|
* mic + lens buttons) is still a row when its items fit; only a
|
|
|
* narrow one that would overflow or squeeze growing items falls
|
|
* narrow one that would overflow or squeeze growing items falls
|
|
|
* back to block flow. */
|
|
* back to block flow. */
|
|
|
- if (avail < 160 && (grow_count || fixed > avail)) {
|
|
|
|
|
|
|
+ if (avail < 160 && fixed + grow_need > avail) {
|
|
|
layout_children(l, parent, pst, depth, link);
|
|
layout_children(l, parent, pst, depth, link);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
grow_w = grow_count ? (avail - fixed) / grow_count : 0;
|
|
grow_w = grow_count ? (avail - fixed) / grow_count : 0;
|
|
|
- if (grow_w < 96)
|
|
|
|
|
|
|
+ /* A growing item capped by max-width (Docusaurus' doc column,
|
|
|
|
|
+ * `max-width: 75%`; its main container, `calc(100% - 300px)`)
|
|
|
|
|
+ * keeps its cap and leaves the rest of the free space to the other
|
|
|
|
|
+ * growing items. */
|
|
|
|
|
+ if (grow_count) {
|
|
|
|
|
+ int pass, capped[32] = { 0 };
|
|
|
|
|
+
|
|
|
|
|
+ for (pass = 0; pass < nitem; pass++) {
|
|
|
|
|
+ int changed = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (idx = 0; idx < nitem; idx++) {
|
|
|
|
|
+ struct br_style cs;
|
|
|
|
|
+ int lim;
|
|
|
|
|
+
|
|
|
|
|
+ if (capped[idx])
|
|
|
|
|
+ continue;
|
|
|
|
|
+ br_style_for(&doc, it[idx].node, pst, &cs);
|
|
|
|
|
+ if (!cs.flex_grow || cs.width_kind)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ lim = flex_clamp_w(&cs, grow_w, avail);
|
|
|
|
|
+ if (lim == grow_w)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ capped[idx] = lim + 1;
|
|
|
|
|
+ fixed += lim;
|
|
|
|
|
+ grow_count--;
|
|
|
|
|
+ changed = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!changed || !grow_count)
|
|
|
|
|
+ break;
|
|
|
|
|
+ grow_w = (avail - fixed) / grow_count;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (idx = 0; idx < nitem; idx++)
|
|
|
|
|
+ it[idx].w = capped[idx] ? capped[idx] - 1 : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (grow_w < 96 && avail >= 160)
|
|
|
grow_w = 96;
|
|
grow_w = 96;
|
|
|
for (idx = 0; idx < nitem; idx++) {
|
|
for (idx = 0; idx < nitem; idx++) {
|
|
|
struct br_style cs;
|
|
struct br_style cs;
|
|
|
|
|
|
|
|
|
|
+ if (it[idx].w)
|
|
|
|
|
+ continue; /* capped growing item */
|
|
|
br_style_for(&doc, it[idx].node, pst, &cs);
|
|
br_style_for(&doc, it[idx].node, pst, &cs);
|
|
|
if (cs.flex_grow && !cs.width_kind)
|
|
if (cs.flex_grow && !cs.width_kind)
|
|
|
it[idx].w = grow_w;
|
|
it[idx].w = grow_w;
|
|
|
else
|
|
else
|
|
|
- it[idx].w = flex_item_width(l, it[idx].node, &cs, avail);
|
|
|
|
|
|
|
+ it[idx].w = flex_clamp_w(&cs,
|
|
|
|
|
+ flex_item_width(l,
|
|
|
|
|
+ it[idx].node,
|
|
|
|
|
+ &cs, avail),
|
|
|
|
|
+ avail);
|
|
|
if (it[idx].w > avail)
|
|
if (it[idx].w > avail)
|
|
|
it[idx].w = avail;
|
|
it[idx].w = avail;
|
|
|
if (it[idx].w < 8)
|
|
if (it[idx].w < 8)
|
|
@@ -11150,6 +11342,7 @@ static int measure_page(int left, int right)
|
|
|
l->depth = 0;
|
|
l->depth = 0;
|
|
|
l->nruns = 0;
|
|
l->nruns = 0;
|
|
|
l->space_pending = 0;
|
|
l->space_pending = 0;
|
|
|
|
|
+ base = root_style();
|
|
|
layout_children(l, doc.root, &base, 0, 0);
|
|
layout_children(l, doc.root, &base, 0, 0);
|
|
|
return l->y + 8;
|
|
return l->y + 8;
|
|
|
}
|
|
}
|
|
@@ -11210,6 +11403,7 @@ static void render_page(int left, int right, int y0)
|
|
|
l->space_pending = 0;
|
|
l->space_pending = 0;
|
|
|
nhits = 0;
|
|
nhits = 0;
|
|
|
ndeferred = 0;
|
|
ndeferred = 0;
|
|
|
|
|
+ base = root_style();
|
|
|
layout_children(l, doc.root, &base, 0, 0);
|
|
layout_children(l, doc.root, &base, 0, 0);
|
|
|
sort_deferred();
|
|
sort_deferred();
|
|
|
{
|
|
{
|
|
@@ -11236,10 +11430,32 @@ static void render_page(int left, int right, int y0)
|
|
|
if (st.pos == 2 && block_h[deferred[i].node]) {
|
|
if (st.pos == 2 && block_h[deferred[i].node]) {
|
|
|
struct ngui_rect clip;
|
|
struct ngui_rect clip;
|
|
|
int ch = block_h[deferred[i].node] + 24;
|
|
int ch = block_h[deferred[i].node] + 24;
|
|
|
-
|
|
|
|
|
- clip.x = page_rect.x;
|
|
|
|
|
|
|
+ int pr = page_rect.x + page_rect.w - 12;
|
|
|
|
|
+ int x0 = page_rect.x, x1 = pr;
|
|
|
|
|
+
|
|
|
|
|
+ /* The background pre-fill spans the box's own
|
|
|
|
|
+ * columns, not the whole page: Docusaurus parks
|
|
|
|
|
+ * a white "Skip to main content" link at
|
|
|
|
|
+ * `left: 100%` with a z-index above the navbar,
|
|
|
|
|
+ * and a full-width fill painted over the bar. */
|
|
|
|
|
+ if (st.left_set)
|
|
|
|
|
+ x0 = page_rect.x + st.left;
|
|
|
|
|
+ if (st.width_kind == 1) {
|
|
|
|
|
+ if (st.right_set && !st.left_set)
|
|
|
|
|
+ x0 = pr - st.right - st.width;
|
|
|
|
|
+ x1 = x0 + st.width;
|
|
|
|
|
+ } else if (st.right_set) {
|
|
|
|
|
+ x1 = pr - st.right;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (x0 >= pr || x1 <= page_rect.x)
|
|
|
|
|
+ continue; /* entirely off-screen */
|
|
|
|
|
+ if (x0 < page_rect.x)
|
|
|
|
|
+ x0 = page_rect.x;
|
|
|
|
|
+ if (x1 > pr)
|
|
|
|
|
+ x1 = pr;
|
|
|
|
|
+ clip.x = x0;
|
|
|
clip.y = page_rect.y;
|
|
clip.y = page_rect.y;
|
|
|
- clip.w = page_rect.w - 12;
|
|
|
|
|
|
|
+ clip.w = x1 - x0;
|
|
|
if (ch > page_rect.h)
|
|
if (ch > page_rect.h)
|
|
|
ch = page_rect.h;
|
|
ch = page_rect.h;
|
|
|
clip.h = ch;
|
|
clip.h = ch;
|
|
@@ -11708,16 +11924,35 @@ static void draw_page(struct ngui_rect page)
|
|
|
unsigned int body = doc.nnode > 1 ?
|
|
unsigned int body = doc.nnode > 1 ?
|
|
|
br_find_tag(&doc, BR_TAG_BODY) : 0;
|
|
br_find_tag(&doc, BR_TAG_BODY) : 0;
|
|
|
struct br_style bs;
|
|
struct br_style bs;
|
|
|
|
|
+ int bg_found = 0;
|
|
|
|
|
|
|
|
if (root) {
|
|
if (root) {
|
|
|
style_for_node(root - 1, &bs);
|
|
style_for_node(root - 1, &bs);
|
|
|
- if (bs.has_bg)
|
|
|
|
|
|
|
+ if (bs.has_bg) {
|
|
|
page_bg = bs.bg;
|
|
page_bg = bs.bg;
|
|
|
|
|
+ bg_found = 1;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (body) {
|
|
if (body) {
|
|
|
style_for_node(body - 1, &bs);
|
|
style_for_node(body - 1, &bs);
|
|
|
- if (bs.has_bg)
|
|
|
|
|
|
|
+ if (bs.has_bg) {
|
|
|
page_bg = bs.bg;
|
|
page_bg = bs.bg;
|
|
|
|
|
+ bg_found = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /* No canvas colour, but the author made the text dark
|
|
|
|
|
+ * (Infima's light theme: `--ifm-background-color:
|
|
|
|
|
+ * transparent` on html, #1c1e21 text): the page expects the
|
|
|
|
|
+ * white canvas of a normal browser, and dark text on the
|
|
|
|
|
+ * dark default canvas is unreadable. */
|
|
|
|
|
+ if (!bg_found && (body || root) && bs.color != ui.theme.text) {
|
|
|
|
|
+ unsigned int c = bs.color;
|
|
|
|
|
+ unsigned int lum = ((c >> 11) & 31) * 8 * 299 +
|
|
|
|
|
+ ((c >> 5) & 63) * 4 * 587 +
|
|
|
|
|
+ (c & 31) * 8 * 114;
|
|
|
|
|
+
|
|
|
|
|
+ if (lum < 100 * 1000)
|
|
|
|
|
+ page_bg = 0xFFFF;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (page_backbuf && pagebuf_w == ui.w && pagebuf_h == ui.h &&
|
|
if (page_backbuf && pagebuf_w == ui.w && pagebuf_h == ui.h &&
|