@ng-native/desktop 0.0.0-stage → 0.23.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.
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +276 -0
- package/native/appkit/CMakeLists.txt +109 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +130 -0
- package/native/appkit/camera.h +39 -0
- package/native/appkit/camera.mm +362 -0
- package/native/appkit/cg-canvas.h +17 -0
- package/native/appkit/cg-canvas.mm +518 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +629 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1200 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1515 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +558 -0
- package/native/appkit/svg-view.h +17 -0
- package/native/appkit/svg-view.mm +57 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +76 -0
- package/native/appkit/text-input-field.mm +444 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +477 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +9 -0
- package/native/appkit/web-view-component.mm +56 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +394 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +146 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +112 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +128 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +105 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +130 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +161 -0
- package/native/core/include/ngn/safe-areas.h +77 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/svg.h +393 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +125 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +133 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +352 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +91 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +345 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +405 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +221 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +371 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +380 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +422 -0
- package/native/core/src/safe-areas.cpp +130 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +1883 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +126 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +171 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +70 -3
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// What the host knows about the app that JavaScript reads and listens to: whether it is active,
|
|
2
|
+
// its window's size, the colour scheme and the URLs it was asked to open. One for the app, set by
|
|
3
|
+
// the backend as things change; each runtime's modules subscribe to it, so a reload keeps it.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <folly/dynamic.h>
|
|
7
|
+
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <deque>
|
|
10
|
+
#include <functional>
|
|
11
|
+
#include <map>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <mutex>
|
|
14
|
+
#include <optional>
|
|
15
|
+
#include <string>
|
|
16
|
+
#include <vector>
|
|
17
|
+
|
|
18
|
+
namespace ngn {
|
|
19
|
+
|
|
20
|
+
// Listeners that can be dropped from any thread at any time. Dropping one waits for a call to it
|
|
21
|
+
// already running elsewhere, so once its handle is gone nothing calls into what it captured (a
|
|
22
|
+
// module a reload is destroying). A listener may drop its own handle while it is being called.
|
|
23
|
+
template <typename T>
|
|
24
|
+
class Listeners {
|
|
25
|
+
public:
|
|
26
|
+
using Listener = std::function<void(const T &)>;
|
|
27
|
+
|
|
28
|
+
// Listens until the returned handle is destroyed.
|
|
29
|
+
std::shared_ptr<void> add(Listener listener) {
|
|
30
|
+
auto entry = std::make_shared<Entry>();
|
|
31
|
+
entry->call = std::move(listener);
|
|
32
|
+
int id;
|
|
33
|
+
{
|
|
34
|
+
std::lock_guard lock(state_->mutex);
|
|
35
|
+
id = state_->next++;
|
|
36
|
+
state_->entries[id] = entry;
|
|
37
|
+
}
|
|
38
|
+
std::weak_ptr<State> state = state_;
|
|
39
|
+
return std::shared_ptr<void>(nullptr, [state, entry, id](void *) {
|
|
40
|
+
{
|
|
41
|
+
// Waits for a call in progress on another thread; the same thread re-enters.
|
|
42
|
+
std::lock_guard calling(entry->calling);
|
|
43
|
+
entry->live = false;
|
|
44
|
+
}
|
|
45
|
+
if (auto shared = state.lock()) {
|
|
46
|
+
std::lock_guard lock(shared->mutex);
|
|
47
|
+
shared->entries.erase(id);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bool empty() const {
|
|
53
|
+
std::lock_guard lock(state_->mutex);
|
|
54
|
+
return state_->entries.empty();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Calls each listener, and answers how many were called: none when the last handle went while
|
|
58
|
+
// this ran.
|
|
59
|
+
size_t notify(const T &value) const {
|
|
60
|
+
std::map<int, std::shared_ptr<Entry>> entries;
|
|
61
|
+
{
|
|
62
|
+
std::lock_guard lock(state_->mutex);
|
|
63
|
+
entries = state_->entries;
|
|
64
|
+
}
|
|
65
|
+
size_t called = 0;
|
|
66
|
+
for (auto &[_, entry] : entries) {
|
|
67
|
+
std::lock_guard calling(entry->calling);
|
|
68
|
+
if (entry->live) {
|
|
69
|
+
entry->call(value);
|
|
70
|
+
called++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return called;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
struct Entry {
|
|
78
|
+
std::recursive_mutex calling;
|
|
79
|
+
bool live{true};
|
|
80
|
+
Listener call;
|
|
81
|
+
};
|
|
82
|
+
// Shared with each handle, which may outlive these listeners.
|
|
83
|
+
struct State {
|
|
84
|
+
std::mutex mutex;
|
|
85
|
+
std::map<int, std::shared_ptr<Entry>> entries;
|
|
86
|
+
int next{0};
|
|
87
|
+
};
|
|
88
|
+
std::shared_ptr<State> state_ = std::make_shared<State>();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// A value with listeners. Setting it to what it already is notifies nobody. Listeners hear the
|
|
92
|
+
// values in the order they were set, a value set by a listener after the one it is hearing, and
|
|
93
|
+
// a set made while another thread is notifying returns at once, that thread notifying for it.
|
|
94
|
+
// A listener given the current value hears only the values set after it.
|
|
95
|
+
template <typename T>
|
|
96
|
+
class Watched {
|
|
97
|
+
public:
|
|
98
|
+
using Listener = std::function<void(const T &)>;
|
|
99
|
+
|
|
100
|
+
explicit Watched(T value = T{}) : value_(std::move(value)) {}
|
|
101
|
+
|
|
102
|
+
T get() const {
|
|
103
|
+
std::lock_guard lock(mutex_);
|
|
104
|
+
return value_;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void set(T value) {
|
|
108
|
+
{
|
|
109
|
+
std::lock_guard lock(mutex_);
|
|
110
|
+
if (value_ == value) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
value_ = value;
|
|
114
|
+
queued_.push_back({++serial_, std::move(value)});
|
|
115
|
+
if (notifying_) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
notifying_ = true;
|
|
119
|
+
}
|
|
120
|
+
notifyQueued();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Listens until the returned handle is destroyed.
|
|
124
|
+
std::shared_ptr<void> listen(Listener listener) {
|
|
125
|
+
return listeners_.add([listener = std::move(listener)](const Set &set) { listener(set.value); });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Listens, with `current` set to the value the listener's first call follows: a change made
|
|
129
|
+
// between reading the value and listening is heard, and one set before it and still queued is
|
|
130
|
+
// not.
|
|
131
|
+
std::shared_ptr<void> listen(Listener listener, T ¤t) {
|
|
132
|
+
std::lock_guard lock(mutex_);
|
|
133
|
+
current = value_;
|
|
134
|
+
return listeners_.add([listener = std::move(listener), after = serial_](const Set &set) {
|
|
135
|
+
if (set.serial > after) {
|
|
136
|
+
listener(set.value);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private:
|
|
142
|
+
struct Set {
|
|
143
|
+
uint64_t serial;
|
|
144
|
+
T value;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
void notifyQueued() {
|
|
148
|
+
for (;;) {
|
|
149
|
+
std::optional<Set> next;
|
|
150
|
+
{
|
|
151
|
+
std::lock_guard lock(mutex_);
|
|
152
|
+
if (queued_.empty()) {
|
|
153
|
+
notifying_ = false;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
next = std::move(queued_.front());
|
|
157
|
+
queued_.pop_front();
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
listeners_.notify(*next);
|
|
161
|
+
} catch (...) {
|
|
162
|
+
std::lock_guard lock(mutex_);
|
|
163
|
+
queued_.clear();
|
|
164
|
+
notifying_ = false;
|
|
165
|
+
throw;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
mutable std::mutex mutex_;
|
|
171
|
+
T value_;
|
|
172
|
+
// Set, and not yet sent to the listeners.
|
|
173
|
+
std::deque<Set> queued_;
|
|
174
|
+
// The number of the last set.
|
|
175
|
+
uint64_t serial_{0};
|
|
176
|
+
bool notifying_{false};
|
|
177
|
+
Listeners<Set> listeners_;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
enum class Activity { Active, Inactive, Background };
|
|
181
|
+
|
|
182
|
+
struct Dimensions {
|
|
183
|
+
double width{0};
|
|
184
|
+
double height{0};
|
|
185
|
+
double scale{1};
|
|
186
|
+
double fontScale{1};
|
|
187
|
+
bool operator==(const Dimensions &) const = default;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// The system's accessibility settings that apps adapt to, as React Native's AccessibilityInfo
|
|
191
|
+
// names them. A desktop without one of them reports it off.
|
|
192
|
+
struct AccessibilitySettings {
|
|
193
|
+
// A screen reader is running (VoiceOver on macOS).
|
|
194
|
+
bool screenReader{false};
|
|
195
|
+
bool reduceMotion{false};
|
|
196
|
+
bool reduceTransparency{false};
|
|
197
|
+
bool invertColors{false};
|
|
198
|
+
bool boldText{false};
|
|
199
|
+
// Increase contrast, which iOS calls darker system colours.
|
|
200
|
+
bool increaseContrast{false};
|
|
201
|
+
bool grayscale{false};
|
|
202
|
+
bool operator==(const AccessibilitySettings &) const = default;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
struct WindowMetrics {
|
|
206
|
+
Dimensions window;
|
|
207
|
+
Dimensions screen;
|
|
208
|
+
bool operator==(const WindowMetrics &) const = default;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
class HostState {
|
|
212
|
+
public:
|
|
213
|
+
Watched<Activity> activity{Activity::Active};
|
|
214
|
+
Watched<WindowMetrics> metrics;
|
|
215
|
+
// "light" or "dark".
|
|
216
|
+
Watched<std::string> colorScheme{"light"};
|
|
217
|
+
// Set by the backend from the system's notifications, never by polling.
|
|
218
|
+
Watched<AccessibilitySettings> accessibility;
|
|
219
|
+
// The clipboard's change count (System::clipboardChangeCount), as the backend last checked it.
|
|
220
|
+
// There is no change notification: the backend checks when the app becomes active and after
|
|
221
|
+
// each key press, click and menu command, so an idle app never wakes to poll.
|
|
222
|
+
Watched<int64_t> clipboardChangeCount{0};
|
|
223
|
+
|
|
224
|
+
// The URL the app was launched to open, if any.
|
|
225
|
+
void setInitialUrl(std::string url);
|
|
226
|
+
std::optional<std::string> initialUrl() const;
|
|
227
|
+
// A URL the app was asked to open while running. Each one is delivered once: to the listeners
|
|
228
|
+
// there are, or, when there are none yet, to the first listener when it starts listening.
|
|
229
|
+
void openUrl(const std::string &url);
|
|
230
|
+
// A URL from the OS: a link to the app's scheme, or a file from Open With or a drop on the Dock
|
|
231
|
+
// icon. Before the app has finished launching the first is the initial URL and the rest wait
|
|
232
|
+
// for a listener; once it has, each is an event.
|
|
233
|
+
void receiveUrl(std::string url, bool launched);
|
|
234
|
+
std::shared_ptr<void> listenForUrls(std::function<void(const std::string &)> listener);
|
|
235
|
+
|
|
236
|
+
private:
|
|
237
|
+
mutable std::mutex mutex_;
|
|
238
|
+
std::optional<std::string> initialUrl_;
|
|
239
|
+
std::vector<std::string> pendingUrls_;
|
|
240
|
+
Listeners<std::string> urlListeners_;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
} // namespace ngn
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// NgNativeImageManipulator: what @ng-native/expo's ImageEditor calls on expo-image-manipulator,
|
|
2
|
+
// over an ImageCodec, which the AppKit backend implements with ImageIO and Core Graphics. A
|
|
3
|
+
// TurboModule cannot hand back expo's context and image objects, so the desktop loader keeps a
|
|
4
|
+
// context's actions in JavaScript and sends them whole:
|
|
5
|
+
//
|
|
6
|
+
// - renderAsync(uri, actions, loadOptions): {width, height}, the size the actions give, read from
|
|
7
|
+
// the file's header without decoding it.
|
|
8
|
+
// - saveAsync(uri, actions, loadOptions, saveOptions): expo's ImageResult, {uri, width, height,
|
|
9
|
+
// base64?}, the edited image written to a new file in `<caches>/ImageManipulator`.
|
|
10
|
+
//
|
|
11
|
+
// `uri` is a `file:` uri, an absolute path, a `data:` uri or an `http(s):` url (an asset on the
|
|
12
|
+
// dev server), all read through the backend's HTTP client. A file is read only where `files` lets
|
|
13
|
+
// it (FileAccess::readFor), so a copy in `<caches>` never holds what FileSystem could not read. `actions` are expo's: `resize`,
|
|
14
|
+
// `rotate` (degrees, clockwise), `flip` and `crop`, applied in order to the image the right way
|
|
15
|
+
// up, sized and checked as expo's iOS module does. `loadOptions` is `{maxWidth, maxHeight}`, which
|
|
16
|
+
// scales a larger image down to fit first. `saveOptions` is `{format: jpeg | png | webp, compress
|
|
17
|
+
// (0 to 1, JPEG only), base64}`; a format ImageIO cannot write here (WebP) refuses the save.
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include "ngn/native-module.h"
|
|
21
|
+
#include "ngn/file-system.h"
|
|
22
|
+
#include "ngn/network.h"
|
|
23
|
+
|
|
24
|
+
#include <memory>
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include <string>
|
|
27
|
+
#include <vector>
|
|
28
|
+
|
|
29
|
+
namespace ngn {
|
|
30
|
+
|
|
31
|
+
struct ImageSize {
|
|
32
|
+
int width{0};
|
|
33
|
+
int height{0};
|
|
34
|
+
bool operator==(const ImageSize &) const = default;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// One edit, with the size of the image it gives.
|
|
38
|
+
struct ImageStep {
|
|
39
|
+
enum class Kind { Resize, Rotate, FlipHorizontal, FlipVertical, Crop };
|
|
40
|
+
Kind kind{Kind::Resize};
|
|
41
|
+
ImageSize size;
|
|
42
|
+
// Rotate: clockwise.
|
|
43
|
+
double degrees{0};
|
|
44
|
+
// Crop: the rectangle's origin in pixels from the top left; its size is `size`.
|
|
45
|
+
int x{0};
|
|
46
|
+
int y{0};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// The steps `actions` make of an upright image of `source` size, `loadOptions` first. Throws
|
|
50
|
+
// std::invalid_argument with the reason for an action that cannot apply.
|
|
51
|
+
std::vector<ImageStep> planImageEdits(ImageSize source, const folly::dynamic &actions, const folly::dynamic &loadOptions);
|
|
52
|
+
|
|
53
|
+
class ImageCodec {
|
|
54
|
+
public:
|
|
55
|
+
virtual ~ImageCodec() = default;
|
|
56
|
+
// The size of the encoded image the right way up, by its orientation, or nothing for bytes that
|
|
57
|
+
// are not an image.
|
|
58
|
+
virtual std::optional<ImageSize> size(const std::string &bytes) = 0;
|
|
59
|
+
// Whether it can encode `format`: jpeg, png or webp.
|
|
60
|
+
virtual bool encodes(const std::string &format) = 0;
|
|
61
|
+
// Decodes the image the right way up, applies `steps` and encodes the result as `format` at
|
|
62
|
+
// `quality` (0 to 1, for a lossy format). Throws std::runtime_error with the reason it cannot.
|
|
63
|
+
virtual std::string render(const std::string &bytes, const std::vector<ImageStep> &steps, const std::string &format, double quality) = 0;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// `folder` is where saved images go: `<caches>/ImageManipulator`.
|
|
67
|
+
std::shared_ptr<NativeModule> makeImageManipulatorModule(
|
|
68
|
+
std::shared_ptr<ImageCodec> codec, std::shared_ptr<Http> http, std::string folder, std::shared_ptr<FileAccess> files);
|
|
69
|
+
|
|
70
|
+
} // namespace ngn
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// The core's InputSink: hit tests each pointer event against the ViewTree from the container's
|
|
2
|
+
// root, turns a press into Fabric touches on the deepest view, and sends the desktop's mouse
|
|
3
|
+
// events. UI thread only, like the tree it reads.
|
|
4
|
+
//
|
|
5
|
+
// The contract with the engine (packages/integration-tests/mouse-events.test.ts):
|
|
6
|
+
//
|
|
7
|
+
// - Every move goes to the deepest view under the pointer as a pointer move, and a pointer leave
|
|
8
|
+
// follows the pointer out of the surface, as React Native iOS sends them. React Native's
|
|
9
|
+
// PointerEventsProcessor turns those into over, out, enter and leave for the views that listen,
|
|
10
|
+
// and passes the move on only when a view in the path listens for it.
|
|
11
|
+
// - Double click, context menu and wheel are the element events `doubleClick`, `contextMenu` and
|
|
12
|
+
// `wheel`, sent to the deepest view when it or an ancestor opts in through its desktop props
|
|
13
|
+
// (desktop-view-props.h). The engine bubbles them up from there.
|
|
14
|
+
//
|
|
15
|
+
// - A drag of files, text or urls goes to the nearest view under it whose `fileDrop` prop is true,
|
|
16
|
+
// as `dropEnter` when it comes over that view, `dropLeave` when it goes off it without dropping
|
|
17
|
+
// and `dropPerform` on a drop, which ends the drag without a leave. Enter and perform carry
|
|
18
|
+
// `{ files: [{ uri, name }], text, urls }` (packages/integration-tests/drag-and-drop.test.ts).
|
|
19
|
+
// - A press that moves past the drag threshold on a view whose nearest ancestor-or-self with a
|
|
20
|
+
// `dragItem` prop offers something is cancelled (touch cancel), and `onDragOut` starts the drag
|
|
21
|
+
// session; the rest of the gesture belongs to it.
|
|
22
|
+
//
|
|
23
|
+
// It also decides the cursor: the nearest view under the pointer that names one, `text` over a
|
|
24
|
+
// text input, and the default otherwise.
|
|
25
|
+
#pragma once
|
|
26
|
+
|
|
27
|
+
#include "ngn/default-menu.h"
|
|
28
|
+
#include "ngn/desktop-view-props.h"
|
|
29
|
+
#include "ngn/file-system.h"
|
|
30
|
+
#include "ngn/input.h"
|
|
31
|
+
#include "ngn/view-tree.h"
|
|
32
|
+
|
|
33
|
+
#include <react/renderer/components/view/PointerEvent.h>
|
|
34
|
+
#include <react/renderer/components/view/TouchEvent.h>
|
|
35
|
+
#include <react/renderer/components/view/primitives.h>
|
|
36
|
+
|
|
37
|
+
#include <folly/dynamic.h>
|
|
38
|
+
|
|
39
|
+
#include <functional>
|
|
40
|
+
#include <memory>
|
|
41
|
+
#include <map>
|
|
42
|
+
#include <optional>
|
|
43
|
+
#include <string>
|
|
44
|
+
#include <vector>
|
|
45
|
+
|
|
46
|
+
namespace ngn {
|
|
47
|
+
|
|
48
|
+
class Gestures;
|
|
49
|
+
struct GesturePointer;
|
|
50
|
+
|
|
51
|
+
enum class TouchPhase { Start, Move, End, Cancel };
|
|
52
|
+
enum class PointerKind { Enter, Leave, Move, Over, Out };
|
|
53
|
+
|
|
54
|
+
using facebook::react::Cursor;
|
|
55
|
+
|
|
56
|
+
// The cursor the views under the pointer ask for, `chain` running from the container's root to
|
|
57
|
+
// the deepest. `Cursor::Auto` when none does: the toolkit's default.
|
|
58
|
+
Cursor cursorFor(const ViewTree &tree, const std::vector<Tag> &chain);
|
|
59
|
+
|
|
60
|
+
// What a `[dragItem]` view offers when dragged out: `file://` urls, text and a url. `uses` holds
|
|
61
|
+
// open the picks its files read (FileAccess::Use) until whatever takes the item lets it go, once
|
|
62
|
+
// the drag has handed the files on.
|
|
63
|
+
struct DragOutItem {
|
|
64
|
+
std::vector<std::string> files;
|
|
65
|
+
std::optional<std::string> text;
|
|
66
|
+
std::optional<std::string> url;
|
|
67
|
+
std::vector<std::shared_ptr<FileAccess::Use>> uses;
|
|
68
|
+
bool operator==(const DragOutItem &other) const {
|
|
69
|
+
return files == other.files && text == other.text && url == other.url;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// The item of a `dragItem` prop, or nothing when it is null or offers nothing. A file (in `files`,
|
|
74
|
+
// or a file `url`) is offered only inside the file boundary `files` draws (readableSource), as the
|
|
75
|
+
// file uri checked; the dispatcher uses the views' (viewFileAccess).
|
|
76
|
+
std::optional<DragOutItem> dragItemOf(const folly::dynamic &prop, const FileAccess *files);
|
|
77
|
+
|
|
78
|
+
// How far a press moves before it becomes a drag, in points (AppKit's own threshold).
|
|
79
|
+
constexpr float kDragThreshold = 4;
|
|
80
|
+
|
|
81
|
+
class InputDispatcher : public InputSink {
|
|
82
|
+
public:
|
|
83
|
+
explicit InputDispatcher(const ViewTree &tree);
|
|
84
|
+
|
|
85
|
+
void addContainer(ContainerId container, SurfaceId surfaceId, Tag rootTag) override;
|
|
86
|
+
void removeContainer(ContainerId container) override;
|
|
87
|
+
void pointerDown(const PointerInput &input) override;
|
|
88
|
+
void pointerMove(const PointerInput &input) override;
|
|
89
|
+
void pointerUp(const PointerInput &input) override;
|
|
90
|
+
void pointerLeave(SurfaceId surfaceId, const PointerInput &input) override;
|
|
91
|
+
bool contextMenu(const PointerInput &input) override;
|
|
92
|
+
WheelResult wheel(const PointerInput &input, const WheelDelta &delta) override;
|
|
93
|
+
bool dragOver(const PointerInput &input, const DragItems &items) override;
|
|
94
|
+
void dragExit(ContainerId container) override;
|
|
95
|
+
bool drop(const PointerInput &input, const DragItems &items) override;
|
|
96
|
+
void magnify(const PointerInput &input, double magnification, GesturePhase phase) override;
|
|
97
|
+
void rotate(const PointerInput &input, double degrees, GesturePhase phase) override;
|
|
98
|
+
|
|
99
|
+
// The gesture handler's recognisers (gestures.h), which see every press, move, hover, scroll and
|
|
100
|
+
// trackpad gesture before JavaScript's touches do. One that activates cancels the press
|
|
101
|
+
// JavaScript was told of. Null for none.
|
|
102
|
+
void setGestures(Gestures *gestures);
|
|
103
|
+
|
|
104
|
+
// The context menu a secondary click at `input` shows: the nearest view under it with a
|
|
105
|
+
// `contextMenu` prop, and its entries. Nothing when no view there has one.
|
|
106
|
+
struct ContextMenuTarget {
|
|
107
|
+
Tag tag;
|
|
108
|
+
std::vector<MenuItem> items;
|
|
109
|
+
};
|
|
110
|
+
std::optional<ContextMenuTarget> contextMenuAt(const PointerInput &input) const;
|
|
111
|
+
// An item of the context menu of `tag` was chosen: `topContextMenuSelect` with its id.
|
|
112
|
+
void contextMenuSelect(Tag tag, const std::string &id);
|
|
113
|
+
|
|
114
|
+
// VoiceOver's press, or Space on a focused view, for a view with no handler of its own: a press
|
|
115
|
+
// and release at the view's centre, sent to the view itself as iOS's synthesized tap is, through
|
|
116
|
+
// the container of `surfaceId` nearest to it. False when no container holds it or a press is
|
|
117
|
+
// already down.
|
|
118
|
+
bool activate(SurfaceId surfaceId, Tag tag);
|
|
119
|
+
|
|
120
|
+
// After a transaction: the views under a still pointer may have changed what cursor they ask
|
|
121
|
+
// for.
|
|
122
|
+
void didMount(SurfaceId surfaceId);
|
|
123
|
+
|
|
124
|
+
// The hovered views of a surface, outermost first.
|
|
125
|
+
const std::vector<Tag> &hovered(SurfaceId surfaceId) const;
|
|
126
|
+
|
|
127
|
+
// Told each time the cursor should change.
|
|
128
|
+
std::function<void(Cursor)> onCursor;
|
|
129
|
+
// Told when a press becomes a drag out of `tag`, at `input` (the move that crossed the
|
|
130
|
+
// threshold): the backend starts the drag session with the item.
|
|
131
|
+
std::function<void(Tag tag, const PointerInput &input, const DragOutItem &item)> onDragOut;
|
|
132
|
+
|
|
133
|
+
protected:
|
|
134
|
+
// Where events leave the core. The defaults send them through the view's event emitter; tests
|
|
135
|
+
// record them instead.
|
|
136
|
+
virtual void emitTouch(TouchPhase phase, const ViewTree::Node &target, const facebook::react::TouchEvent &event);
|
|
137
|
+
virtual void emitPointer(PointerKind kind, const ViewTree::Node &node, const facebook::react::PointerEvent &event);
|
|
138
|
+
// `name` without React Native's `top` prefix: `doubleClick`, `contextMenu`, `contextMenuSelect`,
|
|
139
|
+
// `wheel`, `dropEnter`, `dropLeave` or `dropPerform`.
|
|
140
|
+
virtual void emitElementEvent(const ViewTree::Node &node, const std::string &name, folly::dynamic payload);
|
|
141
|
+
|
|
142
|
+
private:
|
|
143
|
+
struct Container {
|
|
144
|
+
SurfaceId surfaceId;
|
|
145
|
+
Tag root;
|
|
146
|
+
};
|
|
147
|
+
struct Press {
|
|
148
|
+
ContainerId container;
|
|
149
|
+
Tag target;
|
|
150
|
+
int clickCount;
|
|
151
|
+
Point start;
|
|
152
|
+
};
|
|
153
|
+
// Whether a drag out starts from this move of the press; true when it did.
|
|
154
|
+
bool startDragOut(const PointerInput &input);
|
|
155
|
+
|
|
156
|
+
void updateHover(const Container &container, std::vector<Tag> chain, const PointerInput &input);
|
|
157
|
+
void sendTouch(TouchPhase phase, const PointerInput &input);
|
|
158
|
+
// Sends an element event to the deepest view of `chain` when it or an ancestor opted in.
|
|
159
|
+
bool sendElementEvent(
|
|
160
|
+
const Container &container,
|
|
161
|
+
const std::vector<Tag> &chain,
|
|
162
|
+
bool DesktopProps::*optIn,
|
|
163
|
+
const std::string &name,
|
|
164
|
+
folly::dynamic payload);
|
|
165
|
+
folly::dynamic locationPayload(const Container &container, Tag target, Point point) const;
|
|
166
|
+
// Where a container's root sits in its surface: page coordinates are the surface's.
|
|
167
|
+
// `point` (in `root`'s coordinates) in `tag`'s own, through any transforms between them; by its
|
|
168
|
+
// layout origin when a transform flattens it.
|
|
169
|
+
Point localPoint(Tag tag, Tag root, Point point) const;
|
|
170
|
+
Point pageOrigin(const Container &container) const;
|
|
171
|
+
facebook::react::PointerEvent pointerEvent(const PointerInput &input, Point pageOrigin) const;
|
|
172
|
+
void setCursor(Cursor cursor);
|
|
173
|
+
// The nearest view under `input` that takes drops.
|
|
174
|
+
std::optional<Tag> dropTargetAt(const PointerInput &input) const;
|
|
175
|
+
void leaveDropTarget();
|
|
176
|
+
|
|
177
|
+
// The surface's coordinates of a point in a container, and the gesture pointer for it.
|
|
178
|
+
GesturePointer gesturePointer(const Container &container, const PointerInput &input) const;
|
|
179
|
+
// A gesture took the press: JavaScript's touch is cancelled.
|
|
180
|
+
void claimPress();
|
|
181
|
+
// The gestures lose the press (a drag out took it, or its container went): its handlers are
|
|
182
|
+
// cancelled and see no more of it.
|
|
183
|
+
void cancelGesturePress();
|
|
184
|
+
|
|
185
|
+
const ViewTree &tree_;
|
|
186
|
+
Gestures *gestures_{nullptr};
|
|
187
|
+
std::optional<PointerInput> lastInput_;
|
|
188
|
+
// The container of the press the gestures saw, which they keep after one of them takes it from
|
|
189
|
+
// JavaScript, and its button as the gestures name it (0 primary, 1 middle, 2 secondary).
|
|
190
|
+
std::optional<ContainerId> gesturePress_;
|
|
191
|
+
int gestureButton_{0};
|
|
192
|
+
std::map<ContainerId, Container> containers_;
|
|
193
|
+
std::map<SurfaceId, std::vector<Tag>> hovered_;
|
|
194
|
+
std::optional<Press> press_;
|
|
195
|
+
// A drag out has the rest of the gesture, up to the release.
|
|
196
|
+
bool draggingOut_{false};
|
|
197
|
+
// The surface the pointer is over, if any, and the cursor last asked for.
|
|
198
|
+
std::optional<SurfaceId> pointerSurface_;
|
|
199
|
+
std::optional<Cursor> cursor_;
|
|
200
|
+
// The view a drag is over, and the container it came through.
|
|
201
|
+
struct DropTarget {
|
|
202
|
+
ContainerId container;
|
|
203
|
+
Tag tag;
|
|
204
|
+
};
|
|
205
|
+
std::optional<DropTarget> dropTarget_;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// A drag's items as the drop events carry them: `{ files: [{ uri, name }], text, urls }`.
|
|
209
|
+
folly::dynamic dropPayload(const DragItems &items);
|
|
210
|
+
|
|
211
|
+
} // namespace ngn
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// A script of input for a dev run to replay into its own window (NGN_INPUT_SCRIPT): what drives the
|
|
2
|
+
// host's screens with real toolkit events when no accessibility grant lets anything else post them.
|
|
3
|
+
// One step a line, `#` starts a comment, and points are in the window's content, top-left origin:
|
|
4
|
+
//
|
|
5
|
+
// wait <ms>
|
|
6
|
+
// move <x> <y> the pointer, no button down
|
|
7
|
+
// down <x> <y> the primary button
|
|
8
|
+
// drag <x> <y>
|
|
9
|
+
// up <x> <y>
|
|
10
|
+
// secondary <x> <y> a secondary click (the right button down and up): a context menu
|
|
11
|
+
// scroll <x> <y> <dx> <dy> [began|changed|ended] a trackpad scroll by the fingers' movement
|
|
12
|
+
// magnify <x> <y> <amount> began|changed|ended
|
|
13
|
+
// rotate <x> <y> <degrees> began|changed|ended anticlockwise
|
|
14
|
+
// key <key> [cmd] [shift] [option] [ctrl] to the key window, whichever it is (the
|
|
15
|
+
// script's own when none is): a character, escape, return, space, tab or
|
|
16
|
+
// delete; a character (or a space) with no command or control modifier is
|
|
17
|
+
// typed into a focused field
|
|
18
|
+
// type <text> the rest of the line, inner spaces and all, typed a character at a time
|
|
19
|
+
// into the focused field, as the keyboard would (no `#`, which starts a
|
|
20
|
+
// comment)
|
|
21
|
+
// choose <title> the next menu to open (a pop-up button's, a picker's, a context menu)
|
|
22
|
+
// picks its item with this title a second after it opens, as a click on
|
|
23
|
+
// the item does: a menu tracks the real pointer, which nothing replayed moves
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include "ngn/input.h"
|
|
27
|
+
|
|
28
|
+
#include <optional>
|
|
29
|
+
#include <string>
|
|
30
|
+
#include <vector>
|
|
31
|
+
|
|
32
|
+
namespace ngn {
|
|
33
|
+
|
|
34
|
+
struct InputStep {
|
|
35
|
+
enum class Kind { Wait, Move, Down, Drag, Up, Secondary, Scroll, Magnify, Rotate, Key, Type, Choose } kind;
|
|
36
|
+
enum Modifier : unsigned { Command = 1 << 0, Shift = 1 << 1, Option = 1 << 2, Control = 1 << 3 };
|
|
37
|
+
double x{0};
|
|
38
|
+
double y{0};
|
|
39
|
+
// The wait's milliseconds, a scroll's dx, a magnification or a rotation.
|
|
40
|
+
double amount{0};
|
|
41
|
+
double dy{0};
|
|
42
|
+
std::optional<GesturePhase> phase;
|
|
43
|
+
// A key step's key and modifiers, a type step's text, or a choose step's title.
|
|
44
|
+
std::string key;
|
|
45
|
+
unsigned modifiers{0};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// The steps, or the first bad line's number and why.
|
|
49
|
+
struct InputScript {
|
|
50
|
+
std::vector<InputStep> steps;
|
|
51
|
+
std::optional<std::string> error;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
InputScript parseInputScript(const std::string &text);
|
|
55
|
+
|
|
56
|
+
} // namespace ngn
|