@ng-native/desktop 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/bin/app-config.mjs +1 -0
- package/bin/archive.mjs +166 -0
- package/bin/autolink.mjs +61 -30
- package/bin/cli.mjs +127 -27
- package/bin/host.mjs +255 -58
- package/bin/package-linux.mjs +1394 -0
- package/bin/package.mjs +171 -35
- package/bin/plist.mjs +6 -2
- package/bin/png-icon.mjs +315 -0
- package/bin/prebuilt.mjs +147 -26
- package/bin/toolchain.mjs +258 -19
- package/native/CMakeLists.txt +64 -6
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/appkit-backend.h +1 -0
- package/native/appkit/appkit-backend.mm +13 -0
- package/native/appkit/header-toolbar.mm +28 -25
- package/native/appkit/host-view.h +10 -0
- package/native/appkit/host-view.mm +146 -40
- package/native/appkit/input-replay.h +6 -0
- package/native/appkit/input-replay.mm +21 -12
- package/native/appkit/main.mm +11 -7
- package/native/appkit/native-controls.mm +13 -1
- package/native/appkit/split-view.mm +7 -13
- package/native/appkit/text-input-field.h +4 -0
- package/native/appkit/text-input-field.mm +20 -1
- package/native/cmake/curl.cmake +79 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
- package/native/cmake/libraries/react-native-worklets.cmake +5 -0
- package/native/cmake/linked-modules.cmake +20 -4
- package/native/cmake/react-native.cmake +18 -1
- package/native/core/include/ngn/accent-colors.h +38 -0
- package/native/core/include/ngn/accessibility-relations.h +65 -0
- package/native/core/include/ngn/accessibility.h +26 -0
- package/native/core/include/ngn/animated-frame-loop.h +56 -0
- package/native/core/include/ngn/app-info.h +24 -8
- package/native/core/include/ngn/app-menus.h +14 -1
- package/native/core/include/ngn/app-windows.h +15 -2
- package/native/core/include/ngn/aria-role.h +96 -0
- package/native/core/include/ngn/audio.h +2 -0
- package/native/core/include/ngn/camera.h +9 -0
- package/native/core/include/ngn/control-sizes.h +7 -2
- package/native/core/include/ngn/crash-report.h +31 -0
- package/native/core/include/ngn/curl-network.h +93 -0
- package/native/core/include/ngn/dbus-menu.h +39 -0
- package/native/core/include/ngn/default-menu.h +36 -0
- package/native/core/include/ngn/desktop-expo.h +7 -1
- package/native/core/include/ngn/desktop-modules.h +22 -0
- package/native/core/include/ngn/desktop-props.h +21 -1
- package/native/core/include/ngn/desktop-view-props.h +6 -0
- package/native/core/include/ngn/focus-order.h +10 -0
- package/native/core/include/ngn/header-bar.h +22 -0
- package/native/core/include/ngn/host-os.h +6 -0
- package/native/core/include/ngn/host-reload.h +21 -0
- package/native/core/include/ngn/host-state.h +23 -0
- package/native/core/include/ngn/image-source.h +26 -1
- package/native/core/include/ngn/input-script.h +3 -3
- package/native/core/include/ngn/input.h +4 -1
- package/native/core/include/ngn/launch-frame.h +21 -0
- package/native/core/include/ngn/launch-settings.h +23 -5
- package/native/core/include/ngn/mounting-backend.h +5 -0
- package/native/core/include/ngn/mounting-manager.h +1 -0
- package/native/core/include/ngn/native-controls.h +26 -5
- package/native/core/include/ngn/notification-schedule.h +74 -0
- package/native/core/include/ngn/notifications.h +2 -1
- package/native/core/include/ngn/openssl-update-crypto.h +15 -0
- package/native/core/include/ngn/photo-library.h +60 -20
- package/native/core/include/ngn/posix-locale.h +43 -0
- package/native/core/include/ngn/runtime.h +5 -0
- package/native/core/include/ngn/safe-areas.h +14 -2
- package/native/core/include/ngn/split-view.h +78 -0
- package/native/core/include/ngn/surface-metrics.h +7 -0
- package/native/core/include/ngn/system.h +14 -0
- package/native/core/include/ngn/text-input.h +13 -0
- package/native/core/include/ngn/text-units.h +38 -0
- package/native/core/include/ngn/updates.h +14 -2
- package/native/core/include/ngn/view-box.h +40 -0
- package/native/core/include/ngn/view-transform.h +15 -0
- package/native/core/include/ngn/web-browser.h +46 -0
- package/native/core/src/accent-colors.cpp +88 -0
- package/native/core/src/accessibility-relations.cpp +138 -0
- package/native/core/src/accessibility.cpp +50 -0
- package/native/core/src/animated-frame-loop.cpp +166 -0
- package/native/core/src/app-menus.cpp +26 -9
- package/native/core/src/app-windows.cpp +27 -6
- package/native/core/src/aria-role.cpp +127 -0
- package/native/core/src/control-sizes.cpp +9 -5
- package/native/core/src/crash-report.cpp +196 -0
- package/native/core/src/curl-network.cpp +1562 -0
- package/native/core/src/dbus-menu.cpp +71 -0
- package/native/core/src/default-menu.cpp +134 -0
- package/native/core/src/desktop-view-props.cpp +14 -0
- package/native/core/src/focus-order.cpp +19 -0
- package/native/core/src/header-bar.cpp +20 -0
- package/native/core/src/host-os.cpp +19 -0
- package/native/core/src/host-reload.cpp +45 -0
- package/native/core/src/host-state.cpp +8 -0
- package/native/core/src/image-source.cpp +90 -0
- package/native/core/src/input-dispatcher.cpp +27 -5
- package/native/core/src/input-script.cpp +3 -2
- package/native/core/src/launch-settings.cpp +76 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
- package/native/core/src/modules/app-info.cpp +55 -6
- package/native/core/src/modules/app-modules.cpp +1 -1
- package/native/core/src/modules/audio.cpp +4 -2
- package/native/core/src/modules/camera.cpp +8 -11
- package/native/core/src/modules/desktop-expo.cpp +10 -5
- package/native/core/src/modules/desktop-modules.cpp +106 -41
- package/native/core/src/modules/file-photo-picker.cpp +408 -0
- package/native/core/src/modules/notifications.cpp +13 -17
- package/native/core/src/modules/photo-library.cpp +42 -13
- package/native/core/src/modules/web-browser.cpp +89 -0
- package/native/core/src/mounting-manager.cpp +12 -0
- package/native/core/src/native-controls.cpp +42 -1
- package/native/core/src/notification-schedule.cpp +429 -0
- package/native/core/src/openssl-update-crypto.cpp +83 -0
- package/native/core/src/posix-locale.cpp +192 -0
- package/native/core/src/runtime.cpp +30 -1
- package/native/core/src/safe-areas.cpp +19 -4
- package/native/core/src/spawn-rules.cpp +4 -1
- package/native/core/src/split-view.cpp +93 -0
- package/native/core/src/system.cpp +19 -0
- package/native/core/src/text-input.cpp +18 -1
- package/native/core/src/text-units.cpp +99 -0
- package/native/core/src/updates.cpp +76 -17
- package/native/core/src/view-box.cpp +75 -40
- package/native/core/src/view-transform.cpp +28 -0
- package/native/docker/Dockerfile +38 -0
- package/native/docker/Dockerfile.fedora +36 -0
- package/native/docker/glibc-floor.sh +49 -0
- package/native/gtk/CMakeLists.txt +137 -0
- package/native/gtk/accent-colour.cpp +57 -0
- package/native/gtk/accent-colour.h +41 -0
- package/native/gtk/accessibility-settings.cpp +159 -0
- package/native/gtk/accessibility-settings.h +62 -0
- package/native/gtk/accessible-text.cpp +151 -0
- package/native/gtk/accessible-text.h +49 -0
- package/native/gtk/accessible.cpp +306 -0
- package/native/gtk/accessible.h +75 -0
- package/native/gtk/alerts.cpp +267 -0
- package/native/gtk/alerts.h +30 -0
- package/native/gtk/animation-frames.cpp +159 -0
- package/native/gtk/animation-frames.h +20 -0
- package/native/gtk/app-info.cpp +91 -0
- package/native/gtk/app-info.h +25 -0
- package/native/gtk/app-windows.cpp +439 -0
- package/native/gtk/app-windows.h +150 -0
- package/native/gtk/audio.cpp +370 -0
- package/native/gtk/audio.h +54 -0
- package/native/gtk/auth-session.cpp +73 -0
- package/native/gtk/auth-session.h +16 -0
- package/native/gtk/battery.cpp +110 -0
- package/native/gtk/battery.h +19 -0
- package/native/gtk/box-paint.cpp +262 -0
- package/native/gtk/box-paint.h +32 -0
- package/native/gtk/cairo-canvas.cpp +755 -0
- package/native/gtk/cairo-canvas.h +49 -0
- package/native/gtk/camera.cpp +909 -0
- package/native/gtk/camera.h +69 -0
- package/native/gtk/capture.cpp +46 -0
- package/native/gtk/capture.h +19 -0
- package/native/gtk/clock-format.cpp +151 -0
- package/native/gtk/clock-format.h +36 -0
- package/native/gtk/crypto.cpp +75 -0
- package/native/gtk/crypto.h +14 -0
- package/native/gtk/dbus-properties.cpp +131 -0
- package/native/gtk/dbus-properties.h +61 -0
- package/native/gtk/drag-and-drop.cpp +339 -0
- package/native/gtk/drag-and-drop.h +30 -0
- package/native/gtk/file-dialogs.cpp +239 -0
- package/native/gtk/file-dialogs.h +21 -0
- package/native/gtk/file-system.cpp +212 -0
- package/native/gtk/file-system.h +25 -0
- package/native/gtk/focus.cpp +282 -0
- package/native/gtk/focus.h +37 -0
- package/native/gtk/fonts.cpp +89 -0
- package/native/gtk/fonts.h +22 -0
- package/native/gtk/gst-frames.cpp +150 -0
- package/native/gtk/gst-frames.h +47 -0
- package/native/gtk/gst-playback.cpp +496 -0
- package/native/gtk/gst-playback.h +81 -0
- package/native/gtk/gtk-backend.cpp +690 -0
- package/native/gtk/gtk-backend.h +134 -0
- package/native/gtk/host-sources.cpp +354 -0
- package/native/gtk/host-sources.h +46 -0
- package/native/gtk/image-manipulator.cpp +254 -0
- package/native/gtk/image-manipulator.h +30 -0
- package/native/gtk/image-view.cpp +256 -0
- package/native/gtk/image-view.h +54 -0
- package/native/gtk/input-replay.cpp +299 -0
- package/native/gtk/input-replay.h +36 -0
- package/native/gtk/launcher-badge.cpp +29 -0
- package/native/gtk/launcher-badge.h +21 -0
- package/native/gtk/locales.cpp +131 -0
- package/native/gtk/locales.h +23 -0
- package/native/gtk/location.cpp +274 -0
- package/native/gtk/location.h +19 -0
- package/native/gtk/main.cpp +1092 -0
- package/native/gtk/menus.cpp +447 -0
- package/native/gtk/menus.h +100 -0
- package/native/gtk/native-controls.cpp +831 -0
- package/native/gtk/native-controls.h +58 -0
- package/native/gtk/network-state.cpp +72 -0
- package/native/gtk/network-state.h +24 -0
- package/native/gtk/notifications.cpp +235 -0
- package/native/gtk/notifications.h +30 -0
- package/native/gtk/pango-text.cpp +274 -0
- package/native/gtk/pango-text.h +73 -0
- package/native/gtk/portal.cpp +451 -0
- package/native/gtk/portal.h +71 -0
- package/native/gtk/printing.cpp +338 -0
- package/native/gtk/printing.h +34 -0
- package/native/gtk/proxy-resolver.cpp +74 -0
- package/native/gtk/proxy-resolver.h +20 -0
- package/native/gtk/screens.cpp +1461 -0
- package/native/gtk/screens.h +274 -0
- package/native/gtk/scroll-view.cpp +414 -0
- package/native/gtk/scroll-view.h +82 -0
- package/native/gtk/secret-store.cpp +120 -0
- package/native/gtk/secret-store.h +27 -0
- package/native/gtk/settings-portal.cpp +129 -0
- package/native/gtk/settings-portal.h +47 -0
- package/native/gtk/split-view.cpp +1105 -0
- package/native/gtk/split-view.h +195 -0
- package/native/gtk/status-notifier.cpp +487 -0
- package/native/gtk/status-notifier.h +43 -0
- package/native/gtk/surface-input.cpp +251 -0
- package/native/gtk/surface-input.h +57 -0
- package/native/gtk/system-access.cpp +295 -0
- package/native/gtk/system-access.h +37 -0
- package/native/gtk/text-field.cpp +827 -0
- package/native/gtk/text-field.h +78 -0
- package/native/gtk/video.cpp +527 -0
- package/native/gtk/video.h +47 -0
- package/native/gtk/view-widget.cpp +431 -0
- package/native/gtk/view-widget.h +105 -0
- package/native/gtk/window-scale.cpp +95 -0
- package/native/gtk/window-scale.h +35 -0
- package/native/scripts/atspi-check.py +310 -0
- package/native/scripts/atspi-check.test.py +48 -0
- package/native/scripts/build.sh +20 -3
- package/native/scripts/compilers.sh +17 -0
- package/native/scripts/deb-depends-check.sh +22 -0
- package/native/scripts/fetch.sh +23 -2
- package/native/scripts/launch-cell.sh +157 -0
- package/native/scripts/launch-probe.sh +14 -3
- package/native/scripts/make-prebuilt.mjs +133 -44
- package/native/scripts/prebuilt-host-cache.mjs +71 -40
- package/native/scripts/reset-for-compilers.sh +44 -0
- package/native/scripts/start-xvfb.sh +35 -0
- package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
- package/native/shim/worklets/linux-reanimated-props.h +14 -0
- package/native/shim/worklets/linux-worklets.h +23 -0
- package/package.json +6 -3
- package/prebuilt.json +70 -6
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// react-native-screens' native stack and React Native's <modal> on GTK, over the core's screen
|
|
2
|
+
// stacks (screen-stacks.h), header (header-bar.h) and modal sizing (desktop-modal.h).
|
|
3
|
+
//
|
|
4
|
+
// A surface's window is an AdwApplicationWindow whose content is an AdwToolbarView: an
|
|
5
|
+
// AdwHeaderBar on top, over a GtkOverlay holding the surface. The window's title-bar mode
|
|
6
|
+
// (app-windows.h's TitleBar) is how the two meet. `default` keeps the content below a raised header
|
|
7
|
+
// bar; `transparent` runs it under a flat one, which the safe area's top inset clears; `hidden` does
|
|
8
|
+
// the same and hides the title, keeping the window controls, as AppKit does. The front screen's
|
|
9
|
+
// header goes into the header bar as the AppKit host puts it into the window's toolbar: the back
|
|
10
|
+
// and forward pair, the header's subviews moved into slots of their own, its bar buttons and its
|
|
11
|
+
// search fields, with the title between. The pair follows the window's history as the app's router
|
|
12
|
+
// reports it (app-menus.h's historyButtons), and a secondary click or a long press on either lists
|
|
13
|
+
// the entries that way (historyMenu).
|
|
14
|
+
//
|
|
15
|
+
// Where the app's menus go (default-menu.h's MenuPlacement) is set up with the chrome: an empty
|
|
16
|
+
// GtkPopoverMenuBar under the header bar, or a primary GtkMenuButton at its end, each hidden until
|
|
17
|
+
// the window lifecycle gives it a menu.
|
|
18
|
+
//
|
|
19
|
+
// A <modal>, and a react-native-screens screen presented with `present()` (screen-presentation.h),
|
|
20
|
+
// shows the way the macOS host shows it. A sheet is an AdwDialog inside the window on libadwaita
|
|
21
|
+
// 1.5 and later, found at run time since the build targets 1.4's API, and a drawn overlay on 1.4: a
|
|
22
|
+
// dimmed backdrop with the sheet on a card in the middle. A cover is an overlay filling the window
|
|
23
|
+
// below the header bar. One with an anchor on screen is a GtkPopover pointing at the anchor. Each
|
|
24
|
+
// way the view moves into a slot of its own, a container of its own for input, and takes the size
|
|
25
|
+
// the core works out from its content (sheetSize, popoverSize).
|
|
26
|
+
//
|
|
27
|
+
// A presented screen's header becomes the sheet's own header bar: its title in the middle, its left
|
|
28
|
+
// items (Cancel) at the start and its right ones at the end, the last the default on Return. Escape
|
|
29
|
+
// presses Cancel, or without one asks the app to close the sheet: onRequestClose for a <modal>,
|
|
30
|
+
// `dismissed` for a screen, which the router follows. A click outside a popover asks the same.
|
|
31
|
+
#pragma once
|
|
32
|
+
|
|
33
|
+
#include "ngn/app-menus.h"
|
|
34
|
+
#include "ngn/app-windows.h"
|
|
35
|
+
#include "ngn/default-menu.h"
|
|
36
|
+
#include "ngn/desktop-modal.h"
|
|
37
|
+
#include "ngn/header-bar.h"
|
|
38
|
+
#include "ngn/mounting-backend.h"
|
|
39
|
+
#include "ngn/safe-areas.h"
|
|
40
|
+
#include "ngn/screen-presentation.h"
|
|
41
|
+
#include "ngn/screen-stacks.h"
|
|
42
|
+
|
|
43
|
+
#include <gtk/gtk.h>
|
|
44
|
+
|
|
45
|
+
#include <dlfcn.h>
|
|
46
|
+
|
|
47
|
+
#include <functional>
|
|
48
|
+
#include <map>
|
|
49
|
+
#include <memory>
|
|
50
|
+
#include <optional>
|
|
51
|
+
#include <set>
|
|
52
|
+
#include <vector>
|
|
53
|
+
|
|
54
|
+
namespace ngn::gtk {
|
|
55
|
+
|
|
56
|
+
class GtkBackend;
|
|
57
|
+
|
|
58
|
+
// How a window's chrome is made.
|
|
59
|
+
struct ChromeOptions {
|
|
60
|
+
TitleBar titleBar{TitleBar::Default};
|
|
61
|
+
MenuPlacement menus{MenuPlacement::PrimaryMenu};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// What a surface's window holds besides it.
|
|
65
|
+
struct WindowChrome {
|
|
66
|
+
GtkWidget *toolbarView{nullptr};
|
|
67
|
+
GtkWidget *headerBar{nullptr};
|
|
68
|
+
GtkWidget *overlay{nullptr};
|
|
69
|
+
// Where the menus go: the bar under the header bar, or the header bar's menu button. One of the
|
|
70
|
+
// two, hidden until it has a menu.
|
|
71
|
+
GtkWidget *menuBar{nullptr};
|
|
72
|
+
GtkWidget *primaryMenu{nullptr};
|
|
73
|
+
TitleBar titleBar{TitleBar::Default};
|
|
74
|
+
// The widgets a cover or drawn sheet in front holds still (Modals::hold), each with what it took
|
|
75
|
+
// before: the pointer, the focus, whether it was sensitive, and a menu button whether F10 opened it.
|
|
76
|
+
struct Held {
|
|
77
|
+
GtkWidget *widget;
|
|
78
|
+
bool target;
|
|
79
|
+
bool focus;
|
|
80
|
+
bool sensitive;
|
|
81
|
+
bool primary;
|
|
82
|
+
};
|
|
83
|
+
std::vector<Held> held;
|
|
84
|
+
~WindowChrome();
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// The toolbar view holding `surface` under the header bar, for a window's content; the window's
|
|
88
|
+
// chromeOf(surface) from then on.
|
|
89
|
+
GtkWidget *wrapInChrome(GtkWidget *surface, const ChromeOptions &options = {});
|
|
90
|
+
// The chrome of `surface`'s window, or null for a surface wrapInChrome did not wrap.
|
|
91
|
+
const WindowChrome *chromeOf(GtkWidget *surface);
|
|
92
|
+
// Holds the window still around `front`, a layer on its overlay, as a sheet does on macOS: every
|
|
93
|
+
// header bar's items (its window controls aside) and the menus take no pointer or keyboard, the
|
|
94
|
+
// surface takes no focus, and the overlay's other layers neither. Null gives back what it held.
|
|
95
|
+
void holdChrome(GtkWidget *surface, GtkWidget *front);
|
|
96
|
+
// Whether the surface's content runs under its header bar: `transparent` and `hidden`.
|
|
97
|
+
bool runsUnderHeaderBar(const WindowChrome &chrome);
|
|
98
|
+
// The surface's size and the insets its chrome gives it: none while its content stays below the
|
|
99
|
+
// header bar. Under it, the top bars' height on top, and how far the window controls reach in from
|
|
100
|
+
// each side (titlebarLeading and titlebarTrailing), as gtk-decoration-layout places them.
|
|
101
|
+
ContainerInsets chromeInsets(GtkWidget *surface);
|
|
102
|
+
|
|
103
|
+
// A slot holding one view moved out of the tree's widgets: it measures as the view's frame, or as
|
|
104
|
+
// the size set on it, and puts the view at its top left.
|
|
105
|
+
GtkWidget *makeHostSlot();
|
|
106
|
+
void setSlotSize(GtkWidget *slot, std::optional<std::pair<int, int>> size);
|
|
107
|
+
|
|
108
|
+
// A RNSSearchBar's field for the header bar, reporting to the view `tag`'s emitter as
|
|
109
|
+
// react-native-screens' iOS search bar does (searchBarEvents); its config and commands.
|
|
110
|
+
GtkWidget *makeSearchEntry(GtkBackend &backend, Tag tag);
|
|
111
|
+
void applySearchBar(GtkWidget *entry, const facebook::react::Props &props);
|
|
112
|
+
void runSearchBarCommand(GtkWidget *entry, const std::string &name, const folly::dynamic &args);
|
|
113
|
+
|
|
114
|
+
// A libadwaita function newer than the 1.4 API the build targets, found at run time; null on an
|
|
115
|
+
// older libadwaita.
|
|
116
|
+
template <typename Fn>
|
|
117
|
+
Fn adwFunction(const char *name) {
|
|
118
|
+
return reinterpret_cast<Fn>(dlsym(RTLD_DEFAULT, name));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Whether AdwDialog is there to present a sheet with: libadwaita 1.5 or later at run time.
|
|
122
|
+
bool haveAdwDialog();
|
|
123
|
+
|
|
124
|
+
// A CSS class setting `property` ("color" or "background-color") to `color`, added to the display's
|
|
125
|
+
// sheet the first time it is asked for; empty for no colour. The class names its colour, so its rule
|
|
126
|
+
// never goes stale.
|
|
127
|
+
std::string colorClass(const char *property, const facebook::react::SharedColor &color);
|
|
128
|
+
// The rule colorClass adds for a class `name`: the alpha is written with a point in any locale.
|
|
129
|
+
std::string colorRule(const char *name, const char *property, float red, float green, float blue, float alpha);
|
|
130
|
+
|
|
131
|
+
// The header the window of each surface shows.
|
|
132
|
+
class Headers {
|
|
133
|
+
public:
|
|
134
|
+
explicit Headers(GtkBackend &backend) : backend_(backend) {}
|
|
135
|
+
~Headers();
|
|
136
|
+
void show(SurfaceId surfaceId, const std::optional<ScreenStacks::FrontHeader> &header);
|
|
137
|
+
// After a transaction: a header whose config, subviews or props changed is laid out again.
|
|
138
|
+
void refresh();
|
|
139
|
+
// A view went: a header showing it lets it go.
|
|
140
|
+
void forget(Tag tag);
|
|
141
|
+
// The window's split view came or went: its sidebar button with it (split-view.h).
|
|
142
|
+
void refreshChrome(SurfaceId surfaceId);
|
|
143
|
+
// Show Sidebar, from the sidebar button.
|
|
144
|
+
void toggleSidebar(SurfaceId surfaceId);
|
|
145
|
+
// The sidebar button, for tests; null when the window has no split view of its own.
|
|
146
|
+
GtkWidget *sidebarButton(SurfaceId surfaceId) const;
|
|
147
|
+
// A surface went: its header, history and pair with it.
|
|
148
|
+
void removeSurface(SurfaceId surfaceId);
|
|
149
|
+
// The window's history, as the app's router reports it (MenuHost::history), for the pair.
|
|
150
|
+
void setHistory(SurfaceId surfaceId, const std::optional<WindowHistory> &history);
|
|
151
|
+
// What a press of the pair, or an entry chosen from its list, asks of the window's history.
|
|
152
|
+
std::function<void(SurfaceId, NavigationDirection, int steps)> navigate;
|
|
153
|
+
// A chevron pressed: through the history, or, for an app that reports none, the stack's back.
|
|
154
|
+
void pressChevron(SurfaceId surfaceId, NavigationDirection direction);
|
|
155
|
+
// The list of the entries `direction` way, at the chevron, as a secondary click shows it. Whether
|
|
156
|
+
// there was one to show.
|
|
157
|
+
bool showHistoryMenu(SurfaceId surfaceId, NavigationDirection direction);
|
|
158
|
+
// The window's header bar's back and forward chevrons, for tests; null when the pair is not shown.
|
|
159
|
+
GtkWidget *backButton(SurfaceId surfaceId) const;
|
|
160
|
+
GtkWidget *forwardButton(SurfaceId surfaceId) const;
|
|
161
|
+
|
|
162
|
+
private:
|
|
163
|
+
struct Shown {
|
|
164
|
+
std::optional<ScreenStacks::FrontHeader> header;
|
|
165
|
+
// What it was laid out from, against which a refresh is a change.
|
|
166
|
+
std::optional<HeaderBar> bar;
|
|
167
|
+
HeaderLayout layout;
|
|
168
|
+
// The widgets it put in the header bar, and the views moved into slots.
|
|
169
|
+
std::vector<GtkWidget *> packed;
|
|
170
|
+
std::vector<Tag> hosted;
|
|
171
|
+
// The window's history, and the pair it shows.
|
|
172
|
+
std::optional<WindowHistory> history;
|
|
173
|
+
HistoryButtons buttons;
|
|
174
|
+
// The search fields packed at the end, kept across a layout that keeps them.
|
|
175
|
+
std::vector<GtkWidget *> searches;
|
|
176
|
+
GtkWidget *back{nullptr};
|
|
177
|
+
GtkWidget *forward{nullptr};
|
|
178
|
+
GtkWidget *sidebarButton{nullptr};
|
|
179
|
+
// The bar's background colour class.
|
|
180
|
+
std::string background;
|
|
181
|
+
};
|
|
182
|
+
void layOut(SurfaceId surfaceId, Shown &shown);
|
|
183
|
+
void layOutBar(SurfaceId surfaceId, Shown &shown);
|
|
184
|
+
void clear(SurfaceId surfaceId, Shown &shown, bool keepSearches = false);
|
|
185
|
+
GtkWidget *headerBarOf(SurfaceId surfaceId) const;
|
|
186
|
+
|
|
187
|
+
GtkBackend &backend_;
|
|
188
|
+
std::map<SurfaceId, Shown> shown_;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// The <modal>s presented on each surface.
|
|
192
|
+
class Modals {
|
|
193
|
+
public:
|
|
194
|
+
// The shadow tree's view of a modal's content, which sizes a sheet (Runtime::sheetNode).
|
|
195
|
+
using SheetNodes = std::function<std::optional<SheetNode>(SurfaceId, Tag)>;
|
|
196
|
+
|
|
197
|
+
explicit Modals(GtkBackend &backend) : backend_(backend) {}
|
|
198
|
+
~Modals();
|
|
199
|
+
void setSheetNodes(SheetNodes nodes) {
|
|
200
|
+
sheetNodes_ = std::move(nodes);
|
|
201
|
+
}
|
|
202
|
+
// A modal was mounted into the tree: it presents once the transaction has mounted, with its
|
|
203
|
+
// presentation known.
|
|
204
|
+
void mounted(SurfaceId surfaceId, Tag tag);
|
|
205
|
+
// A modal left the tree, or went: it is dismissed.
|
|
206
|
+
void unmounted(Tag tag);
|
|
207
|
+
// The core presents a screen over its stack, or takes it back (ScreenStacks::takePresented): it
|
|
208
|
+
// presents once the transaction has mounted, as a modal does.
|
|
209
|
+
void setPresented(SurfaceId surfaceId, Tag screen, bool presented);
|
|
210
|
+
// After a transaction: presents the modals mounted in it, and fits each sheet to its content.
|
|
211
|
+
// Also as a window changes size, which a sheet stays within and a cover fills.
|
|
212
|
+
void settle();
|
|
213
|
+
// The presentation a modal shows in, for tests: its slot, and whether it is an AdwDialog.
|
|
214
|
+
GtkWidget *slotOf(Tag tag) const;
|
|
215
|
+
bool inDialog(Tag tag) const;
|
|
216
|
+
// Its GtkPopover, and the header bar a presented screen's sheet draws, for tests; null for none.
|
|
217
|
+
GtkWidget *popoverOf(Tag tag) const;
|
|
218
|
+
GtkWidget *sheetHeaderOf(Tag tag) const;
|
|
219
|
+
// What Escape does: presses a sheet's Cancel, or asks the app to close the presentation.
|
|
220
|
+
void requestClose(Tag tag);
|
|
221
|
+
// The presentation shown last over `window`'s surfaces, which Ctrl+W closes before the window, as
|
|
222
|
+
// Cmd-W does on macOS.
|
|
223
|
+
std::optional<Tag> front(GtkWindow *window) const;
|
|
224
|
+
// What Return does: presses a sheet's default button. Whether there was one to press.
|
|
225
|
+
bool pressDefault(Tag tag);
|
|
226
|
+
// Escape over a surface's modals: asks to close the one presented last.
|
|
227
|
+
void requestCloseFront(SurfaceId surfaceId);
|
|
228
|
+
// Return over a surface's modals: presses the default button of the one presented last. Whether it had one.
|
|
229
|
+
bool pressDefaultFront(SurfaceId surfaceId);
|
|
230
|
+
// The window around the cover or drawn sheet in front holds still (holdChrome), and once none is
|
|
231
|
+
// left takes input again. Again after the header bar changes, which may have packed new items.
|
|
232
|
+
void hold(SurfaceId surfaceId);
|
|
233
|
+
|
|
234
|
+
private:
|
|
235
|
+
// The tag of the modal presented last on a surface, or 0.
|
|
236
|
+
Tag frontOf(SurfaceId surfaceId) const;
|
|
237
|
+
struct Presented {
|
|
238
|
+
SurfaceId surfaceId;
|
|
239
|
+
ModalPresentation presentation{ModalPresentation::Sheet};
|
|
240
|
+
// A presented RNSScreen, not a <modal>.
|
|
241
|
+
bool screen{false};
|
|
242
|
+
// When it was presented among the others: the latest is in front.
|
|
243
|
+
uint64_t order{0};
|
|
244
|
+
GtkWidget *slot{nullptr};
|
|
245
|
+
// The AdwDialog, the overlay's backdrop or cover, or the popover.
|
|
246
|
+
GtkWidget *dialog{nullptr};
|
|
247
|
+
GtkWidget *layer{nullptr};
|
|
248
|
+
GtkWidget *popover{nullptr};
|
|
249
|
+
// A sheet's box of its header and the slot, and the header, when the screen has one.
|
|
250
|
+
GtkWidget *card{nullptr};
|
|
251
|
+
GtkWidget *header{nullptr};
|
|
252
|
+
SheetChrome chrome;
|
|
253
|
+
// The name it was last given (presentationLabel).
|
|
254
|
+
std::string label;
|
|
255
|
+
bool labelled{false};
|
|
256
|
+
std::pair<int, int> size{0, 0};
|
|
257
|
+
// Where the focus was, to go back to.
|
|
258
|
+
GtkWidget *opener{nullptr};
|
|
259
|
+
};
|
|
260
|
+
void present(SurfaceId surfaceId, Tag tag);
|
|
261
|
+
void fit(Tag tag, Presented &presented);
|
|
262
|
+
// Brings a presented screen's sheet header and the presentation's label in step with its props.
|
|
263
|
+
void dress(Tag tag, Presented &presented);
|
|
264
|
+
void press(Tag tag, const std::string &buttonId);
|
|
265
|
+
void dismiss(Tag tag);
|
|
266
|
+
|
|
267
|
+
GtkBackend &backend_;
|
|
268
|
+
SheetNodes sheetNodes_;
|
|
269
|
+
std::set<std::pair<SurfaceId, Tag>> pending_;
|
|
270
|
+
std::map<Tag, Presented> presented_;
|
|
271
|
+
uint64_t presentations_{0};
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
#include "scroll-view.h"
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/scrollview/ScrollViewEventEmitter.h>
|
|
4
|
+
#include <react/renderer/components/scrollview/ScrollViewProps.h>
|
|
5
|
+
#include <react/renderer/components/scrollview/ScrollViewState.h>
|
|
6
|
+
#include <react/renderer/core/ConcreteState.h>
|
|
7
|
+
|
|
8
|
+
#include <algorithm>
|
|
9
|
+
#include <optional>
|
|
10
|
+
#include <set>
|
|
11
|
+
#include <utility>
|
|
12
|
+
|
|
13
|
+
using namespace facebook::react;
|
|
14
|
+
|
|
15
|
+
namespace ngn::gtk {
|
|
16
|
+
|
|
17
|
+
namespace {
|
|
18
|
+
|
|
19
|
+
ScrollOffsetChanged gOffsetChanged;
|
|
20
|
+
|
|
21
|
+
using ScrollState = ConcreteState<ScrollViewState>;
|
|
22
|
+
|
|
23
|
+
std::shared_ptr<const ScrollState> stateOf(const ViewData &view) {
|
|
24
|
+
return std::dynamic_pointer_cast<const ScrollState>(view.state);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
GtkAdjustment *horizontal(const ScrollBox &box) {
|
|
28
|
+
return gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(box.scrolled));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
GtkAdjustment *vertical(const ScrollBox &box) {
|
|
32
|
+
return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(box.scrolled));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Point offsetOf(const ScrollBox &box) {
|
|
36
|
+
return {static_cast<Float>(gtk_adjustment_get_value(horizontal(box))), static_cast<Float>(gtk_adjustment_get_value(vertical(box)))};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The part of the view the content shows through: the view less the classic scroll bars' strips.
|
|
40
|
+
Size viewportOf(const ScrollBox &box) {
|
|
41
|
+
auto gutter = ScrollerGutters::shared().get(box.view->tag);
|
|
42
|
+
const auto &frame = box.view->layout.frame.size;
|
|
43
|
+
return {std::max<Float>(0, frame.width - gutter.right), std::max<Float>(0, frame.height - gutter.bottom)};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Gives the view's state the content's offset now. React Native applies a state update later, on
|
|
47
|
+
// the state it then holds, and a later update of the same view replaces one not yet applied: each
|
|
48
|
+
// carries the offset GTK shows, compared with the state it is applied to, never with the one this
|
|
49
|
+
// view last mounted. `relayout` sends it even when the offset is the state's, for a clone that
|
|
50
|
+
// reads a new gutter, and so does each later update until one such clone is applied.
|
|
51
|
+
void syncState(const ScrollBox &box, bool relayout) {
|
|
52
|
+
auto state = stateOf(*box.view);
|
|
53
|
+
if (!state) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (relayout) {
|
|
57
|
+
box.relayoutOwed->store(true);
|
|
58
|
+
}
|
|
59
|
+
Point offset = offsetOf(box);
|
|
60
|
+
// React Native runs an update's callback again when its commit is retried: the update takes the
|
|
61
|
+
// owed relayout once, and each run after answers as the first did.
|
|
62
|
+
auto takes = std::make_shared<std::optional<bool>>();
|
|
63
|
+
state->updateState([offset, owed = box.relayoutOwed, takes](const ScrollViewState &old) -> StateData::Shared {
|
|
64
|
+
if (!takes->has_value()) {
|
|
65
|
+
*takes = owed->exchange(false);
|
|
66
|
+
}
|
|
67
|
+
if (!**takes && old.contentOffset == offset) {
|
|
68
|
+
return nullptr;
|
|
69
|
+
}
|
|
70
|
+
auto data = std::make_shared<ScrollViewState>(old);
|
|
71
|
+
data->contentOffset = offset;
|
|
72
|
+
return data;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
void scrolled(GtkAdjustment *, gpointer user) {
|
|
77
|
+
auto *box = static_cast<ScrollBox *>(user);
|
|
78
|
+
if (!box->view) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
Point offset = offsetOf(*box);
|
|
82
|
+
if (gOffsetChanged) {
|
|
83
|
+
gOffsetChanged(box->view->tag, offset);
|
|
84
|
+
}
|
|
85
|
+
syncState(*box, false);
|
|
86
|
+
if (auto emitter = std::dynamic_pointer_cast<const ScrollViewEventEmitter>(box->view->emitter)) {
|
|
87
|
+
ScrollEvent event;
|
|
88
|
+
event.contentOffset = offset;
|
|
89
|
+
event.contentSize = box->content;
|
|
90
|
+
event.containerSize = box->view->layout.frame.size;
|
|
91
|
+
event.zoomScale = 1;
|
|
92
|
+
event.timestamp = static_cast<double>(g_get_monotonic_time()) / G_USEC_PER_SEC;
|
|
93
|
+
emitter->onScroll(event);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Moves the content to `target`, kept within it. The adjustments are given the content's and the
|
|
98
|
+
// viewport's sizes first, which GTK's own layout gives them only on the next frame.
|
|
99
|
+
void moveTo(ScrollBox &box, Point target) {
|
|
100
|
+
Size page = viewportOf(box);
|
|
101
|
+
auto set = [](GtkAdjustment *adjustment, double value, double content, double page) {
|
|
102
|
+
double upper = std::max(content, page);
|
|
103
|
+
gtk_adjustment_configure(adjustment, std::clamp(value, 0.0, upper - page), 0, upper, page * 0.1, page * 0.9, page);
|
|
104
|
+
};
|
|
105
|
+
set(horizontal(box), target.x, box.content.width, page.width);
|
|
106
|
+
set(vertical(box), target.y, box.content.height, page.height);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// The starting offset the props ask for, within the content, once there is content to scroll.
|
|
110
|
+
void applyPendingOffset(ScrollBox &box) {
|
|
111
|
+
Size page = viewportOf(box);
|
|
112
|
+
if (!box.pendingOffset || box.content.width <= 0 || box.content.height <= 0 || page.width <= 0 || page.height <= 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
Point target = *box.pendingOffset;
|
|
116
|
+
box.pendingOffset.reset();
|
|
117
|
+
moveTo(box, target);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// After the rest of this mount: its state and its layout, which come after the props, give the
|
|
121
|
+
// content's size and the view's. Once, however many of them change.
|
|
122
|
+
void applyPendingOffsetAfterMount(ScrollBox &box) {
|
|
123
|
+
if (!box.pendingOffset || box.pendingSource != 0) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
box.pendingSource = g_idle_add_full(
|
|
127
|
+
G_PRIORITY_DEFAULT,
|
|
128
|
+
[](gpointer user) -> gboolean {
|
|
129
|
+
auto *box = static_cast<ScrollBox *>(user);
|
|
130
|
+
box->pendingSource = 0;
|
|
131
|
+
applyPendingOffset(*box);
|
|
132
|
+
return G_SOURCE_REMOVE;
|
|
133
|
+
},
|
|
134
|
+
&box, nullptr);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// GTK's wheel, drag and kinetic controllers on the scrolled window, on or off. Off, the wheel goes
|
|
138
|
+
// on to a scroll view around it, as on macOS.
|
|
139
|
+
void enableControllers(ScrollBox &box, bool enabled) {
|
|
140
|
+
if (box.enabled == enabled) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
box.enabled = enabled;
|
|
144
|
+
for (auto &[controller, phase] : box.controllers) {
|
|
145
|
+
// GTK moves some of them itself (the drag gesture follows kinetic scrolling): each goes back to
|
|
146
|
+
// the phase it had as it was turned off.
|
|
147
|
+
if (!enabled) {
|
|
148
|
+
phase = gtk_event_controller_get_propagation_phase(controller);
|
|
149
|
+
}
|
|
150
|
+
gtk_event_controller_set_propagation_phase(controller, enabled ? phase : GTK_PHASE_NONE);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Every scroll view's box, which a change to the desktop's scroll bars reaches.
|
|
155
|
+
std::set<ScrollBox *> &scrollBoxes() {
|
|
156
|
+
static std::set<ScrollBox *> boxes;
|
|
157
|
+
return boxes;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// `scrollbar-width: thin`: a narrower slider, which a classic scroll bar's gutter follows.
|
|
161
|
+
void installThinScrollbars() {
|
|
162
|
+
static bool installed = false;
|
|
163
|
+
if (installed || !gdk_display_get_default()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
installed = true;
|
|
167
|
+
GtkCssProvider *css = gtk_css_provider_new();
|
|
168
|
+
gtk_css_provider_load_from_data(
|
|
169
|
+
css,
|
|
170
|
+
"scrolledwindow.ngn-thin-scrollbars > scrollbar slider { margin: 0; border-width: 1px; }"
|
|
171
|
+
// Only the thickness narrows: the theme's minimum length along the scrolling axis stays, so
|
|
172
|
+
// the thumb of a long document remains big enough to grab.
|
|
173
|
+
"scrolledwindow.ngn-thin-scrollbars > scrollbar.vertical slider { min-width: 3px; }"
|
|
174
|
+
"scrolledwindow.ngn-thin-scrollbars > scrollbar.horizontal slider { min-height: 3px; }"
|
|
175
|
+
"scrolledwindow.ngn-thin-scrollbars > scrollbar { padding: 0; }",
|
|
176
|
+
-1);
|
|
177
|
+
gtk_style_context_add_provider_for_display(gdk_display_get_default(), GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
178
|
+
g_object_unref(css);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// A new scroll bar style applies as GTK next draws, and Adwaita eases a scroll bar's width into
|
|
182
|
+
// it: the gutter is measured again after each frame until the width has held for 10 frames, for
|
|
183
|
+
// at most 120.
|
|
184
|
+
void remeasureAfterFrames(ScrollBox *box) {
|
|
185
|
+
// Only a classic scroll bar takes a gutter, whose width this is.
|
|
186
|
+
if (scrollerStyle(box->scrolled) != ScrollerStyle::Legacy) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
GdkFrameClock *clock = gtk_widget_get_frame_clock(box->scrolled);
|
|
190
|
+
box->remeasureFrames = 120;
|
|
191
|
+
box->steadyFrames = 0;
|
|
192
|
+
box->measuredWidth = -1;
|
|
193
|
+
if (!clock) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (box->remeasure != 0) {
|
|
197
|
+
if (box->remeasureClock == clock) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
// Moved to another window while measuring: the old clock may never paint again.
|
|
201
|
+
g_signal_handlers_disconnect_by_data(box->remeasureClock, box);
|
|
202
|
+
box->remeasure = 0;
|
|
203
|
+
g_clear_object(&box->remeasureClock);
|
|
204
|
+
}
|
|
205
|
+
box->remeasureClock = GDK_FRAME_CLOCK(g_object_ref(clock));
|
|
206
|
+
box->remeasure = g_signal_connect(clock, "after-paint", G_CALLBACK(+[](GdkFrameClock *clock, gpointer data) {
|
|
207
|
+
auto *box = static_cast<ScrollBox *>(data);
|
|
208
|
+
float width = classicScrollerWidth(box->scrolled);
|
|
209
|
+
box->steadyFrames = width == box->measuredWidth ? box->steadyFrames + 1 : 0;
|
|
210
|
+
bool settled = box->steadyFrames >= 10 || --box->remeasureFrames <= 0;
|
|
211
|
+
box->measuredWidth = width;
|
|
212
|
+
updateScrollers(*box->view);
|
|
213
|
+
if (settled) {
|
|
214
|
+
g_signal_handler_disconnect(clock, std::exchange(box->remeasure, 0));
|
|
215
|
+
g_clear_object(&box->remeasureClock);
|
|
216
|
+
} else {
|
|
217
|
+
gtk_widget_queue_draw(box->scrolled);
|
|
218
|
+
}
|
|
219
|
+
}), box);
|
|
220
|
+
gtk_widget_queue_draw(box->scrolled);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// The desktop switching between overlay and classic scroll bars: every scroll view's gutter
|
|
224
|
+
// follows, as GTK's own scroll bars do.
|
|
225
|
+
void watchScrollerStyle(GtkWidget *widget) {
|
|
226
|
+
static bool watching = false;
|
|
227
|
+
if (watching) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
watching = true;
|
|
231
|
+
g_signal_connect(gtk_widget_get_settings(widget), "notify::gtk-overlay-scrolling", G_CALLBACK(+[](GObject *, GParamSpec *, gpointer) {
|
|
232
|
+
for (ScrollBox *box : scrollBoxes()) {
|
|
233
|
+
updateScrollers(*box->view);
|
|
234
|
+
remeasureAfterFrames(box);
|
|
235
|
+
}
|
|
236
|
+
}), nullptr);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
} // namespace
|
|
240
|
+
|
|
241
|
+
void onScrollOffset(ScrollOffsetChanged changed) {
|
|
242
|
+
gOffsetChanged = std::move(changed);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
ScrollerStyle scrollerStyle(GtkWidget *widget) {
|
|
246
|
+
gboolean overlay = TRUE;
|
|
247
|
+
g_object_get(gtk_widget_get_settings(widget), "gtk-overlay-scrolling", &overlay, nullptr);
|
|
248
|
+
return overlay ? ScrollerStyle::Overlay : ScrollerStyle::Legacy;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
float classicScrollerWidth(GtkWidget *scrolled) {
|
|
252
|
+
int minimum = 0, natural = 0;
|
|
253
|
+
GtkWidget *bar = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(scrolled));
|
|
254
|
+
gtk_widget_measure(bar, GTK_ORIENTATION_HORIZONTAL, -1, &minimum, &natural, nullptr, nullptr);
|
|
255
|
+
return static_cast<float>(natural);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void makeScrollView(GtkWidget *widget, ViewData &view) {
|
|
259
|
+
auto *box = new ScrollBox();
|
|
260
|
+
box->view = &view;
|
|
261
|
+
box->scrolled = gtk_scrolled_window_new();
|
|
262
|
+
box->document = makeViewWidget();
|
|
263
|
+
viewData(box->document)->documentOf = box;
|
|
264
|
+
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(box->scrolled), box->document);
|
|
265
|
+
gtk_scrolled_window_set_propagate_natural_width(GTK_SCROLLED_WINDOW(box->scrolled), FALSE);
|
|
266
|
+
gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(box->scrolled), FALSE);
|
|
267
|
+
gtk_widget_set_parent(box->scrolled, widget);
|
|
268
|
+
GListModel *controllers = gtk_widget_observe_controllers(box->scrolled);
|
|
269
|
+
for (guint i = 0, n = g_list_model_get_n_items(controllers); i < n; ++i) {
|
|
270
|
+
auto *controller = GTK_EVENT_CONTROLLER(g_list_model_get_item(controllers, i));
|
|
271
|
+
box->controllers.emplace_back(controller, gtk_event_controller_get_propagation_phase(controller));
|
|
272
|
+
// The scrolled window keeps it.
|
|
273
|
+
g_object_unref(controller);
|
|
274
|
+
}
|
|
275
|
+
g_object_unref(controllers);
|
|
276
|
+
g_signal_connect(horizontal(*box), "value-changed", G_CALLBACK(scrolled), box);
|
|
277
|
+
g_signal_connect(vertical(*box), "value-changed", G_CALLBACK(scrolled), box);
|
|
278
|
+
view.scroll = box;
|
|
279
|
+
scrollBoxes().insert(box);
|
|
280
|
+
watchScrollerStyle(box->scrolled);
|
|
281
|
+
// Measured before it had a style of its own (`thin`, or the display's): again once it shows.
|
|
282
|
+
g_signal_connect(box->scrolled, "map", G_CALLBACK(+[](GtkWidget *, gpointer data) { remeasureAfterFrames(static_cast<ScrollBox *>(data)); }), box);
|
|
283
|
+
applyScrollViewProps(view);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
void destroyScrollView(ViewData &view) {
|
|
287
|
+
ScrollBox *box = std::exchange(view.scroll, nullptr);
|
|
288
|
+
if (!box) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (box->pendingSource != 0) {
|
|
292
|
+
g_source_remove(box->pendingSource);
|
|
293
|
+
}
|
|
294
|
+
g_signal_handlers_disconnect_by_data(horizontal(*box), box);
|
|
295
|
+
g_signal_handlers_disconnect_by_data(vertical(*box), box);
|
|
296
|
+
if (ViewData *document = viewData(box->document)) {
|
|
297
|
+
document->documentOf = nullptr;
|
|
298
|
+
}
|
|
299
|
+
ScrollerGutters::shared().remove(view.tag);
|
|
300
|
+
scrollBoxes().erase(box);
|
|
301
|
+
g_signal_handlers_disconnect_by_data(box->scrolled, box);
|
|
302
|
+
if (box->remeasure != 0) {
|
|
303
|
+
// A window destroyed meanwhile has already dropped its clock's handlers.
|
|
304
|
+
g_signal_handlers_disconnect_by_data(box->remeasureClock, box);
|
|
305
|
+
g_clear_object(&box->remeasureClock);
|
|
306
|
+
}
|
|
307
|
+
if (gtk_widget_get_parent(box->scrolled)) {
|
|
308
|
+
gtk_widget_unparent(box->scrolled);
|
|
309
|
+
}
|
|
310
|
+
delete box;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
GtkWidget *contentWidget(GtkWidget *widget) {
|
|
314
|
+
ViewData *view = viewData(widget);
|
|
315
|
+
return view && view->scroll ? view->scroll->document : widget;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
void applyScrollViewProps(ViewData &view) {
|
|
319
|
+
auto props = std::dynamic_pointer_cast<const ScrollViewProps>(view.props);
|
|
320
|
+
ScrollBox *box = view.scroll;
|
|
321
|
+
if (!props || !box) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
box->showsVertical = props->showsVerticalScrollIndicator;
|
|
325
|
+
box->showsHorizontal = props->showsHorizontalScrollIndicator;
|
|
326
|
+
enableControllers(*box, props->scrollEnabled);
|
|
327
|
+
updateScrollers(view);
|
|
328
|
+
if (box->offsetProp != props->contentOffset) {
|
|
329
|
+
bool first = !box->offsetProp;
|
|
330
|
+
box->offsetProp = props->contentOffset;
|
|
331
|
+
if (!first || props->contentOffset != Point{}) {
|
|
332
|
+
box->pendingOffset = props->contentOffset;
|
|
333
|
+
}
|
|
334
|
+
applyPendingOffsetAfterMount(*box);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
void applyScrollViewState(ViewData &view) {
|
|
339
|
+
ScrollBox *box = view.scroll;
|
|
340
|
+
auto state = stateOf(view);
|
|
341
|
+
if (!box || !state) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
Size content = state->getData().getContentSize();
|
|
345
|
+
if (content != box->content) {
|
|
346
|
+
box->content = content;
|
|
347
|
+
gtk_widget_queue_resize(box->document);
|
|
348
|
+
}
|
|
349
|
+
updateScrollers(view);
|
|
350
|
+
applyPendingOffsetAfterMount(*box);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
void updateScrollers(ViewData &view) {
|
|
354
|
+
ScrollBox *box = view.scroll;
|
|
355
|
+
if (!box) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
auto visibility = scrollerVisibility(view.desktop, box->showsVertical, box->showsHorizontal, box->content, view.layout.frame.size);
|
|
359
|
+
auto policy = [&visibility](bool shown) {
|
|
360
|
+
// A scroll bar not shown still scrolls, by the wheel and the keyboard.
|
|
361
|
+
return !shown ? GTK_POLICY_EXTERNAL : visibility.autohides ? GTK_POLICY_AUTOMATIC : GTK_POLICY_ALWAYS;
|
|
362
|
+
};
|
|
363
|
+
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box->scrolled), policy(visibility.horizontal), policy(visibility.vertical));
|
|
364
|
+
installThinScrollbars();
|
|
365
|
+
bool thin = view.desktop.scrollbarWidth == ScrollbarWidth::Thin;
|
|
366
|
+
if (thin != gtk_widget_has_css_class(box->scrolled, "ngn-thin-scrollbars")) {
|
|
367
|
+
if (thin) {
|
|
368
|
+
gtk_widget_add_css_class(box->scrolled, "ngn-thin-scrollbars");
|
|
369
|
+
} else {
|
|
370
|
+
gtk_widget_remove_css_class(box->scrolled, "ngn-thin-scrollbars");
|
|
371
|
+
}
|
|
372
|
+
remeasureAfterFrames(box);
|
|
373
|
+
}
|
|
374
|
+
auto style = scrollerStyle(box->scrolled);
|
|
375
|
+
auto gutter = scrollerGutter(style, style == ScrollerStyle::Legacy ? classicScrollerWidth(box->scrolled) : 0, visibility);
|
|
376
|
+
// Recorded only once there is a state to update, so a gutter is never recorded that no layout
|
|
377
|
+
// has asked for. A state update clones the scroll view's node, which reads its gutter.
|
|
378
|
+
if (stateOf(view) && ScrollerGutters::shared().set(view.tag, gutter)) {
|
|
379
|
+
syncState(*box, true);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
void allocateScrollView(ViewData &view, int width, int height) {
|
|
384
|
+
if (view.scroll) {
|
|
385
|
+
gtk_widget_allocate(view.scroll->scrolled, width, height, -1, nullptr);
|
|
386
|
+
// A starting offset that waited for a view with a size is tried again once it has one.
|
|
387
|
+
applyPendingOffsetAfterMount(*view.scroll);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
void scrollViewCommand(ViewData &view, const std::string &name, const folly::dynamic &args) {
|
|
392
|
+
ScrollBox *box = view.scroll;
|
|
393
|
+
if (!box) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (name == "scrollTo" && args.isArray() && args.size() >= 2 && args[0].isNumber() && args[1].isNumber()) {
|
|
397
|
+
// A starting offset still waiting would move the content back after the command.
|
|
398
|
+
box->pendingOffset.reset();
|
|
399
|
+
moveTo(*box, {static_cast<Float>(args[0].asDouble()), static_cast<Float>(args[1].asDouble())});
|
|
400
|
+
} else if (name == "scrollToEnd") {
|
|
401
|
+
Size page = viewportOf(*box);
|
|
402
|
+
Point target = offsetOf(*box);
|
|
403
|
+
// The end along the axis the content overflows, down before across, as on macOS.
|
|
404
|
+
if (box->content.height > page.height) {
|
|
405
|
+
target.y = box->content.height - page.height;
|
|
406
|
+
} else {
|
|
407
|
+
target.x = std::max<Float>(0, box->content.width - page.width);
|
|
408
|
+
}
|
|
409
|
+
box->pendingOffset.reset();
|
|
410
|
+
moveTo(*box, target);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
} // namespace ngn::gtk
|