@native-sdk/cli 0.9.1 → 0.9.3
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/build/app.zig +26 -9
- package/build.zig +124 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/packages/core/sdk/events.d.ts +7 -0
- package/packages/core/sdk/events.ts +26 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +58 -1
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +10 -8
- package/skill-data/ts-core/SKILL.md +8 -5
- package/src/app_runner/root.zig +301 -12
- package/src/app_runner/ts_core_main.zig +6 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +271 -52
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +222 -14
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +129 -1
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +14 -2
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +65 -0
- package/src/primitives/canvas/ui.zig +66 -10
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +84 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +33 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ts_ui_app.zig +164 -1
- package/src/runtime/ui_app.zig +100 -21
- package/src/runtime/ui_app_tests.zig +351 -32
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/verbs.zig +1 -0
- package/src/tooling/web_engine.zig +1 -1
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/shim_rt.zig +20 -0
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
#include <string.h>
|
|
27
27
|
#include <time.h>
|
|
28
28
|
|
|
29
|
+
#include "../ios/apple_image_fit.h"
|
|
30
|
+
|
|
29
31
|
@class NativeSdkAppKitHost;
|
|
30
32
|
@class NativeSdkAudioCaptureTarget;
|
|
31
33
|
@class NativeSdkScreenAudioCapture;
|
|
@@ -99,7 +101,11 @@ static void *NativeSdkAppKitVideoTimeControlContext = &NativeSdkAppKitVideoTimeC
|
|
|
99
101
|
/* Render-thread ring state for the spectrum tap; defined with the rest
|
|
100
102
|
* of the spectrum machinery in the audio section below. */
|
|
101
103
|
typedef struct native_sdk_spectrum_tap_state native_sdk_spectrum_tap_state_t;
|
|
102
|
-
static
|
|
104
|
+
static NSScreen *NativeSdkPrimaryScreen(void);
|
|
105
|
+
static NSScreen *NativeSdkScreenForFrame(NSRect frame);
|
|
106
|
+
static NSRect NativeSdkConstrainFrameToScreen(NSRect frame, NSScreen *screen);
|
|
107
|
+
static NSRect NativeSdkConstrainFrame(NSRect frame);
|
|
108
|
+
static NSRect NativeSdkCenterFrameOnScreen(NSRect frame, NSScreen *screen);
|
|
103
109
|
static NSString *NativeSdkAppKitBridgeScript(void);
|
|
104
110
|
static NSString *NativeSdkMenuKeyEquivalent(NSString *key);
|
|
105
111
|
static NSString *NativeSdkMimeTypeForPath(NSString *path);
|
|
@@ -267,6 +273,8 @@ static NSAccessibilityRole NativeSdkAccessibilityRoleForWidgetRole(NSInteger rol
|
|
|
267
273
|
return NSAccessibilityCheckBoxRole;
|
|
268
274
|
case NATIVE_SDK_APPKIT_WIDGET_ROLE_RADIO:
|
|
269
275
|
return NSAccessibilityRadioButtonRole;
|
|
276
|
+
case NATIVE_SDK_APPKIT_WIDGET_ROLE_RADIOGROUP:
|
|
277
|
+
return NSAccessibilityRadioGroupRole;
|
|
270
278
|
case NATIVE_SDK_APPKIT_WIDGET_ROLE_MENU:
|
|
271
279
|
return NSAccessibilityMenuRole;
|
|
272
280
|
case NATIVE_SDK_APPKIT_WIDGET_ROLE_MENUITEM:
|
|
@@ -470,11 +478,12 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
470
478
|
@property(nonatomic, assign) uint32_t actionFlags;
|
|
471
479
|
@property(nonatomic, assign) BOOL canUndo;
|
|
472
480
|
@property(nonatomic, assign) BOOL canRedo;
|
|
481
|
+
@property(nonatomic, assign) NSRect surfaceFrame;
|
|
473
482
|
- (BOOL)emitSetTextAccessibilityValue:(id)value;
|
|
474
483
|
- (BOOL)emitSetSelectionAccessibilityValue:(id)value;
|
|
475
484
|
@end
|
|
476
485
|
|
|
477
|
-
@interface NativeSdkMetalSurfaceView : NSView <NSTextInputClient>
|
|
486
|
+
@interface NativeSdkMetalSurfaceView : NSView <NSTextInputClient, NSDraggingDestination>
|
|
478
487
|
@property(nonatomic, strong) id<MTLDevice> device;
|
|
479
488
|
@property(nonatomic, strong) id<MTLCommandQueue> commandQueue;
|
|
480
489
|
@property(nonatomic, strong) CAMetalLayer *metalLayer;
|
|
@@ -493,6 +502,7 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
493
502
|
@property(nonatomic, assign) NativeSdkAppKitHost *host;
|
|
494
503
|
@property(nonatomic, assign) uint64_t windowId;
|
|
495
504
|
@property(nonatomic, strong) NSString *surfaceLabel;
|
|
505
|
+
@property(nonatomic, strong) NSString *viewLabel;
|
|
496
506
|
@property(nonatomic, assign) NSUInteger frameIndex;
|
|
497
507
|
/* Whether this surface has completed at least one REAL present. Gates the
|
|
498
508
|
* occluded short-circuit: until the first present lands, occluded frames
|
|
@@ -665,6 +675,7 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
665
675
|
@property(nonatomic, assign) NSRange selectedTextRange;
|
|
666
676
|
@property(nonatomic, assign) BOOL interpretedKeyEventEmittedInput;
|
|
667
677
|
@property(nonatomic, strong) NSArray<NSAccessibilityElement *> *widgetAccessibilityElements;
|
|
678
|
+
@property(nonatomic, strong) NSArray<NSAccessibilityElement *> *widgetAccessibilityRootElements;
|
|
668
679
|
@property(nonatomic, strong) NSMutableArray<NativeSdkScrollDriverView *> *scrollDrivers;
|
|
669
680
|
@property(nonatomic, assign) NSPoint wheelGesturePoint;
|
|
670
681
|
@property(nonatomic, assign) BOOL wheelGestureActive;
|
|
@@ -743,7 +754,7 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
743
754
|
- (void)updateSurfaceTrackingArea;
|
|
744
755
|
- (void)emitSelectAllTextInputCommand;
|
|
745
756
|
- (void)emitTextInputEventWithKind:(NSInteger)kind text:(NSString *)text compositionCursor:(NSInteger)compositionCursor;
|
|
746
|
-
- (
|
|
757
|
+
- (NativeSdkWidgetAccessibilityElement *)focusedTextAccessibilityElement;
|
|
747
758
|
- (BOOL)emitWidgetAccessibilityActionWithId:(uint64_t)widgetId action:(NSInteger)action;
|
|
748
759
|
- (BOOL)emitWidgetAccessibilityActionWithId:(uint64_t)widgetId action:(NSInteger)action text:(NSString *)text selectedRange:(NSRange)selectedRange hasSelectedRange:(BOOL)hasSelectedRange;
|
|
749
760
|
- (void)setSurfaceCursor:(NSCursor *)cursor;
|
|
@@ -1013,8 +1024,8 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
1013
1024
|
@property(nonatomic, strong) NSArray<NSString *> *allowedNavigationOrigins;
|
|
1014
1025
|
@property(nonatomic, strong) NSArray<NSString *> *allowedExternalURLs;
|
|
1015
1026
|
@property(nonatomic, assign) NSInteger externalLinkAction;
|
|
1016
|
-
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags;
|
|
1017
|
-
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
1027
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent dockVisible:(BOOL)dockVisible windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags;
|
|
1028
|
+
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
1018
1029
|
- (void)orderWindowForImplicitShow:(uint64_t)windowId;
|
|
1019
1030
|
- (void)showDeferredWindowIfPending:(uint64_t)windowId reason:(const char *)reason;
|
|
1020
1031
|
- (void)applyWindowClearColor:(uint64_t)windowId red:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue alpha:(uint8_t)alpha;
|
|
@@ -1090,7 +1101,7 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
1090
1101
|
- (void)stop;
|
|
1091
1102
|
- (BOOL)drainPendingPreRunStop;
|
|
1092
1103
|
- (void)emitEvent:(native_sdk_appkit_event_t)event;
|
|
1093
|
-
- (BOOL)emitDroppedFileURLs:(NSArray<NSURL *> *)urls windowId:(uint64_t)windowId;
|
|
1104
|
+
- (BOOL)emitDroppedFileURLs:(NSArray<NSURL *> *)urls windowId:(uint64_t)windowId viewLabel:(NSString *)viewLabel point:(NSPoint)point;
|
|
1094
1105
|
- (void)startApplicationActivationObservers;
|
|
1095
1106
|
- (void)stopApplicationActivationObservers;
|
|
1096
1107
|
- (void)applicationDidBecomeActive:(NSNotification *)notification;
|
|
@@ -1189,6 +1200,14 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
|
|
|
1189
1200
|
}
|
|
1190
1201
|
}
|
|
1191
1202
|
|
|
1203
|
+
// Convert an AppKit-local point to the runtime's top-left-origin space.
|
|
1204
|
+
// Unflipped canvas/content views need the y inversion; flipped views such as
|
|
1205
|
+
// WKWebView already use the runtime's orientation and must pass through.
|
|
1206
|
+
static NSPoint NativeSdkViewLocalYDownPoint(NSView *view, NSPoint point) {
|
|
1207
|
+
if (!view.isFlipped) point.y = view.bounds.size.height - point.y;
|
|
1208
|
+
return point;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1192
1211
|
@implementation NativeSdkWindowDelegate
|
|
1193
1212
|
|
|
1194
1213
|
- (void)windowDidResize:(NSNotification *)notification {
|
|
@@ -1281,9 +1300,9 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
|
|
|
1281
1300
|
|
|
1282
1301
|
// The window is a dragging destination now that the main WebView (whose
|
|
1283
1302
|
// registration used to catch every drop) is lazy: NSWindow forwards
|
|
1284
|
-
// these to its delegate
|
|
1285
|
-
//
|
|
1286
|
-
//
|
|
1303
|
+
// these to its delegate. A present main/child WebView or canvas surface
|
|
1304
|
+
// still wins (views outrank the window for registered types); the fallback
|
|
1305
|
+
// hit-tests anyway so adopted/layered content keeps the most specific label.
|
|
1287
1306
|
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
|
1288
1307
|
(void)sender;
|
|
1289
1308
|
return NSDragOperationCopy;
|
|
@@ -1293,7 +1312,36 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
|
|
|
1293
1312
|
NSPasteboard *pasteboard = sender.draggingPasteboard;
|
|
1294
1313
|
NSArray<NSURL *> *urls = [pasteboard readObjectsForClasses:@[ [NSURL class] ]
|
|
1295
1314
|
options:@{ NSPasteboardURLReadingFileURLsOnlyKey : @YES }];
|
|
1296
|
-
|
|
1315
|
+
NSWindow *window = self.host.windows[@(self.windowId)] ?: (self.windowId == 1 ? self.host.window : nil);
|
|
1316
|
+
NSView *contentView = window.contentView;
|
|
1317
|
+
if (!contentView) return NO;
|
|
1318
|
+
|
|
1319
|
+
const NSPoint windowPoint = sender.draggingLocation;
|
|
1320
|
+
const NSPoint contentPoint = [contentView convertPoint:windowPoint fromView:nil];
|
|
1321
|
+
NSView *targetView = [contentView hitTest:contentPoint];
|
|
1322
|
+
NSString *viewLabel = @"";
|
|
1323
|
+
for (NSView *candidate = targetView; candidate; candidate = candidate.superview) {
|
|
1324
|
+
if ([candidate isKindOfClass:[NativeSdkMetalSurfaceView class]]) {
|
|
1325
|
+
NSString *label = ((NativeSdkMetalSurfaceView *)candidate).viewLabel;
|
|
1326
|
+
if (label.length > 0) {
|
|
1327
|
+
targetView = candidate;
|
|
1328
|
+
viewLabel = label;
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
} else if ([candidate isKindOfClass:[NativeSdkWebView class]]) {
|
|
1332
|
+
NSString *label = ((NativeSdkWebView *)candidate).viewLabel;
|
|
1333
|
+
if (label.length > 0) {
|
|
1334
|
+
targetView = candidate;
|
|
1335
|
+
viewLabel = label;
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
if (candidate == contentView) break;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
NSView *coordinateView = viewLabel.length > 0 ? targetView : contentView;
|
|
1343
|
+
NSPoint point = NativeSdkViewLocalYDownPoint(coordinateView, [coordinateView convertPoint:windowPoint fromView:nil]);
|
|
1344
|
+
return [self.host emitDroppedFileURLs:urls windowId:self.windowId viewLabel:viewLabel point:point];
|
|
1297
1345
|
}
|
|
1298
1346
|
|
|
1299
1347
|
// close_policy .hide: the USER's close affordance (the red button,
|
|
@@ -1397,7 +1445,8 @@ static void NativeSdkEmitGpuSurfaceResizes(NSView *view) {
|
|
|
1397
1445
|
NSPasteboard *pasteboard = sender.draggingPasteboard;
|
|
1398
1446
|
NSArray<NSURL *> *urls = [pasteboard readObjectsForClasses:@[[NSURL class]]
|
|
1399
1447
|
options:@{ NSPasteboardURLReadingFileURLsOnlyKey: @YES }];
|
|
1400
|
-
|
|
1448
|
+
NSPoint point = NativeSdkViewLocalYDownPoint(self, [self convertPoint:sender.draggingLocation fromView:nil]);
|
|
1449
|
+
return [self.host emitDroppedFileURLs:urls windowId:self.windowId viewLabel:self.viewLabel point:point];
|
|
1401
1450
|
}
|
|
1402
1451
|
|
|
1403
1452
|
@end
|
|
@@ -2536,28 +2585,48 @@ int native_sdk_appkit_measure_text_advances(uint64_t font_id, double size, const
|
|
|
2536
2585
|
// CGBitmapContext can render into) and is un-premultiplied in place,
|
|
2537
2586
|
// because the canvas image pipeline — the reference renderer and the
|
|
2538
2587
|
// packet host's kCGImageAlphaLast upload — expects straight alpha.
|
|
2539
|
-
int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8_t *pixels, size_t pixels_len, size_t *out_width, size_t *out_height) {
|
|
2588
|
+
int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8_t *pixels, size_t pixels_len, size_t max_pixels, size_t *out_width, size_t *out_height) {
|
|
2540
2589
|
if (out_width) *out_width = 0;
|
|
2541
2590
|
if (out_height) *out_height = 0;
|
|
2542
|
-
if (!bytes || bytes_len == 0 || !pixels) return 0;
|
|
2591
|
+
if (!bytes || bytes_len == 0 || !pixels || max_pixels == 0) return 0;
|
|
2543
2592
|
@autoreleasepool {
|
|
2544
2593
|
NSData *data = [NSData dataWithBytesNoCopy:(void *)bytes length:bytes_len freeWhenDone:NO];
|
|
2545
2594
|
CGImageRef image = NULL;
|
|
2546
2595
|
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
|
|
2547
2596
|
if (source) {
|
|
2548
|
-
|
|
2597
|
+
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
|
|
2598
|
+
int64_t source_width_value = 0;
|
|
2599
|
+
int64_t source_height_value = 0;
|
|
2600
|
+
if (properties) {
|
|
2601
|
+
CFNumberRef width_value = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
|
|
2602
|
+
CFNumberRef height_value = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
|
|
2603
|
+
if (width_value) CFNumberGetValue(width_value, kCFNumberSInt64Type, &source_width_value);
|
|
2604
|
+
if (height_value) CFNumberGetValue(height_value, kCFNumberSInt64Type, &source_height_value);
|
|
2605
|
+
CFRelease(properties);
|
|
2606
|
+
}
|
|
2607
|
+
size_t source_width = source_width_value > 0 ? (size_t)source_width_value : 0;
|
|
2608
|
+
size_t source_height = source_height_value > 0 ? (size_t)source_height_value : 0;
|
|
2609
|
+
if (source_width > 0 && source_height > 0) {
|
|
2610
|
+
const size_t max_dimension = native_sdk_apple_image_thumbnail_max_dimension(source_width, source_height, max_pixels);
|
|
2611
|
+
NSDictionary *thumbnail_options = @{
|
|
2612
|
+
(NSString *)kCGImageSourceCreateThumbnailFromImageAlways: @YES,
|
|
2613
|
+
(NSString *)kCGImageSourceThumbnailMaxPixelSize: @(max_dimension),
|
|
2614
|
+
(NSString *)kCGImageSourceCreateThumbnailWithTransform: @YES,
|
|
2615
|
+
};
|
|
2616
|
+
image = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef)thumbnail_options);
|
|
2617
|
+
}
|
|
2549
2618
|
CFRelease(source);
|
|
2550
2619
|
}
|
|
2551
2620
|
if (!image) {
|
|
2552
2621
|
NSImage *system_image = [[NSImage alloc] initWithData:data];
|
|
2553
2622
|
NSSize size = system_image ? system_image.size : NSZeroSize;
|
|
2554
|
-
if (size.width > 0 && size.height > 0 && size.width
|
|
2623
|
+
if (size.width > 0 && size.height > 0 && isfinite(size.width) && isfinite(size.height)) {
|
|
2555
2624
|
// SVG is resolution-independent, so cap the proposed point
|
|
2556
2625
|
// extent before NSImage selects its Retina representation.
|
|
2557
2626
|
// A 256pt square becomes at most the registry's 512px square
|
|
2558
2627
|
// on macOS's 2x displays instead of materializing an
|
|
2559
2628
|
// attacker-declared multi-hundred-megabyte bitmap first.
|
|
2560
|
-
const CGFloat max_raster_points =
|
|
2629
|
+
const CGFloat max_raster_points = sqrt((CGFloat)max_pixels) / 2.0;
|
|
2561
2630
|
const CGFloat raster_scale = MIN(1.0, MIN(max_raster_points / size.width, max_raster_points / size.height));
|
|
2562
2631
|
NSRect proposed = NSMakeRect(0, 0, size.width * raster_scale, size.height * raster_scale);
|
|
2563
2632
|
CGImageRef rendered = [system_image CGImageForProposedRect:&proposed context:nil hints:nil];
|
|
@@ -2568,14 +2637,14 @@ int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8
|
|
|
2568
2637
|
|
|
2569
2638
|
size_t width = CGImageGetWidth(image);
|
|
2570
2639
|
size_t height = CGImageGetHeight(image);
|
|
2571
|
-
if (width == 0 || height == 0 || width >
|
|
2640
|
+
if (width == 0 || height == 0 || width > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION || height > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION) {
|
|
2572
2641
|
CGImageRelease(image);
|
|
2573
2642
|
return 0;
|
|
2574
2643
|
}
|
|
2575
2644
|
if (out_width) *out_width = width;
|
|
2576
2645
|
if (out_height) *out_height = height;
|
|
2577
2646
|
size_t byte_len = width * height * 4;
|
|
2578
|
-
if (byte_len / 4 / height != width || pixels_len < byte_len) {
|
|
2647
|
+
if (width > max_pixels / height || byte_len / 4 / height != width || pixels_len < byte_len) {
|
|
2579
2648
|
CGImageRelease(image);
|
|
2580
2649
|
return -1;
|
|
2581
2650
|
}
|
|
@@ -3683,6 +3752,14 @@ static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *de
|
|
|
3683
3752
|
|
|
3684
3753
|
@implementation NativeSdkMetalSurfaceView
|
|
3685
3754
|
|
|
3755
|
+
- (NSString *)viewLabel {
|
|
3756
|
+
return self.surfaceLabel;
|
|
3757
|
+
}
|
|
3758
|
+
|
|
3759
|
+
- (void)setViewLabel:(NSString *)viewLabel {
|
|
3760
|
+
self.surfaceLabel = viewLabel ?: @"";
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3686
3763
|
- (instancetype)initWithFrame:(NSRect)frameRect {
|
|
3687
3764
|
self = [super initWithFrame:frameRect];
|
|
3688
3765
|
if (!self) return nil;
|
|
@@ -3731,7 +3808,7 @@ static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *de
|
|
|
3731
3808
|
- (void)configureWithHost:(NativeSdkAppKitHost *)host windowId:(uint64_t)windowId label:(NSString *)label {
|
|
3732
3809
|
self.host = host;
|
|
3733
3810
|
self.windowId = windowId;
|
|
3734
|
-
self.
|
|
3811
|
+
self.viewLabel = label;
|
|
3735
3812
|
__weak NativeSdkMetalSurfaceView *weakSelf = self;
|
|
3736
3813
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
3737
3814
|
NativeSdkMetalSurfaceView *strongSelf = weakSelf;
|
|
@@ -3742,6 +3819,19 @@ static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *de
|
|
|
3742
3819
|
});
|
|
3743
3820
|
}
|
|
3744
3821
|
|
|
3822
|
+
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
|
3823
|
+
(void)sender;
|
|
3824
|
+
return NSDragOperationCopy;
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3827
|
+
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
|
3828
|
+
NSPasteboard *pasteboard = sender.draggingPasteboard;
|
|
3829
|
+
NSArray<NSURL *> *urls = [pasteboard readObjectsForClasses:@[[NSURL class]]
|
|
3830
|
+
options:@{ NSPasteboardURLReadingFileURLsOnlyKey: @YES }];
|
|
3831
|
+
NSPoint point = NativeSdkViewLocalYDownPoint(self, [self convertPoint:sender.draggingLocation fromView:nil]);
|
|
3832
|
+
return [self.host emitDroppedFileURLs:urls windowId:self.windowId viewLabel:self.viewLabel point:point];
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3745
3835
|
- (void)dealloc {
|
|
3746
3836
|
[self stopDisplayTimer];
|
|
3747
3837
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
@@ -3752,7 +3842,7 @@ static void NativeSdkPremultiplyStraightRgba8(const uint8_t *source, uint8_t *de
|
|
|
3752
3842
|
}
|
|
3753
3843
|
|
|
3754
3844
|
- (NSArray *)accessibilityChildren {
|
|
3755
|
-
return self.
|
|
3845
|
+
return self.widgetAccessibilityRootElements ?: @[];
|
|
3756
3846
|
}
|
|
3757
3847
|
|
|
3758
3848
|
- (BOOL)isAvailable {
|
|
@@ -5612,11 +5702,14 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5612
5702
|
- (void)updateWidgetAccessibilityWithNodes:(const native_sdk_appkit_widget_accessibility_node_t *)nodes count:(NSUInteger)count {
|
|
5613
5703
|
if (!nodes || count == 0) {
|
|
5614
5704
|
self.widgetAccessibilityElements = @[];
|
|
5705
|
+
self.widgetAccessibilityRootElements = @[];
|
|
5615
5706
|
NSAccessibilityPostNotification(self, NSAccessibilityLayoutChangedNotification);
|
|
5616
5707
|
return;
|
|
5617
5708
|
}
|
|
5618
5709
|
|
|
5619
|
-
NSMutableArray<
|
|
5710
|
+
NSMutableArray<NativeSdkWidgetAccessibilityElement *> *elements = [NSMutableArray arrayWithCapacity:count];
|
|
5711
|
+
NSMutableArray<NSNumber *> *parentIds = [NSMutableArray arrayWithCapacity:count];
|
|
5712
|
+
NSMutableDictionary<NSNumber *, NativeSdkWidgetAccessibilityElement *> *elementsById = [NSMutableDictionary dictionaryWithCapacity:count];
|
|
5620
5713
|
for (NSUInteger index = 0; index < count; index++) {
|
|
5621
5714
|
const native_sdk_appkit_widget_accessibility_node_t node = nodes[index];
|
|
5622
5715
|
NSString *label = NativeSdkStringFromBytes(node.label, node.label_len) ?: @"";
|
|
@@ -5627,7 +5720,6 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5627
5720
|
element.surfaceView = self;
|
|
5628
5721
|
element.widgetId = node.id;
|
|
5629
5722
|
element.actionFlags = node.action_flags;
|
|
5630
|
-
element.accessibilityParent = self;
|
|
5631
5723
|
element.accessibilityRole = NativeSdkAccessibilityRoleForWidgetRole(node.role);
|
|
5632
5724
|
element.accessibilityIdentifier = [NSString stringWithFormat:@"native-sdk-widget-%llu", node.id];
|
|
5633
5725
|
element.accessibilityLabel = name;
|
|
@@ -5704,10 +5796,46 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5704
5796
|
element.accessibilityValueDescription = [stateDescriptions componentsJoinedByString:@", "];
|
|
5705
5797
|
}
|
|
5706
5798
|
CGFloat nativeY = self.bounds.size.height - node.y - node.height;
|
|
5707
|
-
element.
|
|
5799
|
+
element.surfaceFrame = NSMakeRect(node.x, nativeY, node.width, node.height);
|
|
5800
|
+
element.accessibilityFrameInParentSpace = element.surfaceFrame;
|
|
5708
5801
|
[elements addObject:element];
|
|
5802
|
+
[parentIds addObject:@(node.parent_id)];
|
|
5803
|
+
[elementsById setObject:element forKey:@(node.id)];
|
|
5804
|
+
}
|
|
5805
|
+
|
|
5806
|
+
NSMutableArray<NSAccessibilityElement *> *rootElements = [NSMutableArray arrayWithCapacity:count];
|
|
5807
|
+
NSMutableDictionary<NSNumber *, NSMutableArray<NSAccessibilityElement *> *> *childrenByParentId = [NSMutableDictionary dictionaryWithCapacity:count];
|
|
5808
|
+
for (NSUInteger index = 0; index < elements.count; index++) {
|
|
5809
|
+
NativeSdkWidgetAccessibilityElement *element = elements[index];
|
|
5810
|
+
NSNumber *parentId = parentIds[index];
|
|
5811
|
+
NativeSdkWidgetAccessibilityElement *parent = parentId.unsignedLongLongValue == 0 ? nil : [elementsById objectForKey:parentId];
|
|
5812
|
+
if (parent && parent != element) {
|
|
5813
|
+
element.accessibilityParent = parent;
|
|
5814
|
+
NSRect parentFrame = parent.surfaceFrame;
|
|
5815
|
+
NSRect childFrame = element.surfaceFrame;
|
|
5816
|
+
element.accessibilityFrameInParentSpace = NSMakeRect(
|
|
5817
|
+
childFrame.origin.x - parentFrame.origin.x,
|
|
5818
|
+
childFrame.origin.y - parentFrame.origin.y,
|
|
5819
|
+
childFrame.size.width,
|
|
5820
|
+
childFrame.size.height
|
|
5821
|
+
);
|
|
5822
|
+
NSMutableArray<NSAccessibilityElement *> *children = [childrenByParentId objectForKey:parentId];
|
|
5823
|
+
if (!children) {
|
|
5824
|
+
children = [NSMutableArray array];
|
|
5825
|
+
[childrenByParentId setObject:children forKey:parentId];
|
|
5826
|
+
}
|
|
5827
|
+
[children addObject:element];
|
|
5828
|
+
} else {
|
|
5829
|
+
element.accessibilityParent = self;
|
|
5830
|
+
[rootElements addObject:element];
|
|
5831
|
+
}
|
|
5832
|
+
}
|
|
5833
|
+
for (NSNumber *parentId in childrenByParentId) {
|
|
5834
|
+
NativeSdkWidgetAccessibilityElement *parent = [elementsById objectForKey:parentId];
|
|
5835
|
+
parent.accessibilityChildren = [childrenByParentId objectForKey:parentId];
|
|
5709
5836
|
}
|
|
5710
5837
|
self.widgetAccessibilityElements = elements;
|
|
5838
|
+
self.widgetAccessibilityRootElements = rootElements;
|
|
5711
5839
|
NSAccessibilityPostNotification(self, NSAccessibilityLayoutChangedNotification);
|
|
5712
5840
|
}
|
|
5713
5841
|
|
|
@@ -6951,7 +7079,7 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
6951
7079
|
|
|
6952
7080
|
- (void)emitInputEventWithKind:(NSInteger)kind point:(NSPoint)point timestampNs:(uint64_t)timestampNs modifiers:(uint32_t)modifiers keyText:(NSString *)keyText inputText:(NSString *)inputText button:(NSInteger)button deltaX:(double)deltaX deltaY:(double)deltaY {
|
|
6953
7081
|
if (!self.host || self.surfaceLabel.length == 0) return;
|
|
6954
|
-
|
|
7082
|
+
const NSPoint yDownPoint = NativeSdkViewLocalYDownPoint(self, point);
|
|
6955
7083
|
const char *labelBytes = self.surfaceLabel.UTF8String ?: "";
|
|
6956
7084
|
NSString *safeKeyText = keyText ?: @"";
|
|
6957
7085
|
NSString *safeInputText = inputText ?: @"";
|
|
@@ -6961,8 +7089,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
6961
7089
|
.kind = NATIVE_SDK_APPKIT_EVENT_GPU_SURFACE_INPUT,
|
|
6962
7090
|
.window_id = self.windowId,
|
|
6963
7091
|
.timestamp_ns = timestampNs,
|
|
6964
|
-
.x =
|
|
6965
|
-
.y = y,
|
|
7092
|
+
.x = yDownPoint.x,
|
|
7093
|
+
.y = yDownPoint.y,
|
|
6966
7094
|
.view_label = labelBytes,
|
|
6967
7095
|
.view_label_len = [self.surfaceLabel lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
6968
7096
|
.key_text = keyBytes,
|
|
@@ -7082,10 +7210,10 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7082
7210
|
}
|
|
7083
7211
|
|
|
7084
7212
|
- (NSUInteger)characterIndexForPoint:(NSPoint)point {
|
|
7085
|
-
|
|
7213
|
+
NativeSdkWidgetAccessibilityElement *element = [self focusedTextAccessibilityElement];
|
|
7086
7214
|
if (!element || !self.window) return 0;
|
|
7087
7215
|
|
|
7088
|
-
NSRect frame = element.
|
|
7216
|
+
NSRect frame = element.surfaceFrame;
|
|
7089
7217
|
if (NSIsEmptyRect(frame)) return 0;
|
|
7090
7218
|
|
|
7091
7219
|
NSPoint windowPoint = [self.window convertPointFromScreen:point];
|
|
@@ -7100,10 +7228,10 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7100
7228
|
}
|
|
7101
7229
|
|
|
7102
7230
|
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange {
|
|
7103
|
-
|
|
7231
|
+
NativeSdkWidgetAccessibilityElement *element = [self focusedTextAccessibilityElement];
|
|
7104
7232
|
NSRect localRect = NSZeroRect;
|
|
7105
7233
|
if (element) {
|
|
7106
|
-
NSRect frame = element.
|
|
7234
|
+
NSRect frame = element.surfaceFrame;
|
|
7107
7235
|
NSInteger characterCount = MAX(0, element.accessibilityNumberOfCharacters);
|
|
7108
7236
|
NSUInteger location = range.location == NSNotFound ? 0 : MIN(range.location, (NSUInteger)characterCount);
|
|
7109
7237
|
NSUInteger length = range.location == NSNotFound ? 0 : MIN(range.length, (NSUInteger)characterCount - location);
|
|
@@ -7126,8 +7254,8 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7126
7254
|
return self.window ? [self.window convertRectToScreen:windowRect] : windowRect;
|
|
7127
7255
|
}
|
|
7128
7256
|
|
|
7129
|
-
- (
|
|
7130
|
-
for (
|
|
7257
|
+
- (NativeSdkWidgetAccessibilityElement *)focusedTextAccessibilityElement {
|
|
7258
|
+
for (NativeSdkWidgetAccessibilityElement *element in self.widgetAccessibilityElements ?: @[]) {
|
|
7131
7259
|
if (!element.accessibilityFocused) continue;
|
|
7132
7260
|
if ([element.accessibilityRole isEqualToString:NSAccessibilityTextFieldRole]) return element;
|
|
7133
7261
|
}
|
|
@@ -7684,7 +7812,7 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7684
7812
|
|
|
7685
7813
|
@implementation NativeSdkAppKitHost
|
|
7686
7814
|
|
|
7687
|
-
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags {
|
|
7815
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription hasWebContent:(BOOL)hasWebContent dockVisible:(BOOL)dockVisible windowTitle:(NSString *)windowTitle bundleIdentifier:(NSString *)bundleIdentifier iconPath:(NSString *)iconPath windowLabel:(NSString *)windowLabel x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags {
|
|
7688
7816
|
self = [super init];
|
|
7689
7817
|
if (!self) {
|
|
7690
7818
|
return nil;
|
|
@@ -7692,7 +7820,8 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7692
7820
|
|
|
7693
7821
|
NativeSdkLaunchLap("host_init");
|
|
7694
7822
|
[NSApplication sharedApplication];
|
|
7695
|
-
|
|
7823
|
+
NSApplicationActivationPolicy policy = dockVisible ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory;
|
|
7824
|
+
[NSApp setActivationPolicy:policy];
|
|
7696
7825
|
NativeSdkLaunchLap("nsapp_ready");
|
|
7697
7826
|
NativeSdkRegisterBundledFonts();
|
|
7698
7827
|
NativeSdkLaunchLap("fonts_registered");
|
|
@@ -7733,7 +7862,7 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7733
7862
|
[self configureApplication];
|
|
7734
7863
|
NativeSdkLaunchLap("app_configured");
|
|
7735
7864
|
|
|
7736
|
-
[self createWindowWithId:1 title:(windowTitle.length > 0 ? windowTitle : self.appName) label:self.windowLabel x:x y:y width:width height:height restoreFrame:restoreFrame resizable:resizable titlebarStyle:titlebarStyle showPolicy:showPolicy windowFlags:windowFlags makeMain:YES];
|
|
7865
|
+
[self createWindowWithId:1 title:(windowTitle.length > 0 ? windowTitle : self.appName) label:self.windowLabel x:x y:y width:width height:height restoreFrame:restoreFrame initialPlacement:initialPlacement restorePolicy:restorePolicy resizable:resizable titlebarStyle:titlebarStyle showPolicy:showPolicy windowFlags:windowFlags makeMain:YES];
|
|
7737
7866
|
self.didShutdown = NO;
|
|
7738
7867
|
self.pendingPreRunStop = NO;
|
|
7739
7868
|
self.observesApplicationActivation = NO;
|
|
@@ -7741,16 +7870,23 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7741
7870
|
return self;
|
|
7742
7871
|
}
|
|
7743
7872
|
|
|
7744
|
-
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
7873
|
+
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle showPolicy:(int)showPolicy windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
7745
7874
|
NSNumber *key = @(windowId);
|
|
7746
7875
|
if (self.windows[key]) {
|
|
7747
7876
|
return NO;
|
|
7748
7877
|
}
|
|
7749
7878
|
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7879
|
+
(void)restoreFrame; // Persistence opt-in; initialPlacement says whether a frame was found.
|
|
7880
|
+
const BOOL restoredPlacement = initialPlacement == 0;
|
|
7881
|
+
// A restored center policy deliberately discards only the saved origin;
|
|
7882
|
+
// its saved OUTER size is reapplied after construction below. Fresh
|
|
7883
|
+
// frames remain content rectangles, preserving the public width/height
|
|
7884
|
+
// contract for authored windows.
|
|
7885
|
+
const BOOL centerOnPrimary = initialPlacement == 2 || (restoredPlacement && restorePolicy == 1);
|
|
7886
|
+
NSScreen *primaryScreen = NativeSdkPrimaryScreen();
|
|
7887
|
+
NSRect rect = centerOnPrimary
|
|
7888
|
+
? NativeSdkConstrainFrameToScreen(NSMakeRect(0, 0, width, height), primaryScreen)
|
|
7889
|
+
: NativeSdkConstrainFrame(NSMakeRect(x, y, width, height));
|
|
7754
7890
|
NSWindowStyleMask styleMask = NSWindowStyleMaskTitled |
|
|
7755
7891
|
NSWindowStyleMaskClosable |
|
|
7756
7892
|
NSWindowStyleMaskMiniaturizable;
|
|
@@ -7832,14 +7968,30 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7832
7968
|
window.toolbarStyle = NSWindowToolbarStyleUnified;
|
|
7833
7969
|
window.titlebarSeparatorStyle = NSTitlebarSeparatorStyleNone;
|
|
7834
7970
|
}
|
|
7835
|
-
if (
|
|
7836
|
-
|
|
7971
|
+
if (restoredPlacement) {
|
|
7972
|
+
// Window-state events persist content geometry. Convert that saved
|
|
7973
|
+
// rect through the window's FINAL chrome, then constrain/center the
|
|
7974
|
+
// completed outer frame so the content rect round-trips without
|
|
7975
|
+
// titlebar growth while the whole window stays visible.
|
|
7976
|
+
NSRect restoredContentFrame = NSMakeRect(x, y, width, height);
|
|
7977
|
+
NSRect restoredWindowFrame = [window frameRectForContentRect:restoredContentFrame];
|
|
7978
|
+
restoredWindowFrame = restorePolicy == 1
|
|
7979
|
+
? NativeSdkCenterFrameOnScreen(restoredWindowFrame, primaryScreen)
|
|
7980
|
+
: NativeSdkConstrainFrame(restoredWindowFrame);
|
|
7981
|
+
[window setFrame:restoredWindowFrame display:NO];
|
|
7982
|
+
} else if (initialPlacement == 1) {
|
|
7983
|
+
// Fresh authored dimensions are content size, but visibility is an
|
|
7984
|
+
// OUTER-frame guarantee. AppKit adds titlebar chrome during
|
|
7985
|
+
// construction, so constrain the completed frame as the final step.
|
|
7986
|
+
[window setFrame:NativeSdkConstrainFrame(window.frame) display:NO];
|
|
7987
|
+
} else if (centerOnPrimary) {
|
|
7988
|
+
[window setFrame:NativeSdkCenterFrameOnScreen(window.frame, primaryScreen) display:NO];
|
|
7837
7989
|
// AppKit centers every new window by default, which leaves a
|
|
7838
7990
|
// model-declared secondary window exactly covering the editor that
|
|
7839
7991
|
// opened it. Cascade from the active window like Win32's default
|
|
7840
7992
|
// placement so repeated Command+N windows stay visibly distinct.
|
|
7841
7993
|
NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;
|
|
7842
|
-
if (!makeMain && referenceWindow) {
|
|
7994
|
+
if (initialPlacement == 2 && restorePolicy == 0 && !makeMain && referenceWindow) {
|
|
7843
7995
|
NSRect referenceFrame = referenceWindow.frame;
|
|
7844
7996
|
NSRect cascadedFrame = window.frame;
|
|
7845
7997
|
cascadedFrame.origin.x = NSMinX(referenceFrame) + 24.0;
|
|
@@ -7861,7 +8013,7 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7861
8013
|
}
|
|
7862
8014
|
if (makeMain) NativeSdkLaunchLap("window_chrome_ready");
|
|
7863
8015
|
|
|
7864
|
-
NSView *container = [[NSView alloc] initWithFrame:
|
|
8016
|
+
NSView *container = [[NSView alloc] initWithFrame:window.contentView.bounds];
|
|
7865
8017
|
container.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
7866
8018
|
window.contentView = container;
|
|
7867
8019
|
// The window's MAIN WebView is created lazily
|
|
@@ -8357,6 +8509,7 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
8357
8509
|
case NATIVE_SDK_APPKIT_VIEW_GPU_SURFACE: {
|
|
8358
8510
|
NativeSdkMetalSurfaceView *surface = [[NativeSdkMetalSurfaceView alloc] initWithFrame:NSZeroRect];
|
|
8359
8511
|
if (![surface isAvailable]) return nil;
|
|
8512
|
+
[surface registerForDraggedTypes:@[NSPasteboardTypeFileURL]];
|
|
8360
8513
|
view = surface;
|
|
8361
8514
|
break;
|
|
8362
8515
|
}
|
|
@@ -9175,8 +9328,46 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
9175
9328
|
}
|
|
9176
9329
|
}
|
|
9177
9330
|
|
|
9178
|
-
static
|
|
9179
|
-
|
|
9331
|
+
static NSScreen *NativeSdkPrimaryScreen(void) {
|
|
9332
|
+
// AppKit's mainScreen follows the key window. The first screen is the
|
|
9333
|
+
// menu-bar display: macOS's primary screen and the policy contract.
|
|
9334
|
+
return [NSScreen screens].firstObject ?: [NSScreen mainScreen];
|
|
9335
|
+
}
|
|
9336
|
+
|
|
9337
|
+
static NSScreen *NativeSdkScreenForFrame(NSRect frame) {
|
|
9338
|
+
NSArray<NSScreen *> *screens = [NSScreen screens];
|
|
9339
|
+
NSScreen *bestScreen = nil;
|
|
9340
|
+
CGFloat bestArea = 0;
|
|
9341
|
+
for (NSScreen *screen in screens) {
|
|
9342
|
+
NSRect intersection = NSIntersectionRect(frame, screen.visibleFrame);
|
|
9343
|
+
CGFloat area = NSWidth(intersection) * NSHeight(intersection);
|
|
9344
|
+
if (area > bestArea) {
|
|
9345
|
+
bestArea = area;
|
|
9346
|
+
bestScreen = screen;
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
9349
|
+
if (bestScreen) return bestScreen;
|
|
9350
|
+
|
|
9351
|
+
// A frame from a disconnected display has no intersection. Clamp it to
|
|
9352
|
+
// the nearest remaining display instead of always teleporting to primary.
|
|
9353
|
+
NSPoint center = NSMakePoint(NSMidX(frame), NSMidY(frame));
|
|
9354
|
+
CGFloat bestDistance = CGFLOAT_MAX;
|
|
9355
|
+
for (NSScreen *screen in screens) {
|
|
9356
|
+
NSRect visible = screen.visibleFrame;
|
|
9357
|
+
CGFloat nearestX = MIN(MAX(center.x, NSMinX(visible)), NSMaxX(visible));
|
|
9358
|
+
CGFloat nearestY = MIN(MAX(center.y, NSMinY(visible)), NSMaxY(visible));
|
|
9359
|
+
CGFloat dx = center.x - nearestX;
|
|
9360
|
+
CGFloat dy = center.y - nearestY;
|
|
9361
|
+
CGFloat distance = dx * dx + dy * dy;
|
|
9362
|
+
if (distance < bestDistance) {
|
|
9363
|
+
bestDistance = distance;
|
|
9364
|
+
bestScreen = screen;
|
|
9365
|
+
}
|
|
9366
|
+
}
|
|
9367
|
+
return bestScreen ?: [NSScreen mainScreen];
|
|
9368
|
+
}
|
|
9369
|
+
|
|
9370
|
+
static NSRect NativeSdkConstrainFrameToScreen(NSRect frame, NSScreen *screen) {
|
|
9180
9371
|
if (!screen) return frame;
|
|
9181
9372
|
NSRect visible = screen.visibleFrame;
|
|
9182
9373
|
if (frame.size.width > visible.size.width) frame.size.width = visible.size.width;
|
|
@@ -9188,6 +9379,19 @@ static NSRect constrainFrame(NSRect frame) {
|
|
|
9188
9379
|
return frame;
|
|
9189
9380
|
}
|
|
9190
9381
|
|
|
9382
|
+
static NSRect NativeSdkConstrainFrame(NSRect frame) {
|
|
9383
|
+
return NativeSdkConstrainFrameToScreen(frame, NativeSdkScreenForFrame(frame));
|
|
9384
|
+
}
|
|
9385
|
+
|
|
9386
|
+
static NSRect NativeSdkCenterFrameOnScreen(NSRect frame, NSScreen *screen) {
|
|
9387
|
+
frame = NativeSdkConstrainFrameToScreen(frame, screen);
|
|
9388
|
+
if (!screen) return frame;
|
|
9389
|
+
NSRect visible = screen.visibleFrame;
|
|
9390
|
+
frame.origin.x = NSMidX(visible) - NSWidth(frame) / 2.0;
|
|
9391
|
+
frame.origin.y = NSMidY(visible) - NSHeight(frame) / 2.0;
|
|
9392
|
+
return NativeSdkConstrainFrameToScreen(frame, screen);
|
|
9393
|
+
}
|
|
9394
|
+
|
|
9191
9395
|
static NSString *NativeSdkAppKitBridgeScript(void) {
|
|
9192
9396
|
return @"(function(){"
|
|
9193
9397
|
"if(window.zero&&window.zero.invoke){return;}"
|
|
@@ -10037,7 +10241,16 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
|
|
|
10037
10241
|
- (void)emitWindowFrameForWindowId:(uint64_t)windowId open:(BOOL)open {
|
|
10038
10242
|
NSWindow *window = self.windows[@(windowId)] ?: self.window;
|
|
10039
10243
|
NSString *label = self.windowLabels[@(windowId)] ?: (windowId == 1 ? self.windowLabel : @"");
|
|
10040
|
-
|
|
10244
|
+
// The frame event's rect is the CONTENT rect in screen coordinates,
|
|
10245
|
+
// never window.frame: every consumer treats these numbers as content
|
|
10246
|
+
// geometry — shell layout bounds, the resize channel
|
|
10247
|
+
// (contentView.bounds), window-state persistence, and
|
|
10248
|
+
// createWindowWithId:'s initWithContentRect: round-trip — and the
|
|
10249
|
+
// GTK/Win32 hosts report content size on the same event. The outer
|
|
10250
|
+
// frame here laid shell views past the content's bottom edge on
|
|
10251
|
+
// open/restore and grew every restored window by the titlebar height
|
|
10252
|
+
// once per launch.
|
|
10253
|
+
NSRect frame = [window contentRectForFrameRect:window.frame];
|
|
10041
10254
|
[self emitEvent:(native_sdk_appkit_event_t){
|
|
10042
10255
|
.kind = NATIVE_SDK_APPKIT_EVENT_WINDOW_FRAME,
|
|
10043
10256
|
.window_id = windowId,
|
|
@@ -11884,7 +12097,7 @@ static void NativeSdkVideoFittedSize(double naturalWidth, double naturalHeight,
|
|
|
11884
12097
|
}];
|
|
11885
12098
|
}
|
|
11886
12099
|
|
|
11887
|
-
- (BOOL)emitDroppedFileURLs:(NSArray<NSURL *> *)urls windowId:(uint64_t)windowId {
|
|
12100
|
+
- (BOOL)emitDroppedFileURLs:(NSArray<NSURL *> *)urls windowId:(uint64_t)windowId viewLabel:(NSString *)viewLabel point:(NSPoint)point {
|
|
11888
12101
|
if (urls.count == 0) return NO;
|
|
11889
12102
|
NSMutableArray<NSString *> *paths = [NSMutableArray array];
|
|
11890
12103
|
for (NSURL *url in urls) {
|
|
@@ -11901,9 +12114,15 @@ static void NativeSdkVideoFittedSize(double naturalWidth, double naturalHeight,
|
|
|
11901
12114
|
[data appendData:pathData];
|
|
11902
12115
|
}
|
|
11903
12116
|
if (data.length == 0) return NO;
|
|
12117
|
+
NSString *safeViewLabel = viewLabel ?: @"";
|
|
12118
|
+
const char *viewLabelBytes = safeViewLabel.UTF8String ?: "";
|
|
11904
12119
|
[self emitEvent:(native_sdk_appkit_event_t){
|
|
11905
12120
|
.kind = NATIVE_SDK_APPKIT_EVENT_FILES_DROPPED,
|
|
11906
12121
|
.window_id = windowId,
|
|
12122
|
+
.x = point.x,
|
|
12123
|
+
.y = point.y,
|
|
12124
|
+
.view_label = viewLabelBytes,
|
|
12125
|
+
.view_label_len = [safeViewLabel lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
11907
12126
|
.drop_paths = data.bytes,
|
|
11908
12127
|
.drop_paths_len = data.length,
|
|
11909
12128
|
}];
|
|
@@ -12209,7 +12428,7 @@ static BOOL NativeSdkPolicyListMatches(NSArray<NSString *> *values, NSURL *url)
|
|
|
12209
12428
|
return NO;
|
|
12210
12429
|
}
|
|
12211
12430
|
|
|
12212
|
-
native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
12431
|
+
native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, int dock_visible, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int initial_placement, int restore_policy, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
12213
12432
|
@autoreleasepool {
|
|
12214
12433
|
NSString *appNameString = [[NSString alloc] initWithBytes:app_name length:app_name_len encoding:NSUTF8StringEncoding] ?: @"native-sdk";
|
|
12215
12434
|
NSString *displayNameString = [[NSString alloc] initWithBytes:display_name length:display_name_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
@@ -12219,7 +12438,7 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
|
|
|
12219
12438
|
NSString *bundleIdString = [[NSString alloc] initWithBytes:bundle_id length:bundle_id_len encoding:NSUTF8StringEncoding] ?: @"dev.native_sdk.app";
|
|
12220
12439
|
NSString *iconPathString = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
12221
12440
|
NSString *windowLabelString = [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] ?: @"main";
|
|
12222
|
-
NativeSdkAppKitHost *host = [[NativeSdkAppKitHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString hasWebContent:(has_web_content != 0) windowTitle:windowTitleString bundleIdentifier:bundleIdString iconPath:iconPathString windowLabel:windowLabelString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags];
|
|
12441
|
+
NativeSdkAppKitHost *host = [[NativeSdkAppKitHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString hasWebContent:(has_web_content != 0) dockVisible:(dock_visible != 0) windowTitle:windowTitleString bundleIdentifier:bundleIdString iconPath:iconPathString windowLabel:windowLabelString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) initialPlacement:initial_placement restorePolicy:restore_policy resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags];
|
|
12223
12442
|
return (__bridge_retained native_sdk_appkit_host_t *)host;
|
|
12224
12443
|
}
|
|
12225
12444
|
}
|
|
@@ -12537,11 +12756,11 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
|
|
|
12537
12756
|
[object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
|
|
12538
12757
|
}
|
|
12539
12758
|
|
|
12540
|
-
int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
12759
|
+
int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int initial_placement, int restore_policy, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
12541
12760
|
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
12542
12761
|
NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"";
|
|
12543
12762
|
NSString *labelString = window_label ? [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] : @"";
|
|
12544
|
-
return [object createWindowWithId:window_id title:titleString ?: @"" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags makeMain:NO] ? 1 : 0;
|
|
12763
|
+
return [object createWindowWithId:window_id title:titleString ?: @"" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) initialPlacement:initial_placement restorePolicy:restore_policy resizable:(resizable != 0) titlebarStyle:titlebar_style showPolicy:show_policy windowFlags:window_flags makeMain:NO] ? 1 : 0;
|
|
12545
12764
|
}
|
|
12546
12765
|
|
|
12547
12766
|
int native_sdk_appkit_set_window_content_min_size(native_sdk_appkit_host_t *host, uint64_t window_id, double min_width, double min_height) {
|