darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 2 | * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved. |
alp@webkit.org | 01dce40 | 2008-02-08 10:41:58 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008 Collabora, Ltd. All rights reserved. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
andersca@apple.com | a59dc4c | 2016-09-27 19:08:34 +0000 | [diff] [blame] | 27 | #pragma once |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 28 | |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 29 | #include "KeypressCommand.h" |
weinig@apple.com | 4824ed5 | 2011-12-16 22:46:17 +0000 | [diff] [blame] | 30 | #include "PlatformEvent.h" |
paroga@webkit.org | 51f3bcd | 2013-07-30 18:54:18 +0000 | [diff] [blame] | 31 | #include <wtf/WindowsExtras.h> |
weinig@apple.com | 4824ed5 | 2011-12-16 22:46:17 +0000 | [diff] [blame] | 32 | #include <wtf/text/WTFString.h> |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 33 | |
mitz@apple.com | 1a8d7d3 | 2014-02-07 23:37:54 +0000 | [diff] [blame] | 34 | #if PLATFORM(COCOA) |
beidson | 4ce6494 | 2007-03-24 23:21:50 +0000 | [diff] [blame] | 35 | #include <wtf/RetainPtr.h> |
weinig@apple.com | c122cb2 | 2012-01-17 23:46:16 +0000 | [diff] [blame] | 36 | OBJC_CLASS NSEvent; |
darin | e4d34c6 | 2006-10-29 06:48:02 +0000 | [diff] [blame] | 37 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 38 | |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 39 | #if PLATFORM(IOS) |
mitz@apple.com | a87102a | 2014-02-08 00:07:48 +0000 | [diff] [blame] | 40 | OBJC_CLASS WebEvent; |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
zecke | 2752405 | 2007-09-23 09:50:35 +0000 | [diff] [blame] | 43 | #if PLATFORM(GTK) |
zecke | 258b9a8 | 2007-08-07 22:04:09 +0000 | [diff] [blame] | 44 | typedef struct _GdkEventKey GdkEventKey; |
mrobinson@webkit.org | 611bde9 | 2012-05-04 16:49:39 +0000 | [diff] [blame] | 45 | #include "CompositionResults.h" |
ggaren | 1ec9953 | 2006-06-10 16:09:27 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
eric@webkit.org | be7b75d | 2010-04-06 05:51:47 +0000 | [diff] [blame] | 48 | #if PLATFORM(EFL) |
eric@webkit.org | f32b063 | 2010-06-17 16:26:13 +0000 | [diff] [blame] | 49 | typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down; |
| 50 | typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up; |
eric@webkit.org | be7b75d | 2010-04-06 05:51:47 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 53 | namespace WebCore { |
| 54 | |
weinig@apple.com | 4824ed5 | 2011-12-16 22:46:17 +0000 | [diff] [blame] | 55 | class PlatformKeyboardEvent : public PlatformEvent { |
zoltan@webkit.org | 2eb7bec | 2012-09-14 09:12:48 +0000 | [diff] [blame] | 56 | WTF_MAKE_FAST_ALLOCATED; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 57 | public: |
andersca@apple.com | fbe6d8c | 2010-03-02 22:27:26 +0000 | [diff] [blame] | 58 | PlatformKeyboardEvent() |
weinig@apple.com | 4824ed5 | 2011-12-16 22:46:17 +0000 | [diff] [blame] | 59 | : PlatformEvent(PlatformEvent::KeyDown) |
andersca@apple.com | fbe6d8c | 2010-03-02 22:27:26 +0000 | [diff] [blame] | 60 | , m_windowsVirtualKeyCode(0) |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 61 | #if USE(APPKIT) || PLATFORM(GTK) |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 62 | , m_handledByInputMethod(false) |
| 63 | #endif |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 64 | , m_autoRepeat(false) |
andersca@apple.com | fbe6d8c | 2010-03-02 22:27:26 +0000 | [diff] [blame] | 65 | , m_isKeypad(false) |
andersca@apple.com | fbe6d8c | 2010-03-02 22:27:26 +0000 | [diff] [blame] | 66 | , m_isSystemKey(false) |
andersca@apple.com | fbe6d8c | 2010-03-02 22:27:26 +0000 | [diff] [blame] | 67 | #if PLATFORM(GTK) |
| 68 | , m_gdkEventKey(0) |
| 69 | #endif |
andersca@apple.com | fbe6d8c | 2010-03-02 22:27:26 +0000 | [diff] [blame] | 70 | { |
| 71 | } |
weinig@apple.com | 4824ed5 | 2011-12-16 22:46:17 +0000 | [diff] [blame] | 72 | |
cdumez@apple.com | e7cc9ac | 2016-10-03 21:32:47 +0000 | [diff] [blame] | 73 | PlatformKeyboardEvent(Type type, const String& text, const String& unmodifiedText, |
| 74 | #if ENABLE(KEYBOARD_KEY_ATTRIBUTE) |
| 75 | const String& key, |
| 76 | #endif |
cdumez@apple.com | 913b1f8 | 2016-10-05 03:13:35 +0000 | [diff] [blame] | 77 | #if ENABLE(KEYBOARD_CODE_ATTRIBUTE) |
| 78 | const String& code, |
| 79 | #endif |
cdumez@apple.com | e7cc9ac | 2016-10-03 21:32:47 +0000 | [diff] [blame] | 80 | const String& keyIdentifier, int windowsVirtualKeyCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, double timestamp) |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 81 | : PlatformEvent(type, modifiers, timestamp) |
| 82 | , m_text(text) |
| 83 | , m_unmodifiedText(unmodifiedText) |
cdumez@apple.com | e7cc9ac | 2016-10-03 21:32:47 +0000 | [diff] [blame] | 84 | #if ENABLE(KEYBOARD_KEY_ATTRIBUTE) |
| 85 | , m_key(key) |
| 86 | #endif |
cdumez@apple.com | 913b1f8 | 2016-10-05 03:13:35 +0000 | [diff] [blame] | 87 | #if ENABLE(KEYBOARD_CODE_ATTRIBUTE) |
| 88 | , m_code(code) |
| 89 | #endif |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 90 | , m_keyIdentifier(keyIdentifier) |
| 91 | , m_windowsVirtualKeyCode(windowsVirtualKeyCode) |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 92 | #if USE(APPKIT) || PLATFORM(GTK) |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 93 | , m_handledByInputMethod(false) |
| 94 | #endif |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 95 | , m_autoRepeat(isAutoRepeat) |
| 96 | , m_isKeypad(isKeypad) |
| 97 | , m_isSystemKey(isSystemKey) |
| 98 | { |
| 99 | } |
| 100 | |
commit-queue@webkit.org | 8cc7564 | 2014-08-22 18:25:37 +0000 | [diff] [blame] | 101 | WEBCORE_EXPORT void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events. |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 102 | |
| 103 | // Text as as generated by processing a virtual key code with a keyboard layout |
| 104 | // (in most cases, just a character code, but the layout can emit several |
| 105 | // characters in a single keypress event on some platforms). |
| 106 | // This may bear no resemblance to the ultimately inserted text if an input method |
| 107 | // processes the input. |
| 108 | // Will be null for KeyUp and RawKeyDown events. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 109 | String text() const { return m_text; } |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 110 | |
| 111 | // Text that would have been generated by the keyboard if no modifiers were pressed |
| 112 | // (except for Shift); useful for shortcut (accelerator) key handling. |
| 113 | // Otherwise, same as text(). |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 114 | String unmodifiedText() const { return m_unmodifiedText; } |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 115 | |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 116 | String keyIdentifier() const { return m_keyIdentifier; } |
| 117 | |
cdumez@apple.com | e7cc9ac | 2016-10-03 21:32:47 +0000 | [diff] [blame] | 118 | #if ENABLE(KEYBOARD_KEY_ATTRIBUTE) |
| 119 | const String& key() const { return m_key; } |
| 120 | #endif |
cdumez@apple.com | 913b1f8 | 2016-10-05 03:13:35 +0000 | [diff] [blame] | 121 | #if ENABLE(KEYBOARD_CODE_ATTRIBUTE) |
| 122 | const String& code() const { return m_code; } |
| 123 | #endif |
cdumez@apple.com | e7cc9ac | 2016-10-03 21:32:47 +0000 | [diff] [blame] | 124 | |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 125 | // Most compatible Windows virtual key code associated with the event. |
| 126 | // Zero for Char events. |
| 127 | int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; } |
| 128 | void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; } |
| 129 | |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 130 | #if USE(APPKIT) || PLATFORM(GTK) |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 131 | bool handledByInputMethod() const { return m_handledByInputMethod; } |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 132 | #endif |
| 133 | #if USE(APPKIT) |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 134 | const Vector<KeypressCommand>& commands() const { return m_commands; } |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 135 | #elif PLATFORM(GTK) |
| 136 | const Vector<String>& commands() const { return m_commands; } |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 139 | bool isAutoRepeat() const { return m_autoRepeat; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 140 | bool isKeypad() const { return m_isKeypad; } |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 141 | bool isSystemKey() const { return m_isSystemKey; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 142 | |
adele | e902c4c | 2007-10-30 21:05:22 +0000 | [diff] [blame] | 143 | static bool currentCapsLockState(); |
mitz@apple.com | b5a5688 | 2010-03-12 17:06:39 +0000 | [diff] [blame] | 144 | static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey); |
adele | e902c4c | 2007-10-30 21:05:22 +0000 | [diff] [blame] | 145 | |
mitz@apple.com | 1a8d7d3 | 2014-02-07 23:37:54 +0000 | [diff] [blame] | 146 | #if PLATFORM(COCOA) |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 147 | #if !PLATFORM(IOS) |
adele | 1c20483 | 2007-01-23 19:37:35 +0000 | [diff] [blame] | 148 | NSEvent* macEvent() const { return m_macEvent.get(); } |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 149 | #else |
| 150 | WebEvent *event() const { return m_Event.get(); } |
| 151 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 152 | #endif |
| 153 | |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 154 | #if PLATFORM(WIN) |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 155 | PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 156 | #endif |
| 157 | |
zecke | 2752405 | 2007-09-23 09:50:35 +0000 | [diff] [blame] | 158 | #if PLATFORM(GTK) |
mrobinson@webkit.org | 611bde9 | 2012-05-04 16:49:39 +0000 | [diff] [blame] | 159 | PlatformKeyboardEvent(GdkEventKey*, const CompositionResults&); |
| 160 | GdkEventKey* gdkEventKey() const { return m_gdkEventKey; } |
| 161 | const CompositionResults& compositionResults() const { return m_compositionResults; } |
alex@webkit.org | 948c72d | 2011-02-24 17:41:25 +0000 | [diff] [blame] | 162 | |
| 163 | // Used by WebKit2 |
| 164 | static String keyIdentifierForGdkKeyCode(unsigned); |
| 165 | static int windowsKeyCodeForGdkKeyCode(unsigned); |
| 166 | static String singleCharacterString(unsigned); |
ggaren | 1ec9953 | 2006-06-10 16:09:27 +0000 | [diff] [blame] | 167 | #endif |
| 168 | |
eric@webkit.org | be7b75d | 2010-04-06 05:51:47 +0000 | [diff] [blame] | 169 | #if PLATFORM(EFL) |
gyuyoung.kim@samsung.com | 0245dfc | 2012-07-26 08:55:13 +0000 | [diff] [blame] | 170 | explicit PlatformKeyboardEvent(const Evas_Event_Key_Down*); |
| 171 | explicit PlatformKeyboardEvent(const Evas_Event_Key_Up*); |
eric@webkit.org | be7b75d | 2010-04-06 05:51:47 +0000 | [diff] [blame] | 172 | #endif |
| 173 | |
darin@chromium.org | 5a0619c | 2008-10-15 05:15:47 +0000 | [diff] [blame] | 174 | protected: |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 175 | String m_text; |
| 176 | String m_unmodifiedText; |
cdumez@apple.com | e7cc9ac | 2016-10-03 21:32:47 +0000 | [diff] [blame] | 177 | #if ENABLE(KEYBOARD_KEY_ATTRIBUTE) |
| 178 | String m_key; |
| 179 | #endif |
cdumez@apple.com | 913b1f8 | 2016-10-05 03:13:35 +0000 | [diff] [blame] | 180 | #if ENABLE(KEYBOARD_CODE_ATTRIBUTE) |
| 181 | String m_code; |
| 182 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 183 | String m_keyIdentifier; |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 184 | int m_windowsVirtualKeyCode; |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 185 | #if USE(APPKIT) || PLATFORM(GTK) |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 186 | bool m_handledByInputMethod; |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 187 | #endif |
| 188 | #if USE(APPKIT) |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 189 | Vector<KeypressCommand> m_commands; |
carlosgc@webkit.org | f8a017d | 2015-06-10 13:32:22 +0000 | [diff] [blame] | 190 | #elif PLATFORM(GTK) |
| 191 | Vector<String> m_commands; |
ap@apple.com | abfe52c | 2014-03-09 22:56:08 +0000 | [diff] [blame] | 192 | #endif |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 193 | bool m_autoRepeat; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 194 | bool m_isKeypad; |
weinig@apple.com | 9ef4510 | 2011-12-24 03:45:50 +0000 | [diff] [blame] | 195 | bool m_isSystemKey; |
ap@webkit.org | 6a50667 | 2007-12-11 19:11:46 +0000 | [diff] [blame] | 196 | |
mitz@apple.com | 1a8d7d3 | 2014-02-07 23:37:54 +0000 | [diff] [blame] | 197 | #if PLATFORM(COCOA) |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 198 | #if !PLATFORM(IOS) |
adele | 1c20483 | 2007-01-23 19:37:35 +0000 | [diff] [blame] | 199 | RetainPtr<NSEvent> m_macEvent; |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 200 | #else |
| 201 | RetainPtr<WebEvent> m_Event; |
| 202 | #endif |
adele | 1c20483 | 2007-01-23 19:37:35 +0000 | [diff] [blame] | 203 | #endif |
alp@webkit.org | 01dce40 | 2008-02-08 10:41:58 +0000 | [diff] [blame] | 204 | #if PLATFORM(GTK) |
| 205 | GdkEventKey* m_gdkEventKey; |
mrobinson@webkit.org | 611bde9 | 2012-05-04 16:49:39 +0000 | [diff] [blame] | 206 | CompositionResults m_compositionResults; |
alp@webkit.org | 01dce40 | 2008-02-08 10:41:58 +0000 | [diff] [blame] | 207 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 208 | }; |
antti.j.koivisto@nokia.com | 622a426 | 2010-07-07 12:37:55 +0000 | [diff] [blame] | 209 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 210 | } // namespace WebCore |