basalt-win32 0.0.0-rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/cli/runWindows.js +35 -0
  3. package/cli/shared.js +75 -0
  4. package/native/CMakeLists.txt +398 -0
  5. package/native/tests/test_win32_accessibility.cpp +271 -0
  6. package/native/tests/test_win32_clipboard.cpp +121 -0
  7. package/native/tests/test_win32_focus.cpp +195 -0
  8. package/native/tests/test_win32_hittest.cpp +410 -0
  9. package/native/tests/test_win32_image.cpp +239 -0
  10. package/native/tests/test_win32_imageloader.cpp +208 -0
  11. package/native/tests/test_win32_input.cpp +361 -0
  12. package/native/tests/test_win32_key_events.cpp +84 -0
  13. package/native/tests/test_win32_mounting.cpp +410 -0
  14. package/native/tests/test_win32_paint.cpp +505 -0
  15. package/native/tests/test_win32_scrollview.cpp +385 -0
  16. package/native/tests/test_win32_text.cpp +258 -0
  17. package/native/tests/test_win32_textinput.cpp +609 -0
  18. package/native/tests/test_win32_titlebar.cpp +111 -0
  19. package/native/tests/test_win32_titlebar_actions.cpp +62 -0
  20. package/native/tests/test_win32_view.cpp +222 -0
  21. package/native/win32/ColorSchemeWin32.cpp +56 -0
  22. package/native/win32/ComponentRegistryWin32.cpp +124 -0
  23. package/native/win32/DirectWriteLayout.cpp +116 -0
  24. package/native/win32/DirectWriteLayout.h +36 -0
  25. package/native/win32/DirectWriteLayoutManager.cpp +124 -0
  26. package/native/win32/FontRegistryDirectWrite.cpp +117 -0
  27. package/native/win32/PlatformServicesWin32.cpp +643 -0
  28. package/native/win32/RnWin32Accessible.cpp +258 -0
  29. package/native/win32/RnWin32Accessible.h +91 -0
  30. package/native/win32/RnWin32Image.cpp +265 -0
  31. package/native/win32/RnWin32Image.h +93 -0
  32. package/native/win32/RnWin32TextLayout.cpp +310 -0
  33. package/native/win32/RnWin32TextLayout.h +160 -0
  34. package/native/win32/RnWin32View.cpp +1281 -0
  35. package/native/win32/RnWin32View.h +506 -0
  36. package/native/win32/Win32AnimationChoreographer.cpp +76 -0
  37. package/native/win32/Win32AnimationChoreographer.h +61 -0
  38. package/native/win32/Win32Clip.h +173 -0
  39. package/native/win32/Win32DropTarget.cpp +567 -0
  40. package/native/win32/Win32DropTarget.h +42 -0
  41. package/native/win32/Win32Focus.cpp +262 -0
  42. package/native/win32/Win32Focus.h +109 -0
  43. package/native/win32/Win32ImageLoader.cpp +167 -0
  44. package/native/win32/Win32ImageLoader.h +104 -0
  45. package/native/win32/Win32KeyEvents.cpp +126 -0
  46. package/native/win32/Win32KeyEvents.h +20 -0
  47. package/native/win32/Win32MenuBar.cpp +352 -0
  48. package/native/win32/Win32MenuBar.h +16 -0
  49. package/native/win32/Win32MountingManager.cpp +727 -0
  50. package/native/win32/Win32MountingManager.h +203 -0
  51. package/native/win32/Win32Packaging.cpp +161 -0
  52. package/native/win32/Win32Packaging.h +56 -0
  53. package/native/win32/Win32RunLoopObserver.cpp +48 -0
  54. package/native/win32/Win32RunLoopObserver.h +42 -0
  55. package/native/win32/Win32ScrollView.cpp +515 -0
  56. package/native/win32/Win32ScrollView.h +208 -0
  57. package/native/win32/Win32SkiaContext.cpp +221 -0
  58. package/native/win32/Win32SkiaContext.h +53 -0
  59. package/native/win32/Win32SkiaModule.cpp +80 -0
  60. package/native/win32/Win32SkiaModule.h +50 -0
  61. package/native/win32/Win32SkiaPeer.cpp +358 -0
  62. package/native/win32/Win32SkiaPeer.h +66 -0
  63. package/native/win32/Win32SkiaUnicode.cpp +42 -0
  64. package/native/win32/Win32Snapshot.cpp +201 -0
  65. package/native/win32/Win32Snapshot.h +66 -0
  66. package/native/win32/Win32Strings.h +54 -0
  67. package/native/win32/Win32TextInput.cpp +811 -0
  68. package/native/win32/Win32TextInput.h +232 -0
  69. package/native/win32/Win32TitleBar.cpp +562 -0
  70. package/native/win32/Win32TitleBar.h +146 -0
  71. package/native/win32/Win32TitleBarLayout.cpp +46 -0
  72. package/native/win32/Win32TitleBarLayout.h +58 -0
  73. package/native/win32/Win32TouchDispatcher.cpp +443 -0
  74. package/native/win32/Win32TouchDispatcher.h +153 -0
  75. package/native/win32/Win32UiThread.h +27 -0
  76. package/native/win32/Win32WindowControl.cpp +329 -0
  77. package/native/win32/Win32WindowModule.cpp +209 -0
  78. package/native/win32/Win32WindowModule.h +72 -0
  79. package/native/win32/demo_layout_win32.cpp +232 -0
  80. package/native/win32/main_win32.cpp +2481 -0
  81. package/native/win32/mount_harness_win32.cpp +316 -0
  82. package/package.json +26 -0
  83. package/react-native.config.js +22 -0
