Flutter Engine
The Flutter Engine
FlutterFakeKeyEvents.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h"
6
7#include "flutter/fml/logging.h"
8#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
9#import "flutter/shell/platform/darwin/ios/framework/Source/KeyCodeMap_Internal.h"
10
12
13@implementation FakeUIPressProxy
14- (instancetype)initWithData:(UIPressPhase)phase
15 key:(UIKey*)key
16 type:(UIEventType)type
17 timestamp:(NSTimeInterval)timestamp API_AVAILABLE(ios(13.4)) {
18 self = [super init];
19 if (self) {
20 _dataPhase = phase;
21 _dataKey = [key copy];
22 _dataType = type;
23 _dataTimestamp = timestamp;
24 }
25 return self;
26}
27
28- (UIPressPhase)phase API_AVAILABLE(ios(13.4)) {
29 return _dataPhase;
30}
31
32- (UIKey*)key API_AVAILABLE(ios(13.4)) {
33 return _dataKey;
34}
35
36- (UIEventType)type API_AVAILABLE(ios(13.4)) {
37 return _dataType;
38}
39
40- (NSTimeInterval)timestamp API_AVAILABLE(ios(13.4)) {
41 return _dataTimestamp;
42}
43@end
44
45@implementation FakeUIKey
46- (instancetype)initWithData:(UIKeyboardHIDUsage)keyCode
47 modifierFlags:(UIKeyModifierFlags)modifierFlags
48 characters:(NSString*)characters
49 charactersIgnoringModifiers:(NSString*)charactersIgnoringModifiers API_AVAILABLE(ios(13.4)) {
50 self = [super init];
51 if (self) {
52 _dataKeyCode = keyCode;
53 _dataModifierFlags = modifierFlags;
54 _dataCharacters = characters;
55 _dataCharactersIgnoringModifiers = charactersIgnoringModifiers;
56 }
57 return self;
58}
59
60- (id)copyWithZone:(NSZone*)zone {
61 FakeUIKey* another = [super copyWithZone:zone];
62 another.dataKeyCode = _dataKeyCode;
63 another.dataModifierFlags = _dataModifierFlags;
64 another.dataCharacters = [_dataCharacters copyWithZone:zone];
65 another.dataCharactersIgnoringModifiers = [_dataCharactersIgnoringModifiers copyWithZone:zone];
66
67 return another;
68}
69
70- (UIKeyboardHIDUsage)keyCode API_AVAILABLE(ios(13.4)) {
71 return _dataKeyCode;
72}
73
74- (UIKeyModifierFlags)modifierFlags API_AVAILABLE(ios(13.4)) {
75 return _dataModifierFlags;
76}
77
78- (NSString*)characters API_AVAILABLE(ios(13.4)) {
79 return _dataCharacters;
80}
81
83 return _dataCharactersIgnoringModifiers;
84}
85@end
86
87namespace flutter {
88namespace testing {
89
90FlutterUIPressProxy* keyDownEvent(UIKeyboardHIDUsage keyCode,
91 UIKeyModifierFlags modifierFlags,
92 NSTimeInterval timestamp,
93 const char* characters,
94 const char* charactersIgnoringModifiers)
95 API_AVAILABLE(ios(13.4)) {
96 return keyEventWithPhase(UIPressPhaseBegan, keyCode, modifierFlags, timestamp, characters,
97 charactersIgnoringModifiers);
98}
99
100FlutterUIPressProxy* keyUpEvent(UIKeyboardHIDUsage keyCode,
101 UIKeyModifierFlags modifierFlags,
102 NSTimeInterval timestamp,
103 const char* characters,
104 const char* charactersIgnoringModifiers) API_AVAILABLE(ios(13.4)) {
105 return keyEventWithPhase(UIPressPhaseEnded, keyCode, modifierFlags, timestamp, characters,
106 charactersIgnoringModifiers);
107}
108
110 UIKeyboardHIDUsage keyCode,
111 UIKeyModifierFlags modifierFlags,
112 NSTimeInterval timestamp,
113 const char* characters,
114 const char* charactersIgnoringModifiers)
115 API_AVAILABLE(ios(13.4)) {
116 FML_DCHECK(!(modifierFlags & kModifierFlagSidedMask))
117 << "iOS doesn't supply modifier side flags, so don't create events with them.";
118 UIKey* key =
119 [[FakeUIKey alloc] initWithData:keyCode
120 modifierFlags:modifierFlags
121 characters:[NSString stringWithUTF8String:characters]
122 charactersIgnoringModifiers:[NSString stringWithUTF8String:charactersIgnoringModifiers]];
123
124 return [[FakeUIPressProxy alloc] initWithData:phase
125 key:key
126 type:UIEventTypePresses
127 timestamp:timestamp];
128}
129} // namespace testing
130} // namespace flutter
FLUTTER_ASSERT_ARC
GLenum type
#define FML_DCHECK(condition)
Definition: logging.h:103
UIKeyModifierFlags dataModifierFlags
NSString * dataCharacters
UIKeyboardHIDUsage keyCode()
UIKeyModifierFlags modifierFlags()
NSString * dataCharactersIgnoringModifiers
UIKeyboardHIDUsage dataKeyCode
NSString * characters()
NSString * charactersIgnoringModifiers()
constexpr uint32_t kModifierFlagSidedMask
SK_API sk_sp< SkSurface > ios(9.0)
FlutterUIPressProxy * keyEventWithPhase(UIPressPhase phase, UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
FlutterUIPressProxy * keyUpEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
FlutterUIPressProxy * keyDownEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
API_AVAILABLE(ios(14.0), macos(11.0)) static NSString *MTLCommandEncoderErrorStateToString(MTLCommandEncoderErrorState state)
const uintptr_t id