11
11
12
12
#import " KeyCodeMap_Internal.h"
13
13
#import " flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
14
+ #import " flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
15
+
16
+ FLUTTER_ASSERT_ARC
14
17
15
18
namespace {
16
19
@@ -165,7 +168,7 @@ static uint64_t GetLogicalKeyForEvent(FlutterUIPressProxy* press, NSNumber* mayb
165
168
const char * characters =
166
169
getEventCharacters (press.key .charactersIgnoringModifiers , press.key .keyCode );
167
170
NSString * keyLabel =
168
- characters == nullptr ? nil : [[[ NSString alloc ] initWithUTF8String: characters] autorelease ];
171
+ characters == nullptr ? nil : [[NSString alloc ] initWithUTF8String: characters];
169
172
NSUInteger keyLabelLength = [keyLabel length ];
170
173
// If this key is printable, generate the logical key from its Unicode
171
174
// value. Control keys such as ESC, CTRL, and SHIFT are not printable. HOME,
@@ -252,7 +255,7 @@ static bool isKeyDown(FlutterUIPressProxy* press) API_AVAILABLE(ios(13.4)) {
252
255
*/
253
256
@interface FlutterKeyPendingResponse : NSObject
254
257
255
- @property (readonly ) FlutterEmbedderKeyResponder* responder;
258
+ @property (readonly , weak ) FlutterEmbedderKeyResponder* responder;
256
259
257
260
@property (nonatomic ) uint64_t responseId;
258
261
@@ -302,7 +305,7 @@ - (void)resolveTo:(BOOL)handled;
302
305
* Only set in debug mode. Nil in release mode, or if the callback has not been
303
306
* handled.
304
307
*/
305
- @property (readonly ) NSString * debugHandleSource;
308
+ @property (readonly , copy ) NSString * debugHandleSource;
306
309
@end
307
310
308
311
@implementation FlutterKeyCallbackGuard {
@@ -313,17 +316,12 @@ @implementation FlutterKeyCallbackGuard {
313
316
- (nonnull instancetype )initWithCallback : (FlutterAsyncKeyCallback)callback {
314
317
self = [super init ];
315
318
if (self != nil ) {
316
- _callback = [ callback copy ] ;
319
+ _callback = callback;
317
320
_handled = FALSE ;
318
321
}
319
322
return self;
320
323
}
321
324
322
- - (void )dealloc {
323
- [_callback release ];
324
- [super dealloc ];
325
- }
326
-
327
325
- (void )pendTo : (nonnull NSMutableDictionary <NSNumber*, FlutterAsyncKeyCallback>*)pendingResponses
328
326
withId : (uint64_t )responseId {
329
327
NSAssert (!_handled, @" This callback has been handled by %@ ." , _debugHandleSource);
@@ -356,15 +354,15 @@ @interface FlutterEmbedderKeyResponder ()
356
354
*
357
355
* Set by the initializer.
358
356
*/
359
- @property (nonatomic , copy , readonly ) FlutterSendKeyEvent sendEvent;
357
+ @property (nonatomic , readonly ) FlutterSendKeyEvent sendEvent;
360
358
361
359
/* *
362
360
* A map of pressed keys.
363
361
*
364
362
* The keys of the dictionary are physical keys, while the values are the logical keys
365
363
* of the key down event.
366
364
*/
367
- @property (nonatomic , retain , readonly ) NSMutableDictionary <NSNumber*, NSNumber*>* pressingRecords;
365
+ @property (nonatomic , readonly ) NSMutableDictionary <NSNumber*, NSNumber*>* pressingRecords;
368
366
369
367
/* *
370
368
* A constant mask for NSEvent.modifierFlags that Flutter synchronizes with.
@@ -403,7 +401,7 @@ @interface FlutterEmbedderKeyResponder ()
403
401
* Its values are |responseId|s, and keys are the callback that was received
404
402
* along with the event.
405
403
*/
406
- @property (nonatomic , retain , readonly )
404
+ @property (nonatomic , readonly )
407
405
NSMutableDictionary <NSNumber*, FlutterAsyncKeyCallback>* pendingResponses;
408
406
409
407
/* *
@@ -492,7 +490,7 @@ @implementation FlutterEmbedderKeyResponder
492
490
- (nonnull instancetype )initWithSendEvent : (FlutterSendKeyEvent)sendEvent {
493
491
self = [super init ];
494
492
if (self != nil ) {
495
- _sendEvent = [ sendEvent copy ] ;
493
+ _sendEvent = sendEvent;
496
494
_pressingRecords = [[NSMutableDictionary alloc ] init ];
497
495
_pendingResponses = [[NSMutableDictionary alloc ] init ];
498
496
_responseId = 1 ;
@@ -502,13 +500,6 @@ - (nonnull instancetype)initWithSendEvent:(FlutterSendKeyEvent)sendEvent {
502
500
return self;
503
501
}
504
502
505
- - (void )dealloc {
506
- [_sendEvent release ];
507
- [_pressingRecords release ];
508
- [_pendingResponses release ];
509
- [super dealloc ];
510
- }
511
-
512
503
- (void )handlePress : (nonnull FlutterUIPressProxy*)press
513
504
callback : (FlutterAsyncKeyCallback)callback API_AVAILABLE(ios(13.4 )) {
514
505
if (@available (iOS 13.4 , *)) {
@@ -522,11 +513,11 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
522
513
FlutterKeyCallbackGuard* guardedCallback = nil ;
523
514
switch (press.phase ) {
524
515
case UIPressPhaseBegan:
525
- guardedCallback = [[[ FlutterKeyCallbackGuard alloc ] initWithCallback: callback] autorelease ];
516
+ guardedCallback = [[FlutterKeyCallbackGuard alloc ] initWithCallback: callback];
526
517
[self handlePressBegin: press callback: guardedCallback];
527
518
break ;
528
519
case UIPressPhaseEnded:
529
- guardedCallback = [[[ FlutterKeyCallbackGuard alloc ] initWithCallback: callback] autorelease ];
520
+ guardedCallback = [[FlutterKeyCallbackGuard alloc ] initWithCallback: callback];
530
521
[self handlePressEnd: press callback: guardedCallback];
531
522
break ;
532
523
case UIPressPhaseChanged:
@@ -632,9 +623,9 @@ - (void)sendPrimaryFlutterEvent:(const FlutterKeyEvent&)event
632
623
_responseId += 1 ;
633
624
uint64_t responseId = _responseId;
634
625
FlutterKeyPendingResponse* pending =
635
- [[[ FlutterKeyPendingResponse alloc ] initWithHandler: self responseId: responseId] autorelease ];
626
+ [[FlutterKeyPendingResponse alloc ] initWithHandler: self responseId: responseId];
636
627
[callback pendTo: _pendingResponses withId: responseId];
637
- _sendEvent (event, HandleResponse, pending);
628
+ _sendEvent (event, HandleResponse, ( void * _Nullable) CFBridgingRetain ( pending) );
638
629
}
639
630
640
631
- (void )sendEmptyEvent {
@@ -883,7 +874,7 @@ - (UInt32)adjustModifiers:(nonnull FlutterUIPressProxy*)press API_AVAILABLE(ios(
883
874
884
875
namespace {
885
876
void HandleResponse (bool handled, void * user_data) {
886
- FlutterKeyPendingResponse* pending = reinterpret_cast < FlutterKeyPendingResponse*> (user_data);
877
+ FlutterKeyPendingResponse* pending = ( FlutterKeyPendingResponse*) CFBridgingRelease (user_data);
887
878
[pending.responder handleResponse: handled forId: pending.responseId];
888
879
}
889
880
} // namespace
0 commit comments