| Flutter macOS Embedder |

Instance Methods | Properties | List of all members
KeyboardTester Class Reference
Inheritance diagram for KeyboardTester:

## Instance Methods
(nonnull instancetype) | - init
(void) | - respondEmbedderCallsWith:
(void) | - recordEmbedderCallsTo:
(void) | - recordEmbedderEventsTo:returning:
(void) | - respondChannelCallsWith:
(void) | - recordChannelCallsTo:
(void) | - respondTextInputWith:
(void) | - recordCallTypesTo:forTypes:
(id) | - lastKeyboardChannelResult
(void) | - sendKeyboardChannelMessage:
(void) | - handleEmbedderEvent:callback:userData:
(void) | - handleChannelMessage:message:binaryReply:
(BOOL) | - handleTextInputKeyEvent:

## Properties
FlutterKeyboardManager * | manager
id< FlutterKeyboardManagerEventContext > | eventContextMock
NSResponder * | nextResponder

## Detailed Description

Definition at line 181 of file FlutterKeyboardManagerTest.mm.

## Method Documentation

## ◆ handleChannelMessage:message:binaryReply:

- (void) handleChannelMessage: |  | (NSString*) | channel
message: |  | (NSData* _Nullable) | message
binaryReply: |  | (FlutterBinaryReply _Nullable) | callback

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

382 :(NSString*)channel
383 message:(NSData* _Nullable)message
384 binaryReply:(FlutterBinaryReply _Nullable)callback {
385 if (_typeStorage != nil && (_typeStorageMask & kChannelCall) != 0) {
386 [_typeStorage addObject:@(kChannelCall)];
387 }
388 _channelHandler(^(BOOL handled) {
389 NSDictionary* result = @{
390 @"handled" : @(handled),
391 };
392 NSData* encodedKeyEvent = [[FlutterJSONMessageCodec sharedInstance] encode:result];
393 callback(encodedKeyEvent);
394 });
395 }
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
_typeStorageMask
uint32_t _typeStorageMask
Definition: FlutterKeyboardManagerTest.mm:243
_channelHandler
AsyncKeyCallbackHandler _channelHandler
Definition: FlutterKeyboardManagerTest.mm:237
_typeStorage
NSMutableArray< NSNumber * > * _typeStorage
Definition: FlutterKeyboardManagerTest.mm:242
FlutterJSONMessageCodec
Definition: FlutterCodecs.h:81
+[FlutterMessageCodec-p sharedInstance]
instancetype sharedInstance()

## ◆ handleEmbedderEvent:callback:userData:

- (void) handleEmbedderEvent: |  | (const FlutterKeyEvent&) | event
callback: |  | (nullable FlutterKeyEventCallback) | callback
userData: |  | (nullable void*) | userData

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

369 :(const FlutterKeyEvent&)event
370 callback:(nullable FlutterKeyEventCallback)callback
371 userData:(nullable void*)userData {
372 if (_typeStorage != nil && (_typeStorageMask & kEmbedderCall) != 0) {
373 [_typeStorage addObject:@(kEmbedderCall)];
374 }
375 if (callback != nullptr) {
376 _embedderHandler(&event, ^(BOOL handled) {
377 callback(handled, userData);
378 });
379 }
380 }

## ◆ handleTextInputKeyEvent:

- (BOOL) handleTextInputKeyEvent: |  | (NSEvent*) | event |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

403 :(NSEvent*)event {
404 if (_typeStorage != nil && (_typeStorageMask & kTextCall) != 0) {
405 [_typeStorage addObject:@(kTextCall)];
406 }
407 return _textCallback(event);
408 }
_textCallback
TextInputCallback _textCallback
Definition: FlutterKeyboardManagerTest.mm:240

## ◆ init

- (nonnull instancetype) init |  |  |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

255 {
256 self = [super init];
257 if (self == nil) {
258 return nil;
259 }
260
261 _nextResponder = OCMClassMock([NSResponder class]);
262 [self respondChannelCallsWith:FALSE];
263 [self respondEmbedderCallsWith:FALSE];
264 [self respondTextInputWith:FALSE];
265
266 _currentLayout = &kUsLayout;
267
268 _messengerMock = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger));
269 OCMStub([_messengerMock sendOnChannel:@"flutter/keyevent"
270 message:[OCMArg any]
271 binaryReply:[OCMArg any]])
272 .andCall(self, @selector(handleChannelMessage:message:binaryReply:));
273 OCMStub([_messengerMock setMessageHandlerOnChannel:@"flutter/keyboard"
274 binaryMessageHandler:[OCMArg any]])
275 .andCall(self, @selector(setKeyboardChannelHandler:handler:));
276 OCMStub([_messengerMock sendOnChannel:@"flutter/keyboard" message:[OCMArg any]])
277 .andCall(self, @selector(handleKeyboardChannelMessage:message:));
278 id managerDelegateMock = OCMStrictProtocolMock(@protocol(FlutterKeyboardManagerDelegate));
279 OCMStub([managerDelegateMock binaryMessenger]).andReturn(_messengerMock);
280 OCMStub([managerDelegateMock sendKeyEvent:*(const FlutterKeyEvent*)[OCMArg anyPointer]
281 callback:nil
282 userData:nil])
283 .ignoringNonObjectArgs()
284 .andCall(self, @selector(handleEmbedderEvent:callback:userData:));
285
286 _eventContextMock = OCMStrictProtocolMock(@protocol(FlutterKeyboardManagerEventContext));
287 OCMStub([_eventContextMock nextResponder]).andReturn(_nextResponder);
288 OCMStub([_eventContextMock onTextInputKeyEvent:[OCMArg any]])
289 .andCall(self, @selector(handleTextInputKeyEvent:));
290
291 id keyboardLayoutMock = OCMStrictClassMock([FlutterKeyboardLayout class]);
292 OCMStub([keyboardLayoutMock lookUpLayoutForKeyCode:0 shift:false])
293 .ignoringNonObjectArgs()
294 .andCall(self, @selector(lookUpLayoutForKeyCode:shift:));
295 OCMStub([keyboardLayoutMock setDelegate:[OCMArg any]])
296 .andCall(self, @selector(onSetKeyboardLayoutDelegate:));
297
298 _manager = [[FlutterKeyboardManager alloc] initWithDelegate:managerDelegateMock
299 keyboardLayout:keyboardLayoutMock];
300 return self;
301 }
_eventContextMock
NSObject< FlutterKeyboardManagerEventContext > * _eventContextMock
Definition: FlutterKeyboardManagerTest.mm:252
_currentLayout
const MockLayoutData * _currentLayout
Definition: FlutterKeyboardManagerTest.mm:246
_messengerMock
NSObject< FlutterBinaryMessenger > * _messengerMock
Definition: FlutterKeyboardManagerTest.mm:249
FlutterKeyboardLayout
Definition: FlutterKeyboardLayout.h:51
FlutterKeyboardManager
Definition: FlutterKeyboardManager.h:79
KeyboardTester::nextResponder
NSResponder * nextResponder
Definition: FlutterKeyboardManagerTest.mm:222
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49
FlutterKeyboardManagerDelegate-p
Definition: FlutterKeyboardManager.h:13
FlutterKeyboardManagerEventContext-p
Definition: FlutterKeyboardManager.h:40

