diff options
Diffstat (limited to 'Source/WebCore/dom/KeyboardEvent.cpp')
-rw-r--r-- | Source/WebCore/dom/KeyboardEvent.cpp | 90 |
1 files changed, 63 insertions, 27 deletions
diff --git a/Source/WebCore/dom/KeyboardEvent.cpp b/Source/WebCore/dom/KeyboardEvent.cpp index c0e16f841..2bd931fc4 100644 --- a/Source/WebCore/dom/KeyboardEvent.cpp +++ b/Source/WebCore/dom/KeyboardEvent.cpp @@ -24,11 +24,12 @@ #include "KeyboardEvent.h" #include "Document.h" +#include "Editor.h" #include "EventDispatcher.h" #include "EventHandler.h" +#include "EventNames.h" #include "Frame.h" #include "PlatformKeyboardEvent.h" -#include "Settings.h" #include "WindowsKeyboardCodes.h" namespace WebCore { @@ -90,36 +91,58 @@ static inline KeyboardEvent::KeyLocationCode keyLocationCode(const PlatformKeybo } } -KeyboardEventInit::KeyboardEventInit() - : location(0) - , ctrlKey(false) - , altKey(false) - , shiftKey(false) - , metaKey(false) -{ -} +KeyboardEvent::KeyboardEvent() = default; -KeyboardEvent::KeyboardEvent() - : m_location(DOM_KEY_LOCATION_STANDARD) - , m_altGraphKey(false) +KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, DOMWindow* view) + : UIEventWithKeyState(eventTypeForKeyboardEventType(key.type()) + , true, true, key.timestamp(), view, 0, key.ctrlKey(), key.altKey(), key.shiftKey() + , key.metaKey(), false, key.modifiers().contains(PlatformEvent::Modifier::CapsLockKey)) + , m_keyEvent(std::make_unique<PlatformKeyboardEvent>(key)) +#if ENABLE(KEYBOARD_KEY_ATTRIBUTE) + , m_key(key.key()) +#endif +#if ENABLE(KEYBOARD_CODE_ATTRIBUTE) + , m_code(key.code()) +#endif + , m_keyIdentifier(key.keyIdentifier()) + , m_location(keyLocationCode(key)) + , m_repeat(key.isAutoRepeat()) + , m_isComposing(view && view->frame() && view->frame()->editor().hasComposition()) +#if PLATFORM(COCOA) +#if USE(APPKIT) + , m_handledByInputMethod(key.handledByInputMethod()) + , m_keypressCommands(key.commands()) +#else + , m_handledByInputMethod(false) +#endif +#endif { } -KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, AbstractView* view) - : UIEventWithKeyState(eventTypeForKeyboardEventType(key.type()), - true, true, key.timestamp(), view, 0, key.ctrlKey(), key.altKey(), key.shiftKey(), key.metaKey()) - , m_keyEvent(adoptPtr(new PlatformKeyboardEvent(key))) - , m_keyIdentifier(key.keyIdentifier()) - , m_location(keyLocationCode(key)) - , m_altGraphKey(false) +// FIXME: This method should be get ride of in the future. +// DO NOT USE IT! +KeyboardEvent::KeyboardEvent(WTF::HashTableDeletedValueType) { } -KeyboardEvent::KeyboardEvent(const AtomicString& eventType, const KeyboardEventInit& initializer) - : UIEventWithKeyState(eventType, initializer.bubbles, initializer.cancelable, initializer.view, initializer.detail, initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializer.metaKey) +KeyboardEvent::KeyboardEvent(const AtomicString& eventType, const Init& initializer, IsTrusted isTrusted) + : UIEventWithKeyState(eventType, initializer, isTrusted) +#if ENABLE(KEYBOARD_KEY_ATTRIBUTE) + , m_key(initializer.key) +#endif +#if ENABLE(KEYBOARD_CODE_ATTRIBUTE) + , m_code(initializer.code) +#endif , m_keyIdentifier(initializer.keyIdentifier) - , m_location(initializer.location) - , m_altGraphKey(false) + , m_location(initializer.keyLocation ? *initializer.keyLocation : initializer.location) + , m_repeat(initializer.repeat) + , m_isComposing(initializer.isComposing) + , m_charCode(initializer.charCode) + , m_keyCode(initializer.keyCode) + , m_which(initializer.which) +#if PLATFORM(COCOA) + , m_handledByInputMethod(false) +#endif { } @@ -127,7 +150,7 @@ KeyboardEvent::~KeyboardEvent() { } -void KeyboardEvent::initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view, +void KeyboardEvent::initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow* view, const String &keyIdentifier, unsigned location, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey) { @@ -155,11 +178,19 @@ bool KeyboardEvent::getModifierState(const String& keyIdentifier) const return altKey(); if (keyIdentifier == "Meta") return metaKey(); + if (keyIdentifier == "AltGraph") + return altGraphKey(); + if (keyIdentifier == "CapsLock") + return capsLockKey(); + // FIXME: The specification also has Fn, FnLock, Hyper, NumLock, Super, ScrollLock, Symbol, SymbolLock. return false; } int KeyboardEvent::keyCode() const { + if (m_keyCode) + return m_keyCode.value(); + // IE: virtual key code for keyup/keydown, character code for keypress // Firefox: virtual key code for keyup/keydown, zero for keypress // We match IE. @@ -173,6 +204,9 @@ int KeyboardEvent::keyCode() const int KeyboardEvent::charCode() const { + if (m_charCode) + return m_charCode.value(); + // IE: not supported // Firefox: 0 for keydown/keyup events, character code for keypress // We match Firefox, unless in backward compatibility mode, where we always return the character code. @@ -200,15 +234,17 @@ int KeyboardEvent::which() const { // Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress. // That's exactly what IE's "keyCode" returns. So they are the same for keyboard events. + if (m_which) + return m_which.value(); return keyCode(); } KeyboardEvent* findKeyboardEvent(Event* event) { for (Event* e = event; e; e = e->underlyingEvent()) - if (e->isKeyboardEvent()) - return static_cast<KeyboardEvent*>(e); - return 0; + if (is<KeyboardEvent>(*e)) + return downcast<KeyboardEvent>(e); + return nullptr; } } // namespace WebCore |