@ng-native/desktop 0.26.0 → 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
@@ -0,0 +1,138 @@
1
+ #include "ngn/accessibility-relations.h"
2
+
3
+ #include "ngn/desktop-view-props.h"
4
+ #include "ngn/text-input.h"
5
+
6
+ #include <react/renderer/components/view/ViewProps.h>
7
+
8
+ using namespace facebook::react;
9
+
10
+ namespace ngn {
11
+
12
+ namespace {
13
+
14
+ // The ids a view's props say describe it: a view's desktop props have them, and so do a text
15
+ // input's.
16
+ const std::vector<std::string> &describedByIds(const Props &props) {
17
+ static const std::vector<std::string> none;
18
+ if (const auto *input = dynamic_cast<const DesktopTextInputProps *>(&props)) {
19
+ return input->accessibilityDescribedBy;
20
+ }
21
+ const auto *desktop = dynamic_cast<const HasDesktopProps *>(&props);
22
+ return desktop ? desktop->desktop.accessibilityDescribedBy : none;
23
+ }
24
+
25
+ } // namespace
26
+
27
+ void AccessibilityRelations::update(const ShadowView &view) {
28
+ const auto *props = dynamic_cast<const ViewProps *>(view.props.get());
29
+ std::string id = view.props ? view.props->nativeId : std::string{};
30
+ auto known = idOf_.find(view.tag);
31
+ if (known == idOf_.end() ? !id.empty() : known->second.second != id) {
32
+ forgetId(view.tag);
33
+ if (!id.empty()) {
34
+ ids_[view.surfaceId][id].insert(view.tag);
35
+ idOf_[view.tag] = {view.surfaceId, id};
36
+ }
37
+ dirty_.insert(view.surfaceId);
38
+ }
39
+ Names names{.surfaceId = view.surfaceId};
40
+ if (props) {
41
+ names.labelledBy = props->accessibilityLabelledBy.value;
42
+ names.describedBy = describedByIds(*props);
43
+ }
44
+ auto naming = naming_.find(view.tag);
45
+ bool namesAny = !names.labelledBy.empty() || !names.describedBy.empty();
46
+ if (naming == naming_.end() && !namesAny) {
47
+ return;
48
+ }
49
+ if (naming != naming_.end() && naming->second.labelledBy == names.labelledBy &&
50
+ naming->second.describedBy == names.describedBy) {
51
+ return;
52
+ }
53
+ if (namesAny) {
54
+ naming_[view.tag] = std::move(names);
55
+ } else {
56
+ naming_.erase(view.tag);
57
+ }
58
+ dirty_.insert(view.surfaceId);
59
+ }
60
+
61
+ void AccessibilityRelations::remove(Tag tag) {
62
+ if (auto known = idOf_.find(tag); known != idOf_.end()) {
63
+ dirty_.insert(known->second.first);
64
+ }
65
+ forgetId(tag);
66
+ naming_.erase(tag);
67
+ // Its widget goes with it: nothing to clear.
68
+ reported_.erase(tag);
69
+ }
70
+
71
+ void AccessibilityRelations::forgetId(Tag tag) {
72
+ auto known = idOf_.find(tag);
73
+ if (known == idOf_.end()) {
74
+ return;
75
+ }
76
+ auto &[surfaceId, id] = known->second;
77
+ auto &surface = ids_[surfaceId];
78
+ if (auto views = surface.find(id); views != surface.end()) {
79
+ views->second.erase(tag);
80
+ if (views->second.empty()) {
81
+ surface.erase(views);
82
+ }
83
+ }
84
+ if (surface.empty()) {
85
+ ids_.erase(surfaceId);
86
+ }
87
+ idOf_.erase(known);
88
+ }
89
+
90
+ std::vector<Tag> AccessibilityRelations::resolve(SurfaceId surfaceId, const std::vector<std::string> &ids) const {
91
+ std::vector<Tag> tags;
92
+ auto surface = ids_.find(surfaceId);
93
+ if (surface == ids_.end()) {
94
+ return tags;
95
+ }
96
+ for (const auto &id : ids) {
97
+ if (auto views = surface->second.find(id); views != surface->second.end() && !views->second.empty()) {
98
+ // The lowest tag wins. Fabric counts tags up as views are made, so that is the one made first.
99
+ tags.push_back(*views->second.begin());
100
+ }
101
+ }
102
+ return tags;
103
+ }
104
+
105
+ std::vector<std::pair<Tag, AxRelations>> AccessibilityRelations::didMount(SurfaceId surfaceId) {
106
+ std::vector<std::pair<Tag, AxRelations>> changed;
107
+ if (dirty_.erase(surfaceId) == 0) {
108
+ return changed;
109
+ }
110
+ for (const auto &[tag, names] : naming_) {
111
+ if (names.surfaceId != surfaceId) {
112
+ continue;
113
+ }
114
+ AxRelations now{resolve(surfaceId, names.labelledBy), resolve(surfaceId, names.describedBy)};
115
+ auto it = reported_.find(tag);
116
+ if (it == reported_.end() ? now.empty() : it->second.second == now) {
117
+ continue;
118
+ }
119
+ if (now.empty()) {
120
+ reported_.erase(it);
121
+ } else {
122
+ reported_[tag] = {surfaceId, now};
123
+ }
124
+ changed.emplace_back(tag, std::move(now));
125
+ }
126
+ // A view that stopped naming any: its relations clear.
127
+ for (auto it = reported_.begin(); it != reported_.end();) {
128
+ if (it->second.first == surfaceId && !naming_.contains(it->first)) {
129
+ changed.emplace_back(it->first, AxRelations{});
130
+ it = reported_.erase(it);
131
+ } else {
132
+ ++it;
133
+ }
134
+ }
135
+ return changed;
136
+ }
137
+
138
+ } // namespace ngn
@@ -1,5 +1,6 @@
1
1
  #include "ngn/accessibility.h"
