| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) | 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
| 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) | 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
| 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 5 * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "core/events/KeyboardEvent.h" | 23 #include "core/events/KeyboardEvent.h" |
| 24 | 24 |
| 25 #include "bindings/core/v8/DOMWrapperWorld.h" | 25 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 26 #include "bindings/core/v8/ScriptState.h" | 26 #include "bindings/core/v8/ScriptState.h" |
| 27 #include "platform/PlatformKeyboardEvent.h" | |
| 28 #include "platform/WindowsKeyboardCodes.h" | 27 #include "platform/WindowsKeyboardCodes.h" |
| 28 #include "public/platform/Platform.h" |
| 29 #include "public/platform/WebInputEvent.h" |
| 29 #include "wtf/PtrUtil.h" | 30 #include "wtf/PtrUtil.h" |
| 30 | 31 |
| 31 namespace blink { | 32 namespace blink { |
| 32 | 33 |
| 33 static inline const AtomicString& eventTypeForKeyboardEventType(PlatformEvent::E
ventType type) | 34 static inline const AtomicString& eventTypeForKeyboardEventType(WebInputEvent::T
ype type) |
| 34 { | 35 { |
| 35 switch (type) { | 36 switch (type) { |
| 36 case PlatformEvent::KeyUp: | 37 case WebInputEvent::KeyUp: |
| 37 return EventTypeNames::keyup; | 38 return EventTypeNames::keyup; |
| 38 case PlatformEvent::RawKeyDown: | 39 case WebInputEvent::RawKeyDown: |
| 39 return EventTypeNames::keydown; | 40 return EventTypeNames::keydown; |
| 40 case PlatformEvent::Char: | 41 case WebInputEvent::Char: |
| 41 return EventTypeNames::keypress; | 42 return EventTypeNames::keypress; |
| 42 case PlatformEvent::KeyDown: | 43 case WebInputEvent::KeyDown: |
| 43 // The caller should disambiguate the combined event into RawKeyDown
or Char events. | 44 // The caller should disambiguate the combined event into RawKeyDown or
Char events. |
| 44 break; | 45 break; |
| 45 default: | 46 default: |
| 46 break; | 47 break; |
| 47 } | 48 } |
| 48 NOTREACHED(); | 49 NOTREACHED(); |
| 49 return EventTypeNames::keydown; | 50 return EventTypeNames::keydown; |
| 50 } | 51 } |
| 51 | 52 |
| 52 static inline KeyboardEvent::KeyLocationCode keyLocationCode(const PlatformKeybo
ardEvent& key) | 53 static inline KeyboardEvent::KeyLocationCode keyLocationCode(const WebInputEvent
& key) |
| 53 { | 54 { |
| 54 if (key.isKeypad()) | 55 if (key.modifiers & WebInputEvent::IsKeyPad) |
| 55 return KeyboardEvent::kDomKeyLocationNumpad; | 56 return KeyboardEvent::kDomKeyLocationNumpad; |
| 56 if (key.getModifiers() & PlatformEvent::IsLeft) | 57 if (key.modifiers & WebInputEvent::IsLeft) |
| 57 return KeyboardEvent::kDomKeyLocationLeft; | 58 return KeyboardEvent::kDomKeyLocationLeft; |
| 58 if (key.getModifiers() & PlatformEvent::IsRight) | 59 if (key.modifiers & WebInputEvent::IsRight) |
| 59 return KeyboardEvent::kDomKeyLocationRight; | 60 return KeyboardEvent::kDomKeyLocationRight; |
| 60 return KeyboardEvent::kDomKeyLocationStandard; | 61 return KeyboardEvent::kDomKeyLocationStandard; |
| 61 } | 62 } |
| 62 | 63 |
| 63 KeyboardEvent* KeyboardEvent::create(ScriptState* scriptState, const AtomicStrin
g& type, const KeyboardEventInit& initializer) | 64 KeyboardEvent* KeyboardEvent::create(ScriptState* scriptState, const AtomicStrin
g& type, const KeyboardEventInit& initializer) |
| 64 { | 65 { |
| 65 if (scriptState->world().isIsolatedWorld()) | 66 if (scriptState->world().isIsolatedWorld()) |
| 66 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey()
, initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); | 67 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey()
, initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); |
| 67 return new KeyboardEvent(type, initializer); | 68 return new KeyboardEvent(type, initializer); |
| 68 } | 69 } |
| 69 | 70 |
| 70 KeyboardEvent::KeyboardEvent() | 71 KeyboardEvent::KeyboardEvent() |
| 71 : m_location(kDomKeyLocationStandard) | 72 : m_location(kDomKeyLocationStandard) |
| 72 { | 73 { |
| 73 } | 74 } |
| 74 | 75 |
| 75 KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, AbstractView* vie
w) | 76 KeyboardEvent::KeyboardEvent(const WebKeyboardEvent& key, AbstractView* view) |
| 76 : UIEventWithKeyState(eventTypeForKeyboardEventType(key.type()), true, true,
view, 0, key.getModifiers(), key.timestamp(), InputDeviceCapabilities::doesntFi
reTouchEventsSourceCapabilities()) | 77 : UIEventWithKeyState(eventTypeForKeyboardEventType(key.type), true, true, v
iew, 0, static_cast<PlatformEvent::Modifiers>(key.modifiers), key.timeStampSecon
ds, InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities()) |
| 77 , m_keyEvent(wrapUnique(new PlatformKeyboardEvent(key))) | 78 , m_keyEvent(wrapUnique(new WebKeyboardEvent(key))) |
| 78 , m_code(key.code()) | 79 // TODO: BUG482880 Fix this initialization to lazy initialization. |
| 79 , m_key(key.key()) | 80 , m_code(Platform::current()->domCodeStringFromEnum(key.domCode)) |
| 81 , m_key(Platform::current()->domKeyStringFromEnum(key.domKey)) |
| 80 , m_location(keyLocationCode(key)) | 82 , m_location(keyLocationCode(key)) |
| 81 { | 83 { |
| 82 initLocationModifiers(m_location); | 84 initLocationModifiers(m_location); |
| 83 } | 85 } |
| 84 | 86 |
| 85 KeyboardEvent::KeyboardEvent(const AtomicString& eventType, const KeyboardEventI
nit& initializer) | 87 KeyboardEvent::KeyboardEvent(const AtomicString& eventType, const KeyboardEventI
nit& initializer) |
| 86 : UIEventWithKeyState(eventType, initializer) | 88 : UIEventWithKeyState(eventType, initializer) |
| 87 , m_code(initializer.code()) | 89 , m_code(initializer.code()) |
| 88 , m_key(initializer.key()) | 90 , m_key(initializer.key()) |
| 89 , m_location(initializer.location()) | 91 , m_location(initializer.location()) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 { | 130 { |
| 129 // IE: virtual key code for keyup/keydown, character code for keypress | 131 // IE: virtual key code for keyup/keydown, character code for keypress |
| 130 // Firefox: virtual key code for keyup/keydown, zero for keypress | 132 // Firefox: virtual key code for keyup/keydown, zero for keypress |
| 131 // We match IE. | 133 // We match IE. |
| 132 if (!m_keyEvent) | 134 if (!m_keyEvent) |
| 133 return 0; | 135 return 0; |
| 134 | 136 |
| 135 #if OS(ANDROID) | 137 #if OS(ANDROID) |
| 136 // FIXME: Check to see if this applies to other OS. | 138 // FIXME: Check to see if this applies to other OS. |
| 137 // If the key event belongs to IME composition then propagate to JS. | 139 // If the key event belongs to IME composition then propagate to JS. |
| 138 if (m_keyEvent->nativeVirtualKeyCode() == 0xE5) // VKEY_PROCESSKEY | 140 if (m_keyEvent->nativeKeyCode == 0xE5) // VKEY_PROCESSKEY |
| 139 return m_keyEvent->nativeVirtualKeyCode(); | 141 return m_keyEvent->nativeKeyCode; |
| 140 #endif | 142 #endif |
| 141 | 143 |
| 142 if (type() == EventTypeNames::keydown || type() == EventTypeNames::keyup) | 144 if (type() == EventTypeNames::keydown || type() == EventTypeNames::keyup) |
| 143 return m_keyEvent->windowsVirtualKeyCode(); | 145 return m_keyEvent->windowsKeyCode; |
| 144 | 146 |
| 145 return charCode(); | 147 return charCode(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 int KeyboardEvent::charCode() const | 150 int KeyboardEvent::charCode() const |
| 149 { | 151 { |
| 150 // IE: not supported | 152 // IE: not supported |
| 151 // Firefox: 0 for keydown/keyup events, character code for keypress | 153 // Firefox: 0 for keydown/keyup events, character code for keypress |
| 152 // We match Firefox | 154 // We match Firefox |
| 153 | 155 |
| 154 if (!m_keyEvent || (type() != EventTypeNames::keypress)) | 156 if (!m_keyEvent || (type() != EventTypeNames::keypress)) |
| 155 return 0; | 157 return 0; |
| 156 String text = m_keyEvent->text(); | 158 return m_keyEvent->text[0]; |
| 157 return static_cast<int>(text.characterStartingAt(0)); | |
| 158 } | 159 } |
| 159 | 160 |
| 160 const AtomicString& KeyboardEvent::interfaceName() const | 161 const AtomicString& KeyboardEvent::interfaceName() const |
| 161 { | 162 { |
| 162 return EventNames::KeyboardEvent; | 163 return EventNames::KeyboardEvent; |
| 163 } | 164 } |
| 164 | 165 |
| 165 bool KeyboardEvent::isKeyboardEvent() const | 166 bool KeyboardEvent::isKeyboardEvent() const |
| 166 { | 167 { |
| 167 return true; | 168 return true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 188 break; | 189 break; |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 DEFINE_TRACE(KeyboardEvent) | 193 DEFINE_TRACE(KeyboardEvent) |
| 193 { | 194 { |
| 194 UIEventWithKeyState::trace(visitor); | 195 UIEventWithKeyState::trace(visitor); |
| 195 } | 196 } |
| 196 | 197 |
| 197 } // namespace blink | 198 } // namespace blink |
| OLD | NEW |