1/*
2 * Copyright (C) 2010 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#include "config.h"
27#include "WebEvent.h"
28
29#include "WebCoreArgumentCoders.h"
30#include <WebCore/KeypressCommand.h>
31
32namespace WebKit {
33
34WebKeyboardEvent::WebKeyboardEvent()
35{
36}
37
38#if USE(APPKIT)
39
40WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, const Vector<WebCore::KeypressCommand>& commands, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, WallTime timestamp)
41 : WebEvent(type, modifiers, timestamp)
42 , m_text(text)
43 , m_unmodifiedText(unmodifiedText)
44#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
45 , m_key(key)
46#endif
47#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
48 , m_code(code)
49#endif
50 , m_keyIdentifier(keyIdentifier)
51 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
52 , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
53 , m_macCharCode(macCharCode)
54 , m_handledByInputMethod(handledByInputMethod)
55 , m_commands(commands)
56 , m_isAutoRepeat(isAutoRepeat)
57 , m_isKeypad(isKeypad)
58 , m_isSystemKey(isSystemKey)
59{
60 ASSERT(isKeyboardEventType(type));
61}
62
63#elif PLATFORM(GTK)
64
65WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, OptionSet<Modifier> modifiers, WallTime timestamp)
66 : WebEvent(type, modifiers, timestamp)
67 , m_text(text)
68 , m_unmodifiedText(text)
69 , m_key(key)
70 , m_code(code)
71 , m_keyIdentifier(keyIdentifier)
72 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
73 , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
74 , m_macCharCode(0)
75 , m_handledByInputMethod(handledByInputMethod)
76 , m_commands(WTFMove(commands))
77 , m_isAutoRepeat(false)
78 , m_isKeypad(isKeypad)
79 , m_isSystemKey(false)
80{
81 ASSERT(isKeyboardEventType(type));
82}
83
84#elif PLATFORM(IOS_FAMILY)
85
86WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, WallTime timestamp)
87 : WebEvent(type, modifiers, timestamp)
88 , m_text(text)
89 , m_unmodifiedText(unmodifiedText)
90#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
91 , m_key(key)
92#endif
93#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
94 , m_code(code)
95#endif
96 , m_keyIdentifier(keyIdentifier)
97 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
98 , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
99 , m_macCharCode(macCharCode)
100#if USE(UIKIT_KEYBOARD_ADDITIONS)
101 , m_handledByInputMethod(handledByInputMethod)
102#endif
103 , m_isAutoRepeat(isAutoRepeat)
104 , m_isKeypad(isKeypad)
105 , m_isSystemKey(isSystemKey)
106{
107 ASSERT(isKeyboardEventType(type));
108}
109
110#elif USE(LIBWPE)
111
112WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool isKeypad, OptionSet<Modifier> modifiers, WallTime timestamp)
113 : WebEvent(type, modifiers, timestamp)
114 , m_text(text)
115 , m_unmodifiedText(text)
116#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
117 , m_key(key)
118#endif
119#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
120 , m_code(code)
121#endif
122 , m_keyIdentifier(keyIdentifier)
123 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
124 , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
125 , m_macCharCode(0)
126 , m_isAutoRepeat(false)
127 , m_isKeypad(isKeypad)
128 , m_isSystemKey(false)
129{
130 ASSERT(isKeyboardEventType(type));
131}
132
133#else
134
135WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, WallTime timestamp)
136 : WebEvent(type, modifiers, timestamp)
137 , m_text(text)
138 , m_unmodifiedText(unmodifiedText)
139 , m_keyIdentifier(keyIdentifier)
140 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
141 , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
142 , m_macCharCode(macCharCode)
143 , m_isAutoRepeat(isAutoRepeat)
144 , m_isKeypad(isKeypad)
145 , m_isSystemKey(isSystemKey)
146{
147 ASSERT(isKeyboardEventType(type));
148}
149
150#endif
151
152WebKeyboardEvent::~WebKeyboardEvent()
153{
154}
155
156void WebKeyboardEvent::encode(IPC::Encoder& encoder) const
157{
158 WebEvent::encode(encoder);
159
160 encoder << m_text;
161 encoder << m_unmodifiedText;
162#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
163 encoder << m_key;
164#endif
165#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
166 encoder << m_code;
167#endif
168 encoder << m_keyIdentifier;
169 encoder << m_windowsVirtualKeyCode;
170 encoder << m_nativeVirtualKeyCode;
171 encoder << m_macCharCode;
172#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
173 encoder << m_handledByInputMethod;
174#endif
175#if USE(APPKIT) || PLATFORM(GTK)
176 encoder << m_commands;
177#endif
178 encoder << m_isAutoRepeat;
179 encoder << m_isKeypad;
180 encoder << m_isSystemKey;
181}
182
183bool WebKeyboardEvent::decode(IPC::Decoder& decoder, WebKeyboardEvent& result)
184{
185 if (!WebEvent::decode(decoder, result))
186 return false;
187
188 if (!decoder.decode(result.m_text))
189 return false;
190 if (!decoder.decode(result.m_unmodifiedText))
191 return false;
192#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
193 if (!decoder.decode(result.m_key))
194 return false;
195#endif
196#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
197 if (!decoder.decode(result.m_code))
198 return false;
199#endif
200 if (!decoder.decode(result.m_keyIdentifier))
201 return false;
202 if (!decoder.decode(result.m_windowsVirtualKeyCode))
203 return false;
204 if (!decoder.decode(result.m_nativeVirtualKeyCode))
205 return false;
206 if (!decoder.decode(result.m_macCharCode))
207 return false;
208#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
209 if (!decoder.decode(result.m_handledByInputMethod))
210 return false;
211#endif
212#if USE(APPKIT) || PLATFORM(GTK)
213 if (!decoder.decode(result.m_commands))
214 return false;
215#endif
216 if (!decoder.decode(result.m_isAutoRepeat))
217 return false;
218 if (!decoder.decode(result.m_isKeypad))
219 return false;
220 if (!decoder.decode(result.m_isSystemKey))
221 return false;
222
223 return true;
224}
225
226bool WebKeyboardEvent::isKeyboardEventType(Type type)
227{
228 return type == RawKeyDown || type == KeyDown || type == KeyUp || type == Char;
229}
230
231} // namespace WebKit
232