@ng-native/desktop 0.24.0 → 0.26.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/bin/package.mjs +65 -9
- package/bin/prebuilt.mjs +25 -4
- package/native/CMakeLists.txt +51 -4
- package/native/appkit/CMakeLists.txt +16 -2
- package/native/appkit/appkit-backend.mm +28 -3
- package/native/appkit/cg-canvas.h +5 -0
- package/native/appkit/cg-canvas.mm +21 -6
- package/native/appkit/desktop-expo.h +6 -0
- package/native/appkit/desktop-expo.mm +5 -0
- package/native/appkit/host-view.mm +32 -0
- package/native/appkit/image-request.h +2 -10
- package/native/appkit/image-request.mm +0 -22
- package/native/appkit/image-view.mm +121 -4
- package/native/appkit/main.mm +130 -185
- package/native/appkit/scroll-view.mm +57 -16
- package/native/appkit/scrollers.h +22 -2
- package/native/appkit/scrollers.mm +221 -2
- package/native/appkit/split-view.h +4 -0
- package/native/appkit/split-view.mm +60 -12
- package/native/appkit/system-access.mm +3 -0
- package/native/appkit/system.mm +33 -48
- package/native/appkit/text-layout.h +6 -0
- package/native/appkit/text-layout.mm +147 -24
- package/native/appkit/view-effects.h +27 -0
- package/native/appkit/view-effects.mm +90 -0
- package/native/cmake/react-native.cmake +9 -0
- package/native/cmake/runtime-dependencies.cmake +32 -1
- package/native/core/include/ngn/app-info.h +3 -2
- package/native/core/include/ngn/app-menus.h +5 -11
- package/native/core/include/ngn/default-menu.h +16 -6
- package/native/core/include/ngn/desktop-expo.h +0 -5
- package/native/core/include/ngn/desktop-modules.h +144 -0
- package/native/core/include/ngn/dev-server.h +12 -3
- package/native/core/include/ngn/host-os.h +45 -0
- package/native/core/include/ngn/host-views.h +25 -0
- package/native/core/include/ngn/image-source.h +18 -0
- package/native/core/include/ngn/launch-settings.h +9 -7
- package/native/core/include/ngn/module-registry.h +2 -0
- package/native/core/include/ngn/notifications.h +6 -0
- package/native/core/include/ngn/runtime.h +4 -1
- package/native/core/include/ngn/scrollers.h +5 -0
- package/native/core/include/ngn/spawn-rules.h +3 -2
- package/native/core/include/ngn/split-view.h +12 -0
- package/native/core/include/ngn/system.h +47 -0
- package/native/core/include/ngn/text-measurer.h +11 -0
- package/native/core/include/ngn/undo.h +27 -0
- package/native/core/include/ngn/updates.h +3 -2
- package/native/core/include/ngn/view-filter.h +33 -0
- package/native/core/src/app-menus.cpp +9 -11
- package/native/core/src/default-menu.cpp +6 -2
- package/native/core/src/dev-server-helper.cpp +3 -2
- package/native/core/src/dev-server.cpp +22 -5
- package/native/core/src/host-os.cpp +20 -0
- package/native/core/src/host-views.cpp +25 -0
- package/native/core/src/image-source.cpp +30 -0
- package/native/core/src/launch-settings.cpp +10 -6
- package/native/core/src/module-registry.cpp +9 -0
- package/native/core/src/modules/app-info.cpp +4 -4
- package/native/core/src/modules/app-modules.cpp +4 -2
- package/native/core/src/modules/desktop-expo.cpp +0 -5
- package/native/core/src/modules/desktop-modules.cpp +132 -0
- package/native/core/src/modules/notifications.cpp +4 -4
- package/native/core/src/runtime.cpp +2 -0
- package/native/core/src/scrollers.cpp +11 -0
- package/native/core/src/spawn-rules.cpp +1 -4
- package/native/core/src/split-view.cpp +10 -0
- package/native/core/src/system.cpp +52 -0
- package/native/core/src/text-layout-manager.cpp +13 -0
- package/native/core/src/undo-stacks.cpp +71 -0
- package/native/core/src/view-filter.cpp +114 -0
- package/native/scripts/build-hermes.sh +19 -7
- package/native/scripts/build-icu.sh +36 -0
- package/native/scripts/build-lock.sh +21 -0
- package/native/scripts/build.sh +46 -7
- package/native/scripts/fetch-hermes.sh +70 -0
- package/native/scripts/fetch.sh +24 -2
- package/native/scripts/hermes-built.sh +5 -4
- package/native/scripts/hermes-target.sh +18 -0
- package/native/scripts/icu-filter.json +22 -0
- package/native/scripts/make-prebuilt.mjs +13 -6
- package/native/scripts/prebuilt-host-cache.mjs +1 -1
- package/native/shim/openssl/sha.h +108 -3
- package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
- package/package.json +2 -2
- package/prebuilt.json +6 -6
|
@@ -65,6 +65,9 @@ std::function<void(NSInteger, CGPoint)> gOffsetChanged;
|
|
|
65
65
|
object:_scrollView.contentView];
|
|
66
66
|
[self addSubview:_scrollView];
|
|
67
67
|
__weak NGNScrollView *weakSelf = self;
|
|
68
|
+
_scrollView.phaseChanged = ^(NGNScrollPhase phase, NSPoint velocity) {
|
|
69
|
+
[weakSelf report:phase velocity:velocity];
|
|
70
|
+
};
|
|
68
71
|
_styleObserver = [[NGNScrollerStyleObserver alloc] initWithChanged:^{
|
|
69
72
|
[weakSelf updateScrollers];
|
|
70
73
|
}];
|
|
@@ -94,6 +97,7 @@ std::function<void(NSInteger, CGPoint)> gOffsetChanged;
|
|
|
94
97
|
_scrollView.horizontalScrollElasticity = _scrollView.verticalScrollElasticity;
|
|
95
98
|
// The inner scroll view takes the wheel before this view does.
|
|
96
99
|
_scrollView.scrollingDisabled = !p->scrollEnabled;
|
|
100
|
+
_scrollView.pagingEnabled = p->pagingEnabled;
|
|
97
101
|
if (_offsetProp != p->contentOffset) {
|
|
98
102
|
bool first = !_offsetProp;
|
|
99
103
|
_offsetProp = p->contentOffset;
|
|
@@ -198,15 +202,6 @@ std::function<void(NSInteger, CGPoint)> gOffsetChanged;
|
|
|
198
202
|
[self applyPendingOffsetAfterMount];
|
|
199
203
|
}
|
|
200
204
|
|
|
201
|
-
- (void)scrollWheel:(NSEvent *)event {
|
|
202
|
-
auto p = std::dynamic_pointer_cast<const ScrollViewProps>(self.props);
|
|
203
|
-
if (p && !p->scrollEnabled) {
|
|
204
|
-
[self.nextResponder scrollWheel:event];
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
[_scrollView scrollWheel:event];
|
|
208
|
-
}
|
|
209
|
-
|
|
210
205
|
- (void)boundsDidChange:(NSNotification *)note {
|
|
211
206
|
NSPoint origin = _scrollView.contentView.bounds.origin;
|
|
212
207
|
if (gOffsetChanged) {
|
|
@@ -220,13 +215,45 @@ std::function<void(NSInteger, CGPoint)> gOffsetChanged;
|
|
|
220
215
|
}
|
|
221
216
|
auto emitter = std::dynamic_pointer_cast<const ScrollViewEventEmitter>(self.eventEmitter);
|
|
222
217
|
if (emitter) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
218
|
+
emitter->onScroll([self scrollEvent]);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
- (ScrollEvent)scrollEvent {
|
|
223
|
+
NSPoint origin = _scrollView.contentView.bounds.origin;
|
|
224
|
+
ScrollEvent event;
|
|
225
|
+
event.contentOffset = {static_cast<Float>(origin.x), static_cast<Float>(origin.y)};
|
|
226
|
+
event.contentSize = {static_cast<Float>(_document.frame.size.width), static_cast<Float>(_document.frame.size.height)};
|
|
227
|
+
event.containerSize = {static_cast<Float>(self.bounds.size.width), static_cast<Float>(self.bounds.size.height)};
|
|
228
|
+
event.zoomScale = 1;
|
|
229
|
+
event.timestamp = NSProcessInfo.processInfo.systemUptime;
|
|
230
|
+
return event;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// A trackpad gesture's drag and momentum, as onScrollBeginDrag, onScrollEndDrag,
|
|
234
|
+
// onMomentumScrollBegin and onMomentumScrollEnd report a touch's on iOS.
|
|
235
|
+
- (void)report:(NGNScrollPhase)phase velocity:(NSPoint)velocity {
|
|
236
|
+
auto emitter = std::dynamic_pointer_cast<const ScrollViewEventEmitter>(self.eventEmitter);
|
|
237
|
+
if (!emitter) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
switch (phase) {
|
|
241
|
+
case NGNScrollPhaseDragBegan:
|
|
242
|
+
emitter->onScrollBeginDrag([self scrollEvent]);
|
|
243
|
+
break;
|
|
244
|
+
case NGNScrollPhaseDragEnded: {
|
|
245
|
+
ScrollEndDragEvent event([self scrollEvent]);
|
|
246
|
+
event.velocity = {static_cast<Float>(velocity.x), static_cast<Float>(velocity.y)};
|
|
247
|
+
event.targetContentOffset = event.contentOffset;
|
|
248
|
+
emitter->onScrollEndDrag(event);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case NGNScrollPhaseMomentumBegan:
|
|
252
|
+
emitter->onMomentumScrollBegin([self scrollEvent]);
|
|
253
|
+
break;
|
|
254
|
+
case NGNScrollPhaseMomentumEnded:
|
|
255
|
+
emitter->onMomentumScrollEnd([self scrollEvent]);
|
|
256
|
+
break;
|
|
230
257
|
}
|
|
231
258
|
}
|
|
232
259
|
|
|
@@ -244,6 +271,20 @@ std::function<void(NSInteger, CGPoint)> gOffsetChanged;
|
|
|
244
271
|
} else {
|
|
245
272
|
return;
|
|
246
273
|
}
|
|
274
|
+
// scrollTo's third argument, and scrollToEnd's only one, is whether it animates.
|
|
275
|
+
const auto &animated = name == "scrollTo" ? (args.size() >= 3 ? args[2] : folly::dynamic()) : (args.isArray() && !args.empty() ? args[0] : folly::dynamic());
|
|
276
|
+
if (animated.isBool() && animated.asBool()) {
|
|
277
|
+
NGNWheelScrollView *scroll = _scrollView;
|
|
278
|
+
[NSAnimationContext
|
|
279
|
+
runAnimationGroup:^(NSAnimationContext *context) {
|
|
280
|
+
context.duration = 0.3;
|
|
281
|
+
clip.animator.boundsOrigin = target;
|
|
282
|
+
}
|
|
283
|
+
completionHandler:^{
|
|
284
|
+
[scroll reflectScrolledClipView:clip];
|
|
285
|
+
}];
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
247
288
|
[clip scrollToPoint:target];
|
|
248
289
|
[_scrollView reflectScrolledClipView:clip];
|
|
249
290
|
}
|
|
@@ -18,8 +18,28 @@ float NGNLegacyScrollerWidth(BOOL thin);
|
|
|
18
18
|
- (instancetype)initWithChanged:(void (^)(void))changed;
|
|
19
19
|
@end
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
|
|
21
|
+
// Where a trackpad scroll is, as a scroll view's drag and momentum events report it.
|
|
22
|
+
typedef NS_ENUM(NSInteger, NGNScrollPhase) {
|
|
23
|
+
NGNScrollPhaseDragBegan,
|
|
24
|
+
NGNScrollPhaseDragEnded,
|
|
25
|
+
NGNScrollPhaseMomentumBegan,
|
|
26
|
+
NGNScrollPhaseMomentumEnded,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// A scroll view's NSScrollView, which takes a wheel turn before the view holding it. A turn goes
|
|
30
|
+
// past it, up the responder chain, with `scrollingDisabled` (`scrollEnabled={false}`), or when the
|
|
31
|
+
// content cannot scroll along the turn's axis: a vertical turn over a horizontal scroll view
|
|
32
|
+
// scrolls the one around it. A trackpad gesture is routed once, as it begins, and its momentum
|
|
33
|
+
// follows it. A view drawn mirrored (an inverted list's scale of -1) scrolls by mirrored deltas, so
|
|
34
|
+
// the content follows the fingers, and the user's scroll direction, as drawn.
|
|
23
35
|
@interface NGNWheelScrollView : NSScrollView
|
|
24
36
|
@property (nonatomic) BOOL scrollingDisabled;
|
|
37
|
+
// `pagingEnabled`: a gesture's end settles on a page, the view's size along the axis.
|
|
38
|
+
@property (nonatomic) BOOL pagingEnabled;
|
|
39
|
+
// Called as a trackpad gesture this view scrolls with begins and ends, and as its momentum, or a
|
|
40
|
+
// page settling, begins and ends. `velocity` is the drag's at its end, in points a millisecond.
|
|
41
|
+
@property (nonatomic, copy) void (^phaseChanged)(NGNScrollPhase phase, NSPoint velocity);
|
|
25
42
|
@end
|
|
43
|
+
|
|
44
|
+
// `event` with its deltas along the axes given turned round.
|
|
45
|
+
NSEvent *NGNMirroredScroll(NSEvent *event, BOOL x, BOOL y);
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
#import "scrollers.h"
|
|
2
2
|
|
|
3
|
+
#import <QuartzCore/QuartzCore.h>
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <cmath>
|
|
7
|
+
|
|
3
8
|
ngn::ScrollerStyle NGNPreferredScrollerStyle() {
|
|
4
9
|
return NSScroller.preferredScrollerStyle == NSScrollerStyleLegacy ? ngn::ScrollerStyle::Legacy
|
|
5
10
|
: ngn::ScrollerStyle::Overlay;
|
|
@@ -32,12 +37,226 @@ float NGNLegacyScrollerWidth(BOOL thin) {
|
|
|
32
37
|
|
|
33
38
|
@end
|
|
34
39
|
|
|
35
|
-
|
|
40
|
+
NSEvent *NGNMirroredScroll(NSEvent *event, BOOL x, BOOL y) {
|
|
41
|
+
if ((!x && !y) || event.CGEvent == nullptr) {
|
|
42
|
+
return event;
|
|
43
|
+
}
|
|
44
|
+
CGEventRef cg = CGEventCreateCopy(event.CGEvent);
|
|
45
|
+
// Setting the lines recomputes the other two from them, so all three are read first and set in
|
|
46
|
+
// this order. The points are read as a double, which keeps a trackpad's fractions.
|
|
47
|
+
auto negate = [cg](CGEventField lines, CGEventField fixed, CGEventField points) {
|
|
48
|
+
int64_t l = CGEventGetIntegerValueField(cg, lines);
|
|
49
|
+
double f = CGEventGetDoubleValueField(cg, fixed), p = CGEventGetDoubleValueField(cg, points);
|
|
50
|
+
CGEventSetIntegerValueField(cg, lines, -l);
|
|
51
|
+
CGEventSetDoubleValueField(cg, fixed, -f);
|
|
52
|
+
CGEventSetDoubleValueField(cg, points, -p);
|
|
53
|
+
};
|
|
54
|
+
if (y) {
|
|
55
|
+
negate(kCGScrollWheelEventDeltaAxis1, kCGScrollWheelEventFixedPtDeltaAxis1, kCGScrollWheelEventPointDeltaAxis1);
|
|
56
|
+
}
|
|
57
|
+
if (x) {
|
|
58
|
+
negate(kCGScrollWheelEventDeltaAxis2, kCGScrollWheelEventFixedPtDeltaAxis2, kCGScrollWheelEventPointDeltaAxis2);
|
|
59
|
+
}
|
|
60
|
+
NSEvent *mirrored = [NSEvent eventWithCGEvent:cg];
|
|
61
|
+
CFRelease(cg);
|
|
62
|
+
return mirrored != nil ? mirrored : event;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@implementation NGNWheelScrollView {
|
|
66
|
+
// The gesture under way goes up the responder chain: it began along an axis this view cannot
|
|
67
|
+
// scroll along.
|
|
68
|
+
BOOL _passing;
|
|
69
|
+
// A gesture's start with no deltas yet, held until an event says which axis it goes along.
|
|
70
|
+
NSEvent *_heldStart;
|
|
71
|
+
// The gesture under way ended in a page settling, so its momentum moves nothing.
|
|
72
|
+
BOOL _settling;
|
|
73
|
+
// A drag has begun and not yet ended: an end with no beginning (a touch that never moved) reports
|
|
74
|
+
// nothing and settles nothing.
|
|
75
|
+
BOOL _dragging;
|
|
76
|
+
NSPoint _velocity;
|
|
77
|
+
NSTimeInterval _lastWheel;
|
|
78
|
+
// When the deltas last moved: a drag held still before it ends was not flicked.
|
|
79
|
+
NSTimeInterval _lastMove;
|
|
80
|
+
// Moved on by each page settling, so only the latest one's end is reported.
|
|
81
|
+
uint64_t _settle;
|
|
82
|
+
BOOL _settleUnderway;
|
|
83
|
+
// A mouse's wheel queued a settling that has not run.
|
|
84
|
+
BOOL _settleQueued;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
- (void)setPagingEnabled:(BOOL)pagingEnabled {
|
|
88
|
+
_pagingEnabled = pagingEnabled;
|
|
89
|
+
if (!pagingEnabled) {
|
|
90
|
+
[self dropSettle];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Whether the content overflows the view along the axis the deltas mostly go along.
|
|
95
|
+
- (BOOL)scrollsAlong:(NSEvent *)event {
|
|
96
|
+
NSSize content = self.documentView.frame.size, view = self.contentView.bounds.size;
|
|
97
|
+
if (std::fabs(event.scrollingDeltaX) > std::fabs(event.scrollingDeltaY)) {
|
|
98
|
+
return content.width > view.width + 0.5;
|
|
99
|
+
}
|
|
100
|
+
return content.height > view.height + 0.5;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Whether the view is drawn mirrored along each axis: an odd number of the layers above it scaled
|
|
104
|
+
// by a negative amount along it.
|
|
105
|
+
- (void)mirroredX:(BOOL *)x y:(BOOL *)y {
|
|
106
|
+
*x = NO;
|
|
107
|
+
*y = NO;
|
|
108
|
+
for (NSView *view = self; view != nil; view = view.superview) {
|
|
109
|
+
CATransform3D t = view.layer.transform;
|
|
110
|
+
*x ^= t.m11 < 0;
|
|
111
|
+
*y ^= t.m22 < 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
36
115
|
- (void)scrollWheel:(NSEvent *)event {
|
|
37
116
|
if (self.scrollingDisabled) {
|
|
38
117
|
[self.nextResponder scrollWheel:event];
|
|
39
118
|
return;
|
|
40
119
|
}
|
|
41
|
-
|
|
120
|
+
NSEventPhase phase = event.phase, momentum = event.momentumPhase;
|
|
121
|
+
BOOL wheel = phase == NSEventPhaseNone && momentum == NSEventPhaseNone;
|
|
122
|
+
BOOL still = event.scrollingDeltaX == 0 && event.scrollingDeltaY == 0;
|
|
123
|
+
if (phase == NSEventPhaseMayBegin) {
|
|
124
|
+
_passing = NO;
|
|
125
|
+
_heldStart = nil;
|
|
126
|
+
} else if (phase == NSEventPhaseBegan && still) {
|
|
127
|
+
_heldStart = event;
|
|
128
|
+
_passing = NO;
|
|
129
|
+
// A settling the wheel queued waits until the gesture's direction says whose it is.
|
|
130
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(settleOnPage) object:nil];
|
|
131
|
+
return;
|
|
132
|
+
} else if (phase == NSEventPhaseBegan || wheel || (_heldStart != nil && !still)) {
|
|
133
|
+
_passing = ![self scrollsAlong:event];
|
|
134
|
+
_settling = NO;
|
|
135
|
+
if (!wheel && _settleQueued) {
|
|
136
|
+
// A gesture this view takes settles itself; one that goes past leaves the wheel's to run.
|
|
137
|
+
if (_passing) {
|
|
138
|
+
[self queueSettle];
|
|
139
|
+
} else {
|
|
140
|
+
[self dropSettle];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (_heldStart != nil && (!still || (phase != NSEventPhaseChanged && phase != NSEventPhaseStationary))) {
|
|
145
|
+
NSEvent *start = _heldStart;
|
|
146
|
+
_heldStart = nil;
|
|
147
|
+
[self scrollDecided:start];
|
|
148
|
+
}
|
|
149
|
+
[self scrollDecided:event];
|
|
42
150
|
}
|
|
151
|
+
|
|
152
|
+
// An event of a gesture whose route is decided.
|
|
153
|
+
- (void)scrollDecided:(NSEvent *)event {
|
|
154
|
+
NSEventPhase phase = event.phase, momentum = event.momentumPhase;
|
|
155
|
+
BOOL wheel = phase == NSEventPhaseNone && momentum == NSEventPhaseNone;
|
|
156
|
+
if (_passing) {
|
|
157
|
+
[self.nextResponder scrollWheel:event];
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
BOOL x, y;
|
|
161
|
+
[self mirroredX:&x y:&y];
|
|
162
|
+
NSEvent *scroll = NGNMirroredScroll(event, x, y);
|
|
163
|
+
if (momentum != NSEventPhaseNone && _settling) {
|
|
164
|
+
if (momentum == NSEventPhaseEnded || momentum == NSEventPhaseCancelled) {
|
|
165
|
+
_settling = NO;
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (phase == NSEventPhaseBegan || phase == NSEventPhaseChanged || wheel) {
|
|
170
|
+
NSTimeInterval elapsed = std::max(scroll.timestamp - _lastWheel, 0.001);
|
|
171
|
+
_lastWheel = scroll.timestamp;
|
|
172
|
+
if (scroll.scrollingDeltaX != 0 || scroll.scrollingDeltaY != 0) {
|
|
173
|
+
// AppKit's deltas move the content; the offset goes the other way. A mouse's are in lines.
|
|
174
|
+
CGFloat across = scroll.hasPreciseScrollingDeltas ? 1 : self.horizontalLineScroll;
|
|
175
|
+
CGFloat down = scroll.hasPreciseScrollingDeltas ? 1 : self.verticalLineScroll;
|
|
176
|
+
_velocity = NSMakePoint(-scroll.scrollingDeltaX * across / (elapsed * 1000),
|
|
177
|
+
-scroll.scrollingDeltaY * down / (elapsed * 1000));
|
|
178
|
+
_lastMove = scroll.timestamp;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
[super scrollWheel:scroll];
|
|
182
|
+
if (phase == NSEventPhaseBegan) {
|
|
183
|
+
_velocity = NSZeroPoint;
|
|
184
|
+
_dragging = YES;
|
|
185
|
+
[self report:NGNScrollPhaseDragBegan];
|
|
186
|
+
} else if ((phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled) && _dragging) {
|
|
187
|
+
_dragging = NO;
|
|
188
|
+
// ponytail: a tenth of a second held still is no flick; tune here if it feels off.
|
|
189
|
+
if (scroll.timestamp - _lastMove > 0.1) {
|
|
190
|
+
_velocity = NSZeroPoint;
|
|
191
|
+
}
|
|
192
|
+
[self report:NGNScrollPhaseDragEnded];
|
|
193
|
+
if (self.pagingEnabled) {
|
|
194
|
+
_settling = YES;
|
|
195
|
+
[self settleOnPage];
|
|
196
|
+
}
|
|
197
|
+
} else if (momentum == NSEventPhaseBegan) {
|
|
198
|
+
[self report:NGNScrollPhaseMomentumBegan];
|
|
199
|
+
} else if (momentum == NSEventPhaseEnded || momentum == NSEventPhaseCancelled) {
|
|
200
|
+
[self report:NGNScrollPhaseMomentumEnded];
|
|
201
|
+
} else if (wheel && self.pagingEnabled) {
|
|
202
|
+
// A mouse's wheel has no end: the page settles once it stops turning.
|
|
203
|
+
[self queueSettle];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
- (void)queueSettle {
|
|
208
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(settleOnPage) object:nil];
|
|
209
|
+
[self performSelector:@selector(settleOnPage) withObject:nil afterDelay:0.2];
|
|
210
|
+
_settleQueued = YES;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
- (void)dropSettle {
|
|
214
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(settleOnPage) object:nil];
|
|
215
|
+
_settleQueued = NO;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
- (void)report:(NGNScrollPhase)phase {
|
|
219
|
+
if (self.phaseChanged) {
|
|
220
|
+
self.phaseChanged(phase, _velocity);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Animates to the page the drag points at (ngn::pagedOffset), reporting it as momentum.
|
|
225
|
+
- (void)settleOnPage {
|
|
226
|
+
_settleQueued = NO;
|
|
227
|
+
if (!self.pagingEnabled) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
NSClipView *clip = self.contentView;
|
|
231
|
+
NSSize content = self.documentView.frame.size, view = clip.bounds.size;
|
|
232
|
+
NSPoint from = clip.bounds.origin;
|
|
233
|
+
NSPoint to = NSMakePoint(
|
|
234
|
+
ngn::pagedOffset(from.x, _velocity.x, view.width, content.width - view.width),
|
|
235
|
+
ngn::pagedOffset(from.y, _velocity.y, view.height, content.height - view.height));
|
|
236
|
+
_velocity = NSZeroPoint;
|
|
237
|
+
// One settling in front of another ends the first before the second begins.
|
|
238
|
+
if (_settleUnderway) {
|
|
239
|
+
[self report:NGNScrollPhaseMomentumEnded];
|
|
240
|
+
}
|
|
241
|
+
uint64_t settle = ++_settle;
|
|
242
|
+
_settleUnderway = YES;
|
|
243
|
+
[self report:NGNScrollPhaseMomentumBegan];
|
|
244
|
+
__weak NGNWheelScrollView *weakSelf = self;
|
|
245
|
+
[NSAnimationContext
|
|
246
|
+
runAnimationGroup:^(NSAnimationContext *context) {
|
|
247
|
+
context.duration = 0.25;
|
|
248
|
+
context.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
|
|
249
|
+
clip.animator.boundsOrigin = to;
|
|
250
|
+
}
|
|
251
|
+
completionHandler:^{
|
|
252
|
+
NGNWheelScrollView *strong = weakSelf;
|
|
253
|
+
if (strong == nil || strong->_settle != settle) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
strong->_settleUnderway = NO;
|
|
257
|
+
[strong reflectScrolledClipView:clip];
|
|
258
|
+
[strong report:NGNScrollPhaseMomentumEnded];
|
|
259
|
+
}];
|
|
260
|
+
}
|
|
261
|
+
|
|
43
262
|
@end
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
- (void)placeAsWindows:(BOOL)window;
|
|
39
39
|
// The split view is leaving: the window gets its surface back.
|
|
40
40
|
- (void)uninstall;
|
|
41
|
+
// A screen above the one holding this split view covers it (`covered`), or it shows again: a
|
|
42
|
+
// window's split view gives the window its surface back while covered, so the screen in front
|
|
43
|
+
// shows, and takes the window again as its screen shows.
|
|
44
|
+
- (void)setScreenCovered:(BOOL)covered;
|
|
41
45
|
@end
|
|
42
46
|
|
|
43
47
|
// NgNativeSidebar and NgNativeSplitContent: filled by their container, not placed by Yoga.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#import "split-view.h"
|
|
2
|
+
|
|
3
|
+
#include <optional>
|
|
2
4
|
#import "test-launch.h"
|
|
3
5
|
|
|
4
6
|
#import "surface-view.h"
|
|
@@ -34,10 +36,6 @@ void send(NGNView *view, const std::string &name, folly::dynamic payload) {
|
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
// The narrowest and widest a sidebar is dragged to when the app sets no bound.
|
|
38
|
-
constexpr CGFloat kSidebarMinimum = 150;
|
|
39
|
-
constexpr CGFloat kSidebarMaximum = 400;
|
|
40
|
-
|
|
41
39
|
} // namespace
|
|
42
40
|
|
|
43
41
|
#pragma mark - Sizes back into layout
|
|
@@ -169,6 +167,10 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
169
167
|
CGFloat _plainWidth;
|
|
170
168
|
ngn::SidebarCollapse _collapse;
|
|
171
169
|
std::string _autosave;
|
|
170
|
+
// The sidebar's width as a screen in front covered it, for when it takes the window again.
|
|
171
|
+
CGFloat _widthBeforeCover;
|
|
172
|
+
// What the app's `collapsed` asked for while no controller was there to take it.
|
|
173
|
+
std::optional<bool> _collapseWhileCovered;
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
+ (ngn::InputSink *)input {
|
|
@@ -294,7 +296,7 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
294
296
|
|
|
295
297
|
- (void)viewDidMoveToWindow {
|
|
296
298
|
[super viewDidMoveToWindow];
|
|
297
|
-
if (_decided && _windows && _controller == nil && self.window != nil) {
|
|
299
|
+
if (_decided && _windows && _controller == nil && self.window != nil && ![self underCoveredScreen]) {
|
|
298
300
|
[self build];
|
|
299
301
|
}
|
|
300
302
|
}
|
|
@@ -304,7 +306,9 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
304
306
|
return;
|
|
305
307
|
}
|
|
306
308
|
if (_windows) {
|
|
307
|
-
[self
|
|
309
|
+
if (![self underCoveredScreen]) {
|
|
310
|
+
[self installInWindow];
|
|
311
|
+
}
|
|
308
312
|
} else {
|
|
309
313
|
[self buildPlain];
|
|
310
314
|
}
|
|
@@ -312,17 +316,15 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
- (CGFloat)minimumWidth {
|
|
315
|
-
|
|
316
|
-
return p && p->paneMinWidth > 0 ? p->paneMinWidth : kSidebarMinimum;
|
|
319
|
+
return ngn::sidebarWidths([_sidebar paneProps]).minimum;
|
|
317
320
|
}
|
|
318
321
|
|
|
319
322
|
- (CGFloat)maximumWidth {
|
|
320
|
-
|
|
321
|
-
return std::max([self minimumWidth], p && p->paneMaxWidth > 0 ? (CGFloat)p->paneMaxWidth : kSidebarMaximum);
|
|
323
|
+
return ngn::sidebarWidths([_sidebar paneProps]).maximum;
|
|
322
324
|
}
|
|
323
325
|
|
|
324
326
|
- (CGFloat)startingWidth {
|
|
325
|
-
return
|
|
327
|
+
return ngn::sidebarWidths([_sidebar paneProps]).starting;
|
|
326
328
|
}
|
|
327
329
|
|
|
328
330
|
// Whether the split view's autosave already holds its divider, which it then restores.
|
|
@@ -369,13 +371,29 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
369
371
|
_controller.splitView.autosaveName = autosaveKey(_autosave);
|
|
370
372
|
}
|
|
371
373
|
BOOL restoring = [self hasAutosavedFrames];
|
|
374
|
+
// Installed again after a screen covered it: the sidebar stays collapsed if the app or the user
|
|
375
|
+
// had it so, unless the autosave restores the user's. After the divider is placed, which opens it.
|
|
376
|
+
std::optional<bool> collapse;
|
|
377
|
+
if (!restoring && p != nullptr && p->collapsed) {
|
|
378
|
+
collapse = true;
|
|
379
|
+
}
|
|
380
|
+
// The app asked while covered: that wins, autosave or not.
|
|
381
|
+
if (_collapseWhileCovered) {
|
|
382
|
+
collapse = *_collapseWhileCovered;
|
|
383
|
+
}
|
|
384
|
+
_collapseWhileCovered.reset();
|
|
372
385
|
[_controller addSplitViewItem:_sidebarItem];
|
|
373
386
|
[_controller addSplitViewItem:contentItem];
|
|
374
387
|
window.contentViewController = _controller;
|
|
375
388
|
[window setFrame:frame display:YES];
|
|
376
389
|
if (!restoring) {
|
|
377
|
-
|
|
390
|
+
CGFloat width = _widthBeforeCover > 0 ? _widthBeforeCover : [self startingWidth];
|
|
391
|
+
[_controller.splitView setPosition:width ofDividerAtIndex:0];
|
|
392
|
+
}
|
|
393
|
+
if (collapse && *collapse != _sidebarItem.collapsed) {
|
|
394
|
+
_sidebarItem.collapsed = *collapse;
|
|
378
395
|
}
|
|
396
|
+
_widthBeforeCover = 0;
|
|
379
397
|
[_sidebarItem addObserver:self forKeyPath:@"collapsed" options:NSKeyValueObservingOptionNew context:nil];
|
|
380
398
|
// A collapsed state the autosave restored is the user's: the app hears it.
|
|
381
399
|
if (_sidebarItem.collapsed) {
|
|
@@ -429,6 +447,33 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
429
447
|
_ownWindow = nil;
|
|
430
448
|
}
|
|
431
449
|
|
|
450
|
+
// Whether a screen above the one holding this split view covers it, however long ago.
|
|
451
|
+
- (BOOL)underCoveredScreen {
|
|
452
|
+
for (NSView *view = self.superview; view != nil; view = view.superview) {
|
|
453
|
+
if ([view isKindOfClass:NGNView.class] && ((NGNView *)view).covered) {
|
|
454
|
+
return YES;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return NO;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
- (void)setScreenCovered:(BOOL)covered {
|
|
461
|
+
// Only a window's split view holds the window; a plain one stays in its screen.
|
|
462
|
+
if (!_windows) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (covered) {
|
|
466
|
+
if (_controller != nil) {
|
|
467
|
+
// The divider's position: the sidebar pane's edge, whatever inset its view has in it.
|
|
468
|
+
NSArray<NSView *> *panes = _controller.splitView.arrangedSubviews;
|
|
469
|
+
_widthBeforeCover = _sidebarItem.collapsed || panes.count == 0 ? 0 : NSMaxX(panes[0].frame);
|
|
470
|
+
[self uninstall];
|
|
471
|
+
}
|
|
472
|
+
} else if (_decided && _controller == nil) {
|
|
473
|
+
[self build];
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
432
477
|
- (void)dealloc {
|
|
433
478
|
[self uninstall];
|
|
434
479
|
}
|
|
@@ -452,6 +497,9 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
452
497
|
view.autosaveName = autosaveKey(_autosave);
|
|
453
498
|
}
|
|
454
499
|
if (auto collapsed = _collapse.propChanged(p->collapsed)) {
|
|
500
|
+
if (_windows && _controller == nil) {
|
|
501
|
+
_collapseWhileCovered = *collapsed;
|
|
502
|
+
}
|
|
455
503
|
[self setToolkitCollapsed:*collapsed];
|
|
456
504
|
}
|
|
457
505
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#import "system-access.h"
|
|
2
2
|
|
|
3
|
+
#include "ngn/host-os.h"
|
|
4
|
+
|
|
3
5
|
#import <AppKit/AppKit.h>
|
|
4
6
|
#import <Security/Security.h>
|
|
5
7
|
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
|
@@ -109,6 +111,7 @@ ProcessesSetup processesSetup(const std::string &capabilitiesJson) {
|
|
|
109
111
|
setup.lookup = {
|
|
110
112
|
.isExecutable = [](const std::string &path) { return access(path.c_str(), X_OK) == 0; },
|
|
111
113
|
.isStub = isDeveloperStub,
|
|
114
|
+
.searchPath = macOS().searchPath,
|
|
112
115
|
};
|
|
113
116
|
NSDictionary *info = NSBundle.mainBundle.infoDictionary;
|
|
114
117
|
if (auto packaged = packagedApp()) {
|
package/native/appkit/system.mm
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
#import <AppKit/AppKit.h>
|
|
5
5
|
#import <ImageIO/ImageIO.h>
|
|
6
6
|
|
|
7
|
-
#include <
|
|
8
|
-
|
|
9
|
-
#include <atomic>
|
|
10
|
-
#include <mutex>
|
|
7
|
+
#include <memory>
|
|
11
8
|
|
|
12
9
|
namespace {
|
|
13
10
|
|
|
@@ -51,13 +48,28 @@ void postAnnouncement(const Announcement &announcement) {
|
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
// The app's defaults, which a test launch keeps in a suite of its own.
|
|
52
|
+
class DefaultsStore final : public StringStore {
|
|
55
53
|
public:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
std::optional<std::string> get(const std::string &key) override {
|
|
55
|
+
NSString *value = [appDefaults() stringForKey:ns(key)];
|
|
56
|
+
return value != nil ? std::optional(str(value)) : std::nullopt;
|
|
57
|
+
}
|
|
58
|
+
void set(const std::string &key, const std::string &value) override {
|
|
59
|
+
[appDefaults() setObject:ns(value) forKey:ns(key)];
|
|
60
60
|
}
|
|
61
|
+
void remove(const std::string &key) override {
|
|
62
|
+
[appDefaults() removeObjectForKey:ns(key)];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
class AppKitSystem final : public System {
|
|
67
|
+
public:
|
|
68
|
+
// The system's scheme is read once here on the main thread; JavaScript asks from its own.
|
|
69
|
+
explicit AppKitSystem(std::string appId)
|
|
70
|
+
: appId_(std::move(appId)),
|
|
71
|
+
scheme_(schemeOf(NSApp.effectiveAppearance)),
|
|
72
|
+
rightToLeft_(NSApp.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionRightToLeft) {}
|
|
61
73
|
|
|
62
74
|
DeviceFacts facts() override {
|
|
63
75
|
NSOperatingSystemVersion v = NSProcessInfo.processInfo.operatingSystemVersion;
|
|
@@ -99,15 +111,11 @@ class AppKitSystem final : public System {
|
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
std::string colorScheme() override {
|
|
102
|
-
|
|
103
|
-
return override_.value_or(systemScheme_);
|
|
114
|
+
return scheme_.current();
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
void setColorScheme(std::optional<std::string> scheme, std::function<void(std::string)> applied) override {
|
|
107
|
-
|
|
108
|
-
std::lock_guard lock(mutex_);
|
|
109
|
-
override_ = scheme;
|
|
110
|
-
}
|
|
118
|
+
scheme_.set(scheme);
|
|
111
119
|
auto told = std::make_shared<std::function<void(std::string)>>(std::move(applied));
|
|
112
120
|
onMain(^{
|
|
113
121
|
NSApp.appearance = !scheme ? nil
|
|
@@ -119,22 +127,16 @@ class AppKitSystem final : public System {
|
|
|
119
127
|
systemSchemeChanged(schemeOf(NSApp.effectiveAppearance));
|
|
120
128
|
}
|
|
121
129
|
// The scheme this change applied, not the latest override: a later change queued behind
|
|
122
|
-
// this one has set
|
|
130
|
+
// this one has set the override already, and tells its own scheme when it applies.
|
|
123
131
|
if (*told) {
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
std::lock_guard lock(mutex_);
|
|
127
|
-
applied = scheme.value_or(systemScheme_);
|
|
128
|
-
}
|
|
129
|
-
(*told)(applied);
|
|
132
|
+
(*told)(scheme_.applied(scheme));
|
|
130
133
|
}
|
|
131
134
|
});
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
// The system's own scheme, with no override. Main thread.
|
|
135
138
|
void systemSchemeChanged(std::string scheme) {
|
|
136
|
-
std::
|
|
137
|
-
systemScheme_ = std::move(scheme);
|
|
139
|
+
scheme_.systemChanged(std::move(scheme));
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
void showAlert(const AlertRequest &request, std::function<void(int, std::string, std::string)> done) override {
|
|
@@ -209,24 +211,11 @@ class AppKitSystem final : public System {
|
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
std::optional<folly::dynamic> preference(const std::string &key) override {
|
|
212
|
-
|
|
213
|
-
if (json == nil) {
|
|
214
|
-
return std::nullopt;
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
return folly::parseJson(str(json));
|
|
218
|
-
} catch (...) {
|
|
219
|
-
return std::nullopt;
|
|
220
|
-
}
|
|
214
|
+
return preferences_.get(key);
|
|
221
215
|
}
|
|
222
216
|
|
|
223
217
|
void setPreference(const std::string &key, std::optional<folly::dynamic> value) override {
|
|
224
|
-
|
|
225
|
-
if (value) {
|
|
226
|
-
[defaults setObject:ns(folly::toJson(*value)) forKey:ns(prefixed(key))];
|
|
227
|
-
} else {
|
|
228
|
-
[defaults removeObjectForKey:ns(prefixed(key))];
|
|
229
|
-
}
|
|
218
|
+
preferences_.set(key, value);
|
|
230
219
|
}
|
|
231
220
|
|
|
232
221
|
void announce(const Announcement &announcement) override {
|
|
@@ -264,16 +253,12 @@ class AppKitSystem final : public System {
|
|
|
264
253
|
}
|
|
265
254
|
|
|
266
255
|
private:
|
|
267
|
-
// A bare host binary has no bundle identifier, so every app run with it would share one
|
|
268
|
-
// defaults domain: the app's id keeps them apart.
|
|
269
|
-
std::string prefixed(const std::string &key) const {
|
|
270
|
-
return NSBundle.mainBundle.bundleIdentifier ? key : appId_ + "." + key;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
256
|
std::string appId_;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
257
|
+
ColorSchemeOverride scheme_;
|
|
258
|
+
// A bare host binary has no bundle identifier, so every app run with it shares one defaults
|
|
259
|
+
// domain: the app's id keeps them apart.
|
|
260
|
+
JsonPreferences preferences_{
|
|
261
|
+
std::make_shared<DefaultsStore>(), appId_, NSBundle.mainBundle.bundleIdentifier == nil};
|
|
277
262
|
bool rightToLeft_{false};
|
|
278
263
|
};
|
|
279
264
|
|