| Flutter iOS Embedder |

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
11 FLUTTER_ASSERT_ARC;
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
82 - (NSString*)charactersIgnoringModifiers API_AVAILABLE(ios(13.4)) {
83 return _dataCharactersIgnoringModifiers;
84 }
85 @end
86
87 namespace flutter {
88 namespace testing {
89
90 FlutterUIPressProxy* 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
100 FlutterUIPressProxy* 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
109 FlutterUIPressProxy* keyEventWithPhase(UIPressPhase phase,
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
FakeUIKey::dataCharactersIgnoringModifiers
NSString * dataCharactersIgnoringModifiers
Definition: FlutterFakeKeyEvents.h:47
-[FakeUIKey keyCode]
UIKeyboardHIDUsage keyCode()
flutter::testing::keyDownEvent
FlutterUIPressProxy * keyDownEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
Definition: FlutterFakeKeyEvents.mm:90
FakeUIKey::dataModifierFlags
UIKeyModifierFlags dataModifierFlags
Definition: FlutterFakeKeyEvents.h:45
API_AVAILABLE
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
flutter::testing::keyEventWithPhase
FlutterUIPressProxy * keyEventWithPhase(UIPressPhase phase, UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
Definition: FlutterFakeKeyEvents.mm:109
FlutterMacros.h
-[FakeUIKey characters]
NSString * characters()
kModifierFlagSidedMask
constexpr uint32_t kModifierFlagSidedMask
Definition: KeyCodeMap_Internal.h:93
-[FakeUIKey charactersIgnoringModifiers]
NSString * charactersIgnoringModifiers()
FlutterFakeKeyEvents.h
flutter
Definition: accessibility_bridge.h:27
FakeUIKey::dataKeyCode
UIKeyboardHIDUsage dataKeyCode
Definition: FlutterFakeKeyEvents.h:44
FakeUIPressProxy
Definition: FlutterFakeKeyEvents.h:15
FlutterUIPressProxy
Definition: FlutterUIPressProxy.h:17
-[FakeUIKey modifierFlags]
UIKeyModifierFlags modifierFlags()
FakeUIKey
Definition: FlutterFakeKeyEvents.h:33
KeyCodeMap_Internal.h
FakeUIKey::dataCharacters
NSString * dataCharacters
Definition: FlutterFakeKeyEvents.h:46
flutter::testing::keyUpEvent
FlutterUIPressProxy * keyUpEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
Definition: FlutterFakeKeyEvents.mm:100
FLUTTER_ASSERT_ARC
FLUTTER_ASSERT_ARC
Definition: FlutterFakeKeyEvents.mm:11