| 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 #import "flutter/shell/platform/darwin/ios/ios_test_flutter_swift/ios_test_flutter_swift.h"
11
12 FLUTTER_ASSERT_ARC;
13
14 @implementation FakeUIKey
15 - (instancetype)initWithData:(UIKeyboardHIDUsage)keyCode
16 modifierFlags:(UIKeyModifierFlags)modifierFlags
17 characters:(NSString*)characters
18 charactersIgnoringModifiers:(NSString*)charactersIgnoringModifiers API_AVAILABLE(ios(13.4)) {
19 self = [super init];
20 if (self) {
21 _dataKeyCode = keyCode;
22 _dataModifierFlags = modifierFlags;
23 _dataCharacters = characters;
24 _dataCharactersIgnoringModifiers = charactersIgnoringModifiers;
25 }
26 return self;
27 }
28
29 - (id)copyWithZone:(NSZone*)zone {
30 FakeUIKey* another = [super copyWithZone:zone];
31 another.dataKeyCode = _dataKeyCode;
32 another.dataModifierFlags = _dataModifierFlags;
33 another.dataCharacters = [_dataCharacters copyWithZone:zone];
34 another.dataCharactersIgnoringModifiers = [_dataCharactersIgnoringModifiers copyWithZone:zone];
35
36 return another;
37 }
38
39 - (UIKeyboardHIDUsage)keyCode API_AVAILABLE(ios(13.4)) {
40 return _dataKeyCode;
41 }
42
43 - (UIKeyModifierFlags)modifierFlags API_AVAILABLE(ios(13.4)) {
44 return _dataModifierFlags;
45 }
46
47 - (NSString*)characters API_AVAILABLE(ios(13.4)) {
48 return _dataCharacters;
49 }
50
51 - (NSString*)charactersIgnoringModifiers API_AVAILABLE(ios(13.4)) {
52 return _dataCharactersIgnoringModifiers;
53 }
54 @end
55
56 namespace flutter {
57 namespace testing {
58
59 FlutterUIPressProxy* keyDownEvent(UIKeyboardHIDUsage keyCode,
60 UIKeyModifierFlags modifierFlags,
61 NSTimeInterval timestamp,
62 const char* characters,
63 const char* charactersIgnoringModifiers)
64 API_AVAILABLE(ios(13.4)) {
65 return keyEventWithPhase(UIPressPhaseBegan, keyCode, modifierFlags, timestamp, characters,
66 charactersIgnoringModifiers);
67 }
68
69 FlutterUIPressProxy* keyUpEvent(UIKeyboardHIDUsage keyCode,
70 UIKeyModifierFlags modifierFlags,
71 NSTimeInterval timestamp,
72 const char* characters,
73 const char* charactersIgnoringModifiers) API_AVAILABLE(ios(13.4)) {
74 return keyEventWithPhase(UIPressPhaseEnded, keyCode, modifierFlags, timestamp, characters,
75 charactersIgnoringModifiers);
76 }
77
78 FlutterUIPressProxy* keyEventWithPhase(UIPressPhase phase,
79 UIKeyboardHIDUsage keyCode,
80 UIKeyModifierFlags modifierFlags,
81 NSTimeInterval timestamp,
82 const char* characters,
83 const char* charactersIgnoringModifiers)
84 API_AVAILABLE(ios(13.4)) {
85 FML_DCHECK(!(modifierFlags & kModifierFlagSidedMask))
86 << "iOS doesn't supply modifier side flags, so don't create events with them.";
87 UIKey* key =
88 [[FakeUIKey alloc] initWithData:keyCode
89 modifierFlags:modifierFlags
90 characters:[NSString stringWithUTF8String:characters]
91 charactersIgnoringModifiers:[NSString stringWithUTF8String:charactersIgnoringModifiers]];
92
93 return [[FakeUIPressProxy alloc] initWithPhase:phase
94 key:key
95 type:UIEventTypePresses
96 timestamp:timestamp];
97 }
98 } // namespace testing
99 } // namespace flutter
FlutterFakeKeyEvents.h
FLUTTER_ASSERT_ARC
FLUTTER_ASSERT_ARC
Definition: FlutterFakeKeyEvents.mm:12
FlutterMacros.h
API_AVAILABLE
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
KeyCodeMap_Internal.h
kModifierFlagSidedMask
constexpr uint32_t kModifierFlagSidedMask
Definition: KeyCodeMap_Internal.h:93
FakeUIKey
Definition: FlutterFakeKeyEvents.h:16
FakeUIKey::dataModifierFlags
UIKeyModifierFlags dataModifierFlags
Definition: FlutterFakeKeyEvents.h:27
FakeUIKey::dataCharacters
NSString * dataCharacters
Definition: FlutterFakeKeyEvents.h:28
-[FakeUIKey keyCode]
UIKeyboardHIDUsage keyCode()
-[FakeUIKey modifierFlags]
UIKeyModifierFlags modifierFlags()
FakeUIKey::dataCharactersIgnoringModifiers
NSString * dataCharactersIgnoringModifiers
Definition: FlutterFakeKeyEvents.h:29
-[FakeUIKey charactersIgnoringModifiers]
NSString * charactersIgnoringModifiers()
-[FakeUIKey characters]
NSString * characters()
FakeUIKey::dataKeyCode
UIKeyboardHIDUsage dataKeyCode
Definition: FlutterFakeKeyEvents.h:26
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:78
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:69
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:59
flutter
Definition: accessibility_bridge.h:26