|
@@ -162,6 +162,17 @@ struct br_layout_box {
|
|
|
unsigned char valid;
|
|
unsigned char valid;
|
|
|
};
|
|
};
|
|
|
static struct br_layout_box layout_boxes[BR_MAX_NODES];
|
|
static struct br_layout_box layout_boxes[BR_MAX_NODES];
|
|
|
|
|
+/* Inline boxes are built from their line runs in flush_line(): a box is
|
|
|
|
|
+ * replaced when a new layout pass (or a re-layout at the same or an
|
|
|
|
|
+ * earlier line) reaches it, and grown when its runs continue on the same
|
|
|
|
|
+ * or a later line of the same pass. inline_box_parent[] is the enclosing
|
|
|
|
|
+ * inline box (node + 1), so nested spans grow their ancestors too. */
|
|
|
|
|
+static unsigned int inline_box_pass_id;
|
|
|
|
|
+static unsigned int inline_box_flush_id;
|
|
|
|
|
+static unsigned int inline_box_pass[BR_MAX_NODES];
|
|
|
|
|
+static unsigned int inline_box_flush[BR_MAX_NODES];
|
|
|
|
|
+static int inline_box_y[BR_MAX_NODES];
|
|
|
|
|
+static unsigned short inline_box_parent[BR_MAX_NODES];
|
|
|
|
|
|
|
|
/* Images are loaded one per main-loop iteration so the parsed page stays
|
|
/* Images are loaded one per main-loop iteration so the parsed page stays
|
|
|
* interactive while a slow network/TLS fetch or 4K decode is in progress. */
|
|
* interactive while a slow network/TLS fetch or 4K decode is in progress. */
|
|
@@ -267,6 +278,10 @@ struct lay_run {
|
|
|
unsigned short pb_bg;
|
|
unsigned short pb_bg;
|
|
|
short pb_img;
|
|
short pb_img;
|
|
|
short pb_x, pb_y, pb_w, pb_h;
|
|
short pb_x, pb_y, pb_w, pb_h;
|
|
|
|
|
+ /* Innermost inline element (node + 1) whose box this run belongs
|
|
|
|
|
+ * to, 0 = none; flush_line() unions the placed runs into
|
|
|
|
|
+ * layout_boxes[] so getBoundingClientRect() sees inline boxes. */
|
|
|
|
|
+ unsigned short box;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct lay {
|
|
struct lay {
|
|
@@ -288,6 +303,7 @@ struct lay {
|
|
|
int float_left, float_right, float_bottom;
|
|
int float_left, float_right, float_bottom;
|
|
|
struct lay_run runs[96];
|
|
struct lay_run runs[96];
|
|
|
int nruns;
|
|
int nruns;
|
|
|
|
|
+ unsigned short box_owner; /* node + 1 of the open inline box */
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct hit {
|
|
struct hit {
|
|
@@ -6926,10 +6942,51 @@ static void start_line(struct lay *l, const struct br_style *st)
|
|
|
l->run_x = l->line_left;
|
|
l->run_x = l->line_left;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void inline_box_add(const struct lay *l, unsigned int owner, int x,
|
|
|
|
|
+ int w)
|
|
|
|
|
+{
|
|
|
|
|
+ int y = l->line_y;
|
|
|
|
|
+ int h = l->line_h ? l->line_h : 16;
|
|
|
|
|
+ int depth = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (owner && owner <= BR_MAX_NODES && depth++ < 16) {
|
|
|
|
|
+ unsigned int node = owner - 1;
|
|
|
|
|
+ struct br_layout_box *b = &layout_boxes[node];
|
|
|
|
|
+
|
|
|
|
|
+ if (b->valid && inline_box_pass[node] == inline_box_pass_id &&
|
|
|
|
|
+ (inline_box_flush[node] == inline_box_flush_id ||
|
|
|
|
|
+ inline_box_y[node] < y)) {
|
|
|
|
|
+ int x1 = b->x + b->w, y1 = b->y + b->h;
|
|
|
|
|
+
|
|
|
|
|
+ if (x < b->x)
|
|
|
|
|
+ b->x = x;
|
|
|
|
|
+ if (y < b->y)
|
|
|
|
|
+ b->y = y;
|
|
|
|
|
+ if (x + w > x1)
|
|
|
|
|
+ x1 = x + w;
|
|
|
|
|
+ if (y + h > y1)
|
|
|
|
|
+ y1 = y + h;
|
|
|
|
|
+ b->w = x1 - b->x;
|
|
|
|
|
+ b->h = y1 - b->y;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ b->x = x;
|
|
|
|
|
+ b->y = y;
|
|
|
|
|
+ b->w = w;
|
|
|
|
|
+ b->h = h;
|
|
|
|
|
+ b->valid = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ inline_box_pass[node] = inline_box_pass_id;
|
|
|
|
|
+ inline_box_flush[node] = inline_box_flush_id;
|
|
|
|
|
+ inline_box_y[node] = y;
|
|
|
|
|
+ owner = inline_box_parent[node];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void flush_line(struct lay *l)
|
|
static void flush_line(struct lay *l)
|
|
|
{
|
|
{
|
|
|
int total, x, i, vis;
|
|
int total, x, i, vis;
|
|
|
|
|
|
|
|
|
|
+ inline_box_flush_id++;
|
|
|
if (!l->nruns && l->line_x == l->line_left) {
|
|
if (!l->nruns && l->line_x == l->line_left) {
|
|
|
l->line_h = 0;
|
|
l->line_h = 0;
|
|
|
return;
|
|
return;
|
|
@@ -7232,6 +7289,8 @@ static void flush_line(struct lay *l)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (r->box)
|
|
|
|
|
+ inline_box_add(l, r->box, x, w);
|
|
|
x += w;
|
|
x += w;
|
|
|
}
|
|
}
|
|
|
l->y += l->line_h + 2;
|
|
l->y += l->line_h + 2;
|
|
@@ -7267,6 +7326,7 @@ static void add_run(struct lay *l, unsigned int off, unsigned short len,
|
|
|
|
|
|
|
|
if (gap < 0)
|
|
if (gap < 0)
|
|
|
gap = 0;
|
|
gap = 0;
|
|
|
|
|
+ r->box = l->box_owner;
|
|
|
r->gap = (unsigned short)gap;
|
|
r->gap = (unsigned short)gap;
|
|
|
r->off = off;
|
|
r->off = off;
|
|
|
r->len = len;
|
|
r->len = len;
|
|
@@ -7474,6 +7534,7 @@ static void add_image_run(struct lay *l, unsigned int node,
|
|
|
|
|
|
|
|
if (gap < 0)
|
|
if (gap < 0)
|
|
|
gap = 0;
|
|
gap = 0;
|
|
|
|
|
+ r->box = l->box_owner;
|
|
|
r->gap = (unsigned short)gap;
|
|
r->gap = (unsigned short)gap;
|
|
|
r->off = 0;
|
|
r->off = 0;
|
|
|
r->len = 0;
|
|
r->len = 0;
|
|
@@ -7564,6 +7625,7 @@ static void add_svg_run(struct lay *l, unsigned int node,
|
|
|
l->line_x += ml;
|
|
l->line_x += ml;
|
|
|
r = &l->runs[l->nruns++];
|
|
r = &l->runs[l->nruns++];
|
|
|
memset(r, 0, sizeof(*r));
|
|
memset(r, 0, sizeof(*r));
|
|
|
|
|
+ r->box = l->box_owner;
|
|
|
r->gap = (unsigned short)(l->line_x > l->run_x ?
|
|
r->gap = (unsigned short)(l->line_x > l->run_x ?
|
|
|
l->line_x - l->run_x : 0);
|
|
l->line_x - l->run_x : 0);
|
|
|
r->off = node;
|
|
r->off = node;
|
|
@@ -7964,6 +8026,7 @@ static void add_form_run(struct lay *l, unsigned int node,
|
|
|
}
|
|
}
|
|
|
l->line_x += ml;
|
|
l->line_x += ml;
|
|
|
r = &l->runs[l->nruns++];
|
|
r = &l->runs[l->nruns++];
|
|
|
|
|
+ r->box = l->box_owner;
|
|
|
r->gap = (unsigned short)(l->line_x - l->run_x);
|
|
r->gap = (unsigned short)(l->line_x - l->run_x);
|
|
|
r->off = r->len = 0;
|
|
r->off = r->len = 0;
|
|
|
r->color = st->color;
|
|
r->color = st->color;
|
|
@@ -11858,6 +11921,7 @@ static void emit_pseudo_box(struct lay *l, const struct br_style *parent,
|
|
|
l->line_x += ml;
|
|
l->line_x += ml;
|
|
|
r = &l->runs[l->nruns++];
|
|
r = &l->runs[l->nruns++];
|
|
|
memset(r, 0, sizeof(*r));
|
|
memset(r, 0, sizeof(*r));
|
|
|
|
|
+ r->box = l->box_owner;
|
|
|
r->gap = (unsigned short)(l->line_x > l->run_x ?
|
|
r->gap = (unsigned short)(l->line_x > l->run_x ?
|
|
|
l->line_x - l->run_x : 0);
|
|
l->line_x - l->run_x : 0);
|
|
|
r->img = RUN_PBOX;
|
|
r->img = RUN_PBOX;
|
|
@@ -12036,6 +12100,23 @@ static int layout_out_of_flow(struct lay *l, unsigned int n,
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* An element laid out in the text line (an inline span, or an inline-block
|
|
|
|
|
+ * that flows like one): its runs are tagged with it, so flush_line() can
|
|
|
|
|
+ * record its box for getBoundingClientRect() and click targeting. */
|
|
|
|
|
+static void layout_inline_box(struct lay *l, unsigned int node,
|
|
|
|
|
+ const struct br_style *cs, int depth,
|
|
|
|
|
+ unsigned short link)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned short saved = l->box_owner;
|
|
|
|
|
+
|
|
|
|
|
+ if (node < BR_MAX_NODES) {
|
|
|
|
|
+ inline_box_parent[node] = saved;
|
|
|
|
|
+ l->box_owner = (unsigned short)(node + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ layout_children(l, node, cs, depth + 1, link);
|
|
|
|
|
+ l->box_owner = saved;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void layout_children(struct lay *l, unsigned int parent,
|
|
static void layout_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)
|
|
@@ -12135,7 +12216,7 @@ static void layout_children(struct lay *l, unsigned int parent,
|
|
|
}
|
|
}
|
|
|
if (cs.display == BR_DISPLAY_INLINE_BLOCK &&
|
|
if (cs.display == BR_DISPLAY_INLINE_BLOCK &&
|
|
|
inline_block_flows(n, &cs, 0)) {
|
|
inline_block_flows(n, &cs, 0)) {
|
|
|
- layout_children(l, n, &cs, depth + 1, lk);
|
|
|
|
|
|
|
+ layout_inline_box(l, n, &cs, depth, lk);
|
|
|
n = nd->next;
|
|
n = nd->next;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -12158,6 +12239,9 @@ static void layout_children(struct lay *l, unsigned int parent,
|
|
|
cs.display == BR_DISPLAY_FLEX ||
|
|
cs.display == BR_DISPLAY_FLEX ||
|
|
|
br_tag_is_block(nd->tag))
|
|
br_tag_is_block(nd->tag))
|
|
|
layout_block(l, n, &cs, depth + 1, lk);
|
|
layout_block(l, n, &cs, depth + 1, lk);
|
|
|
|
|
+ else if (cs.display == BR_DISPLAY_INLINE &&
|
|
|
|
|
+ nd->tag != BR_TAG_TD && nd->tag != BR_TAG_TH)
|
|
|
|
|
+ layout_inline_box(l, n, &cs, depth, lk);
|
|
|
else {
|
|
else {
|
|
|
layout_children(l, n, &cs, depth + 1, lk);
|
|
layout_children(l, n, &cs, depth + 1, lk);
|
|
|
if (nd->tag == BR_TAG_TD || nd->tag == BR_TAG_TH)
|
|
if (nd->tag == BR_TAG_TD || nd->tag == BR_TAG_TH)
|
|
@@ -12187,6 +12271,8 @@ static int measure_page(int left, int right)
|
|
|
layout_boxes[i].valid = 0;
|
|
layout_boxes[i].valid = 0;
|
|
|
}
|
|
}
|
|
|
memset(li_marker, 0, sizeof(li_marker));
|
|
memset(li_marker, 0, sizeof(li_marker));
|
|
|
|
|
+ inline_box_pass_id++;
|
|
|
|
|
+ l->box_owner = 0;
|
|
|
l->draw = 0;
|
|
l->draw = 0;
|
|
|
l->ui = &ui;
|
|
l->ui = &ui;
|
|
|
l->left = left;
|
|
l->left = left;
|
|
@@ -12246,6 +12332,8 @@ static void render_page(int left, int right, int y0)
|
|
|
{
|
|
{
|
|
|
struct lay *l = &layout_state;
|
|
struct lay *l = &layout_state;
|
|
|
struct br_style base = base_style();
|
|
struct br_style base = base_style();
|
|
|
|
|
+ inline_box_pass_id++;
|
|
|
|
|
+ l->box_owner = 0;
|
|
|
l->draw = 1;
|
|
l->draw = 1;
|
|
|
l->ui = &ui;
|
|
l->ui = &ui;
|
|
|
l->left = left;
|
|
l->left = left;
|