@@ -0,0 +1,66 @@
1
+ // Rendering a view tree without showing it -- to a PNG, or to pixels a test can
2
+ // read.
3
+ //
4
+ // The PNG is shared by the demo and, later, the mount harness, and it is the
5
+ // only way either of them proves anything: a tree dump prints the frames that
6
+ // were *set*, which looks identical whether or not the transform composition,
7
+ // the clip and the paint order are right. A picture does not.
8
+ //
9
+ // The pixels are the same render with the encoder left off, and they exist
10
+ // because of a gap `docs/BACKLOG.md` has carried since GTK: "the widget tree
11
+ // says a view has a colour and a frame, not that the right pixels reached the
12
+ // screen -- GTK's cairo renderer mangled every transform in the demo and no
13
+ // test noticed". Neither of the other hosts can close that cheaply. GTK needs a
14
+ // display server and macOS needs an offscreen NSWindow and a display cycle;
15
+ // Direct2D renders into a WIC bitmap with no window, no device and no display,
16
+ // so on this platform a rendering assertion costs a function call. That is also
17
+ // what lets the Windows suite run on a headless CI machine with none of the
18
+ // xvfb arrangement `docs/TESTING.md` describes for GTK.
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <string>
24
+ #include <vector>
25
+
26
+ namespace basalt::win32 {
27
+
28
+ class RnWin32View;
29
+
30
+ // Straight (not premultiplied) sRGB, 0..255, as the components went in.
31
+ struct RnPixel {
32
+ uint8_t red = 0;
33
+ uint8_t green = 0;
34
+ uint8_t blue = 0;
35
+ uint8_t alpha = 0;
36
+ };
37
+
38
+ class RnPixels {
39
+ public:
40
+ RnPixels(unsigned width, unsigned height, std::vector<uint8_t> bgra)
41
+ : width_(width), height_(height), bgra_(std::move(bgra)) {}
42
+
43
+ unsigned width() const { return width_; }
44
+ unsigned height() const { return height_; }
45
+ bool empty() const { return bgra_.empty(); }
46
+
47
+ // The colour at a point, unpremultiplied. Out of bounds reads as transparent
48
+ // black rather than throwing: a test that asks about the wrong pixel should
49
+ // fail on the colour, where the message says what it expected.
50
+ RnPixel at(unsigned x, unsigned y) const;
51
+
52
+ private:
53
+ unsigned width_ = 0;
54
+ unsigned height_ = 0;
55
+ std::vector<uint8_t> bgra_; // premultiplied BGRA, stride = width * 4
56
+ };
57
+
58
+ // Renders `root` and its subtree at the root's own size, onto transparent
59
+ // black. An empty result means the render failed.
60
+ RnPixels renderToPixels(const RnWin32View &root);
61
+
62
+ // The same render, encoded as a PNG at `path`. Returns false if the tree could
63
+ // not be rendered or the file could not be written.
64
+ bool writeSnapshot(const RnWin32View &root, const std::string &path);
65
+
66
+ } // namespace basalt::win32
@@ -0,0 +1,54 @@
1
+ // UTF-8 in, UTF-16 out, and back.
2
+ //
3
+ // Windows is a UTF-16 platform and React Native is a UTF-8 one, so this
4
+ // conversion sits on every boundary between them: DirectWrite takes wide
5
+ // strings, WIC's filenames are wide, and everything arriving from JavaScript
6
+ // through Fabric is UTF-8. Small enough to be tempting to write again in each
7
+ // file, which is how two of them end up disagreeing about what to do with a
8
+ // lone surrogate.
9
+
10
+ #pragma once
11
+
12
+ #include <windows.h>
13
+
14
+ #include <string>
15
+
16
+ namespace basalt::win32 {
17
+
18
+ inline std::wstring widen(const std::string &text) {
19
+ if (text.empty()) {
20
+ return {};
21
+ }
22
+ const int needed =
23
+ MultiByteToWideChar(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0);
24
+ if (needed <= 0) {
25
+ return {};
26
+ }
27
+ std::wstring wide(static_cast<size_t>(needed), L'\0');
28
+ MultiByteToWideChar(
29
+ CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), wide.data(), needed);
30
+ return wide;
31
+ }
32
+
33
+ inline std::string narrow(const std::wstring &text) {
34
+ if (text.empty()) {
35
+ return {};
36
+ }
37
+ const int needed = WideCharToMultiByte(
38
+ CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);
39
+ if (needed <= 0) {
40
+ return {};
41
+ }
42
+ std::string narrowed(static_cast<size_t>(needed), '\0');
43
+ WideCharToMultiByte(CP_UTF8,
44
+ 0,
45
+ text.c_str(),
46
+ static_cast<int>(text.size()),
47
+ narrowed.data(),
48
+ needed,
49
+ nullptr,
50
+ nullptr);
51
+ return narrowed;
52
+ }
53
+
54
+ } // namespace basalt::win32