@elurjs/universal 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/cli/create-app.mjs +15 -8
  2. package/cli/dev.mjs +45 -16
  3. package/cli/doctor.mjs +40 -14
  4. package/cli/elur.mjs +18 -4
  5. package/docs/INSTALACION-Y-DEV.md +13 -6
  6. package/package.json +5 -1
  7. package/targets/linux/CMakeLists.txt +196 -0
  8. package/targets/linux/README.md +422 -0
  9. package/targets/linux/ci/tsan.supp +15 -0
  10. package/targets/linux/generated/elur_module_registrar.cpp +14 -0
  11. package/targets/linux/generated/module_sources.cmake +5 -0
  12. package/targets/linux/src/elur_applicator.cpp +5073 -0
  13. package/targets/linux/src/elur_applicator.h +387 -0
  14. package/targets/linux/src/elur_clip.cpp +76 -0
  15. package/targets/linux/src/elur_clip.h +23 -0
  16. package/targets/linux/src/elur_crypto_module.cpp +121 -0
  17. package/targets/linux/src/elur_events.h +57 -0
  18. package/targets/linux/src/elur_fonts.cpp +106 -0
  19. package/targets/linux/src/elur_fonts.h +31 -0
  20. package/targets/linux/src/elur_host.cpp +1041 -0
  21. package/targets/linux/src/elur_host.h +66 -0
  22. package/targets/linux/src/elur_http_module.cpp +437 -0
  23. package/targets/linux/src/elur_js.h +40 -0
  24. package/targets/linux/src/elur_modules.cpp +453 -0
  25. package/targets/linux/src/elur_modules.h +159 -0
  26. package/targets/linux/src/elur_renderer.h +46 -0
  27. package/targets/linux/src/elur_shot.cpp +64 -0
  28. package/targets/linux/src/elur_shot.h +17 -0
  29. package/targets/linux/src/elur_skia_a11y.cpp +987 -0
  30. package/targets/linux/src/elur_skia_a11y.h +146 -0
  31. package/targets/linux/src/elur_skia_app.cpp +1770 -0
  32. package/targets/linux/src/elur_skia_app.h +18 -0
  33. package/targets/linux/src/elur_state_module.cpp +99 -0
  34. package/targets/linux/src/elur_tck_module.cpp +186 -0
  35. package/targets/linux/src/elur_ui_module.cpp +84 -0
  36. package/targets/linux/src/elur_yoga.cpp +452 -0
  37. package/targets/linux/src/elur_yoga.h +95 -0
  38. package/targets/linux/src/main.cpp +294 -0
  39. package/targets/windows/Package.appxmanifest +28 -0
  40. package/targets/windows/README.md +44 -0
  41. package/targets/windows/elur-windows.vcxproj +133 -0
  42. package/targets/windows/packages.config +10 -0
  43. package/targets/windows/src/elur_crypto_module_win.cpp +106 -0
  44. package/targets/windows/src/elur_events.h +58 -0
  45. package/targets/windows/src/elur_host_win.cpp +645 -0
  46. package/targets/windows/src/elur_host_win.h +75 -0
  47. package/targets/windows/src/elur_http_module_win.cpp +331 -0
  48. package/targets/windows/src/elur_js.h +40 -0
  49. package/targets/windows/src/elur_modules.cpp +460 -0
  50. package/targets/windows/src/elur_modules.h +159 -0
  51. package/targets/windows/src/elur_state_module.cpp +99 -0
  52. package/targets/windows/src/elur_ui_module_win.cpp +75 -0
  53. package/targets/windows/src/elur_uia_host.h +129 -0
  54. package/targets/windows/src/elur_win_applicator.cpp +3118 -0
  55. package/targets/windows/src/elur_win_applicator.h +186 -0
  56. package/targets/windows/src/elur_yoga.cpp +452 -0
  57. package/targets/windows/src/elur_yoga.h +95 -0
  58. package/targets/windows/src/main.cpp +321 -0
