Implement keyboard event sending for iOS in WebKitTestRunner
[WebKit-https.git] / Tools / WebKitTestRunner / ios / IOKitSPI.h
1 /*
2  * Copyright (C) 2015 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef IOKitSPI_h
27 #define IOKitSPI_h
28
29 #import <wtf/Platform.h>
30
31 #if PLATFORM(IOS)
32
33 #if USE(APPLE_INTERNAL_SDK)
34
35 #import <IOKit/hid/IOHIDEvent.h>
36 #import <IOKit/hid/IOHIDEventSystemClient.h>
37 #import <IOKit/hid/IOHIDUsageTables.h>
38
39 #else
40
41 WTF_EXTERN_C_BEGIN
42
43 #ifdef __LP64__
44 typedef double IOHIDFloat;
45 #else
46 typedef float IOHIDFloat;
47 #endif
48
49 enum {
50     kIOHIDEventOptionNone = 0,
51 };
52
53 typedef UInt32 IOOptionBits;
54 typedef uint32_t IOHIDEventOptionBits;
55 typedef uint32_t IOHIDEventField;
56
57 typedef struct __IOHIDEventSystemClient * IOHIDEventSystemClientRef;
58 typedef struct __IOHIDEvent * IOHIDEventRef;
59
60 #define IOHIDEventFieldBase(type) (type << 16)
61
62 enum {
63     kHIDPage_KeyboardOrKeypad       = 0x07
64     kHIDPage_VendorDefinedStart     = 0xFF00
65 };
66
67 enum {
68     kIOHIDDigitizerEventRange       = 1<<0,
69     kIOHIDDigitizerEventTouch       = 1<<1,
70     kIOHIDDigitizerEventPosition    = 1<<2,
71     kIOHIDDigitizerEventIdentity    = 1<<5,
72     kIOHIDDigitizerEventAttribute   = 1<<6,
73     kIOHIDDigitizerEventCancel      = 1<<7,
74     kIOHIDDigitizerEventStart       = 1<<8,
75 };
76 typedef uint32_t IOHIDDigitizerEventMask;
77
78 enum {
79     kIOHIDEventTypeNULL,
80     kIOHIDEventTypeVendorDefined,
81     kIOHIDEventTypeKeyboard = 3,
82     kIOHIDEventTypeDigitizer = 11,
83 };
84 typedef uint32_t IOHIDEventType;
85
86 enum {
87     kIOHIDEventFieldVendorDefinedUsagePage = IOHIDEventFieldBase(kIOHIDEventTypeVendorDefined),
88     kIOHIDEventFieldVendorDefinedReserved,
89     kIOHIDEventFieldVendorDefinedReserved1,
90     kIOHIDEventFieldVendorDefinedDataLength,
91     kIOHIDEventFieldVendorDefinedData
92 };
93
94 enum {
95     kIOHIDEventFieldDigitizerX = IOHIDEventFieldBase(kIOHIDEventTypeDigitizer),
96     kIOHIDEventFieldDigitizerY,
97     kIOHIDEventFieldDigitizerMajorRadius = kIOHIDEventFieldDigitizerX + 20,
98     kIOHIDEventFieldDigitizerMinorRadius,
99     kIOHIDEventFieldDigitizerIsDisplayIntegrated = kIOHIDEventFieldDigitizerMajorRadius + 5,
100 };
101
102 enum {
103     kIOHIDDigitizerTransducerTypeHand = 3
104 };
105 typedef uint32_t IOHIDDigitizerTransducerType;
106
107 IOHIDEventRef IOHIDEventCreateDigitizerEvent(CFAllocatorRef, uint64_t, IOHIDDigitizerTransducerType, uint32_t, uint32_t, IOHIDDigitizerEventMask, uint32_t, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, boolean_t, boolean_t, IOOptionBits);
108
109 IOHIDEventRef IOHIDEventCreateDigitizerFingerEvent(CFAllocatorRef, uint64_t, uint32_t, uint32_t, IOHIDDigitizerEventMask, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, boolean_t, boolean_t, IOHIDEventOptionBits);
110
111 IOHIDEventRef IOHIDEventCreateForceEvent(CFAllocatorRef, uint64_t, uint32_t, IOHIDFloat, uint32_t, IOHIDFloat, IOHIDEventOptionBits);
112
113 IOHIDEventRef IOHIDEventCreateKeyboardEvent(CFAllocatorRef, uint64_t, uint32_t, uint32_t, boolean_t, IOOptionBits);
114
115 IOHIDEventRef IOHIDEventCreateVendorDefinedEvent(CFAllocatorRef, uint64_t, uint32_t, uint32_t, uint32_t, uint8_t*, CFIndex, IOHIDEventOptionBits);
116
117 IOHIDEventType IOHIDEventGetType(IOHIDEventRef);
118
119 void IOHIDEventSetFloatValue(IOHIDEventRef, IOHIDEventField, IOHIDFloat);
120
121 CFIndex IOHIDEventGetIntegerValue(IOHIDEventRef, IOHIDEventField);
122 void IOHIDEventSetIntegerValue(IOHIDEventRef, IOHIDEventField, CFIndex);
123
124 void IOHIDEventAppendEvent(IOHIDEventRef, IOHIDEventRef, IOOptionBits);
125
126 IOHIDEventSystemClientRef IOHIDEventSystemClientCreate(CFAllocatorRef);
127
128 #define kGSEventPathInfoInRange (1 << 0)
129 #define kGSEventPathInfoInTouch (1 << 1)
130
131 enum {
132     kHIDUsage_KeyboardA = 0x04,
133     kHIDUsage_Keyboard1 = 0x1E,
134     kHIDUsage_Keyboard2 = 0x1F,
135     kHIDUsage_Keyboard3 = 0x20,
136     kHIDUsage_Keyboard4 = 0x21,
137     kHIDUsage_Keyboard5 = 0x22,
138     kHIDUsage_Keyboard6 = 0x23,
139     kHIDUsage_Keyboard7 = 0x24,
140     kHIDUsage_Keyboard8 = 0x25,
141     kHIDUsage_Keyboard9 = 0x26,
142     kHIDUsage_Keyboard0 = 0x27,
143     kHIDUsage_KeyboardReturnOrEnter = 0x28,
144     kHIDUsage_KeyboardEscape = 0x29,
145     kHIDUsage_KeyboardDeleteOrBackspace = 0x2A,
146     kHIDUsage_KeyboardTab = 0x2B,
147     kHIDUsage_KeyboardSpacebar = 0x2C,
148     kHIDUsage_KeyboardHyphen = 0x2D,
149     kHIDUsage_KeyboardEqualSign = 0x2E,
150     kHIDUsage_KeyboardOpenBracket = 0x2F,
151     kHIDUsage_KeyboardCloseBracket = 0x30,
152     kHIDUsage_KeyboardBackslash = 0x31,
153     kHIDUsage_KeyboardSemicolon = 0x33,
154     kHIDUsage_KeyboardQuote = 0x34,
155     kHIDUsage_KeyboardGraveAccentAndTilde = 0x35,
156     kHIDUsage_KeyboardComma = 0x36,
157     kHIDUsage_KeyboardPeriod = 0x37,
158     kHIDUsage_KeyboardSlash = 0x38,
159     kHIDUsage_KeyboardF1 = 0x3A,
160     kHIDUsage_KeyboardHome = 0x4A,
161     kHIDUsage_KeyboardPageUp = 0x4B,
162     kHIDUsage_KeyboardEnd = 0x4D,
163     kHIDUsage_KeyboardRightArrow = 0x4F,
164     kHIDUsage_KeyboardLeftArrow = 0x50,
165     kHIDUsage_KeyboardDownArrow = 0x51,
166     kHIDUsage_KeyboardUpArrow = 0x52,
167     kHIDUsage_KeyboardLeftControl = 0xE0,
168     kHIDUsage_KeyboardLeftShift = 0xE1,
169     kHIDUsage_KeyboardLeftAlt = 0xE2
170 };
171
172 WTF_EXTERN_C_END
173
174 #endif // USE(APPLE_INTERNAL_SDK)
175
176 #endif // PLATFORM(IOS)
177
178 #endif // IOKitSPI_h