|
|
@@ -400,6 +400,8 @@ static unsigned int form_option_text(unsigned int node, unsigned int idx,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static int form_is_control(unsigned int node);
|
|
|
+
|
|
|
static struct form_state *form_get(unsigned int node, int create)
|
|
|
{
|
|
|
struct form_state *slot = 0;
|
|
|
@@ -413,6 +415,22 @@ static struct form_state *form_get(unsigned int node, int create)
|
|
|
slot = &form_states[i];
|
|
|
}
|
|
|
}
|
|
|
+ if (create && !slot) {
|
|
|
+ /* Full: a client-side router (Docusaurus' React Router)
|
|
|
+ * replaces page content without a navigation, so slots of
|
|
|
+ * controls that left the document pile up until no new
|
|
|
+ * control can be drawn or focused.
|
|
|
+ * Reuse those first, then slots of nodes that are no longer
|
|
|
+ * controls. */
|
|
|
+ for (i = 0; i < FORM_MAX && !slot; i++)
|
|
|
+ if (form_states[i].node != form_focus &&
|
|
|
+ br_node_detached(&doc, form_states[i].node))
|
|
|
+ slot = &form_states[i];
|
|
|
+ for (i = 0; i < FORM_MAX && !slot; i++)
|
|
|
+ if (form_states[i].node != form_focus &&
|
|
|
+ !form_is_control(form_states[i].node))
|
|
|
+ slot = &form_states[i];
|
|
|
+ }
|
|
|
if (!create || !slot)
|
|
|
return 0;
|
|
|
slot->node = node;
|
|
|
@@ -8282,10 +8300,14 @@ static void svg_draw_node(struct svgr_layer *L, unsigned int node,
|
|
|
double ow = svg_vp_w, oh = svg_vp_h;
|
|
|
|
|
|
if (svg_viewbox4(tgt, vb)) {
|
|
|
- double w = svg_attr_num(node, "width", vb[2],
|
|
|
- ow);
|
|
|
- double h = svg_attr_num(node, "height", vb[3],
|
|
|
- oh);
|
|
|
+ /* A <use> without width/height sizes the
|
|
|
+ * symbol to 100% of the viewport: Docusaurus'
|
|
|
+ * 13.5px external-link icon references a
|
|
|
+ * 24-unit symbol and showed only its corner. */
|
|
|
+ double w = svg_attr_num(node, "width",
|
|
|
+ ow > 0 ? ow : vb[2], ow);
|
|
|
+ double h = svg_attr_num(node, "height",
|
|
|
+ oh > 0 ? oh : vb[3], oh);
|
|
|
double vm[6];
|
|
|
|
|
|
svg_viewport_matrix(tgt, vb, w, h, vm);
|
|
|
@@ -12454,6 +12476,10 @@ static void draw_status(struct ngui_rect r)
|
|
|
ngui_fill_rect(&ui, r, ui.theme.panel);
|
|
|
ngui_fill_rect(&ui, (struct ngui_rect){r.x, r.y, r.w, 1},
|
|
|
ui.theme.border);
|
|
|
+ /* A form control under the pointer is not a link. */
|
|
|
+ if (hover && !br_href(&doc, (unsigned int)hover) &&
|
|
|
+ form_is_control((unsigned int)hover))
|
|
|
+ hover = 0;
|
|
|
if (hover) {
|
|
|
const char *href = br_href(&doc, (unsigned int)hover);
|
|
|
char url[BR_URL_MAX];
|
|
|
@@ -12843,14 +12869,26 @@ static void form_click(unsigned int node)
|
|
|
return;
|
|
|
if (form_focus != node)
|
|
|
form_blur();
|
|
|
- if (!js_browser_event(node, "click", 1, 1))
|
|
|
- return;
|
|
|
fs = form_get(node, 1);
|
|
|
if (!fs)
|
|
|
return;
|
|
|
kind = form_kind_of(node);
|
|
|
+ /* Focus moves on the press, before `click` is dispatched: a page
|
|
|
+ * that cancels the click (a framework's root listener) suppresses
|
|
|
+ * the activation behaviour below, never the focus (as in other
|
|
|
+ * browsers, where focus follows mousedown). */
|
|
|
form_focus = node;
|
|
|
form_dirty = 0;
|
|
|
+ if (kind == FORM_TEXT || kind == FORM_PASSWORD ||
|
|
|
+ kind == FORM_TEXTAREA)
|
|
|
+ fs->caret = fs->len;
|
|
|
+ layout_valid = 0;
|
|
|
+ ngui_invalidate(&ui);
|
|
|
+ if (!js_browser_event(node, "click", 1, 1))
|
|
|
+ return;
|
|
|
+ fs = form_get(node, 0); /* the handler may have changed the DOM */
|
|
|
+ if (!fs)
|
|
|
+ return;
|
|
|
if (kind == FORM_CHECKBOX) {
|
|
|
fs->checked = !fs->checked;
|
|
|
changed = 1;
|
|
|
@@ -12889,9 +12927,6 @@ static void form_click(unsigned int node)
|
|
|
} else if (kind == FORM_RESET) {
|
|
|
form_reset_event(form_ancestor(node));
|
|
|
return;
|
|
|
- } else if (kind == FORM_TEXT || kind == FORM_PASSWORD ||
|
|
|
- kind == FORM_TEXTAREA) {
|
|
|
- fs->caret = fs->len;
|
|
|
}
|
|
|
if (changed) {
|
|
|
js_browser_event(node, "input", 1, 0);
|