## ◆ lastKeyboardChannelResult

- (id) lastKeyboardChannelResult |  |  |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

303 {
304 return _keyboardChannelResult;
305 }
_keyboardChannelResult
id _keyboardChannelResult
Definition: FlutterKeyboardManagerTest.mm:248

## ◆ recordCallTypesTo:forTypes:

- (void) recordCallTypesTo: |  | (nonnull NSMutableArray<NSNumber*>*) | typeStorage
forTypes: |  | (uint32_t) | typeMask

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

352 :(nonnull NSMutableArray<NSNumber*>*)typeStorage
353 forTypes:(uint32_t)typeMask {
354 _typeStorage = typeStorage;
355 _typeStorageMask = typeMask;
356 }

## ◆ recordChannelCallsTo:

- (void) recordChannelCallsTo: |  | (nonnull NSMutableArray<FlutterAsyncKeyCallback>*) | storage |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

340 :(nonnull NSMutableArray<FlutterAsyncKeyCallback>*)storage {
341 _channelHandler = ^(FlutterAsyncKeyCallback callback) {
342 [storage addObject:callback];
343 };
344 }
FlutterAsyncKeyCallback
void(^ FlutterAsyncKeyCallback)(BOOL handled)
Definition: FlutterKeyPrimaryResponder.h:10

## ◆ recordEmbedderCallsTo:

- (void) recordEmbedderCallsTo: |  | (nonnull NSMutableArray<FlutterAsyncKeyCallback>*) | storage |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

313 :(nonnull NSMutableArray<FlutterAsyncKeyCallback>*)storage {
314 _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
315 [storage addObject:callback];
316 };
317 }

## ◆ recordEmbedderEventsTo:returning:

- (void) recordEmbedderEventsTo: |  | (nonnull std::vector<FlutterKeyEvent>*) | storage
returning: |  | (bool) | handled

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

319 :(nonnull std::vector<FlutterKeyEvent>*)storage
320 returning:(bool)handled {
321 _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
322 FlutterKeyEvent newEvent = *event;
323 if (event->character != nullptr) {
324 size_t charLen = strlen(event->character);
325 char* newCharacter = new char[charLen + 1];
326 strlcpy(newCharacter, event->character, charLen + 1);
327 newEvent.character = newCharacter;
328 }
329 storage->push_back(newEvent);
330 callback(handled);
331 };
332 }

## ◆ respondChannelCallsWith:

- (void) respondChannelCallsWith: |  | (BOOL) | response |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

334 :(BOOL)response {
335 _channelHandler = ^(FlutterAsyncKeyCallback callback) {
336 callback(response);
337 };
338 }

## ◆ respondEmbedderCallsWith:

- (void) respondEmbedderCallsWith: |  | (BOOL) | response |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

307 :(BOOL)response {
308 _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
309 callback(response);
310 };
311 }

## ◆ respondTextInputWith:

- (void) respondTextInputWith: |  | (BOOL) | response |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

346 :(BOOL)response {
347 _textCallback = ^(NSEvent* event) {
348 return response;
349 };
350 }

## ◆ sendKeyboardChannelMessage:

- (void) sendKeyboardChannelMessage: |  | (NSData* _Nullable) | message |

Definition at line 252 of file FlutterKeyboardManagerTest.mm.

358 :(NSData* _Nullable)message {
359 [_messengerMock sendOnChannel:@"flutter/keyboard" message:message];
360 }

## Property Documentation

## ◆ eventContextMock

- (id<FlutterKeyboardManagerEventContext>) eventContextMock
| readnonatomicstrong

Definition at line 221 of file FlutterKeyboardManagerTest.mm.

## ◆ manager

- (FlutterKeyboardManager*) manager
| readnonatomicstrong

Definition at line 220 of file FlutterKeyboardManagerTest.mm.

## ◆ nextResponder

- (NSResponder*) nextResponder
| readwritenonatomicstrong

Definition at line 222 of file FlutterKeyboardManagerTest.mm.

The documentation for this class was generated from the following file:

- shell/platform/darwin/macos/framework/Source/FlutterKeyboardManagerTest.mm