| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "core/events/UIEventWithKeyState.h" | 21 #include "core/events/UIEventWithKeyState.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 UIEventWithKeyState::UIEventWithKeyState( | 25 UIEventWithKeyState::UIEventWithKeyState( |
| 26 const AtomicString& type, | 26 const AtomicString& type, |
| 27 bool canBubble, | 27 bool canBubble, |
| 28 bool cancelable, | 28 bool cancelable, |
| 29 AbstractView* view, | 29 AbstractView* view, |
| 30 int detail, | 30 int detail, |
| 31 PlatformEvent::Modifiers modifiers, | 31 WebInputEvent::Modifiers modifiers, |
| 32 TimeTicks platformTimeStamp, | 32 TimeTicks platformTimeStamp, |
| 33 InputDeviceCapabilities* sourceCapabilities) | 33 InputDeviceCapabilities* sourceCapabilities) |
| 34 : UIEvent(type, | 34 : UIEvent(type, |
| 35 canBubble, | 35 canBubble, |
| 36 cancelable, | 36 cancelable, |
| 37 ComposedMode::Composed, | 37 ComposedMode::Composed, |
| 38 platformTimeStamp, | 38 platformTimeStamp, |
| 39 view, | 39 view, |
| 40 detail, | 40 detail, |
| 41 sourceCapabilities), | 41 sourceCapabilities), |
| 42 m_modifiers(modifiers) {} | 42 m_modifiers(modifiers) {} |
| 43 | 43 |
| 44 UIEventWithKeyState::UIEventWithKeyState(const AtomicString& type, | 44 UIEventWithKeyState::UIEventWithKeyState(const AtomicString& type, |
| 45 const EventModifierInit& initializer) | 45 const EventModifierInit& initializer) |
| 46 : UIEvent(type, initializer), m_modifiers(0) { | 46 : UIEvent(type, initializer), m_modifiers(0) { |
| 47 if (initializer.ctrlKey()) | 47 if (initializer.ctrlKey()) |
| 48 m_modifiers |= PlatformEvent::CtrlKey; | 48 m_modifiers |= WebInputEvent::ControlKey; |
| 49 if (initializer.shiftKey()) | 49 if (initializer.shiftKey()) |
| 50 m_modifiers |= PlatformEvent::ShiftKey; | 50 m_modifiers |= WebInputEvent::ShiftKey; |
| 51 if (initializer.altKey()) | 51 if (initializer.altKey()) |
| 52 m_modifiers |= PlatformEvent::AltKey; | 52 m_modifiers |= WebInputEvent::AltKey; |
| 53 if (initializer.metaKey()) | 53 if (initializer.metaKey()) |
| 54 m_modifiers |= PlatformEvent::MetaKey; | 54 m_modifiers |= WebInputEvent::MetaKey; |
| 55 if (initializer.modifierAltGraph()) | 55 if (initializer.modifierAltGraph()) |
| 56 m_modifiers |= PlatformEvent::AltGrKey; | 56 m_modifiers |= WebInputEvent::AltGrKey; |
| 57 if (initializer.modifierFn()) | 57 if (initializer.modifierFn()) |
| 58 m_modifiers |= PlatformEvent::FnKey; | 58 m_modifiers |= WebInputEvent::FnKey; |
| 59 if (initializer.modifierCapsLock()) | 59 if (initializer.modifierCapsLock()) |
| 60 m_modifiers |= PlatformEvent::CapsLockOn; | 60 m_modifiers |= WebInputEvent::CapsLockOn; |
| 61 if (initializer.modifierScrollLock()) | 61 if (initializer.modifierScrollLock()) |
| 62 m_modifiers |= PlatformEvent::ScrollLockOn; | 62 m_modifiers |= WebInputEvent::ScrollLockOn; |
| 63 if (initializer.modifierNumLock()) | 63 if (initializer.modifierNumLock()) |
| 64 m_modifiers |= PlatformEvent::NumLockOn; | 64 m_modifiers |= WebInputEvent::NumLockOn; |
| 65 if (initializer.modifierSymbol()) | 65 if (initializer.modifierSymbol()) |
| 66 m_modifiers |= PlatformEvent::SymbolKey; | 66 m_modifiers |= WebInputEvent::SymbolKey; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool UIEventWithKeyState::s_newTabModifierSetFromIsolatedWorld = false; | 69 bool UIEventWithKeyState::s_newTabModifierSetFromIsolatedWorld = false; |
| 70 | 70 |
| 71 void UIEventWithKeyState::didCreateEventInIsolatedWorld(bool ctrlKey, | 71 void UIEventWithKeyState::didCreateEventInIsolatedWorld(bool ctrlKey, |
| 72 bool shiftKey, | 72 bool shiftKey, |
| 73 bool altKey, | 73 bool altKey, |
| 74 bool metaKey) { | 74 bool metaKey) { |
| 75 #if OS(MACOSX) | 75 #if OS(MACOSX) |
| 76 const bool newTabModifierSet = metaKey; | 76 const bool newTabModifierSet = metaKey; |
| 77 #else | 77 #else |
| 78 const bool newTabModifierSet = ctrlKey; | 78 const bool newTabModifierSet = ctrlKey; |
| 79 #endif | 79 #endif |
| 80 s_newTabModifierSetFromIsolatedWorld |= newTabModifierSet; | 80 s_newTabModifierSetFromIsolatedWorld |= newTabModifierSet; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void UIEventWithKeyState::setFromPlatformModifiers( | |
| 84 EventModifierInit& initializer, | |
| 85 const PlatformEvent::Modifiers modifiers) { | |
| 86 setFromWebInputEventModifiers( | |
| 87 initializer, static_cast<WebInputEvent::Modifiers>(modifiers)); | |
| 88 } | |
| 89 | |
| 90 void UIEventWithKeyState::setFromWebInputEventModifiers( | 83 void UIEventWithKeyState::setFromWebInputEventModifiers( |
| 91 EventModifierInit& initializer, | 84 EventModifierInit& initializer, |
| 92 WebInputEvent::Modifiers modifiers) { | 85 WebInputEvent::Modifiers modifiers) { |
| 93 if (modifiers & WebInputEvent::ControlKey) | 86 if (modifiers & WebInputEvent::ControlKey) |
| 94 initializer.setCtrlKey(true); | 87 initializer.setCtrlKey(true); |
| 95 if (modifiers & WebInputEvent::ShiftKey) | 88 if (modifiers & WebInputEvent::ShiftKey) |
| 96 initializer.setShiftKey(true); | 89 initializer.setShiftKey(true); |
| 97 if (modifiers & WebInputEvent::AltKey) | 90 if (modifiers & WebInputEvent::AltKey) |
| 98 initializer.setAltKey(true); | 91 initializer.setAltKey(true); |
| 99 if (modifiers & WebInputEvent::MetaKey) | 92 if (modifiers & WebInputEvent::MetaKey) |
| 100 initializer.setMetaKey(true); | 93 initializer.setMetaKey(true); |
| 101 if (modifiers & WebInputEvent::AltGrKey) | 94 if (modifiers & WebInputEvent::AltGrKey) |
| 102 initializer.setModifierAltGraph(true); | 95 initializer.setModifierAltGraph(true); |
| 103 if (modifiers & WebInputEvent::FnKey) | 96 if (modifiers & WebInputEvent::FnKey) |
| 104 initializer.setModifierFn(true); | 97 initializer.setModifierFn(true); |
| 105 if (modifiers & WebInputEvent::CapsLockOn) | 98 if (modifiers & WebInputEvent::CapsLockOn) |
| 106 initializer.setModifierCapsLock(true); | 99 initializer.setModifierCapsLock(true); |
| 107 if (modifiers & WebInputEvent::ScrollLockOn) | 100 if (modifiers & WebInputEvent::ScrollLockOn) |
| 108 initializer.setModifierScrollLock(true); | 101 initializer.setModifierScrollLock(true); |
| 109 if (modifiers & WebInputEvent::NumLockOn) | 102 if (modifiers & WebInputEvent::NumLockOn) |
| 110 initializer.setModifierNumLock(true); | 103 initializer.setModifierNumLock(true); |
| 111 if (modifiers & WebInputEvent::SymbolKey) | 104 if (modifiers & WebInputEvent::SymbolKey) |
| 112 initializer.setModifierSymbol(true); | 105 initializer.setModifierSymbol(true); |
| 113 } | 106 } |
| 114 | 107 |
| 115 bool UIEventWithKeyState::getModifierState(const String& keyIdentifier) const { | 108 bool UIEventWithKeyState::getModifierState(const String& keyIdentifier) const { |
| 116 struct Identifier { | 109 struct Identifier { |
| 117 const char* identifier; | 110 const char* identifier; |
| 118 PlatformEvent::Modifiers mask; | 111 WebInputEvent::Modifiers mask; |
| 119 }; | 112 }; |
| 120 static const Identifier kIdentifiers[] = { | 113 static const Identifier kIdentifiers[] = { |
| 121 {"Shift", PlatformEvent::ShiftKey}, | 114 {"Shift", WebInputEvent::ShiftKey}, |
| 122 {"Control", PlatformEvent::CtrlKey}, | 115 {"Control", WebInputEvent::ControlKey}, |
| 123 {"Alt", PlatformEvent::AltKey}, | 116 {"Alt", WebInputEvent::AltKey}, |
| 124 {"Meta", PlatformEvent::MetaKey}, | 117 {"Meta", WebInputEvent::MetaKey}, |
| 125 {"AltGraph", PlatformEvent::AltGrKey}, | 118 {"AltGraph", WebInputEvent::AltGrKey}, |
| 126 {"Accel", | 119 {"Accel", |
| 127 #if OS(MACOSX) | 120 #if OS(MACOSX) |
| 128 PlatformEvent::MetaKey | 121 WebInputEvent::MetaKey |
| 129 #else | 122 #else |
| 130 PlatformEvent::CtrlKey | 123 WebInputEvent::ControlKey |
| 131 #endif | 124 #endif |
| 132 }, | 125 }, |
| 133 {"Fn", PlatformEvent::FnKey}, | 126 {"Fn", WebInputEvent::FnKey}, |
| 134 {"CapsLock", PlatformEvent::CapsLockOn}, | 127 {"CapsLock", WebInputEvent::CapsLockOn}, |
| 135 {"ScrollLock", PlatformEvent::ScrollLockOn}, | 128 {"ScrollLock", WebInputEvent::ScrollLockOn}, |
| 136 {"NumLock", PlatformEvent::NumLockOn}, | 129 {"NumLock", WebInputEvent::NumLockOn}, |
| 137 {"Symbol", PlatformEvent::SymbolKey}, | 130 {"Symbol", WebInputEvent::SymbolKey}, |
| 138 }; | 131 }; |
| 139 for (const auto& identifier : kIdentifiers) { | 132 for (const auto& identifier : kIdentifiers) { |
| 140 if (keyIdentifier == identifier.identifier) | 133 if (keyIdentifier == identifier.identifier) |
| 141 return m_modifiers & identifier.mask; | 134 return m_modifiers & identifier.mask; |
| 142 } | 135 } |
| 143 return false; | 136 return false; |
| 144 } | 137 } |
| 145 | 138 |
| 146 void UIEventWithKeyState::initModifiers(bool ctrlKey, | 139 void UIEventWithKeyState::initModifiers(bool ctrlKey, |
| 147 bool altKey, | 140 bool altKey, |
| 148 bool shiftKey, | 141 bool shiftKey, |
| 149 bool metaKey) { | 142 bool metaKey) { |
| 150 m_modifiers = 0; | 143 m_modifiers = 0; |
| 151 if (ctrlKey) | 144 if (ctrlKey) |
| 152 m_modifiers |= PlatformEvent::CtrlKey; | 145 m_modifiers |= WebInputEvent::ControlKey; |
| 153 if (altKey) | 146 if (altKey) |
| 154 m_modifiers |= PlatformEvent::AltKey; | 147 m_modifiers |= WebInputEvent::AltKey; |
| 155 if (shiftKey) | 148 if (shiftKey) |
| 156 m_modifiers |= PlatformEvent::ShiftKey; | 149 m_modifiers |= WebInputEvent::ShiftKey; |
| 157 if (metaKey) | 150 if (metaKey) |
| 158 m_modifiers |= PlatformEvent::MetaKey; | 151 m_modifiers |= WebInputEvent::MetaKey; |
| 159 } | 152 } |
| 160 | 153 |
| 161 UIEventWithKeyState* findEventWithKeyState(Event* event) { | 154 UIEventWithKeyState* findEventWithKeyState(Event* event) { |
| 162 for (Event* e = event; e; e = e->underlyingEvent()) | 155 for (Event* e = event; e; e = e->underlyingEvent()) |
| 163 if (e->isKeyboardEvent() || e->isMouseEvent()) | 156 if (e->isKeyboardEvent() || e->isMouseEvent()) |
| 164 return static_cast<UIEventWithKeyState*>(e); | 157 return static_cast<UIEventWithKeyState*>(e); |
| 165 return nullptr; | 158 return nullptr; |
| 166 } | 159 } |
| 167 | 160 |
| 168 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |