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
31namespace WebKit {
32using namespace WebCore;
33
34WebMouseEvent::WebMouseEvent()
35 : WebEvent()
36 , m_button(static_cast<uint32_t>(NoButton))
37 , m_deltaX(0)
38 , m_deltaY(0)
39 , m_deltaZ(0)
40 , m_clickCount(0)
41#if PLATFORM(MAC)
42 , m_eventNumber(-1)
43 , m_menuTypeForEvent(0)
44#endif
45{
46}
47
48#if PLATFORM(MAC)
49WebMouseEvent::WebMouseEvent(Type type, Button button, unsigned short buttons, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, OptionSet<Modifier> modifiers, WallTime timestamp, double force, SyntheticClickType syntheticClickType, int eventNumber, int menuType)
50#else
51WebMouseEvent::WebMouseEvent(Type type, Button button, unsigned short buttons, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, OptionSet<Modifier> modifiers, WallTime timestamp, double force, SyntheticClickType syntheticClickType)
52#endif
53 : WebEvent(type, modifiers, timestamp)
54 , m_button(button)
55 , m_buttons(buttons)
56 , m_position(position)
57 , m_globalPosition(globalPosition)
58 , m_deltaX(deltaX)
59 , m_deltaY(deltaY)
60 , m_deltaZ(deltaZ)
61 , m_clickCount(clickCount)
62#if PLATFORM(MAC)
63 , m_eventNumber(eventNumber)
64 , m_menuTypeForEvent(menuType)
65#endif
66 , m_force(force)
67 , m_syntheticClickType(syntheticClickType)
68{
69 ASSERT(isMouseEventType(type));
70}
71
72void WebMouseEvent::encode(IPC::Encoder& encoder) const
73{
74 WebEvent::encode(encoder);
75
76 encoder << m_button;
77 encoder << m_buttons;
78 encoder << m_position;
79 encoder << m_globalPosition;
80 encoder << m_deltaX;
81 encoder << m_deltaY;
82 encoder << m_deltaZ;
83 encoder << m_clickCount;
84#if PLATFORM(MAC)
85 encoder << m_eventNumber;
86 encoder << m_menuTypeForEvent;
87#endif
88 encoder << m_force;
89 encoder << m_syntheticClickType;
90}
91
92bool WebMouseEvent::decode(IPC::Decoder& decoder, WebMouseEvent& result)
93{
94 if (!WebEvent::decode(decoder, result))
95 return false;
96
97 if (!decoder.decode(result.m_button))
98 return false;
99 if (!decoder.decode(result.m_buttons))
100 return false;
101 if (!decoder.decode(result.m_position))
102 return false;
103 if (!decoder.decode(result.m_globalPosition))
104 return false;
105 if (!decoder.decode(result.m_deltaX))
106 return false;
107 if (!decoder.decode(result.m_deltaY))
108 return false;
109 if (!decoder.decode(result.m_deltaZ))
110 return false;
111 if (!decoder.decode(result.m_clickCount))
112 return false;
113#if PLATFORM(MAC)
114 if (!decoder.decode(result.m_eventNumber))
115 return false;
116 if (!decoder.decode(result.m_menuTypeForEvent))
117 return false;
118#endif
119 if (!decoder.decode(result.m_force))
120 return false;
121
122 if (!decoder.decode(result.m_syntheticClickType))
123 return false;
124
125 return true;
126}
127
128bool WebMouseEvent::isMouseEventType(Type type)
129{
130 return type == MouseDown || type == MouseUp || type == MouseMove || type == MouseForceUp || type == MouseForceDown || type == MouseForceChanged;
131}
132
133} // namespace WebKit
134