@ng-native/desktop 0.26.1 → 0.27.0

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 (256) hide show
  1. package/README.md +6 -3
  2. package/bin/app-config.mjs +1 -0
  3. package/bin/archive.mjs +166 -0
  4. package/bin/autolink.mjs +61 -30
  5. package/bin/cli.mjs +127 -27
  6. package/bin/host.mjs +255 -58
  7. package/bin/package-linux.mjs +1394 -0
  8. package/bin/package.mjs +171 -35
  9. package/bin/plist.mjs +6 -2
  10. package/bin/png-icon.mjs +315 -0
  11. package/bin/prebuilt.mjs +147 -26
  12. package/bin/toolchain.mjs +258 -19
  13. package/native/CMakeLists.txt +64 -6
  14. package/native/appkit/CMakeLists.txt +2 -1
  15. package/native/appkit/appkit-backend.h +1 -0
  16. package/native/appkit/appkit-backend.mm +13 -0
  17. package/native/appkit/header-toolbar.mm +28 -25
  18. package/native/appkit/host-view.h +10 -0
  19. package/native/appkit/host-view.mm +146 -40
  20. package/native/appkit/input-replay.h +6 -0
  21. package/native/appkit/input-replay.mm +21 -12
  22. package/native/appkit/main.mm +11 -7
  23. package/native/appkit/native-controls.mm +13 -1
  24. package/native/appkit/split-view.mm +7 -13
  25. package/native/appkit/text-input-field.h +4 -0
  26. package/native/appkit/text-input-field.mm +20 -1
  27. package/native/cmake/curl.cmake +79 -0
  28. package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
  29. package/native/cmake/libraries/react-native-worklets.cmake +5 -0
  30. package/native/cmake/linked-modules.cmake +20 -4
  31. package/native/cmake/react-native.cmake +18 -1
  32. package/native/core/include/ngn/accent-colors.h +38 -0
  33. package/native/core/include/ngn/accessibility-relations.h +65 -0
  34. package/native/core/include/ngn/accessibility.h +26 -0
  35. package/native/core/include/ngn/animated-frame-loop.h +56 -0
  36. package/native/core/include/ngn/app-info.h +24 -8
  37. package/native/core/include/ngn/app-menus.h +14 -1
  38. package/native/core/include/ngn/app-windows.h +15 -2
  39. package/native/core/include/ngn/aria-role.h +96 -0
  40. package/native/core/include/ngn/audio.h +2 -0
  41. package/native/core/include/ngn/camera.h +9 -0
  42. package/native/core/include/ngn/control-sizes.h +7 -2
  43. package/native/core/include/ngn/crash-report.h +31 -0
  44. package/native/core/include/ngn/curl-network.h +93 -0
  45. package/native/core/include/ngn/dbus-menu.h +39 -0
  46. package/native/core/include/ngn/default-menu.h +36 -0
  47. package/native/core/include/ngn/desktop-expo.h +7 -1
  48. package/native/core/include/ngn/desktop-modules.h +22 -0
  49. package/native/core/include/ngn/desktop-props.h +21 -1
  50. package/native/core/include/ngn/desktop-view-props.h +6 -0
  51. package/native/core/include/ngn/focus-order.h +10 -0
  52. package/native/core/include/ngn/header-bar.h +22 -0
  53. package/native/core/include/ngn/host-os.h +6 -0
  54. package/native/core/include/ngn/host-reload.h +21 -0
  55. package/native/core/include/ngn/host-state.h +23 -0
  56. package/native/core/include/ngn/image-source.h +26 -1
  57. package/native/core/include/ngn/input-script.h +3 -3
  58. package/native/core/include/ngn/input.h +4 -1
  59. package/native/core/include/ngn/launch-frame.h +21 -0
  60. package/native/core/include/ngn/launch-settings.h +23 -5
  61. package/native/core/include/ngn/mounting-backend.h +5 -0
  62. package/native/core/include/ngn/mounting-manager.h +1 -0
  63. package/native/core/include/ngn/native-controls.h +26 -5
  64. package/native/core/include/ngn/notification-schedule.h +74 -0
  65. package/native/core/include/ngn/notifications.h +2 -1
  66. package/native/core/include/ngn/openssl-update-crypto.h +15 -0
  67. package/native/core/include/ngn/photo-library.h +60 -20
  68. package/native/core/include/ngn/posix-locale.h +43 -0
  69. package/native/core/include/ngn/runtime.h +5 -0
  70. package/native/core/include/ngn/safe-areas.h +14 -2
  71. package/native/core/include/ngn/split-view.h +78 -0
  72. package/native/core/include/ngn/surface-metrics.h +7 -0
  73. package/native/core/include/ngn/system.h +14 -0
  74. package/native/core/include/ngn/text-input.h +13 -0
  75. package/native/core/include/ngn/text-units.h +38 -0
  76. package/native/core/include/ngn/updates.h +14 -2
  77. package/native/core/include/ngn/view-box.h +40 -0
  78. package/native/core/include/ngn/view-transform.h +15 -0
  79. package/native/core/include/ngn/web-browser.h +46 -0
  80. package/native/core/src/accent-colors.cpp +88 -0
  81. package/native/core/src/accessibility-relations.cpp +138 -0
  82. package/native/core/src/accessibility.cpp +50 -0
  83. package/native/core/src/animated-frame-loop.cpp +166 -0
  84. package/native/core/src/app-menus.cpp +26 -9
  85. package/native/core/src/app-windows.cpp +27 -6
  86. package/native/core/src/aria-role.cpp +127 -0
  87. package/native/core/src/control-sizes.cpp +9 -5
  88. package/native/core/src/crash-report.cpp +196 -0
  89. package/native/core/src/curl-network.cpp +1562 -0
  90. package/native/core/src/dbus-menu.cpp +71 -0
  91. package/native/core/src/default-menu.cpp +134 -0
  92. package/native/core/src/desktop-view-props.cpp +14 -0
  93. package/native/core/src/focus-order.cpp +19 -0
  94. package/native/core/src/header-bar.cpp +20 -0
  95. package/native/core/src/host-os.cpp +19 -0
  96. package/native/core/src/host-reload.cpp +45 -0
  97. package/native/core/src/host-state.cpp +8 -0
  98. package/native/core/src/image-source.cpp +90 -0
  99. package/native/core/src/input-dispatcher.cpp +27 -5
  100. package/native/core/src/input-script.cpp +3 -2
  101. package/native/core/src/launch-settings.cpp +76 -0
  102. package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
  103. package/native/core/src/modules/app-info.cpp +55 -6
  104. package/native/core/src/modules/app-modules.cpp +1 -1
  105. package/native/core/src/modules/audio.cpp +4 -2
  106. package/native/core/src/modules/camera.cpp +8 -11
  107. package/native/core/src/modules/desktop-expo.cpp +10 -5
  108. package/native/core/src/modules/desktop-modules.cpp +106 -41
  109. package/native/core/src/modules/file-photo-picker.cpp +408 -0
  110. package/native/core/src/modules/notifications.cpp +13 -17
  111. package/native/core/src/modules/photo-library.cpp +42 -13
  112. package/native/core/src/modules/web-browser.cpp +89 -0
  113. package/native/core/src/mounting-manager.cpp +12 -0
  114. package/native/core/src/native-controls.cpp +42 -1
  115. package/native/core/src/notification-schedule.cpp +429 -0
  116. package/native/core/src/openssl-update-crypto.cpp +83 -0
  117. package/native/core/src/posix-locale.cpp +192 -0
  118. package/native/core/src/runtime.cpp +30 -1
  119. package/native/core/src/safe-areas.cpp +19 -4
  120. package/native/core/src/spawn-rules.cpp +4 -1
  121. package/native/core/src/split-view.cpp +93 -0
  122. package/native/core/src/system.cpp +19 -0
  123. package/native/core/src/text-input.cpp +18 -1
  124. package/native/core/src/text-units.cpp +99 -0
  125. package/native/core/src/updates.cpp +76 -17
  126. package/native/core/src/view-box.cpp +75 -40
  127. package/native/core/src/view-transform.cpp +28 -0
  128. package/native/docker/Dockerfile +38 -0
  129. package/native/docker/Dockerfile.fedora +36 -0
  130. package/native/docker/glibc-floor.sh +49 -0
  131. package/native/gtk/CMakeLists.txt +137 -0
  132. package/native/gtk/accent-colour.cpp +57 -0
  133. package/native/gtk/accent-colour.h +41 -0
  134. package/native/gtk/accessibility-settings.cpp +159 -0
  135. package/native/gtk/accessibility-settings.h +62 -0
  136. package/native/gtk/accessible-text.cpp +151 -0
  137. package/native/gtk/accessible-text.h +49 -0
  138. package/native/gtk/accessible.cpp +306 -0
  139. package/native/gtk/accessible.h +75 -0
  140. package/native/gtk/alerts.cpp +267 -0
  141. package/native/gtk/alerts.h +30 -0
  142. package/native/gtk/animation-frames.cpp +159 -0
  143. package/native/gtk/animation-frames.h +20 -0
  144. package/native/gtk/app-info.cpp +91 -0
  145. package/native/gtk/app-info.h +25 -0
  146. package/native/gtk/app-windows.cpp +439 -0
  147. package/native/gtk/app-windows.h +150 -0
  148. package/native/gtk/audio.cpp +370 -0
  149. package/native/gtk/audio.h +54 -0
  150. package/native/gtk/auth-session.cpp +73 -0
  151. package/native/gtk/auth-session.h +16 -0
  152. package/native/gtk/battery.cpp +110 -0
  153. package/native/gtk/battery.h +19 -0
  154. package/native/gtk/box-paint.cpp +262 -0
  155. package/native/gtk/box-paint.h +32 -0
  156. package/native/gtk/cairo-canvas.cpp +755 -0
  157. package/native/gtk/cairo-canvas.h +49 -0
  158. package/native/gtk/camera.cpp +909 -0
  159. package/native/gtk/camera.h +69 -0
  160. package/native/gtk/capture.cpp +46 -0
  161. package/native/gtk/capture.h +19 -0
  162. package/native/gtk/clock-format.cpp +151 -0
  163. package/native/gtk/clock-format.h +36 -0
  164. package/native/gtk/crypto.cpp +75 -0
  165. package/native/gtk/crypto.h +14 -0
  166. package/native/gtk/dbus-properties.cpp +131 -0
  167. package/native/gtk/dbus-properties.h +61 -0
  168. package/native/gtk/drag-and-drop.cpp +339 -0
  169. package/native/gtk/drag-and-drop.h +30 -0
  170. package/native/gtk/file-dialogs.cpp +239 -0
  171. package/native/gtk/file-dialogs.h +21 -0
  172. package/native/gtk/file-system.cpp +212 -0
  173. package/native/gtk/file-system.h +25 -0
  174. package/native/gtk/focus.cpp +282 -0
  175. package/native/gtk/focus.h +37 -0
  176. package/native/gtk/fonts.cpp +89 -0
  177. package/native/gtk/fonts.h +22 -0
  178. package/native/gtk/gst-frames.cpp +150 -0
  179. package/native/gtk/gst-frames.h +47 -0
  180. package/native/gtk/gst-playback.cpp +496 -0
  181. package/native/gtk/gst-playback.h +81 -0
  182. package/native/gtk/gtk-backend.cpp +690 -0
  183. package/native/gtk/gtk-backend.h +134 -0
  184. package/native/gtk/host-sources.cpp +354 -0
  185. package/native/gtk/host-sources.h +46 -0
  186. package/native/gtk/image-manipulator.cpp +254 -0
  187. package/native/gtk/image-manipulator.h +30 -0
  188. package/native/gtk/image-view.cpp +256 -0
  189. package/native/gtk/image-view.h +54 -0
  190. package/native/gtk/input-replay.cpp +299 -0
  191. package/native/gtk/input-replay.h +36 -0
  192. package/native/gtk/launcher-badge.cpp +29 -0
  193. package/native/gtk/launcher-badge.h +21 -0
  194. package/native/gtk/locales.cpp +131 -0
  195. package/native/gtk/locales.h +23 -0
  196. package/native/gtk/location.cpp +274 -0
  197. package/native/gtk/location.h +19 -0
  198. package/native/gtk/main.cpp +1092 -0
  199. package/native/gtk/menus.cpp +447 -0
  200. package/native/gtk/menus.h +100 -0
  201. package/native/gtk/native-controls.cpp +831 -0
  202. package/native/gtk/native-controls.h +58 -0
  203. package/native/gtk/network-state.cpp +72 -0
  204. package/native/gtk/network-state.h +24 -0
  205. package/native/gtk/notifications.cpp +235 -0
  206. package/native/gtk/notifications.h +30 -0
  207. package/native/gtk/pango-text.cpp +274 -0
  208. package/native/gtk/pango-text.h +73 -0
  209. package/native/gtk/portal.cpp +451 -0
  210. package/native/gtk/portal.h +71 -0
  211. package/native/gtk/printing.cpp +338 -0
  212. package/native/gtk/printing.h +34 -0
  213. package/native/gtk/proxy-resolver.cpp +74 -0
  214. package/native/gtk/proxy-resolver.h +20 -0
  215. package/native/gtk/screens.cpp +1461 -0
  216. package/native/gtk/screens.h +274 -0
  217. package/native/gtk/scroll-view.cpp +414 -0
  218. package/native/gtk/scroll-view.h +82 -0
  219. package/native/gtk/secret-store.cpp +120 -0
  220. package/native/gtk/secret-store.h +27 -0
  221. package/native/gtk/settings-portal.cpp +129 -0
  222. package/native/gtk/settings-portal.h +47 -0
  223. package/native/gtk/split-view.cpp +1105 -0
  224. package/native/gtk/split-view.h +195 -0
  225. package/native/gtk/status-notifier.cpp +487 -0
  226. package/native/gtk/status-notifier.h +43 -0
  227. package/native/gtk/surface-input.cpp +251 -0
  228. package/native/gtk/surface-input.h +57 -0
  229. package/native/gtk/system-access.cpp +295 -0
  230. package/native/gtk/system-access.h +37 -0
  231. package/native/gtk/text-field.cpp +827 -0
  232. package/native/gtk/text-field.h +78 -0
  233. package/native/gtk/video.cpp +527 -0
  234. package/native/gtk/video.h +47 -0
  235. package/native/gtk/view-widget.cpp +431 -0
  236. package/native/gtk/view-widget.h +105 -0
  237. package/native/gtk/window-scale.cpp +95 -0
  238. package/native/gtk/window-scale.h +35 -0
  239. package/native/scripts/atspi-check.py +310 -0
  240. package/native/scripts/atspi-check.test.py +48 -0
  241. package/native/scripts/build.sh +20 -3
  242. package/native/scripts/compilers.sh +17 -0
  243. package/native/scripts/deb-depends-check.sh +22 -0
  244. package/native/scripts/fetch.sh +23 -2
  245. package/native/scripts/launch-cell.sh +157 -0
  246. package/native/scripts/launch-probe.sh +14 -3
  247. package/native/scripts/make-prebuilt.mjs +133 -44
  248. package/native/scripts/prebuilt-host-cache.mjs +71 -40
  249. package/native/scripts/reset-for-compilers.sh +44 -0
  250. package/native/scripts/start-xvfb.sh +35 -0
  251. package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
  252. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
  253. package/native/shim/worklets/linux-reanimated-props.h +14 -0
  254. package/native/shim/worklets/linux-worklets.h +23 -0
  255. package/package.json +6 -3
  256. package/prebuilt.json +70 -6
