@geastack/apple 0.2.14 → 0.2.16
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/dist/index.js +7 -0
- package/generated/ActivityKit.d.ts +3 -0
- package/generated/AppKit.d.ts +5 -0
- package/generated/CoreGraphics.d.ts +3 -0
- package/generated/CoreLocation.d.ts +1 -0
- package/generated/CoreMedia.d.ts +1 -0
- package/generated/Dispatch.d.ts +2 -0
- package/generated/Foundation.d.ts +7 -0
- package/generated/MapKit.d.ts +1 -0
- package/generated/Metal.d.ts +2 -0
- package/generated/Security.d.ts +3 -0
- package/generated/SwiftData.d.ts +5 -0
- package/generated/UIKit.d.ts +1 -0
- package/generated/UserNotifications.d.ts +3 -0
- package/package.json +7 -7
- package/targets/ios/generate-xcode-project.mjs +5 -0
- package/targets/macos/app-compiler-plugins.mjs +22 -0
- package/targets/macos/build-macos.sh +108 -6
- package/targets/macos/generate-resident-entry.mjs +1 -1
- package/targets/macos/main/canvas_view.mm +8 -8
- package/targets/macos/main/color_convert.h +3 -3
- package/targets/macos/main/color_convert.mm +12 -12
- package/targets/macos/main/font_registry.h +2 -0
- package/targets/macos/main/font_registry.mm +72 -51
- package/targets/macos/main/image_bridge.h +5 -2
- package/targets/macos/main/image_bridge.mm +47 -9
- package/targets/macos/main/macos_background_test.h +54 -0
- package/targets/macos/main/macos_control_admission.h +13 -0
- package/targets/macos/main/macos_display.mm +29 -27
- package/targets/macos/main/macos_key_event.h +73 -0
- package/targets/macos/main/macos_main.mm +410 -14
- package/targets/macos/main/macos_renderer.h +5 -0
- package/targets/macos/main/macos_renderer.mm +717 -80
- package/targets/macos/main/press_bridge.h +21 -3
- package/targets/macos/main/press_bridge.mm +126 -26
- package/targets/macos/sync-resources.mjs +24 -2
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
#import <CoreImage/CoreImage.h>
|
|
6
6
|
|
|
7
7
|
#include "macos_renderer.h"
|
|
8
|
+
#include "ui/selector.h"
|
|
9
|
+
#include "ui/control_commit.h"
|
|
10
|
+
#include "ui/input_retirement.h"
|
|
11
|
+
#include <exception>
|
|
12
|
+
#include <stdexcept>
|
|
13
|
+
#include "macos_control_admission.h"
|
|
8
14
|
#include "canvas_view.h"
|
|
9
15
|
#include "color_convert.h"
|
|
10
16
|
#include "font_registry.h"
|
|
@@ -20,11 +26,69 @@
|
|
|
20
26
|
|
|
21
27
|
#include <algorithm>
|
|
22
28
|
#include <cmath>
|
|
29
|
+
#include <charconv>
|
|
30
|
+
#include <limits>
|
|
23
31
|
#include <string>
|
|
24
32
|
#include <cstring>
|
|
25
33
|
#include <cstdlib>
|
|
26
34
|
#include <vector>
|
|
27
35
|
|
|
36
|
+
// Native views retain the allocation they were bound to. A queued callback
|
|
37
|
+
// must not authenticate a reused integer id by looking up its NEW owner.
|
|
38
|
+
@interface GeaNativeBinding : NSObject {
|
|
39
|
+
@public
|
|
40
|
+
int nodeId;
|
|
41
|
+
gea::framework::identity::Owner owner;
|
|
42
|
+
BOOL active;
|
|
43
|
+
}
|
|
44
|
+
- (instancetype)initWithNode:(int)node;
|
|
45
|
+
@end
|
|
46
|
+
@implementation GeaNativeBinding
|
|
47
|
+
- (instancetype)initWithNode:(int)node {
|
|
48
|
+
if((self=[super init])){nodeId=node;owner=gea::framework::identity::node(node);active=YES;}
|
|
49
|
+
return self;
|
|
50
|
+
}
|
|
51
|
+
@end
|
|
52
|
+
static bool geaViewBindingCurrent(NSView *view,int node) {
|
|
53
|
+
GeaNativeBinding *binding=objc_getAssociatedObject(view,"gea.node_binding");
|
|
54
|
+
return binding && binding->active && binding->nodeId==node && gea::framework::identity::current(node,binding->owner);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static bool geaControlAdmitted(NSView *view,int node) {
|
|
58
|
+
GeaNativeBinding *binding=objc_getAssociatedObject(view,"gea.node_binding");
|
|
59
|
+
return binding && binding->active && binding->nodeId==node && gea::macos::controlAdmitted(node,binding->owner);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Native responder leases retain the allocation captured at the actual focus
|
|
63
|
+
// transition. The view is weak: retaining focus never extends a native view.
|
|
64
|
+
struct GeaFocusLease { __weak NSView* view=nil; gea::embedded::ui::NodeHandle node; };
|
|
65
|
+
static GeaFocusLease geaFocused;
|
|
66
|
+
static gea::embedded::ui::NodeHandle geaPendingFocus;
|
|
67
|
+
static bool geaOwnsResponder(NSView*view){if(!view||!view.window)return false;NSResponder*first=view.window.firstResponder;if(first==view)return true;return [view isKindOfClass:NSTextField.class]&&[(NSTextField*)view currentEditor]&&first==[(NSTextField*)view currentEditor];}
|
|
68
|
+
static void geaClearFocusedView(NSView*view,bool descendants=false){
|
|
69
|
+
NSView*focused=geaFocused.view;if(!focused||!(focused==view||(descendants&&[focused isDescendantOf:view])))return;
|
|
70
|
+
auto old=geaFocused.node;geaFocused.view=nil;geaFocused.node={};
|
|
71
|
+
auto&t=gea::embedded::ui::Tree::instance();if(old.valid()&&t.activeInputId()==old.id())t.setActiveInput(-1);
|
|
72
|
+
}
|
|
73
|
+
static void geaNativeFocusBegan(NSView*view,int node,bool acceptedTransition=false){
|
|
74
|
+
if(!view.window||(!acceptedTransition&&!geaOwnsResponder(view))||!geaControlAdmitted(view,node))return;
|
|
75
|
+
gea::embedded::ui::NodeHandle owner(node);if(!owner.isConnected())return;
|
|
76
|
+
geaFocused.view=view;geaFocused.node=owner;gea::embedded::ui::Tree::instance().setActiveInput(node);
|
|
77
|
+
}
|
|
78
|
+
static void geaNativeFocusEnded(NSView*view){geaClearFocusedView(view);}
|
|
79
|
+
static void geaRetireNativeView(NSView *view) {
|
|
80
|
+
GeaNativeBinding *binding=objc_getAssociatedObject(view,"gea.node_binding");
|
|
81
|
+
// A generic logical node can focus the root responder, which is an ancestor
|
|
82
|
+
// rather than a descendant of its materialized view. Retire its exact subtree
|
|
83
|
+
// allocation as well; ordinary responder-end callbacks stay exact-view only.
|
|
84
|
+
if(binding&&binding->active&&gea::framework::identity::current(binding->nodeId,binding->owner)&&geaFocused.node.valid()&&gea::embedded::ui::Tree::instance().containsNode(binding->nodeId,geaFocused.node.id())){
|
|
85
|
+
NSView*focused=geaFocused.view;geaClearFocusedView(focused);
|
|
86
|
+
}else geaClearFocusedView(view,true);
|
|
87
|
+
if(binding)binding->active=NO;
|
|
88
|
+
PressBridge *bridge=objc_getAssociatedObject(view,"gea.press_bridge");
|
|
89
|
+
if(bridge)bridge.nodeId=-1;
|
|
90
|
+
}
|
|
91
|
+
|
|
28
92
|
// NSTextField defaults to consuming mouse events even when bezeled / editable /
|
|
29
93
|
// selectable are all NO. Keep labels in hit testing so the press bridge can
|
|
30
94
|
// preserve their node identity and bubble through their logical ancestors.
|
|
@@ -38,10 +102,33 @@
|
|
|
38
102
|
// full bounds, with no implicit padding, so the text fits the same space
|
|
39
103
|
// our host measurement reported.
|
|
40
104
|
@interface GeaTextCell : NSTextFieldCell
|
|
105
|
+
@property(nonatomic, assign) NSEdgeInsets contentInsets;
|
|
106
|
+
@property(nonatomic, assign) BOOL verticallyCenters;
|
|
41
107
|
@end
|
|
42
108
|
@implementation GeaTextCell
|
|
43
109
|
- (NSRect)drawingRectForBounds:(NSRect)bounds { return bounds; }
|
|
44
110
|
- (NSRect)titleRectForBounds:(NSRect)bounds { return bounds; }
|
|
111
|
+
- (NSRect)contentRectForBounds:(NSRect)bounds inView:(NSView *)view
|
|
112
|
+
{
|
|
113
|
+
const NSEdgeInsets inset = self.contentInsets;
|
|
114
|
+
bounds.origin.x += inset.left;
|
|
115
|
+
bounds.origin.y += view.isFlipped ? inset.top : inset.bottom;
|
|
116
|
+
bounds.size.width = std::max<CGFloat>(0, bounds.size.width - inset.left - inset.right);
|
|
117
|
+
bounds.size.height = std::max<CGFloat>(0, bounds.size.height - inset.top - inset.bottom);
|
|
118
|
+
return bounds;
|
|
119
|
+
}
|
|
120
|
+
- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view
|
|
121
|
+
{
|
|
122
|
+
// NSString drawing respects paragraph alignment without NSTextFieldCell's
|
|
123
|
+
// extra centered-text margins. The engine owns the CSS border/content boxes.
|
|
124
|
+
NSRect content = [self contentRectForBounds:frame inView:view];
|
|
125
|
+
if (self.verticallyCenters) {
|
|
126
|
+
const NSRect measured = [self.attributedStringValue boundingRectWithSize:NSMakeSize(content.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
|
|
127
|
+
content.origin.y += std::max<CGFloat>(0, (content.size.height - measured.size.height) / 2);
|
|
128
|
+
}
|
|
129
|
+
[self.attributedStringValue drawWithRect:content
|
|
130
|
+
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
|
|
131
|
+
}
|
|
45
132
|
@end
|
|
46
133
|
|
|
47
134
|
@interface GeaLabelTextField : NSTextField
|
|
@@ -53,6 +140,30 @@
|
|
|
53
140
|
- (void)mouseUp:(NSEvent *)event { [self.nextResponder mouseUp:event]; }
|
|
54
141
|
@end
|
|
55
142
|
|
|
143
|
+
@interface GeaInputCell : NSTextFieldCell
|
|
144
|
+
@property(nonatomic, assign) NSEdgeInsets contentInsets;
|
|
145
|
+
@end
|
|
146
|
+
@implementation GeaInputCell
|
|
147
|
+
- (NSRect)drawingRectForBounds:(NSRect)bounds
|
|
148
|
+
{
|
|
149
|
+
const NSEdgeInsets inset = self.contentInsets;
|
|
150
|
+
bounds.origin.x += inset.left;
|
|
151
|
+
bounds.origin.y += self.controlView.isFlipped ? inset.top : inset.bottom;
|
|
152
|
+
bounds.size.width = std::max<CGFloat>(0, bounds.size.width - inset.left - inset.right);
|
|
153
|
+
bounds.size.height = std::max<CGFloat>(0, bounds.size.height - inset.top - inset.bottom);
|
|
154
|
+
return bounds;
|
|
155
|
+
}
|
|
156
|
+
- (NSRect)titleRectForBounds:(NSRect)bounds { return [self drawingRectForBounds:bounds]; }
|
|
157
|
+
- (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event
|
|
158
|
+
{
|
|
159
|
+
[super editWithFrame:[self drawingRectForBounds:frame] inView:view editor:editor delegate:delegate event:event];
|
|
160
|
+
}
|
|
161
|
+
- (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(NSInteger)start length:(NSInteger)length
|
|
162
|
+
{
|
|
163
|
+
[super selectWithFrame:[self drawingRectForBounds:frame] inView:view editor:editor delegate:delegate start:start length:length];
|
|
164
|
+
}
|
|
165
|
+
@end
|
|
166
|
+
|
|
56
167
|
// Editable text field used to materialize `<input>` JSX elements. Holds the
|
|
57
168
|
// owning node id and forwards `controlTextDidChange:` to the framework as an
|
|
58
169
|
// `input` PointerEvent; the framework's per-node listener registry then routes
|
|
@@ -62,11 +173,12 @@
|
|
|
62
173
|
// `keydown` events with the corresponding `keyCode` value JS apps expect
|
|
63
174
|
// (matching the browser keyCode table for the few keys the framework cares
|
|
64
175
|
// about — Enter, Backspace, arrows, Escape, Tab).
|
|
65
|
-
@interface GeaInputField : NSTextField <NSTextFieldDelegate>
|
|
176
|
+
@interface GeaInputField : NSTextField <NSTextFieldDelegate> { gea::embedded::ui::ControlCommit _geaCommit; BOOL _geaEditing; }
|
|
66
177
|
@property(nonatomic, assign) int nodeId;
|
|
67
178
|
@end
|
|
68
179
|
|
|
69
180
|
@implementation GeaInputField
|
|
181
|
+
+ (Class)cellClass { return [GeaInputCell class]; }
|
|
70
182
|
|
|
71
183
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
72
184
|
{
|
|
@@ -102,7 +214,7 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
102
214
|
using gea::framework::events::PointerEvent;
|
|
103
215
|
if (_nodeId < 0) return;
|
|
104
216
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
105
|
-
if (_nodeId
|
|
217
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
106
218
|
PointerEvent event;
|
|
107
219
|
event.type = type;
|
|
108
220
|
event.targetId = _nodeId;
|
|
@@ -110,18 +222,24 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
110
222
|
tree.dispatchEvent(event);
|
|
111
223
|
}
|
|
112
224
|
|
|
225
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,_nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,_nodeId,true);return accepted;}
|
|
226
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
227
|
+
- (void)controlTextDidBeginEditing:(NSNotification *)note { (void)note;if(!geaControlAdmitted(self,_nodeId))return;geaNativeFocusBegan(self,_nodeId);_geaCommit.begin(_nodeId);_geaEditing=YES; }
|
|
228
|
+
- (void)controlTextDidEndEditing:(NSNotification *)note { (void)note;geaNativeFocusEnded(self);if(!_geaEditing)return;_geaEditing=NO;if(!geaControlAdmitted(self,_nodeId))return;auto commit=_geaCommit;commit.commit(); }
|
|
113
229
|
- (void)controlTextDidChange:(NSNotification *)note
|
|
114
230
|
{
|
|
115
231
|
(void)note;
|
|
116
232
|
if (_nodeId < 0) return;
|
|
117
233
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
118
|
-
if (_nodeId
|
|
234
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
235
|
+
if(!_geaEditing){_geaCommit.begin(_nodeId);_geaEditing=YES;}
|
|
119
236
|
const std::string newValue = std::string([self.stringValue UTF8String] ?: "");
|
|
120
237
|
// Mirror the current text into the node's `value` attribute. The
|
|
121
238
|
// framework's DOM-shim reads `event.currentTarget.value` by falling
|
|
122
239
|
// through to `getAttribute("value")`, so the user's onInput handler sees
|
|
123
240
|
// the latest text without us needing a dedicated event-payload slot.
|
|
124
241
|
tree.setAttribute(_nodeId, "value", newValue.c_str());
|
|
242
|
+
_geaCommit.edited(_nodeId);
|
|
125
243
|
[self dispatchEventOfType:gea::framework::events::PointerEventType::Input withKeyCode:0];
|
|
126
244
|
}
|
|
127
245
|
|
|
@@ -150,7 +268,7 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
150
268
|
// listens for text changes and reflects them to the node's `value` attribute
|
|
151
269
|
// so user code reading `event.currentTarget.value` (or observing the store
|
|
152
270
|
// bound to it) sees the latest text.
|
|
153
|
-
@interface GeaTextAreaView : NSTextView <NSTextViewDelegate>
|
|
271
|
+
@interface GeaTextAreaView : NSTextView <NSTextViewDelegate> { gea::embedded::ui::ControlCommit _geaCommit; BOOL _geaEditing; }
|
|
154
272
|
@property(nonatomic, assign) int nodeId;
|
|
155
273
|
@property(nonatomic, assign) BOOL suppressChangeNotification;
|
|
156
274
|
@end
|
|
@@ -176,6 +294,10 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
176
294
|
return self;
|
|
177
295
|
}
|
|
178
296
|
|
|
297
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,_nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,_nodeId,true);return accepted;}
|
|
298
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
299
|
+
- (void)textDidBeginEditing:(NSNotification *)note { (void)note;if(!geaControlAdmitted(self,_nodeId))return;geaNativeFocusBegan(self,_nodeId);_geaCommit.begin(_nodeId);_geaEditing=YES; }
|
|
300
|
+
- (void)textDidEndEditing:(NSNotification *)note { (void)note;geaNativeFocusEnded(self);if(!_geaEditing)return;_geaEditing=NO;if(!geaControlAdmitted(self,_nodeId))return;auto commit=_geaCommit;commit.commit(); }
|
|
179
301
|
- (void)textDidChange:(NSNotification *)note
|
|
180
302
|
{
|
|
181
303
|
(void)note;
|
|
@@ -183,9 +305,11 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
183
305
|
using gea::framework::events::PointerEvent;
|
|
184
306
|
using gea::framework::events::PointerEventType;
|
|
185
307
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
186
|
-
if (_nodeId
|
|
308
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
309
|
+
if(!_geaEditing){_geaCommit.begin(_nodeId);_geaEditing=YES;}
|
|
187
310
|
const std::string newValue = std::string([self.string UTF8String] ?: "");
|
|
188
311
|
tree.setAttribute(_nodeId, "value", newValue.c_str());
|
|
312
|
+
_geaCommit.edited(_nodeId);
|
|
189
313
|
PointerEvent event;
|
|
190
314
|
event.type = PointerEventType::Input;
|
|
191
315
|
event.targetId = _nodeId;
|
|
@@ -194,6 +318,71 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
194
318
|
}
|
|
195
319
|
@end
|
|
196
320
|
|
|
321
|
+
static bool geaBooleanAttribute(int nodeId, const char *name)
|
|
322
|
+
{
|
|
323
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
324
|
+
const char *value = tree.getAttribute(nodeId, name);
|
|
325
|
+
return tree.hasAttribute(nodeId, name) && (!value || (std::strcmp(value, "false") != 0 && std::strcmp(value, "0") != 0));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static void geaControlInput(NSView *view, int nodeId, const char *value, const char *checked = nullptr)
|
|
329
|
+
{
|
|
330
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
331
|
+
if (!geaControlAdmitted(view,nodeId)) return;
|
|
332
|
+
gea::embedded::ui::ControlCommit commit;commit.begin(nodeId,checked?"checked":"value");
|
|
333
|
+
if (value) tree.setAttribute(nodeId, "value", value);
|
|
334
|
+
if (checked) tree.setAttribute(nodeId, "checked", checked);
|
|
335
|
+
commit.edited(nodeId);
|
|
336
|
+
gea::framework::events::PointerEvent event;
|
|
337
|
+
event.type = gea::framework::events::PointerEventType::Input;
|
|
338
|
+
event.targetId = nodeId;
|
|
339
|
+
tree.dispatchEvent(event);
|
|
340
|
+
commit.commit();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
@interface GeaChoice : NSButton
|
|
344
|
+
@property(nonatomic, assign) int nodeId;
|
|
345
|
+
@property(nonatomic, assign) BOOL radio;
|
|
346
|
+
@end
|
|
347
|
+
@implementation GeaChoice
|
|
348
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,self.nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,self.nodeId,true);return accepted;}
|
|
349
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
350
|
+
- (void)geaChanged:(id)sender
|
|
351
|
+
{
|
|
352
|
+
(void)sender;
|
|
353
|
+
if (!geaControlAdmitted(self,self.nodeId)) return;
|
|
354
|
+
if (self.radio) self.state = NSControlStateValueOn;
|
|
355
|
+
geaControlInput(self, self.nodeId, nullptr, self.state == NSControlStateValueOn ? "true" : "false");
|
|
356
|
+
}
|
|
357
|
+
@end
|
|
358
|
+
|
|
359
|
+
@interface GeaPopUp : NSPopUpButton
|
|
360
|
+
@property(nonatomic, assign) int nodeId;
|
|
361
|
+
@end
|
|
362
|
+
@implementation GeaPopUp
|
|
363
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,self.nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,self.nodeId,true);return accepted;}
|
|
364
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
365
|
+
- (void)geaChanged:(id)sender
|
|
366
|
+
{
|
|
367
|
+
(void)sender;
|
|
368
|
+
NSString *value = self.selectedItem.representedObject ?: self.selectedItem.title;
|
|
369
|
+
geaControlInput(self, self.nodeId, [value UTF8String] ?: "");
|
|
370
|
+
}
|
|
371
|
+
@end
|
|
372
|
+
|
|
373
|
+
@interface GeaStepper : NSStepper
|
|
374
|
+
@property(nonatomic, assign) int nodeId;
|
|
375
|
+
@end
|
|
376
|
+
@implementation GeaStepper
|
|
377
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,self.nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,self.nodeId,true);return accepted;}
|
|
378
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
379
|
+
- (void)geaChanged:(id)sender
|
|
380
|
+
{
|
|
381
|
+
(void)sender;
|
|
382
|
+
geaControlInput(self, self.nodeId, [[NSString stringWithFormat:@"%.15g", self.doubleValue] UTF8String]);
|
|
383
|
+
}
|
|
384
|
+
@end
|
|
385
|
+
|
|
197
386
|
// Root-level press handler. Installed once on the contentView during
|
|
198
387
|
// MacosRenderer::sync. On mouse-down, asks the recognizer for the location,
|
|
199
388
|
// hit-tests against the root, then walks up via nodeIdForView to find the
|
|
@@ -205,6 +394,7 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
205
394
|
@interface GeaRootClickBridge : NSObject <NSGestureRecognizerDelegate>
|
|
206
395
|
@property(nonatomic, weak) NSView *rootView;
|
|
207
396
|
@property(nonatomic, assign) int pressedNodeId; // -1 when no press in flight
|
|
397
|
+
@property(nonatomic,strong) GeaNativeBinding *pressedBinding;
|
|
208
398
|
// Tree-space origin of rootView: 0,0 for a window root, the pane node's
|
|
209
399
|
// layout.x/y for a split-view pane.
|
|
210
400
|
@property(nonatomic, assign) int originX;
|
|
@@ -215,6 +405,8 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
215
405
|
@property(nonatomic, assign) int lastY;
|
|
216
406
|
@property(nonatomic, assign) BOOL dragged;
|
|
217
407
|
- (void)fire:(NSGestureRecognizer *)gr;
|
|
408
|
+
@property(nonatomic, assign) BOOL ending;
|
|
409
|
+
- (BOOL)closeInputBinding:(GeaNativeBinding *)binding;
|
|
218
410
|
@end
|
|
219
411
|
|
|
220
412
|
namespace gea::macos {
|
|
@@ -226,17 +418,61 @@ static NSView *hitTestInRoot(NSView *root, NSPoint point)
|
|
|
226
418
|
return [root hitTest:[root convertPoint:point toView:root.superview]];
|
|
227
419
|
}
|
|
228
420
|
|
|
421
|
+
void publishControlEventBounds(int nodeId)
|
|
422
|
+
{
|
|
423
|
+
auto &tree=gea::embedded::ui::Tree::instance();
|
|
424
|
+
for(int control=nodeId;control>=0;control=tree.node(control).parent){
|
|
425
|
+
if(std::strcmp(tree.getAttribute(control,"data-gea-control"),"true")!=0)continue;
|
|
426
|
+
auto bounds=tree.node(control).layout;
|
|
427
|
+
// Range values follow the thumb's actual travel, excluding arrow
|
|
428
|
+
// buttons, frame padding, and the value label.
|
|
429
|
+
const int owner=tree.node(control).parent;
|
|
430
|
+
const char *ownerType=tree.getAttribute(owner,"data-xaml-type");
|
|
431
|
+
if(std::strcmp(tree.getAttribute(control,"role"),"slider")==0 || std::strcmp(ownerType,"Slider")==0 || std::strcmp(ownerType,"LSSlider")==0){
|
|
432
|
+
for(int thumb=0;thumb<tree.nodeCount();++thumb){
|
|
433
|
+
const char *type=tree.getAttribute(thumb,"data-xaml-type");
|
|
434
|
+
if(std::strcmp(type,"LSThumb")!=0&&std::strcmp(type,"Thumb")!=0)continue;
|
|
435
|
+
bool belongs=false;
|
|
436
|
+
for(int ancestor=tree.node(thumb).parent;ancestor>=0;ancestor=tree.node(ancestor).parent)if(ancestor==owner){belongs=true;break;}
|
|
437
|
+
const int track=tree.node(thumb).parent;
|
|
438
|
+
if(!belongs||track<0)continue;
|
|
439
|
+
const auto &thumbBox=tree.node(thumb).layout;
|
|
440
|
+
const auto &trackBox=tree.node(track).layout;
|
|
441
|
+
if(trackBox.width>thumbBox.width){bounds.x=trackBox.x+thumbBox.width/2;bounds.width=trackBox.width-thumbBox.width;}
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
tree.setAttribute(control,"data-gea-x",std::to_string(bounds.x).c_str());
|
|
446
|
+
tree.setAttribute(control,"data-gea-y",std::to_string(bounds.y).c_str());
|
|
447
|
+
tree.setAttribute(control,"data-gea-width",std::to_string(bounds.width).c_str());
|
|
448
|
+
tree.setAttribute(control,"data-gea-height",std::to_string(bounds.height).c_str());
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
229
453
|
int nodeIdForView(NSView *view)
|
|
230
454
|
{
|
|
231
455
|
while (view) {
|
|
232
456
|
NSNumber *n = objc_getAssociatedObject(view, "gea.node_id");
|
|
233
|
-
if (n) return n.intValue;
|
|
457
|
+
if (n) return geaViewBindingCurrent(view,n.intValue)?n.intValue:-1;
|
|
234
458
|
view = view.superview;
|
|
235
459
|
}
|
|
236
460
|
return -1;
|
|
237
461
|
}
|
|
238
462
|
} // namespace gea::macos
|
|
239
463
|
|
|
464
|
+
static void geaEmitRootCancellation(const gea::embedded::ui::NodeHandle &owner,int x,int y) {
|
|
465
|
+
if(!owner.valid())return;
|
|
466
|
+
gea::framework::events::PointerEvent event{};
|
|
467
|
+
event.type=gea::framework::events::PointerEventType::PointerCancel;event.targetId=owner.id();event.pointerId=1;
|
|
468
|
+
event.x=event.clientX=event.pageX=event.screenX=x;event.y=event.clientY=event.pageY=event.screenY=y;
|
|
469
|
+
event.changedTouchesLength=1;event.changedTouches[0].identifier=1;
|
|
470
|
+
event.changedTouches[0].target=gea::framework::events::EventTarget(owner.id());
|
|
471
|
+
event.changedTouches[0].clientX=event.changedTouches[0].pageX=event.changedTouches[0].screenX=x;
|
|
472
|
+
event.changedTouches[0].clientY=event.changedTouches[0].pageY=event.changedTouches[0].screenY=y;
|
|
473
|
+
gea::embedded::ui::Tree::instance().dispatchEvent(event);
|
|
474
|
+
}
|
|
475
|
+
|
|
240
476
|
@implementation GeaRootClickBridge
|
|
241
477
|
|
|
242
478
|
- (instancetype)init
|
|
@@ -268,8 +504,18 @@ int nodeIdForView(NSView *view)
|
|
|
268
504
|
if (nodeId < 0) return;
|
|
269
505
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
270
506
|
if (nodeId >= tree.nodeCount()) return;
|
|
271
|
-
|
|
272
|
-
|
|
507
|
+
if(!self.pressedBinding || !self.pressedBinding->active || self.pressedBinding->nodeId!=nodeId ||
|
|
508
|
+
!gea::framework::identity::current(nodeId,self.pressedBinding->owner))return;
|
|
509
|
+
bool retireDisabled=false;
|
|
510
|
+
if(type!=PointerEventType::PointerCancel && !gea::macos::controlAdmitted(nodeId,self.pressedBinding->owner)) {
|
|
511
|
+
if(type==PointerEventType::TouchStart || type==PointerEventType::Click) {
|
|
512
|
+
self.pressedNodeId=-1;self.pressedBinding=nil;return;
|
|
513
|
+
}
|
|
514
|
+
type=PointerEventType::PointerCancel;retireDisabled=true;
|
|
515
|
+
}
|
|
516
|
+
gea::macos::publishControlEventBounds(nodeId);
|
|
517
|
+
PointerEvent ev;
|
|
518
|
+
ev.type = type;
|
|
273
519
|
ev.targetId = nodeId;
|
|
274
520
|
ev.pointerId = 1;
|
|
275
521
|
ev.x = px;
|
|
@@ -296,6 +542,7 @@ int nodeIdForView(NSView *view)
|
|
|
296
542
|
ev.targetTouches[0] = point;
|
|
297
543
|
ev.changedTouches[0] = point;
|
|
298
544
|
tree.dispatchEvent(ev);
|
|
545
|
+
if(retireDisabled){self.pressedNodeId=-1;self.pressedBinding=nil;}
|
|
299
546
|
};
|
|
300
547
|
|
|
301
548
|
switch (gr.state) {
|
|
@@ -306,13 +553,17 @@ int nodeIdForView(NSView *view)
|
|
|
306
553
|
// editor's value guard no longer skips, letting the title/body refresh
|
|
307
554
|
// to the newly selected note. (Clicks on editable fields never reach
|
|
308
555
|
// this recognizer — the delegate declines them.)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
556
|
+
bool customInputs=false;
|
|
557
|
+
auto &inputTree=gea::embedded::ui::Tree::instance();
|
|
558
|
+
for(int i=0;i<inputTree.nodeCount();++i)if(std::strcmp(inputTree.getAttribute(i,"data-gea-inputs"),"true")==0){customInputs=true;break;}
|
|
559
|
+
if(customInputs)[root.window makeFirstResponder:root];
|
|
560
|
+
else if(root.window.firstResponder!=root.window)[root.window makeFirstResponder:nil];
|
|
561
|
+
|
|
312
562
|
// Mouse-down: hit-test now, remember the node so the move and up
|
|
313
563
|
// phases dispatch to the same target even if the cursor drifts.
|
|
314
564
|
NSView *hit = gea::macos::hitTestInRoot(root, pInRoot);
|
|
315
565
|
self.pressedNodeId = gea::macos::nodeIdForView(hit);
|
|
566
|
+
self.pressedBinding=[[GeaNativeBinding alloc] initWithNode:self.pressedNodeId];self.ending=NO;
|
|
316
567
|
self.startX = x;
|
|
317
568
|
self.startY = y;
|
|
318
569
|
self.lastX = x;
|
|
@@ -334,9 +585,21 @@ int nodeIdForView(NSView *view)
|
|
|
334
585
|
case NSGestureRecognizerStateCancelled:
|
|
335
586
|
case NSGestureRecognizerStateFailed: {
|
|
336
587
|
const int nodeId = self.pressedNodeId;
|
|
337
|
-
self.
|
|
338
|
-
|
|
339
|
-
|
|
588
|
+
GeaNativeBinding *terminalBinding=self.pressedBinding;
|
|
589
|
+
self.pressedNodeId = -1;self.ending=YES;
|
|
590
|
+
// Retire this terminal lease even when a user callback throws. A
|
|
591
|
+
// reentrant Begin owns a different binding and must survive this frame.
|
|
592
|
+
auto closeTerminal = [&]() {
|
|
593
|
+
if(self.pressedBinding==terminalBinding){self.pressedBinding=nil;self.ending=NO;}
|
|
594
|
+
};
|
|
595
|
+
try {
|
|
596
|
+
fireEvent(nodeId, gr.state==NSGestureRecognizerStateEnded?PointerEventType::TouchEnd:PointerEventType::PointerCancel, self.lastX, self.lastY, false);
|
|
597
|
+
if (self.pressedBinding==terminalBinding && gr.state == NSGestureRecognizerStateEnded && !self.dragged) fireEvent(nodeId, PointerEventType::Click, self.lastX, self.lastY, false);
|
|
598
|
+
} catch (...) {
|
|
599
|
+
closeTerminal();
|
|
600
|
+
throw;
|
|
601
|
+
}
|
|
602
|
+
closeTerminal();
|
|
340
603
|
break;
|
|
341
604
|
}
|
|
342
605
|
default:
|
|
@@ -344,6 +607,13 @@ int nodeIdForView(NSView *view)
|
|
|
344
607
|
}
|
|
345
608
|
}
|
|
346
609
|
|
|
610
|
+
- (BOOL)closeInputBinding:(GeaNativeBinding *)binding {
|
|
611
|
+
if(!binding || self.pressedBinding!=binding)return NO;
|
|
612
|
+
const BOOL emit=!self.ending && gea::framework::identity::current(binding->nodeId,binding->owner);
|
|
613
|
+
binding->active=NO;self.pressedBinding=nil;self.pressedNodeId=-1;self.ending=NO;
|
|
614
|
+
return emit;
|
|
615
|
+
}
|
|
616
|
+
|
|
347
617
|
// Don't let the root press-recognizer swallow clicks that land on an editable
|
|
348
618
|
// text control (the note title <input> / body <textarea>). If we recognized
|
|
349
619
|
// those, the field never becomes first responder and the user can't focus or
|
|
@@ -359,8 +629,12 @@ int nodeIdForView(NSView *view)
|
|
|
359
629
|
const NSPoint p = [root convertPoint:event.locationInWindow fromView:nil];
|
|
360
630
|
NSView *hit = gea::macos::hitTestInRoot(root, p);
|
|
361
631
|
for (NSView *v = hit; v != nil; v = v.superview) {
|
|
632
|
+
// Native controls own their tracking loops and dispatch their own actions.
|
|
633
|
+
// Recognizing a root press as well steals drags, menu tracking and repeats.
|
|
634
|
+
if ([v isKindOfClass:[NSButton class]] || [v isKindOfClass:[NSSlider class]] ||
|
|
635
|
+
[v isKindOfClass:[NSSwitch class]] || [v isKindOfClass:[NSStepper class]]) return NO;
|
|
362
636
|
if ([v isKindOfClass:[NSTextView class]]) return NO;
|
|
363
|
-
if ([v isKindOfClass:[NSTextField class]] && ((NSTextField *)v).isEditable) return NO;
|
|
637
|
+
if ([v isKindOfClass:[NSTextField class]] && (((NSTextField *)v).isEditable || ((NSTextField *)v).isSelectable)) return NO;
|
|
364
638
|
// Canvas views dispatch their own coordinate-carrying touch events
|
|
365
639
|
// (mouseDown/Dragged/Up in GeaCanvasView) — recognizing here too would
|
|
366
640
|
// double-fire the press.
|
|
@@ -432,7 +706,7 @@ struct GeaSyncDepthScope {
|
|
|
432
706
|
{
|
|
433
707
|
if (self.nodeId < 0) return;
|
|
434
708
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
435
|
-
if (self.nodeId >= tree.nodeCount()) return;
|
|
709
|
+
if (self.nodeId >= tree.nodeCount() || !geaViewBindingCurrent(self,self.nodeId)) return;
|
|
436
710
|
const CGFloat y = self.bounds.origin.y;
|
|
437
711
|
const CGFloat maxY = std::max<CGFloat>(0, NSHeight(self.documentView.frame) - NSHeight(self.bounds));
|
|
438
712
|
if (y < -0.5 || y > maxY + 0.5) return;
|
|
@@ -444,12 +718,14 @@ struct GeaSyncDepthScope {
|
|
|
444
718
|
// change it writes its integer value into the node's `value` attribute and
|
|
445
719
|
// dispatches an `input` PointerEvent, so the app's onInput handler reads the new
|
|
446
720
|
// value off event.currentTarget.value (same convention as GeaInputField).
|
|
447
|
-
@interface GeaSlider : NSSlider
|
|
721
|
+
@interface GeaSlider : NSSlider { gea::embedded::ui::ControlCommit _geaCommit; }
|
|
448
722
|
@property(nonatomic, assign) int nodeId;
|
|
449
723
|
@property(nonatomic, assign) BOOL geaDragging;
|
|
450
724
|
@end
|
|
451
725
|
|
|
452
726
|
@implementation GeaSlider
|
|
727
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,self.nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,self.nodeId,true);return accepted;}
|
|
728
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
453
729
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
454
730
|
{
|
|
455
731
|
if ((self = [super initWithFrame:frameRect])) {
|
|
@@ -462,22 +738,54 @@ struct GeaSyncDepthScope {
|
|
|
462
738
|
{
|
|
463
739
|
// Guard the tracking loop so applySliderProps doesn't fight the user's drag
|
|
464
740
|
// by writing back a (possibly lagging) bound value mid-gesture.
|
|
465
|
-
|
|
741
|
+
if(!geaControlAdmitted(self,_nodeId))return;
|
|
742
|
+
_geaCommit.begin(_nodeId);_geaDragging = YES;
|
|
466
743
|
[super mouseDown:event];
|
|
467
744
|
_geaDragging = NO;
|
|
745
|
+
auto commit=_geaCommit;commit.commit();
|
|
468
746
|
}
|
|
469
747
|
- (void)geaChanged:(id)sender
|
|
470
748
|
{
|
|
471
749
|
(void)sender;
|
|
472
750
|
if (_nodeId < 0) return;
|
|
473
751
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
474
|
-
if (_nodeId
|
|
475
|
-
|
|
476
|
-
|
|
752
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
753
|
+
gea::embedded::ui::ControlCommit discreteCommit;if(!_geaDragging)discreteCommit.begin(_nodeId);
|
|
754
|
+
// Keep the range contract in doubles: signed fractional controls (gain,
|
|
755
|
+
// pan) must not pass through the former unsigned integer rounding path.
|
|
756
|
+
const double minimum = self.minValue, maximum = self.maxValue;
|
|
757
|
+
double v = self.doubleValue;
|
|
758
|
+
if (!std::isfinite(v) || !std::isfinite(minimum) ||
|
|
759
|
+
!std::isfinite(maximum) || maximum < minimum) return;
|
|
760
|
+
v = std::clamp(v, minimum, maximum);
|
|
761
|
+
const char *stepAttribute = tree.getAttribute(_nodeId, "step");
|
|
762
|
+
if (!stepAttribute || std::strcmp(stepAttribute, "any") != 0) {
|
|
763
|
+
double step = 1.0;
|
|
764
|
+
if (stepAttribute && stepAttribute[0]) {
|
|
765
|
+
char *end = nullptr;
|
|
766
|
+
const double parsed = std::strtod(stepAttribute, &end);
|
|
767
|
+
if (end != stepAttribute && *end == '\0' && std::isfinite(parsed) && parsed > 0)
|
|
768
|
+
step = parsed;
|
|
769
|
+
}
|
|
770
|
+
const long double span = ((long double)maximum - minimum) / step;
|
|
771
|
+
// Attribute doubles can put an aligned maximum a few ulps below its
|
|
772
|
+
// integer index. Admit that endpoint, but never an out-of-range step.
|
|
773
|
+
const long double tolerance = 8 * std::numeric_limits<double>::epsilon() * std::max(1.0L, std::abs(span));
|
|
774
|
+
const long double last = std::floor(span + tolerance);
|
|
775
|
+
const long double index = std::clamp(std::floor(((long double)v - minimum) / step + 0.5L), 0.0L, last);
|
|
776
|
+
v = std::clamp((double)((long double)minimum + index * step), minimum, maximum);
|
|
777
|
+
}
|
|
778
|
+
// Shortest round-trippable decimal, without to_string's six-digit loss.
|
|
779
|
+
char value[64];
|
|
780
|
+
const auto encoded = std::to_chars(value, value + sizeof(value), v == 0 ? 0.0 : v);
|
|
781
|
+
if (encoded.ec != std::errc{}) return;
|
|
782
|
+
tree.setAttribute(_nodeId, "value", std::string(value, encoded.ptr).c_str());
|
|
783
|
+
if(_geaDragging)_geaCommit.edited(_nodeId);else discreteCommit.edited(_nodeId);
|
|
477
784
|
gea::framework::events::PointerEvent event;
|
|
478
785
|
event.type = gea::framework::events::PointerEventType::Input;
|
|
479
786
|
event.targetId = _nodeId;
|
|
480
787
|
tree.dispatchEvent(event);
|
|
788
|
+
if(!_geaDragging)discreteCommit.commit();
|
|
481
789
|
}
|
|
482
790
|
@end
|
|
483
791
|
|
|
@@ -489,6 +797,8 @@ struct GeaSyncDepthScope {
|
|
|
489
797
|
@end
|
|
490
798
|
|
|
491
799
|
@implementation GeaSwitch
|
|
800
|
+
- (BOOL)becomeFirstResponder {if(!geaControlAdmitted(self,self.nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,self.nodeId,true);return accepted;}
|
|
801
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
492
802
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
493
803
|
{
|
|
494
804
|
if ((self = [super initWithFrame:frameRect])) {
|
|
@@ -501,13 +811,68 @@ struct GeaSyncDepthScope {
|
|
|
501
811
|
(void)sender;
|
|
502
812
|
if (_nodeId < 0) return;
|
|
503
813
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
504
|
-
if (_nodeId
|
|
814
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
505
815
|
const bool on = self.state == NSControlStateValueOn;
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
816
|
+
geaControlInput(self,_nodeId,nullptr,on?"true":"false");
|
|
817
|
+
}
|
|
818
|
+
@end
|
|
819
|
+
|
|
820
|
+
#include "macos_key_event.h"
|
|
821
|
+
static bool geaDispatchButtonKey(NSButton *button,NSEvent *native,bool up) {
|
|
822
|
+
PressBridge *bridge=objc_getAssociatedObject(button,"gea.press_bridge");
|
|
823
|
+
if(!bridge || !geaControlAdmitted(button,bridge.nodeId))return true;
|
|
824
|
+
auto event=geaNativeKey(native,false,up);event.targetId=bridge.nodeId;
|
|
825
|
+
gea::embedded::ui::dispatchRootKeyEvent(event);
|
|
826
|
+
return event.defaultPrevented;
|
|
827
|
+
}
|
|
828
|
+
@interface GeaButton : NSButton
|
|
829
|
+
@property(nonatomic) NSUInteger geaKeyboardTicket;
|
|
830
|
+
@property(nonatomic) unsigned short geaHeldKey;
|
|
831
|
+
- (void)geaTrackMouseEvent:(NSEvent *)event;
|
|
832
|
+
@end
|
|
833
|
+
@implementation GeaButton
|
|
834
|
+
- (BOOL)becomeFirstResponder {PressBridge*b=objc_getAssociatedObject(self,"gea.press_bridge");if(!b||!geaControlAdmitted(self,b.nodeId))return NO;const BOOL accepted=[super becomeFirstResponder];if(accepted)geaNativeFocusBegan(self,b.nodeId,true);return accepted;}
|
|
835
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)geaNativeFocusEnded(self);return accepted;}
|
|
836
|
+
- (void)geaTrackMouseEvent:(NSEvent *)event { [super mouseDown:event]; }
|
|
837
|
+
- (void)mouseDown:(NSEvent *)event {
|
|
838
|
+
if(!self.enabled || !geaControlAdmitted(self,[(PressBridge*)objc_getAssociatedObject(self,"gea.press_bridge") nodeId]))return;
|
|
839
|
+
PressBridge *bridge=objc_getAssociatedObject(self,"gea.press_bridge");
|
|
840
|
+
const auto ticket=[bridge beginPointerPress:event];if(!ticket)return;
|
|
841
|
+
@try { [self geaTrackMouseEvent:event]; }
|
|
842
|
+
@finally { [bridge endPressTracking:ticket]; }
|
|
843
|
+
}
|
|
844
|
+
- (void)cancelOperation:(id)sender {
|
|
845
|
+
PressBridge *bridge=objc_getAssociatedObject(self,"gea.press_bridge");
|
|
846
|
+
[bridge cancelPress:sender];
|
|
847
|
+
if(self.geaKeyboardTicket)[bridge endPressTracking:self.geaKeyboardTicket];
|
|
848
|
+
self.geaKeyboardTicket=0;[self highlight:NO];
|
|
849
|
+
}
|
|
850
|
+
- (void)keyDown:(NSEvent *)event {
|
|
851
|
+
if(event.keyCode==53 && self.geaKeyboardTicket)[self cancelOperation:self];
|
|
852
|
+
if(geaDispatchButtonKey(self,event,false))return;
|
|
853
|
+
if(event.keyCode!=49 && event.keyCode!=36 && event.keyCode!=76){[super keyDown:event];return;}
|
|
854
|
+
if(!self.enabled || event.isARepeat || self.geaKeyboardTicket)return;
|
|
855
|
+
PressBridge *bridge=objc_getAssociatedObject(self,"gea.press_bridge");
|
|
856
|
+
self.geaKeyboardTicket=[bridge beginKeyboardPress:self];self.geaHeldKey=event.keyCode;
|
|
857
|
+
if(self.geaKeyboardTicket)[self highlight:YES];
|
|
858
|
+
}
|
|
859
|
+
- (void)keyUp:(NSEvent *)event {
|
|
860
|
+
PressBridge *admission=objc_getAssociatedObject(self,"gea.press_bridge");
|
|
861
|
+
if(!geaControlAdmitted(self,admission.nodeId)){[self cancelOperation:self];return;}
|
|
862
|
+
const bool handled=geaDispatchButtonKey(self,event,true);
|
|
863
|
+
if(!self.geaKeyboardTicket || event.keyCode!=self.geaHeldKey){
|
|
864
|
+
// A cancelled/repeated activation key has no native default to replay.
|
|
865
|
+
if(!handled && event.keyCode!=49 && event.keyCode!=36 && event.keyCode!=76)[super keyUp:event];
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
PressBridge *bridge=objc_getAssociatedObject(self,"gea.press_bridge");
|
|
869
|
+
const auto ticket=self.geaKeyboardTicket;self.geaKeyboardTicket=0;
|
|
870
|
+
if(handled)[bridge cancelPress:self];else [bridge fire:self];
|
|
871
|
+
[bridge endPressTracking:ticket];[self highlight:NO];
|
|
872
|
+
}
|
|
873
|
+
- (void)setEnabled:(BOOL)enabled { if(!enabled)[self cancelOperation:self];[super setEnabled:enabled]; }
|
|
874
|
+
- (void)viewWillMoveToWindow:(NSWindow *)window {
|
|
875
|
+
if(!window)[self cancelOperation:self];[super viewWillMoveToWindow:window];
|
|
511
876
|
}
|
|
512
877
|
@end
|
|
513
878
|
|
|
@@ -608,9 +973,44 @@ NSView *makeSwitch()
|
|
|
608
973
|
return sw;
|
|
609
974
|
}
|
|
610
975
|
|
|
976
|
+
NSView *makeChoice(bool radio)
|
|
977
|
+
{
|
|
978
|
+
GeaChoice *choice = [[GeaChoice alloc] initWithFrame:NSZeroRect];
|
|
979
|
+
choice.nodeId = -1;
|
|
980
|
+
choice.radio = radio;
|
|
981
|
+
choice.buttonType = radio ? NSButtonTypeRadio : NSButtonTypeSwitch;
|
|
982
|
+
choice.title = @"";
|
|
983
|
+
choice.target = choice;
|
|
984
|
+
choice.action = @selector(geaChanged:);
|
|
985
|
+
return choice;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
NSView *makePopUp()
|
|
989
|
+
{
|
|
990
|
+
GeaPopUp *popup = [[GeaPopUp alloc] initWithFrame:NSZeroRect pullsDown:NO];
|
|
991
|
+
popup.nodeId = -1;
|
|
992
|
+
popup.menu.autoenablesItems = NO;
|
|
993
|
+
popup.target = popup;
|
|
994
|
+
popup.action = @selector(geaChanged:);
|
|
995
|
+
return popup;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
NSView *makeStepper()
|
|
999
|
+
{
|
|
1000
|
+
GeaStepper *stepper = [[GeaStepper alloc] initWithFrame:NSZeroRect];
|
|
1001
|
+
stepper.nodeId = -1;
|
|
1002
|
+
stepper.minValue = 0;
|
|
1003
|
+
stepper.maxValue = 100;
|
|
1004
|
+
stepper.increment = 1;
|
|
1005
|
+
stepper.valueWraps = NO;
|
|
1006
|
+
stepper.target = stepper;
|
|
1007
|
+
stepper.action = @selector(geaChanged:);
|
|
1008
|
+
return stepper;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
611
1011
|
NSView *makeButton()
|
|
612
1012
|
{
|
|
613
|
-
NSButton *btn = [[
|
|
1013
|
+
NSButton *btn = [[GeaButton alloc] initWithFrame:NSZeroRect];
|
|
614
1014
|
btn.buttonType = NSButtonTypeMomentaryLight;
|
|
615
1015
|
btn.bezelStyle = NSBezelStyleRounded;
|
|
616
1016
|
[btn setWantsLayer:YES];
|
|
@@ -699,6 +1099,7 @@ NSView *makeSymbolView()
|
|
|
699
1099
|
NSView *makeTextArea()
|
|
700
1100
|
{
|
|
701
1101
|
NSScrollView *sv = [[NSScrollView alloc] initWithFrame:NSZeroRect];
|
|
1102
|
+
sv.automaticallyAdjustsContentInsets = NO;
|
|
702
1103
|
sv.hasVerticalScroller = YES;
|
|
703
1104
|
sv.hasHorizontalScroller = NO;
|
|
704
1105
|
sv.autohidesScrollers = YES;
|
|
@@ -711,6 +1112,7 @@ NSView *makeTextArea()
|
|
|
711
1112
|
const NSSize cs = sv.contentSize;
|
|
712
1113
|
NSTextContainer *tc = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(cs.width, CGFLOAT_MAX)];
|
|
713
1114
|
tc.widthTracksTextView = YES;
|
|
1115
|
+
tc.lineFragmentPadding = 0;
|
|
714
1116
|
NSLayoutManager *lm = [[NSLayoutManager alloc] init];
|
|
715
1117
|
[lm addTextContainer:tc];
|
|
716
1118
|
NSTextStorage *ts = [[NSTextStorage alloc] init];
|
|
@@ -738,14 +1140,24 @@ NSView *makeTextArea()
|
|
|
738
1140
|
// materialized instead of an empty NSView. Calls to applyInputProps later
|
|
739
1141
|
// pick up placeholder / value / font / color from the node.
|
|
740
1142
|
NSView *makeViewForType(gea::embedded::ui::NodeType type, const char *tagName,
|
|
741
|
-
const gea::embedded::ui::ComputedStyle &style, const char *inputType)
|
|
1143
|
+
const gea::embedded::ui::ComputedStyle &style, const char *inputType, bool checkboxButton)
|
|
742
1144
|
{
|
|
743
1145
|
using gea::embedded::ui::NodeType;
|
|
744
1146
|
if (type == NodeType::View && tagName && std::strcmp(tagName, "input") == 0) {
|
|
745
1147
|
if (inputType && std::strcmp(inputType, "range") == 0) return makeSlider();
|
|
1148
|
+
if (inputType && std::strcmp(inputType, "radio") == 0) return makeChoice(true);
|
|
1149
|
+
if (checkboxButton) return makeChoice(false);
|
|
746
1150
|
if (inputType && std::strcmp(inputType, "checkbox") == 0) return makeSwitch();
|
|
747
1151
|
return makeInputField();
|
|
748
1152
|
}
|
|
1153
|
+
if (type == NodeType::View && tagName && std::strcmp(tagName, "select") == 0) return makePopUp();
|
|
1154
|
+
if (type == NodeType::View && tagName && std::strcmp(tagName, "stepper") == 0) return makeStepper();
|
|
1155
|
+
if (type == NodeType::View && tagName && std::strcmp(tagName, "progress") == 0) {
|
|
1156
|
+
NSProgressIndicator *progress = [[NSProgressIndicator alloc] initWithFrame:NSZeroRect];
|
|
1157
|
+
progress.indeterminate = NO;
|
|
1158
|
+
progress.maxValue = 100;
|
|
1159
|
+
return progress;
|
|
1160
|
+
}
|
|
749
1161
|
if (type == NodeType::View && tagName && std::strcmp(tagName, "textarea") == 0) {
|
|
750
1162
|
return makeTextArea();
|
|
751
1163
|
}
|
|
@@ -940,7 +1352,7 @@ char kInsetShadowKey; // CAShapeLayer casting the inset box-shadow
|
|
|
940
1352
|
|
|
941
1353
|
CGColorRef createStyleCGColor(gea::embedded::ui::style_color_t color, uint8_t alpha)
|
|
942
1354
|
{
|
|
943
|
-
CGColor *base = gea::macos::
|
|
1355
|
+
CGColor *base = gea::macos::nativeToCGColor(color);
|
|
944
1356
|
if (alpha == 255) return base;
|
|
945
1357
|
CGColor *faded = CGColorCreateCopyWithAlpha(base, alpha / 255.0);
|
|
946
1358
|
CGColorRelease(base);
|
|
@@ -1201,7 +1613,7 @@ void applyViewStyle(NSView *view, const gea::embedded::ui::Node &node,
|
|
|
1201
1613
|
// alpha in bg_alpha (255 = opaque). Without honoring it, translucent
|
|
1202
1614
|
// backgrounds (weather's rgba(255,255,255,0.12) city chips) painted
|
|
1203
1615
|
// fully opaque.
|
|
1204
|
-
CGColor *bg = gea::macos::
|
|
1616
|
+
CGColor *bg = gea::macos::nativeToCGColor(node.style.bg_color);
|
|
1205
1617
|
if (node.style.bg_alpha != 255) {
|
|
1206
1618
|
CGColor *faded = CGColorCreateCopyWithAlpha(bg, node.style.bg_alpha / 255.0);
|
|
1207
1619
|
CGColorRelease(bg);
|
|
@@ -1215,12 +1627,14 @@ void applyViewStyle(NSView *view, const gea::embedded::ui::Node &node,
|
|
|
1215
1627
|
}
|
|
1216
1628
|
|
|
1217
1629
|
view.alphaValue = static_cast<CGFloat>(node.style.opacity) / 255.0;
|
|
1218
|
-
|
|
1630
|
+
// Visibility preserves the arranged box, but suppresses its native artwork
|
|
1631
|
+
// and hit testing. Gea checkmarks toggle this independently of display.
|
|
1632
|
+
view.hidden = (node.style.display == 1 || node.style.visibility != 0);
|
|
1219
1633
|
|
|
1220
1634
|
// Border (border_alpha carries the CSS alpha, same as bg_alpha above).
|
|
1221
1635
|
if (node.style.border_width > 0) {
|
|
1222
1636
|
view.layer.borderWidth = node.style.border_width;
|
|
1223
|
-
CGColor *bc = gea::macos::
|
|
1637
|
+
CGColor *bc = gea::macos::nativeToCGColor(node.style.border_color);
|
|
1224
1638
|
if (node.style.border_alpha != 255) {
|
|
1225
1639
|
CGColor *faded = CGColorCreateCopyWithAlpha(bc, node.style.border_alpha / 255.0);
|
|
1226
1640
|
CGColorRelease(bc);
|
|
@@ -1306,11 +1720,19 @@ bool attributedStringHasTextDecoration(NSAttributedString *value)
|
|
|
1306
1720
|
[value attribute:NSStrikethroughStyleAttributeName atIndex:0 effectiveRange:nil] != nil;
|
|
1307
1721
|
}
|
|
1308
1722
|
|
|
1309
|
-
void applyTextProps(NSTextField *tf, const gea::embedded::ui::Node &node)
|
|
1723
|
+
void applyTextProps(NSTextField *tf, const gea::embedded::ui::Node &node, int nodeId)
|
|
1310
1724
|
{
|
|
1311
1725
|
NSString *raw = [NSString stringWithUTF8String:(node.text.empty() ? "" : node.text.c_str())];
|
|
1312
|
-
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
1313
|
-
NSColor *color = gea::macos::
|
|
1726
|
+
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1727
|
+
NSColor *color = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1728
|
+
GeaTextCell *cell = (GeaTextCell *)tf.cell;
|
|
1729
|
+
const char *vertical = gea::embedded::ui::Tree::instance().getAttribute(nodeId, "data-text-valign");
|
|
1730
|
+
cell.verticallyCenters = vertical && std::strcmp(vertical, "center") == 0;
|
|
1731
|
+
cell.contentInsets = NSEdgeInsetsMake(
|
|
1732
|
+
node.style.padding[0] + gea::embedded::ui::computedBorderWidth(node.style, 0),
|
|
1733
|
+
node.style.padding[3] + gea::embedded::ui::computedBorderWidth(node.style, 3),
|
|
1734
|
+
node.style.padding[2] + gea::embedded::ui::computedBorderWidth(node.style, 2),
|
|
1735
|
+
node.style.padding[1] + gea::embedded::ui::computedBorderWidth(node.style, 1));
|
|
1314
1736
|
|
|
1315
1737
|
NSTextAlignment alignment;
|
|
1316
1738
|
switch (node.style.text_align) {
|
|
@@ -1319,30 +1741,15 @@ void applyTextProps(NSTextField *tf, const gea::embedded::ui::Node &node)
|
|
|
1319
1741
|
default: alignment = NSTextAlignmentLeft;
|
|
1320
1742
|
}
|
|
1321
1743
|
|
|
1322
|
-
// Use the same attributes the host measurement hook (font_registry.mm's
|
|
1323
|
-
// gea_host_measure_text) uses — same font, same break mode, default
|
|
1324
|
-
// kerning. Identical attributes guarantee the rendered NSTextField has
|
|
1325
|
-
// exactly the width/height the framework's layout engine allocated for
|
|
1326
|
-
// the text node, so titles never end up with a gap below them from
|
|
1327
|
-
// over-allocation and long labels never overflow into clipped territory
|
|
1328
|
-
// from under-allocation.
|
|
1329
|
-
//
|
|
1330
|
-
// Alignment is deliberately NOT one of those attributes. An
|
|
1331
|
-
// NSParagraphStyle whose `alignment` is NSTextAlignmentCenter makes
|
|
1332
|
-
// NSTextFieldCell demand FOUR MORE POINTS of width for the same string
|
|
1333
|
-
// (measured: "Reset"/Inter 15 needs 44pt with a natural or left/right
|
|
1334
|
-
// paragraph and 48pt with a centred one). The measurement hook sets only
|
|
1335
|
-
// `lineBreakMode`, so every centre-aligned label was laid out 4pt narrower
|
|
1336
|
-
// than AppKit would draw it, `wraps = YES` broke the word onto a second
|
|
1337
|
-
// line, and the field's one-line height hid it: "COUNTER" rendered as
|
|
1338
|
-
// "COUNTE", "Reset" as "Rese", "Ready" as "Read". Single-glyph labels
|
|
1339
|
-
// survived only because their boxes had more than 4pt of slack.
|
|
1340
|
-
//
|
|
1341
|
-
// `tf.alignment` below still centres the text and costs nothing, because
|
|
1342
|
-
// the cell -- not the paragraph style -- applies it. Keep alignment there.
|
|
1343
1744
|
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
1344
|
-
const CGFloat
|
|
1745
|
+
const CGFloat contentWidth = node.layout.width - cell.contentInsets.left - cell.contentInsets.right;
|
|
1746
|
+
const CGFloat availableWidth = node.layout.width > 0 ? std::max<CGFloat>(0, contentWidth) : CGFLOAT_MAX;
|
|
1345
1747
|
paragraph.lineBreakMode = gea::macos::lineBreakModeForText(raw, font, availableWidth);
|
|
1748
|
+
paragraph.alignment = alignment;
|
|
1749
|
+
if (node.style.line_height > 0) {
|
|
1750
|
+
paragraph.minimumLineHeight = node.style.line_height;
|
|
1751
|
+
paragraph.maximumLineHeight = node.style.line_height;
|
|
1752
|
+
}
|
|
1346
1753
|
NSMutableDictionary *attrs = textAttributes(font ?: [NSFont systemFontOfSize:node.style.font_size > 0 ? node.style.font_size : 12],
|
|
1347
1754
|
color,
|
|
1348
1755
|
node.style.text_decoration);
|
|
@@ -1360,6 +1767,13 @@ void applyInputProps(GeaInputField *tf, const gea::embedded::ui::Node &node, int
|
|
|
1360
1767
|
{
|
|
1361
1768
|
using gea::embedded::ui::Tree;
|
|
1362
1769
|
tf.nodeId = nodeId;
|
|
1770
|
+
tf.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1771
|
+
tf.editable = tf.enabled && !geaBooleanAttribute(nodeId, "readOnly") && !geaBooleanAttribute(nodeId, "readonly");
|
|
1772
|
+
((GeaInputCell *)tf.cell).contentInsets = NSEdgeInsetsMake(
|
|
1773
|
+
node.style.padding[0] + gea::embedded::ui::computedBorderWidth(node.style, 0),
|
|
1774
|
+
node.style.padding[3] + gea::embedded::ui::computedBorderWidth(node.style, 3),
|
|
1775
|
+
node.style.padding[2] + gea::embedded::ui::computedBorderWidth(node.style, 2),
|
|
1776
|
+
node.style.padding[1] + gea::embedded::ui::computedBorderWidth(node.style, 1));
|
|
1363
1777
|
|
|
1364
1778
|
// The store drives `value` via the framework's reactive-attribute machinery,
|
|
1365
1779
|
// which writes to `node.setAttribute("value", ...)`. Mirror that to the
|
|
@@ -1372,8 +1786,8 @@ void applyInputProps(GeaInputField *tf, const gea::embedded::ui::Node &node, int
|
|
|
1372
1786
|
// whether the field is currently focused — so the editor clears correctly.
|
|
1373
1787
|
auto &tree = Tree::instance();
|
|
1374
1788
|
const char *value = tree.getAttribute(nodeId, "value");
|
|
1375
|
-
tf.textColor = gea::macos::
|
|
1376
|
-
tf.font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
1789
|
+
tf.textColor = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1790
|
+
tf.font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1377
1791
|
switch (node.style.text_align) {
|
|
1378
1792
|
case 1: tf.alignment = NSTextAlignmentCenter; break;
|
|
1379
1793
|
case 2: tf.alignment = NSTextAlignmentRight; break;
|
|
@@ -1405,6 +1819,7 @@ void applySliderProps(GeaSlider *sl, const gea::embedded::ui::Node &node, int no
|
|
|
1405
1819
|
using gea::embedded::ui::Tree;
|
|
1406
1820
|
auto &tree = Tree::instance();
|
|
1407
1821
|
sl.nodeId = nodeId;
|
|
1822
|
+
sl.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1408
1823
|
const char *minA = tree.getAttribute(nodeId, "min");
|
|
1409
1824
|
const char *maxA = tree.getAttribute(nodeId, "max");
|
|
1410
1825
|
if (minA && minA[0]) sl.minValue = atof(minA);
|
|
@@ -1424,6 +1839,7 @@ void applySwitchProps(GeaSwitch *sw, const gea::embedded::ui::Node &node, int no
|
|
|
1424
1839
|
using gea::embedded::ui::Tree;
|
|
1425
1840
|
auto &tree = Tree::instance();
|
|
1426
1841
|
sw.nodeId = nodeId;
|
|
1842
|
+
sw.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1427
1843
|
const char *checked = tree.getAttribute(nodeId, "checked");
|
|
1428
1844
|
const bool hasChecked = tree.hasAttribute(nodeId, "checked");
|
|
1429
1845
|
const bool explicitlyOff = checked && (std::strcmp(checked, "false") == 0 || std::strcmp(checked, "0") == 0);
|
|
@@ -1432,6 +1848,105 @@ void applySwitchProps(GeaSwitch *sw, const gea::embedded::ui::Node &node, int no
|
|
|
1432
1848
|
if (sw.state != want) sw.state = want;
|
|
1433
1849
|
}
|
|
1434
1850
|
|
|
1851
|
+
void applyChoiceProps(GeaChoice *choice, int nodeId)
|
|
1852
|
+
{
|
|
1853
|
+
choice.nodeId = nodeId;
|
|
1854
|
+
choice.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1855
|
+
const NSControlStateValue state = geaBooleanAttribute(nodeId, "checked") ? NSControlStateValueOn : NSControlStateValueOff;
|
|
1856
|
+
if (choice.state != state) choice.state = state;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
NSString *controlText(int nodeId)
|
|
1860
|
+
{
|
|
1861
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1862
|
+
std::string result;
|
|
1863
|
+
std::vector<int> stack{nodeId};
|
|
1864
|
+
while (!stack.empty()) {
|
|
1865
|
+
const int id = stack.back();
|
|
1866
|
+
stack.pop_back();
|
|
1867
|
+
const auto &node = tree.node(id);
|
|
1868
|
+
if (!node.text.empty()) result += node.text.c_str();
|
|
1869
|
+
std::vector<int> children;
|
|
1870
|
+
for (int child = node.first_child; child >= 0; child = tree.node(child).next_sibling) children.push_back(child);
|
|
1871
|
+
for (auto it = children.rbegin(); it != children.rend(); ++it) stack.push_back(*it);
|
|
1872
|
+
}
|
|
1873
|
+
return [NSString stringWithUTF8String:result.c_str()] ?: @"";
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
void applyPopUpProps(GeaPopUp *popup, const gea::embedded::ui::Node &node, int nodeId)
|
|
1877
|
+
{
|
|
1878
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1879
|
+
popup.nodeId = nodeId;
|
|
1880
|
+
popup.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1881
|
+
popup.font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1882
|
+
NSMutableArray<NSString *> *titles = [NSMutableArray array], *values = [NSMutableArray array];
|
|
1883
|
+
std::vector<bool> disabled;
|
|
1884
|
+
NSInteger selected = -1;
|
|
1885
|
+
const char *value = tree.getAttribute(nodeId, "value");
|
|
1886
|
+
NSString *desired = tree.hasAttribute(nodeId, "value") ? [NSString stringWithUTF8String:value] : nil;
|
|
1887
|
+
for (int child = node.first_child; child >= 0; child = tree.node(child).next_sibling) {
|
|
1888
|
+
const char *tag = tree.tagName(child);
|
|
1889
|
+
if (!tag || std::strcmp(tag, "option") != 0) continue;
|
|
1890
|
+
NSString *title = controlText(child);
|
|
1891
|
+
const char *optionValue = tree.getAttribute(child, "value");
|
|
1892
|
+
NSString *itemValue = tree.hasAttribute(child, "value") ? [NSString stringWithUTF8String:optionValue] : title;
|
|
1893
|
+
if ((desired && [desired isEqualToString:itemValue]) || (!desired && geaBooleanAttribute(child, "selected"))) selected = titles.count;
|
|
1894
|
+
[titles addObject:title];
|
|
1895
|
+
[values addObject:itemValue ?: @""];
|
|
1896
|
+
disabled.push_back(gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), child));
|
|
1897
|
+
}
|
|
1898
|
+
BOOL changed = popup.numberOfItems != (NSInteger)titles.count;
|
|
1899
|
+
for (NSUInteger i = 0; !changed && i < titles.count; ++i) {
|
|
1900
|
+
NSMenuItem *item = [popup itemAtIndex:i];
|
|
1901
|
+
changed = ![item.title isEqualToString:titles[i]] || ![item.representedObject isEqual:values[i]];
|
|
1902
|
+
}
|
|
1903
|
+
if (changed) {
|
|
1904
|
+
[popup removeAllItems];
|
|
1905
|
+
for (NSUInteger i = 0; i < titles.count; ++i) {
|
|
1906
|
+
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:titles[i] action:nil keyEquivalent:@""];
|
|
1907
|
+
item.representedObject = values[i];
|
|
1908
|
+
[popup.menu addItem:item];
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
for (NSUInteger i = 0; i < titles.count; ++i) [popup itemAtIndex:i].enabled = !disabled[i];
|
|
1912
|
+
if (selected >= 0 && popup.indexOfSelectedItem != selected) [popup selectItemAtIndex:selected];
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
void applyStepperProps(GeaStepper *stepper, int nodeId)
|
|
1916
|
+
{
|
|
1917
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1918
|
+
stepper.nodeId = nodeId;
|
|
1919
|
+
stepper.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1920
|
+
const char *min = tree.getAttribute(nodeId, "min"), *max = tree.getAttribute(nodeId, "max");
|
|
1921
|
+
const char *step = tree.getAttribute(nodeId, "step"), *value = tree.getAttribute(nodeId, "value");
|
|
1922
|
+
stepper.minValue = min && min[0] ? atof(min) : 0;
|
|
1923
|
+
stepper.maxValue = max && max[0] ? atof(max) : 100;
|
|
1924
|
+
stepper.increment = step && atof(step) > 0 ? atof(step) : 1;
|
|
1925
|
+
if (value && value[0]) stepper.doubleValue = atof(value);
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
void applyProgressProps(NSProgressIndicator *progress, int nodeId)
|
|
1929
|
+
{
|
|
1930
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1931
|
+
const char *style = tree.getAttribute(nodeId, "data-style");
|
|
1932
|
+
const NSProgressIndicatorStyle desiredStyle = style && std::strcmp(style, "spinner") == 0 ? NSProgressIndicatorStyleSpinning : NSProgressIndicatorStyleBar;
|
|
1933
|
+
const bool styleChanged = progress.style != desiredStyle;
|
|
1934
|
+
if (styleChanged) progress.style = desiredStyle;
|
|
1935
|
+
const bool indeterminate = geaBooleanAttribute(nodeId, "indeterminate");
|
|
1936
|
+
const bool modeChanged = progress.indeterminate != indeterminate;
|
|
1937
|
+
if (modeChanged) progress.indeterminate = indeterminate;
|
|
1938
|
+
const char *max = tree.getAttribute(nodeId, "max"), *value = tree.getAttribute(nodeId, "value");
|
|
1939
|
+
progress.maxValue = max && atof(max) > 0 ? atof(max) : 100;
|
|
1940
|
+
if (value && value[0]) progress.doubleValue = atof(value);
|
|
1941
|
+
const bool running = indeterminate && (!tree.hasAttribute(nodeId, "data-running") || geaBooleanAttribute(nodeId, "data-running"));
|
|
1942
|
+
NSNumber *previous = objc_getAssociatedObject(progress, "gea.progress_running");
|
|
1943
|
+
if (!previous || previous.boolValue != running || styleChanged || modeChanged) {
|
|
1944
|
+
if (running) [progress startAnimation:nil];
|
|
1945
|
+
else [progress stopAnimation:nil];
|
|
1946
|
+
objc_setAssociatedObject(progress, "gea.progress_running", @(running), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1435
1950
|
void applySymbolProps(NSImageView *iv, const gea::embedded::ui::Node &node, int nodeId)
|
|
1436
1951
|
{
|
|
1437
1952
|
using gea::embedded::ui::Tree;
|
|
@@ -1455,7 +1970,7 @@ void applySymbolProps(NSImageView *iv, const gea::embedded::ui::Node &node, int
|
|
|
1455
1970
|
// SF Symbols render as template images; tint with the node's CSS color
|
|
1456
1971
|
// (falls back to the system label color so they adapt to dark mode).
|
|
1457
1972
|
if (node.style.text_color != 0) {
|
|
1458
|
-
iv.contentTintColor = gea::macos::
|
|
1973
|
+
iv.contentTintColor = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1459
1974
|
} else {
|
|
1460
1975
|
iv.contentTintColor = [NSColor labelColor];
|
|
1461
1976
|
}
|
|
@@ -1490,10 +2005,17 @@ void applyTextAreaProps(NSScrollView *sv, const gea::embedded::ui::Node &node, i
|
|
|
1490
2005
|
Tree &tree = Tree::instance();
|
|
1491
2006
|
GeaTextAreaView *tv = objc_getAssociatedObject(sv, "gea.text_view");
|
|
1492
2007
|
if (!tv) return;
|
|
2008
|
+
sv.contentInsets = NSEdgeInsetsMake(
|
|
2009
|
+
node.style.padding[0] + gea::embedded::ui::computedBorderWidth(node.style, 0),
|
|
2010
|
+
node.style.padding[3] + gea::embedded::ui::computedBorderWidth(node.style, 3),
|
|
2011
|
+
node.style.padding[2] + gea::embedded::ui::computedBorderWidth(node.style, 2),
|
|
2012
|
+
node.style.padding[1] + gea::embedded::ui::computedBorderWidth(node.style, 1));
|
|
1493
2013
|
tv.nodeId = nodeId;
|
|
2014
|
+
objc_setAssociatedObject(tv,"gea.node_binding",objc_getAssociatedObject(sv,"gea.node_binding"),OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2015
|
+
tv.editable = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId) && !geaBooleanAttribute(nodeId, "readOnly") && !geaBooleanAttribute(nodeId, "readonly");
|
|
1494
2016
|
|
|
1495
|
-
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size > 0 ? node.style.font_size : 14);
|
|
1496
|
-
NSColor *color = gea::macos::
|
|
2017
|
+
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size > 0 ? node.style.font_size : 14, node.style.font_weight, node.style.font_stretch);
|
|
2018
|
+
NSColor *color = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1497
2019
|
tv.font = font ?: [NSFont systemFontOfSize:14];
|
|
1498
2020
|
tv.textColor = color ?: [NSColor labelColor];
|
|
1499
2021
|
tv.insertionPointColor = tv.textColor;
|
|
@@ -1527,6 +2049,7 @@ void applyButtonProps(NSButton *btn, const gea::embedded::ui::Node &node, int no
|
|
|
1527
2049
|
{
|
|
1528
2050
|
using namespace gea::embedded::ui;
|
|
1529
2051
|
Tree &tree = Tree::instance();
|
|
2052
|
+
btn.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1530
2053
|
|
|
1531
2054
|
// Title from the first Text child, if any. JSX <Button>label</Button>
|
|
1532
2055
|
// produces a Button with a text child.
|
|
@@ -1571,8 +2094,8 @@ void applyButtonProps(NSButton *btn, const gea::embedded::ui::Node &node, int no
|
|
|
1571
2094
|
const bool cssStyled = node.style.has_bg;
|
|
1572
2095
|
if (btn.bordered != static_cast<BOOL>(!cssStyled)) btn.bordered = !cssStyled;
|
|
1573
2096
|
if (cssStyled) {
|
|
1574
|
-
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
1575
|
-
NSColor *color = node.style.text_color != 0 ? gea::macos::
|
|
2097
|
+
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
2098
|
+
NSColor *color = node.style.text_color != 0 ? gea::macos::nativeToNSColor(node.style.text_color)
|
|
1576
2099
|
: [NSColor labelColor];
|
|
1577
2100
|
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
1578
2101
|
paragraph.alignment = NSTextAlignmentCenter;
|
|
@@ -1615,21 +2138,30 @@ void ensureViewClickRecognizer(NSView *view, int nodeId, bool wantsClick)
|
|
|
1615
2138
|
// pressId at runtime.
|
|
1616
2139
|
}
|
|
1617
2140
|
|
|
1618
|
-
void applyImageProps(NSImageView *iv, const gea::embedded::ui::Node &node)
|
|
2141
|
+
void applyImageProps(NSImageView *iv, const gea::embedded::ui::Node &node, int nodeId)
|
|
1619
2142
|
{
|
|
1620
2143
|
// Re-decode when image_id changes; otherwise leave the current NSImage in
|
|
1621
2144
|
// place to avoid rebuilding the bitmap every frame. We stash the last
|
|
1622
2145
|
// imageId on the view via associated object.
|
|
1623
2146
|
NSNumber *currentId = objc_getAssociatedObject(iv, "gea.image_id");
|
|
1624
|
-
|
|
1625
|
-
|
|
2147
|
+
NSValue *previousBox = objc_getAssociatedObject(iv, "gea.image_box");
|
|
2148
|
+
NSNumber *previousFit = objc_getAssociatedObject(iv, "gea.image_fit");
|
|
2149
|
+
const NSSize box = NSMakeSize(node.layout.width, node.layout.height);
|
|
2150
|
+
auto &imageTree = gea::embedded::ui::Tree::instance();
|
|
2151
|
+
NSString *cropKey = [NSString stringWithFormat:@"%s/%s/%s/%s", imageTree.getAttribute(nodeId, "data-source-x"), imageTree.getAttribute(nodeId, "data-source-y"), imageTree.getAttribute(nodeId, "data-source-width"), imageTree.getAttribute(nodeId, "data-source-height")];
|
|
2152
|
+
NSString *previousCrop = objc_getAssociatedObject(iv, "gea.image_crop");
|
|
2153
|
+
if (!iv.image || ![previousCrop isEqualToString:cropKey] || !currentId || currentId.intValue != node.image_id || !previousFit || previousFit.intValue != node.style.image_fit || (node.style.image_fit == 2 && (!previousBox || !NSEqualSizes(previousBox.sizeValue, box)))) {
|
|
2154
|
+
iv.image = gea::macos::imageForNode(nodeId);
|
|
2155
|
+
objc_setAssociatedObject(iv, "gea.image_crop", cropKey, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2156
|
+
objc_setAssociatedObject(iv, "gea.image_box", [NSValue valueWithSize:box], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2157
|
+
objc_setAssociatedObject(iv, "gea.image_fit", @(node.style.image_fit), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1626
2158
|
objc_setAssociatedObject(iv, "gea.image_id", @(node.image_id),
|
|
1627
2159
|
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1628
2160
|
}
|
|
1629
2161
|
switch (node.style.image_fit) {
|
|
1630
2162
|
case 0: iv.imageScaling = NSImageScaleAxesIndependently; break;
|
|
1631
2163
|
case 1: iv.imageScaling = NSImageScaleProportionallyUpOrDown; break;
|
|
1632
|
-
case 2: iv.imageScaling =
|
|
2164
|
+
case 2: iv.imageScaling = NSImageScaleAxesIndependently; break; // cropped to the destination aspect above
|
|
1633
2165
|
case 3: iv.imageScaling = NSImageScaleNone; break;
|
|
1634
2166
|
case 4: iv.imageScaling = NSImageScaleProportionallyDown; break;
|
|
1635
2167
|
default: iv.imageScaling = NSImageScaleAxesIndependently;
|
|
@@ -1674,17 +2206,25 @@ void applyTypeSpecificProps(NSView *view, const gea::embedded::ui::Node &node, i
|
|
|
1674
2206
|
{
|
|
1675
2207
|
using gea::embedded::ui::NodeType;
|
|
1676
2208
|
if (node.type == NodeType::Text) {
|
|
1677
|
-
applyTextProps((NSTextField *)view, node);
|
|
2209
|
+
applyTextProps((NSTextField *)view, node, nodeId);
|
|
1678
2210
|
} else if (node.type == NodeType::Button) {
|
|
1679
2211
|
applyButtonProps((NSButton *)view, node, nodeId);
|
|
1680
2212
|
} else if (node.type == NodeType::Image) {
|
|
1681
|
-
applyImageProps((NSImageView *)view, node);
|
|
2213
|
+
applyImageProps((NSImageView *)view, node, nodeId);
|
|
1682
2214
|
} else if (node.type == NodeType::Canvas) {
|
|
1683
2215
|
applyCanvasProps((GeaCanvasView *)view, node, nodeId);
|
|
1684
2216
|
} else if ([view isKindOfClass:[GeaSlider class]]) {
|
|
1685
2217
|
applySliderProps((GeaSlider *)view, node, nodeId);
|
|
1686
2218
|
} else if ([view isKindOfClass:[GeaSwitch class]]) {
|
|
1687
2219
|
applySwitchProps((GeaSwitch *)view, node, nodeId);
|
|
2220
|
+
} else if ([view isKindOfClass:[GeaChoice class]]) {
|
|
2221
|
+
applyChoiceProps((GeaChoice *)view, nodeId);
|
|
2222
|
+
} else if ([view isKindOfClass:[GeaPopUp class]]) {
|
|
2223
|
+
applyPopUpProps((GeaPopUp *)view, node, nodeId);
|
|
2224
|
+
} else if ([view isKindOfClass:[GeaStepper class]]) {
|
|
2225
|
+
applyStepperProps((GeaStepper *)view, nodeId);
|
|
2226
|
+
} else if ([view isKindOfClass:[NSProgressIndicator class]]) {
|
|
2227
|
+
applyProgressProps((NSProgressIndicator *)view, nodeId);
|
|
1688
2228
|
} else if ([view isKindOfClass:[GeaInputField class]]) {
|
|
1689
2229
|
applyInputProps((GeaInputField *)view, node, nodeId);
|
|
1690
2230
|
} else if (objc_getAssociatedObject(view, "gea.is_symbol")) {
|
|
@@ -1702,6 +2242,7 @@ void applyTypeSpecificProps(NSView *view, const gea::embedded::ui::Node &node, i
|
|
|
1702
2242
|
NSScrollView *sv = (NSScrollView *)view;
|
|
1703
2243
|
if ([sv.contentView isKindOfClass:[GeaFlippedClipView class]]) {
|
|
1704
2244
|
((GeaFlippedClipView *)sv.contentView).nodeId = nodeId;
|
|
2245
|
+
objc_setAssociatedObject(sv.contentView,"gea.node_binding",objc_getAssociatedObject(view,"gea.node_binding"),OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1705
2246
|
}
|
|
1706
2247
|
applyScrollContentSize(sv, node);
|
|
1707
2248
|
}
|
|
@@ -1715,7 +2256,7 @@ void applyTypeSpecificProps(NSView *view, const gea::embedded::ui::Node &node, i
|
|
|
1715
2256
|
}
|
|
1716
2257
|
|
|
1717
2258
|
bool viewMatchesNode(NSView *view, const gea::embedded::ui::Node &node,
|
|
1718
|
-
const char *tagName, const char *inputType)
|
|
2259
|
+
const char *tagName, const char *inputType, bool checkboxButton)
|
|
1719
2260
|
{
|
|
1720
2261
|
using gea::embedded::ui::NodeType;
|
|
1721
2262
|
if (!view) return false;
|
|
@@ -1725,9 +2266,14 @@ bool viewMatchesNode(NSView *view, const gea::embedded::ui::Node &node,
|
|
|
1725
2266
|
|
|
1726
2267
|
if (node.type == NodeType::View && tagName && std::strcmp(tagName, "input") == 0) {
|
|
1727
2268
|
if (inputType && std::strcmp(inputType, "range") == 0) return [view isKindOfClass:[GeaSlider class]];
|
|
2269
|
+
const bool radio = inputType && std::strcmp(inputType, "radio") == 0;
|
|
2270
|
+
if (radio || checkboxButton) return [view isKindOfClass:[GeaChoice class]] && ((GeaChoice *)view).radio == radio;
|
|
1728
2271
|
if (inputType && std::strcmp(inputType, "checkbox") == 0) return [view isKindOfClass:[GeaSwitch class]];
|
|
1729
2272
|
return [view isKindOfClass:[GeaInputField class]];
|
|
1730
2273
|
}
|
|
2274
|
+
if (node.type == NodeType::View && tagName && std::strcmp(tagName, "select") == 0) return [view isKindOfClass:[GeaPopUp class]];
|
|
2275
|
+
if (node.type == NodeType::View && tagName && std::strcmp(tagName, "stepper") == 0) return [view isKindOfClass:[GeaStepper class]];
|
|
2276
|
+
if (node.type == NodeType::View && tagName && std::strcmp(tagName, "progress") == 0) return [view isKindOfClass:[NSProgressIndicator class]];
|
|
1731
2277
|
if (node.type == NodeType::View && tagName && std::strcmp(tagName, "textarea") == 0) {
|
|
1732
2278
|
return isTextAreaView;
|
|
1733
2279
|
}
|
|
@@ -1758,6 +2304,8 @@ bool viewMatchesNode(NSView *view, const gea::embedded::ui::Node &node,
|
|
|
1758
2304
|
![view isKindOfClass:[GeaCanvasView class]] &&
|
|
1759
2305
|
![view isKindOfClass:[GeaSlider class]] &&
|
|
1760
2306
|
![view isKindOfClass:[GeaSwitch class]] &&
|
|
2307
|
+
![view isKindOfClass:[GeaStepper class]] &&
|
|
2308
|
+
![view isKindOfClass:[NSProgressIndicator class]] &&
|
|
1761
2309
|
![view isKindOfClass:[GeaInputField class]];
|
|
1762
2310
|
}
|
|
1763
2311
|
}
|
|
@@ -1768,18 +2316,22 @@ NSView *ensureViewForNode(int nodeId, const gea::embedded::ui::Node &node)
|
|
|
1768
2316
|
NSView *view = nodeIdToView()[key];
|
|
1769
2317
|
const char *tagName = gea::embedded::ui::Tree::instance().tagName(nodeId);
|
|
1770
2318
|
const char *inputType = gea::embedded::ui::Tree::instance().getAttribute(nodeId, "type");
|
|
1771
|
-
|
|
2319
|
+
const char *control = gea::embedded::ui::Tree::instance().getAttribute(nodeId, "data-control");
|
|
2320
|
+
const bool checkboxButton = inputType && std::strcmp(inputType, "checkbox") == 0 && control && std::strcmp(control, "checkbox") == 0;
|
|
2321
|
+
if (view && (!geaViewBindingCurrent(view,nodeId) || !viewMatchesNode(view, node, tagName, inputType, checkboxButton))) {
|
|
2322
|
+
geaRetireNativeView(view);
|
|
1772
2323
|
[view removeFromSuperview];
|
|
1773
2324
|
[nodeIdToView() removeObjectForKey:key];
|
|
1774
2325
|
view = nil;
|
|
1775
2326
|
}
|
|
1776
2327
|
if (view) return view;
|
|
1777
|
-
view = makeViewForType(node.type, tagName, node.style, inputType);
|
|
2328
|
+
view = makeViewForType(node.type, tagName, node.style, inputType, checkboxButton);
|
|
1778
2329
|
// Stamp the nodeId on the view so the root-level click handler can map
|
|
1779
2330
|
// hit-tested NSViews back to tree nodes. Used by GeaRootClickBridge to
|
|
1780
2331
|
// dispatch with the deepest matching node's id (event delegation —
|
|
1781
2332
|
// the framework binds listeners on document.body and checks event.target).
|
|
1782
2333
|
objc_setAssociatedObject(view, "gea.node_id", key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2334
|
+
objc_setAssociatedObject(view,"gea.node_binding",[[GeaNativeBinding alloc] initWithNode:nodeId],OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1783
2335
|
nodeIdToView()[key] = view;
|
|
1784
2336
|
return view;
|
|
1785
2337
|
}
|
|
@@ -1851,9 +2403,9 @@ void appendInlineRuns(NSMutableAttributedString *out, int nodeId,
|
|
|
1851
2403
|
// ancestor's class). When the framework has filled them in we use
|
|
1852
2404
|
// them; otherwise we keep the parent's value as the inherited default.
|
|
1853
2405
|
if (node.style.text_color != 0) {
|
|
1854
|
-
col = gea::macos::
|
|
2406
|
+
col = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1855
2407
|
}
|
|
1856
|
-
NSFont *resolved = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
2408
|
+
NSFont *resolved = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1857
2409
|
if (resolved) font = resolved;
|
|
1858
2410
|
NSMutableDictionary *attrs = textAttributes(font, col, node.style.text_decoration);
|
|
1859
2411
|
[out appendAttributedString:[[NSAttributedString alloc] initWithString:str attributes:attrs]];
|
|
@@ -1864,9 +2416,9 @@ void appendInlineRuns(NSMutableAttributedString *out, int nodeId,
|
|
|
1864
2416
|
NSColor *col = parentColor;
|
|
1865
2417
|
NSFont *font = parentFont;
|
|
1866
2418
|
if (node.style.text_color != 0) {
|
|
1867
|
-
col = gea::macos::
|
|
2419
|
+
col = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1868
2420
|
}
|
|
1869
|
-
NSFont *resolved = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
2421
|
+
NSFont *resolved = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1870
2422
|
if (resolved) font = resolved;
|
|
1871
2423
|
for (int c = node.first_child; c >= 0; c = tree.node(c).next_sibling) {
|
|
1872
2424
|
appendInlineRuns(out, c, font, col);
|
|
@@ -1904,8 +2456,8 @@ NSTextField *renderInlineComposition(int nodeId, NSView *parentNSView,
|
|
|
1904
2456
|
objc_setAssociatedObject(parentNSView, "gea.inline_field", field, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1905
2457
|
}
|
|
1906
2458
|
|
|
1907
|
-
NSFont *parentFont = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
1908
|
-
NSColor *parentColor = gea::macos::
|
|
2459
|
+
NSFont *parentFont = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
2460
|
+
NSColor *parentColor = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1909
2461
|
NSMutableAttributedString *composite = [[NSMutableAttributedString alloc] init];
|
|
1910
2462
|
for (int c = node.first_child; c >= 0; c = tree.node(c).next_sibling) {
|
|
1911
2463
|
appendInlineRuns(composite, c, parentFont, parentColor);
|
|
@@ -1914,7 +2466,13 @@ NSTextField *renderInlineComposition(int nodeId, NSView *parentNSView,
|
|
|
1914
2466
|
// uses, so the visual style stays consistent.
|
|
1915
2467
|
NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
|
|
1916
2468
|
ps.lineBreakMode = NSLineBreakByWordWrapping;
|
|
2469
|
+
ps.alignment = node.style.text_align == 1 ? NSTextAlignmentCenter : node.style.text_align == 2 ? NSTextAlignmentRight : NSTextAlignmentLeft;
|
|
1917
2470
|
[composite addAttribute:NSParagraphStyleAttributeName value:ps range:NSMakeRange(0, composite.length)];
|
|
2471
|
+
((GeaTextCell *)field.cell).contentInsets = NSEdgeInsetsMake(
|
|
2472
|
+
node.style.padding[0] + computedBorderWidth(node.style, 0),
|
|
2473
|
+
node.style.padding[3] + computedBorderWidth(node.style, 3),
|
|
2474
|
+
node.style.padding[2] + computedBorderWidth(node.style, 2),
|
|
2475
|
+
node.style.padding[1] + computedBorderWidth(node.style, 1));
|
|
1918
2476
|
|
|
1919
2477
|
field.attributedStringValue = composite;
|
|
1920
2478
|
// Fill the parent's content box. The framework already laid the parent
|
|
@@ -1939,6 +2497,7 @@ void syncRecursive(int nodeId, NSView *parent, int parentAbsX, int parentAbsY, i
|
|
|
1939
2497
|
Tree &tree = Tree::instance();
|
|
1940
2498
|
if (nodeId < 0 || nodeId >= tree.nodeCount()) return;
|
|
1941
2499
|
const Node &node = tree.node(nodeId);
|
|
2500
|
+
if (isStructuralNodeType(node.type)) return;
|
|
1942
2501
|
|
|
1943
2502
|
NSNumber *key = @(nodeId);
|
|
1944
2503
|
[unseen removeObject:key];
|
|
@@ -1955,6 +2514,7 @@ void syncRecursive(int nodeId, NSView *parent, int parentAbsX, int parentAbsY, i
|
|
|
1955
2514
|
// applyButtonProps; materializing the child as an NSTextField on top
|
|
1956
2515
|
// would just be a redundant overlay. Skip descending into Buttons.
|
|
1957
2516
|
if (node.type == NodeType::Button) return;
|
|
2517
|
+
if ([view isKindOfClass:[GeaPopUp class]]) return;
|
|
1958
2518
|
|
|
1959
2519
|
// `<textarea>` owns its NSTextView as its only descendant — JSX children
|
|
1960
2520
|
// (if any were authored) would otherwise be pushed inside NSTextView and
|
|
@@ -2043,6 +2603,8 @@ void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
|
|
|
2043
2603
|
Tree &tree = Tree::instance();
|
|
2044
2604
|
if (rootNodeId < 0 || rootNodeId >= tree.nodeCount()) return;
|
|
2045
2605
|
|
|
2606
|
+
GeaNativeBinding*rootBinding=objc_getAssociatedObject(parentForRoot,"gea.focus_root_binding");
|
|
2607
|
+
if(!rootBinding||!gea::framework::identity::current(rootNodeId,rootBinding->owner)||rootBinding->nodeId!=rootNodeId){geaClearFocusedView(parentForRoot);objc_setAssociatedObject(parentForRoot,"gea.focus_root_binding",[[GeaNativeBinding alloc]initWithNode:rootNodeId],OBJC_ASSOCIATION_RETAIN_NONATOMIC);}
|
|
2046
2608
|
ensureRootClickBridge(parentForRoot, 0, 0);
|
|
2047
2609
|
|
|
2048
2610
|
// Mark every existing entry stale; syncRecursive removes the keys it
|
|
@@ -2060,6 +2622,7 @@ void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
|
|
|
2060
2622
|
|
|
2061
2623
|
for (NSNumber *gone in unseen) {
|
|
2062
2624
|
NSView *v = nodeIdToView()[gone];
|
|
2625
|
+
geaRetireNativeView(v);
|
|
2063
2626
|
[v removeFromSuperview];
|
|
2064
2627
|
[nodeIdToView() removeObjectForKey:gone];
|
|
2065
2628
|
}
|
|
@@ -2093,6 +2656,7 @@ void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
|
|
|
2093
2656
|
|
|
2094
2657
|
for (NSNumber *gone in unseen) {
|
|
2095
2658
|
NSView *v = nodeIdToView()[gone];
|
|
2659
|
+
geaRetireNativeView(v);
|
|
2096
2660
|
[v removeFromSuperview];
|
|
2097
2661
|
[nodeIdToView() removeObjectForKey:gone];
|
|
2098
2662
|
}
|
|
@@ -2101,9 +2665,82 @@ void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
|
|
|
2101
2665
|
void MacosRenderer::teardown()
|
|
2102
2666
|
{
|
|
2103
2667
|
for (NSView *v in [nodeIdToView() allValues]) {
|
|
2668
|
+
geaRetireNativeView(v);
|
|
2104
2669
|
[v removeFromSuperview];
|
|
2105
2670
|
}
|
|
2106
2671
|
[nodeIdToView() removeAllObjects];
|
|
2107
2672
|
}
|
|
2108
2673
|
|
|
2674
|
+
void nativeRootFocusChanged(NSView*view,bool focused,int node){
|
|
2675
|
+
if(!focused){geaNativeFocusEnded(view);return;}
|
|
2676
|
+
GeaNativeBinding*root=objc_getAssociatedObject(view,"gea.focus_root_binding");
|
|
2677
|
+
if(!root||!root->active||!gea::framework::identity::current(root->nodeId,root->owner))return;
|
|
2678
|
+
auto&t=gea::embedded::ui::Tree::instance();
|
|
2679
|
+
auto owner=geaPendingFocus.valid()?geaPendingFocus:gea::embedded::ui::NodeHandle(node);
|
|
2680
|
+
if(!owner.valid()||!owner.isConnected()||!t.containsNode(root->nodeId,owner.id())||gea::embedded::ui::selector::disabled(t,owner.id()))return;
|
|
2681
|
+
geaFocused.view=view;geaFocused.node=owner;t.setActiveInput(owner.id());
|
|
2682
|
+
}
|
|
2683
|
+
static gea::embedded::ui::NativeFocusResult requestFocusNode(gea::embedded::ui::NodeHandle node,bool focus){
|
|
2684
|
+
using namespace gea::embedded::ui;
|
|
2685
|
+
if(![NSThread isMainThread]||!node.valid()||!node.isConnected())return NativeFocusResult::refused;
|
|
2686
|
+
if(!focus){if(!geaFocused.node.valid()||geaFocused.node.identity()!=node.identity())return NativeFocusResult::accepted;NSView*view=geaFocused.view;if(!geaOwnsResponder(view)){geaNativeFocusEnded(view);return NativeFocusResult::accepted;}const BOOL accepted=[view.window makeFirstResponder:nil];if(accepted)geaNativeFocusEnded(view);return accepted?NativeFocusResult::accepted:NativeFocusResult::refused;}
|
|
2687
|
+
NSView*view=nodeIdToView()[@(node.id())];if(!view||!geaViewBindingCurrent(view,node.id())||!geaControlAdmitted(view,node.id()))return NativeFocusResult::refused;
|
|
2688
|
+
NSView*responder=view;
|
|
2689
|
+
if(isScrollView(view)&&objc_getAssociatedObject(view,"gea.text_view"))responder=objc_getAssociatedObject(view,"gea.text_view");
|
|
2690
|
+
if(![responder acceptsFirstResponder]){responder=view.superview;while(responder&&!objc_getAssociatedObject(responder,"gea.focus_root_binding"))responder=responder.superview;}
|
|
2691
|
+
if(!responder||!responder.window||![responder acceptsFirstResponder])return NativeFocusResult::refused;
|
|
2692
|
+
geaPendingFocus=node;const BOOL accepted=[responder.window makeFirstResponder:responder];geaPendingFocus={};
|
|
2693
|
+
if(!accepted||!node.valid()||!geaOwnsResponder(responder)||!geaViewBindingCurrent(view,node.id()))return NativeFocusResult::refused;
|
|
2694
|
+
GeaNativeBinding*root=objc_getAssociatedObject(responder,"gea.focus_root_binding");
|
|
2695
|
+
if(root)nativeRootFocusChanged(responder,true,node.id());else geaNativeFocusBegan(responder,node.id());
|
|
2696
|
+
return geaFocused.node.valid()&&geaFocused.node.identity()==node.identity()?NativeFocusResult::accepted:NativeFocusResult::refused;
|
|
2697
|
+
}
|
|
2109
2698
|
} // namespace gea::macos
|
|
2699
|
+
|
|
2700
|
+
namespace gea::embedded::ui {
|
|
2701
|
+
void retirePlatformInputForSubtrees(const InputRetirementRoots &removed,const InputRetirementRoots &retained) {
|
|
2702
|
+
if(![NSThread isMainThread])throw std::runtime_error("native input retirement requires UI owner thread");
|
|
2703
|
+
struct ViewLease {__strong NSView *view;__strong GeaNativeBinding *binding;__strong PressBridge *press;};
|
|
2704
|
+
struct RootLease {__strong GeaRootClickBridge *bridge;__strong GeaNativeBinding *binding;NodeHandle owner;int x,y;bool emit=false;};
|
|
2705
|
+
std::vector<ViewLease> views;std::vector<RootLease> roots;
|
|
2706
|
+
// Snapshot actual associations and all root recognizers before user code.
|
|
2707
|
+
NSArray<NSView *> *mapped=[gea::macos::nodeIdToView() allValues];
|
|
2708
|
+
for(NSView *view in mapped){
|
|
2709
|
+
GeaNativeBinding *binding=objc_getAssociatedObject(view,"gea.node_binding");
|
|
2710
|
+
if(binding && binding->active && gea::framework::identity::current(binding->nodeId,binding->owner) && inputOwnerLeaving(NodeHandle(binding->nodeId),removed,retained))
|
|
2711
|
+
views.push_back({view,binding,objc_getAssociatedObject(view,"gea.press_bridge")});
|
|
2712
|
+
for(NSView *ancestor=view;ancestor;ancestor=ancestor.superview){
|
|
2713
|
+
GeaRootClickBridge *bridge=objc_getAssociatedObject(ancestor,"gea.root_click_bridge");
|
|
2714
|
+
if(!bridge || !bridge.pressedBinding)continue;
|
|
2715
|
+
GeaNativeBinding *lease=bridge.pressedBinding;
|
|
2716
|
+
if(!lease->active || !gea::framework::identity::current(lease->nodeId,lease->owner) || !inputOwnerLeaving(NodeHandle(lease->nodeId),removed,retained))continue;
|
|
2717
|
+
bool found=false;for(const auto &entry:roots)if(entry.bridge==bridge){found=true;break;}
|
|
2718
|
+
if(!found)roots.push_back({bridge,lease,NodeHandle(lease->nodeId),bridge.lastX,bridge.lastY,false});
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
// Input-only retirement: retained descendant responder leases are untouched.
|
|
2722
|
+
std::vector<__strong GeaRetiredPress *> presses;presses.reserve(views.size());
|
|
2723
|
+
for(const auto &entry:views)entry.binding->active=NO;
|
|
2724
|
+
for(const auto &entry:views)if(entry.press)presses.push_back([entry.press closeInputBinding]);
|
|
2725
|
+
for(auto &entry:roots)entry.emit=[entry.bridge closeInputBinding:entry.binding];
|
|
2726
|
+
std::exception_ptr failure;
|
|
2727
|
+
for(GeaRetiredPress *press:presses)try{[press emitCancellation];}catch(...){if(!failure)failure=std::current_exception();}
|
|
2728
|
+
for(const auto &entry:roots)try{if(entry.emit)geaEmitRootCancellation(entry.owner,entry.x,entry.y);}catch(...){if(!failure)failure=std::current_exception();}
|
|
2729
|
+
if(failure)std::rethrow_exception(failure);
|
|
2730
|
+
// A cancellation handler can render/rebind; never commit across a revived association.
|
|
2731
|
+
for(NSView *view in [gea::macos::nodeIdToView() allValues]){
|
|
2732
|
+
GeaNativeBinding *binding=objc_getAssociatedObject(view,"gea.node_binding");
|
|
2733
|
+
if(binding && binding->active && gea::framework::identity::current(binding->nodeId,binding->owner) && inputOwnerLeaving(NodeHandle(binding->nodeId),removed,retained))
|
|
2734
|
+
throw std::runtime_error("native binding revived during input retirement");
|
|
2735
|
+
for(NSView *ancestor=view;ancestor;ancestor=ancestor.superview){
|
|
2736
|
+
GeaRootClickBridge *bridge=objc_getAssociatedObject(ancestor,"gea.root_click_bridge");
|
|
2737
|
+
GeaNativeBinding *lease=bridge.pressedBinding;
|
|
2738
|
+
if(lease && lease->active && gea::framework::identity::current(lease->nodeId,lease->owner) && inputOwnerLeaving(NodeHandle(lease->nodeId),removed,retained))
|
|
2739
|
+
throw std::runtime_error("native root gesture revived during input retirement");
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
NativeFocusResult requestNativeFocus(NodeHandle node,bool focus){return gea::macos::requestFocusNode(node,focus);}
|
|
2745
|
+
NativeFocusQuery queryNativeFocus(){auto node=geaFocused.node;return {true, node.valid()&&node.isConnected()&&geaOwnsResponder(geaFocused.view)?node:NodeHandle()};}
|
|
2746
|
+
}
|