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 "Arguments.h" 30#include "WebCoreArgumentCoders.h" 31 32using namespace WebCore; 33 34namespace WebKit { 35 36WebMouseEvent::WebMouseEvent() 37 : WebEvent() 38 , m_button(static_cast<uint32_t>(NoButton)) 39 , m_deltaX(0) 40 , m_deltaY(0) 41 , m_deltaZ(0) 42 , m_clickCount(0) 43{ 44} 45 46WebMouseEvent::WebMouseEvent(Type type, Button button, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers modifiers, double timestamp) 47 : WebEvent(type, modifiers, timestamp) 48 , m_button(button) 49 , m_position(position) 50 , m_globalPosition(globalPosition) 51 , m_deltaX(deltaX) 52 , m_deltaY(deltaY) 53 , m_deltaZ(deltaZ) 54 , m_clickCount(clickCount) 55{ 56 ASSERT(isMouseEventType(type)); 57} 58 59void WebMouseEvent::encode(IPC::ArgumentEncoder& encoder) const 60{ 61 WebEvent::encode(encoder); 62 63 encoder << m_button; 64 encoder << m_position; 65 encoder << m_globalPosition; 66 encoder << m_deltaX; 67 encoder << m_deltaY; 68 encoder << m_deltaZ; 69 encoder << m_clickCount; 70} 71 72bool WebMouseEvent::decode(IPC::ArgumentDecoder& decoder, WebMouseEvent& result) 73{ 74 if (!WebEvent::decode(decoder, result)) 75 return false; 76 77 if (!decoder.decode(result.m_button)) 78 return false; 79 if (!decoder.decode(result.m_position)) 80 return false; 81 if (!decoder.decode(result.m_globalPosition)) 82 return false; 83 if (!decoder.decode(result.m_deltaX)) 84 return false; 85 if (!decoder.decode(result.m_deltaY)) 86 return false; 87 if (!decoder.decode(result.m_deltaZ)) 88 return false; 89 if (!decoder.decode(result.m_clickCount)) 90 return false; 91 92 return true; 93} 94 95bool WebMouseEvent::isMouseEventType(Type type) 96{ 97 return type == MouseDown || type == MouseUp || type == MouseMove; 98} 99 100} // namespace WebKit 101