@@ -3,6 +3,8 @@
3
3
  # core/ toolkit-free C++: mounting, the view tree and hit testing, input and hover, text
4
4
  # measurement, the module registry and desktop view props. No AppKit, no Objective-C.
5
5
  # appkit/ the macOS backend and the ngn-macos binary.
6
+ # gtk/ the Linux backend over GTK 4 and the ngn-linux binary; it also builds on a Mac against
7
+ # Homebrew's GTK, as a dev loop.
6
8
  #
7
9
  # scripts/build.sh is the way in: it fetches the pinned sources into the per-user cache and passes
8
10
  # their paths here. NGN_BACKEND=none builds only the core and its tests (any OS, no Hermes), which
@@ -16,8 +18,8 @@ if(APPLE)
16
18
  else()
17
19
  set(_default_backend none)
18
20
  endif()
19
- set(NGN_BACKEND ${_default_backend} CACHE STRING "appkit or none")
20
- set_property(CACHE NGN_BACKEND PROPERTY STRINGS appkit none)
21
+ set(NGN_BACKEND ${_default_backend} CACHE STRING "appkit, gtk or none")
22
+ set_property(CACHE NGN_BACKEND PROPERTY STRINGS appkit gtk none)
21
23
  option(NGN_TESTS "Build the core tests" ON)
