@geastack/apple 0.2.15 → 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/package.json +6 -6
- package/targets/ios/generate-xcode-project.mjs +5 -0
- package/targets/macos/app-compiler-plugins.mjs +22 -0
- package/targets/macos/build-macos.sh +40 -2
- package/targets/macos/main/font_registry.h +2 -0
- package/targets/macos/main/font_registry.mm +72 -51
- 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_key_event.h +73 -0
- package/targets/macos/main/macos_main.mm +100 -19
- package/targets/macos/main/macos_renderer.h +2 -0
- package/targets/macos/main/macos_renderer.mm +349 -46
- 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.
|
|
@@ -109,7 +173,7 @@
|
|
|
109
173
|
// `keydown` events with the corresponding `keyCode` value JS apps expect
|
|
110
174
|
// (matching the browser keyCode table for the few keys the framework cares
|
|
111
175
|
// about — Enter, Backspace, arrows, Escape, Tab).
|
|
112
|
-
@interface GeaInputField : NSTextField <NSTextFieldDelegate>
|
|
176
|
+
@interface GeaInputField : NSTextField <NSTextFieldDelegate> { gea::embedded::ui::ControlCommit _geaCommit; BOOL _geaEditing; }
|
|
113
177
|
@property(nonatomic, assign) int nodeId;
|
|
114
178
|
@end
|
|
115
179
|
|
|
@@ -150,7 +214,7 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
150
214
|
using gea::framework::events::PointerEvent;
|
|
151
215
|
if (_nodeId < 0) return;
|
|
152
216
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
153
|
-
if (_nodeId
|
|
217
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
154
218
|
PointerEvent event;
|
|
155
219
|
event.type = type;
|
|
156
220
|
event.targetId = _nodeId;
|
|
@@ -158,18 +222,24 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
158
222
|
tree.dispatchEvent(event);
|
|
159
223
|
}
|
|
160
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(); }
|
|
161
229
|
- (void)controlTextDidChange:(NSNotification *)note
|
|
162
230
|
{
|
|
163
231
|
(void)note;
|
|
164
232
|
if (_nodeId < 0) return;
|
|
165
233
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
166
|
-
if (_nodeId
|
|
234
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
235
|
+
if(!_geaEditing){_geaCommit.begin(_nodeId);_geaEditing=YES;}
|
|
167
236
|
const std::string newValue = std::string([self.stringValue UTF8String] ?: "");
|
|
168
237
|
// Mirror the current text into the node's `value` attribute. The
|
|
169
238
|
// framework's DOM-shim reads `event.currentTarget.value` by falling
|
|
170
239
|
// through to `getAttribute("value")`, so the user's onInput handler sees
|
|
171
240
|
// the latest text without us needing a dedicated event-payload slot.
|
|
172
241
|
tree.setAttribute(_nodeId, "value", newValue.c_str());
|
|
242
|
+
_geaCommit.edited(_nodeId);
|
|
173
243
|
[self dispatchEventOfType:gea::framework::events::PointerEventType::Input withKeyCode:0];
|
|
174
244
|
}
|
|
175
245
|
|
|
@@ -198,7 +268,7 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
198
268
|
// listens for text changes and reflects them to the node's `value` attribute
|
|
199
269
|
// so user code reading `event.currentTarget.value` (or observing the store
|
|
200
270
|
// bound to it) sees the latest text.
|
|
201
|
-
@interface GeaTextAreaView : NSTextView <NSTextViewDelegate>
|
|
271
|
+
@interface GeaTextAreaView : NSTextView <NSTextViewDelegate> { gea::embedded::ui::ControlCommit _geaCommit; BOOL _geaEditing; }
|
|
202
272
|
@property(nonatomic, assign) int nodeId;
|
|
203
273
|
@property(nonatomic, assign) BOOL suppressChangeNotification;
|
|
204
274
|
@end
|
|
@@ -224,6 +294,10 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
224
294
|
return self;
|
|
225
295
|
}
|
|
226
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(); }
|
|
227
301
|
- (void)textDidChange:(NSNotification *)note
|
|
228
302
|
{
|
|
229
303
|
(void)note;
|
|
@@ -231,9 +305,11 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
231
305
|
using gea::framework::events::PointerEvent;
|
|
232
306
|
using gea::framework::events::PointerEventType;
|
|
233
307
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
234
|
-
if (_nodeId
|
|
308
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
309
|
+
if(!_geaEditing){_geaCommit.begin(_nodeId);_geaEditing=YES;}
|
|
235
310
|
const std::string newValue = std::string([self.string UTF8String] ?: "");
|
|
236
311
|
tree.setAttribute(_nodeId, "value", newValue.c_str());
|
|
312
|
+
_geaCommit.edited(_nodeId);
|
|
237
313
|
PointerEvent event;
|
|
238
314
|
event.type = PointerEventType::Input;
|
|
239
315
|
event.targetId = _nodeId;
|
|
@@ -249,17 +325,19 @@ static bool geaBooleanAttribute(int nodeId, const char *name)
|
|
|
249
325
|
return tree.hasAttribute(nodeId, name) && (!value || (std::strcmp(value, "false") != 0 && std::strcmp(value, "0") != 0));
|
|
250
326
|
}
|
|
251
327
|
|
|
252
|
-
static void geaControlInput(int nodeId, const char *value, const char *checked = nullptr)
|
|
328
|
+
static void geaControlInput(NSView *view, int nodeId, const char *value, const char *checked = nullptr)
|
|
253
329
|
{
|
|
254
330
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
255
|
-
if (nodeId
|
|
256
|
-
|
|
331
|
+
if (!geaControlAdmitted(view,nodeId)) return;
|
|
332
|
+
gea::embedded::ui::ControlCommit commit;commit.begin(nodeId,checked?"checked":"value");
|
|
257
333
|
if (value) tree.setAttribute(nodeId, "value", value);
|
|
258
334
|
if (checked) tree.setAttribute(nodeId, "checked", checked);
|
|
335
|
+
commit.edited(nodeId);
|
|
259
336
|
gea::framework::events::PointerEvent event;
|
|
260
337
|
event.type = gea::framework::events::PointerEventType::Input;
|
|
261
338
|
event.targetId = nodeId;
|
|
262
339
|
tree.dispatchEvent(event);
|
|
340
|
+
commit.commit();
|
|
263
341
|
}
|
|
264
342
|
|
|
265
343
|
@interface GeaChoice : NSButton
|
|
@@ -267,11 +345,14 @@ static void geaControlInput(int nodeId, const char *value, const char *checked =
|
|
|
267
345
|
@property(nonatomic, assign) BOOL radio;
|
|
268
346
|
@end
|
|
269
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;}
|
|
270
350
|
- (void)geaChanged:(id)sender
|
|
271
351
|
{
|
|
272
352
|
(void)sender;
|
|
353
|
+
if (!geaControlAdmitted(self,self.nodeId)) return;
|
|
273
354
|
if (self.radio) self.state = NSControlStateValueOn;
|
|
274
|
-
geaControlInput(self.nodeId, nullptr, self.state == NSControlStateValueOn ? "true" : "false");
|
|
355
|
+
geaControlInput(self, self.nodeId, nullptr, self.state == NSControlStateValueOn ? "true" : "false");
|
|
275
356
|
}
|
|
276
357
|
@end
|
|
277
358
|
|
|
@@ -279,11 +360,13 @@ static void geaControlInput(int nodeId, const char *value, const char *checked =
|
|
|
279
360
|
@property(nonatomic, assign) int nodeId;
|
|
280
361
|
@end
|
|
281
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;}
|
|
282
365
|
- (void)geaChanged:(id)sender
|
|
283
366
|
{
|
|
284
367
|
(void)sender;
|
|
285
368
|
NSString *value = self.selectedItem.representedObject ?: self.selectedItem.title;
|
|
286
|
-
geaControlInput(self.nodeId, [value UTF8String] ?: "");
|
|
369
|
+
geaControlInput(self, self.nodeId, [value UTF8String] ?: "");
|
|
287
370
|
}
|
|
288
371
|
@end
|
|
289
372
|
|
|
@@ -291,10 +374,12 @@ static void geaControlInput(int nodeId, const char *value, const char *checked =
|
|
|
291
374
|
@property(nonatomic, assign) int nodeId;
|
|
292
375
|
@end
|
|
293
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;}
|
|
294
379
|
- (void)geaChanged:(id)sender
|
|
295
380
|
{
|
|
296
381
|
(void)sender;
|
|
297
|
-
geaControlInput(self.nodeId, [[NSString stringWithFormat:@"%.15g", self.doubleValue] UTF8String]);
|
|
382
|
+
geaControlInput(self, self.nodeId, [[NSString stringWithFormat:@"%.15g", self.doubleValue] UTF8String]);
|
|
298
383
|
}
|
|
299
384
|
@end
|
|
300
385
|
|
|
@@ -309,6 +394,7 @@ static void geaControlInput(int nodeId, const char *value, const char *checked =
|
|
|
309
394
|
@interface GeaRootClickBridge : NSObject <NSGestureRecognizerDelegate>
|
|
310
395
|
@property(nonatomic, weak) NSView *rootView;
|
|
311
396
|
@property(nonatomic, assign) int pressedNodeId; // -1 when no press in flight
|
|
397
|
+
@property(nonatomic,strong) GeaNativeBinding *pressedBinding;
|
|
312
398
|
// Tree-space origin of rootView: 0,0 for a window root, the pane node's
|
|
313
399
|
// layout.x/y for a split-view pane.
|
|
314
400
|
@property(nonatomic, assign) int originX;
|
|
@@ -319,6 +405,8 @@ static void geaControlInput(int nodeId, const char *value, const char *checked =
|
|
|
319
405
|
@property(nonatomic, assign) int lastY;
|
|
320
406
|
@property(nonatomic, assign) BOOL dragged;
|
|
321
407
|
- (void)fire:(NSGestureRecognizer *)gr;
|
|
408
|
+
@property(nonatomic, assign) BOOL ending;
|
|
409
|
+
- (BOOL)closeInputBinding:(GeaNativeBinding *)binding;
|
|
322
410
|
@end
|
|
323
411
|
|
|
324
412
|
namespace gea::macos {
|
|
@@ -366,13 +454,25 @@ int nodeIdForView(NSView *view)
|
|
|
366
454
|
{
|
|
367
455
|
while (view) {
|
|
368
456
|
NSNumber *n = objc_getAssociatedObject(view, "gea.node_id");
|
|
369
|
-
if (n) return n.intValue;
|
|
457
|
+
if (n) return geaViewBindingCurrent(view,n.intValue)?n.intValue:-1;
|
|
370
458
|
view = view.superview;
|
|
371
459
|
}
|
|
372
460
|
return -1;
|
|
373
461
|
}
|
|
374
462
|
} // namespace gea::macos
|
|
375
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
|
+
|
|
376
476
|
@implementation GeaRootClickBridge
|
|
377
477
|
|
|
378
478
|
- (instancetype)init
|
|
@@ -404,6 +504,15 @@ int nodeIdForView(NSView *view)
|
|
|
404
504
|
if (nodeId < 0) return;
|
|
405
505
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
406
506
|
if (nodeId >= tree.nodeCount()) return;
|
|
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
|
+
}
|
|
407
516
|
gea::macos::publishControlEventBounds(nodeId);
|
|
408
517
|
PointerEvent ev;
|
|
409
518
|
ev.type = type;
|
|
@@ -433,6 +542,7 @@ int nodeIdForView(NSView *view)
|
|
|
433
542
|
ev.targetTouches[0] = point;
|
|
434
543
|
ev.changedTouches[0] = point;
|
|
435
544
|
tree.dispatchEvent(ev);
|
|
545
|
+
if(retireDisabled){self.pressedNodeId=-1;self.pressedBinding=nil;}
|
|
436
546
|
};
|
|
437
547
|
|
|
438
548
|
switch (gr.state) {
|
|
@@ -453,6 +563,7 @@ int nodeIdForView(NSView *view)
|
|
|
453
563
|
// phases dispatch to the same target even if the cursor drifts.
|
|
454
564
|
NSView *hit = gea::macos::hitTestInRoot(root, pInRoot);
|
|
455
565
|
self.pressedNodeId = gea::macos::nodeIdForView(hit);
|
|
566
|
+
self.pressedBinding=[[GeaNativeBinding alloc] initWithNode:self.pressedNodeId];self.ending=NO;
|
|
456
567
|
self.startX = x;
|
|
457
568
|
self.startY = y;
|
|
458
569
|
self.lastX = x;
|
|
@@ -474,9 +585,21 @@ int nodeIdForView(NSView *view)
|
|
|
474
585
|
case NSGestureRecognizerStateCancelled:
|
|
475
586
|
case NSGestureRecognizerStateFailed: {
|
|
476
587
|
const int nodeId = self.pressedNodeId;
|
|
477
|
-
self.
|
|
478
|
-
|
|
479
|
-
|
|
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();
|
|
480
603
|
break;
|
|
481
604
|
}
|
|
482
605
|
default:
|
|
@@ -484,6 +607,13 @@ int nodeIdForView(NSView *view)
|
|
|
484
607
|
}
|
|
485
608
|
}
|
|
486
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
|
+
|
|
487
617
|
// Don't let the root press-recognizer swallow clicks that land on an editable
|
|
488
618
|
// text control (the note title <input> / body <textarea>). If we recognized
|
|
489
619
|
// those, the field never becomes first responder and the user can't focus or
|
|
@@ -576,7 +706,7 @@ struct GeaSyncDepthScope {
|
|
|
576
706
|
{
|
|
577
707
|
if (self.nodeId < 0) return;
|
|
578
708
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
579
|
-
if (self.nodeId >= tree.nodeCount()) return;
|
|
709
|
+
if (self.nodeId >= tree.nodeCount() || !geaViewBindingCurrent(self,self.nodeId)) return;
|
|
580
710
|
const CGFloat y = self.bounds.origin.y;
|
|
581
711
|
const CGFloat maxY = std::max<CGFloat>(0, NSHeight(self.documentView.frame) - NSHeight(self.bounds));
|
|
582
712
|
if (y < -0.5 || y > maxY + 0.5) return;
|
|
@@ -588,12 +718,14 @@ struct GeaSyncDepthScope {
|
|
|
588
718
|
// change it writes its integer value into the node's `value` attribute and
|
|
589
719
|
// dispatches an `input` PointerEvent, so the app's onInput handler reads the new
|
|
590
720
|
// value off event.currentTarget.value (same convention as GeaInputField).
|
|
591
|
-
@interface GeaSlider : NSSlider
|
|
721
|
+
@interface GeaSlider : NSSlider { gea::embedded::ui::ControlCommit _geaCommit; }
|
|
592
722
|
@property(nonatomic, assign) int nodeId;
|
|
593
723
|
@property(nonatomic, assign) BOOL geaDragging;
|
|
594
724
|
@end
|
|
595
725
|
|
|
596
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;}
|
|
597
729
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
598
730
|
{
|
|
599
731
|
if ((self = [super initWithFrame:frameRect])) {
|
|
@@ -606,22 +738,54 @@ struct GeaSyncDepthScope {
|
|
|
606
738
|
{
|
|
607
739
|
// Guard the tracking loop so applySliderProps doesn't fight the user's drag
|
|
608
740
|
// by writing back a (possibly lagging) bound value mid-gesture.
|
|
609
|
-
|
|
741
|
+
if(!geaControlAdmitted(self,_nodeId))return;
|
|
742
|
+
_geaCommit.begin(_nodeId);_geaDragging = YES;
|
|
610
743
|
[super mouseDown:event];
|
|
611
744
|
_geaDragging = NO;
|
|
745
|
+
auto commit=_geaCommit;commit.commit();
|
|
612
746
|
}
|
|
613
747
|
- (void)geaChanged:(id)sender
|
|
614
748
|
{
|
|
615
749
|
(void)sender;
|
|
616
750
|
if (_nodeId < 0) return;
|
|
617
751
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
618
|
-
if (_nodeId
|
|
619
|
-
|
|
620
|
-
|
|
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);
|
|
621
784
|
gea::framework::events::PointerEvent event;
|
|
622
785
|
event.type = gea::framework::events::PointerEventType::Input;
|
|
623
786
|
event.targetId = _nodeId;
|
|
624
787
|
tree.dispatchEvent(event);
|
|
788
|
+
if(!_geaDragging)discreteCommit.commit();
|
|
625
789
|
}
|
|
626
790
|
@end
|
|
627
791
|
|
|
@@ -633,6 +797,8 @@ struct GeaSyncDepthScope {
|
|
|
633
797
|
@end
|
|
634
798
|
|
|
635
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;}
|
|
636
802
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
637
803
|
{
|
|
638
804
|
if ((self = [super initWithFrame:frameRect])) {
|
|
@@ -645,13 +811,68 @@ struct GeaSyncDepthScope {
|
|
|
645
811
|
(void)sender;
|
|
646
812
|
if (_nodeId < 0) return;
|
|
647
813
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
648
|
-
if (_nodeId
|
|
814
|
+
if (!geaControlAdmitted(self,_nodeId)) return;
|
|
649
815
|
const bool on = self.state == NSControlStateValueOn;
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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];
|
|
655
876
|
}
|
|
656
877
|
@end
|
|
657
878
|
|
|
@@ -789,7 +1010,7 @@ NSView *makeStepper()
|
|
|
789
1010
|
|
|
790
1011
|
NSView *makeButton()
|
|
791
1012
|
{
|
|
792
|
-
NSButton *btn = [[
|
|
1013
|
+
NSButton *btn = [[GeaButton alloc] initWithFrame:NSZeroRect];
|
|
793
1014
|
btn.buttonType = NSButtonTypeMomentaryLight;
|
|
794
1015
|
btn.bezelStyle = NSBezelStyleRounded;
|
|
795
1016
|
[btn setWantsLayer:YES];
|
|
@@ -1502,7 +1723,7 @@ bool attributedStringHasTextDecoration(NSAttributedString *value)
|
|
|
1502
1723
|
void applyTextProps(NSTextField *tf, const gea::embedded::ui::Node &node, int nodeId)
|
|
1503
1724
|
{
|
|
1504
1725
|
NSString *raw = [NSString stringWithUTF8String:(node.text.empty() ? "" : node.text.c_str())];
|
|
1505
|
-
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
1726
|
+
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1506
1727
|
NSColor *color = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1507
1728
|
GeaTextCell *cell = (GeaTextCell *)tf.cell;
|
|
1508
1729
|
const char *vertical = gea::embedded::ui::Tree::instance().getAttribute(nodeId, "data-text-valign");
|
|
@@ -1546,7 +1767,7 @@ void applyInputProps(GeaInputField *tf, const gea::embedded::ui::Node &node, int
|
|
|
1546
1767
|
{
|
|
1547
1768
|
using gea::embedded::ui::Tree;
|
|
1548
1769
|
tf.nodeId = nodeId;
|
|
1549
|
-
tf.enabled = !
|
|
1770
|
+
tf.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1550
1771
|
tf.editable = tf.enabled && !geaBooleanAttribute(nodeId, "readOnly") && !geaBooleanAttribute(nodeId, "readonly");
|
|
1551
1772
|
((GeaInputCell *)tf.cell).contentInsets = NSEdgeInsetsMake(
|
|
1552
1773
|
node.style.padding[0] + gea::embedded::ui::computedBorderWidth(node.style, 0),
|
|
@@ -1566,7 +1787,7 @@ void applyInputProps(GeaInputField *tf, const gea::embedded::ui::Node &node, int
|
|
|
1566
1787
|
auto &tree = Tree::instance();
|
|
1567
1788
|
const char *value = tree.getAttribute(nodeId, "value");
|
|
1568
1789
|
tf.textColor = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1569
|
-
tf.font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
1790
|
+
tf.font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1570
1791
|
switch (node.style.text_align) {
|
|
1571
1792
|
case 1: tf.alignment = NSTextAlignmentCenter; break;
|
|
1572
1793
|
case 2: tf.alignment = NSTextAlignmentRight; break;
|
|
@@ -1598,7 +1819,7 @@ void applySliderProps(GeaSlider *sl, const gea::embedded::ui::Node &node, int no
|
|
|
1598
1819
|
using gea::embedded::ui::Tree;
|
|
1599
1820
|
auto &tree = Tree::instance();
|
|
1600
1821
|
sl.nodeId = nodeId;
|
|
1601
|
-
sl.enabled = !
|
|
1822
|
+
sl.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1602
1823
|
const char *minA = tree.getAttribute(nodeId, "min");
|
|
1603
1824
|
const char *maxA = tree.getAttribute(nodeId, "max");
|
|
1604
1825
|
if (minA && minA[0]) sl.minValue = atof(minA);
|
|
@@ -1618,7 +1839,7 @@ void applySwitchProps(GeaSwitch *sw, const gea::embedded::ui::Node &node, int no
|
|
|
1618
1839
|
using gea::embedded::ui::Tree;
|
|
1619
1840
|
auto &tree = Tree::instance();
|
|
1620
1841
|
sw.nodeId = nodeId;
|
|
1621
|
-
sw.enabled = !
|
|
1842
|
+
sw.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1622
1843
|
const char *checked = tree.getAttribute(nodeId, "checked");
|
|
1623
1844
|
const bool hasChecked = tree.hasAttribute(nodeId, "checked");
|
|
1624
1845
|
const bool explicitlyOff = checked && (std::strcmp(checked, "false") == 0 || std::strcmp(checked, "0") == 0);
|
|
@@ -1630,7 +1851,7 @@ void applySwitchProps(GeaSwitch *sw, const gea::embedded::ui::Node &node, int no
|
|
|
1630
1851
|
void applyChoiceProps(GeaChoice *choice, int nodeId)
|
|
1631
1852
|
{
|
|
1632
1853
|
choice.nodeId = nodeId;
|
|
1633
|
-
choice.enabled = !
|
|
1854
|
+
choice.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1634
1855
|
const NSControlStateValue state = geaBooleanAttribute(nodeId, "checked") ? NSControlStateValueOn : NSControlStateValueOff;
|
|
1635
1856
|
if (choice.state != state) choice.state = state;
|
|
1636
1857
|
}
|
|
@@ -1656,8 +1877,8 @@ void applyPopUpProps(GeaPopUp *popup, const gea::embedded::ui::Node &node, int n
|
|
|
1656
1877
|
{
|
|
1657
1878
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1658
1879
|
popup.nodeId = nodeId;
|
|
1659
|
-
popup.enabled = !
|
|
1660
|
-
popup.font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
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);
|
|
1661
1882
|
NSMutableArray<NSString *> *titles = [NSMutableArray array], *values = [NSMutableArray array];
|
|
1662
1883
|
std::vector<bool> disabled;
|
|
1663
1884
|
NSInteger selected = -1;
|
|
@@ -1672,7 +1893,7 @@ void applyPopUpProps(GeaPopUp *popup, const gea::embedded::ui::Node &node, int n
|
|
|
1672
1893
|
if ((desired && [desired isEqualToString:itemValue]) || (!desired && geaBooleanAttribute(child, "selected"))) selected = titles.count;
|
|
1673
1894
|
[titles addObject:title];
|
|
1674
1895
|
[values addObject:itemValue ?: @""];
|
|
1675
|
-
disabled.push_back(
|
|
1896
|
+
disabled.push_back(gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), child));
|
|
1676
1897
|
}
|
|
1677
1898
|
BOOL changed = popup.numberOfItems != (NSInteger)titles.count;
|
|
1678
1899
|
for (NSUInteger i = 0; !changed && i < titles.count; ++i) {
|
|
@@ -1695,7 +1916,7 @@ void applyStepperProps(GeaStepper *stepper, int nodeId)
|
|
|
1695
1916
|
{
|
|
1696
1917
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1697
1918
|
stepper.nodeId = nodeId;
|
|
1698
|
-
stepper.enabled = !
|
|
1919
|
+
stepper.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1699
1920
|
const char *min = tree.getAttribute(nodeId, "min"), *max = tree.getAttribute(nodeId, "max");
|
|
1700
1921
|
const char *step = tree.getAttribute(nodeId, "step"), *value = tree.getAttribute(nodeId, "value");
|
|
1701
1922
|
stepper.minValue = min && min[0] ? atof(min) : 0;
|
|
@@ -1790,9 +2011,10 @@ void applyTextAreaProps(NSScrollView *sv, const gea::embedded::ui::Node &node, i
|
|
|
1790
2011
|
node.style.padding[2] + gea::embedded::ui::computedBorderWidth(node.style, 2),
|
|
1791
2012
|
node.style.padding[1] + gea::embedded::ui::computedBorderWidth(node.style, 1));
|
|
1792
2013
|
tv.nodeId = nodeId;
|
|
1793
|
-
tv
|
|
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");
|
|
1794
2016
|
|
|
1795
|
-
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size > 0 ? node.style.font_size : 14);
|
|
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);
|
|
1796
2018
|
NSColor *color = gea::macos::nativeToNSColor(node.style.text_color);
|
|
1797
2019
|
tv.font = font ?: [NSFont systemFontOfSize:14];
|
|
1798
2020
|
tv.textColor = color ?: [NSColor labelColor];
|
|
@@ -1827,7 +2049,7 @@ void applyButtonProps(NSButton *btn, const gea::embedded::ui::Node &node, int no
|
|
|
1827
2049
|
{
|
|
1828
2050
|
using namespace gea::embedded::ui;
|
|
1829
2051
|
Tree &tree = Tree::instance();
|
|
1830
|
-
btn.enabled = !
|
|
2052
|
+
btn.enabled = !gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), nodeId);
|
|
1831
2053
|
|
|
1832
2054
|
// Title from the first Text child, if any. JSX <Button>label</Button>
|
|
1833
2055
|
// produces a Button with a text child.
|
|
@@ -1872,7 +2094,7 @@ void applyButtonProps(NSButton *btn, const gea::embedded::ui::Node &node, int no
|
|
|
1872
2094
|
const bool cssStyled = node.style.has_bg;
|
|
1873
2095
|
if (btn.bordered != static_cast<BOOL>(!cssStyled)) btn.bordered = !cssStyled;
|
|
1874
2096
|
if (cssStyled) {
|
|
1875
|
-
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
2097
|
+
NSFont *font = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
1876
2098
|
NSColor *color = node.style.text_color != 0 ? gea::macos::nativeToNSColor(node.style.text_color)
|
|
1877
2099
|
: [NSColor labelColor];
|
|
1878
2100
|
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
@@ -2020,6 +2242,7 @@ void applyTypeSpecificProps(NSView *view, const gea::embedded::ui::Node &node, i
|
|
|
2020
2242
|
NSScrollView *sv = (NSScrollView *)view;
|
|
2021
2243
|
if ([sv.contentView isKindOfClass:[GeaFlippedClipView class]]) {
|
|
2022
2244
|
((GeaFlippedClipView *)sv.contentView).nodeId = nodeId;
|
|
2245
|
+
objc_setAssociatedObject(sv.contentView,"gea.node_binding",objc_getAssociatedObject(view,"gea.node_binding"),OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2023
2246
|
}
|
|
2024
2247
|
applyScrollContentSize(sv, node);
|
|
2025
2248
|
}
|
|
@@ -2095,7 +2318,8 @@ NSView *ensureViewForNode(int nodeId, const gea::embedded::ui::Node &node)
|
|
|
2095
2318
|
const char *inputType = gea::embedded::ui::Tree::instance().getAttribute(nodeId, "type");
|
|
2096
2319
|
const char *control = gea::embedded::ui::Tree::instance().getAttribute(nodeId, "data-control");
|
|
2097
2320
|
const bool checkboxButton = inputType && std::strcmp(inputType, "checkbox") == 0 && control && std::strcmp(control, "checkbox") == 0;
|
|
2098
|
-
if (view && !viewMatchesNode(view, node, tagName, inputType, checkboxButton)) {
|
|
2321
|
+
if (view && (!geaViewBindingCurrent(view,nodeId) || !viewMatchesNode(view, node, tagName, inputType, checkboxButton))) {
|
|
2322
|
+
geaRetireNativeView(view);
|
|
2099
2323
|
[view removeFromSuperview];
|
|
2100
2324
|
[nodeIdToView() removeObjectForKey:key];
|
|
2101
2325
|
view = nil;
|
|
@@ -2107,6 +2331,7 @@ NSView *ensureViewForNode(int nodeId, const gea::embedded::ui::Node &node)
|
|
|
2107
2331
|
// dispatch with the deepest matching node's id (event delegation —
|
|
2108
2332
|
// the framework binds listeners on document.body and checks event.target).
|
|
2109
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);
|
|
2110
2335
|
nodeIdToView()[key] = view;
|
|
2111
2336
|
return view;
|
|
2112
2337
|
}
|
|
@@ -2180,7 +2405,7 @@ void appendInlineRuns(NSMutableAttributedString *out, int nodeId,
|
|
|
2180
2405
|
if (node.style.text_color != 0) {
|
|
2181
2406
|
col = gea::macos::nativeToNSColor(node.style.text_color);
|
|
2182
2407
|
}
|
|
2183
|
-
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);
|
|
2184
2409
|
if (resolved) font = resolved;
|
|
2185
2410
|
NSMutableDictionary *attrs = textAttributes(font, col, node.style.text_decoration);
|
|
2186
2411
|
[out appendAttributedString:[[NSAttributedString alloc] initWithString:str attributes:attrs]];
|
|
@@ -2193,7 +2418,7 @@ void appendInlineRuns(NSMutableAttributedString *out, int nodeId,
|
|
|
2193
2418
|
if (node.style.text_color != 0) {
|
|
2194
2419
|
col = gea::macos::nativeToNSColor(node.style.text_color);
|
|
2195
2420
|
}
|
|
2196
|
-
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);
|
|
2197
2422
|
if (resolved) font = resolved;
|
|
2198
2423
|
for (int c = node.first_child; c >= 0; c = tree.node(c).next_sibling) {
|
|
2199
2424
|
appendInlineRuns(out, c, font, col);
|
|
@@ -2231,7 +2456,7 @@ NSTextField *renderInlineComposition(int nodeId, NSView *parentNSView,
|
|
|
2231
2456
|
objc_setAssociatedObject(parentNSView, "gea.inline_field", field, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2232
2457
|
}
|
|
2233
2458
|
|
|
2234
|
-
NSFont *parentFont = gea::macos::fontForId(node.style.font_id, node.style.font_size);
|
|
2459
|
+
NSFont *parentFont = gea::macos::fontForId(node.style.font_id, node.style.font_size, node.style.font_weight, node.style.font_stretch);
|
|
2235
2460
|
NSColor *parentColor = gea::macos::nativeToNSColor(node.style.text_color);
|
|
2236
2461
|
NSMutableAttributedString *composite = [[NSMutableAttributedString alloc] init];
|
|
2237
2462
|
for (int c = node.first_child; c >= 0; c = tree.node(c).next_sibling) {
|
|
@@ -2272,6 +2497,7 @@ void syncRecursive(int nodeId, NSView *parent, int parentAbsX, int parentAbsY, i
|
|
|
2272
2497
|
Tree &tree = Tree::instance();
|
|
2273
2498
|
if (nodeId < 0 || nodeId >= tree.nodeCount()) return;
|
|
2274
2499
|
const Node &node = tree.node(nodeId);
|
|
2500
|
+
if (isStructuralNodeType(node.type)) return;
|
|
2275
2501
|
|
|
2276
2502
|
NSNumber *key = @(nodeId);
|
|
2277
2503
|
[unseen removeObject:key];
|
|
@@ -2377,6 +2603,8 @@ void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
|
|
|
2377
2603
|
Tree &tree = Tree::instance();
|
|
2378
2604
|
if (rootNodeId < 0 || rootNodeId >= tree.nodeCount()) return;
|
|
2379
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);}
|
|
2380
2608
|
ensureRootClickBridge(parentForRoot, 0, 0);
|
|
2381
2609
|
|
|
2382
2610
|
// Mark every existing entry stale; syncRecursive removes the keys it
|
|
@@ -2394,6 +2622,7 @@ void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
|
|
|
2394
2622
|
|
|
2395
2623
|
for (NSNumber *gone in unseen) {
|
|
2396
2624
|
NSView *v = nodeIdToView()[gone];
|
|
2625
|
+
geaRetireNativeView(v);
|
|
2397
2626
|
[v removeFromSuperview];
|
|
2398
2627
|
[nodeIdToView() removeObjectForKey:gone];
|
|
2399
2628
|
}
|
|
@@ -2427,6 +2656,7 @@ void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
|
|
|
2427
2656
|
|
|
2428
2657
|
for (NSNumber *gone in unseen) {
|
|
2429
2658
|
NSView *v = nodeIdToView()[gone];
|
|
2659
|
+
geaRetireNativeView(v);
|
|
2430
2660
|
[v removeFromSuperview];
|
|
2431
2661
|
[nodeIdToView() removeObjectForKey:gone];
|
|
2432
2662
|
}
|
|
@@ -2435,9 +2665,82 @@ void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
|
|
|
2435
2665
|
void MacosRenderer::teardown()
|
|
2436
2666
|
{
|
|
2437
2667
|
for (NSView *v in [nodeIdToView() allValues]) {
|
|
2668
|
+
geaRetireNativeView(v);
|
|
2438
2669
|
[v removeFromSuperview];
|
|
2439
2670
|
}
|
|
2440
2671
|
[nodeIdToView() removeAllObjects];
|
|
2441
2672
|
}
|
|
2442
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
|
+
}
|
|
2443
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
|
+
}
|