WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) { if (event.type() == eventNames().keydownEvent) type = KeyDown; else if (event.type() == eventNames().keyupEvent) type = WebInputEvent::KeyUp; else if (event.type() == eventNames().keypressEvent) type = WebInputEvent::Char; else return; // Skip all other keyboard events. modifiers = getWebInputModifiers(event); if (event.keyLocation() == KeyboardEvent::DOMKeyLocationNumpad) modifiers |= WebInputEvent::IsKeyPad; else if (event.keyLocation() == KeyboardEvent::DOMKeyLocationLeft) modifiers |= WebInputEvent::IsLeft; else if (event.keyLocation() == KeyboardEvent::DOMKeyLocationRight) modifiers |= WebInputEvent::IsRight; timeStampSeconds = event.timeStamp() / millisPerSecond; windowsKeyCode = event.keyCode(); // The platform keyevent does not exist if the event was created using // initKeyboardEvent. if (!event.keyEvent()) return; nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), static_cast<unsigned>(textLengthCap)); for (unsigned i = 0; i < numberOfCharacters; ++i) { text[i] = event.keyEvent()->text()[i]; unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i]; } memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), event.keyIdentifier().length()); }
JSValue* JSKeyboardEvent::getValueProperty(ExecState* exec, int token) const { switch (token) { case KeyIdentifierAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsString(exec, imp->keyIdentifier()); } case KeyLocationAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsNumber(exec, imp->keyLocation()); } case CtrlKeyAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsBoolean(imp->ctrlKey()); } case ShiftKeyAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsBoolean(imp->shiftKey()); } case AltKeyAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsBoolean(imp->altKey()); } case MetaKeyAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsBoolean(imp->metaKey()); } case AltGraphKeyAttrNum: { KeyboardEvent* imp = static_cast<KeyboardEvent*>(impl()); return jsBoolean(imp->altGraphKey()); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }