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
36WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, Modifiers modifiers, double timestamp)
37    : WebEvent(type, modifiers, timestamp)
38    , m_position(position)
39    , m_globalPosition(globalPosition)
40    , m_delta(delta)
41    , m_wheelTicks(wheelTicks)
42    , m_granularity(granularity)
43#if PLATFORM(MAC)
44    , m_phase(PhaseNone)
45    , m_hasPreciseScrollingDeltas(false)
46#endif
47{
48    ASSERT(isWheelEventType(type));
49}
50
51#if PLATFORM(MAC)
52WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, Phase phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, Modifiers modifiers, double timestamp)
53    : WebEvent(type, modifiers, timestamp)
54    , m_position(position)
55    , m_globalPosition(globalPosition)
56    , m_delta(delta)
57    , m_wheelTicks(wheelTicks)
58    , m_granularity(granularity)
59    , m_phase(phase)
60    , m_momentumPhase(momentumPhase)
61    , m_hasPreciseScrollingDeltas(hasPreciseScrollingDeltas)
62{
63    ASSERT(isWheelEventType(type));
64}
65#endif
66
67void WebWheelEvent::encode(CoreIPC::ArgumentEncoder* encoder) const
68{
69    WebEvent::encode(encoder);
70
71    encoder->encode(m_position);
72    encoder->encode(m_globalPosition);
73    encoder->encode(m_delta);
74    encoder->encode(m_wheelTicks);
75    encoder->encode(m_granularity);
76#if PLATFORM(MAC)
77    encoder->encode(m_phase);
78    encoder->encode(m_momentumPhase);
79    encoder->encode(m_hasPreciseScrollingDeltas);
80#endif
81}
82
83bool WebWheelEvent::decode(CoreIPC::ArgumentDecoder* decoder, WebWheelEvent& t)
84{
85    if (!WebEvent::decode(decoder, t))
86        return false;
87    if (!decoder->decode(t.m_position))
88        return false;
89    if (!decoder->decode(t.m_globalPosition))
90        return false;
91    if (!decoder->decode(t.m_delta))
92        return false;
93    if (!decoder->decode(t.m_wheelTicks))
94        return false;
95    if (!decoder->decode(t.m_granularity))
96        return false;
97#if PLATFORM(MAC)
98    if (!decoder->decode(t.m_phase))
99        return false;
100    if (!decoder->decode(t.m_momentumPhase))
101        return false;
102    if (!decoder->decode(t.m_hasPreciseScrollingDeltas))
103        return false;
104#endif
105    return true;
106}
107
108bool WebWheelEvent::isWheelEventType(Type type)
109{
110    return type == Wheel;
111}
112
113} // namespace WebKit
114