@@ -0,0 +1,987 @@
1
+ // elur_skia_a11y.cpp — GObject accesible virtual + manager del árbol
2
+ // AT-SPI del carril Skia. Ver el contrato en el header.
3
+ #include "elur_skia_a11y.h"
4
+
5
+ #if ELUR_HAS_SKIA
6
+
7
+ #include <algorithm>
8
+ #include <cstdio>
9
+ #include <cstdlib>
10
+ #include <unordered_set>
11
+
12
+ namespace elur {
13
+ // ariaRole del carril views (elur_applicator.cpp) — misma tabla ARIA.
14
+ bool elurAriaRole(const std::string &, GtkAccessibleRole &);
15
+ } // namespace elur
16
+
17
+ // ElurSkiaA11y — GObject con la interfaz GtkAccessible. El estado que
18
+ // GTK no puede derivar de la interfaz (rol para el ATContext, flags de
19
+ // plataforma, nivel live) vive en la instancia; la geometría y el
20
+ // parentesco se resuelven perezoso sobre el SkiaTree vía el manager —
21
+ // así insert/remove/move no requieren re-enlazar nada.
22
+ struct _ElurSkiaA11y {
23
+ GObject parent_instance;
24
+ elur::SkiaA11y *mgr; // no poseído — el manager nos sobrevive
25
+ int id;
26
+ GtkATContext *atctx;
27
+ int role; // GtkAccessibleRole — fijo por ATContext (recreado al cambiar)
28
+ bool hidden;
29
+ bool focusable;
30
+ bool focused;
31
+ int liveLevel;
32
+ };
33
+
34
+ enum { SKIA_A11Y_PROP_0, SKIA_A11Y_PROP_ROLE };
35
+
36
+ G_DECLARE_FINAL_TYPE(ElurSkiaA11y, elur_skia_a11y, ELUR, SKIA_A11Y, GObject)
37
+
38
+ static void skiaA11yAccessibleInit(GtkAccessibleInterface *iface);
39
+ static void skiaA11yTextInit(GtkAccessibleTextInterface *iface);
40
+
41
+ G_DEFINE_TYPE_WITH_CODE(ElurSkiaA11y, elur_skia_a11y, G_TYPE_OBJECT,
42
+ G_IMPLEMENT_INTERFACE(GTK_TYPE_ACCESSIBLE,
43
+ skiaA11yAccessibleInit)
44
+ G_IMPLEMENT_INTERFACE(GTK_TYPE_ACCESSIBLE_TEXT,
45
+ skiaA11yTextInit))
46
+
47
+ static void skiaA11yGetProperty(GObject *obj, guint propId, GValue *value,
48
+ GParamSpec *) {
49
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(obj);
50
+ if (propId == SKIA_A11Y_PROP_ROLE)
51
+ g_value_set_enum(value, self->role);
52
+ }
53
+
54
+ static void skiaA11ySetProperty(GObject *obj, guint propId, const GValue *value,
55
+ GParamSpec *) {
56
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(obj);
57
+ if (propId == SKIA_A11Y_PROP_ROLE)
58
+ self->role = g_value_get_enum(value);
59
+ }
60
+
61
+ static void skiaA11yDispose(GObject *obj) {
62
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(obj);
63
+ g_clear_object(&self->atctx);
64
+ G_OBJECT_CLASS(elur_skia_a11y_parent_class)->dispose(obj);
65
+ }
66
+
67
+ static void elur_skia_a11y_class_init(ElurSkiaA11yClass *klass) {
68
+ GObjectClass *oc = G_OBJECT_CLASS(klass);
69
+ oc->get_property = skiaA11yGetProperty;
70
+ oc->set_property = skiaA11ySetProperty;
71
+ oc->dispose = skiaA11yDispose;
72
+ g_object_class_override_property(oc, SKIA_A11Y_PROP_ROLE, "accessible-role");
73
+ }
74
+
75
+ static void elur_skia_a11y_init(ElurSkiaA11y *) {}
76
+
77
+ static void skiaA11yCtxStateChange(GtkATContext *, gpointer ud) {
78
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(ud);
79
+ a->mgr->announced(a->id);
80
+ }
81
+
82
+ static GtkATContext *skiaA11yGetAtContext(GtkAccessible *acc) {
83
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(acc);
84
+ if (self->hidden)
85
+ return nullptr; // accessible:false — fuera del árbol AT
86
+ if (!self->atctx) {
87
+ GdkDisplay *d = gdk_display_get_default();
88
+ if (!d)
89
+ return nullptr;
90
+ self->atctx = gtk_at_context_create((GtkAccessibleRole)self->role, acc, d);
91
+ // state-change solo se emite con el ctx realizado — marca que el
92
+ // acc ya publica eventos por D-Bus (sale de pending_).
93
+ // connect_object: la conexión muere con el acc — el ctx puede
94
+ // sobrevivirle si GTK lo refea externamente (registro/caché).
95
+ if (self->atctx)
96
+ g_signal_connect_object(self->atctx, "state-change",
97
+ G_CALLBACK(skiaA11yCtxStateChange), self,
98
+ (GConnectFlags)0);
99
+ }
100
+ return self->atctx ? GTK_AT_CONTEXT(g_object_ref(self->atctx)) : nullptr;
101
+ }
102
+
103
+ static gboolean skiaA11yGetPlatformState(GtkAccessible *acc,
104
+ GtkAccessiblePlatformState st) {
105
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(acc);
106
+ switch (st) {
107
+ case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE:
108
+ return self->focusable;
109
+ case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
110
+ return self->focused;
111
+ case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
112
+ return FALSE;
113
+ }
114
+ return FALSE;
115
+ }
116
+
117
+ static GtkAccessible *skiaA11yGetParent(GtkAccessible *acc) {
118
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(acc);
119
+ void *p = self->mgr->parentAcc(self->id);
120
+ return p ? GTK_ACCESSIBLE(g_object_ref(p)) : nullptr;
121
+ }
122
+
123
+ static GtkAccessible *skiaA11yGetFirstChild(GtkAccessible *acc) {
124
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(acc);
125
+ void *c = self->mgr->firstChildAcc(self->id);
126
+ return c ? GTK_ACCESSIBLE(g_object_ref(c)) : nullptr;
127
+ }
128
+
129
+ static GtkAccessible *skiaA11yGetNextSibling(GtkAccessible *acc) {
130
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(acc);
131
+ void *s = self->mgr->nextSiblingAcc(self->id);
132
+ return s ? GTK_ACCESSIBLE(g_object_ref(s)) : nullptr;
133
+ }
134
+
135
+ static gboolean skiaA11yGetBounds(GtkAccessible *acc, int *x, int *y, int *w,
136
+ int *h) {
137
+ ElurSkiaA11y *self = ELUR_SKIA_A11Y(acc);
138
+ int ix, iy, iw, ih;
139
+ if (!self->mgr->bounds(self->id, ix, iy, iw, ih))
140
+ return FALSE;
141
+ *x = ix;
142
+ *y = iy;
143
+ *w = iw;
144
+ *h = ih;
145
+ return TRUE;
146
+ }
147
+
148
+ static void skiaA11yAccessibleInit(GtkAccessibleInterface *iface) {
149
+ iface->get_at_context = skiaA11yGetAtContext;
150
+ iface->get_platform_state = skiaA11yGetPlatformState;
151
+ iface->get_accessible_parent = skiaA11yGetParent;
152
+ iface->get_first_accessible_child = skiaA11yGetFirstChild;
153
+ iface->get_next_accessible_sibling = skiaA11yGetNextSibling;
154
+ iface->get_bounds = skiaA11yGetBounds;
155
+ }
156
+
157
+ // ── GtkAccessibleText — contenido textual del nodo ─────────────────
158
+ // atspi exporta org.a11y.atspi.Text solo para objetos que implementan
159
+ // GtkAccessibleText (gtkatspitext.c — los vtables alternativos son
160
+ // para widgets). EditableText queda restringido a GTK_IS_EDITABLE →
161
+ // gap IME declarado: la escritura vía AT llega con GtkIMContext.
162
+ static std::string a11yNodeText(ElurSkiaA11y *a) {
163
+ return a->mgr->textContent(a->id);
164
+ }
165
+
166
+ static GBytes *a11yTextGetContents(GtkAccessibleText *self, guint start,
167
+ guint end) {
168
+ std::string s = a11yNodeText(ELUR_SKIA_A11Y(self));
169
+ guint len = g_utf8_strlen(s.c_str(), s.size());
170
+ // end<start u offsets fuera de rango → e-b negativo: gsize underflow
171
+ // en g_bytes_new = malloc gigante → heap corruption.
172
+ if (end != G_MAXUINT && end < start)
173
+ end = start;
174
+ if (start > len)
175
+ start = len;
176
+ const gchar *b = g_utf8_offset_to_pointer(s.c_str(), start);
177
+ const gchar *e = end == G_MAXUINT || end > len
178
+ ? s.c_str() + s.size()
179
+ : g_utf8_offset_to_pointer(s.c_str(), end);
180
+ return g_bytes_new(b, e - b);
181
+ }
182
+
183
+ static GBytes *a11yTextGetContentsAt(GtkAccessibleText *self, guint offset,
184
+ GtkAccessibleTextGranularity gran,
185
+ guint *start, guint *end) {
186
+ std::string s = a11yNodeText(ELUR_SKIA_A11Y(self));
187
+ guint len = g_utf8_strlen(s.c_str(), s.size());
188
+ if (gran == GTK_ACCESSIBLE_TEXT_GRANULARITY_CHARACTER && offset < len) {
189
+ *start = offset;
190
+ *end = offset + 1;
191
+ const gchar *b = g_utf8_offset_to_pointer(s.c_str(), offset);
192
+ return g_bytes_new(b, g_utf8_offset_to_pointer(s.c_str(), offset + 1) - b);
193
+ }
194
+ // Word/sentence/line/paragraph → el contenido completo: los nodos
195
+ // son labels cortos single-line en esta fase (sin shaping — el
196
+ // split fino llega con skparagraph en fase 3).
197
+ *start = 0;
198
+ *end = len;
199
+ return g_bytes_new(s.data(), s.size());
200
+ }
201
+
202
+ static guint a11yTextGetCaretPosition(GtkAccessibleText *) { return 0; }
203
+
204
+ static gboolean a11yTextGetSelection(GtkAccessibleText *, gsize *n,
205
+ GtkAccessibleTextRange **ranges) {
206
+ *n = 0;
207
+ *ranges = nullptr;
208
+ return FALSE;
209
+ }
210
+
211
+ static gboolean a11yTextGetAttributes(GtkAccessibleText *self, guint, gsize *n,
212
+ GtkAccessibleTextRange **ranges,
213
+ char ***names, char ***values) {
214
+ // Contrato defensivo: gtkatspitext.c itera names[i] sin check en
215
+ // GetAttributeValue/GetAttributeRun y los locales del caller llegan
216
+ // sin inicializar — un out-param intocable convierte FALSE en lectura
217
+ // salvaje. Inicializar siempre, devolver strv vacío si no hay attrs.
218
+ *n = 0;
219
+ *ranges = nullptr;
220
+ *names = g_new0(char *, 1);
221
+ *values = g_new0(char *, 1);
222
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(self);
223
+ const elur::skia::SkiaNode *nd = a->mgr->nodeFor(a->id);
224
+ std::vector<std::string> ns, vs;
225
+ if (nd) {
226
+ // Evidencia tipográfica real del árbol — la misma fuente que la
227
+ // pintura (visual.fontFamily resuelto por el glue, fontSizePx).
228
+ if (auto it = nd->visual.find("fontFamily");
229
+ it != nd->visual.end() && !it->second.empty()) {
230
+ ns.push_back("family-name");
231
+ vs.push_back(it->second);
232
+ }
233
+ if (nd->fontSizePx > 0) {
234
+ char b[24];
235
+ snprintf(b, sizeof b, "%d", (int)(nd->fontSizePx * 0.75 + 0.5f));
236
+ ns.push_back("size");
237
+ vs.push_back(b); // px → pt, como lo reporta Pango
238
+ }
239
+ if (auto it = nd->visual.find("fontWeight");
240
+ it != nd->visual.end() && !it->second.empty()) {
241
+ ns.push_back("weight");
242
+ vs.push_back(it->second == "bold" ? "700" : it->second);
243
+ }
244
+ }
245
+ if (ns.empty())
246
+ return FALSE;
247
+ guint len = g_utf8_strlen(a11yNodeText(a).c_str(), -1);
248
+ *ranges = g_new(GtkAccessibleTextRange, ns.size());
249
+ *names = g_new(char *, ns.size() + 1);
250
+ *values = g_new(char *, ns.size() + 1);
251
+ for (size_t i = 0; i < ns.size(); i++) {
252
+ (*ranges)[i] = {0, len};
253
+ (*names)[i] = g_strdup(ns[i].c_str());
254
+ (*values)[i] = g_strdup(vs[i].c_str());
255
+ }
256
+ (*names)[ns.size()] = nullptr;
257
+ (*values)[ns.size()] = nullptr;
258
+ *n = ns.size();
259
+ return TRUE;
260
+ }
261
+
262
+ static void a11yTextGetDefaultAttributes(GtkAccessibleText *, char ***names,
263
+ char ***values) {
264
+ // El handler D-Bus itera names[i] sin NULL-check (gtkatspitext.c —
265
+ // GetDefaultAttributes/GetDefaultAttributeSet): NULL → SEGV.
266
+ *names = g_new0(char *, 1);
267
+ *values = g_new0(char *, 1);
268
+ }
269
+
270
+ static void skiaA11yTextInit(GtkAccessibleTextInterface *iface) {
271
+ iface->get_contents = a11yTextGetContents;
272
+ iface->get_contents_at = a11yTextGetContentsAt;
273
+ iface->get_caret_position = a11yTextGetCaretPosition;
274
+ iface->get_selection = a11yTextGetSelection;
275
+ iface->get_attributes = a11yTextGetAttributes;
276
+ iface->get_default_attributes = a11yTextGetDefaultAttributes;
277
+ }
278
+
279
+ // ── ElurSkiaArea — el canvas que injerta el árbol virtual ──────────
280
+ // Subclase de GtkDrawingArea cuyo get_first_accessible_child devuelve
281
+ // la raíz virtual: el árbol AT-SPI la descubre por enumeración vfunc
282
+ // pura (sin context-stored parents/siblings — esas rutas privadas de
283
+ // gtkaccessible.c disparan un unref que desecha el widget bajo bus
284
+ // atspi activo; medido: g_object_unref en update_next_accessible_sibling
285
+ // acababa en dispose en cadena del área → use-after-free).
286
+ typedef struct _ElurSkiaArea ElurSkiaArea;
287
+ typedef struct {
288
+ GtkDrawingAreaClass parent_class;
289
+ } ElurSkiaAreaClass;
290
+ struct _ElurSkiaArea {
291
+ GtkDrawingArea parent_instance;
292
+ elur::SkiaA11y *mgr;
293
+ };
294
+
295
+ #define ELUR_TYPE_SKIA_AREA (elur_skia_area_get_type())
296
+ #define ELUR_SKIA_AREA(o) \
297
+ (G_TYPE_CHECK_INSTANCE_CAST((o), ELUR_TYPE_SKIA_AREA, ElurSkiaArea))
298
+ GType elur_skia_area_get_type(void);
299
+
300
+ static void skiaAreaAccessibleInit(GtkAccessibleInterface *iface);
301
+
302
+ G_DEFINE_TYPE_WITH_CODE(ElurSkiaArea, elur_skia_area, GTK_TYPE_DRAWING_AREA,
303
+ G_IMPLEMENT_INTERFACE(GTK_TYPE_ACCESSIBLE,
304
+ skiaAreaAccessibleInit))
305
+
306
+ static void elur_skia_area_class_init(ElurSkiaAreaClass *) {}
307
+ static void elur_skia_area_init(ElurSkiaArea *self) { self->mgr = nullptr; }
308
+
309
+ static GtkAccessible *skiaAreaFirstChild(GtkAccessible *acc) {
310
+ ElurSkiaArea *self = ELUR_SKIA_AREA(acc);
311
+ if (!self->mgr)
312
+ return nullptr;
313
+ void *c = self->mgr->firstRootAcc();
314
+ return c ? GTK_ACCESSIBLE(g_object_ref(G_OBJECT(c))) : nullptr;
315
+ }
316
+
317
+ static void skiaAreaAccessibleInit(GtkAccessibleInterface *iface) {
318
+ // Solo first_child — el resto de vfuncs quedan heredados del
319
+ // impl GtkWidget del padre (parent/siblings/bounds de widget).
320
+ iface->get_first_accessible_child = skiaAreaFirstChild;
321
+ }
322
+
323
+ GtkWidget *elur_skia_area_new(void) {
324
+ return GTK_WIDGET(g_object_new(elur_skia_area_get_type(), nullptr));
325
+ }
326
+
327
+ // ── ElurSkiaGlArea — mismo injerto accesible sobre GtkGLArea ──────
328
+ // Backend GPU opt-in (fase 4). Idéntico layout {parent, mgr} para que
329
+ // set_a11y/shutdown sirvan a cualquiera de las dos superficies.
330
+ typedef struct _ElurSkiaGlArea ElurSkiaGlArea;
331
+ typedef struct {
332
+ GtkGLAreaClass parent_class;
333
+ } ElurSkiaGlAreaClass;
334
+ struct _ElurSkiaGlArea {
335
+ GtkGLArea parent_instance;
336
+ elur::SkiaA11y *mgr;
337
+ };
338
+
339
+ #define ELUR_TYPE_SKIA_GLAREA (elur_skia_glarea_get_type())
340
+ #define ELUR_SKIA_GLAREA(o) \
341
+ (G_TYPE_CHECK_INSTANCE_CAST((o), ELUR_TYPE_SKIA_GLAREA, ElurSkiaGlArea))
342
+ GType elur_skia_glarea_get_type(void);
343
+
344
+ static void skiaGlAreaAccessibleInit(GtkAccessibleInterface *iface);
345
+
346
+ G_DEFINE_TYPE_WITH_CODE(ElurSkiaGlArea, elur_skia_glarea, GTK_TYPE_GL_AREA,
347
+ G_IMPLEMENT_INTERFACE(GTK_TYPE_ACCESSIBLE,
348
+ skiaGlAreaAccessibleInit))
349
+
350
+ static void elur_skia_glarea_class_init(ElurSkiaGlAreaClass *) {}
351
+ static void elur_skia_glarea_init(ElurSkiaGlArea *self) { self->mgr = nullptr; }
352
+
353
+ static GtkAccessible *skiaGlAreaFirstChild(GtkAccessible *acc) {
354
+ ElurSkiaGlArea *self = ELUR_SKIA_GLAREA(acc);
355
+ if (!self->mgr)
356
+ return nullptr;
357
+ void *c = self->mgr->firstRootAcc();
358
+ return c ? GTK_ACCESSIBLE(g_object_ref(G_OBJECT(c))) : nullptr;
359
+ }
360
+
361
+ static void skiaGlAreaAccessibleInit(GtkAccessibleInterface *iface) {
362
+ iface->get_first_accessible_child = skiaGlAreaFirstChild;
363
+ }
364
+
365
+ GtkWidget *elur_skia_glarea_new(void) {
366
+ return GTK_WIDGET(g_object_new(elur_skia_glarea_get_type(), nullptr));
367
+ }
368
+
369
+ void elur_skia_area_set_a11y(GtkWidget *area, elur::SkiaA11y *mgr) {
370
+ if (G_TYPE_CHECK_INSTANCE_TYPE(G_OBJECT(area), ELUR_TYPE_SKIA_GLAREA))
371
+ ELUR_SKIA_GLAREA(area)->mgr = mgr;
372
+ else
373
+ ELUR_SKIA_AREA(area)->mgr = mgr;
374
+ }
375
+
376
+ namespace elur {
377
+
378
+ static bool dbg() { return getenv("ELUR_DEBUG") != nullptr; }
379
+
380
+ void SkiaA11y::init(GtkWidget *area, skia::SkiaTree *tree) {
381
+ area_ = area;
382
+ tree_ = tree;
383
+ elur_skia_area_set_a11y(area, this);
384
+ }
385
+
386
+ void SkiaA11y::shutdown() {
387
+ if (drainSrc_) {
388
+ g_source_remove(drainSrc_);
389
+ drainSrc_ = 0;
390
+ }
391
+ pending_.clear();
392
+ // El widget sobrevive al manager en el teardown — su vfunc de
393
+ // first_child desreferencia mgr si queda colgando.
394
+ if (area_)
395
+ elur_skia_area_set_a11y(area_, nullptr);
396
+ for (auto &kv : accs_)
397
+ g_object_unref(kv.second);
398
+ accs_.clear();
399
+ }
400
+
401
+ void SkiaA11y::announced(int id) { pending_.erase(id); }
402
+
403
+ void SkiaA11y::setFocused(int id, bool f) {
404
+ if (f)
405
+ focusedId_ = id;
406
+ else if (focusedId_ == id)
407
+ focusedId_ = 0;
408
+ auto it = accs_.find(id);
409
+ if (it != accs_.end())
410
+ ELUR_SKIA_A11Y(it->second)->focused = f;
411
+ }
412
+
413
+ static gboolean skiaA11yDrainTick(gpointer ud) {
414
+ static_cast<SkiaA11y *>(ud)->drainPending();
415
+ return G_SOURCE_REMOVE;
416
+ }
417
+
418
+ void SkiaA11y::armDrain() {
419
+ if (!draining_ && !pending_.empty() && !drainSrc_) {
420
+ drainCount_ = 0;
421
+ drainSrc_ = g_timeout_add(120, skiaA11yDrainTick, this);
422
+ }
423
+ }
424
+
425
+ void SkiaA11y::drainPending() {
426
+ draining_ = true;
427
+ drainSrc_ = 0;
428
+ std::vector<int> ids(pending_.begin(), pending_.end());
429
+ for (int id : ids) {
430
+ auto ni = tree_->nodes.find(id);
431
+ auto it = accs_.find(id);
432
+ if (ni == tree_->nodes.end() || it == accs_.end() ||
433
+ ni->second.absorbedBy || ELUR_SKIA_A11Y(it->second)->hidden) {
434
+ pending_.erase(id);
435
+ continue;
436
+ }
437
+ childLinked(id); // re-injerta+flap; la señal borra los que emiten
438
+ }
439
+ draining_ = false;
440
+ if (!pending_.empty() && ++drainCount_ < 50)
441
+ drainSrc_ = g_timeout_add(120, skiaA11yDrainTick, this);
442
+ }
443
+
444
+ int SkiaA11y::naturalRole(const std::string &type) const {
445
+ if (type == "button")
446
+ return GTK_ACCESSIBLE_ROLE_BUTTON;
447
+ if (type == "text")
448
+ return GTK_ACCESSIBLE_ROLE_LABEL;
449
+ if (type == "text-input")
450
+ return GTK_ACCESSIBLE_ROLE_TEXT_BOX;
451
+ if (type == "switch")
452
+ return GTK_ACCESSIBLE_ROLE_SWITCH;
453
+ if (type == "slider")
454
+ return GTK_ACCESSIBLE_ROLE_SLIDER;
455
+ if (type == "image")
456
+ return GTK_ACCESSIBLE_ROLE_IMG;
457
+ // Contenedores: mismo rol que un GtkWidget sin rol explícito
458
+ // (paridad views — el atspi lo expone como panel/filler).
459
+ return GTK_ACCESSIBLE_ROLE_WIDGET;
460
+ }
461
+
462
+ void *SkiaA11y::ensure(int id) {
463
+ auto it = accs_.find(id);
464
+ if (it != accs_.end())
465
+ return it->second;
466
+ auto ni = tree_->nodes.find(id);
467
+ if (ni == tree_->nodes.end())
468
+ return nullptr;
469
+ ElurSkiaA11y *a =
470
+ ELUR_SKIA_A11Y(g_object_new(elur_skia_a11y_get_type(), nullptr));
471
+ a->mgr = this;
472
+ a->id = id;
473
+ if (dbg())
474
+ fprintf(stderr, "[a11y] ensure id=%d type=%s\n", id,
475
+ ni->second.type.c_str());
476
+ a->role = naturalRole(ni->second.type);
477
+ const std::string &t = ni->second.type;
478
+ a->focusable =
479
+ t == "button" || t == "text-input" || t == "switch" || t == "slider";
480
+ a->focused = id == focusedId_; // puede materializar tras el foco
481
+ accs_[id] = a;
482
+ // Paridad GtkLabel: el name de un text es su propio texto desde la
483
+ // materialización (el acc puede nacer tras un set-text anterior).
484
+ if (t == "text" && !ni->second.text.empty())
485
+ gtk_accessible_update_property(GTK_ACCESSIBLE(a),
486
+ GTK_ACCESSIBLE_PROPERTY_LABEL,
487
+ ni->second.text.c_str(), -1);
488
+ return a;
489
+ }
490
+
491
+ void SkiaA11y::add(int id) { ensure(id); }
492
+
493
+ void SkiaA11y::childLinked(int childId) {
494
+ auto ni = tree_->nodes.find(childId);
495
+ if (ni == tree_->nodes.end())
496
+ return;
497
+ auto it = accs_.find(childId);
498
+ if (it == accs_.end())
499
+ return;
500
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(it->second);
501
+ if (!a->hidden && !ni->second.absorbedBy) {
502
+ // NO set_accessible_parent: un accessible_parent almacenado hace
503
+ // que get_next_accessible_sibling devuelva el sibling almacenado
504
+ // (inexistente) en vez del vfunc — la enumeración truncaba cada
505
+ // padre a su primer hijo. La realización llega por la propia
506
+ // enumeración del registry (GetChildren realiza cada ctx que
507
+ // sirve); el drenaje re-dispara los flaps silenciosos hasta que
508
+ // su ctx se realiza — el bootstrap lo da el área, widget cuyo ctx
509
+ // se realiza al primer walk de la ventana.
510
+ pending_.insert(childId);
511
+ announceStructure(childId);
512
+ armDrain();
513
+ }
514
+ // Si el enlace absorbió al hijo (button), su texto es el name del
515
+ // padre — paridad GtkButton(label=…): el hijo no sale al AT.
516
+ if (!ni->second.absorbedBy)
517
+ return;
518
+ auto pi = tree_->nodes.find(ni->second.absorbedBy);
519
+ if (pi != tree_->nodes.end())
520
+ if (void *p = accFor(pi->first))
521
+ gtk_accessible_update_property(GTK_ACCESSIBLE(p),
522
+ GTK_ACCESSIBLE_PROPERTY_LABEL,
523
+ pi->second.absorbedText.c_str(), -1);
524
+ }
525
+
526
+ void SkiaA11y::childUnlinked(int childId) {
527
+ auto ni = tree_->nodes.find(childId);
528
+ if (ni == tree_->nodes.end())
529
+ return;
530
+ // Sin padre ni raíz = aún no está en el AT (nodo recién creado) —
531
+ // no hay nada que retirar.
532
+ if (!ni->second.parent && std::find(tree_->roots.begin(), tree_->roots.end(),
533
+ childId) == tree_->roots.end())
534
+ return;
535
+ void *v = accFor(childId); // nullptr si nunca estuvo en el AT
536
+ if (!v)
537
+ return;
538
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(v);
539
+ if (!a->atctx)
540
+ return;
541
+ // REMOVED llega al padre aún intacto vía el cambio de HIDDEN — la
542
+ // notificación estructural solo existe por esta vía en API pública.
543
+ gtk_accessible_update_state(GTK_ACCESSIBLE(a), GTK_ACCESSIBLE_STATE_HIDDEN,
544
+ TRUE, -1);
545
+ pending_.erase(childId);
546
+ }
547
+
548
+ void *SkiaA11y::firstRootAcc() {
549
+ for (int r : tree_->roots) {
550
+ void *a = accFor(r);
551
+ if (a)
552
+ return a;
553
+ }
554
+ return nullptr;
555
+ }
556
+
557
+ void SkiaA11y::collectSubtree(int id, std::vector<int> &out) {
558
+ auto ni = tree_->nodes.find(id);
559
+ if (ni == tree_->nodes.end())
560
+ return;
561
+ out.push_back(id);
562
+ for (int c : ni->second.children)
563
+ collectSubtree(c, out);
564
+ }
565
+
566
+ void SkiaA11y::remove(int id) {
567
+ std::vector<int> ids;
568
+ collectSubtree(id, ids);
569
+ for (int c : ids) {
570
+ pending_.erase(c);
571
+ auto it = accs_.find(c);
572
+ if (it == accs_.end())
573
+ continue;
574
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(it->second);
575
+ // REMOVED llega al padre vía el cambio de HIDDEN (el atspi lo
576
+ // deriva) — el árbol aún está intacto en este punto.
577
+ if (a->atctx)
578
+ gtk_accessible_update_state(GTK_ACCESSIBLE(a),
579
+ GTK_ACCESSIBLE_STATE_HIDDEN, TRUE, -1);
580
+ g_object_unref(a);
581
+ accs_.erase(it);
582
+ }
583
+ }
584
+
585
+ void *SkiaA11y::accFor(int id) {
586
+ auto it = accs_.find(id);
587
+ if (it == accs_.end())
588
+ return nullptr;
589
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(it->second);
590
+ if (a->hidden)
591
+ return nullptr;
592
+ // Hijos absorbidos (button) — su acc existe pero no sale al AT:
593
+ // paridad views, donde el absorbido no materializa widget.
594
+ auto ni = tree_->nodes.find(id);
595
+ if (ni != tree_->nodes.end() && ni->second.absorbedBy)
596
+ return nullptr;
597
+ return a;
598
+ }
599
+
600
+ void *SkiaA11y::parentAcc(int id) {
601
+ auto ni = tree_->nodes.find(id);
602
+ if (ni == tree_->nodes.end())
603
+ return nullptr;
604
+ int p = ni->second.parent;
605
+ while (p) {
606
+ void *a = accFor(p);
607
+ if (a)
608
+ return a;
609
+ auto pi = tree_->nodes.find(p);
610
+ if (pi == tree_->nodes.end())
611
+ break;
612
+ p = pi->second.parent;
613
+ }
614
+ // Sin ancestro accesible: la raíz virtual cuelga del propio área —
615
+ // es su first_accessible_child por el vfunc de ElurSkiaArea.
616
+ return GTK_ACCESSIBLE(area_);
617
+ }
618
+
619
+ // Primer acc del subárbol de `id` en orden de documento, sin contar el
620
+ // propio id — los descendientes de nodos no-accesibles se aplanan.
621
+ static void *firstAccDescendant(SkiaA11y *self, skia::SkiaTree *tree, int id) {
622
+ auto ni = tree->nodes.find(id);
623
+ if (ni == tree->nodes.end())
624
+ return nullptr;
625
+ for (int c : ni->second.children) {
626
+ if (void *a = self->accFor(c))
627
+ return a;
628
+ if (void *a = firstAccDescendant(self, tree, c))
629
+ return a;
630
+ }
631
+ return nullptr;
632
+ }
633
+
634
+ void *SkiaA11y::firstChildAcc(int id) {
635
+ return firstAccDescendant(this, tree_, id);
636
+ }
637
+
638
+ void *SkiaA11y::nextSiblingAcc(int id) {
639
+ auto ni = tree_->nodes.find(id);
640
+ if (ni == tree_->nodes.end())
641
+ return nullptr;
642
+ int cur = id;
643
+ for (;;) {
644
+ const std::vector<int> *sibs = nullptr;
645
+ int parent = 0;
646
+ auto ci = tree_->nodes.find(cur);
647
+ if (ci == tree_->nodes.end())
648
+ return nullptr;
649
+ parent = ci->second.parent;
650
+ if (parent) {
651
+ auto pi = tree_->nodes.find(parent);
652
+ if (pi == tree_->nodes.end())
653
+ return nullptr;
654
+ sibs = &pi->second.children;
655
+ } else {
656
+ sibs = &tree_->roots;
657
+ }
658
+ auto it = std::find(sibs->begin(), sibs->end(), cur);
659
+ if (it == sibs->end())
660
+ return nullptr;
661
+ for (++it; it != sibs->end(); ++it) {
662
+ if (void *a = accFor(*it))
663
+ return a;
664
+ if (void *a = firstAccDescendant(this, tree_, *it))
665
+ return a;
666
+ }
667
+ // Sin más hermanos accesibles a este nivel: si el padre tiene acc
668
+ // propio, el nodo era su último hijo accesible → fin; si no, el
669
+ // padre se aplasta y los hermanos siguen un nivel arriba.
670
+ if (!parent || accFor(parent))
671
+ return nullptr;
672
+ cur = parent;
673
+ }
674
+ }
675
+
676
+ bool SkiaA11y::absPos(int id, float &ax, float &ay) const {
677
+ auto ni = tree_->nodes.find(id);
678
+ if (ni == tree_->nodes.end() || !ni->second.hasRect)
679
+ return false;
680
+ ax = ni->second.rx;
681
+ ay = ni->second.ry;
682
+ int p = ni->second.parent;
683
+ while (p) {
684
+ auto pi = tree_->nodes.find(p);
685
+ if (pi == tree_->nodes.end())
686
+ break;
687
+ ax += pi->second.rx - pi->second.scrollX;
688
+ ay += pi->second.ry - pi->second.scrollY;
689
+ p = pi->second.parent;
690
+ }
691
+ return true;
692
+ }
693
+
694
+ bool SkiaA11y::bounds(int id, int &x, int &y, int &w, int &h) {
695
+ auto ni = tree_->nodes.find(id);
696
+ if (ni == tree_->nodes.end() || !ni->second.hasRect)
697
+ return false;
698
+ float ax, ay;
699
+ if (!absPos(id, ax, ay))
700
+ return false;
701
+ // get_bounds es en espacio del padre accesible — el ancestro acc
702
+ // más cercano (o el contenedor del área para raíces, ~origen 0,0).
703
+ float px = 0, py = 0;
704
+ int p = ni->second.parent;
705
+ while (p) {
706
+ void *a = accFor(p);
707
+ if (a) {
708
+ absPos(p, px, py);
709
+ break;
710
+ }
711
+ auto pi = tree_->nodes.find(p);
712
+ if (pi == tree_->nodes.end())
713
+ break;
714
+ p = pi->second.parent;
715
+ }
716
+ x = (int)(ax - px + 0.5f);
717
+ y = (int)(ay - py + 0.5f);
718
+ w = (int)(ni->second.rw + 0.5f);
719
+ if (dbg())
720
+ fprintf(stderr,
721
+ "[a11y] bounds id=%d rel=(%d,%d %dx%d) abs=(%.0f,%.0f) "
722
+ "pabs=(%.0f,%.0f) rect=(%.0f,%.0f %.0fx%.0f)\n",
723
+ id, x, y, w, (int)(ni->second.rh + 0.5f), ax, ay, px, py,
724
+ ni->second.rx, ni->second.ry, ni->second.rw, ni->second.rh);
725
+ h = (int)(ni->second.rh + 0.5f);
726
+ return true;
727
+ }
728
+
729
+ void SkiaA11y::announceStructure(int id) {
730
+ auto it = accs_.find(id);
731
+ if (it == accs_.end())
732
+ return;
733
+ // El acc existe pero no está en el AT (hidden semántico, absorbido):
734
+ // anunciarlo generaría un refetch sin cambio visible.
735
+ auto ni = tree_->nodes.find(id);
736
+ if (ni == tree_->nodes.end() || ni->second.absorbedBy)
737
+ return;
738
+ GtkAccessible *acc = GTK_ACCESSIBLE(it->second);
739
+ if (ELUR_SKIA_A11Y(acc)->hidden)
740
+ return;
741
+ if (dbg())
742
+ fprintf(stderr, "[a11y] announce id=%d hidden=%d\n", id,
743
+ (int)ELUR_SKIA_A11Y(acc)->hidden);
744
+ // Transición HIDDEN true→false = ChildrenChanged(ADDED) sobre el
745
+ // padre (el contexto atspi lo deriva del cambio de estado — la única
746
+ // vía de notificación estructural en la API pública de GTK4).
747
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_HIDDEN, TRUE, -1);
748
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_HIDDEN, FALSE, -1);
749
+ }
750
+
751
+ std::string SkiaA11y::textContent(int id) const {
752
+ const skia::SkiaNode *n = nodeFor(id);
753
+ if (!n)
754
+ return {};
755
+ if (n->type == "text-input") {
756
+ auto it = n->props.find("value");
757
+ return it != n->props.end() ? it->second : std::string();
758
+ }
759
+ // Paridad GtkButton: su AccessibleText reporta el label — en el
760
+ // árbol ese texto vive absorbido del hijo text.
761
+ if (n->type == "button")
762
+ return n->absorbedText;
763
+ return n->type == "text" ? n->text : std::string();
764
+ }
765
+
766
+ const skia::SkiaNode *SkiaA11y::nodeFor(int id) const {
767
+ auto ni = tree_->nodes.find(id);
768
+ return ni == tree_->nodes.end() ? nullptr : &ni->second;
769
+ }
770
+
771
+ void SkiaA11y::textChanged(int id) {
772
+ auto it = accs_.find(id);
773
+ if (it == accs_.end())
774
+ return;
775
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(it->second);
776
+ auto ni = tree_->nodes.find(id);
777
+ if (ni == tree_->nodes.end())
778
+ return;
779
+ // Paridad GtkLabel: el accessible-name de un text es su propio
780
+ // texto — `label` no lo sobrescribe (documentado en el TCK).
781
+ if (ni->second.type == "text") {
782
+ gtk_accessible_update_property(GTK_ACCESSIBLE(a),
783
+ GTK_ACCESSIBLE_PROPERTY_LABEL,
784
+ ni->second.text.c_str(), -1);
785
+ guint len = g_utf8_strlen(ni->second.text.c_str(), -1);
786
+ gtk_accessible_text_update_contents(
787
+ GTK_ACCESSIBLE_TEXT(a), GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_INSERT, 0,
788
+ len);
789
+ // Absorbido por un button: el texto vive en el name del padre.
790
+ if (ni->second.absorbedBy)
791
+ if (void *p = accFor(ni->second.absorbedBy))
792
+ if (auto pi = tree_->nodes.find(ni->second.absorbedBy);
793
+ pi != tree_->nodes.end())
794
+ gtk_accessible_update_property(GTK_ACCESSIBLE(p),
795
+ GTK_ACCESSIBLE_PROPERTY_LABEL,
796
+ pi->second.absorbedText.c_str(), -1);
797
+ }
798
+ if (!a->liveLevel || a->hidden)
799
+ return;
800
+ gtk_accessible_announce(GTK_ACCESSIBLE(a), ni->second.text.c_str(),
801
+ a->liveLevel > 1
802
+ ? GTK_ACCESSIBLE_ANNOUNCEMENT_PRIORITY_HIGH
803
+ : GTK_ACCESSIBLE_ANNOUNCEMENT_PRIORITY_MEDIUM);
804
+ }
805
+
806
+ void SkiaA11y::applyAs(int id, const std::string &s) {
807
+ // Paridad views/Android: solo h1–h6 materializan rol heading; el
808
+ // resto de etiquetas se ignora (documentado en applyProp del
809
+ // aplicador views — `as` llega por set-prop, no por update-semantics).
810
+ if (s.size() != 2 || s[0] != 'h' || s[1] < '1' || s[1] > '6')
811
+ return;
812
+ void *v = ensure(id);
813
+ if (!v)
814
+ return;
815
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(v);
816
+ if (a->role != GTK_ACCESSIBLE_ROLE_HEADING) {
817
+ a->role = GTK_ACCESSIBLE_ROLE_HEADING;
818
+ g_object_notify(G_OBJECT(a), "accessible-role");
819
+ g_clear_object(&a->atctx); // el rol vive en el ctx → recrear
820
+ }
821
+ gtk_accessible_update_property(GTK_ACCESSIBLE(a),
822
+ GTK_ACCESSIBLE_PROPERTY_ROLE_DESCRIPTION,
823
+ s.c_str(), -1);
824
+ }
825
+
826
+ // Mismo vocabulario que Applicator::applySemantics (ADR-0117) — cada
827
+ // clave materializa en el acc virtual con las mismas funciones
828
+ // públicas; sin widgets que actualizar (el acc ES el objeto AT).
829
+ void SkiaA11y::apply(int id, const std::string &key, bool isNull,
830
+ const std::string &s, double num, bool b) {
831
+ GtkAccessible *acc = GTK_ACCESSIBLE(ensure(id));
832
+ if (!acc)
833
+ return;
834
+ ElurSkiaA11y *a = ELUR_SKIA_A11Y(acc);
835
+ auto ni = tree_->nodes.find(id);
836
+ if (ni == tree_->nodes.end())
837
+ return;
838
+ const std::string &type = ni->second.type;
839
+
840
+ if (key == "label") {
841
+ // Paridad GtkLabel: en un nodo `text` el name es su propio texto —
842
+ // `label` no lo sobrescribe (gap de plataforma del propio GTK,
843
+ // replicado aquí para que el TCK valga a ambos carriles).
844
+ if (type == "text") {
845
+ gtk_accessible_update_property(acc, GTK_ACCESSIBLE_PROPERTY_LABEL,
846
+ ni->second.text.c_str(), -1);
847
+ } else if (isNull)
848
+ gtk_accessible_reset_property(acc, GTK_ACCESSIBLE_PROPERTY_LABEL);
849
+ else
850
+ gtk_accessible_update_property(acc, GTK_ACCESSIBLE_PROPERTY_LABEL,
851
+ s.c_str(), -1);
852
+ } else if (key == "accessible") {
853
+ if (isNull || b) {
854
+ if (a->hidden) {
855
+ a->hidden = false;
856
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_HIDDEN, FALSE,
857
+ -1);
858
+ }
859
+ } else if (!a->hidden) {
860
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_HIDDEN, TRUE, -1);
861
+ a->hidden = true;
862
+ }
863
+ } else if (key == "role") {
864
+ if (isNull) {
865
+ gtk_accessible_reset_property(acc,
866
+ GTK_ACCESSIBLE_PROPERTY_ROLE_DESCRIPTION);
867
+ if (a->role != naturalRole(type)) {
868
+ a->role = naturalRole(type);
869
+ g_clear_object(&a->atctx); // el rol vive en el ctx → recrear
870
+ }
871
+ } else {
872
+ GtkAccessibleRole r;
873
+ if (elurAriaRole(s, r) && (int)r != a->role) {
874
+ a->role = r;
875
+ g_object_notify(G_OBJECT(a), "accessible-role");
876
+ g_clear_object(&a->atctx);
877
+ }
878
+ gtk_accessible_update_property(
879
+ acc, GTK_ACCESSIBLE_PROPERTY_ROLE_DESCRIPTION, s.c_str(), -1);
880
+ }
881
+ } else if (key == "live") {
882
+ a->liveLevel = isNull ? 0 : s == "assertive" ? 2 : s == "polite" ? 1 : 0;
883
+ } else if (key == "checked") {
884
+ // Paridad views: materializa el control Y el estado AT — el
885
+ // checked visual del switch/slider vive en props del árbol.
886
+ if (type == "switch" && !isNull) {
887
+ tree_->setProp(id, "checked", s != "mixed" && b ? "true" : "false");
888
+ gtk_widget_queue_draw(area_);
889
+ }
890
+ if (isNull)
891
+ gtk_accessible_reset_state(acc, GTK_ACCESSIBLE_STATE_CHECKED);
892
+ else
893
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_CHECKED,
894
+ s == "mixed" ? GTK_ACCESSIBLE_TRISTATE_MIXED
895
+ : b ? GTK_ACCESSIBLE_TRISTATE_TRUE
896
+ : GTK_ACCESSIBLE_TRISTATE_FALSE,
897
+ -1);
898
+ } else if (key == "selected") {
899
+ if (isNull)
900
+ gtk_accessible_reset_state(acc, GTK_ACCESSIBLE_STATE_SELECTED);
901
+ else
902
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_SELECTED,
903
+ b ? TRUE : FALSE, -1);
904
+ } else if (key == "disabled") {
905
+ if (isNull)
906
+ gtk_accessible_reset_state(acc, GTK_ACCESSIBLE_STATE_DISABLED);
907
+ else
908
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_DISABLED,
909
+ b ? TRUE : FALSE, -1);
910
+ } else if (key == "hint") {
911
+ if (isNull)
912
+ gtk_accessible_reset_property(acc, GTK_ACCESSIBLE_PROPERTY_DESCRIPTION);
913
+ else
914
+ gtk_accessible_update_property(acc, GTK_ACCESSIBLE_PROPERTY_DESCRIPTION,
915
+ s.c_str(), -1);
916
+ } else if (key == "focused") {
917
+ a->focused = !isNull && b;
918
+ // platform_changed no tiene emit público en GTK4 — el AT lee
919
+ // FOCUSED bajo demanda (gap hasta la cadena de foco).
920
+ } else if (key == "focusable") {
921
+ bool def = type == "text-input" || type == "button" || type == "switch" ||
922
+ type == "slider";
923
+ a->focusable = isNull ? def : b;
924
+ } else if (key == "expanded") {
925
+ if (isNull)
926
+ gtk_accessible_reset_state(acc, GTK_ACCESSIBLE_STATE_EXPANDED);
927
+ else
928
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_EXPANDED,
929
+ b ? TRUE : FALSE, -1);
930
+ // La acción expand/collapse derivada (ADR-0190) necesita el muxer
931
+ // GAction — sin iface Action para no-widgets en el atspi (gap).
932
+ } else if (key == "invalid") {
933
+ GtkAccessibleInvalidState inv =
934
+ isNull ? GTK_ACCESSIBLE_INVALID_FALSE
935
+ : s == "grammar" ? GTK_ACCESSIBLE_INVALID_GRAMMAR
936
+ : s == "spelling" ? GTK_ACCESSIBLE_INVALID_SPELLING
937
+ : b ? GTK_ACCESSIBLE_INVALID_TRUE
938
+ : GTK_ACCESSIBLE_INVALID_FALSE;
939
+ gtk_accessible_update_state(acc, GTK_ACCESSIBLE_STATE_INVALID, inv, -1);
940
+ } else if (key == "required") {
941
+ if (isNull)
942
+ gtk_accessible_reset_property(acc, GTK_ACCESSIBLE_PROPERTY_REQUIRED);
943
+ else
944
+ gtk_accessible_update_property(acc, GTK_ACCESSIBLE_PROPERTY_REQUIRED,
945
+ b ? TRUE : FALSE, -1);
946
+ } else if (key == "valueMin" || key == "valueMax" || key == "valueNow") {
947
+ GtkAccessibleProperty p =
948
+ key == "valueMin" ? GTK_ACCESSIBLE_PROPERTY_VALUE_MIN
949
+ : key == "valueMax" ? GTK_ACCESSIBLE_PROPERTY_VALUE_MAX
950
+ : GTK_ACCESSIBLE_PROPERTY_VALUE_NOW;
951
+ if (isNull)
952
+ gtk_accessible_reset_property(acc, p);
953
+ else
954
+ gtk_accessible_update_property(acc, p, num, -1);
955
+ } else if (key == "valueText") {
956
+ if (isNull)
957
+ gtk_accessible_reset_property(acc, GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT);
958
+ else
959
+ gtk_accessible_update_property(acc, GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT,
960
+ s.c_str(), -1);
961
+ } else if (key == "actions") {
962
+ // org.a11y.atspi.Action solo se registra para accessibles con
963
+ // Action vtable (widgets con muxer — gtkatspicontext.c); un
964
+ // GObject puro no la obtiene. Gap declarado: las acciones AT del
965
+ // carril Skia esperan decisión de diseño (muxer externo o acción
966
+ // sintética). Warn explícito — nunca silencio.
967
+ static bool warned = false;
968
+ if (!warned) {
969
+ warned = true;
970
+ g_warning("[skia] semantics 'actions' sin soporte en el carril "
971
+ "Skia (AT-SPI Action requiere widget)");
972
+ }
973
+ } else {
974
+ static std::unordered_set<std::string> seen;
975
+ if (seen.insert(key).second)
976
+ g_warning("[skia] semantics desconocida: %s", key.c_str());
977
+ }
978
+ }
979
+
980
+ } // namespace elur
981
+
982
+ #else
983
+ // Build stub — el símbolo existe para que main.cpp compile; wantSkia
984
+ // es falso sin la lib así que el área retornada no llega a usarse.
985
+ GtkWidget *elur_skia_area_new(void) { return gtk_drawing_area_new(); }
986
+ GtkWidget *elur_skia_glarea_new(void) { return gtk_drawing_area_new(); }
987
+ #endif // ELUR_HAS_SKIA