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 | |
31 | namespace WebKit { |
32 | |
33 | using namespace WebCore; |
34 | |
35 | WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, OptionSet<Modifier> modifiers, WallTime timestamp) |
36 | : WebEvent(type, modifiers, timestamp) |
37 | , m_position(position) |
38 | , m_globalPosition(globalPosition) |
39 | , m_delta(delta) |
40 | , m_wheelTicks(wheelTicks) |
41 | , m_granularity(granularity) |
42 | , m_directionInvertedFromDevice(false) |
43 | #if PLATFORM(COCOA) |
44 | , m_phase(PhaseNone) |
45 | , m_hasPreciseScrollingDeltas(false) |
46 | , m_scrollCount(0) |
47 | #endif |
48 | { |
49 | ASSERT(isWheelEventType(type)); |
50 | } |
51 | |
52 | #if PLATFORM(COCOA) |
53 | WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, bool directionInvertedFromDevice, Phase phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, OptionSet<Modifier> modifiers, WallTime timestamp) |
54 | : WebEvent(type, modifiers, timestamp) |
55 | , m_position(position) |
56 | , m_globalPosition(globalPosition) |
57 | , m_delta(delta) |
58 | , m_wheelTicks(wheelTicks) |
59 | , m_granularity(granularity) |
60 | , m_directionInvertedFromDevice(directionInvertedFromDevice) |
61 | , m_phase(phase) |
62 | , m_momentumPhase(momentumPhase) |
63 | , m_hasPreciseScrollingDeltas(hasPreciseScrollingDeltas) |
64 | , m_scrollCount(scrollCount) |
65 | , m_unacceleratedScrollingDelta(unacceleratedScrollingDelta) |
66 | { |
67 | ASSERT(isWheelEventType(type)); |
68 | } |
69 | #elif PLATFORM(GTK) |
70 | WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Phase phase, Phase momentumPhase, Granularity granularity, OptionSet<Modifier> modifiers, WallTime timestamp) |
71 | : WebEvent(type, modifiers, timestamp) |
72 | , m_position(position) |
73 | , m_globalPosition(globalPosition) |
74 | , m_delta(delta) |
75 | , m_wheelTicks(wheelTicks) |
76 | , m_granularity(granularity) |
77 | , m_directionInvertedFromDevice(false) |
78 | , m_phase(phase) |
79 | , m_momentumPhase(momentumPhase) |
80 | { |
81 | ASSERT(isWheelEventType(type)); |
82 | } |
83 | #endif |
84 | |
85 | void WebWheelEvent::encode(IPC::Encoder& encoder) const |
86 | { |
87 | WebEvent::encode(encoder); |
88 | |
89 | encoder << m_position; |
90 | encoder << m_globalPosition; |
91 | encoder << m_delta; |
92 | encoder << m_wheelTicks; |
93 | encoder << m_granularity; |
94 | encoder << m_directionInvertedFromDevice; |
95 | #if PLATFORM(COCOA) || PLATFORM(GTK) |
96 | encoder << m_phase; |
97 | encoder << m_momentumPhase; |
98 | #endif |
99 | #if PLATFORM(COCOA) |
100 | encoder << m_hasPreciseScrollingDeltas; |
101 | encoder << m_scrollCount; |
102 | encoder << m_unacceleratedScrollingDelta; |
103 | #endif |
104 | } |
105 | |
106 | bool WebWheelEvent::decode(IPC::Decoder& decoder, WebWheelEvent& t) |
107 | { |
108 | if (!WebEvent::decode(decoder, t)) |
109 | return false; |
110 | if (!decoder.decode(t.m_position)) |
111 | return false; |
112 | if (!decoder.decode(t.m_globalPosition)) |
113 | return false; |
114 | if (!decoder.decode(t.m_delta)) |
115 | return false; |
116 | if (!decoder.decode(t.m_wheelTicks)) |
117 | return false; |
118 | if (!decoder.decode(t.m_granularity)) |
119 | return false; |
120 | if (!decoder.decode(t.m_directionInvertedFromDevice)) |
121 | return false; |
122 | #if PLATFORM(COCOA) || PLATFORM(GTK) |
123 | if (!decoder.decode(t.m_phase)) |
124 | return false; |
125 | if (!decoder.decode(t.m_momentumPhase)) |
126 | return false; |
127 | #endif |
128 | #if PLATFORM(COCOA) |
129 | if (!decoder.decode(t.m_hasPreciseScrollingDeltas)) |
130 | return false; |
131 | if (!decoder.decode(t.m_scrollCount)) |
132 | return false; |
133 | if (!decoder.decode(t.m_unacceleratedScrollingDelta)) |
134 | return false; |
135 | #endif |
136 | return true; |
137 | } |
138 | |
139 | bool WebWheelEvent::isWheelEventType(Type type) |
140 | { |
141 | return type == Wheel; |
142 | } |
143 | |
144 | } // namespace WebKit |
145 | |