|
@@ -197,6 +197,7 @@ struct lay {
|
|
|
int line_x, line_y, line_h;
|
|
int line_x, line_y, line_h;
|
|
|
int line_left, line_right;
|
|
int line_left, line_right;
|
|
|
int parent_top;
|
|
int parent_top;
|
|
|
|
|
+ int cb_left, cb_right, cb_top; /* containing block for absolute boxes */
|
|
|
int run_x;
|
|
int run_x;
|
|
|
int align;
|
|
int align;
|
|
|
int depth;
|
|
int depth;
|
|
@@ -5503,8 +5504,10 @@ static void draw_svg(struct ngui *ui, unsigned node,
|
|
|
|
|
|
|
|
r.x = ox + (int)nd->svg_x * dw / vw;
|
|
r.x = ox + (int)nd->svg_x * dw / vw;
|
|
|
r.y = oy + (int)nd->svg_y * dh / vh;
|
|
r.y = oy + (int)nd->svg_y * dh / vh;
|
|
|
- r.w = (int)nd->width_attr * dw / vw;
|
|
|
|
|
- r.h = (int)nd->height_attr * dh / vh;
|
|
|
|
|
|
|
+ r.w = nd->width_pct ? dw * nd->width_attr / 100 :
|
|
|
|
|
+ (int)nd->width_attr * dw / vw;
|
|
|
|
|
+ r.h = nd->height_pct ? dh * nd->height_attr / 100 :
|
|
|
|
|
+ (int)nd->height_attr * dh / vh;
|
|
|
if (r.w < 1)
|
|
if (r.w < 1)
|
|
|
r.w = 1;
|
|
r.w = 1;
|
|
|
if (r.h < 1)
|
|
if (r.h < 1)
|
|
@@ -5537,10 +5540,11 @@ static void draw_svg(struct ngui *ui, unsigned node,
|
|
|
oy + (int)nd->height_attr * dh / vh,
|
|
oy + (int)nd->height_attr * dh / vh,
|
|
|
st.border_c[0]);
|
|
st.border_c[0]);
|
|
|
} else if (s_eq(nm, "path")) {
|
|
} else if (s_eq(nm, "path")) {
|
|
|
- if (st.border_w[0] && nd->src_off)
|
|
|
|
|
|
|
+ unsigned short pc = st.has_bg ? st.bg : st.border_c[0];
|
|
|
|
|
+
|
|
|
|
|
+ if ((st.has_bg || st.border_w[0]) && nd->src_off)
|
|
|
svg_path(ui, doc.attrs + nd->src_off,
|
|
svg_path(ui, doc.attrs + nd->src_off,
|
|
|
- ox, oy, dw, dh, vw, vh,
|
|
|
|
|
- st.border_c[0]);
|
|
|
|
|
|
|
+ ox, oy, dw, dh, vw, vh, pc);
|
|
|
} else if (s_eq(nm, "text")) {
|
|
} else if (s_eq(nm, "text")) {
|
|
|
unsigned int t = nd->first;
|
|
unsigned int t = nd->first;
|
|
|
const char *s;
|
|
const char *s;
|
|
@@ -5573,16 +5577,95 @@ static void draw_svg(struct ngui *ui, unsigned node,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* Size and paint a block-level/absolutely positioned <img>. Inline images
|
|
|
|
|
+ * keep using add_image_run(); this covers the CSS `position:absolute;
|
|
|
|
|
+ * width:100%` poster pattern used by news sites. */
|
|
|
|
|
+static void image_block_size(unsigned int node, const struct br_style *st,
|
|
|
|
|
+ int cbw, int *out_w, int *out_h)
|
|
|
|
|
+{
|
|
|
|
|
+ struct br_node *nd = &doc.nodes[node];
|
|
|
|
|
+ int idx = nd->img_index;
|
|
|
|
|
+ int iw = 0, ih = 0, w, h;
|
|
|
|
|
+
|
|
|
|
|
+ if (idx >= 0 && idx < image_count && images[idx].state == 1) {
|
|
|
|
|
+ iw = (int)images[idx].img.w;
|
|
|
|
|
+ ih = (int)images[idx].img.h;
|
|
|
|
|
+ if (iw <= 0 || ih <= 0) {
|
|
|
|
|
+ iw = (int)images[idx].native_w;
|
|
|
|
|
+ ih = (int)images[idx].native_h;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (st->width_kind)
|
|
|
|
|
+ w = style_width_px(st, cbw);
|
|
|
|
|
+ else if (nd->width_attr)
|
|
|
|
|
+ w = nd->width_pct ? cbw * nd->width_attr / 100 :
|
|
|
|
|
+ (int)nd->width_attr;
|
|
|
|
|
+ else if (iw)
|
|
|
|
|
+ w = iw;
|
|
|
|
|
+ else
|
|
|
|
|
+ w = 64;
|
|
|
|
|
+ if (w < 8)
|
|
|
|
|
+ w = 8;
|
|
|
|
|
+ if (cbw > 0 && w > cbw)
|
|
|
|
|
+ w = cbw;
|
|
|
|
|
+ if (st->height_kind)
|
|
|
|
|
+ h = style_height_px(st, cbw);
|
|
|
|
|
+ else if (nd->height_attr)
|
|
|
|
|
+ h = nd->height_pct ? cbw * nd->height_attr / 100 :
|
|
|
|
|
+ (int)nd->height_attr;
|
|
|
|
|
+ else if (iw && ih)
|
|
|
|
|
+ h = w * ih / iw;
|
|
|
|
|
+ else
|
|
|
|
|
+ h = 64;
|
|
|
|
|
+ if (h < 8)
|
|
|
|
|
+ h = 8;
|
|
|
|
|
+ *out_w = w;
|
|
|
|
|
+ *out_h = h;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void draw_image_block(struct lay *l, unsigned int node, int x, int y,
|
|
|
|
|
+ int dw, int dh)
|
|
|
|
|
+{
|
|
|
|
|
+ int idx = doc.nodes[node].img_index;
|
|
|
|
|
+
|
|
|
|
|
+ if (idx >= 0 && idx < image_count && images[idx].state == 1) {
|
|
|
|
|
+ struct img_blit b;
|
|
|
|
|
+
|
|
|
|
|
+ b.dst = l->ui->px;
|
|
|
|
|
+ b.dst_w = l->ui->w;
|
|
|
|
|
+ b.dst_h = l->ui->h;
|
|
|
|
|
+ b.clip_x = page_rect.x;
|
|
|
|
|
+ b.clip_y = page_rect.y;
|
|
|
|
|
+ b.clip_w = page_rect.w - 12;
|
|
|
|
|
+ b.clip_h = page_rect.h;
|
|
|
|
|
+ b.x = x;
|
|
|
|
|
+ b.y = y;
|
|
|
|
|
+ b.scale = ((unsigned int)dw << 16) / images[idx].img.w;
|
|
|
|
|
+ b.bg = ui.theme.bg;
|
|
|
|
|
+ b.bg2 = ui.theme.bg;
|
|
|
|
|
+ b.flags = IMG_BLIT_OVER_DST;
|
|
|
|
|
+ img_draw(&images[idx].img, &b);
|
|
|
|
|
+ } else if (l->draw) {
|
|
|
|
|
+ ngui_fill_rect(l->ui, (struct ngui_rect){x, y, dw, dh},
|
|
|
|
|
+ 0xD69A);
|
|
|
|
|
+ ngui_frame(l->ui, (struct ngui_rect){x, y, dw, dh}, 0x8410);
|
|
|
|
|
+ ngui_text(l->ui, x + 8, y + 8, "[image]", 0x4208);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void layout_block(struct lay *l, unsigned int node,
|
|
static void layout_block(struct lay *l, unsigned int node,
|
|
|
const struct br_style *st, int depth,
|
|
const struct br_style *st, int depth,
|
|
|
unsigned short link)
|
|
unsigned short link)
|
|
|
{
|
|
{
|
|
|
int old_left = l->left, old_right = l->right, old_align = l->align;
|
|
int old_left = l->left, old_right = l->right, old_align = l->align;
|
|
|
int saved_parent_top = l->parent_top;
|
|
int saved_parent_top = l->parent_top;
|
|
|
|
|
+ int saved_cb_left = l->cb_left, saved_cb_right = l->cb_right;
|
|
|
|
|
+ int saved_cb_top = l->cb_top;
|
|
|
int top, l0, r0;
|
|
int top, l0, r0;
|
|
|
int flow_y, flow_left, flow_right, positioned, relative, sticky, shifted;
|
|
int flow_y, flow_left, flow_right, positioned, relative, sticky, shifted;
|
|
|
int cbw, ml, mr, bl, br, pl, pr, bt, bb, pt, pb;
|
|
int cbw, ml, mr, bl, br, pl, pr, bt, bb, pt, pb;
|
|
|
int deco_w, deco_h, content_w, content_h, box_h;
|
|
int deco_w, deco_h, content_w, content_h, box_h;
|
|
|
|
|
+ int img_dh = 0;
|
|
|
int definite_w = 0;
|
|
int definite_w = 0;
|
|
|
int normal_top = 0;
|
|
int normal_top = 0;
|
|
|
int rel_dx = 0, rel_dy = 0;
|
|
int rel_dx = 0, rel_dy = 0;
|
|
@@ -5747,6 +5830,13 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
mr = free_w;
|
|
mr = free_w;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (doc.nodes[node].tag == BR_TAG_IMG) {
|
|
|
|
|
+ int iw, ih;
|
|
|
|
|
+
|
|
|
|
|
+ image_block_size(node, st, cbw, &iw, &ih);
|
|
|
|
|
+ content_w = iw;
|
|
|
|
|
+ img_dh = ih;
|
|
|
|
|
+ }
|
|
|
l0 = old_left + ml;
|
|
l0 = old_left + ml;
|
|
|
r0 = l0 + deco_w + content_w;
|
|
r0 = l0 + deco_w + content_w;
|
|
|
if (r0 < l0 + 8)
|
|
if (r0 < l0 + 8)
|
|
@@ -5787,6 +5877,13 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
r0 += rel_dx;
|
|
r0 += rel_dx;
|
|
|
}
|
|
}
|
|
|
l->parent_top = top;
|
|
l->parent_top = top;
|
|
|
|
|
+ if (st->pos != 0) {
|
|
|
|
|
+ /* Positioned boxes establish the containing block for their
|
|
|
|
|
+ * absolutely positioned descendants. */
|
|
|
|
|
+ l->cb_left = l0;
|
|
|
|
|
+ l->cb_right = r0;
|
|
|
|
|
+ l->cb_top = top;
|
|
|
|
|
+ }
|
|
|
if (l->draw && block_h[node] &&
|
|
if (l->draw && block_h[node] &&
|
|
|
top < page_rect.y + page_rect.h &&
|
|
top < page_rect.y + page_rect.h &&
|
|
|
top + block_h[node] > page_rect.y) {
|
|
top + block_h[node] > page_rect.y) {
|
|
@@ -5840,6 +5937,9 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
draw_border_box(l->ui, box, st);
|
|
draw_border_box(l->ui, box, st);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (l->draw && doc.nodes[node].tag == BR_TAG_IMG)
|
|
|
|
|
+ draw_image_block(l, node, l0 + bl + pl, top + bt + pt,
|
|
|
|
|
+ content_w, img_dh);
|
|
|
if (l->draw && st->overflow_hidden && block_h[node] > 0 &&
|
|
if (l->draw && st->overflow_hidden && block_h[node] > 0 &&
|
|
|
l->ui && l->ui->nclip < 4) {
|
|
l->ui && l->ui->nclip < 4) {
|
|
|
clip_rect.x = l0 + bl;
|
|
clip_rect.x = l0 + bl;
|
|
@@ -5959,7 +6059,9 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
l->y = l->float_bottom;
|
|
l->y = l->float_bottom;
|
|
|
l->float_active = 0;
|
|
l->float_active = 0;
|
|
|
}
|
|
}
|
|
|
- if (st->height_kind &&
|
|
|
|
|
|
|
+ if (doc.nodes[node].tag == BR_TAG_IMG) {
|
|
|
|
|
+ content_h = img_dh;
|
|
|
|
|
+ } else if (st->height_kind &&
|
|
|
!((doc.nodes[node].tag == BR_TAG_HTML ||
|
|
!((doc.nodes[node].tag == BR_TAG_HTML ||
|
|
|
doc.nodes[node].tag == BR_TAG_BODY) &&
|
|
doc.nodes[node].tag == BR_TAG_BODY) &&
|
|
|
st->height_kind == 2)) {
|
|
st->height_kind == 2)) {
|
|
@@ -6026,6 +6128,9 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
l->right = flow_right;
|
|
l->right = flow_right;
|
|
|
}
|
|
}
|
|
|
l->parent_top = saved_parent_top;
|
|
l->parent_top = saved_parent_top;
|
|
|
|
|
+ l->cb_left = saved_cb_left;
|
|
|
|
|
+ l->cb_right = saved_cb_right;
|
|
|
|
|
+ l->cb_top = saved_cb_top;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -6055,6 +6160,7 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
{
|
|
{
|
|
|
unsigned int c;
|
|
unsigned int c;
|
|
|
int line_w = 0, max_w = 0;
|
|
int line_w = 0, max_w = 0;
|
|
|
|
|
+ int flex_row = pst->display == BR_DISPLAY_FLEX && !pst->flex_col;
|
|
|
|
|
|
|
|
if (depth > 12)
|
|
if (depth > 12)
|
|
|
return 0;
|
|
return 0;
|
|
@@ -6144,10 +6250,18 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
mp_px(&cs, 5, base) +
|
|
mp_px(&cs, 5, base) +
|
|
|
mp_px(&cs, 3, base) +
|
|
mp_px(&cs, 3, base) +
|
|
|
mp_px(&cs, 1, base) +
|
|
mp_px(&cs, 1, base) +
|
|
|
- cs.border_w[1] + cs.border_w[3] +
|
|
|
|
|
- intrinsic_width(ui, c, &cs, depth + 1, base);
|
|
|
|
|
|
|
+ cs.border_w[1] + cs.border_w[3];
|
|
|
|
|
+
|
|
|
|
|
+ if (cs.width_kind == 1)
|
|
|
|
|
+ cw += cs.width;
|
|
|
|
|
+ else if (cs.width_kind == 2 || cs.width_kind == 3)
|
|
|
|
|
+ cw += style_width_px(&cs, base);
|
|
|
|
|
+ else
|
|
|
|
|
+ cw += intrinsic_width(ui, c, &cs, depth + 1,
|
|
|
|
|
+ base);
|
|
|
|
|
|
|
|
- if (cs.float_left || cs.display == BR_DISPLAY_INLINE ||
|
|
|
|
|
|
|
+ if (flex_row || cs.float_left ||
|
|
|
|
|
+ cs.display == BR_DISPLAY_INLINE ||
|
|
|
cs.display == BR_DISPLAY_INLINE_BLOCK) {
|
|
cs.display == BR_DISPLAY_INLINE_BLOCK) {
|
|
|
line_w += cw;
|
|
line_w += cw;
|
|
|
} else {
|
|
} else {
|
|
@@ -6353,11 +6467,14 @@ static int flex_item_width(struct lay *l, unsigned int n,
|
|
|
w = 64;
|
|
w = 64;
|
|
|
} else {
|
|
} else {
|
|
|
w = intrinsic_width(l->ui, n, cs, 0, avail);
|
|
w = intrinsic_width(l->ui, n, cs, 0, avail);
|
|
|
- w += mp_px(cs, 7, avail);
|
|
|
|
|
- w += mp_px(cs, 5, avail);
|
|
|
|
|
- w += mp_px(cs, 3, avail);
|
|
|
|
|
- w += mp_px(cs, 1, avail);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ /* Explicit widths are content-box sizes; the flex item's outer width
|
|
|
|
|
+ * must include padding, borders and margins. */
|
|
|
|
|
+ w += mp_px(cs, 7, avail);
|
|
|
|
|
+ w += mp_px(cs, 5, avail);
|
|
|
|
|
+ w += mp_px(cs, 3, avail);
|
|
|
|
|
+ w += mp_px(cs, 1, avail);
|
|
|
|
|
+ w += cs->border_w[1] + cs->border_w[3];
|
|
|
if (w < 24)
|
|
if (w < 24)
|
|
|
w = 24;
|
|
w = 24;
|
|
|
if (w > avail)
|
|
if (w > avail)
|
|
@@ -6532,7 +6649,9 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
while (idx < nitem) {
|
|
while (idx < nitem) {
|
|
|
int add = it[idx].w + (count ? gap : 0);
|
|
int add = it[idx].w + (count ? gap : 0);
|
|
|
|
|
|
|
|
- if (count && pst->flex_wrap != 2 &&
|
|
|
|
|
|
|
+ /* CSS default is nowrap; only flex-wrap: wrap (1)
|
|
|
|
|
+ * starts a new row. */
|
|
|
|
|
+ if (count && pst->flex_wrap == 1 &&
|
|
|
row_w + add > avail)
|
|
row_w + add > avail)
|
|
|
break;
|
|
break;
|
|
|
row_w += add;
|
|
row_w += add;
|
|
@@ -7634,9 +7753,12 @@ static void layout_children(struct lay *l, unsigned int parent,
|
|
|
ndeferred++;
|
|
ndeferred++;
|
|
|
} else if (l->draw && ndeferred < 16) {
|
|
} else if (l->draw && ndeferred < 16) {
|
|
|
deferred[ndeferred].node = n;
|
|
deferred[ndeferred].node = n;
|
|
|
- deferred[ndeferred].flow_y = l->y;
|
|
|
|
|
- deferred[ndeferred].flow_left = l->left;
|
|
|
|
|
- deferred[ndeferred].flow_right = l->right;
|
|
|
|
|
|
|
+ deferred[ndeferred].flow_y =
|
|
|
|
|
+ cs.pos == 1 ? l->cb_top : l->y;
|
|
|
|
|
+ deferred[ndeferred].flow_left =
|
|
|
|
|
+ cs.pos == 1 ? l->cb_left : l->left;
|
|
|
|
|
+ deferred[ndeferred].flow_right =
|
|
|
|
|
+ cs.pos == 1 ? l->cb_right : l->right;
|
|
|
deferred[ndeferred].link = lk;
|
|
deferred[ndeferred].link = lk;
|
|
|
deferred[ndeferred].z_index = cs.z_index;
|
|
deferred[ndeferred].z_index = cs.z_index;
|
|
|
deferred[ndeferred].z_set = cs.z_set;
|
|
deferred[ndeferred].z_set = cs.z_set;
|
|
@@ -7741,6 +7863,9 @@ static int measure_page(int left, int right)
|
|
|
l->align = BR_ALIGN_LEFT;
|
|
l->align = BR_ALIGN_LEFT;
|
|
|
l->float_active = 0;
|
|
l->float_active = 0;
|
|
|
l->parent_top = 0;
|
|
l->parent_top = 0;
|
|
|
|
|
+ l->cb_left = left;
|
|
|
|
|
+ l->cb_right = right;
|
|
|
|
|
+ l->cb_top = 0;
|
|
|
l->depth = 0;
|
|
l->depth = 0;
|
|
|
l->nruns = 0;
|
|
l->nruns = 0;
|
|
|
l->space_pending = 0;
|
|
l->space_pending = 0;
|
|
@@ -7795,6 +7920,9 @@ static void render_page(int left, int right, int y0)
|
|
|
l->align = BR_ALIGN_LEFT;
|
|
l->align = BR_ALIGN_LEFT;
|
|
|
l->float_active = 0;
|
|
l->float_active = 0;
|
|
|
l->parent_top = 0;
|
|
l->parent_top = 0;
|
|
|
|
|
+ l->cb_left = left;
|
|
|
|
|
+ l->cb_right = right;
|
|
|
|
|
+ l->cb_top = y0;
|
|
|
l->depth = 0;
|
|
l->depth = 0;
|
|
|
l->nruns = 0;
|
|
l->nruns = 0;
|
|
|
l->space_pending = 0;
|
|
l->space_pending = 0;
|