2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include "EventModifierInit.h"
27 #include "KeypressCommand.h"
28 #include "UIEventWithKeyState.h"
30 #include <wtf/Vector.h>
35 class PlatformKeyboardEvent;
37 class KeyboardEvent final : public UIEventWithKeyState {
39 enum KeyLocationCode {
40 DOM_KEY_LOCATION_STANDARD = 0x00,
41 DOM_KEY_LOCATION_LEFT = 0x01,
42 DOM_KEY_LOCATION_RIGHT = 0x02,
43 DOM_KEY_LOCATION_NUMPAD = 0x03
46 WEBCORE_EXPORT static Ref<KeyboardEvent> create(const PlatformKeyboardEvent&, RefPtr<WindowProxy>&&);
47 static Ref<KeyboardEvent> createForBindings();
49 struct Init : public EventModifierInit {
58 Optional<unsigned> keyLocation;
64 static Ref<KeyboardEvent> create(const AtomString& type, const Init&);
66 virtual ~KeyboardEvent();
68 WEBCORE_EXPORT void initKeyboardEvent(const AtomString& type, bool canBubble, bool cancelable, RefPtr<WindowProxy>&&,
69 const String& keyIdentifier, unsigned location,
70 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false);
72 #if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
73 const String& key() const { return m_key; }
75 #if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
76 const String& code() const { return m_code; }
79 const String& keyIdentifier() const { return m_keyIdentifier; }
80 unsigned location() const { return m_location; }
81 bool repeat() const { return m_repeat; }
83 const PlatformKeyboardEvent* underlyingPlatformEvent() const { return m_underlyingPlatformEvent.get(); }
84 PlatformKeyboardEvent* underlyingPlatformEvent() { return m_underlyingPlatformEvent.get(); }
86 WEBCORE_EXPORT int keyCode() const; // key code for keydown and keyup, character for keypress
87 WEBCORE_EXPORT int charCode() const; // character code for keypress, 0 for keydown and keyup
89 EventInterface eventInterface() const final;
90 bool isKeyboardEvent() const final;
91 int which() const final;
93 bool isComposing() const { return m_isComposing; }
96 bool handledByInputMethod() const { return m_handledByInputMethod; }
97 const Vector<KeypressCommand>& keypressCommands() const { return m_keypressCommands; }
98 Vector<KeypressCommand>& keypressCommands() { return m_keypressCommands; }
103 KeyboardEvent(const PlatformKeyboardEvent&, RefPtr<WindowProxy>&&);
104 KeyboardEvent(const AtomString&, const Init&);
106 std::unique_ptr<PlatformKeyboardEvent> m_underlyingPlatformEvent;
107 #if ENABLE(KEYBOARD_KEY_ATTRIBUTE)
110 #if ENABLE(KEYBOARD_CODE_ATTRIBUTE)
113 String m_keyIdentifier;
114 unsigned m_location { DOM_KEY_LOCATION_STANDARD };
115 bool m_repeat { false };
116 bool m_isComposing { false };
117 Optional<unsigned> m_charCode;
118 Optional<unsigned> m_keyCode;
119 Optional<unsigned> m_which;
122 // Commands that were sent by AppKit when interpreting the event. Doesn't include input method commands.
123 bool m_handledByInputMethod { false };
124 Vector<KeypressCommand> m_keypressCommands;
128 } // namespace WebCore
130 SPECIALIZE_TYPE_TRAITS_EVENT(KeyboardEvent)