2
2
  #include "ngn/desktop-props.h"
3
+ #include "ngn/text-input.h"
3
4
  #include "ngn/view-tree.h"
4
5
 
5
6
  #include <react/renderer/components/text/ParagraphState.h>
@@ -148,6 +149,22 @@ bool adjustableRole(const std::string &name) {
148
149
  return name == "adjustable" || name == "slider" || name == "spinbutton";
149
150
  }
150
151
 
152
+ // The ARIA states and counts a view's or a text input's props carry; none for any other props.
153
+ const AriaFields *ariaFields(const ViewProps &props) {
154
+ if (const auto *desktop = dynamic_cast<const HasDesktopProps *>(&props)) {
155
+ return &desktop->desktop.aria;
156
+ }
157
+ if (const auto *input = dynamic_cast<const DesktopTextInputProps *>(&props)) {
158
+ return &input->aria;
159
+ }
160
+ return nullptr;
161
+ }
162
+
163
+ // A count or a place in a set, from 1: anything below says nothing.
164
+ std::optional<int> fromOne(std::optional<int> value) {
165
+ return value && *value >= 1 ? value : std::nullopt;
166
+ }
167
+
151
168
  bool declares(const ViewProps &props, const std::string &action) {
152
169
  for (const auto &declared : props.accessibilityActions) {
153
170
  if (declared.name == action) {
@@ -212,6 +229,14 @@ AxInfo accessibilityInfo(const ViewProps &props) {
212
229
  if (props.accessibilityState) {
213
230
  info.expanded = props.accessibilityState->expanded;
214
231
  }
232
+ if (const auto *aria = ariaFields(props)) {
233
+ info.required = aria->required;
234
+ info.invalid = aria->invalid;
235
+ info.positionInSet = fromOne(aria->posInSet);
236
+ info.setSize = fromOne(aria->setSize);
237
+ info.rowCount = fromOne(aria->rowCount);
238
+ info.columnCount = fromOne(aria->columnCount);
239
+ }
215
240
  for (const auto &action : props.accessibilityActions) {
216
241
  const auto &n = action.name;
217
242
  if (n != "activate" && n != "increment" && n != "decrement" && n != "escape") {
@@ -371,4 +396,29 @@ AxDispatch axDispatch(const ViewProps &props, AxVerb verb) {
371
396
  return {};
372
397
  }
373
398
 
399
+ bool performAxVerb(const ViewProps &props, const ViewEventEmitter *emitter, AxVerb verb, const std::function<bool()> &click) {
400
+ auto dispatch = axDispatch(props, verb);
401
+ switch (dispatch.kind) {
402
+ case AxDispatch::Kind::None:
403
+ return false;
404
+ case AxDispatch::Kind::Tap:
405
+ return emitter && (emitter->onAccessibilityTap(), true);
406
+ case AxDispatch::Kind::Escape:
407
+ return emitter && (emitter->onAccessibilityEscape(), true);
408
+ case AxDispatch::Kind::Action:
409
+ return emitter && (emitter->onAccessibilityAction(dispatch.action), true);
410
+ case AxDispatch::Kind::Click:
411
+ return click && click();
412
+ }
413
+ return false;
414
+ }
415
+
416
+ bool sendAxAction(const ViewProps &props, const ViewEventEmitter *emitter, const std::string &name) {
417
+ if (!props.onAccessibilityAction || !emitter) {
418
+ return false;
419
+ }
420
+ emitter->onAccessibilityAction(name);
421
+ return true;
422
+ }
423
+
374
424
  } // namespace ngn
@@ -0,0 +1,166 @@
1
+ #include "ngn/animated-frame-loop.h"
2
+
3
+ #include <react/renderer/animated/NativeAnimatedNodesManagerProvider.h>
4
+
5
+ #include <cstdint>
6
+ #include <mutex>
7
+ #include <utility>
8
+
9
+ namespace ngn {
10
+
11
+ // What a frame's request reads when it runs. A stop and a start between two frames leave the first
12
+ // start's request waiting: the run it belongs to (`run`) tells it from the new one, so it renders
13
+ // nothing and asks for no frame after.
14
+ struct AnimatedFrameLoop::State {
15
+ explicit State(AnimationFrames &frames) : frames(frames) {}
16
+
17
+ AnimationFrames &frames;
18
+ std::mutex mutex;
19
+ // Held for the length of a render, which a stop waits on: React Native's manager is destroyed,
20
+ // stopping the loop on the way, on a reload's own thread, while the UI thread may be inside its
21
+ // render. Recursive, as the manager stops the loop from inside its render too.
22
+ std::recursive_mutex rendering;
23
+ std::function<void()> render;
24
+ std::uint64_t run = 0;
25
+ bool running = false;
26
+ // Closed for good, as its ReactHost goes: a start from the manager that is going does nothing.
27
+ bool closed = false;
28
+ // The starts and stops the manager has made. It starts the loop only once it has cleared its own
29
+ // started flag, and stops it only once it has set it, so the two alternate as it makes them, but
30
+ // they can come here out of turn: a render clears the flag and then stops the loop, and a start
31
+ // from JavaScript in between comes first. So the loop runs while there are more starts than
32
+ // stops, rather than by the last call, whichever thread or render each comes from.
33
+ std::uint64_t starts = 0;
34
+ std::uint64_t stops = 0;
35
+ // Stops and closes waiting for a render on another thread to return.
36
+ int waiting = 0;
37
+ };
38
+
39
+ namespace {
40
+
41
+ void requestFrame(const std::shared_ptr<AnimatedFrameLoop::State> &state, std::uint64_t run);
42
+
43
+ void onFrame(const std::weak_ptr<AnimatedFrameLoop::State> &weak, std::uint64_t run) {
44
+ auto state = weak.lock();
45
+ if (!state) {
46
+ return;
47
+ }
48
+ {
49
+ std::lock_guard rendering(state->rendering);
50
+ std::function<void()> render;
51
+ {
52
+ std::lock_guard lock(state->mutex);
53
+ if (!state->running || state->run != run) {
54
+ return;
55
+ }
56
+ render = state->render;
57
+ }
58
+ // Outside the lock: the manager stops the loop from inside its render once nothing animates.
59
+ render();
60
+ }
61
+ {
62
+ std::lock_guard lock(state->mutex);
63
+ if (!state->running || state->run != run) {
64
+ return;
65
+ }
66
+ }
67
+ requestFrame(state, run);
68
+ }
69
+
70
+ void requestFrame(const std::shared_ptr<AnimatedFrameLoop::State> &state, std::uint64_t run) {
71
+ std::weak_ptr<AnimatedFrameLoop::State> weak = state;
72
+ state->frames.request([weak, run](double) { onFrame(weak, run); });
73
+ }
74
+
75
+ } // namespace
76
+
77
+ AnimatedFrameLoop::AnimatedFrameLoop(AnimationFrames &frames) : state_(std::make_shared<State>(frames)) {}
78
+
79
+ AnimatedFrameLoop::~AnimatedFrameLoop() {
80
+ close();
81
+ }
82
+
83
+ void AnimatedFrameLoop::start(std::function<void()> render) {
84
+ std::uint64_t run = 0;
85
+ {
86
+ std::lock_guard lock(state_->mutex);
87
+ if (state_->closed) {
88
+ return;
89
+ }
90
+ // A stop that came before the start it answers leaves the loop stopped, and nothing to render.
91
+ if (++state_->starts <= state_->stops) {
92
+ return;
93
+ }
94
+ state_->render = std::move(render);
95
+ if (state_->running) {
96
+ return;
97
+ }
98
+ state_->running = true;
99
+ run = ++state_->run;
100
+ }
101
+ requestFrame(state_, run);
102
+ }
103
+
104
+ void AnimatedFrameLoop::stop() {
105
+ // Released after the lock, in case its closure's destructor reaches the loop.
106
+ std::function<void()> released;
107
+ {
108
+ std::lock_guard lock(state_->mutex);
109
+ // A stop a later start overtook: what the start asked for stands, and the loop goes on with it.
110
+ // Not once closed, which stops it whatever is due.
111
+ if (++state_->stops < state_->starts && !state_->closed) {
112
+ return;
113
+ }
114
+ state_->running = false;
115
+ released = std::move(state_->render);
116
+ state_->render = nullptr;
117
+ }
118
+ // A render running on another thread returns before this does, so what it renders with outlives
119
+ // it; none starts after, as the loop no longer runs.
120
+ {
121
+ std::lock_guard lock(state_->mutex);
122
+ ++state_->waiting;
123
+ }
124
+ std::lock_guard rendering(state_->rendering);
125
+ std::lock_guard lock(state_->mutex);
126
+ --state_->waiting;
127
+ }
128
+
129
+ void AnimatedFrameLoop::close() {
130
+ {
131
+ std::lock_guard lock(state_->mutex);
132
+ state_->closed = true;
133
+ }
134
+ // Waits for a render on another thread, whether or not that render stopped the loop itself.
135
+ stop();
136
+ }
137
+
138
+ bool AnimatedFrameLoop::running() const {
139
+ std::lock_guard lock(state_->mutex);
140
+ return state_->running;
141
+ }
142
+
143
+ int AnimatedFrameLoop::waiting() const {
144
+ std::lock_guard lock(state_->mutex);
145
+ return state_->waiting;
146
+ }
147
+
148
+ bool AnimatedFrameLoop::closed() const {
149
+ std::lock_guard lock(state_->mutex);
150
+ return state_->closed;
151
+ }
152
+
153
+ std::shared_ptr<facebook::react::NativeAnimatedNodesManagerProvider> animatedNodesManagerProvider(
154
+ std::shared_ptr<AnimatedFrameLoop> loop) {
155
+ std::weak_ptr<AnimatedFrameLoop> weak = loop;
156
+ return std::make_shared<facebook::react::NativeAnimatedNodesManagerProvider>(
157
+ // The loop is the provider's to keep: the runtime holds the provider through its ReactHost.
158
+ [loop](std::function<void()> &&render, bool /*isAsync*/) { loop->start(std::move(render)); },
159
+ [weak](bool /*isAsync*/) {
160
+ if (auto loop = weak.lock()) {
161
+ loop->stop();
162
+ }
163
+ });
164
+ }
165
+
166
+ } // namespace ngn
@@ -43,6 +43,7 @@ MenuCommand roleCommand(const std::string &role) {
43
43
  {"bringAllToFront", MenuCommand::BringAllToFront},
44
44
  {"close", MenuCommand::CloseWindow},
45
45
  {"print", MenuCommand::Print},
46
+ {"keyboardShortcuts", MenuCommand::KeyboardShortcuts},
46
47
  };
47
48
  auto it = commands.find(role);
48
49
  return it == commands.end() ? MenuCommand::AppItem : it->second;
@@ -95,14 +96,13 @@ const char *directionName(NavigationDirection direction) {
95
96
  return direction == NavigationDirection::Back ? "back" : "forward";
96
97
  }
97
98
 
98
- // The keys a focused text input owns.
99
+ } // namespace
100
+
99
101
  bool editingChord(const KeyChord &chord, const HostOs &os) {
100
102
  static const std::vector<std::string> keys{"z", "x", "c", "v", "a"};
101
- return chord.modifiers == os.primaryModifier && std::find(keys.begin(), keys.end(), chord.key) != keys.end();
103
+ return chord.modifiers == os.primaryModifier && std::find(keys.begin(), keys.end(), normalKey(chord.key)) != keys.end();
102
104
  }
103
105
 
104
- } // namespace
105
-
106
106
  KeyChord parseChord(const folly::dynamic &chord) {
107
107
  KeyChord out{.key = normalKey(text(chord, "key"))};
108
108
  if (flag(chord, "meta")) {
@@ -204,11 +204,11 @@ void MenuHost::setMenuBar(const folly::dynamic &groups) {
204
204
  }
205
205
 
206
206
  void MenuHost::setShortcuts(const folly::dynamic &shortcuts) {
207
- std::vector<std::pair<std::string, KeyChord>> parsed;
207
+ std::vector<Shortcut> parsed;
208
208
  if (shortcuts.isArray()) {
209
209
  for (const auto &shortcut : shortcuts) {
210
210
  if (shortcut.isObject()) {
211
- parsed.emplace_back(text(shortcut, "id"), parseChord(shortcut.getDefault("chord")));
211
+ parsed.push_back({text(shortcut, "id"), parseChord(shortcut.getDefault("chord")), text(shortcut, "label"), text(shortcut, "group")});
212
212
  }
213
213
  }
214
214
  }
@@ -233,9 +233,9 @@ bool MenuHost::keyDown(const KeyChord &pressed, bool textInputFocused) {
233
233
  std::optional<std::string> id;
234
234
  {
235
235
  std::lock_guard lock(mutex_);
236
- for (const auto &[shortcutId, shortcut] : shortcuts_) {
237
- if (shortcut == chord) {
238
- id = shortcutId;
236
+ for (const auto &shortcut : shortcuts_) {
237
+ if (shortcut.chord == chord) {
238
+ id = shortcut.id;
239
239
  break;
240
240
  }
241
241
  }
@@ -247,6 +247,23 @@ bool MenuHost::keyDown(const KeyChord &pressed, bool textInputFocused) {
247
247
  return !(textInputFocused && editingChord(chord, options_.os));
248
248
  }
249
249
 
250
+ std::vector<ShortcutGroup> MenuHost::keyboardShortcuts(const std::vector<MenuItem> &bar) const {
251
+ auto groups = menuShortcuts(bar);
252
+ std::lock_guard lock(mutex_);
253
+ for (const auto &shortcut : shortcuts_) {
254
+ if (shortcut.label.empty()) {
255
+ continue;
256
+ }
257
+ const std::string &title = shortcut.group.empty() ? options_.appName : shortcut.group;
258
+ auto group = std::find_if(groups.begin(), groups.end(), [&title](const ShortcutGroup &g) { return g.title == title; });
259
+ if (group == groups.end()) {
260
+ group = groups.insert(groups.end(), ShortcutGroup{.title = title});
261
+ }
262
+ group->entries.push_back({.title = shortcut.label, .chord = shortcut.chord});
263
+ }
264
+ return groups;
265
+ }
266
+
250
267
  void MenuHost::navigate(NavigationDirection direction, std::optional<SurfaceId> surface, int steps) {
251
268
  folly::dynamic event = folly::dynamic::object("type", "navigate")("direction", directionName(direction));
252
269
  if (surface) {
@@ -31,7 +31,12 @@ std::optional<WindowFrame> savedFrame(const std::optional<folly::dynamic> &value
31
31
  if (!x || !y || !width || !height || *width <= 0 || *height <= 0) {
32
32
  return std::nullopt;
33
33
  }
34
- return WindowFrame{.x = *x, .y = *y, .width = *width, .height = *height};
34
+ auto flag = [&value](const char *name) {
35
+ auto it = value->find(name);
36
+ return it != value->items().end() && it->second.isBool() && it->second.asBool();
37
+ };
38
+ return WindowFrame{
39
+ .x = *x, .y = *y, .width = *width, .height = *height, .maximized = flag("maximized"), .fullScreen = flag("fullScreen")};
35
40
  }
36
41
 
37
42
  double clamp(double value, std::optional<double> min, std::optional<double> max) {
@@ -281,13 +286,17 @@ void WindowHost::focused(std::optional<SurfaceId> surface) {
281
286
  }
282
287
 
283
288
  void WindowHost::resized(SurfaceId surface, const WindowFrame &frame, double scale) {
289
+ resized(surface, frame, scale, frame);
290
+ }
291
+
292
+ void WindowHost::resized(SurfaceId surface, const WindowFrame &frame, double scale, const WindowFrame &saved) {
284
293
  {
285
294
  std::lock_guard lock(mutex_);
286
295
  if (!windows_.contains(surface)) {
287
296
  return;
288
297
  }
289
298
  }
290
- autosave(surface, frame);
299
+ autosave(surface, saved);
291
300
  send(folly::dynamic::object("type", "resize")("surface", surface)("width", frame.width)("height", frame.height)(
292
301
  "scale", scale));
293
302
  }
@@ -304,11 +313,23 @@ void WindowHost::autosave(SurfaceId surface, const WindowFrame &frame) {
304
313
  key = it->second.key;
305
314
  }
306
315
  }
307
- if (key) {
308
- system_->setPreference(
309
- frameKey(*key),
310
- folly::dynamic::object("x", frame.x)("y", frame.y)("width", frame.width)("height", frame.height));
316
+ if (!key) {
317
+ return;
318
+ }
319
+ folly::dynamic saved = folly::dynamic::object("x", frame.x)("y", frame.y)("width", frame.width)("height", frame.height);
320
+ // Only a window filling the screen says so, so a frame saved before reads the same.
321
+ if (frame.maximized) {
322
+ saved["maximized"] = true;
323
+ }
324
+ if (frame.fullScreen) {
325
+ saved["fullScreen"] = true;
311
326
  }
327
+ system_->setPreference(frameKey(*key), std::move(saved));
328
+ }
329
+
330
+ bool WindowHost::lastWindowClosed() {
331
+ std::lock_guard lock(mutex_);
332
+ return listeners_.empty();
312
333
  }
313
334
 
314
335
  void WindowHost::reopen(bool hasVisibleWindows) {
@@ -0,0 +1,127 @@
1
+ #include "ngn/aria-role.h"
2
+
3
+ #include <unordered_map>
4
+
5
+ namespace ngn {
6
+
7
+ namespace {
8
+
9
+ // Every role name roleName gives: React Native's Role (ARIA's), its accessibilityRole values, and
10
+ // the ARIA roles Role lacks that the desktop props keep as written.
11
+ const std::unordered_map<std::string, AriaRole> &roles() {
12
+ static const std::unordered_map<std::string, AriaRole> table{
13
+ // React Native's Role.
14
+ {"alert", AriaRole::Alert},
15
+ {"alertdialog", AriaRole::AlertDialog},
16
+ // GTK's APPLICATION is an AT-SPI frame, which would nest a frame in the window.
17
+ {"application", AriaRole::Group},
18
+ {"article", AriaRole::Article},
19
+ {"banner", AriaRole::Banner},
20
+ {"button", AriaRole::Button},
21
+ {"cell", AriaRole::Cell},
22
+ {"checkbox", AriaRole::Checkbox},
23
+ {"columnheader", AriaRole::ColumnHeader},
24
+ {"combobox", AriaRole::ComboBox},
25
+ {"complementary", AriaRole::Region},
26
+ {"contentinfo", AriaRole::Region},
27
+ {"definition", AriaRole::Generic},
28
+ {"dialog", AriaRole::Dialog},
29
+ {"directory", AriaRole::List},
30
+ {"document", AriaRole::Document},
31
+ {"feed", AriaRole::Feed},
32
+ {"figure", AriaRole::Group},
33
+ {"form", AriaRole::Form},
34
+ {"grid", AriaRole::Grid},
35
+ {"group", AriaRole::Group},
36
+ {"heading", AriaRole::Heading},
37
+ {"img", AriaRole::Img},
38
+ {"link", AriaRole::Link},
39
+ {"list", AriaRole::List},
40
+ {"listitem", AriaRole::ListItem},
41
+ {"log", AriaRole::Log},
42
+ {"main", AriaRole::Main},
43
+ {"marquee", AriaRole::Marquee},
44
+ {"math", AriaRole::Math},
45
+ {"menu", AriaRole::Menu},
46
+ {"menubar", AriaRole::MenuBar},
47
+ {"menuitem", AriaRole::MenuItem},
48
+ {"meter", AriaRole::Meter},
49
+ {"navigation", AriaRole::Navigation},
50
+ {"none", AriaRole::None},
51
+ {"note", AriaRole::Note},
52
+ {"option", AriaRole::Option},
53
+ {"presentation", AriaRole::Presentation},
54
+ {"progressbar", AriaRole::ProgressBar},
55
+ {"radio", AriaRole::Radio},
56
+ {"radiogroup", AriaRole::RadioGroup},
57
+ {"region", AriaRole::Region},
58
+ {"row", AriaRole::Row},
59
+ {"rowgroup", AriaRole::RowGroup},
60
+ {"rowheader", AriaRole::RowHeader},
61
+ {"scrollbar", AriaRole::Scrollbar},
62
+ {"searchbox", AriaRole::SearchBox},
63
+ {"separator", AriaRole::Separator},
64
+ {"slider", AriaRole::Slider},
65
+ {"spinbutton", AriaRole::SpinButton},
66
+ {"status", AriaRole::Status},
67
+ {"summary", AriaRole::Button},
68
+ {"switch", AriaRole::Switch},
69
+ {"tab", AriaRole::Tab},
70
+ {"table", AriaRole::Table},
71
+ {"tablist", AriaRole::TabList},
72
+ {"tabpanel", AriaRole::TabPanel},
73
+ {"term", AriaRole::Label},
74
+ {"timer", AriaRole::Timer},
75
+ {"toolbar", AriaRole::Toolbar},
76
+ {"tooltip", AriaRole::Tooltip},
77
+ {"tree", AriaRole::Tree},
78
+ {"treegrid", AriaRole::TreeGrid},
79
+ {"treeitem", AriaRole::TreeItem},
80
+ // React Native's accessibilityRole values Role does not have.
81
+ {"togglebutton", AriaRole::ToggleButton},
82
+ // A search field, not ARIA's search landmark.
83
+ {"search", AriaRole::SearchBox},
84
+ {"image", AriaRole::Img},
85
+ {"text", AriaRole::Label},
86
+ {"adjustable", AriaRole::Slider},
87
+ {"imagebutton", AriaRole::Button},
88
+ {"header", AriaRole::Heading},
89
+ {"tabbar", AriaRole::TabList},
90
+ {"viewgroup", AriaRole::Generic},
91
+ {"keyboardkey", AriaRole::Button},
92
+ {"pager", AriaRole::Group},
93
+ // The scrolling widget is the scroll pane.
94
+ {"scrollview", AriaRole::Generic},
95
+ {"horizontalscrollview", AriaRole::Generic},
96
+ {"webview", AriaRole::Document},
97
+ {"drawerlayout", AriaRole::Group},
98
+ {"slidingdrawer", AriaRole::Group},
99
+ {"iconmenu", AriaRole::Menu},
100
+ // ARIA roles Role lacks, kept as written (DesktopProps::role).
101
+ {"listbox", AriaRole::ListBox},
102
+ {"gridcell", AriaRole::GridCell},
103
+ {"menuitemcheckbox", AriaRole::MenuItemCheckbox},
104
+ {"menuitemradio", AriaRole::MenuItemRadio},
105
+ };
106
+ return table;
107
+ }
108
+
109
+ } // namespace
110
+
111
+ AriaRole ariaRole(const std::string &name, const AxInfo &info) {
112
+ if (name == "none") {
113
+ return AriaRole::None;
114
+ }
115
+ if (name == "presentation") {
116
+ return AriaRole::Presentation;
117
+ }
118
+ if (!info.element) {
119
+ return AriaRole::Generic;
120
+ }
121
+ if (auto it = roles().find(name); it != roles().end()) {
122
+ return it->second;
123
+ }
124
+ return info.role == AxRole::StaticText ? AriaRole::Label : AriaRole::Group;
125
+ }
126
+
127
+ } // namespace ngn
@@ -95,11 +95,15 @@ Size ControlSizes::layoutSize(
95
95
  Tag tag,
96
96
  ControlKind kind,
97
97
  std::shared_ptr<const NativeControlProps> props,
98
- const State::Shared &state) {
98
+ const State::Shared &state,
99
+ float fontScale) {
99
100
  if (!measurer_ || !props) {
100
101
  return {0, 0};
101
102
  }
102
103
  auto key = controlSizeKey(kind, *props);
104
+ if (fontScale != 1) {
105
+ key += "\x1f@" + std::to_string(fontScale);
106
+ }
103
107
  {
104
108
  std::lock_guard lock(mutex_);
105
109
  hold(tag, key);
@@ -110,7 +114,7 @@ Size ControlSizes::layoutSize(
110
114
  return control.size;
111
115
  }
112
116
  if (!onUiThread_()) {
113
- queued_[tag] = Queued{.kind = kind, .props = std::move(props), .state = state};
117
+ queued_[tag] = Queued{.key = key, .kind = kind, .props = std::move(props), .state = state};
114
118
  if (!posted_ && runOnUiThread_) {
115
119
  posted_ = true;
116
120
  runOnUiThread_([weak = weak_from_this()] {
@@ -144,7 +148,7 @@ void ControlSizes::settle() {
144
148
  queued.swap(queued_);
145
149
  }
146
150
  for (const auto &[tag, request] : queued) {
147
- auto key = controlSizeKey(request.kind, *request.props);
151
+ const auto &key = request.key;
148
152
  bool measure = false;
149
153
  {
150
154
  std::lock_guard lock(mutex_);
@@ -220,13 +224,13 @@ void ControlSizes::release(const std::string &key) {
220
224
  }
221
225
  }
222
226
 
223
- Size measureControl(const ShadowNode &node, ControlKind kind, const ContextContainer *context) {
227
+ Size measureControl(const ShadowNode &node, ControlKind kind, const ContextContainer *context, float fontScale) {
224
228
  auto sizes = context ? context->find<std::shared_ptr<ControlSizes>>(kControlSizesKey) : std::nullopt;
225
229
  if (!sizes || !*sizes) {
226
230
  return {0, 0};
227
231
  }
228
232
  return (*sizes)->layoutSize(
229
- node.getTag(), kind, std::static_pointer_cast<const NativeControlProps>(node.getProps()), node.getState());
233
+ node.getTag(), kind, std::static_pointer_cast<const NativeControlProps>(node.getProps()), node.getState(), fontScale);
230
234
  }
231
235
 
232
236
  } // namespace ngn