2 * Copyright 2007, The Android Open Source Project
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
5 * Copyright (C) 2007 Holger Hans Peter Freyther
6 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "PlatformKeyboardEvent.h"
34 #include "KeyboardCodes.h"
35 #include "NotImplemented.h"
36 #include <ui/KeycodeLabels.h>
40 // compare to same function in gdk/KeyEventGdk.cpp
41 static int windowsKeyCodeForKeyEvent(unsigned int keyCode
)
43 // Does not provide all key codes, and does not handle all keys.
51 case kKeyCodeDpadCenter
:
54 case kKeyCodeShiftLeft
:
55 case kKeyCodeShiftRight
:
57 // back will serve as escape, although we probably do not have access to it
64 case kKeyCodeDpadLeft
:
68 case kKeyCodeDpadRight
:
70 case kKeyCodeDpadDown
:
145 case kKeyCodeSemicolon
:
154 return VK_OEM_PERIOD
;
157 // maybe not the right choice
158 case kKeyCodeLeftBracket
:
160 case kKeyCodeBackslash
:
162 case kKeyCodeRightBracket
:
169 static String
keyIdentifierForAndroidKeyCode(int keyCode
)
171 // Does not return all of the same key identifiers, and
172 // does not handle all the keys.
176 case kKeyCodeNewline
:
177 case kKeyCodeDpadCenter
:
181 case kKeyCodeDpadDown
:
183 case kKeyCodeDpadLeft
:
185 case kKeyCodeDpadRight
:
189 // Standard says that DEL becomes U+00007F.
194 sprintf(upper
, "U+%06X", windowsKeyCodeForKeyEvent(keyCode
));
195 return String(upper
);
199 static inline String
singleCharacterString(UChar32 c
)
204 UChar lead
= U16_LEAD(c
);
205 UChar trail
= U16_TRAIL(c
);
206 UChar utf16
[2] = {lead
, trail
};
207 return String(utf16
, 2);
210 return String(&n
, 1);
213 PlatformKeyboardEvent::PlatformKeyboardEvent(int keyCode
, UChar32 unichar
,
214 int repeatCount
, bool down
, bool cap
, bool alt
, bool sym
)
215 : m_type(down
? KeyDown
: KeyUp
)
216 , m_text(singleCharacterString(unichar
))
217 , m_unmodifiedText(singleCharacterString(unichar
))
218 , m_keyIdentifier(keyIdentifierForAndroidKeyCode(keyCode
))
219 , m_autoRepeat(repeatCount
> 0)
220 , m_windowsVirtualKeyCode(windowsKeyCodeForKeyEvent(keyCode
))
221 , m_nativeVirtualKeyCode(keyCode
)
223 , m_shiftKey(cap
? ShiftKey
: 0)
224 , m_ctrlKey(sym
? CtrlKey
: 0)
225 , m_altKey(alt
? AltKey
: 0)
228 , m_repeatCount(repeatCount
)
231 // Copied from the mac port
232 if (m_windowsVirtualKeyCode
== '\r') {
234 m_unmodifiedText
= "\r";
237 if (m_text
== "\x7F")
239 if (m_unmodifiedText
== "\x7F")
240 m_unmodifiedText
= "\x8";
242 if (m_windowsVirtualKeyCode
== 9) {
244 m_unmodifiedText
= "\x9";
248 bool PlatformKeyboardEvent::currentCapsLockState()
254 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type
, bool backwardCompatibilityMode
)
256 // Copied with modification from the mac port.
257 ASSERT(m_type
== KeyDown
);
258 ASSERT(type
== RawKeyDown
|| type
== Char
);
260 if (backwardCompatibilityMode
)
263 if (type
== RawKeyDown
) {
265 m_unmodifiedText
= String();
267 m_keyIdentifier
= String();
268 m_windowsVirtualKeyCode
= 0;
272 } // namespace WebCore