@native-sdk/cli 0.9.1 → 0.9.2
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 +55 -0
- 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/skill-data/native-ui/SKILL.md +7 -7
- package/skill-data/ts-core/SKILL.md +1 -1
- package/src/app_runner/root.zig +93 -6
- package/src/app_runner/ts_core_main.zig +4 -4
- package/src/app_runner/window_placement.zig +63 -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 +192 -40
- 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 +154 -9
- 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 +50 -0
- 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 +13 -2
- 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 +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- 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 +52 -0
- 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 +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -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 +580 -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_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 +31 -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/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/root.zig +2 -0
- 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/ui_app.zig +9 -3
- package/src/runtime/ui_app_tests.zig +119 -19
- 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_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/web_engine.zig +1 -1
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
#include <stdlib.h>
|
|
14
14
|
#include <string.h>
|
|
15
15
|
|
|
16
|
+
#include "../ios/apple_image_fit.h"
|
|
17
|
+
|
|
16
18
|
#include "include/cef_app.h"
|
|
17
19
|
#include "include/cef_browser.h"
|
|
18
20
|
#include "include/cef_client.h"
|
|
@@ -32,6 +34,7 @@
|
|
|
32
34
|
#endif
|
|
33
35
|
|
|
34
36
|
@class NativeSdkChromiumHost;
|
|
37
|
+
@class NativeSdkChromiumWindowDelegate;
|
|
35
38
|
|
|
36
39
|
@interface NativeSdkChromiumApplication : NSApplication <CefAppProtocol>
|
|
37
40
|
@property(nonatomic, assign) BOOL handlingSendEvent;
|
|
@@ -93,7 +96,12 @@ static int NativeSdkSetLaunchAtLogin(BOOL enabled) {
|
|
|
93
96
|
return succeeded ? NativeSdkLaunchAtLoginStatus() : -2;
|
|
94
97
|
}
|
|
95
98
|
static const char *NativeSdkCefBridgeScript();
|
|
99
|
+
static NSScreen *NativeSdkPrimaryScreen(void);
|
|
100
|
+
static NSScreen *NativeSdkScreenForFrame(NSRect frame);
|
|
101
|
+
static NSRect NativeSdkConstrainFrameToScreen(NSRect frame, NSScreen *screen);
|
|
96
102
|
static NSRect NativeSdkConstrainFrame(NSRect frame);
|
|
103
|
+
static NSRect NativeSdkCenterFrameOnScreen(NSRect frame, NSScreen *screen);
|
|
104
|
+
static void NativeSdkApplyHiddenInsetTitlebar(NSWindow *window, int titlebar_style, NativeSdkChromiumWindowDelegate *delegate);
|
|
97
105
|
static NSString *NativeSdkResolvedAssetRoot(NSString *rootPath);
|
|
98
106
|
static NSURL *NativeSdkAssetEntryFileURL(NSString *rootPath, NSString *entryPath);
|
|
99
107
|
static NSString *NativeSdkSafeAssetPath(NSURL *url, NSString *entryPath);
|
|
@@ -378,8 +386,42 @@ static NSString *NativeSdkCefFrameworkPath(void) {
|
|
|
378
386
|
return [devRoot stringByAppendingPathComponent:@"Release/Chromium Embedded Framework.framework"];
|
|
379
387
|
}
|
|
380
388
|
|
|
381
|
-
static
|
|
382
|
-
NSScreen
|
|
389
|
+
static NSScreen *NativeSdkPrimaryScreen(void) {
|
|
390
|
+
return [NSScreen screens].firstObject ?: [NSScreen mainScreen];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
static NSScreen *NativeSdkScreenForFrame(NSRect frame) {
|
|
394
|
+
NSArray<NSScreen *> *screens = [NSScreen screens];
|
|
395
|
+
NSScreen *bestScreen = nil;
|
|
396
|
+
CGFloat bestArea = 0;
|
|
397
|
+
for (NSScreen *screen in screens) {
|
|
398
|
+
NSRect intersection = NSIntersectionRect(frame, screen.visibleFrame);
|
|
399
|
+
CGFloat area = NSWidth(intersection) * NSHeight(intersection);
|
|
400
|
+
if (area > bestArea) {
|
|
401
|
+
bestArea = area;
|
|
402
|
+
bestScreen = screen;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (bestScreen) return bestScreen;
|
|
406
|
+
|
|
407
|
+
NSPoint center = NSMakePoint(NSMidX(frame), NSMidY(frame));
|
|
408
|
+
CGFloat bestDistance = CGFLOAT_MAX;
|
|
409
|
+
for (NSScreen *screen in screens) {
|
|
410
|
+
NSRect visible = screen.visibleFrame;
|
|
411
|
+
CGFloat nearestX = MIN(MAX(center.x, NSMinX(visible)), NSMaxX(visible));
|
|
412
|
+
CGFloat nearestY = MIN(MAX(center.y, NSMinY(visible)), NSMaxY(visible));
|
|
413
|
+
CGFloat dx = center.x - nearestX;
|
|
414
|
+
CGFloat dy = center.y - nearestY;
|
|
415
|
+
CGFloat distance = dx * dx + dy * dy;
|
|
416
|
+
if (distance < bestDistance) {
|
|
417
|
+
bestDistance = distance;
|
|
418
|
+
bestScreen = screen;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return bestScreen ?: [NSScreen mainScreen];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
static NSRect NativeSdkConstrainFrameToScreen(NSRect frame, NSScreen *screen) {
|
|
383
425
|
if (!screen) return frame;
|
|
384
426
|
NSRect visible = screen.visibleFrame;
|
|
385
427
|
if (frame.size.width > visible.size.width) frame.size.width = visible.size.width;
|
|
@@ -391,6 +433,19 @@ static NSRect NativeSdkConstrainFrame(NSRect frame) {
|
|
|
391
433
|
return frame;
|
|
392
434
|
}
|
|
393
435
|
|
|
436
|
+
static NSRect NativeSdkConstrainFrame(NSRect frame) {
|
|
437
|
+
return NativeSdkConstrainFrameToScreen(frame, NativeSdkScreenForFrame(frame));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
static NSRect NativeSdkCenterFrameOnScreen(NSRect frame, NSScreen *screen) {
|
|
441
|
+
frame = NativeSdkConstrainFrameToScreen(frame, screen);
|
|
442
|
+
if (!screen) return frame;
|
|
443
|
+
NSRect visible = screen.visibleFrame;
|
|
444
|
+
frame.origin.x = NSMidX(visible) - NSWidth(frame) / 2.0;
|
|
445
|
+
frame.origin.y = NSMidY(visible) - NSHeight(frame) / 2.0;
|
|
446
|
+
return NativeSdkConstrainFrameToScreen(frame, screen);
|
|
447
|
+
}
|
|
448
|
+
|
|
394
449
|
static const char *NativeSdkCefBridgeScript() {
|
|
395
450
|
return "(function(){"
|
|
396
451
|
"if(window.zero&&window.zero.invoke){return;}"
|
|
@@ -649,11 +704,11 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
649
704
|
@property(nonatomic, strong) NSArray<NSString *> *allowedNavigationOrigins;
|
|
650
705
|
@property(nonatomic, strong) NSArray<NSString *> *allowedExternalURLs;
|
|
651
706
|
@property(nonatomic, assign) NSInteger externalLinkAction;
|
|
652
|
-
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription title:(NSString *)title width:(double)width height:(double)height;
|
|
707
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription dockVisible:(BOOL)dockVisible title:(NSString *)title x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy titlebarStyle:(int)titlebarStyle;
|
|
653
708
|
- (void)configureApplication;
|
|
654
709
|
- (void)buildMenuBar;
|
|
655
710
|
- (NSMenuItem *)menuItem:(NSString *)title action:(SEL)action key:(NSString *)key modifiers:(NSEventModifierFlags)modifiers;
|
|
656
|
-
- (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 windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
711
|
+
- (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 windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
657
712
|
- (void)orderWindowForImplicitShow:(uint64_t)windowId;
|
|
658
713
|
- (void)focusWindowWithId:(uint64_t)windowId;
|
|
659
714
|
- (void)closeWindowWithId:(uint64_t)windowId;
|
|
@@ -852,13 +907,14 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
852
907
|
|
|
853
908
|
@implementation NativeSdkChromiumHost
|
|
854
909
|
|
|
855
|
-
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription title:(NSString *)title width:(double)width height:(double)height {
|
|
910
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription dockVisible:(BOOL)dockVisible title:(NSString *)title x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy titlebarStyle:(int)titlebarStyle {
|
|
856
911
|
self = [super init];
|
|
857
912
|
if (!self) return nil;
|
|
858
913
|
|
|
859
914
|
[NativeSdkChromiumApplication sharedApplication];
|
|
915
|
+
NSApplicationActivationPolicy policy = dockVisible ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory;
|
|
916
|
+
[NSApp setActivationPolicy:policy];
|
|
860
917
|
ensureCefInitialized();
|
|
861
|
-
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
862
918
|
self.appName = appName.length > 0 ? appName : @"native-sdk";
|
|
863
919
|
self.displayName = displayName.length > 0 ? displayName : self.appName;
|
|
864
920
|
self.appVersion = version ?: @"";
|
|
@@ -896,7 +952,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
896
952
|
self.externalLinkAction = 0;
|
|
897
953
|
self.shortcuts = @[];
|
|
898
954
|
|
|
899
|
-
[self createWindowWithId:1 title:(title.length > 0 ? title : self.appName) label:@"main" x:
|
|
955
|
+
[self createWindowWithId:1 title:(title.length > 0 ? title : self.appName) label:@"main" x:x y:y width:width height:height restoreFrame:restoreFrame initialPlacement:initialPlacement restorePolicy:restorePolicy resizable:YES titlebarStyle:titlebarStyle windowFlags:0 makeMain:YES];
|
|
900
956
|
self.didShutdown = NO;
|
|
901
957
|
self.pendingPreRunStop = NO;
|
|
902
958
|
self.observesApplicationActivation = NO;
|
|
@@ -1013,11 +1069,17 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1013
1069
|
delete self.browsers;
|
|
1014
1070
|
}
|
|
1015
1071
|
|
|
1016
|
-
- (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 windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
1072
|
+
- (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 windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
1017
1073
|
NSNumber *key = @(windowId);
|
|
1018
1074
|
if (self.windows[key]) return NO;
|
|
1019
1075
|
|
|
1020
|
-
|
|
1076
|
+
(void)restoreFrame; // Persistence opt-in; initialPlacement says whether a frame was found.
|
|
1077
|
+
const BOOL restoredPlacement = initialPlacement == 0;
|
|
1078
|
+
const BOOL centerOnPrimary = initialPlacement == 2 || (restoredPlacement && restorePolicy == 1);
|
|
1079
|
+
NSScreen *primaryScreen = NativeSdkPrimaryScreen();
|
|
1080
|
+
NSRect rect = centerOnPrimary
|
|
1081
|
+
? NativeSdkConstrainFrameToScreen(NSMakeRect(0, 0, width, height), primaryScreen)
|
|
1082
|
+
: NativeSdkConstrainFrame(NSMakeRect(x, y, width, height));
|
|
1021
1083
|
NSWindowStyleMask styleMask = NSWindowStyleMaskTitled |
|
|
1022
1084
|
NSWindowStyleMaskClosable |
|
|
1023
1085
|
NSWindowStyleMaskMiniaturizable;
|
|
@@ -1042,13 +1104,33 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1042
1104
|
[window standardWindowButton:NSWindowZoomButton].enabled = NO;
|
|
1043
1105
|
}
|
|
1044
1106
|
[window setTitle:title.length > 0 ? title : @"native-sdk"];
|
|
1045
|
-
|
|
1046
|
-
|
|
1107
|
+
NativeSdkChromiumWindowDelegate *delegate = [[NativeSdkChromiumWindowDelegate alloc] init];
|
|
1108
|
+
delegate.host = self;
|
|
1109
|
+
delegate.windowId = windowId;
|
|
1110
|
+
window.delegate = delegate;
|
|
1111
|
+
// Install the final titlebar before converting persisted content
|
|
1112
|
+
// geometry back to an outer frame; the conversion must include the
|
|
1113
|
+
// actual chrome the window will keep.
|
|
1114
|
+
NativeSdkApplyHiddenInsetTitlebar(window, titlebarStyle, delegate);
|
|
1115
|
+
if (restoredPlacement) {
|
|
1116
|
+
NSRect restoredContentFrame = NSMakeRect(x, y, width, height);
|
|
1117
|
+
NSRect restoredWindowFrame = [window frameRectForContentRect:restoredContentFrame];
|
|
1118
|
+
restoredWindowFrame = restorePolicy == 1
|
|
1119
|
+
? NativeSdkCenterFrameOnScreen(restoredWindowFrame, primaryScreen)
|
|
1120
|
+
: NativeSdkConstrainFrame(restoredWindowFrame);
|
|
1121
|
+
[window setFrame:restoredWindowFrame display:NO];
|
|
1122
|
+
} else if (initialPlacement == 1) {
|
|
1123
|
+
// AppKit adds titlebar chrome to the authored content rectangle;
|
|
1124
|
+
// constrain the completed OUTER frame so no chrome escapes the
|
|
1125
|
+
// matching or nearest display's visible bounds.
|
|
1126
|
+
[window setFrame:NativeSdkConstrainFrame(window.frame) display:NO];
|
|
1127
|
+
} else if (centerOnPrimary) {
|
|
1128
|
+
[window setFrame:NativeSdkCenterFrameOnScreen(window.frame, primaryScreen) display:NO];
|
|
1047
1129
|
// Match the system-WebView host and Win32's default placement:
|
|
1048
1130
|
// secondary windows should reveal the window that opened them,
|
|
1049
1131
|
// not land directly on top of it.
|
|
1050
1132
|
NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;
|
|
1051
|
-
if (!makeMain && referenceWindow) {
|
|
1133
|
+
if (initialPlacement == 2 && restorePolicy == 0 && !makeMain && referenceWindow) {
|
|
1052
1134
|
NSRect referenceFrame = referenceWindow.frame;
|
|
1053
1135
|
NSRect cascadedFrame = window.frame;
|
|
1054
1136
|
cascadedFrame.origin.x = NSMinX(referenceFrame) + 24.0;
|
|
@@ -1066,7 +1148,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1066
1148
|
}
|
|
1067
1149
|
}
|
|
1068
1150
|
|
|
1069
|
-
NSView *stackRoot = [[NSView alloc] initWithFrame:
|
|
1151
|
+
NSView *stackRoot = [[NSView alloc] initWithFrame:window.contentView.bounds];
|
|
1070
1152
|
stackRoot.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
1071
1153
|
window.contentView = stackRoot;
|
|
1072
1154
|
|
|
@@ -1076,10 +1158,6 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1076
1158
|
browserContainer.layer.zPosition = 0;
|
|
1077
1159
|
[stackRoot addSubview:browserContainer positioned:NSWindowAbove relativeTo:nil];
|
|
1078
1160
|
|
|
1079
|
-
NativeSdkChromiumWindowDelegate *delegate = [[NativeSdkChromiumWindowDelegate alloc] init];
|
|
1080
|
-
delegate.host = self;
|
|
1081
|
-
delegate.windowId = windowId;
|
|
1082
|
-
window.delegate = delegate;
|
|
1083
1161
|
CefRefPtr<NativeSdkCefClient> client = new NativeSdkCefClient(self, windowId);
|
|
1084
1162
|
|
|
1085
1163
|
self.windows[key] = window;
|
|
@@ -1428,7 +1506,12 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1428
1506
|
- (void)emitWindowFrameForWindowId:(uint64_t)windowId open:(BOOL)open {
|
|
1429
1507
|
NSWindow *window = self.windows[@(windowId)] ?: self.window;
|
|
1430
1508
|
NSString *label = self.windowLabels[@(windowId)] ?: @"";
|
|
1431
|
-
|
|
1509
|
+
// The frame event's rect is the CONTENT rect in screen coordinates,
|
|
1510
|
+
// never window.frame: consumers treat these numbers as content
|
|
1511
|
+
// geometry (shell layout, the resize channel, window-state
|
|
1512
|
+
// persistence, and the initWithContentRect: round-trip) — see the
|
|
1513
|
+
// AppKit host's emitWindowFrameForWindowId:.
|
|
1514
|
+
NSRect frame = [window contentRectForFrameRect:window.frame];
|
|
1432
1515
|
[self emitEvent:(native_sdk_appkit_event_t){
|
|
1433
1516
|
.kind = NATIVE_SDK_APPKIT_EVENT_WINDOW_FRAME,
|
|
1434
1517
|
.window_id = windowId,
|
|
@@ -2328,7 +2411,7 @@ static void NativeSdkApplyOverlayWindowFlags(NativeSdkChromiumHost *host, uint64
|
|
|
2328
2411
|
}
|
|
2329
2412
|
}
|
|
2330
2413
|
|
|
2331
|
-
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) {
|
|
2414
|
+
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) {
|
|
2332
2415
|
@autoreleasepool {
|
|
2333
2416
|
// A windowed CEF child cannot paint transparent pixels into its
|
|
2334
2417
|
// parent NSWindow. Refuse instead of accepting a flag that leaves
|
|
@@ -2355,14 +2438,10 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
|
|
|
2355
2438
|
NSString *versionString = [[NSString alloc] initWithBytes:version length:version_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
2356
2439
|
NSString *aboutDescriptionString = [[NSString alloc] initWithBytes:about_description length:about_description_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
2357
2440
|
NSString *titleString = [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] ?: appNameString;
|
|
2358
|
-
NativeSdkChromiumHost *host = [[NativeSdkChromiumHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString title:titleString width:width height:height];
|
|
2359
|
-
if (restore_frame) {
|
|
2360
|
-
[host.window setFrame:NativeSdkConstrainFrame(NSMakeRect(x, y, width, height)) display:NO];
|
|
2361
|
-
}
|
|
2441
|
+
NativeSdkChromiumHost *host = [[NativeSdkChromiumHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString dockVisible:(dock_visible != 0) title:titleString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) initialPlacement:initial_placement restorePolicy:restore_policy titlebarStyle:titlebar_style];
|
|
2362
2442
|
if (!resizable) {
|
|
2363
2443
|
host.window.styleMask &= ~NSWindowStyleMaskResizable;
|
|
2364
2444
|
}
|
|
2365
|
-
NativeSdkApplyHiddenInsetTitlebar(host.window, titlebar_style, host.delegates[@1]);
|
|
2366
2445
|
NativeSdkApplyOverlayWindowFlags(host, 1, window_flags);
|
|
2367
2446
|
if (show_policy == 2) [host.policyHiddenWindows addObject:@1];
|
|
2368
2447
|
return (__bridge_retained native_sdk_appkit_host_t *)host;
|
|
@@ -2610,13 +2689,12 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
|
|
|
2610
2689
|
[object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
|
|
2611
2690
|
}
|
|
2612
2691
|
|
|
2613
|
-
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) {
|
|
2692
|
+
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) {
|
|
2614
2693
|
if ((window_flags & (1u << 0)) != 0) return 0;
|
|
2615
2694
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
2616
2695
|
NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"native-sdk";
|
|
2617
2696
|
NSString *labelString = window_label ? [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] : @"";
|
|
2618
|
-
if (![object createWindowWithId:window_id title:titleString ?: @"native-sdk" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) windowFlags:window_flags makeMain:NO]) return 0;
|
|
2619
|
-
NativeSdkApplyHiddenInsetTitlebar(object.windows[@(window_id)], titlebar_style, object.delegates[@(window_id)]);
|
|
2697
|
+
if (![object createWindowWithId:window_id title:titleString ?: @"native-sdk" 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 windowFlags:window_flags makeMain:NO]) return 0;
|
|
2620
2698
|
// Apply chrome and overlay presentation while still hidden, then
|
|
2621
2699
|
// reveal once so a secondary window cannot flash its default frame.
|
|
2622
2700
|
if (show_policy == 2) {
|
|
@@ -3120,25 +3198,45 @@ int native_sdk_appkit_measure_text_advances(uint64_t font_id, double size, const
|
|
|
3120
3198
|
* system SVG rasterizer, with no host state, so both engines decode
|
|
3121
3199
|
* identically. See appkit_host.h for the pixel-format and return-value
|
|
3122
3200
|
* contract. */
|
|
3123
|
-
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) {
|
|
3201
|
+
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) {
|
|
3124
3202
|
if (out_width) *out_width = 0;
|
|
3125
3203
|
if (out_height) *out_height = 0;
|
|
3126
|
-
if (!bytes || bytes_len == 0 || !pixels) return 0;
|
|
3204
|
+
if (!bytes || bytes_len == 0 || !pixels || max_pixels == 0) return 0;
|
|
3127
3205
|
@autoreleasepool {
|
|
3128
3206
|
NSData *data = [NSData dataWithBytesNoCopy:(void *)bytes length:bytes_len freeWhenDone:NO];
|
|
3129
3207
|
CGImageRef image = NULL;
|
|
3130
3208
|
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
|
|
3131
3209
|
if (source) {
|
|
3132
|
-
|
|
3210
|
+
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
|
|
3211
|
+
int64_t source_width_value = 0;
|
|
3212
|
+
int64_t source_height_value = 0;
|
|
3213
|
+
if (properties) {
|
|
3214
|
+
CFNumberRef width_value = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
|
|
3215
|
+
CFNumberRef height_value = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
|
|
3216
|
+
if (width_value) CFNumberGetValue(width_value, kCFNumberSInt64Type, &source_width_value);
|
|
3217
|
+
if (height_value) CFNumberGetValue(height_value, kCFNumberSInt64Type, &source_height_value);
|
|
3218
|
+
CFRelease(properties);
|
|
3219
|
+
}
|
|
3220
|
+
size_t source_width = source_width_value > 0 ? (size_t)source_width_value : 0;
|
|
3221
|
+
size_t source_height = source_height_value > 0 ? (size_t)source_height_value : 0;
|
|
3222
|
+
if (source_width > 0 && source_height > 0) {
|
|
3223
|
+
const size_t max_dimension = native_sdk_apple_image_thumbnail_max_dimension(source_width, source_height, max_pixels);
|
|
3224
|
+
NSDictionary *thumbnail_options = @{
|
|
3225
|
+
(NSString *)kCGImageSourceCreateThumbnailFromImageAlways: @YES,
|
|
3226
|
+
(NSString *)kCGImageSourceThumbnailMaxPixelSize: @(max_dimension),
|
|
3227
|
+
(NSString *)kCGImageSourceCreateThumbnailWithTransform: @YES,
|
|
3228
|
+
};
|
|
3229
|
+
image = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef)thumbnail_options);
|
|
3230
|
+
}
|
|
3133
3231
|
CFRelease(source);
|
|
3134
3232
|
}
|
|
3135
3233
|
if (!image) {
|
|
3136
3234
|
NSImage *system_image = [[NSImage alloc] initWithData:data];
|
|
3137
3235
|
NSSize size = system_image ? system_image.size : NSZeroSize;
|
|
3138
|
-
if (size.width > 0 && size.height > 0 && size.width
|
|
3236
|
+
if (size.width > 0 && size.height > 0 && isfinite(size.width) && isfinite(size.height)) {
|
|
3139
3237
|
// Bound SVG rasterization before NSImage materializes the
|
|
3140
3238
|
// screen-scale representation; see the AppKit mirror.
|
|
3141
|
-
const CGFloat max_raster_points =
|
|
3239
|
+
const CGFloat max_raster_points = sqrt((CGFloat)max_pixels) / 2.0;
|
|
3142
3240
|
const CGFloat raster_scale = MIN(1.0, MIN(max_raster_points / size.width, max_raster_points / size.height));
|
|
3143
3241
|
NSRect proposed = NSMakeRect(0, 0, size.width * raster_scale, size.height * raster_scale);
|
|
3144
3242
|
CGImageRef rendered = [system_image CGImageForProposedRect:&proposed context:nil hints:nil];
|
|
@@ -3149,14 +3247,14 @@ int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8
|
|
|
3149
3247
|
|
|
3150
3248
|
size_t width = CGImageGetWidth(image);
|
|
3151
3249
|
size_t height = CGImageGetHeight(image);
|
|
3152
|
-
if (width == 0 || height == 0 || width >
|
|
3250
|
+
if (width == 0 || height == 0 || width > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION || height > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION) {
|
|
3153
3251
|
CGImageRelease(image);
|
|
3154
3252
|
return 0;
|
|
3155
3253
|
}
|
|
3156
3254
|
if (out_width) *out_width = width;
|
|
3157
3255
|
if (out_height) *out_height = height;
|
|
3158
3256
|
size_t byte_len = width * height * 4;
|
|
3159
|
-
if (byte_len / 4 / height != width || pixels_len < byte_len) {
|
|
3257
|
+
if (width > max_pixels / height || byte_len / 4 / height != width || pixels_len < byte_len) {
|
|
3160
3258
|
CGImageRelease(image);
|
|
3161
3259
|
return -1;
|
|
3162
3260
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <ImageIO/ImageIO.h>
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include "../ios/apple_image_fit.h"
|
|
6
|
+
|
|
7
|
+
/* Test-only ImageIO probe linked by build.zig, not by apps. It exercises the
|
|
8
|
+
* platform's real secondary-dimension rounding against the shared fit helper
|
|
9
|
+
* without pulling the full AppKit host into the framework unit-test binary. */
|
|
10
|
+
int native_sdk_test_imageio_thumbnail_dimensions(
|
|
11
|
+
const uint8_t *bytes,
|
|
12
|
+
size_t bytes_len,
|
|
13
|
+
size_t source_width,
|
|
14
|
+
size_t source_height,
|
|
15
|
+
size_t max_pixels,
|
|
16
|
+
size_t *out_width,
|
|
17
|
+
size_t *out_height
|
|
18
|
+
) {
|
|
19
|
+
if (out_width) *out_width = 0;
|
|
20
|
+
if (out_height) *out_height = 0;
|
|
21
|
+
if (!bytes || bytes_len == 0) return 0;
|
|
22
|
+
@autoreleasepool {
|
|
23
|
+
NSData *data = [NSData dataWithBytesNoCopy:(void *)bytes length:bytes_len freeWhenDone:NO];
|
|
24
|
+
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
|
|
25
|
+
if (!source) return 0;
|
|
26
|
+
const size_t max_dimension = native_sdk_apple_image_thumbnail_max_dimension(
|
|
27
|
+
source_width,
|
|
28
|
+
source_height,
|
|
29
|
+
max_pixels
|
|
30
|
+
);
|
|
31
|
+
NSDictionary *options = @{
|
|
32
|
+
(NSString *)kCGImageSourceCreateThumbnailFromImageAlways: @YES,
|
|
33
|
+
(NSString *)kCGImageSourceThumbnailMaxPixelSize: @(max_dimension),
|
|
34
|
+
(NSString *)kCGImageSourceCreateThumbnailWithTransform: @YES,
|
|
35
|
+
};
|
|
36
|
+
CGImageRef image = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef)options);
|
|
37
|
+
CFRelease(source);
|
|
38
|
+
if (!image) return 0;
|
|
39
|
+
if (out_width) *out_width = CGImageGetWidth(image);
|
|
40
|
+
if (out_height) *out_height = CGImageGetHeight(image);
|
|
41
|
+
CGImageRelease(image);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
}
|