initial import
[vuplus_webkit] / Source / WebKit2 / Shared / WebMouseEvent.cpp
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
32 using namespace WebCore;
33
34 namespace WebKit {
35
36 WebMouseEvent::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 #if PLATFORM(WIN)
44     , m_didActivateWebView(false)
45 #endif
46 {
47 }
48
49 WebMouseEvent::WebMouseEvent(Type type, Button button, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers modifiers, double timestamp)
50     : WebEvent(type, modifiers, timestamp)
51     , m_button(button)
52     , m_position(position)
53     , m_globalPosition(globalPosition)
54     , m_deltaX(deltaX)
55     , m_deltaY(deltaY)
56     , m_deltaZ(deltaZ)
57     , m_clickCount(clickCount)
58 #if PLATFORM(WIN)
59     , m_didActivateWebView(false)
60 #endif
61 {
62     ASSERT(isMouseEventType(type));
63 }
64
65 #if PLATFORM(WIN)
66 WebMouseEvent::WebMouseEvent(Type type, Button button, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers modifiers, double timestamp, bool didActivateWebView)
67     : WebEvent(type, modifiers, timestamp)
68     , m_button(button)
69     , m_position(position)
70     , m_globalPosition(globalPosition)
71     , m_deltaX(deltaX)
72     , m_deltaY(deltaY)
73     , m_deltaZ(deltaZ)
74     , m_clickCount(clickCount)
75     , m_didActivateWebView(didActivateWebView)
76 {
77     ASSERT(isMouseEventType(type));
78 }
79 #endif
80
81 WebMouseEvent::WebMouseEvent(const WebMouseEvent& event, float pageScaleFactor)
82     : WebEvent(event.type(), event.modifiers(), event.timestamp())
83     , m_button(event.button())
84     , m_position(WebCore::IntPoint(event.position().x() / pageScaleFactor, event.position().y() / pageScaleFactor))
85     , m_globalPosition(m_position + (event.globalPosition() - event.position()))
86     , m_deltaX(event.deltaX())
87     , m_deltaY(event.deltaY())
88     , m_deltaZ(event.deltaZ())
89     , m_clickCount(event.clickCount())
90 #if PLATFORM(WIN)
91     , m_didActivateWebView(false)
92 #endif
93 {
94 }
95
96 void WebMouseEvent::encode(CoreIPC::ArgumentEncoder* encoder) const
97 {
98     WebEvent::encode(encoder);
99
100 #if PLATFORM(WIN)
101     // Include m_didActivateWebView on Windows.
102     encoder->encode(CoreIPC::In(m_button, m_position, m_globalPosition, m_deltaX, m_deltaY, m_deltaZ, m_clickCount, m_didActivateWebView));
103 #else
104     encoder->encode(CoreIPC::In(m_button, m_position, m_globalPosition, m_deltaX, m_deltaY, m_deltaZ, m_clickCount));
105 #endif
106 }
107
108 bool WebMouseEvent::decode(CoreIPC::ArgumentDecoder* decoder, WebMouseEvent& t)
109 {
110     if (!WebEvent::decode(decoder, t))
111         return false;
112
113 #if PLATFORM(WIN)
114     // Include m_didActivateWebView on Windows.
115     return decoder->decode(CoreIPC::Out(t.m_button, t.m_position, t.m_globalPosition, t.m_deltaX, t.m_deltaY, t.m_deltaZ, t.m_clickCount, t.m_didActivateWebView));
116 #else
117     return decoder->decode(CoreIPC::Out(t.m_button, t.m_position, t.m_globalPosition, t.m_deltaX, t.m_deltaY, t.m_deltaZ, t.m_clickCount));
118 #endif
119 }
120
121 bool WebMouseEvent::isMouseEventType(Type type)
122 {
123     return type == MouseDown || type == MouseUp || type == MouseMove;
124 }
125     
126 } // namespace WebKit