| 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 "core/editing/InputMethodController.h" |
| 27 #include "platform/WindowsKeyboardCodes.h" | 28 #include "platform/WindowsKeyboardCodes.h" |
| 28 #include "public/platform/Platform.h" | 29 #include "public/platform/Platform.h" |
| 29 #include "public/platform/WebInputEvent.h" | 30 #include "public/platform/WebInputEvent.h" |
| 30 #include "wtf/PtrUtil.h" | 31 #include "wtf/PtrUtil.h" |
| 31 | 32 |
| 32 namespace blink { | 33 namespace blink { |
| 33 | 34 |
| 34 static inline const AtomicString& eventTypeForKeyboardEventType( | 35 namespace { |
| 35 WebInputEvent::Type type) { | 36 |
| 37 const AtomicString& eventTypeForKeyboardEventType(WebInputEvent::Type type) { |
| 36 switch (type) { | 38 switch (type) { |
| 37 case WebInputEvent::KeyUp: | 39 case WebInputEvent::KeyUp: |
| 38 return EventTypeNames::keyup; | 40 return EventTypeNames::keyup; |
| 39 case WebInputEvent::RawKeyDown: | 41 case WebInputEvent::RawKeyDown: |
| 40 return EventTypeNames::keydown; | 42 return EventTypeNames::keydown; |
| 41 case WebInputEvent::Char: | 43 case WebInputEvent::Char: |
| 42 return EventTypeNames::keypress; | 44 return EventTypeNames::keypress; |
| 43 case WebInputEvent::KeyDown: | 45 case WebInputEvent::KeyDown: |
| 44 // The caller should disambiguate the combined event into RawKeyDown or | 46 // The caller should disambiguate the combined event into RawKeyDown or |
| 45 // Char events. | 47 // Char events. |
| 46 break; | 48 break; |
| 47 default: | 49 default: |
| 48 break; | 50 break; |
| 49 } | 51 } |
| 50 NOTREACHED(); | 52 NOTREACHED(); |
| 51 return EventTypeNames::keydown; | 53 return EventTypeNames::keydown; |
| 52 } | 54 } |
| 53 | 55 |
| 54 static inline KeyboardEvent::KeyLocationCode keyLocationCode( | 56 KeyboardEvent::KeyLocationCode keyLocationCode(const WebInputEvent& key) { |
| 55 const WebInputEvent& key) { | |
| 56 if (key.modifiers & WebInputEvent::IsKeyPad) | 57 if (key.modifiers & WebInputEvent::IsKeyPad) |
| 57 return KeyboardEvent::kDomKeyLocationNumpad; | 58 return KeyboardEvent::kDomKeyLocationNumpad; |
| 58 if (key.modifiers & WebInputEvent::IsLeft) | 59 if (key.modifiers & WebInputEvent::IsLeft) |
| 59 return KeyboardEvent::kDomKeyLocationLeft; | 60 return KeyboardEvent::kDomKeyLocationLeft; |
| 60 if (key.modifiers & WebInputEvent::IsRight) | 61 if (key.modifiers & WebInputEvent::IsRight) |
| 61 return KeyboardEvent::kDomKeyLocationRight; | 62 return KeyboardEvent::kDomKeyLocationRight; |
| 62 return KeyboardEvent::kDomKeyLocationStandard; | 63 return KeyboardEvent::kDomKeyLocationStandard; |
| 63 } | 64 } |
| 64 | 65 |
| 66 bool hasCurrentComposition(LocalDOMWindow* domWindow) { |
| 67 if (!domWindow) |
| 68 return false; |
| 69 LocalFrame* localFrame = domWindow->frame(); |
| 70 if (!localFrame) |
| 71 return false; |
| 72 return localFrame->inputMethodController().hasComposition(); |
| 73 } |
| 74 |
| 75 } // namespace |
| 76 |
| 65 KeyboardEvent* KeyboardEvent::create(ScriptState* scriptState, | 77 KeyboardEvent* KeyboardEvent::create(ScriptState* scriptState, |
| 66 const AtomicString& type, | 78 const AtomicString& type, |
| 67 const KeyboardEventInit& initializer) { | 79 const KeyboardEventInit& initializer) { |
| 68 if (scriptState->world().isIsolatedWorld()) | 80 if (scriptState->world().isIsolatedWorld()) |
| 69 UIEventWithKeyState::didCreateEventInIsolatedWorld( | 81 UIEventWithKeyState::didCreateEventInIsolatedWorld( |
| 70 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), | 82 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), |
| 71 initializer.metaKey()); | 83 initializer.metaKey()); |
| 72 return new KeyboardEvent(type, initializer); | 84 return new KeyboardEvent(type, initializer); |
| 73 } | 85 } |
| 74 | 86 |
| 75 KeyboardEvent::KeyboardEvent() : m_location(kDomKeyLocationStandard) {} | 87 KeyboardEvent::KeyboardEvent() : m_location(kDomKeyLocationStandard) {} |
| 76 | 88 |
| 77 KeyboardEvent::KeyboardEvent(const WebKeyboardEvent& key, AbstractView* view) | 89 KeyboardEvent::KeyboardEvent(const WebKeyboardEvent& key, |
| 90 LocalDOMWindow* domWindow) |
| 78 : UIEventWithKeyState( | 91 : UIEventWithKeyState( |
| 79 eventTypeForKeyboardEventType(key.type), | 92 eventTypeForKeyboardEventType(key.type), |
| 80 true, | 93 true, |
| 81 true, | 94 true, |
| 82 view, | 95 domWindow, |
| 83 0, | 96 0, |
| 84 static_cast<PlatformEvent::Modifiers>(key.modifiers), | 97 static_cast<PlatformEvent::Modifiers>(key.modifiers), |
| 85 key.timeStampSeconds, | 98 key.timeStampSeconds, |
| 86 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities()), | 99 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities()), |
| 87 m_keyEvent(wrapUnique(new WebKeyboardEvent(key))), | 100 m_keyEvent(wrapUnique(new WebKeyboardEvent(key))), |
| 88 // TODO(crbug.com/482880): Fix this initialization to lazy initialization. | 101 // TODO(crbug.com/482880): Fix this initialization to lazy initialization. |
| 89 m_code(Platform::current()->domCodeStringFromEnum(key.domCode)), | 102 m_code(Platform::current()->domCodeStringFromEnum(key.domCode)), |
| 90 m_key(Platform::current()->domKeyStringFromEnum(key.domKey)), | 103 m_key(Platform::current()->domKeyStringFromEnum(key.domKey)), |
| 91 m_location(keyLocationCode(key)) { | 104 m_location(keyLocationCode(key)), |
| 105 m_isComposing(hasCurrentComposition(domWindow)) { |
| 92 initLocationModifiers(m_location); | 106 initLocationModifiers(m_location); |
| 93 } | 107 } |
| 94 | 108 |
| 95 KeyboardEvent::KeyboardEvent(const AtomicString& eventType, | 109 KeyboardEvent::KeyboardEvent(const AtomicString& eventType, |
| 96 const KeyboardEventInit& initializer) | 110 const KeyboardEventInit& initializer) |
| 97 : UIEventWithKeyState(eventType, initializer), | 111 : UIEventWithKeyState(eventType, initializer), |
| 98 m_code(initializer.code()), | 112 m_code(initializer.code()), |
| 99 m_key(initializer.key()), | 113 m_key(initializer.key()), |
| 100 m_location(initializer.location()) { | 114 m_location(initializer.location()), |
| 115 m_isComposing(initializer.isComposing()) { |
| 101 if (initializer.repeat()) | 116 if (initializer.repeat()) |
| 102 m_modifiers |= PlatformEvent::IsAutoRepeat; | 117 m_modifiers |= PlatformEvent::IsAutoRepeat; |
| 103 initLocationModifiers(initializer.location()); | 118 initLocationModifiers(initializer.location()); |
| 104 } | 119 } |
| 105 | 120 |
| 106 KeyboardEvent::KeyboardEvent(const AtomicString& eventType, | |
| 107 bool canBubble, | |
| 108 bool cancelable, | |
| 109 AbstractView* view, | |
| 110 const String& code, | |
| 111 const String& key, | |
| 112 unsigned location, | |
| 113 PlatformEvent::Modifiers modifiers, | |
| 114 double plaformTimeStamp) | |
| 115 : UIEventWithKeyState( | |
| 116 eventType, | |
| 117 canBubble, | |
| 118 cancelable, | |
| 119 view, | |
| 120 0, | |
| 121 modifiers, | |
| 122 plaformTimeStamp, | |
| 123 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities()), | |
| 124 m_code(code), | |
| 125 m_key(key), | |
| 126 m_location(location) { | |
| 127 initLocationModifiers(location); | |
| 128 } | |
| 129 | |
| 130 KeyboardEvent::~KeyboardEvent() {} | 121 KeyboardEvent::~KeyboardEvent() {} |
| 131 | 122 |
| 132 void KeyboardEvent::initKeyboardEvent(ScriptState* scriptState, | 123 void KeyboardEvent::initKeyboardEvent(ScriptState* scriptState, |
| 133 const AtomicString& type, | 124 const AtomicString& type, |
| 134 bool canBubble, | 125 bool canBubble, |
| 135 bool cancelable, | 126 bool cancelable, |
| 136 AbstractView* view, | 127 AbstractView* view, |
| 137 const String& keyIdentifier, | 128 const String& keyIdentifier, |
| 138 unsigned location, | 129 unsigned location, |
| 139 bool ctrlKey, | 130 bool ctrlKey, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 m_modifiers |= PlatformEvent::IsRight; | 202 m_modifiers |= PlatformEvent::IsRight; |
| 212 break; | 203 break; |
| 213 } | 204 } |
| 214 } | 205 } |
| 215 | 206 |
| 216 DEFINE_TRACE(KeyboardEvent) { | 207 DEFINE_TRACE(KeyboardEvent) { |
| 217 UIEventWithKeyState::trace(visitor); | 208 UIEventWithKeyState::trace(visitor); |
| 218 } | 209 } |
| 219 | 210 |
| 220 } // namespace blink | 211 } // namespace blink |
| OLD | NEW |