|
@@ -363,6 +363,10 @@ struct lay {
|
|
|
struct hit {
|
|
struct hit {
|
|
|
int x, y, w, h;
|
|
int x, y, w, h;
|
|
|
unsigned short node;
|
|
unsigned short node;
|
|
|
|
|
+ /* A painted absolute/fixed box (a modal, its backdrop, a fixed
|
|
|
|
|
+ * header): it hides the hits painted before it. Inserted below the
|
|
|
|
|
+ * box's own hits, so its links still win. */
|
|
|
|
|
+ unsigned char occl;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/* Live form state; the DOM attributes stay the initial/default value. */
|
|
/* Live form state; the DOM attributes stay the initial/default value. */
|
|
@@ -392,6 +396,8 @@ static int s_eq(const char *a, const char *b);
|
|
|
static void form_key(int k);
|
|
static void form_key(int k);
|
|
|
static void form_click(unsigned int node);
|
|
static void form_click(unsigned int node);
|
|
|
static void style_for_node(unsigned int node, struct br_style *out);
|
|
static void style_for_node(unsigned int node, struct br_style *out);
|
|
|
|
|
+static void anim_reset(void);
|
|
|
|
|
+static void anim_after_frame(void);
|
|
|
static int form_author_styled(const struct br_style *st);
|
|
static int form_author_styled(const struct br_style *st);
|
|
|
static int css_radius(const struct br_style *st, int corner, int w, int h);
|
|
static int css_radius(const struct br_style *st, int corner, int w, int h);
|
|
|
static void form_paint_author(struct ngui *ui, struct ngui_rect box,
|
|
static void form_paint_author(struct ngui *ui, struct ngui_rect box,
|
|
@@ -732,6 +738,7 @@ static int heap_start(void)
|
|
|
|
|
|
|
|
static void heap_clear(void)
|
|
static void heap_clear(void)
|
|
|
{
|
|
{
|
|
|
|
|
+ anim_reset(); /* also drops the page-heap alpha buffer */
|
|
|
memset(font_faces, 0, sizeof(font_faces));
|
|
memset(font_faces, 0, sizeof(font_faces));
|
|
|
memset(font_pick, 0, sizeof(font_pick));
|
|
memset(font_pick, 0, sizeof(font_pick));
|
|
|
ngui_font_detach(&ui);
|
|
ngui_font_detach(&ui);
|
|
@@ -1218,7 +1225,12 @@ static int js_host_computed(unsigned int node, const char *property,
|
|
|
static const char *cl[] = { "none", "left", "right", "both" };
|
|
static const char *cl[] = { "none", "left", "right", "both" };
|
|
|
snprintf(buf, cap, "%s", cl[st.clear < 4 ? st.clear : 0]);
|
|
snprintf(buf, cap, "%s", cl[st.clear < 4 ? st.clear : 0]);
|
|
|
} else if (!strcmp(name, "opacity")) {
|
|
} else if (!strcmp(name, "opacity")) {
|
|
|
- snprintf(buf, cap, "%s", st.opacity_hidden ? "0" : "1");
|
|
|
|
|
|
|
+ if (st.opacity >= 255)
|
|
|
|
|
+ snprintf(buf, cap, "1");
|
|
|
|
|
+ else
|
|
|
|
|
+ snprintf(buf, cap, "0.%02d",
|
|
|
|
|
+ (st.opacity * 100 + 127) / 255 > 99 ? 99 :
|
|
|
|
|
+ (st.opacity * 100 + 127) / 255);
|
|
|
} else if (!strcmp(name, "visibility")) {
|
|
} else if (!strcmp(name, "visibility")) {
|
|
|
snprintf(buf, cap, "%s", st.vis_hidden ? "hidden" : "visible");
|
|
snprintf(buf, cap, "%s", st.vis_hidden ? "hidden" : "visible");
|
|
|
} else if (!strcmp(name, "overflow")) {
|
|
} else if (!strcmp(name, "overflow")) {
|
|
@@ -8012,6 +8024,7 @@ static void flush_line(struct lay *l)
|
|
|
h->w = w;
|
|
h->w = w;
|
|
|
h->h = hh;
|
|
h->h = hh;
|
|
|
h->node = (unsigned short)target;
|
|
h->node = (unsigned short)target;
|
|
|
|
|
+ h->occl = 0;
|
|
|
nhits++;
|
|
nhits++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -9935,6 +9948,244 @@ static void draw_image_block(struct lay *l, unsigned int node, int x, int y,
|
|
|
static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
const struct br_style *pst, int depth, int base);
|
|
const struct br_style *pst, int depth, int base);
|
|
|
|
|
|
|
|
|
|
+/* ---- CSS transitions (opacity, transform translate) ----
|
|
|
|
|
+ *
|
|
|
|
|
+ * The cascade only knows the current computed value, so the paint pass
|
|
|
|
|
+ * remembers each element's last target value (pstate[]). When a later
|
|
|
|
|
+ * paint sees a different target and the element has a transition for that
|
|
|
|
|
+ * property, an animation from the value on screen to the new target starts
|
|
|
|
|
+ * and the page is repainted every pass until it ends; then `transitionend`
|
|
|
|
|
+ * is dispatched. The start state is whatever the previous paint saw: a
|
|
|
|
|
+ * script that changes a class right after display (Bootstrap adds `.in`)
|
|
|
|
|
+ * forces a reflow first (offsetWidth), and js_force_layout() is a paint
|
|
|
|
|
+ * pass, so that state is recorded like in a browser. Only the render
|
|
|
|
|
+ * pass records (render_pass); the measure pass does not. */
|
|
|
|
|
+#define ANIM_MAX 32
|
|
|
|
|
+#define ANIM_OP 0
|
|
|
|
|
+#define ANIM_TX 1
|
|
|
|
|
+#define ANIM_TY 2
|
|
|
|
|
+
|
|
|
|
|
+struct anim {
|
|
|
|
|
+ unsigned short node;
|
|
|
|
|
+ unsigned char prop, ease;
|
|
|
|
|
+ short from, to;
|
|
|
|
|
+ unsigned int t0, dur;
|
|
|
|
|
+ unsigned int seq; /* render_seq of the last paint that saw it */
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+struct paint_state {
|
|
|
|
|
+ short tx, ty;
|
|
|
|
|
+ unsigned char op;
|
|
|
|
|
+ unsigned char seen; /* bit per ANIM_* prop */
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+static struct paint_state pstate[BR_MAX_NODES];
|
|
|
|
|
+static struct anim anims[ANIM_MAX];
|
|
|
|
|
+static int nanims;
|
|
|
|
|
+static int render_pass;
|
|
|
|
|
+static unsigned int render_seq;
|
|
|
|
|
+static unsigned short anim_ended[ANIM_MAX];
|
|
|
|
|
+static int nanim_ended;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+static int anim_ease(int ease, int p) /* p and result 0..1024 */
|
|
|
|
|
+{
|
|
|
|
|
+ int q = 1024 - p;
|
|
|
|
|
+
|
|
|
|
|
+ switch (ease) {
|
|
|
|
|
+ case BR_EASE_LINEAR:
|
|
|
|
|
+ return p;
|
|
|
|
|
+ case BR_EASE_IN:
|
|
|
|
|
+ return (int)((long)p * p / 1024);
|
|
|
|
|
+ case BR_EASE_OUT:
|
|
|
|
|
+ return 1024 - (int)((long)q * q / 1024 * q / 1024);
|
|
|
|
|
+ default: /* ease, ease-in-out: smoothstep */
|
|
|
|
|
+ return (int)((long)p * p / 1024 * (3072 - 2 * p) / 1024);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int anim_find(unsigned int node, int prop)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < nanims; i++)
|
|
|
|
|
+ if (anims[i].node == node && anims[i].prop == prop)
|
|
|
|
|
+ return i;
|
|
|
|
|
+ return -1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int anim_now(const struct anim *a, unsigned int now)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int dt = now - a->t0;
|
|
|
|
|
+ int p;
|
|
|
|
|
+
|
|
|
|
|
+ if (dt >= a->dur)
|
|
|
|
|
+ return a->to;
|
|
|
|
|
+ p = anim_ease(a->ease, (int)(dt * 1024 / a->dur));
|
|
|
|
|
+ return a->from + (int)((long)(a->to - a->from) * p / 1024);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int anim_has(unsigned int node)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < nanims; i++)
|
|
|
|
|
+ if (anims[i].node == node)
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* The value to paint for a property whose computed target is `target`. */
|
|
|
|
|
+static int anim_value(unsigned int node, int prop, int target,
|
|
|
|
|
+ const struct br_style *st)
|
|
|
|
|
+{
|
|
|
|
|
+ struct paint_state *ps;
|
|
|
|
|
+ unsigned int now = u_ticks_ms();
|
|
|
|
|
+ int i, prev, bit = 1 << prop;
|
|
|
|
|
+ int tr = prop == ANIM_OP ? (st->tr_mask & BR_TR_OPACITY) :
|
|
|
|
|
+ (st->tr_mask & BR_TR_TRANSFORM);
|
|
|
|
|
+
|
|
|
|
|
+ if (!render_pass || node >= BR_MAX_NODES)
|
|
|
|
|
+ return target;
|
|
|
|
|
+ ps = &pstate[node];
|
|
|
|
|
+ prev = prop == ANIM_OP ? ps->op : prop == ANIM_TX ? ps->tx : ps->ty;
|
|
|
|
|
+ i = anim_find(node, prop);
|
|
|
|
|
+ if ((ps->seen & bit) && prev != target) {
|
|
|
|
|
+ if (tr && st->tr_ms) {
|
|
|
|
|
+ int from = i >= 0 ? anim_now(&anims[i], now) : prev;
|
|
|
|
|
+
|
|
|
|
|
+ if (i < 0 && nanims < ANIM_MAX)
|
|
|
|
|
+ i = nanims++;
|
|
|
|
|
+ if (i >= 0) {
|
|
|
|
|
+ anims[i].node = (unsigned short)node;
|
|
|
|
|
+ anims[i].prop = (unsigned char)prop;
|
|
|
|
|
+ anims[i].ease = st->tr_ease;
|
|
|
|
|
+ anims[i].from = (short)from;
|
|
|
|
|
+ anims[i].to = (short)target;
|
|
|
|
|
+ anims[i].t0 = now;
|
|
|
|
|
+ anims[i].dur = st->tr_ms;
|
|
|
|
|
+ anims[i].seq = render_seq;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (i >= 0) {
|
|
|
|
|
+ anims[i] = anims[--nanims];
|
|
|
|
|
+ i = -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ps->seen |= (unsigned char)bit;
|
|
|
|
|
+ if (prop == ANIM_OP)
|
|
|
|
|
+ ps->op = (unsigned char)target;
|
|
|
|
|
+ else if (prop == ANIM_TX)
|
|
|
|
|
+ ps->tx = (short)target;
|
|
|
|
|
+ else
|
|
|
|
|
+ ps->ty = (short)target;
|
|
|
|
|
+ if (i < 0)
|
|
|
|
|
+ return target;
|
|
|
|
|
+ anims[i].seq = render_seq;
|
|
|
|
|
+ if (now - anims[i].t0 >= anims[i].dur) {
|
|
|
|
|
+ if (nanim_ended < ANIM_MAX)
|
|
|
|
|
+ anim_ended[nanim_ended++] = anims[i].node;
|
|
|
|
|
+ anims[i] = anims[--nanims];
|
|
|
|
|
+ return target;
|
|
|
|
|
+ }
|
|
|
|
|
+ return anim_now(&anims[i], now);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* After the frame: running animations need another paint, and finished
|
|
|
|
|
+ * ones get their `transitionend` (Bootstrap also has a timer fallback). */
|
|
|
|
|
+static void anim_after_frame(void)
|
|
|
|
|
+{
|
|
|
|
|
+ static unsigned int checked_seq;
|
|
|
|
|
+ int i, j, n = nanim_ended;
|
|
|
|
|
+
|
|
|
|
|
+ /* An element removed or hidden mid-transition is no longer painted;
|
|
|
|
|
+ * its animation would otherwise keep every frame re-rendering. */
|
|
|
|
|
+ if (render_seq != checked_seq) {
|
|
|
|
|
+ for (i = 0; i < nanims; )
|
|
|
|
|
+ if (anims[i].seq != render_seq)
|
|
|
|
|
+ anims[i] = anims[--nanims];
|
|
|
|
|
+ else
|
|
|
|
|
+ i++;
|
|
|
|
|
+ checked_seq = render_seq;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (nanims) {
|
|
|
|
|
+ page_cache_valid = 0;
|
|
|
|
|
+ ngui_invalidate(&ui);
|
|
|
|
|
+ }
|
|
|
|
|
+ nanim_ended = 0;
|
|
|
|
|
+ if (!js_browser_active())
|
|
|
|
|
+ return;
|
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
|
+ for (j = 0; j < i; j++)
|
|
|
|
|
+ if (anim_ended[j] == anim_ended[i])
|
|
|
|
|
+ break;
|
|
|
|
|
+ if (j == i && anim_ended[i] < doc.nnode)
|
|
|
|
|
+ js_browser_event(anim_ended[i], "transitionend", 1, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Group opacity for a translucent positioned box: the page area under it
|
|
|
|
|
+ * is saved before the box paints and blended back afterwards. */
|
|
|
|
|
+static unsigned short *alpha_snap;
|
|
|
|
|
+static unsigned int alpha_snap_px;
|
|
|
|
|
+
|
|
|
|
|
+static void anim_reset(void)
|
|
|
|
|
+{
|
|
|
|
|
+ memset(pstate, 0, sizeof(pstate));
|
|
|
|
|
+ nanims = 0;
|
|
|
|
|
+ nanim_ended = 0;
|
|
|
|
|
+ alpha_snap = 0; /* lived in the page heap that is being reset */
|
|
|
|
|
+ alpha_snap_px = 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int alpha_begin(struct ngui_rect r)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int n = (unsigned int)r.w * (unsigned int)r.h;
|
|
|
|
|
+ int y;
|
|
|
|
|
+
|
|
|
|
|
+ if (r.w <= 0 || r.h <= 0)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ if (n > alpha_snap_px) {
|
|
|
|
|
+ free(alpha_snap);
|
|
|
|
|
+ alpha_snap = (unsigned short *)malloc(n * 2u);
|
|
|
|
|
+ alpha_snap_px = alpha_snap ? n : 0;
|
|
|
|
|
+ if (!alpha_snap)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (y = 0; y < r.h; y++)
|
|
|
|
|
+ memcpy(alpha_snap + y * r.w, ui.px + (r.y + y) * ui.w + r.x,
|
|
|
|
|
+ (unsigned int)r.w * 2u);
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void alpha_end(struct ngui_rect r, struct ngui_rect box, int a)
|
|
|
|
|
+{
|
|
|
|
|
+ int x, y, x0, x1, y0, y1;
|
|
|
|
|
+
|
|
|
|
|
+ x0 = box.x > r.x ? box.x : r.x;
|
|
|
|
|
+ y0 = box.y > r.y ? box.y : r.y;
|
|
|
|
|
+ x1 = box.x + box.w < r.x + r.w ? box.x + box.w : r.x + r.w;
|
|
|
|
|
+ y1 = box.y + box.h < r.y + r.h ? box.y + box.h : r.y + r.h;
|
|
|
|
|
+ for (y = y0; y < y1; y++) {
|
|
|
|
|
+ unsigned short *d = ui.px + y * ui.w;
|
|
|
|
|
+ const unsigned short *o = alpha_snap + (y - r.y) * r.w - r.x;
|
|
|
|
|
+
|
|
|
|
|
+ for (x = x0; x < x1; x++) {
|
|
|
|
|
+ unsigned int n = d[x], b = o[x];
|
|
|
|
|
+ unsigned int rr, gg, bb;
|
|
|
|
|
+
|
|
|
|
|
+ if (n == b)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ rr = (((n >> 11) & 31) * a + ((b >> 11) & 31) *
|
|
|
|
|
+ (255 - a)) / 255;
|
|
|
|
|
+ gg = (((n >> 5) & 63) * a + ((b >> 5) & 63) *
|
|
|
|
|
+ (255 - a)) / 255;
|
|
|
|
|
+ bb = ((n & 31) * a + (b & 31) * (255 - a)) / 255;
|
|
|
|
|
+ d[x] = (unsigned short)(rr << 11 | gg << 5 | bb);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
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)
|
|
@@ -10078,9 +10329,25 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
rel_dy = st->top_set ? st->top :
|
|
rel_dy = st->top_set ? st->top :
|
|
|
(st->bottom_set ? -st->bottom : 0);
|
|
(st->bottom_set ? -st->bottom : 0);
|
|
|
}
|
|
}
|
|
|
- if (st->transform_set) {
|
|
|
|
|
- rel_dx += st->tx;
|
|
|
|
|
- rel_dy += st->ty;
|
|
|
|
|
|
|
+ if (st->transform_set || (st->tr_mask & BR_TR_TRANSFORM) ||
|
|
|
|
|
+ (render_pass && anim_has(node))) {
|
|
|
|
|
+ int tx = st->tx, ty = st->ty;
|
|
|
|
|
+
|
|
|
|
|
+ /* translate(0, -25%): a percentage of the element's own
|
|
|
|
|
+ * box (the measure pass's height, the flow width). */
|
|
|
|
|
+ if (st->tx_pct)
|
|
|
|
|
+ tx = (old_right - old_left) * st->tx / 100;
|
|
|
|
|
+ if (st->ty_pct)
|
|
|
|
|
+ ty = node < BR_MAX_NODES ? block_h[node] * st->ty / 100
|
|
|
|
|
+ : 0;
|
|
|
|
|
+ if (!st->transform_set)
|
|
|
|
|
+ tx = ty = 0;
|
|
|
|
|
+ tx = anim_value(node, ANIM_TX, tx, st);
|
|
|
|
|
+ ty = anim_value(node, ANIM_TY, ty, st);
|
|
|
|
|
+ rel_dx += tx;
|
|
|
|
|
+ rel_dy += ty;
|
|
|
|
|
+ if (tx || ty)
|
|
|
|
|
+ shifted = 1;
|
|
|
}
|
|
}
|
|
|
if ((doc.nodes[node].tag == BR_TAG_INPUT ||
|
|
if ((doc.nodes[node].tag == BR_TAG_INPUT ||
|
|
|
doc.nodes[node].tag == BR_TAG_TEXTAREA ||
|
|
doc.nodes[node].tag == BR_TAG_TEXTAREA ||
|
|
@@ -10485,6 +10752,16 @@ static void layout_block(struct lay *l, unsigned int node,
|
|
|
if (!st->height_kind && node < BR_MAX_NODES &&
|
|
if (!st->height_kind && node < BR_MAX_NODES &&
|
|
|
content_h + deco_h < flex_stretch_h[node])
|
|
content_h + deco_h < flex_stretch_h[node])
|
|
|
content_h = flex_stretch_h[node] - deco_h;
|
|
content_h = flex_stretch_h[node] - deco_h;
|
|
|
|
|
+ /* A fixed box pinned by both top and bottom with an auto height
|
|
|
|
|
+ * spans the viewport between them (Bootstrap's .modal-backdrop is
|
|
|
|
|
+ * an empty `position: fixed; top: 0; bottom: 0` box). */
|
|
|
|
|
+ if (!st->height_kind && st->pos == 2 && st->top_set &&
|
|
|
|
|
+ st->bottom_set) {
|
|
|
|
|
+ int fh = page_rect.h - st->top - st->bottom - deco_h;
|
|
|
|
|
+
|
|
|
|
|
+ if (content_h < fh)
|
|
|
|
|
+ content_h = fh;
|
|
|
|
|
+ }
|
|
|
if (st->max_height_kind) {
|
|
if (st->max_height_kind) {
|
|
|
int mh = st->max_height_kind == 3 ?
|
|
int mh = st->max_height_kind == 3 ?
|
|
|
cbw * st->max_height_calc_pct / 100 +
|
|
cbw * st->max_height_calc_pct / 100 +
|
|
@@ -13110,6 +13387,39 @@ static void sort_deferred(void)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void hit_add_occluder(unsigned int node, int at)
|
|
|
|
|
+{
|
|
|
|
|
+ const struct br_layout_box *b;
|
|
|
|
|
+ struct hit h;
|
|
|
|
|
+ int x0, y0, x1, y1;
|
|
|
|
|
+
|
|
|
|
|
+ if (node >= BR_MAX_NODES || nhits >= HIT_MAX || at > nhits)
|
|
|
|
|
+ return;
|
|
|
|
|
+ b = &layout_boxes[node];
|
|
|
|
|
+ if (!b->valid)
|
|
|
|
|
+ return;
|
|
|
|
|
+ x0 = b->x > page_rect.x ? b->x : page_rect.x;
|
|
|
|
|
+ y0 = b->y > page_rect.y ? b->y : page_rect.y;
|
|
|
|
|
+ x1 = b->x + b->w;
|
|
|
|
|
+ y1 = b->y + b->h;
|
|
|
|
|
+ if (x1 > page_rect.x + page_rect.w - 12)
|
|
|
|
|
+ x1 = page_rect.x + page_rect.w - 12;
|
|
|
|
|
+ if (y1 > page_rect.y + page_rect.h)
|
|
|
|
|
+ y1 = page_rect.y + page_rect.h;
|
|
|
|
|
+ if (x1 <= x0 || y1 <= y0)
|
|
|
|
|
+ return;
|
|
|
|
|
+ h.x = x0;
|
|
|
|
|
+ h.y = y0;
|
|
|
|
|
+ h.w = x1 - x0;
|
|
|
|
|
+ h.h = y1 - y0;
|
|
|
|
|
+ h.node = (unsigned short)node;
|
|
|
|
|
+ h.occl = 1;
|
|
|
|
|
+ memmove(&hits[at + 1], &hits[at],
|
|
|
|
|
+ (unsigned int)(nhits - at) * sizeof(hits[0]));
|
|
|
|
|
+ hits[at] = h;
|
|
|
|
|
+ nhits++;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void render_page(int left, int right, int y0)
|
|
static void render_page(int left, int right, int y0)
|
|
|
{
|
|
{
|
|
|
struct lay *l = &layout_state;
|
|
struct lay *l = &layout_state;
|
|
@@ -13139,6 +13449,8 @@ 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;
|
|
|
|
|
+ render_pass = 1;
|
|
|
|
|
+ render_seq++;
|
|
|
base = root_style();
|
|
base = root_style();
|
|
|
layout_children(l, doc.root, &base, 0, 0);
|
|
layout_children(l, doc.root, &base, 0, 0);
|
|
|
sort_deferred();
|
|
sort_deferred();
|
|
@@ -13147,15 +13459,22 @@ static void render_page(int left, int right, int y0)
|
|
|
|
|
|
|
|
for (i = 0; i < ndeferred; i++) {
|
|
for (i = 0; i < ndeferred; i++) {
|
|
|
struct br_style st;
|
|
struct br_style st;
|
|
|
- int hide;
|
|
|
|
|
|
|
+ int hide, op, blend, hit0;
|
|
|
|
|
|
|
|
br_style_for(&doc, deferred[i].node, &base, &st);
|
|
br_style_for(&doc, deferred[i].node, &base, &st);
|
|
|
if (st.display == BR_DISPLAY_NONE)
|
|
if (st.display == BR_DISPLAY_NONE)
|
|
|
continue;
|
|
continue;
|
|
|
/* A transparent or visibility:hidden positioned box
|
|
/* A transparent or visibility:hidden positioned box
|
|
|
* still gets its boxes (scripts measure it) but no
|
|
* still gets its boxes (scripts measure it) but no
|
|
|
- * paint and no hit rectangles. */
|
|
|
|
|
- hide = st.opacity_hidden || st.vis_hidden;
|
|
|
|
|
|
|
+ * paint and no hit rectangles. A translucent one
|
|
|
|
|
+ * (a 50% modal backdrop, a fading tooltip) is
|
|
|
|
|
+ * blended over what is under it; the opacity may be
|
|
|
|
|
+ * mid-transition. */
|
|
|
|
|
+ hit0 = nhits;
|
|
|
|
|
+ op = anim_value(deferred[i].node, ANIM_OP, st.opacity,
|
|
|
|
|
+ &st);
|
|
|
|
|
+ hide = op == 0 || st.vis_hidden;
|
|
|
|
|
+ blend = !hide && op < 255 && alpha_begin(page_rect);
|
|
|
l->draw = !hide;
|
|
l->draw = !hide;
|
|
|
l->left = deferred[i].flow_left;
|
|
l->left = deferred[i].flow_left;
|
|
|
l->right = deferred[i].flow_right;
|
|
l->right = deferred[i].flow_right;
|
|
@@ -13230,25 +13549,62 @@ static void render_page(int left, int right, int y0)
|
|
|
layout_block(l, deferred[i].node, &st, 0,
|
|
layout_block(l, deferred[i].node, &st, 0,
|
|
|
deferred[i].link);
|
|
deferred[i].link);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!hide && !st.pe_none &&
|
|
|
|
|
+ (st.pos == 1 || st.pos == 2) &&
|
|
|
|
|
+ (st.has_bg || st.bg_image || st.z_set))
|
|
|
|
|
+ hit_add_occluder(deferred[i].node, hit0);
|
|
|
|
|
+ if (blend) {
|
|
|
|
|
+ const struct br_layout_box *b =
|
|
|
|
|
+ &layout_boxes[deferred[i].node];
|
|
|
|
|
+ struct ngui_rect box = page_rect;
|
|
|
|
|
+
|
|
|
|
|
+ /* The box itself; descendants may overflow
|
|
|
|
|
+ * it, so a full-page box is the safe case. */
|
|
|
|
|
+ if (deferred[i].node < BR_MAX_NODES &&
|
|
|
|
|
+ b->valid) {
|
|
|
|
|
+ box.x = b->x;
|
|
|
|
|
+ box.y = b->y;
|
|
|
|
|
+ box.w = b->w;
|
|
|
|
|
+ box.h = b->h;
|
|
|
|
|
+ }
|
|
|
|
|
+ alpha_end(page_rect, box, op);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ render_pass = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* ---- UI ---- */
|
|
/* ---- UI ---- */
|
|
|
|
|
|
|
|
-static int find_hit(int x, int y)
|
|
|
|
|
|
|
+/* The link/control under a point, topmost first. An occluder above it
|
|
|
|
|
+ * returns 0 and its node in *occl (when given), so the caller can target
|
|
|
|
|
+ * the covering box instead of content painted underneath. */
|
|
|
|
|
+static int find_hit_ex(int x, int y, int *occl)
|
|
|
{
|
|
{
|
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
|
|
+ if (occl)
|
|
|
|
|
+ *occl = -1;
|
|
|
for (i = nhits - 1; i >= 0; i--) {
|
|
for (i = nhits - 1; i >= 0; i--) {
|
|
|
struct hit *h = &hits[i];
|
|
struct hit *h = &hits[i];
|
|
|
if (x >= h->x && y >= h->y && x < h->x + h->w &&
|
|
if (x >= h->x && y >= h->y && x < h->x + h->w &&
|
|
|
- y < h->y + h->h)
|
|
|
|
|
|
|
+ y < h->y + h->h) {
|
|
|
|
|
+ if (h->occl) {
|
|
|
|
|
+ if (occl)
|
|
|
|
|
+ *occl = (int)h->node;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
return (int)h->node;
|
|
return (int)h->node;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int find_hit(int x, int y)
|
|
|
|
|
+{
|
|
|
|
|
+ return find_hit_ex(x, y, 0);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* ---- URL-bar autocomplete ----
|
|
/* ---- URL-bar autocomplete ----
|
|
|
*
|
|
*
|
|
|
* While the address bar has the focus a dropdown lists up to SUG_MAX
|
|
* While the address bar has the focus a dropdown lists up to SUG_MAX
|
|
@@ -13858,7 +14214,21 @@ static void draw_page(struct ngui_rect page)
|
|
|
* boxes for nodes they just inserted. Absolute/fixed boxes only get their
|
|
* boxes for nodes they just inserted. Absolute/fixed boxes only get their
|
|
|
* boxes in the painting pass, so this is a full render; the next frame
|
|
* boxes in the painting pass, so this is a full render; the next frame
|
|
|
* repaints the screen as usual. Skipped while the page has never been
|
|
* repaints the screen as usual. Skipped while the page has never been
|
|
|
- * drawn (no viewport yet) or without the back buffer. */
|
|
|
|
|
|
|
+ * drawn (no viewport yet) or without the back buffer.
|
|
|
|
|
+ *
|
|
|
|
|
+ * The guard is a count per main-loop pass, not a time budget: a hover or
|
|
|
|
|
+ * click handler (Bootstrap's tooltip does ~6 write/read rounds) must get
|
|
|
|
|
+ * correct geometry even on the ION, where one re-layout of cloudron.io
|
|
|
|
|
+ * takes longer than any reasonable per-window budget; only a script that
|
|
|
|
|
+ * keeps writing and reading in one pass falls back to the last layout. */
|
|
|
|
|
+#define FORCE_LAYOUT_PER_PASS 8
|
|
|
|
|
+static int force_layout_count;
|
|
|
|
|
+
|
|
|
|
|
+static void js_force_layout_pass_reset(void)
|
|
|
|
|
+{
|
|
|
|
|
+ force_layout_count = 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void js_force_layout(void)
|
|
static void js_force_layout(void)
|
|
|
{
|
|
{
|
|
|
static int busy;
|
|
static int busy;
|
|
@@ -13866,23 +14236,12 @@ static void js_force_layout(void)
|
|
|
int saved_w = ui.w, saved_h = ui.h;
|
|
int saved_w = ui.w, saved_h = ui.h;
|
|
|
struct ngui_rect page = page_rect;
|
|
struct ngui_rect page = page_rect;
|
|
|
|
|
|
|
|
- static unsigned int window_t0, spent;
|
|
|
|
|
- unsigned int t0 = u_ticks_ms();
|
|
|
|
|
-
|
|
|
|
|
if (busy || !page_backbuf || pagebuf_w != ui.w ||
|
|
if (busy || !page_backbuf || pagebuf_w != ui.w ||
|
|
|
pagebuf_h != ui.h || page.w < 40 || page.h < 40 ||
|
|
pagebuf_h != ui.h || page.w < 40 || page.h < 40 ||
|
|
|
- layout_right <= layout_left)
|
|
|
|
|
- return;
|
|
|
|
|
- /* Budget: a script that alternates writes and reads (an animation
|
|
|
|
|
- * loop) would otherwise re-render the page on every read. Past
|
|
|
|
|
- * 40 ms of forced layouts in a 100 ms window it reads the last
|
|
|
|
|
- * layout, as before. */
|
|
|
|
|
- if (t0 - window_t0 >= 100) {
|
|
|
|
|
- window_t0 = t0;
|
|
|
|
|
- spent = 0;
|
|
|
|
|
- }
|
|
|
|
|
- if (spent >= 40)
|
|
|
|
|
|
|
+ layout_right <= layout_left ||
|
|
|
|
|
+ force_layout_count >= FORCE_LAYOUT_PER_PASS)
|
|
|
return;
|
|
return;
|
|
|
|
|
+ force_layout_count++;
|
|
|
busy = 1;
|
|
busy = 1;
|
|
|
ui.px = page_backbuf;
|
|
ui.px = page_backbuf;
|
|
|
layout_view_h = page.h;
|
|
layout_view_h = page.h;
|
|
@@ -13897,7 +14256,6 @@ static void js_force_layout(void)
|
|
|
ui.h = saved_h;
|
|
ui.h = saved_h;
|
|
|
page_cache_valid = 0;
|
|
page_cache_valid = 0;
|
|
|
ngui_invalidate(&ui);
|
|
ngui_invalidate(&ui);
|
|
|
- spent += u_ticks_ms() - t0;
|
|
|
|
|
busy = 0;
|
|
busy = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -14806,10 +15164,17 @@ static int node_invisible(unsigned int n)
|
|
|
* that contains it (the last one wins a tie, i.e. the later/deeper node).
|
|
* that contains it (the last one wins a tie, i.e. the later/deeper node).
|
|
|
* Used to deliver clicks to elements that are neither links nor controls
|
|
* Used to deliver clicks to elements that are neither links nor controls
|
|
|
* (a Vue <div role="button">, a card with a click listener). */
|
|
* (a Vue <div role="button">, a card with a click listener). */
|
|
|
|
|
+static int node_contains(unsigned int a, unsigned int n);
|
|
|
|
|
+
|
|
|
static unsigned int find_box_hit(int x, int y)
|
|
static unsigned int find_box_hit(int x, int y)
|
|
|
{
|
|
{
|
|
|
unsigned int i, best = 0, best_area = 0xFFFFFFFFu;
|
|
unsigned int i, best = 0, best_area = 0xFFFFFFFFu;
|
|
|
|
|
+ int root;
|
|
|
|
|
|
|
|
|
|
+ /* A covering positioned box (a modal) takes the point: only it and
|
|
|
|
|
+ * its descendants are candidates, not the page painted under it. */
|
|
|
|
|
+ if (find_hit_ex(x, y, &root) || root < 0)
|
|
|
|
|
+ root = -1;
|
|
|
for (i = 1; i < doc.nnode && i < BR_MAX_NODES; i++) {
|
|
for (i = 1; i < doc.nnode && i < BR_MAX_NODES; i++) {
|
|
|
const struct br_layout_box *b = &layout_boxes[i];
|
|
const struct br_layout_box *b = &layout_boxes[i];
|
|
|
unsigned int area;
|
|
unsigned int area;
|
|
@@ -14818,6 +15183,8 @@ static unsigned int find_box_hit(int x, int y)
|
|
|
x < b->x || y < b->y || x >= b->x + b->w ||
|
|
x < b->x || y < b->y || x >= b->x + b->w ||
|
|
|
y >= b->y + b->h)
|
|
y >= b->y + b->h)
|
|
|
continue;
|
|
continue;
|
|
|
|
|
+ if (root >= 0 && !node_contains((unsigned int)root, i))
|
|
|
|
|
+ continue;
|
|
|
area = (unsigned int)b->w * (unsigned int)b->h;
|
|
area = (unsigned int)b->w * (unsigned int)b->h;
|
|
|
if (area <= best_area && !node_invisible(i)) {
|
|
if (area <= best_area && !node_invisible(i)) {
|
|
|
best = i;
|
|
best = i;
|
|
@@ -15200,6 +15567,7 @@ void _start(const char *arg)
|
|
|
preload_node = 0;
|
|
preload_node = 0;
|
|
|
preload_active = 1;
|
|
preload_active = 1;
|
|
|
}
|
|
}
|
|
|
|
|
+ js_force_layout_pass_reset();
|
|
|
js_browser_tick();
|
|
js_browser_tick();
|
|
|
if (resize_pending && !pending_action) {
|
|
if (resize_pending && !pending_action) {
|
|
|
resize_pending = 0;
|
|
resize_pending = 0;
|
|
@@ -15227,10 +15595,12 @@ void _start(const char *arg)
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ js_force_layout_pass_reset();
|
|
|
draw(&action);
|
|
draw(&action);
|
|
|
handle_keys(&action);
|
|
handle_keys(&action);
|
|
|
handle_page_click(&action);
|
|
handle_page_click(&action);
|
|
|
page_hover_events();
|
|
page_hover_events();
|
|
|
|
|
+ anim_after_frame();
|
|
|
ngui_end(&ui);
|
|
ngui_end(&ui);
|
|
|
}
|
|
}
|
|
|
if (action & ACT_NAV) {
|
|
if (action & ACT_NAV) {
|