diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/KeyboardEvent.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/KeyboardEvent.h')
-rw-r--r-- | Source/WebCore/dom/KeyboardEvent.h | 136 |
1 files changed, 80 insertions, 56 deletions
diff --git a/Source/WebCore/dom/KeyboardEvent.h b/Source/WebCore/dom/KeyboardEvent.h index b82a014c2..d17b5f6c9 100644 --- a/Source/WebCore/dom/KeyboardEvent.h +++ b/Source/WebCore/dom/KeyboardEvent.h @@ -21,10 +21,12 @@ * */ -#ifndef KeyboardEvent_h -#define KeyboardEvent_h +#pragma once +#include "EventModifierInit.h" +#include "KeypressCommand.h" #include "UIEventWithKeyState.h" +#include <memory> #include <wtf/Vector.h> namespace WebCore { @@ -32,94 +34,116 @@ namespace WebCore { class Node; class PlatformKeyboardEvent; -#if PLATFORM(MAC) -struct KeypressCommand { - KeypressCommand() { } - explicit KeypressCommand(const String& commandName) : commandName(commandName) { ASSERT(isASCIILower(commandName[0U])); } - KeypressCommand(const String& commandName, const String& text) : commandName(commandName), text(text) { ASSERT(commandName == "insertText:"); } - - String commandName; // Actually, a selector name - it may have a trailing colon, and a name that can be different from an editor command name. - String text; -}; -#endif - -struct KeyboardEventInit : public UIEventInit { - KeyboardEventInit(); - - String keyIdentifier; - unsigned location; - bool ctrlKey; - bool altKey; - bool shiftKey; - bool metaKey; -}; - -class KeyboardEvent : public UIEventWithKeyState { +class KeyboardEvent final : public UIEventWithKeyState { public: enum KeyLocationCode { DOM_KEY_LOCATION_STANDARD = 0x00, DOM_KEY_LOCATION_LEFT = 0x01, DOM_KEY_LOCATION_RIGHT = 0x02, DOM_KEY_LOCATION_NUMPAD = 0x03 - // FIXME: The following values are not supported yet (crbug.com/265446) - // DOM_KEY_LOCATION_MOBILE = 0x04, - // DOM_KEY_LOCATION_JOYSTICK = 0x05 }; - - static PassRefPtr<KeyboardEvent> create() + + static Ref<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, DOMWindow* view) { - return adoptRef(new KeyboardEvent); + return adoptRef(*new KeyboardEvent(platformEvent, view)); } - static PassRefPtr<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, AbstractView* view) + static Ref<KeyboardEvent> createForBindings() { - return adoptRef(new KeyboardEvent(platformEvent, view)); + return adoptRef(*new KeyboardEvent); } - static PassRefPtr<KeyboardEvent> create(const AtomicString& type, const KeyboardEventInit& initializer) + struct Init : public EventModifierInit { + String key; + String code; + unsigned location; + bool repeat; + bool isComposing; + + // Legacy. + String keyIdentifier; + std::optional<unsigned> keyLocation; + unsigned charCode; + unsigned keyCode; + unsigned which; + }; + + static Ref<KeyboardEvent> create(const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No) { - return adoptRef(new KeyboardEvent(type, initializer)); + return adoptRef(*new KeyboardEvent(type, initializer, isTrusted)); + } + + // FIXME: This method should be get ride of in the future. + // DO NOT USE IT! + static Ref<KeyboardEvent> createForDummy() + { + return adoptRef(*new KeyboardEvent(WTF::HashTableDeletedValue)); } virtual ~KeyboardEvent(); - void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*, + WEBCORE_EXPORT void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow*, const String& keyIdentifier, unsigned location, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false); +#if ENABLE(KEYBOARD_KEY_ATTRIBUTE) + const String& key() const { return m_key; } +#endif +#if ENABLE(KEYBOARD_CODE_ATTRIBUTE) + const String& code() const { return m_code; } +#endif + const String& keyIdentifier() const { return m_keyIdentifier; } unsigned location() const { return m_location; } + bool repeat() const { return m_repeat; } - bool getModifierState(const String& keyIdentifier) const; - - bool altGraphKey() const { return m_altGraphKey; } + WEBCORE_EXPORT bool getModifierState(const String& keyIdentifier) const; const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); } - virtual int keyCode() const override; // key code for keydown and keyup, character for keypress - virtual int charCode() const override; // character code for keypress, 0 for keydown and keyup + WEBCORE_EXPORT int keyCode() const; // key code for keydown and keyup, character for keypress + WEBCORE_EXPORT int charCode() const; // character code for keypress, 0 for keydown and keyup + + EventInterface eventInterface() const final; + bool isKeyboardEvent() const final; + int which() const final; - virtual EventInterface eventInterface() const override; - virtual bool isKeyboardEvent() const override; - virtual int which() const override; + bool isComposing() const { return m_isComposing; } -#if PLATFORM(MAC) - // We only have this need to store keypress command info on the Mac. +#if PLATFORM(COCOA) + bool handledByInputMethod() const { return m_handledByInputMethod; } + const Vector<KeypressCommand>& keypressCommands() const { return m_keypressCommands; } + + // The non-const version is still needed for WebKit1, which doesn't construct a complete KeyboardEvent with interpreted commands yet. Vector<KeypressCommand>& keypressCommands() { return m_keypressCommands; } #endif private: - KeyboardEvent(); - KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*); - KeyboardEvent(const AtomicString&, const KeyboardEventInit&); - - OwnPtr<PlatformKeyboardEvent> m_keyEvent; + WEBCORE_EXPORT KeyboardEvent(); + WEBCORE_EXPORT KeyboardEvent(const PlatformKeyboardEvent&, DOMWindow*); + KeyboardEvent(const AtomicString&, const Init&, IsTrusted); + // FIXME: This method should be get rid of in the future. + // DO NOT USE IT! + KeyboardEvent(WTF::HashTableDeletedValueType); + + std::unique_ptr<PlatformKeyboardEvent> m_keyEvent; +#if ENABLE(KEYBOARD_KEY_ATTRIBUTE) + String m_key; +#endif +#if ENABLE(KEYBOARD_CODE_ATTRIBUTE) + String m_code; +#endif String m_keyIdentifier; - unsigned m_location; - bool m_altGraphKey : 1; - -#if PLATFORM(MAC) + unsigned m_location { DOM_KEY_LOCATION_STANDARD }; + bool m_repeat { false }; + bool m_isComposing { false }; + std::optional<unsigned> m_charCode; + std::optional<unsigned> m_keyCode; + std::optional<unsigned> m_which; + +#if PLATFORM(COCOA) // Commands that were sent by AppKit when interpreting the event. Doesn't include input method commands. + bool m_handledByInputMethod { false }; Vector<KeypressCommand> m_keypressCommands; #endif }; @@ -128,4 +152,4 @@ KeyboardEvent* findKeyboardEvent(Event*); } // namespace WebCore -#endif // KeyboardEvent_h +SPECIALIZE_TYPE_TRAITS_EVENT(KeyboardEvent) |