22
24
  option(NGN_RUNTIME "With NGN_BACKEND=none, build the runtime half over Hermes too" OFF)
23
25
 
@@ -51,12 +53,12 @@ if(APPLE)
51
53
  # The AppKit backend, and on macOS the core tests of its window-free parts.
52
54
  enable_language(OBJC OBJCXX)
53
55
  endif()
54
- if(NGN_BACKEND STREQUAL "appkit")
56
+ if(NGN_BACKEND STREQUAL "appkit" OR NGN_BACKEND STREQUAL "gtk")
55
57
  set(NGN_WITH_RUNTIME ON)
56
58
  elseif(NGN_BACKEND STREQUAL "none")
57
59
  set(NGN_WITH_RUNTIME ${NGN_RUNTIME})
58
60
  else()
59
- message(FATAL_ERROR "NGN_BACKEND must be appkit or none, not ${NGN_BACKEND}")
61
+ message(FATAL_ERROR "NGN_BACKEND must be appkit, gtk or none, not ${NGN_BACKEND}")
60
62
  endif()
61
63
 
62
64
  # A dev build carries React Native's debugger: Hermes's CDP agents and the inspector targets that
@@ -78,15 +80,20 @@ endif()
78
80
  # --- core -----------------------------------------------------------------------------------------
