blob: 7f40d697024f2ca5bff80ac67618fffb69e66402 [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
mjs@apple.com92047332014-03-15 04:08:27 +00002 * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved.
alp@webkit.org01dce402008-02-08 10:41:58 +00003 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
darinb9481ed2006-03-20 02:57:59 +00004 *
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.com92047332014-03-15 04:08:27 +000014 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
darinb9481ed2006-03-20 02:57:59 +000015 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mjs@apple.com92047332014-03-15 04:08:27 +000017 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
darinb9481ed2006-03-20 02:57:59 +000018 * 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.coma59dc4c2016-09-27 19:08:34 +000027#pragma once
darinb9481ed2006-03-20 02:57:59 +000028
ap@apple.comabfe52c2014-03-09 22:56:08 +000029#include "KeypressCommand.h"
weinig@apple.com4824ed52011-12-16 22:46:17 +000030#include "PlatformEvent.h"
paroga@webkit.org51f3bcd2013-07-30 18:54:18 +000031#include <wtf/WindowsExtras.h>
weinig@apple.com4824ed52011-12-16 22:46:17 +000032#include <wtf/text/WTFString.h>
darinb9481ed2006-03-20 02:57:59 +000033
mitz@apple.com1a8d7d32014-02-07 23:37:54 +000034#if PLATFORM(COCOA)
beidson4ce64942007-03-24 23:21:50 +000035#include <wtf/RetainPtr.h>
weinig@apple.comc122cb22012-01-17 23:46:16 +000036OBJC_CLASS NSEvent;
darine4d34c62006-10-29 06:48:02 +000037#endif
darinb9481ed2006-03-20 02:57:59 +000038
dbates@webkit.orgb8ade582014-01-09 22:59:07 +000039#if PLATFORM(IOS)
mitz@apple.coma87102a2014-02-08 00:07:48 +000040OBJC_CLASS WebEvent;
dbates@webkit.orgb8ade582014-01-09 22:59:07 +000041#endif
42
zecke27524052007-09-23 09:50:35 +000043#if PLATFORM(GTK)
zecke258b9a82007-08-07 22:04:09 +000044typedef struct _GdkEventKey GdkEventKey;
mrobinson@webkit.org611bde92012-05-04 16:49:39 +000045#include "CompositionResults.h"
ggaren1ec99532006-06-10 16:09:27 +000046#endif
47
eric@webkit.orgbe7b75d2010-04-06 05:51:47 +000048#if PLATFORM(EFL)
eric@webkit.orgf32b0632010-06-17 16:26:13 +000049typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down;
50typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up;
eric@webkit.orgbe7b75d2010-04-06 05:51:47 +000051#endif
52
darinb9481ed2006-03-20 02:57:59 +000053namespace WebCore {
54
weinig@apple.com4824ed52011-12-16 22:46:17 +000055 class PlatformKeyboardEvent : public PlatformEvent {
zoltan@webkit.org2eb7bec2012-09-14 09:12:48 +000056 WTF_MAKE_FAST_ALLOCATED;
darinb9481ed2006-03-20 02:57:59 +000057 public:
andersca@apple.comfbe6d8c2010-03-02 22:27:26 +000058 PlatformKeyboardEvent()
weinig@apple.com4824ed52011-12-16 22:46:17 +000059 : PlatformEvent(PlatformEvent::KeyDown)
andersca@apple.comfbe6d8c2010-03-02 22:27:26 +000060 , m_windowsVirtualKeyCode(0)
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +000061#if USE(APPKIT) || PLATFORM(GTK)
ap@apple.comabfe52c2014-03-09 22:56:08 +000062 , m_handledByInputMethod(false)
63#endif
weinig@apple.com9ef45102011-12-24 03:45:50 +000064 , m_autoRepeat(false)
andersca@apple.comfbe6d8c2010-03-02 22:27:26 +000065 , m_isKeypad(false)
andersca@apple.comfbe6d8c2010-03-02 22:27:26 +000066 , m_isSystemKey(false)
andersca@apple.comfbe6d8c2010-03-02 22:27:26 +000067#if PLATFORM(GTK)
68 , m_gdkEventKey(0)
69#endif
andersca@apple.comfbe6d8c2010-03-02 22:27:26 +000070 {
71 }
weinig@apple.com4824ed52011-12-16 22:46:17 +000072
cdumez@apple.come7cc9ac2016-10-03 21:32:47 +000073 PlatformKeyboardEvent(Type type, const String& text, const String& unmodifiedText,
74#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
75 const String& key,
76#endif
cdumez@apple.com913b1f82016-10-05 03:13:35 +000077#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
78 const String& code,
79#endif
cdumez@apple.come7cc9ac2016-10-03 21:32:47 +000080 const String& keyIdentifier, int windowsVirtualKeyCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, double timestamp)
weinig@apple.com9ef45102011-12-24 03:45:50 +000081 : PlatformEvent(type, modifiers, timestamp)
82 , m_text(text)
83 , m_unmodifiedText(unmodifiedText)
cdumez@apple.come7cc9ac2016-10-03 21:32:47 +000084#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
85 , m_key(key)
86#endif
cdumez@apple.com913b1f82016-10-05 03:13:35 +000087#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
88 , m_code(code)
89#endif
weinig@apple.com9ef45102011-12-24 03:45:50 +000090 , m_keyIdentifier(keyIdentifier)
91 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +000092#if USE(APPKIT) || PLATFORM(GTK)
ap@apple.comabfe52c2014-03-09 22:56:08 +000093 , m_handledByInputMethod(false)
94#endif
weinig@apple.com9ef45102011-12-24 03:45:50 +000095 , m_autoRepeat(isAutoRepeat)
96 , m_isKeypad(isKeypad)
97 , m_isSystemKey(isSystemKey)
98 {
99 }
100
commit-queue@webkit.org8cc75642014-08-22 18:25:37 +0000101 WEBCORE_EXPORT void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events.
ap@webkit.org6a506672007-12-11 19:11:46 +0000102
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.
darinb9481ed2006-03-20 02:57:59 +0000109 String text() const { return m_text; }
ap@webkit.org6a506672007-12-11 19:11:46 +0000110
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().
darinb9481ed2006-03-20 02:57:59 +0000114 String unmodifiedText() const { return m_unmodifiedText; }
ap@webkit.org6a506672007-12-11 19:11:46 +0000115
weinig@apple.com9ef45102011-12-24 03:45:50 +0000116 String keyIdentifier() const { return m_keyIdentifier; }
117
cdumez@apple.come7cc9ac2016-10-03 21:32:47 +0000118#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
119 const String& key() const { return m_key; }
120#endif
cdumez@apple.com913b1f82016-10-05 03:13:35 +0000121#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
122 const String& code() const { return m_code; }
123#endif
cdumez@apple.come7cc9ac2016-10-03 21:32:47 +0000124
ap@webkit.org6a506672007-12-11 19:11:46 +0000125 // 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.orgf8a017d2015-06-10 13:32:22 +0000130#if USE(APPKIT) || PLATFORM(GTK)
ap@apple.comabfe52c2014-03-09 22:56:08 +0000131 bool handledByInputMethod() const { return m_handledByInputMethod; }
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +0000132#endif
133#if USE(APPKIT)
ap@apple.comabfe52c2014-03-09 22:56:08 +0000134 const Vector<KeypressCommand>& commands() const { return m_commands; }
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +0000135#elif PLATFORM(GTK)
136 const Vector<String>& commands() const { return m_commands; }
ap@apple.comabfe52c2014-03-09 22:56:08 +0000137#endif
138
darinb9481ed2006-03-20 02:57:59 +0000139 bool isAutoRepeat() const { return m_autoRepeat; }
darinb9481ed2006-03-20 02:57:59 +0000140 bool isKeypad() const { return m_isKeypad; }
weinig@apple.com9ef45102011-12-24 03:45:50 +0000141 bool isSystemKey() const { return m_isSystemKey; }
darinb9481ed2006-03-20 02:57:59 +0000142
adelee902c4c2007-10-30 21:05:22 +0000143 static bool currentCapsLockState();
mitz@apple.comb5a56882010-03-12 17:06:39 +0000144 static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey);
adelee902c4c2007-10-30 21:05:22 +0000145
mitz@apple.com1a8d7d32014-02-07 23:37:54 +0000146#if PLATFORM(COCOA)
dbates@webkit.orgb8ade582014-01-09 22:59:07 +0000147#if !PLATFORM(IOS)
adele1c204832007-01-23 19:37:35 +0000148 NSEvent* macEvent() const { return m_macEvent.get(); }
dbates@webkit.orgb8ade582014-01-09 22:59:07 +0000149#else
150 WebEvent *event() const { return m_Event.get(); }
151#endif
darinb9481ed2006-03-20 02:57:59 +0000152#endif
153
weinigf18aae32006-08-03 21:55:57 +0000154#if PLATFORM(WIN)
ap@webkit.org6a506672007-12-11 19:11:46 +0000155 PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool);
darinb9481ed2006-03-20 02:57:59 +0000156#endif
157
zecke27524052007-09-23 09:50:35 +0000158#if PLATFORM(GTK)
mrobinson@webkit.org611bde92012-05-04 16:49:39 +0000159 PlatformKeyboardEvent(GdkEventKey*, const CompositionResults&);
160 GdkEventKey* gdkEventKey() const { return m_gdkEventKey; }
161 const CompositionResults& compositionResults() const { return m_compositionResults; }
alex@webkit.org948c72d2011-02-24 17:41:25 +0000162
163 // Used by WebKit2
164 static String keyIdentifierForGdkKeyCode(unsigned);
165 static int windowsKeyCodeForGdkKeyCode(unsigned);
166 static String singleCharacterString(unsigned);
ggaren1ec99532006-06-10 16:09:27 +0000167#endif
168
eric@webkit.orgbe7b75d2010-04-06 05:51:47 +0000169#if PLATFORM(EFL)
gyuyoung.kim@samsung.com0245dfc2012-07-26 08:55:13 +0000170 explicit PlatformKeyboardEvent(const Evas_Event_Key_Down*);
171 explicit PlatformKeyboardEvent(const Evas_Event_Key_Up*);
eric@webkit.orgbe7b75d2010-04-06 05:51:47 +0000172#endif
173
darin@chromium.org5a0619c2008-10-15 05:15:47 +0000174 protected:
darinb9481ed2006-03-20 02:57:59 +0000175 String m_text;
176 String m_unmodifiedText;
cdumez@apple.come7cc9ac2016-10-03 21:32:47 +0000177#if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
178 String m_key;
179#endif
cdumez@apple.com913b1f82016-10-05 03:13:35 +0000180#if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
181 String m_code;
182#endif
darinb9481ed2006-03-20 02:57:59 +0000183 String m_keyIdentifier;
ap@webkit.org6a506672007-12-11 19:11:46 +0000184 int m_windowsVirtualKeyCode;
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +0000185#if USE(APPKIT) || PLATFORM(GTK)
ap@apple.comabfe52c2014-03-09 22:56:08 +0000186 bool m_handledByInputMethod;
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +0000187#endif
188#if USE(APPKIT)
ap@apple.comabfe52c2014-03-09 22:56:08 +0000189 Vector<KeypressCommand> m_commands;
carlosgc@webkit.orgf8a017d2015-06-10 13:32:22 +0000190#elif PLATFORM(GTK)
191 Vector<String> m_commands;
ap@apple.comabfe52c2014-03-09 22:56:08 +0000192#endif
weinig@apple.com9ef45102011-12-24 03:45:50 +0000193 bool m_autoRepeat;
darinb9481ed2006-03-20 02:57:59 +0000194 bool m_isKeypad;
weinig@apple.com9ef45102011-12-24 03:45:50 +0000195 bool m_isSystemKey;
ap@webkit.org6a506672007-12-11 19:11:46 +0000196
mitz@apple.com1a8d7d32014-02-07 23:37:54 +0000197#if PLATFORM(COCOA)
dbates@webkit.orgb8ade582014-01-09 22:59:07 +0000198#if !PLATFORM(IOS)
adele1c204832007-01-23 19:37:35 +0000199 RetainPtr<NSEvent> m_macEvent;
dbates@webkit.orgb8ade582014-01-09 22:59:07 +0000200#else
201 RetainPtr<WebEvent> m_Event;
202#endif
adele1c204832007-01-23 19:37:35 +0000203#endif
alp@webkit.org01dce402008-02-08 10:41:58 +0000204#if PLATFORM(GTK)
205 GdkEventKey* m_gdkEventKey;
mrobinson@webkit.org611bde92012-05-04 16:49:39 +0000206 CompositionResults m_compositionResults;
alp@webkit.org01dce402008-02-08 10:41:58 +0000207#endif
darinb9481ed2006-03-20 02:57:59 +0000208 };
antti.j.koivisto@nokia.com622a4262010-07-07 12:37:55 +0000209
weinig681a5172006-06-19 22:58:36 +0000210} // namespace WebCore