@ng-native/desktop 0.0.0 → 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 +52 -0
- 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 +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
#include "ngn/input-dispatcher.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/gestures.h"
|
|
4
|
+
|
|
5
|
+
#include "ngn/app-menus.h"
|
|
6
|
+
#include "ngn/file-system.h"
|
|
7
|
+
|
|
8
|
+
#include <react/renderer/components/view/TouchEventEmitter.h>
|
|
9
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
namespace ngn {
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
std::shared_ptr<const TouchEventEmitter> touchEmitter(const ViewTree::Node &node) {
|
|
18
|
+
return std::dynamic_pointer_cast<const TouchEventEmitter>(node.view.eventEmitter);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace
|
|
22
|
+
|
|
23
|
+
Cursor cursorFor(const ViewTree &tree, const std::vector<Tag> &chain) {
|
|
24
|
+
for (size_t i = chain.size(); i-- > 0;) {
|
|
25
|
+
const auto *node = tree.find(chain[i]);
|
|
26
|
+
if (node == nullptr || !node->view.props) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (auto cursor = desktopProps(*node->view.props).cursor) {
|
|
30
|
+
return *cursor;
|
|
31
|
+
}
|
|
32
|
+
auto props = std::dynamic_pointer_cast<const ViewProps>(node->view.props);
|
|
33
|
+
if (props && props->cursor != Cursor::Auto) {
|
|
34
|
+
return props->cursor;
|
|
35
|
+
}
|
|
36
|
+
if (std::string_view(node->view.componentName) == "TextInput") {
|
|
37
|
+
return Cursor::Text;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Cursor::Auto;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
InputDispatcher::InputDispatcher(const ViewTree &tree) : tree_(tree) {}
|
|
44
|
+
|
|
45
|
+
void InputDispatcher::addContainer(ContainerId container, SurfaceId surfaceId, Tag rootTag) {
|
|
46
|
+
containers_[container] = {surfaceId, rootTag};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void InputDispatcher::removeContainer(ContainerId container) {
|
|
50
|
+
// Cancelled while the container is still there to say where the press was.
|
|
51
|
+
if (press_ && press_->container == container) {
|
|
52
|
+
PointerInput at;
|
|
53
|
+
at.container = container;
|
|
54
|
+
at.point = press_->start;
|
|
55
|
+
sendTouch(TouchPhase::Cancel, lastInput_ && containers_.contains(lastInput_->container) ? *lastInput_ : at);
|
|
56
|
+
press_.reset();
|
|
57
|
+
}
|
|
58
|
+
if (gesturePress_ == container) {
|
|
59
|
+
cancelGesturePress();
|
|
60
|
+
}
|
|
61
|
+
containers_.erase(container);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const std::vector<Tag> &InputDispatcher::hovered(SurfaceId surfaceId) const {
|
|
65
|
+
static const std::vector<Tag> none;
|
|
66
|
+
auto it = hovered_.find(surfaceId);
|
|
67
|
+
return it == hovered_.end() ? none : it->second;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void InputDispatcher::pointerDown(const PointerInput &input) {
|
|
71
|
+
auto container = containers_.find(input.container);
|
|
72
|
+
if (container == containers_.end()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
auto chain = tree_.hitTest(container->second.root, input.point);
|
|
76
|
+
updateHover(container->second, chain, input);
|
|
77
|
+
if (chain.empty()) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
draggingOut_ = false;
|
|
81
|
+
press_ = Press{input.container, chain.back(), input.clickCount, input.point};
|
|
82
|
+
lastInput_ = input;
|
|
83
|
+
sendTouch(TouchPhase::Start, input);
|
|
84
|
+
if (gestures_) {
|
|
85
|
+
gesturePress_ = input.container;
|
|
86
|
+
// The DOM's `buttons` bits (1 primary, 2 secondary, 4 middle) as the button pressed.
|
|
87
|
+
gestureButton_ = input.buttons & 1 ? 0 : input.buttons & 2 ? 2 : input.buttons & 4 ? 1 : 0;
|
|
88
|
+
gestures_->pointerDown(container->second.surfaceId, chain, gesturePointer(container->second, input));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void InputDispatcher::pointerMove(const PointerInput &input) {
|
|
93
|
+
auto container = containers_.find(input.container);
|
|
94
|
+
if (container == containers_.end()) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (draggingOut_) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
auto chain = tree_.hitTest(container->second.root, input.point);
|
|
101
|
+
updateHover(container->second, chain, input);
|
|
102
|
+
if (press_) {
|
|
103
|
+
// A drag out has the move, and the rest of the press.
|
|
104
|
+
if (startDragOut(input)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
lastInput_ = input;
|
|
108
|
+
sendTouch(TouchPhase::Move, input);
|
|
109
|
+
}
|
|
110
|
+
if (gestures_) {
|
|
111
|
+
// A press's moves go to the handlers it began on wherever it goes; the pointer's others hover.
|
|
112
|
+
auto pointer = gesturePointer(container->second, input);
|
|
113
|
+
if (gesturePress_) {
|
|
114
|
+
gestures_->pointerMove(pointer);
|
|
115
|
+
} else {
|
|
116
|
+
gestures_->hover(container->second.surfaceId, chain, pointer);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
bool InputDispatcher::startDragOut(const PointerInput &input) {
|
|
122
|
+
if (input.container != press_->container) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
float dx = input.point.x - press_->start.x;
|
|
126
|
+
float dy = input.point.y - press_->start.y;
|
|
127
|
+
if (dx * dx + dy * dy < kDragThreshold * kDragThreshold) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
auto container = containers_.find(press_->container);
|
|
131
|
+
if (container == containers_.end()) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
auto chain = tree_.chain(press_->target, container->second.root);
|
|
135
|
+
for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
|
|
136
|
+
const auto *node = tree_.find(*it);
|
|
137
|
+
if (node == nullptr || !node->view.props) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
auto item = dragItemOf(desktopProps(*node->view.props).dragItem, viewFileAccess().get());
|
|
141
|
+
if (!item) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
sendTouch(TouchPhase::Cancel, input);
|
|
145
|
+
press_.reset();
|
|
146
|
+
cancelGesturePress();
|
|
147
|
+
draggingOut_ = true;
|
|
148
|
+
if (onDragOut) {
|
|
149
|
+
onDragOut(*it, input, *item);
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
void InputDispatcher::pointerUp(const PointerInput &input) {
|
|
157
|
+
draggingOut_ = false;
|
|
158
|
+
if (gestures_ && gesturePress_) {
|
|
159
|
+
gesturePress_.reset();
|
|
160
|
+
auto container = containers_.find(input.container);
|
|
161
|
+
if (container != containers_.end()) {
|
|
162
|
+
gestures_->pointerUp(gesturePointer(container->second, input));
|
|
163
|
+
}
|
|
164
|
+
gestureButton_ = 0;
|
|
165
|
+
}
|
|
166
|
+
if (!press_) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
sendTouch(TouchPhase::End, input);
|
|
170
|
+
auto press = *press_;
|
|
171
|
+
press_.reset();
|
|
172
|
+
// The DOM's dblclick comes as the second click of a run ends, on the view it pressed.
|
|
173
|
+
auto container = containers_.find(press.container);
|
|
174
|
+
if (press.clickCount == 2 && container != containers_.end() && tree_.find(press.target) != nullptr) {
|
|
175
|
+
// The release may be over another container (a popover): its point, in the pressed one's.
|
|
176
|
+
auto point = input.point;
|
|
177
|
+
auto over = containers_.find(input.container);
|
|
178
|
+
if (over != containers_.end() && over != container) {
|
|
179
|
+
auto from = pageOrigin(over->second);
|
|
180
|
+
auto to = pageOrigin(container->second);
|
|
181
|
+
point = {point.x + from.x - to.x, point.y + from.y - to.y};
|
|
182
|
+
}
|
|
183
|
+
auto chain = tree_.chain(press.target, container->second.root);
|
|
184
|
+
sendElementEvent(
|
|
185
|
+
container->second, chain, &DesktopProps::onDoubleClick, "doubleClick", locationPayload(container->second, press.target, point));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
bool InputDispatcher::activate(SurfaceId surfaceId, Tag tag) {
|
|
190
|
+
const auto *node = tree_.find(tag);
|
|
191
|
+
if (press_ || node == nullptr) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
// The container whose root is nearest above the view: a popover's, not the window's.
|
|
195
|
+
std::optional<ContainerId> holder;
|
|
196
|
+
size_t nearest = 0;
|
|
197
|
+
for (const auto &[id, container] : containers_) {
|
|
198
|
+
if (container.surfaceId != surfaceId) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
auto chain = tree_.chain(tag, container.root);
|
|
202
|
+
if (!chain.empty() && (!holder || chain.size() < nearest)) {
|
|
203
|
+
holder = id;
|
|
204
|
+
nearest = chain.size();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (!holder) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
auto origin = tree_.originIn(tag, containers_[*holder].root).value_or(Point{0, 0});
|
|
211
|
+
const auto &size = node->view.layoutMetrics.frame.size;
|
|
212
|
+
PointerInput input;
|
|
213
|
+
input.container = *holder;
|
|
214
|
+
input.point = {origin.x + size.width / 2, origin.y + size.height / 2};
|
|
215
|
+
input.clickCount = 1;
|
|
216
|
+
press_ = Press{*holder, tag, 1, input.point};
|
|
217
|
+
sendTouch(TouchPhase::Start, input);
|
|
218
|
+
sendTouch(TouchPhase::End, input);
|
|
219
|
+
press_.reset();
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
void InputDispatcher::pointerLeave(SurfaceId surfaceId, const PointerInput &input) {
|
|
224
|
+
updateHover({surfaceId, surfaceId}, {}, input);
|
|
225
|
+
if (gestures_) {
|
|
226
|
+
gestures_->hover(surfaceId, {}, gesturePointer({surfaceId, surfaceId}, input));
|
|
227
|
+
}
|
|
228
|
+
if (pointerSurface_ == surfaceId) {
|
|
229
|
+
pointerSurface_.reset();
|
|
230
|
+
setCursor(Cursor::Auto);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
bool InputDispatcher::contextMenu(const PointerInput &input) {
|
|
235
|
+
auto container = containers_.find(input.container);
|
|
236
|
+
if (container == containers_.end()) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
auto chain = tree_.hitTest(container->second.root, input.point);
|
|
240
|
+
if (chain.empty()) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
return sendElementEvent(
|
|
244
|
+
container->second,
|
|
245
|
+
chain,
|
|
246
|
+
&DesktopProps::onContextMenu,
|
|
247
|
+
"contextMenu",
|
|
248
|
+
locationPayload(container->second, chain.back(), input.point));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
std::optional<InputDispatcher::ContextMenuTarget> InputDispatcher::contextMenuAt(const PointerInput &input) const {
|
|
252
|
+
auto container = containers_.find(input.container);
|
|
253
|
+
if (container == containers_.end()) {
|
|
254
|
+
return std::nullopt;
|
|
255
|
+
}
|
|
256
|
+
auto chain = tree_.hitTest(container->second.root, input.point);
|
|
257
|
+
for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
|
|
258
|
+
const auto *node = tree_.find(*it);
|
|
259
|
+
if (node == nullptr || !node->view.props) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
auto menu = parseMenu(desktopProps(*node->view.props).contextMenu);
|
|
263
|
+
if (!menu.empty()) {
|
|
264
|
+
return ContextMenuTarget{.tag = *it, .items = std::move(menu)};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return std::nullopt;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
void InputDispatcher::contextMenuSelect(Tag tag, const std::string &id) {
|
|
271
|
+
if (const auto *node = tree_.find(tag)) {
|
|
272
|
+
emitElementEvent(*node, "contextMenuSelect", folly::dynamic::object("id", id));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
WheelResult InputDispatcher::wheel(const PointerInput &input, const WheelDelta &delta) {
|
|
277
|
+
WheelResult result;
|
|
278
|
+
auto container = containers_.find(input.container);
|
|
279
|
+
if (container == containers_.end()) {
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
auto chain = tree_.hitTest(container->second.root, input.point);
|
|
283
|
+
if (gestures_) {
|
|
284
|
+
// The fingers' movement: the DOM's deltas are the content's, which natural scrolling moves
|
|
285
|
+
// with the fingers.
|
|
286
|
+
float sign = delta.naturalScrolling ? -1 : 1;
|
|
287
|
+
result.taken = gestures_->scroll(
|
|
288
|
+
container->second.surfaceId,
|
|
289
|
+
chain,
|
|
290
|
+
gesturePointer(container->second, input),
|
|
291
|
+
{static_cast<float>(delta.x) * sign, static_cast<float>(delta.y) * sign},
|
|
292
|
+
delta.phase);
|
|
293
|
+
}
|
|
294
|
+
// A trackpad scroll's beginning and end, which only the gestures needed, move nothing.
|
|
295
|
+
if (delta.x == 0 && delta.y == 0 && delta.z == 0) {
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
result.heard = sendElementEvent(
|
|
299
|
+
container->second,
|
|
300
|
+
chain,
|
|
301
|
+
&DesktopProps::onWheel,
|
|
302
|
+
"wheel",
|
|
303
|
+
folly::dynamic::object("deltaX", delta.x)("deltaY", delta.y)("deltaZ", delta.z)("deltaMode", delta.mode));
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
namespace {
|
|
308
|
+
|
|
309
|
+
int hexValue(char c) {
|
|
310
|
+
if (c >= '0' && c <= '9') {
|
|
311
|
+
return c - '0';
|
|
312
|
+
}
|
|
313
|
+
if (c >= 'a' && c <= 'f') {
|
|
314
|
+
return c - 'a' + 10;
|
|
315
|
+
}
|
|
316
|
+
if (c >= 'A' && c <= 'F') {
|
|
317
|
+
return c - 'A' + 10;
|
|
318
|
+
}
|
|
319
|
+
return -1;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
std::string percentDecoded(std::string_view text) {
|
|
323
|
+
std::string out;
|
|
324
|
+
for (size_t i = 0; i < text.size(); ++i) {
|
|
325
|
+
int high = 0;
|
|
326
|
+
int low = 0;
|
|
327
|
+
if (text[i] == '%' && i + 2 < text.size() && (high = hexValue(text[i + 1])) >= 0 &&
|
|
328
|
+
(low = hexValue(text[i + 2])) >= 0) {
|
|
329
|
+
out.push_back(static_cast<char>(high * 16 + low));
|
|
330
|
+
i += 2;
|
|
331
|
+
} else {
|
|
332
|
+
out.push_back(text[i]);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
} // namespace
|
|
339
|
+
|
|
340
|
+
std::optional<DragOutItem> dragItemOf(const folly::dynamic &prop, const FileAccess *files) {
|
|
341
|
+
if (!prop.isObject()) {
|
|
342
|
+
return std::nullopt;
|
|
343
|
+
}
|
|
344
|
+
// A file only inside the file boundary, as the file uri checked: dropped in Finder, it is copied.
|
|
345
|
+
// The item keeps the pick it reads open for the drag.
|
|
346
|
+
DragOutItem item;
|
|
347
|
+
auto readable = [files, &item](const std::string &uri) -> std::optional<std::string> {
|
|
348
|
+
try {
|
|
349
|
+
auto source = readableSource(files, uri);
|
|
350
|
+
if (source.use != nullptr && source.use->started()) {
|
|
351
|
+
item.uses.push_back(std::move(source.use));
|
|
352
|
+
}
|
|
353
|
+
return std::move(source.uri);
|
|
354
|
+
} catch (const FileRefused &) {
|
|
355
|
+
return std::nullopt;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
if (auto list = prop.get_ptr("files"); list != nullptr && list->isArray()) {
|
|
359
|
+
for (const auto &file : *list) {
|
|
360
|
+
if (file.isString() && isFileScheme(file.asString())) {
|
|
361
|
+
if (auto uri = readable(file.asString())) {
|
|
362
|
+
item.files.push_back(*uri);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (auto text = prop.get_ptr("text"); text != nullptr && text->isString()) {
|
|
368
|
+
item.text = text->asString();
|
|
369
|
+
}
|
|
370
|
+
if (auto url = prop.get_ptr("url"); url != nullptr && url->isString() && !url->asString().empty()) {
|
|
371
|
+
item.url = isFileScheme(url->asString()) ? readable(url->asString()) : url->asString();
|
|
372
|
+
}
|
|
373
|
+
if (item.files.empty() && !item.text && !item.url) {
|
|
374
|
+
return std::nullopt;
|
|
375
|
+
}
|
|
376
|
+
return item;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
DragItems dragItems(const std::vector<std::string> &urls, std::optional<std::string> text) {
|
|
380
|
+
DragItems items;
|
|
381
|
+
items.text = std::move(text);
|
|
382
|
+
for (const auto &url : urls) {
|
|
383
|
+
if (url.rfind("file:", 0) != 0) {
|
|
384
|
+
items.urls.push_back(url);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
std::string_view path(url);
|
|
388
|
+
while (path.size() > 1 && path.back() == '/') {
|
|
389
|
+
path.remove_suffix(1);
|
|
390
|
+
}
|
|
391
|
+
auto slash = path.rfind('/');
|
|
392
|
+
auto last = slash == std::string_view::npos ? path : path.substr(slash + 1);
|
|
393
|
+
items.files.push_back({.uri = url, .name = percentDecoded(last)});
|
|
394
|
+
}
|
|
395
|
+
// The toolkit offers a dragged url as text too, and a file as its path.
|
|
396
|
+
if (items.text) {
|
|
397
|
+
for (const auto &url : urls) {
|
|
398
|
+
bool path = url.rfind("file://", 0) == 0 && percentDecoded(std::string_view(url).substr(7)) == *items.text;
|
|
399
|
+
if (url == *items.text || path) {
|
|
400
|
+
items.text.reset();
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return items;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
folly::dynamic dropPayload(const DragItems &items) {
|
|
409
|
+
auto files = folly::dynamic::array();
|
|
410
|
+
for (const auto &file : items.files) {
|
|
411
|
+
files.push_back(folly::dynamic::object("uri", file.uri)("name", file.name));
|
|
412
|
+
}
|
|
413
|
+
auto urls = folly::dynamic::array();
|
|
414
|
+
for (const auto &url : items.urls) {
|
|
415
|
+
urls.push_back(url);
|
|
416
|
+
}
|
|
417
|
+
return folly::dynamic::object("files", std::move(files))(
|
|
418
|
+
"text", items.text ? folly::dynamic(*items.text) : folly::dynamic(nullptr))("urls", std::move(urls));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
std::optional<Tag> InputDispatcher::dropTargetAt(const PointerInput &input) const {
|
|
422
|
+
auto container = containers_.find(input.container);
|
|
423
|
+
if (container == containers_.end()) {
|
|
424
|
+
return std::nullopt;
|
|
425
|
+
}
|
|
426
|
+
auto chain = tree_.hitTest(container->second.root, input.point);
|
|
427
|
+
for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
|
|
428
|
+
const auto *node = tree_.find(*it);
|
|
429
|
+
if (node != nullptr && node->view.props && desktopProps(*node->view.props).fileDrop) {
|
|
430
|
+
return *it;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return std::nullopt;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
void InputDispatcher::leaveDropTarget() {
|
|
437
|
+
if (!dropTarget_) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
auto tag = dropTarget_->tag;
|
|
441
|
+
dropTarget_.reset();
|
|
442
|
+
if (const auto *node = tree_.find(tag)) {
|
|
443
|
+
emitElementEvent(*node, "dropLeave", folly::dynamic::object());
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
bool InputDispatcher::dragOver(const PointerInput &input, const DragItems &items) {
|
|
448
|
+
auto target = dropTargetAt(input);
|
|
449
|
+
if (dropTarget_ && target == dropTarget_->tag && dropTarget_->container == input.container) {
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
leaveDropTarget();
|
|
453
|
+
if (!target) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
dropTarget_ = DropTarget{input.container, *target};
|
|
457
|
+
if (const auto *node = tree_.find(*target)) {
|
|
458
|
+
emitElementEvent(*node, "dropEnter", dropPayload(items));
|
|
459
|
+
}
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
void InputDispatcher::dragExit(ContainerId container) {
|
|
464
|
+
if (dropTarget_ && dropTarget_->container == container) {
|
|
465
|
+
leaveDropTarget();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
bool InputDispatcher::drop(const PointerInput &input, const DragItems &items) {
|
|
470
|
+
auto target = dropTargetAt(input);
|
|
471
|
+
if (dropTarget_ && dropTarget_->tag != target) {
|
|
472
|
+
leaveDropTarget();
|
|
473
|
+
}
|
|
474
|
+
dropTarget_.reset();
|
|
475
|
+
const auto *node = target ? tree_.find(*target) : nullptr;
|
|
476
|
+
if (node == nullptr) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
emitElementEvent(*node, "dropPerform", dropPayload(items));
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
void InputDispatcher::didMount(SurfaceId surfaceId) {
|
|
484
|
+
if (pointerSurface_ == surfaceId) {
|
|
485
|
+
setCursor(cursorFor(tree_, hovered(surfaceId)));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
bool InputDispatcher::sendElementEvent(
|
|
490
|
+
const Container &container,
|
|
491
|
+
const std::vector<Tag> &chain,
|
|
492
|
+
bool DesktopProps::*optIn,
|
|
493
|
+
const std::string &name,
|
|
494
|
+
folly::dynamic payload) {
|
|
495
|
+
bool asked = false;
|
|
496
|
+
for (auto tag : chain) {
|
|
497
|
+
const auto *node = tree_.find(tag);
|
|
498
|
+
if (node && node->view.props && desktopProps(*node->view.props).*optIn) {
|
|
499
|
+
asked = true;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const auto *target = chain.empty() ? nullptr : tree_.find(chain.back());
|
|
504
|
+
if (!asked || target == nullptr) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
emitElementEvent(*target, name, std::move(payload));
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
void InputDispatcher::setGestures(Gestures *gestures) {
|
|
512
|
+
gestures_ = gestures;
|
|
513
|
+
if (gestures_) {
|
|
514
|
+
gestures_->onClaim = [this] { claimPress(); };
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
GesturePointer InputDispatcher::gesturePointer(const Container &container, const PointerInput &input) const {
|
|
519
|
+
auto origin = pageOrigin(container);
|
|
520
|
+
return {
|
|
521
|
+
.id = 1,
|
|
522
|
+
.page = {input.point.x + origin.x, input.point.y + origin.y},
|
|
523
|
+
.time = input.timestamp * 1000,
|
|
524
|
+
.button = gestureButton_,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
void InputDispatcher::cancelGesturePress() {
|
|
529
|
+
if (!gesturePress_) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
gesturePress_.reset();
|
|
533
|
+
gestureButton_ = 0;
|
|
534
|
+
if (gestures_) {
|
|
535
|
+
gestures_->pointerCancel();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
void InputDispatcher::claimPress() {
|
|
540
|
+
if (!press_ || !lastInput_) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
sendTouch(TouchPhase::Cancel, *lastInput_);
|
|
544
|
+
press_.reset();
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
void InputDispatcher::magnify(const PointerInput &input, double magnification, GesturePhase phase) {
|
|
548
|
+
auto container = containers_.find(input.container);
|
|
549
|
+
if (gestures_ && container != containers_.end()) {
|
|
550
|
+
gestures_->magnify(
|
|
551
|
+
container->second.surfaceId,
|
|
552
|
+
tree_.hitTest(container->second.root, input.point),
|
|
553
|
+
gesturePointer(container->second, input),
|
|
554
|
+
magnification,
|
|
555
|
+
phase);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
void InputDispatcher::rotate(const PointerInput &input, double degrees, GesturePhase phase) {
|
|
560
|
+
auto container = containers_.find(input.container);
|
|
561
|
+
if (gestures_ && container != containers_.end()) {
|
|
562
|
+
gestures_->rotate(
|
|
563
|
+
container->second.surfaceId,
|
|
564
|
+
tree_.hitTest(container->second.root, input.point),
|
|
565
|
+
gesturePointer(container->second, input),
|
|
566
|
+
degrees,
|
|
567
|
+
phase);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
folly::dynamic InputDispatcher::locationPayload(const Container &container, Tag target, Point point) const {
|
|
572
|
+
auto page = pageOrigin(container);
|
|
573
|
+
auto local = localPoint(target, container.root, point);
|
|
574
|
+
return folly::dynamic::object("pageX", point.x + page.x)("pageY", point.y + page.y)("locationX", local.x)(
|
|
575
|
+
"locationY", local.y);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
void InputDispatcher::setCursor(Cursor cursor) {
|
|
579
|
+
if (cursor_ == cursor) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
cursor_ = cursor;
|
|
583
|
+
if (onCursor) {
|
|
584
|
+
onCursor(cursor);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
void InputDispatcher::updateHover(const Container &container, std::vector<Tag> chain, const PointerInput &input) {
|
|
589
|
+
auto &before = hovered_[container.surfaceId];
|
|
590
|
+
auto event = pointerEvent(input, pageOrigin(container));
|
|
591
|
+
// React Native's PointerEventsProcessor tracks hover itself from the moves it is sent, as React
|
|
592
|
+
// Native iOS sends them: it sends over, out, enter and leave to the views that listen, and the
|
|
593
|
+
// move itself only when a view in the path does. A platform leave means the pointer left the
|
|
594
|
+
// surface. Sending enter or leave here as well would deliver each twice.
|
|
595
|
+
if (!chain.empty()) {
|
|
596
|
+
if (const auto *node = tree_.find(chain.back())) {
|
|
597
|
+
event.offsetPoint = localPoint(chain.back(), container.root, input.point);
|
|
598
|
+
emitPointer(PointerKind::Move, *node, event);
|
|
599
|
+
}
|
|
600
|
+
pointerSurface_ = container.surfaceId;
|
|
601
|
+
} else if (!before.empty()) {
|
|
602
|
+
// The processor needs a view of the surface to name; the one the pointer was last over.
|
|
603
|
+
for (size_t i = before.size(); i-- > 0;) {
|
|
604
|
+
if (const auto *node = tree_.find(before[i])) {
|
|
605
|
+
emitPointer(PointerKind::Leave, *node, event);
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
setCursor(cursorFor(tree_, chain));
|
|
611
|
+
before = std::move(chain);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
void InputDispatcher::sendTouch(TouchPhase phase, const PointerInput &input) {
|
|
615
|
+
auto container = containers_.find(press_->container);
|
|
616
|
+
const auto *target = tree_.find(press_->target);
|
|
617
|
+
if (container == containers_.end() || target == nullptr) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
auto root = container->second.root;
|
|
621
|
+
// Touches are reported in the surface's coordinates (page) and the target's (offset), whichever
|
|
622
|
+
// container the press is in. The pointer may be over another container now (a popover).
|
|
623
|
+
auto rootOrigin = pageOrigin(container->second);
|
|
624
|
+
auto over = containers_.find(input.container);
|
|
625
|
+
auto inputOrigin = over != containers_.end() ? pageOrigin(over->second) : rootOrigin;
|
|
626
|
+
Point page{input.point.x + inputOrigin.x, input.point.y + inputOrigin.y};
|
|
627
|
+
Touch touch;
|
|
628
|
+
touch.pagePoint = page;
|
|
629
|
+
touch.offsetPoint = localPoint(press_->target, root, {page.x - rootOrigin.x, page.y - rootOrigin.y});
|
|
630
|
+
touch.screenPoint = input.screenPoint;
|
|
631
|
+
touch.identifier = 0;
|
|
632
|
+
touch.target = press_->target;
|
|
633
|
+
touch.force = input.pressure;
|
|
634
|
+
touch.timestamp = input.timestamp;
|
|
635
|
+
touch.timeStamp = HighResTimeStamp::now();
|
|
636
|
+
TouchEvent event;
|
|
637
|
+
event.changedTouches.insert(touch);
|
|
638
|
+
if (phase != TouchPhase::End && phase != TouchPhase::Cancel) {
|
|
639
|
+
event.touches.insert(touch);
|
|
640
|
+
event.targetTouches.insert(touch);
|
|
641
|
+
}
|
|
642
|
+
emitTouch(phase, *target, event);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
Point InputDispatcher::localPoint(Tag tag, Tag root, Point point) const {
|
|
646
|
+
if (auto local = tree_.pointIn(tag, root, point)) {
|
|
647
|
+
return *local;
|
|
648
|
+
}
|
|
649
|
+
auto origin = tree_.originIn(tag, root).value_or(Point{0, 0});
|
|
650
|
+
return {point.x - origin.x, point.y - origin.y};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
Point InputDispatcher::pageOrigin(const Container &container) const {
|
|
654
|
+
return tree_.originIn(container.root, container.surfaceId).value_or(Point{0, 0});
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
PointerEvent InputDispatcher::pointerEvent(const PointerInput &input, Point pageOrigin) const {
|
|
658
|
+
PointerEvent event{};
|
|
659
|
+
event.pointerId = 1;
|
|
660
|
+
event.pressure = input.pressure;
|
|
661
|
+
event.pointerType = "mouse";
|
|
662
|
+
event.clientPoint = {input.point.x + pageOrigin.x, input.point.y + pageOrigin.y};
|
|
663
|
+
event.screenPoint = input.screenPoint;
|
|
664
|
+
event.offsetPoint = input.point;
|
|
665
|
+
event.width = 1;
|
|
666
|
+
event.height = 1;
|
|
667
|
+
event.detail = 0;
|
|
668
|
+
event.buttons = input.buttons;
|
|
669
|
+
event.isPrimary = true;
|
|
670
|
+
event.button = -1;
|
|
671
|
+
event.timeStamp = HighResTimeStamp::now();
|
|
672
|
+
return event;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
void InputDispatcher::emitTouch(TouchPhase phase, const ViewTree::Node &target, const TouchEvent &event) {
|
|
676
|
+
auto emitter = touchEmitter(target);
|
|
677
|
+
if (!emitter) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
switch (phase) {
|
|
681
|
+
case TouchPhase::Start:
|
|
682
|
+
emitter->onTouchStart(event);
|
|
683
|
+
break;
|
|
684
|
+
case TouchPhase::Move:
|
|
685
|
+
emitter->onTouchMove(event);
|
|
686
|
+
break;
|
|
687
|
+
case TouchPhase::End:
|
|
688
|
+
emitter->onTouchEnd(event);
|
|
689
|
+
break;
|
|
690
|
+
case TouchPhase::Cancel:
|
|
691
|
+
emitter->onTouchCancel(event);
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
void InputDispatcher::emitPointer(PointerKind kind, const ViewTree::Node &node, const PointerEvent &event) {
|
|
697
|
+
auto emitter = touchEmitter(node);
|
|
698
|
+
if (!emitter) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
switch (kind) {
|
|
702
|
+
case PointerKind::Enter:
|
|
703
|
+
emitter->onPointerEnter(event);
|
|
704
|
+
break;
|
|
705
|
+
case PointerKind::Leave:
|
|
706
|
+
emitter->onPointerLeave(event);
|
|
707
|
+
break;
|
|
708
|
+
case PointerKind::Move:
|
|
709
|
+
emitter->onPointerMove(event);
|
|
710
|
+
break;
|
|
711
|
+
case PointerKind::Over:
|
|
712
|
+
emitter->onPointerOver(event);
|
|
713
|
+
break;
|
|
714
|
+
case PointerKind::Out:
|
|
715
|
+
emitter->onPointerOut(event);
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
void InputDispatcher::emitElementEvent(const ViewTree::Node &node, const std::string &name, folly::dynamic payload) {
|
|
721
|
+
if (node.view.eventEmitter) {
|
|
722
|
+
auto category = name == "wheel" ? RawEvent::Category::Continuous : RawEvent::Category::Discrete;
|
|
723
|
+
node.view.eventEmitter->dispatchEvent(name, std::move(payload), category);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
} // namespace ngn
|