1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "config.h" 27#include "WebEvent.h" 28 29#include "WebCoreArgumentCoders.h" 30#include <WebCore/KeypressCommand.h> 31 32namespace WebKit { 33 34WebKeyboardEvent::WebKeyboardEvent() 35{ 36} 37 38#if USE(APPKIT) 39 40WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, const Vector<WebCore::KeypressCommand>& commands, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp) 41 : WebEvent(type, modifiers, timestamp) 42 , m_text(text) 43 , m_unmodifiedText(unmodifiedText) 44 , m_keyIdentifier(keyIdentifier) 45 , m_windowsVirtualKeyCode(windowsVirtualKeyCode) 46 , m_nativeVirtualKeyCode(nativeVirtualKeyCode) 47 , m_macCharCode(macCharCode) 48 , m_handledByInputMethod(handledByInputMethod) 49 , m_commands(commands) 50 , m_isAutoRepeat(isAutoRepeat) 51 , m_isKeypad(isKeypad) 52 , m_isSystemKey(isSystemKey) 53{ 54 ASSERT(isKeyboardEventType(type)); 55} 56 57#else 58 59WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp) 60 : WebEvent(type, modifiers, timestamp) 61 , m_text(text) 62 , m_unmodifiedText(unmodifiedText) 63 , m_keyIdentifier(keyIdentifier) 64 , m_windowsVirtualKeyCode(windowsVirtualKeyCode) 65 , m_nativeVirtualKeyCode(nativeVirtualKeyCode) 66 , m_macCharCode(macCharCode) 67 , m_isAutoRepeat(isAutoRepeat) 68 , m_isKeypad(isKeypad) 69 , m_isSystemKey(isSystemKey) 70{ 71 ASSERT(isKeyboardEventType(type)); 72} 73 74#endif 75 76WebKeyboardEvent::~WebKeyboardEvent() 77{ 78} 79 80void WebKeyboardEvent::encode(IPC::ArgumentEncoder& encoder) const 81{ 82 WebEvent::encode(encoder); 83 84 encoder << m_text; 85 encoder << m_unmodifiedText; 86 encoder << m_keyIdentifier; 87 encoder << m_windowsVirtualKeyCode; 88 encoder << m_nativeVirtualKeyCode; 89 encoder << m_macCharCode; 90#if USE(APPKIT) 91 encoder << m_handledByInputMethod; 92 encoder << m_commands; 93#endif 94 encoder << m_isAutoRepeat; 95 encoder << m_isKeypad; 96 encoder << m_isSystemKey; 97} 98 99bool WebKeyboardEvent::decode(IPC::ArgumentDecoder& decoder, WebKeyboardEvent& result) 100{ 101 if (!WebEvent::decode(decoder, result)) 102 return false; 103 104 if (!decoder.decode(result.m_text)) 105 return false; 106 if (!decoder.decode(result.m_unmodifiedText)) 107 return false; 108 if (!decoder.decode(result.m_keyIdentifier)) 109 return false; 110 if (!decoder.decode(result.m_windowsVirtualKeyCode)) 111 return false; 112 if (!decoder.decode(result.m_nativeVirtualKeyCode)) 113 return false; 114 if (!decoder.decode(result.m_macCharCode)) 115 return false; 116#if USE(APPKIT) 117 if (!decoder.decode(result.m_handledByInputMethod)) 118 return false; 119 if (!decoder.decode(result.m_commands)) 120 return false; 121#endif 122 if (!decoder.decode(result.m_isAutoRepeat)) 123 return false; 124 if (!decoder.decode(result.m_isKeypad)) 125 return false; 126 if (!decoder.decode(result.m_isSystemKey)) 127 return false; 128 129 return true; 130} 131 132bool WebKeyboardEvent::isKeyboardEventType(Type type) 133{ 134 return type == RawKeyDown || type == KeyDown || type == KeyUp || type == Char; 135} 136 137} // namespace WebKit 138