79
81
  add_library(ngn_core STATIC
80
82
  core/src/absent-views.cpp
83
+ core/src/accent-colors.cpp
81
84
  core/src/accessibility.cpp
85
+ core/src/aria-role.cpp
86
+ core/src/animated-frame-loop.cpp
82
87
  core/src/animation-frames.cpp
83
88
  core/src/app-menus.cpp
84
89
  core/src/app-windows.cpp
85
90
  core/src/back-swipe.cpp
86
91
  core/src/bytes.cpp
87
92
  core/src/control-sizes.cpp
93
+ core/src/crash-report.cpp
88
94
  core/src/desktop-modal.cpp
89
95
  core/src/desktop-view-props.cpp
96
+ core/src/dbus-menu.cpp
90
97
  core/src/default-menu.cpp
91
98
  core/src/dev-server.cpp
92
99
  core/src/dom-web-view.cpp
@@ -95,14 +102,18 @@ add_library(ngn_core STATIC
95
102
  core/src/glass.cpp
96
103
  core/src/header-bar.cpp
97
104
  core/src/host-os.cpp
105
+ core/src/host-reload.cpp
98
106
  core/src/host-state.cpp
99
107
  core/src/host-views.cpp
100
108
  core/src/image-source.cpp
101
109
  core/src/input-dispatcher.cpp
102
110
  core/src/input-script.cpp
103
111
  core/src/key-value-store.cpp
112
+ core/src/notification-schedule.cpp
104
113
  core/src/launch-settings.cpp
105
114
  core/src/live-regions.cpp
115
+ core/src/text-units.cpp
116
+ core/src/accessibility-relations.cpp
106
117
  core/src/library-glue.cpp
107
118
  core/src/module-registry.cpp
108
119
  core/src/mounting-manager.cpp
@@ -116,6 +127,7 @@ add_library(ngn_core STATIC
116
127
  core/src/safe-areas.cpp
117
128
  core/src/scrollers.cpp
118
129
  core/src/posix-launcher.cpp
130
+ core/src/posix-locale.cpp
119
131
  core/src/processes.cpp
120
132
  core/src/screen-presentation.cpp
121
133
  core/src/screen-stacks.cpp
@@ -152,6 +164,7 @@ add_library(ngn_core STATIC
152
164
  core/src/modules/crypto.cpp
153
165
  core/src/modules/desktop-expo.cpp
154
166
  core/src/modules/desktop-modules.cpp
167
+ core/src/modules/file-photo-picker.cpp
155
168
  core/src/modules/file-system.cpp
156
169
  core/src/modules/fonts.cpp
157
170
  core/src/modules/image-loader.cpp
@@ -205,8 +218,9 @@ if(NGN_TESTS)
205
218
  set_source_files_properties(${core_test_SRC} PROPERTIES COMPILE_OPTIONS -Wno-c2y-extensions)
206
219
  endif()
207
220
  endif()
208
- # The AppKit backend's own logic that needs no window: on macOS only, over the system's frameworks.
209
- if(APPLE)
221
+ # The AppKit backend's own logic that needs no window: on macOS only, over the system's frameworks,
222
+ # and not in a GTK build on a Mac, which tests the GTK backend instead.
223
+ if(APPLE AND NOT NGN_BACKEND STREQUAL "gtk")
210
224
  ngn_link_swift(ngn_core_tests)
211
225
  target_sources(ngn_core_tests PRIVATE
212
226
  appkit/updates.mm appkit/tests/update-crypto.test.mm
@@ -266,6 +280,48 @@ if(NGN_TESTS)
266
280
  add_test(NAME core COMMAND ngn_core_tests)
267
281
  endif()
268
282
 
283
+ # --- the HTTP and WebSocket client over libcurl, for a backend whose OS has none (gtk) -------------
284
+ # AUTO follows the backend on every configure, so a build directory reused for another backend
285
+ # gets that backend's choice; ON or OFF is the developer's own.
286
+ set(NGN_CURL AUTO CACHE STRING "Build the libcurl client (core/src/curl-network.cpp) and its tests: AUTO (on for gtk), ON or OFF")
287
+ set_property(CACHE NGN_CURL PROPERTY STRINGS AUTO ON OFF)
288
+ if(NGN_CURL STREQUAL "AUTO")
289
+ if(NGN_BACKEND STREQUAL "gtk")
290
+ set(_ngn_curl ON)
291
+ else()
292
+ set(_ngn_curl OFF)
293
+ endif()
294
+ else()
295
+ set(_ngn_curl ${NGN_CURL})
296
+ endif()
297
+ if(NGN_BACKEND STREQUAL "gtk" AND NOT _ngn_curl)
298
+ message(FATAL_ERROR "The GTK backend's networking is the libcurl client: NGN_CURL must be AUTO or ON")
299
+ endif()
300
+ if(_ngn_curl)
301
+ include(cmake/curl.cmake)
302
+ add_library(ngn_curl STATIC core/src/curl-network.cpp)
303
+ target_link_libraries(ngn_curl PUBLIC ngn_core PRIVATE ngn_libcurl)
304
+ target_compile_options(ngn_curl PRIVATE -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers)
305
+ # The Expo Updates client's hash and signature check over the same system OpenSSL 3, for the
306
+ # backend with no OS crypto of its own.
307
+ add_library(ngn_openssl STATIC core/src/openssl-update-crypto.cpp)
308
+ target_include_directories(ngn_openssl PRIVATE ${NGN_OPENSSL_INCLUDE_DIRS})
309
+ target_link_libraries(ngn_openssl PUBLIC ngn_core ${NGN_OPENSSL_LINK_LIBRARIES})
310
+ target_compile_options(ngn_openssl PRIVATE -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers)
311
+ if(NGN_TESTS)
312
+ target_sources(ngn_core_tests PRIVATE core/tests/openssl/update-crypto.test.cpp)
313
+ target_link_libraries(ngn_core_tests PRIVATE ngn_openssl)
314
+ set_source_files_properties(core/tests/openssl/update-crypto.test.cpp PROPERTIES COMPILE_OPTIONS "${NGN_DOCTEST_SOURCE_OPTIONS}")
315
+ # Against a local server, test-server.py, which needs python3.
316
+ set(_curl_tests core/tests/curl/network.test.cpp)
317
+ target_sources(ngn_core_tests PRIVATE ${_curl_tests})
318
+ target_link_libraries(ngn_core_tests PRIVATE ngn_curl)
319
+ set_source_files_properties(${_curl_tests} PROPERTIES
320
+ COMPILE_DEFINITIONS NGN_CURL_TEST_SERVER="${CMAKE_CURRENT_SOURCE_DIR}/core/tests/curl/test-server.py"
321
+ COMPILE_OPTIONS "${NGN_DOCTEST_SOURCE_OPTIONS}")
322
+ endif()
323
+ endif()
324
+
269
325
  # --- the core's runtime half: ReactHost over Hermes ----------------------------------------------
270
326
  if(NGN_WITH_RUNTIME)
271
327
  add_library(ngn_core_runtime STATIC
@@ -321,4 +377,6 @@ endif()
321
377
  # --- backends -------------------------------------------------------------------------------------
322
378
  if(NGN_BACKEND STREQUAL "appkit")
323
379
  add_subdirectory(appkit)
380
+ elseif(NGN_BACKEND STREQUAL "gtk")
381
+ add_subdirectory(gtk)
324
382
  endif()
@@ -133,7 +133,8 @@ if(NGN_TESTS)
133
133
  add_executable(ngn_appkit_tests ../core/tests/main.cpp tests/views/accessibility.test.mm tests/views/svg-foreign-object.test.mm
134
134
  tests/views/tab-walk.test.mm tests/views/camera-view.test.mm tests/views/text-input-alignment.test.mm
135
135
  tests/views/image-view.test.mm tests/views/modal-beside-split.test.mm
136
- tests/views/split-under-pushed-screen.test.mm tests/views/view-effects.test.mm)
136
+ tests/views/split-under-pushed-screen.test.mm tests/views/view-effects.test.mm
137
+ tests/views/native-button.test.mm)
137
138
  target_include_directories(ngn_appkit_tests PRIVATE ../core/tests)
138
139
  target_link_libraries(ngn_appkit_tests PRIVATE ngn_appkit doctest ${NGN_APPKIT_FRAMEWORKS})
139
140
  if(NGN_HERMES_TEST_RPATH)
@@ -53,6 +53,7 @@ class AppKitBackend final : public MountingBackend, public DesktopPropsSink {
53
53
  void setSvgDrawing(SurfaceId surfaceId, Tag svg, std::shared_ptr<const SvgDocument> document) override;
54
54
  void setExpoUITree(SurfaceId surfaceId, Tag host, std::shared_ptr<const ExpoUINode> root) override;
55
55
  void announce(SurfaceId surfaceId, const Announcement &announcement) override;
56
+ void setAccessibilityRelations(SurfaceId surfaceId, Tag tag, const AxRelations &relations) override;
56
57
  void didMount(SurfaceId surfaceId) override;
57
58
  void updateDesktopProps(SurfaceId surfaceId, Tag tag, const DesktopProps &props) override;
58
59
  std::vector<facebook::react::ComponentDescriptorProvider> componentProviders() const override;
@@ -273,6 +273,19 @@ void AppKitBackend::announce(SurfaceId, const Announcement &announcement) {
273
273
  postAnnouncement(announcement);
274
274
  }
275
275
 
276
+ void AppKitBackend::setAccessibilityRelations(SurfaceId, Tag tag, const AxRelations &relations) {
277
+ auto views = [this](const std::vector<Tag> &tags) {
278
+ NSMutableArray<NGNView *> *found = [NSMutableArray array];
279
+ for (Tag target : tags) {
280
+ if (NGNView *v = views_[@(target)]) {
281
+ [found addObject:v];
282
+ }
283
+ }
284
+ return found;
285
+ };
286
+ [views_[@(tag)] setLabelledBy:views(relations.labelledBy) describedBy:views(relations.describedBy)];
287
+ }
288
+
276
289
  void AppKitBackend::didMount(SurfaceId surfaceId) {
277
290
  [NGNPresentedScreenView refreshChrome];
278
291
  [NGNModalHostView fitPopovers];
@@ -263,24 +263,27 @@ NSImage *symbol(const std::string &name, NSString *description) {
263
263
  // A hosted item's own content changed: its size follows its layout.
264
264
  }
265
265
 
266
- - (NSArray<NGNHeaderSubviewView *> *)itemsOfType:(const std::string &)type {
267
- NSMutableArray *items = [NSMutableArray array];
266
+ // The config's header subviews, with where each sits, and each by its tag in `views`.
267
+ - (std::vector<ngn::HeaderSubview>)headerSubviews:(NSMutableDictionary<NSNumber *, NGNHeaderSubviewView *> *)views {
268
+ std::vector<ngn::HeaderSubview> subviews;
269
+ auto add = [&](NGNHeaderSubviewView *v) {
270
+ if (auto type = v.props ? ngn::headerItemType(*v.props) : std::nullopt) {
271
+ subviews.push_back({static_cast<facebook::react::Tag>(v.reactTag), *type});
272
+ views[@(v.reactTag)] = v;
273
+ }
274
+ };
268
275
  for (NSView *v in _config.subviews) {
269
- if ([v isKindOfClass:NGNHeaderSubviewView.class] && ((NGNView *)v).props &&
270
- ngn::headerItemType(*((NGNView *)v).props) == type) {
271
- [items addObject:v];
276
+ if ([v isKindOfClass:NGNHeaderSubviewView.class]) {
277
+ add((NGNHeaderSubviewView *)v);
272
278
  }
273
279
  }
274
280
  // Those already in the toolbar are no longer the config's subviews.
275
281
  for (NGNHeaderSubviewView *v in _hosted.allValues) {
276
- if ([_homes objectForKey:v] == _config && v.props && ngn::headerItemType(*v.props) == type) {
277
- [items addObject:v];
282
+ if ([_homes objectForKey:v] == _config) {
283
+ add(v);
278
284
  }
279
285
  }
280
- [items sortUsingComparator:^NSComparisonResult(NGNView *a, NGNView *b) {
281
- return a.reactTag < b.reactTag ? NSOrderedAscending : a.reactTag > b.reactTag ? NSOrderedDescending : NSOrderedSame;
282
- }];
283
- return items;
286
+ return subviews;
284
287
  }
285
288
 
286
289
  - (void)returnHostedViews {
@@ -340,35 +343,35 @@ NSImage *symbol(const std::string &name, NSString *description) {
340
343
  }
341
344
  }
342
345
  if (bar) {
343
- NSArray *left = [self itemsOfType:"left"];
344
- NSArray *center = [self itemsOfType:"center"];
345
- NSArray *right = [self itemsOfType:"right"];
346
- BOOL replacesBack = left.count > 0 || !_bar.left.empty();
347
- _buttons = ngn::historyButtons(_history, _canGoBack, _bar.hideBackButton || replacesBack);
346
+ // The core's order, which the GTK host's header bar follows too. Whether the chevrons show is
347
+ // the history's to say as well, so the layout is asked as though the screen could go back.
348
+ NSMutableDictionary<NSNumber *, NGNHeaderSubviewView *> *views = [NSMutableDictionary dictionary];
349
+ auto layout = ngn::headerLayout(_bar, [self headerSubviews:views], true);
350
+ _buttons = ngn::historyButtons(_history, _canGoBack, !layout.back);
348
351
  if (_buttons.shown) {
349
352
  [ids addObject:kHistory];
350
353
  }
351
- for (NGNHeaderSubviewView *v in left) {
352
- [ids addObject:[self host:v]];
354
+ for (auto tag : layout.left) {
355
+ [ids addObject:[self host:views[@(tag)]]];
353
356
  }
354
357
  for (size_t i = 0; i < _bar.left.size(); i++) {
355
358
  [ids addObject:[NSString stringWithFormat:@"ngn.button.left.%zu", i]];
356
359
  }
357
360
  [ids addObject:NSToolbarFlexibleSpaceItemIdentifier];
358
- for (NGNHeaderSubviewView *v in center) {
359
- [ids addObject:[self host:v]];
361
+ for (auto tag : layout.center) {
362
+ [ids addObject:[self host:views[@(tag)]]];
360
363
  }
361
- if (center.count > 0) {
364
+ if (!layout.center.empty()) {
362
365
  [ids addObject:NSToolbarFlexibleSpaceItemIdentifier];
363
366
  }
364
367
  for (size_t i = 0; i < _bar.right.size(); i++) {
365
368
  [ids addObject:[NSString stringWithFormat:@"ngn.button.right.%zu", i]];
366
369
  }
367
- for (NGNHeaderSubviewView *v in right) {
368
- [ids addObject:[self host:v]];
370
+ for (auto tag : layout.right) {
371
+ [ids addObject:[self host:views[@(tag)]]];
369
372
  }
370
- for (NGNHeaderSubviewView *v in [self itemsOfType:"searchBar"]) {
371
- for (NSView *child in v.subviews) {
373
+ for (auto tag : layout.searchBars) {
374
+ for (NSView *child in views[@(tag)].subviews) {
372
375
  if ([child isKindOfClass:NGNSearchBarView.class]) {
373
376
  NGNSearchToolbarItem *item = ((NGNSearchBarView *)child).item;
374
377
  _searchItems[item.itemIdentifier] = item;
@@ -39,6 +39,16 @@
39
39
  - (const facebook::react::LayoutMetrics &)layoutMetrics;
40
40
  // What VoiceOver is told about the view (accessibility.h).
41
41
  - (ngn::AxInfo)axInfo;
42
+ // The views it is labelled and described by (accessibility-relations.h), held weakly. Their text is
43
+ // its label, ahead of its own, and its help, ahead of its hint, read each time VoiceOver asks.
44
+ - (void)setLabelledBy:(NSArray<NGNView *> *)labelledBy describedBy:(NSArray<NGNView *> *)describedBy;
45
+ // The AppKit control or field inside the view that is the accessibility element where the view is
46
+ // not (isAccessibilityElement is NO): the relations' text is its label and help, which a view that
47
+ // holds one sets there, and clears with the relations. Nil for a view that is its own element.
48
+ - (NSView *)accessibilityControl;
49
+ // Sets the relations' text on the accessibilityControl again: after the control's own props were
50
+ // applied over it, or the text of a view named changed.
51
+ - (void)refreshControlRelations;
42
52
  // Where Fabric children mount: the view itself, or a scroll view's document view.
43
53
  - (NSView *)contentContainer;
44
54
  // What takes the keyboard when Tab moves the focus here: the view itself, or the AppKit control
@@ -1,5 +1,6 @@
1
1
  #import "host-view.h"
2
2
 
3
+ #include "ngn/focus-order.h"
3
4
  #include "ngn/view-transform.h"
4
5
 
5
6
  #import <QuartzCore/QuartzCore.h>
@@ -203,6 +204,12 @@ static ngn::InputDispatcher *gViewInput;
203
204
  @end
204
205
 
205
206
  @implementation NGNView {
207
+ NSPointerArray *_labelledBy;
208
+ NSPointerArray *_describedBy;
209
+ // The views that name this one, which hear when its text changes.
210
+ NSHashTable<NGNView *> *_namedBy;
211
+ // Whether the relations' text is on the accessibilityControl, to be cleared once they go.
212
+ BOOL _controlRelated;
206
213
  Props::Shared _props;
207
214
  LayoutMetrics _layout;
208
215
  State::Shared _state;
@@ -283,7 +290,7 @@ static ngn::InputDispatcher *gViewInput;
283
290
  // Any tabIndex takes the focus, -1 too, as on the web: out of Tab order, but where a click or the
284
291
  // arrow keys in a composite widget move it (focus-order.h).
285
292
  - (BOOL)acceptsFirstResponder {
286
- return _desktop.focusable.value_or(false) || _desktop.tabIndex.has_value();
293
+ return ngn::viewTakesFocus(_desktop);
287
294
  }
288
295
 
289
296
 
@@ -396,7 +403,84 @@ static BOOL focusFromKeyboard() {
396
403
  return NSAccessibilityRoleDescription(nsRole(info.role), nsSubrole(info.subrole));
397
404
  }
398
405
 
406
+ - (void)setLabelledBy:(NSArray<NGNView *> *)labelledBy describedBy:(NSArray<NGNView *> *)describedBy {
407
+ auto weakly = [](NSArray<NGNView *> *views) {
408
+ NSPointerArray *array = [NSPointerArray weakObjectsPointerArray];
409
+ for (NGNView *view in views) {
410
+ [array addPointer:(__bridge void *)view];
411
+ }
412
+ return views.count > 0 ? array : nil;
413
+ };
414
+ for (NGNView *old in [_labelledBy.allObjects arrayByAddingObjectsFromArray:_describedBy.allObjects]) {
415
+ [old->_namedBy removeObject:self];
416
+ }
417
+ _labelledBy = weakly(labelledBy);
418
+ _describedBy = weakly(describedBy);
419
+ for (NGNView *named in [labelledBy arrayByAddingObjectsFromArray:describedBy]) {
420
+ if (!named->_namedBy) {
421
+ named->_namedBy = [NSHashTable weakObjectsHashTable];
422
+ }
423
+ [named->_namedBy addObject:self];
424
+ }
425
+ [self refreshControlRelations];
426
+ }
427
+
428
+ - (NSView *)accessibilityControl {
429
+ return nil;
430
+ }
431
+
432
+ - (void)refreshControlRelations {
433
+ NSView *control = [self accessibilityControl];
434
+ if (!control) {
435
+ return;
436
+ }
437
+ BOOL related = _labelledBy != nil || _describedBy != nil;
438
+ if (!related && !_controlRelated) {
439
+ return;
440
+ }
441
+ // The element AppKit reads is the control: the view named is its title element, and the text
442
+ // of the views named its label and help. With the relations gone, the control reads its own.
443
+ control.accessibilityTitleUIElement = _labelledBy.allObjects.firstObject;
444
+ control.accessibilityLabel = [self textOfRelation:_labelledBy];
445
+ control.accessibilityHelp = [self textOfRelation:_describedBy];
446
+ _controlRelated = related;
447
+ }
448
+
449
+ // This view's text changed, or the text of a view inside it: the views that name it, or one above
450
+ // it, read it again.
451
+ - (void)relatedTextChanged {
452
+ for (NSView *view = self; view; view = view.superview) {
453
+ if ([view isKindOfClass:NGNView.class]) {
454
+ for (NGNView *namer in ((NGNView *)view)->_namedBy.allObjects) {
455
+ [namer refreshControlRelations];
456
+ }
457
+ }
458
+ }
459
+ }
460
+
461
+ // The text of the views a relation names, in order: each one's label, or the text inside it, as
462
+ // aria-labelledby reads them.
463
+ - (NSString *)textOfRelation:(NSPointerArray *)views {
464
+ NSMutableArray<NSString *> *texts = [NSMutableArray array];
465
+ for (NGNView *view in views.allObjects) {
466
+ NSString *label = view.accessibilityLabel;
467
+ if (label.length > 0) {
468
+ [texts addObject:label];
469
+ } else {
470
+ [view collectTextInto:texts];
471
+ }
472
+ }
473
+ return texts.count > 0 ? [texts componentsJoinedByString:@" "] : nil;
474
+ }
475
+
476
+ - (id)accessibilityTitleUIElement {
477
+ return _labelledBy.allObjects.firstObject;
478
+ }
479
+
399
480
  - (NSString *)accessibilityLabel {
481
+ if (NSString *named = [self textOfRelation:_labelledBy]) {
482
+ return named;
483
+ }
400
484
  auto info = [self axInfo];
401
485
  if (info.label.empty() && info.hidesChildren && ![_componentName isEqualToString:@"Paragraph"]) {
402
486
  // Read as one element with no label of its own: named by the text inside it, as iOS does.
@@ -436,6 +520,9 @@ static BOOL focusFromKeyboard() {
436
520
  }
437
521
 
438
522
  - (NSString *)accessibilityHelp {
523
+ if (NSString *described = [self textOfRelation:_describedBy]) {
524
+ return described;
525
+ }
439
526
  auto info = [self axInfo];
440
527
  return info.hint.empty() ? nil : nsString(info.hint);
441
528
  }
@@ -448,27 +535,58 @@ static BOOL focusFromKeyboard() {
448
535
  return info.value.empty() ? nil : nsString(info.value);
449
536
  }
450
537
 
451
- // The heading level, which AppKit names from macOS 26 and has no property for.
538
+ // The attributes AppKit has no property for, under the names WebKit gives them for the same ARIA:
539
+ // the heading level (AppKit's from macOS 26), whether the value is refused, an item's place in its
540
+ // set, and a table's row and column counts. Each only while the props say it.
452
541
  #pragma clang diagnostic push
453
542
  #pragma clang diagnostic ignored "-Wdeprecated-declarations"
454
- - (NSArray<NSAccessibilityAttributeName> *)accessibilityAttributeNames {
455
- NSArray *names = [super accessibilityAttributeNames];
543
+ - (NSDictionary<NSString *, id> *)extraAttributes {
456
544
  auto info = [self axInfo];
545
+ NSMutableDictionary<NSString *, id> *extra = [NSMutableDictionary dictionary];
457
546
  if (info.level && nativeRole(info.role) && info.role == ngn::AxRole::Heading) {
458
- return [names arrayByAddingObject:@"AXHeadingLevel"];
547
+ extra[@"AXHeadingLevel"] = @(*info.level);
548
+ }
549
+ if (info.invalid) {
550
+ extra[@"AXInvalid"] = @"true";
551
+ }
552
+ if (info.positionInSet) {
553
+ extra[@"AXARIAPosInSet"] = @(*info.positionInSet);
554
+ }
555
+ if (info.setSize) {
556
+ extra[@"AXARIASetSize"] = @(*info.setSize);
557
+ }
558
+ if (info.rowCount) {
559
+ extra[NSAccessibilityRowCountAttribute] = @(*info.rowCount);
560
+ }
561
+ if (info.columnCount) {
562
+ extra[NSAccessibilityColumnCountAttribute] = @(*info.columnCount);
563
+ }
564
+ return extra;
565
+ }
566
+
567
+ - (NSArray<NSAccessibilityAttributeName> *)accessibilityAttributeNames {
568
+ NSArray *names = [super accessibilityAttributeNames];
569
+ NSMutableArray *added = [NSMutableArray array];
570
+ for (NSString *name in [self extraAttributes]) {
571
+ if (![names containsObject:name]) {
572
+ [added addObject:name];
573
+ }
459
574
  }
460
- return names;
575
+ return added.count > 0 ? [names arrayByAddingObjectsFromArray:added] : names;
461
576
  }
462
577
 
463
578
  - (id)accessibilityAttributeValue:(NSAccessibilityAttributeName)attribute {
464
- if ([attribute isEqualToString:@"AXHeadingLevel"]) {
465
- auto level = [self axInfo].level;
466
- return level ? @(*level) : nil;
579
+ if (id value = [self extraAttributes][attribute]) {
580
+ return value;
467
581
  }
468
582
  return [super accessibilityAttributeValue:attribute];
469
583
  }
470
584
  #pragma clang diagnostic pop
471
585
 
586
+ - (BOOL)isAccessibilityRequired {
587
+ return [self axInfo].required;
588
+ }
589
+
472
590
  - (BOOL)isAccessibilityEnabled {
473
591
  return ![self axInfo].disabled;
474
592
  }
@@ -502,11 +620,7 @@ static BOOL focusFromKeyboard() {
502
620
  - (BOOL)sendAccessibilityAction:(const std::string &)name {
503
621
  auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
504
622
  auto emitter = std::dynamic_pointer_cast<const ViewEventEmitter>(_emitter);
505
- if (!viewProps || !viewProps->onAccessibilityAction || !emitter) {
506
- return NO;
507
- }
508
- emitter->onAccessibilityAction(name);
509
- return YES;
623
+ return viewProps && ngn::sendAxAction(*viewProps, emitter.get(), name);
510
624
  }
511
625
 
512
626
  // One of AppKit's standard actions, as the core decides it reaches the app (accessibility.h).
@@ -516,23 +630,11 @@ static BOOL focusFromKeyboard() {
516
630
  if (!viewProps || !emitter) {
517
631
  return NO;
518
632
  }
519
- auto dispatch = ngn::axDispatch(*viewProps, verb);
520
- switch (dispatch.kind) {
521
- case ngn::AxDispatch::Kind::None:
522
- return NO;
523
- case ngn::AxDispatch::Kind::Tap:
524
- emitter->onAccessibilityTap();
525
- return YES;
526
- case ngn::AxDispatch::Kind::Escape:
527
- emitter->onAccessibilityEscape();
528
- return YES;
529
- case ngn::AxDispatch::Kind::Action:
530
- emitter->onAccessibilityAction(dispatch.action);
531
- return YES;
532
- case ngn::AxDispatch::Kind::Click:
533
- return gViewInput != nullptr && gViewInput->activate(static_cast<SurfaceId>(_surfaceId), static_cast<Tag>(_reactTag));
534
- }
535
- return NO;
633
+ SurfaceId surface = static_cast<SurfaceId>(_surfaceId);
634
+ Tag tag = static_cast<Tag>(_reactTag);
635
+ return ngn::performAxVerb(*viewProps, emitter.get(), verb, [surface, tag] {
636
+ return gViewInput != nullptr && gViewInput->activate(surface, tag);
637
+ });
536
638
  }
537
639
 
538
640
  - (BOOL)accessibilityPerformPress {
@@ -590,6 +692,7 @@ static BOOL focusFromKeyboard() {
590
692
  if ([_componentName isEqualToString:@"Paragraph"]) {
591
693
  [self setNeedsDisplay:YES];
592
694
  }
695
+ [self relatedTextChanged];
593
696
  }
594
697
 
595
698
  - (void)updateLayout:(const LayoutMetrics &)metrics {
@@ -628,6 +731,7 @@ static BOOL focusFromKeyboard() {
628
731
  - (void)updateState:(const State::Shared &)state {
629
732
  _state = state;
630
733
  [self setNeedsDisplay:YES];
734
+ [self relatedTextChanged];
631
735
  }
632
736
 
633
737
  - (void)updateEventEmitter:(const EventEmitter::Shared &)emitter {
@@ -794,19 +898,14 @@ void alignInput(id field, const DesktopTextInputProps &p, LayoutDirection direct
794
898
  [field setTextAlignment:alignment writingDirection:writing];
795
899
  }
796
900
 
797
- // The `selection` prop, when it is new in this update: React Native iOS applies it only then.
901
+ // The `selection` prop, when it is new in this update (ngn::newSelection).
798
902
  std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextInputProps &p) {
799
- if (!p.selection) {
800
- return std::nullopt;
801
- }
802
903
  auto before = std::dynamic_pointer_cast<const DesktopTextInputProps>(old);
803
- if (before && before->selection && before->selection->start == p.selection->start &&
804
- before->selection->end == p.selection->end) {
904
+ auto range = ngn::newSelection(before.get(), p);
905
+ if (!range) {
805
906
  return std::nullopt;
806
907
  }
807
- int start = std::max(0, std::min(p.selection->start, p.selection->end));
808
- int end = std::max(p.selection->start, p.selection->end);
809
- return NSMakeRange(start, end - start);
908
+ return NSMakeRange(range->first, range->second - range->first);
810
909
  }
811
910
 
812
911
  } // namespace
@@ -865,6 +964,10 @@ std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextI
865
964
  alignInput(_box, *p, self.layoutMetrics.layoutDirection);
866
965
  field.editable = p->editable && !p->readOnly;
867
966
  [_box applyOptions:ngn::textInputOptions(*p)];
967
+ // Required and refused on the control VoiceOver reads as the field, the one in the box now.
968
+ auto info = [self axInfo];
969
+ field.accessibilityRequired = info.required;
970
+ _box.invalid = info.invalid;
868
971
  // The text prop wins only when it is not older than what the field has sent (React Native iOS's
869
972
  // rule), and never while an input method is composing.
870
973
  if (ngn::controlledTextIsCurrent(p->mostRecentEventCount, _eventCount, [self composing]) && !p->text.empty()) {
@@ -1052,6 +1155,9 @@ std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextI
1052
1155
  alignInput(_text, *p, self.layoutMetrics.layoutDirection);
1053
1156
  _text.editable = p->editable && !p->readOnly;
1054
1157
  [_text applyOptions:ngn::textInputOptions(*p)];
1158
+ auto info = [self axInfo];
1159
+ _text.accessibilityRequired = info.required;
1160
+ _text.invalid = info.invalid;
1055
1161
  if (ngn::controlledTextIsCurrent(p->mostRecentEventCount, _eventCount, _text.hasMarkedText) && !p->text.empty()) {
1056
1162
  NSString *text = nsString(p->text);
1057
1163
  if (![_text.string isEqualToString:text]) {
@@ -9,6 +9,8 @@
9
9
  #import <AppKit/AppKit.h>
10
10
 
11
11
  #include <functional>
12
+ #include <string>
13
+ #include <utility>
12
14
 
13
15
  namespace ngn::appkit {
14
16
 
@@ -17,6 +19,10 @@ void replayInputScript(NSWindow *window, InputScript script);
17
19
  // Plays one step into the window now; a wait does nothing.
18
20
  void playInputStep(NSWindow *window, const InputStep &step);
19
21
 
22
+ // The characters and virtual key code a key step's key sends: a named key's, or a character's own
23
+ // with no code.
24
+ std::pair<NSString *, unsigned short> keyOf(const std::string &key);
25
+
20
26
  // The host's local monitor of scrolls (its back swipe), which a replayed scroll the window takes
21
27
  // itself (the real pointer being elsewhere) passes first, as NSApp's monitors see a real one. It
22
28
  // answers the event to send on, or nil to stop it, and is given the window the event is for.
@@ -158,6 +158,24 @@ NSString *typedWith(NSString *base, NSEventModifierFlags flags) {
158
158
  return base;
159
159
  }
160
160
 
161
+ } // namespace
162
+
163
+ std::pair<NSString *, unsigned short> keyOf(const std::string &key) {
164
+ auto function = [](unichar c) { return [NSString stringWithFormat:@"%C", c]; };
165
+ if (key == "escape") return {@"\x1b", 53};
166
+ if (key == "return") return {@"\r", 36};
167
+ if (key == "space") return {@" ", 49};
168
+ if (key == "tab") return {@"\t", 48};
169
+ if (key == "delete") return {@"\x7f", 51};
170
+ if (key == "left") return {function(NSLeftArrowFunctionKey), 123};
171
+ if (key == "right") return {function(NSRightArrowFunctionKey), 124};
172
+ if (key == "down") return {function(NSDownArrowFunctionKey), 125};
173
+ if (key == "up") return {function(NSUpArrowFunctionKey), 126};
174
+ return {[NSString stringWithUTF8String:key.c_str()], 0};
175
+ }
176
+
177
+ namespace {
178
+
161
179
  // The window the keyboard's steps go to: the modal window while one runs, else the key window (a
162
180
  // red box or a sheet, not only the app's), else the script's window.
163
181
  NSWindow *keyboardWindow(NSWindow *scriptWindow) {
@@ -169,18 +187,7 @@ NSWindow *keyboardWindow(NSWindow *scriptWindow) {
169
187
  // A key press and its release, to the keyboard's window.
170
188
  void sendKey(NSWindow *scriptWindow, const InputStep &step) {
171
189
  NSWindow *window = keyboardWindow(scriptWindow);
172
- NSString *characters = step.key == "escape" ? @"\x1b"
173
- : step.key == "return" ? @"\r"
174
- : step.key == "space" ? @" "
175
- : step.key == "tab" ? @"\t"
176
- : step.key == "delete" ? @"\x7f"
177
- : [NSString stringWithUTF8String:step.key.c_str()];
178
- unsigned short code = step.key == "escape" ? 53
179
- : step.key == "return" ? 36
180
- : step.key == "space" ? 49
181
- : step.key == "tab" ? 48
182
- : step.key == "delete" ? 51
183
- : 0;
190
+ auto [characters, code] = keyOf(step.key);
184
191
  // A character typed into text goes in as the input method puts it, through NSTextInputClient: a
185
192
  // made-up key event reaches the field editor's keyDown, but the text system inserts nothing for
186
193
  // one no keyboard sent.
@@ -191,6 +198,8 @@ void sendKey(NSWindow *scriptWindow, const InputStep &step) {
191
198
  if (step.modifiers & InputStep::Shift) flags |= NSEventModifierFlagShift;
192
199
  if (step.modifiers & InputStep::Option) flags |= NSEventModifierFlagOption;
193
200
  if (step.modifiers & InputStep::Control) flags |= NSEventModifierFlagControl;
201
+ // An arrow is a function key on the keypad, as the keyboard sends it.
202
+ if (code >= 123 && code <= 126) flags |= NSEventModifierFlagFunction | NSEventModifierFlagNumericPad;
194
203
  // Shift and Option change the character typed, as the keyboard layout has them.
195
204
  id responder = window.firstResponder;
196
205
  if (typed && [responder conformsToProtocol:@protocol(NSTextInputClient)]) {